Imported Upstream version 1.1.0
[platform/upstream/iotivity.git] / service / simulator / java / eclipse-plugin / ServiceProviderPlugin / src / oic / simulator / serviceprovider / view / dialogs / MainPage.java
1 /*
2  * Copyright 2015 Samsung Electronics All Rights Reserved.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 package oic.simulator.serviceprovider.view.dialogs;
18
19 import org.eclipse.jface.wizard.IWizardPage;
20 import org.eclipse.jface.wizard.WizardPage;
21 import org.eclipse.swt.SWT;
22 import org.eclipse.swt.events.SelectionAdapter;
23 import org.eclipse.swt.events.SelectionEvent;
24 import org.eclipse.swt.layout.GridData;
25 import org.eclipse.swt.layout.GridLayout;
26 import org.eclipse.swt.widgets.Button;
27 import org.eclipse.swt.widgets.Composite;
28 import org.eclipse.swt.widgets.Label;
29 import org.eclipse.swt.widgets.Text;
30
31 import org.oic.simulator.server.SimulatorResource.Type;
32
33 import oic.simulator.serviceprovider.utils.Constants;
34
35 public class MainPage extends WizardPage {
36
37     private Button simpleBtn;
38     private Button simpleFromRamlBtn;
39     private Text   description;
40
41     public enum Option {
42         SIMPLE, SIMPLE_FROM_RAML
43     }
44
45     private Option option;
46
47     protected MainPage() {
48         super("Main Page");
49     }
50
51     @Override
52     public void createControl(Composite parent) {
53         setPageComplete(false);
54         setTitle(Constants.MAIN_PAGE_TITLE);
55         setMessage(Constants.MAIN_PAGE_MESSAGE);
56         Composite compContent = new Composite(parent, SWT.NONE);
57         GridLayout gridLayout = new GridLayout();
58         compContent.setLayout(gridLayout);
59         GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true);
60         compContent.setLayoutData(gd);
61
62         simpleBtn = new Button(compContent, SWT.RADIO);
63         simpleBtn.setText("Simple resource");
64
65         simpleFromRamlBtn = new Button(compContent, SWT.RADIO);
66         simpleFromRamlBtn.setText("Simple resource(From RAML)");
67
68         Label lbl = new Label(compContent, SWT.NULL);
69         lbl.setText("Details:");
70         gd = new GridData();
71         gd.verticalIndent = 20;
72         lbl.setLayoutData(gd);
73
74         description = new Text(compContent, SWT.MULTI | SWT.READ_ONLY
75                 | SWT.BORDER | SWT.WRAP | SWT.V_SCROLL);
76         description.setBackground(compContent.getBackground());
77         description.setText("[Select an option to view more details]");
78         gd = new GridData(SWT.FILL, SWT.FILL, true, true);
79         description.setLayoutData(gd);
80
81         addUIListeners();
82
83         setControl(compContent);
84     }
85
86     private void addUIListeners() {
87         simpleBtn.addSelectionListener(new SelectionAdapter() {
88             @Override
89             public void widgetSelected(SelectionEvent e) {
90                 description
91                         .setText("Create a simple resource by manually entering all the details given below.\n"
92                                 + "\t1. Basic resource details: URI, Name, Resource Type, and Interface types.\n"
93                                 + "\t2. Options such as Observable and Discoverable.\n"
94                                 + "\t3. Adding simple attributes.");
95                 option = Option.SIMPLE;
96                 getWizard().getContainer().updateButtons();
97             }
98         });
99
100         simpleFromRamlBtn.addSelectionListener(new SelectionAdapter() {
101             @Override
102             public void widgetSelected(SelectionEvent e) {
103                 description
104                         .setText("Create a simple resource from RAML configuration file.\n"
105                                 + "\t1. Resource details, attributes, and other properties will be read from RAML.\n"
106                                 + "\t2. Supports multi-instance creation.\n"
107                                 + "\t3. For single instance creation, allows editing the URI and Name of the resource.");
108                 option = Option.SIMPLE_FROM_RAML;
109                 getWizard().getContainer().updateButtons();
110             }
111         });
112     }
113
114     @Override
115     public boolean canFlipToNextPage() {
116         return true;
117     }
118
119     @Override
120     public IWizardPage getPreviousPage() {
121         return null;
122     }
123
124     @Override
125     public IWizardPage getNextPage() {
126         CreateResourceWizard createWizard = (CreateResourceWizard) getWizard();
127         if (simpleBtn.getSelection()) {
128             return createWizard.getSimpleResourceBasicDetailsPage();
129         }
130         if (simpleFromRamlBtn.getSelection()) {
131             LoadRamlPage page = createWizard.getLoadRamlPage();
132             page.initialSetup(Type.SINGLE);
133             return page;
134         }
135         return null;
136     }
137
138     public Option getOption() {
139         return option;
140     }
141 }