1 package oic.simulator.serviceprovider.view.dialogs;
3 import oic.simulator.serviceprovider.utils.Constants;
5 import org.eclipse.jface.wizard.IWizardPage;
6 import org.eclipse.jface.wizard.WizardPage;
7 import org.eclipse.swt.SWT;
8 import org.eclipse.swt.events.SelectionAdapter;
9 import org.eclipse.swt.events.SelectionEvent;
10 import org.eclipse.swt.layout.GridData;
11 import org.eclipse.swt.layout.GridLayout;
12 import org.eclipse.swt.widgets.Button;
13 import org.eclipse.swt.widgets.Composite;
14 import org.eclipse.swt.widgets.Label;
15 import org.eclipse.swt.widgets.Text;
16 import org.oic.simulator.server.SimulatorResource.Type;
18 public class MainPage extends WizardPage {
20 private Button simpleBtn;
21 private Button collectionBtn;
22 private Button simpleFromRamlBtn;
23 private Button collectionFromRamlBtn;
24 private Button deviceBtn;
25 private Text description;
27 public enum ResourceOption {
28 SIMPLE, SIMPLE_FROM_RAML, COLLECTION, COLLECTION_FROM_RAML, DEVICE, NONE
31 private ResourceOption resOption;
33 protected MainPage() {
38 public void createControl(Composite parent) {
39 setPageComplete(false);
40 setTitle(Constants.MAIN_PAGE_TITLE);
41 setMessage(Constants.MAIN_PAGE_MESSAGE);
42 Composite compContent = new Composite(parent, SWT.NONE);
43 GridLayout gridLayout = new GridLayout();
44 compContent.setLayout(gridLayout);
45 GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true);
46 compContent.setLayoutData(gd);
48 simpleBtn = new Button(compContent, SWT.RADIO);
49 simpleBtn.setText("Simple resource");
51 simpleFromRamlBtn = new Button(compContent, SWT.RADIO);
52 simpleFromRamlBtn.setText("Simple resource(From RAML)");
54 collectionBtn = new Button(compContent, SWT.RADIO);
55 collectionBtn.setText("Collection resource");
57 collectionFromRamlBtn = new Button(compContent, SWT.RADIO);
58 collectionFromRamlBtn.setText("Collection resource(From RAML)");
60 deviceBtn = new Button(compContent, SWT.RADIO);
61 deviceBtn.setText("Device");
63 Label lbl = new Label(compContent, SWT.NULL);
64 lbl.setText("Details:");
66 gd.verticalIndent = 20;
67 lbl.setLayoutData(gd);
69 description = new Text(compContent, SWT.MULTI | SWT.READ_ONLY
70 | SWT.BORDER | SWT.WRAP | SWT.V_SCROLL);
71 description.setBackground(compContent.getBackground());
72 description.setText("[Select an option to view more details]");
73 gd = new GridData(SWT.FILL, SWT.FILL, true, true);
74 description.setLayoutData(gd);
78 setControl(compContent);
81 private void addUIListeners() {
82 simpleBtn.addSelectionListener(new SelectionAdapter() {
84 public void widgetSelected(SelectionEvent e) {
86 .setText("Create a simple resource by manually entering all the details given below.\n"
87 + "\t1. Basic resource details: URI, Name, Resource Types, etc.\n"
88 + "\t2. Options such as Observable, allowed request types, start/stop resource etc.\n"
89 + "\t3. Adding attributes.");
90 resOption = ResourceOption.SIMPLE;
91 getWizard().getContainer().updateButtons();
95 simpleFromRamlBtn.addSelectionListener(new SelectionAdapter() {
97 public void widgetSelected(SelectionEvent e) {
99 .setText("Create a simple resource from RAML configuration file.\n"
100 + "\t1. Resource details, attributes, and other properties will be read from RAML.\n"
101 + "\t2. Supports multi-instance creation.\n"
102 + "\t3. For single instance creation, allows editing the URI and Name of the resource.\n"
103 + "\t4. Allows to start or stop the resource(s).");
104 resOption = ResourceOption.SIMPLE_FROM_RAML;
105 getWizard().getContainer().updateButtons();
109 collectionBtn.addSelectionListener(new SelectionAdapter() {
111 public void widgetSelected(SelectionEvent e) {
113 .setText("Create a collection resource by manually entering all the details given below.\n"
114 + "\t1. Basic resource details: URI, Name, Resource Types, etc.\n"
115 + "\t2. Start/stop the resource.\n"
116 + "\t3. Adding existing simple resources to this collection.");
117 resOption = ResourceOption.COLLECTION;
118 getWizard().getContainer().updateButtons();
122 collectionFromRamlBtn.addSelectionListener(new SelectionAdapter() {
124 public void widgetSelected(SelectionEvent e) {
126 .setText("Create a collection resource from RAML configuration file.\n"
127 + "\t1. Resource details, attributes, and other properties will be read from RAML.\n"
128 + "\t2. Supports multi-instance creation.\n"
129 + "\t3. For single instance creation, allows editing the URI and Name of the resource.\n"
130 + "\t4. Allows to start or stop the resource(s).");
131 resOption = ResourceOption.COLLECTION_FROM_RAML;
132 getWizard().getContainer().updateButtons();
136 deviceBtn.addSelectionListener(new SelectionAdapter() {
138 public void widgetSelected(SelectionEvent e) {
140 .setText("Create a logical device that acts as a top-level logical classification.\n"
141 + "\t1. Takes a device name for identication.\n"
142 + "\t2. One or more simple and collection resources can be added to it.");
143 resOption = ResourceOption.DEVICE;
144 getWizard().getContainer().updateButtons();
150 public boolean canFlipToNextPage() {
151 if (resOption != ResourceOption.NONE) {
158 public IWizardPage getPreviousPage() {
163 public IWizardPage getNextPage() {
164 CreateResourceWizard createWizard = (CreateResourceWizard) getWizard();
165 if (simpleBtn.getSelection()) {
166 return createWizard.getSimpleResourceBasicDetailsPage();
168 if (simpleFromRamlBtn.getSelection()) {
169 LoadRamlPage page = createWizard.getLoadRamlPage();
170 page.initialSetup(Type.SINGLE);
173 if (collectionBtn.getSelection()) {
174 return createWizard.getCollectionResourceBasicDetailsPage();
176 if (collectionFromRamlBtn.getSelection()) {
177 LoadRamlPage page = createWizard.getLoadRamlPage();
178 page.initialSetup(Type.COLLECTION);
181 if (deviceBtn.getSelection()) {
182 DevicePage page = createWizard.getDevicePage();
188 public ResourceOption getResourceOption() {