2 * Copyright 2015 Samsung Electronics All Rights Reserved.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 package oic.simulator.clientcontroller.view.dialogs;
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;
35 import oic.simulator.clientcontroller.utils.Constants;
36 import oic.simulator.clientcontroller.utils.Utility;
39 * This class shows UI for finding resources.
41 public class FindResourcePage extends WizardPage {
43 private Button allRbtn;
44 private Button resTypeRbtn;
45 private Text resTypeTxt;
46 private Label resTypeLbl;
48 private Set<String> typesToSearch;
50 protected FindResourcePage() {
51 super("Find Resource");
55 public void createControl(Composite parent) {
56 setTitle(Constants.FIND_PAGE_TITLE);
57 setMessage(Constants.FIND_PAGE_MESSAGE);
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);
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);
71 gd.horizontalAlignment = SWT.FILL;
72 gd.grabExcessHorizontalSpace = true;
73 configGroup.setLayoutData(gd);
74 configGroup.setText("Resource Type");
76 allRbtn = new Button(configGroup, SWT.RADIO);
77 allRbtn.setText("All");
79 gd.horizontalSpan = 2;
80 allRbtn.setLayoutData(gd);
81 allRbtn.setSelection(true);
83 resTypeRbtn = new Button(configGroup, SWT.RADIO);
84 resTypeRbtn.setText("Specific Resource types (seperated by commas)");
86 gd.horizontalSpan = 2;
87 resTypeRbtn.setLayoutData(gd);
89 resTypeLbl = new Label(configGroup, SWT.NONE);
90 resTypeLbl.setText("Resource Types:");
91 resTypeLbl.setEnabled(false);
93 resTypeTxt = new Text(configGroup, SWT.BORDER);
94 resTypeTxt.setToolTipText("Ex: sample.light, hall.fridge");
95 resTypeTxt.setMessage("Ex: sample.light, hall.fridge");
97 gd.minimumWidth = 200;
98 gd.horizontalAlignment = SWT.FILL;
99 gd.grabExcessHorizontalSpace = true;
100 resTypeTxt.setLayoutData(gd);
101 resTypeTxt.setEnabled(false);
105 setControl(compContent);
108 private void addUIListeners() {
109 allRbtn.addSelectionListener(new SelectionAdapter() {
111 public void widgetSelected(SelectionEvent e) {
112 typesToSearch = null;
113 setPageComplete(true);
114 // Change the visibility of widgets
115 changeVisibility(false);
119 resTypeRbtn.addSelectionListener(new SelectionAdapter() {
121 public void widgetSelected(SelectionEvent e) {
122 String typeText = resTypeTxt.getText();
123 if (null != typeText && typeText.length() > 0) {
124 typesToSearch = Utility.splitStringByComma(typeText);
127 if (null != typesToSearch && typesToSearch.size() > 0) {
128 setPageComplete(true);
130 setPageComplete(false);
132 // Change the visibility of widgets
133 changeVisibility(true);
134 resTypeTxt.setFocus();
138 resTypeTxt.addModifyListener(new ModifyListener() {
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);
146 setPageComplete(false);
152 private void changeVisibility(boolean standard) {
153 resTypeLbl.setEnabled(standard);
154 resTypeTxt.setEnabled(standard);
157 public Set<String> getSearchTypes() {
158 return typesToSearch;