Collection resource support in SDK and Plug-in.
[platform/upstream/iotivity.git] / service / simulator / java / eclipse-plugin / ServiceProviderPlugin / src / oic / simulator / serviceprovider / view / dialogs / MainPage.java
1 package oic.simulator.serviceprovider.view.dialogs;
2
3 import oic.simulator.serviceprovider.utils.Constants;
4
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;
17
18 public class MainPage extends WizardPage {
19
20     private Button simpleBtn;
21     private Button collectionBtn;
22     private Button simpleFromRamlBtn;
23     private Button collectionFromRamlBtn;
24     private Button deviceBtn;
25     private Text   description;
26
27     public enum ResourceOption {
28         SIMPLE, SIMPLE_FROM_RAML, COLLECTION, COLLECTION_FROM_RAML, DEVICE, NONE
29     }
30
31     private ResourceOption resOption;
32
33     protected MainPage() {
34         super("Main Page");
35     }
36
37     @Override
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);
47
48         simpleBtn = new Button(compContent, SWT.RADIO);
49         simpleBtn.setText("Simple resource");
50
51         simpleFromRamlBtn = new Button(compContent, SWT.RADIO);
52         simpleFromRamlBtn.setText("Simple resource(From RAML)");
53
54         collectionBtn = new Button(compContent, SWT.RADIO);
55         collectionBtn.setText("Collection resource");
56
57         collectionFromRamlBtn = new Button(compContent, SWT.RADIO);
58         collectionFromRamlBtn.setText("Collection resource(From RAML)");
59
60         deviceBtn = new Button(compContent, SWT.RADIO);
61         deviceBtn.setText("Device");
62
63         Label lbl = new Label(compContent, SWT.NULL);
64         lbl.setText("Details:");
65         gd = new GridData();
66         gd.verticalIndent = 20;
67         lbl.setLayoutData(gd);
68
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);
75
76         addUIListeners();
77
78         setControl(compContent);
79     }
80
81     private void addUIListeners() {
82         simpleBtn.addSelectionListener(new SelectionAdapter() {
83             @Override
84             public void widgetSelected(SelectionEvent e) {
85                 description
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();
92             }
93         });
94
95         simpleFromRamlBtn.addSelectionListener(new SelectionAdapter() {
96             @Override
97             public void widgetSelected(SelectionEvent e) {
98                 description
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();
106             }
107         });
108
109         collectionBtn.addSelectionListener(new SelectionAdapter() {
110             @Override
111             public void widgetSelected(SelectionEvent e) {
112                 description
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();
119             }
120         });
121
122         collectionFromRamlBtn.addSelectionListener(new SelectionAdapter() {
123             @Override
124             public void widgetSelected(SelectionEvent e) {
125                 description
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();
133             }
134         });
135
136         deviceBtn.addSelectionListener(new SelectionAdapter() {
137             @Override
138             public void widgetSelected(SelectionEvent e) {
139                 description
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();
145             }
146         });
147     }
148
149     @Override
150     public boolean canFlipToNextPage() {
151         if (resOption != ResourceOption.NONE) {
152             return true;
153         }
154         return false;
155     }
156
157     @Override
158     public IWizardPage getPreviousPage() {
159         return null;
160     }
161
162     @Override
163     public IWizardPage getNextPage() {
164         CreateResourceWizard createWizard = (CreateResourceWizard) getWizard();
165         if (simpleBtn.getSelection()) {
166             return createWizard.getSimpleResourceBasicDetailsPage();
167         }
168         if (simpleFromRamlBtn.getSelection()) {
169             LoadRamlPage page = createWizard.getLoadRamlPage();
170             page.initialSetup(Type.SINGLE);
171             return page;
172         }
173         if (collectionBtn.getSelection()) {
174             return createWizard.getCollectionResourceBasicDetailsPage();
175         }
176         if (collectionFromRamlBtn.getSelection()) {
177             LoadRamlPage page = createWizard.getLoadRamlPage();
178             page.initialSetup(Type.COLLECTION);
179             return page;
180         }
181         if (deviceBtn.getSelection()) {
182             DevicePage page = createWizard.getDevicePage();
183             return page;
184         }
185         return null;
186     }
187
188     public ResourceOption getResourceOption() {
189         return resOption;
190     }
191 }