Updated the order of imports in the source files of simulator plugins.
[platform/upstream/iotivity.git] / service / simulator / java / eclipse-plugin / ClientControllerPlugin / src / oic / simulator / clientcontroller / view / dialogs / FindResourcePage.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.clientcontroller.view.dialogs;
18
19 import org.eclipse.jface.wizard.WizardPage;
20 import org.eclipse.swt.SWT;
21 import org.eclipse.swt.events.ModifyEvent;
22 import org.eclipse.swt.events.ModifyListener;
23 import org.eclipse.swt.events.SelectionAdapter;
24 import org.eclipse.swt.events.SelectionEvent;
25 import org.eclipse.swt.layout.GridData;
26 import org.eclipse.swt.layout.GridLayout;
27 import org.eclipse.swt.widgets.Button;
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 import java.util.Set;
34
35 import oic.simulator.clientcontroller.utils.Constants;
36 import oic.simulator.clientcontroller.utils.Utility;
37
38 /**
39  * This class shows UI for finding resources.
40  */
41 public class FindResourcePage extends WizardPage {
42
43     private Button      allRbtn;
44     private Button      resTypeRbtn;
45     private Text        resTypeTxt;
46     private Label       resTypeLbl;
47
48     private Set<String> typesToSearch;
49
50     protected FindResourcePage() {
51         super("Find Resource");
52     }
53
54     @Override
55     public void createControl(Composite parent) {
56         setTitle(Constants.FIND_PAGE_TITLE);
57         setMessage(Constants.FIND_PAGE_MESSAGE);
58
59         Composite compContent = new Composite(parent, SWT.NONE);
60         GridLayout gridLayout = new GridLayout();
61         compContent.setLayout(gridLayout);
62         GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true);
63         compContent.setLayoutData(gd);
64
65         Group configGroup = new Group(compContent, SWT.NONE);
66         gridLayout = new GridLayout(2, false);
67         gridLayout.verticalSpacing = 10;
68         gridLayout.marginTop = 5;
69         configGroup.setLayout(gridLayout);
70         gd = new GridData();
71         gd.horizontalAlignment = SWT.FILL;
72         gd.grabExcessHorizontalSpace = true;
73         configGroup.setLayoutData(gd);
74         configGroup.setText("Resource Type");
75
76         allRbtn = new Button(configGroup, SWT.RADIO);
77         allRbtn.setText("All");
78         gd = new GridData();
79         gd.horizontalSpan = 2;
80         allRbtn.setLayoutData(gd);
81         allRbtn.setSelection(true);
82
83         resTypeRbtn = new Button(configGroup, SWT.RADIO);
84         resTypeRbtn.setText("Specific Resource types (seperated by commas)");
85         gd = new GridData();
86         gd.horizontalSpan = 2;
87         resTypeRbtn.setLayoutData(gd);
88
89         resTypeLbl = new Label(configGroup, SWT.NONE);
90         resTypeLbl.setText("Resource Types:");
91         resTypeLbl.setEnabled(false);
92
93         resTypeTxt = new Text(configGroup, SWT.BORDER);
94         resTypeTxt.setToolTipText("Ex: sample.light, hall.fridge");
95         resTypeTxt.setMessage("Ex: sample.light, hall.fridge");
96         gd = new GridData();
97         gd.minimumWidth = 200;
98         gd.horizontalAlignment = SWT.FILL;
99         gd.grabExcessHorizontalSpace = true;
100         resTypeTxt.setLayoutData(gd);
101         resTypeTxt.setEnabled(false);
102
103         addUIListeners();
104
105         setControl(compContent);
106     }
107
108     private void addUIListeners() {
109         allRbtn.addSelectionListener(new SelectionAdapter() {
110             @Override
111             public void widgetSelected(SelectionEvent e) {
112                 typesToSearch = null;
113                 setPageComplete(true);
114                 // Change the visibility of widgets
115                 changeVisibility(false);
116             }
117         });
118
119         resTypeRbtn.addSelectionListener(new SelectionAdapter() {
120             @Override
121             public void widgetSelected(SelectionEvent e) {
122                 String typeText = resTypeTxt.getText();
123                 if (null != typeText && typeText.length() > 0) {
124                     typesToSearch = Utility.splitStringByComma(typeText);
125                 }
126
127                 if (null != typesToSearch && typesToSearch.size() > 0) {
128                     setPageComplete(true);
129                 } else {
130                     setPageComplete(false);
131                 }
132                 // Change the visibility of widgets
133                 changeVisibility(true);
134                 resTypeTxt.setFocus();
135             }
136         });
137
138         resTypeTxt.addModifyListener(new ModifyListener() {
139             @Override
140             public void modifyText(ModifyEvent e) {
141                 String typeText = resTypeTxt.getText();
142                 typesToSearch = Utility.splitStringByComma(typeText);
143                 if (null != typesToSearch && typesToSearch.size() > 0) {
144                     setPageComplete(true);
145                 } else {
146                     setPageComplete(false);
147                 }
148             }
149         });
150     }
151
152     private void changeVisibility(boolean standard) {
153         resTypeLbl.setEnabled(standard);
154         resTypeTxt.setEnabled(standard);
155     }
156
157     public Set<String> getSearchTypes() {
158         return typesToSearch;
159     }
160 }