6f93ff10a4902a5e295a07ba4dee004e7e3e906c
[platform/upstream/iotivity.git] / service / simulator / java / eclipse-plugin / ServiceProviderPlugin / src / oic / simulator / serviceprovider / view / dialogs / UpdatePropertiesPage.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 oic.simulator.serviceprovider.utils.Constants;
20
21 import org.eclipse.jface.wizard.IWizardPage;
22 import org.eclipse.jface.wizard.WizardPage;
23 import org.eclipse.swt.SWT;
24 import org.eclipse.swt.events.ModifyEvent;
25 import org.eclipse.swt.events.ModifyListener;
26 import org.eclipse.swt.layout.GridData;
27 import org.eclipse.swt.layout.GridLayout;
28 import org.eclipse.swt.widgets.Composite;
29 import org.eclipse.swt.widgets.Group;
30 import org.eclipse.swt.widgets.Label;
31 import org.eclipse.swt.widgets.Text;
32
33 public class UpdatePropertiesPage extends WizardPage {
34
35     private Text   resNameTxt;
36     private Text   resUriTxt;
37
38     private String resName;
39     private String resURI;
40
41     protected UpdatePropertiesPage() {
42         super("Update Properties");
43     }
44
45     @Override
46     public void createControl(Composite parent) {
47         setPageComplete(true);
48         setTitle(Constants.UPDATE_PROP_PAGE_TITLE);
49         setMessage(Constants.UPDATE_PROP_PAGE_MESSAGE);
50
51         Composite comp = new Composite(parent, SWT.NONE);
52         GridLayout gridLayout = new GridLayout();
53         comp.setLayout(gridLayout);
54         GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true);
55         comp.setLayoutData(gd);
56
57         Group grp = new Group(comp, SWT.NONE);
58         gridLayout = new GridLayout(2, false);
59         grp.setLayout(gridLayout);
60         gd = new GridData(SWT.FILL, SWT.FILL, true, true);
61         grp.setLayoutData(gd);
62
63         Label resNameLbl = new Label(grp, SWT.NULL);
64         resNameLbl.setText("Resource Name");
65         gd = new GridData();
66         gd.verticalIndent = 20;
67         resNameLbl.setLayoutData(gd);
68
69         resNameTxt = new Text(grp, SWT.BORDER);
70         resNameTxt.setFocus();
71         gd = new GridData();
72         gd.widthHint = 300;
73         gd.verticalIndent = 20;
74         resNameTxt.setLayoutData(gd);
75
76         Label resUriLbl = new Label(grp, SWT.NULL);
77         resUriLbl.setText("Resource URI");
78         gd = new GridData();
79         gd.verticalIndent = 10;
80         resUriLbl.setLayoutData(gd);
81
82         resUriTxt = new Text(grp, SWT.BORDER);
83         gd = new GridData();
84         gd.widthHint = 300;
85         gd.verticalIndent = 10;
86         resUriTxt.setLayoutData(gd);
87
88         Label descLbl = new Label(comp, SWT.NONE);
89         descLbl.setText("Description:");
90         gd = new GridData();
91         descLbl.setLayoutData(gd);
92
93         final Text text = new Text(comp, SWT.MULTI | SWT.READ_ONLY | SWT.BORDER
94                 | SWT.WRAP | SWT.V_SCROLL);
95         text.setText("These properties can be changed later from properties view.");
96         gd = new GridData(SWT.FILL, SWT.FILL, true, true);
97         text.setLayoutData(gd);
98
99         addUIListeners();
100
101         // Initialize data
102         if (resUriTxt.getText().length() < 1 && null != resURI) {
103             resUriTxt.setText(resURI);
104         }
105         if (resNameTxt.getText().length() < 1 && null != resName) {
106             resNameTxt.setText(resName);
107         }
108
109         setControl(comp);
110     }
111
112     private void addUIListeners() {
113         resNameTxt.addModifyListener(new ModifyListener() {
114             @Override
115             public void modifyText(ModifyEvent e) {
116                 resName = resNameTxt.getText();
117                 setPageComplete(isSelectionDone());
118             }
119         });
120
121         resUriTxt.addModifyListener(new ModifyListener() {
122             @Override
123             public void modifyText(ModifyEvent e) {
124                 resURI = resUriTxt.getText();
125                 if (null == resURI) {
126                     return;
127                 }
128
129                 setPageComplete(isSelectionDone());
130             }
131         });
132     }
133
134     @Override
135     public boolean canFlipToNextPage() {
136         return false;
137     }
138
139     public boolean isSelectionDone() {
140         boolean done = false;
141         if (null != resName && resName.trim().length() > 0 && null != resURI
142                 && resURI.trim().length() > 0) {
143             done = true;
144         }
145         return done;
146     }
147
148     @Override
149     public IWizardPage getNextPage() {
150         return null;
151     }
152
153     public void setResName(String resName) {
154         this.resName = resName;
155         if (!resNameTxt.isDisposed())
156             resNameTxt.setText(resName);
157     }
158
159     public void setResURI(String resURI) {
160         this.resURI = resURI;
161         if (!resUriTxt.isDisposed())
162             resUriTxt.setText(resURI);
163     }
164
165     public String getResName() {
166         return resName;
167     }
168
169     public String getResURI() {
170         return resURI;
171     }
172 }