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.serviceprovider.view.dialogs;
19 import java.util.Iterator;
20 import java.util.List;
22 import oic.simulator.serviceprovider.Activator;
23 import oic.simulator.serviceprovider.resource.DeleteCategory;
24 import oic.simulator.serviceprovider.utils.Constants;
26 import org.eclipse.jface.wizard.WizardPage;
27 import org.eclipse.swt.SWT;
28 import org.eclipse.swt.custom.CCombo;
29 import org.eclipse.swt.events.ModifyEvent;
30 import org.eclipse.swt.events.ModifyListener;
31 import org.eclipse.swt.events.SelectionAdapter;
32 import org.eclipse.swt.events.SelectionEvent;
33 import org.eclipse.swt.layout.GridData;
34 import org.eclipse.swt.layout.GridLayout;
35 import org.eclipse.swt.widgets.Button;
36 import org.eclipse.swt.widgets.Composite;
37 import org.eclipse.swt.widgets.Group;
38 import org.eclipse.swt.widgets.Text;
41 * This class shows UI for deleting resources.
43 public class DeleteResourcePage extends WizardPage {
45 private Button allRbtn;
46 private Button byTypeRbtn;
47 private Button byUriRbtn;
49 private CCombo resourceTypeCmb;
50 private Text resourceUriTxt;
52 private DeleteCategory deleteCategory;
54 // It will hold either the resource type or resource uri
55 private String deleteCandidate;
57 protected DeleteResourcePage() {
58 super("Delete Resource");
62 public void createControl(Composite parent) {
63 setPageComplete(false);
64 setTitle(Constants.DELETE_PAGE_TITLE);
65 setMessage(Constants.DELETE_PAGE_MESSAGE);
67 Composite compContent = new Composite(parent, SWT.NONE);
68 compContent.setLayout(new GridLayout(1, false));
69 GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true);
70 compContent.setLayoutData(gd);
72 Group group = new Group(compContent, SWT.NONE);
73 group.setText("Select Category");
74 GridLayout gridLayout = new GridLayout(2, false);
75 gridLayout.verticalSpacing = 15;
76 gridLayout.marginTop = 10;
77 gridLayout.marginLeft = 10;
78 group.setLayout(gridLayout);
79 gd = new GridData(SWT.FILL, SWT.FILL, true, true);
80 group.setLayoutData(gd);
82 allRbtn = new Button(group, SWT.RADIO);
83 allRbtn.setText("All resources");
85 gd.horizontalSpan = 2;
87 allRbtn.setLayoutData(gd);
89 byTypeRbtn = new Button(group, SWT.RADIO);
90 byTypeRbtn.setText("All (By resource type)");
93 byTypeRbtn.setLayoutData(gd);
95 resourceTypeCmb = new CCombo(group, SWT.READ_ONLY | SWT.BORDER);
98 resourceTypeCmb.setLayoutData(gd);
100 byUriRbtn = new Button(group, SWT.RADIO);
101 byUriRbtn.setText("By Resource URI");
104 byUriRbtn.setLayoutData(gd);
106 resourceUriTxt = new Text(group, SWT.BORDER);
109 resourceUriTxt.setLayoutData(gd);
111 // Setting the initial visibility of controls
112 allRbtn.setSelection(false);
113 byTypeRbtn.setSelection(false);
114 byUriRbtn.setSelection(false);
116 resourceTypeCmb.setEnabled(false);
117 resourceUriTxt.setEnabled(false);
119 deleteCategory = DeleteCategory.NONE;
125 setControl(compContent);
128 private void populateDataInUI() {
129 // Populate Resourcetype in Combo
130 populateResourceTypeCombo();
133 private void populateResourceTypeCombo() {
134 List<String> resourceTypeList;
135 resourceTypeList = Activator.getDefault().getResourceManager()
136 .getResourceTypeList();
137 if (null != resourceTypeList) {
138 Iterator<String> itr = resourceTypeList.iterator();
139 while (itr.hasNext()) {
140 resourceTypeCmb.add(itr.next());
144 // By default, select the first item in the combo
145 if (resourceTypeCmb.getItemCount() > 0) {
146 resourceTypeCmb.select(0);
147 deleteCandidate = resourceTypeCmb.getText();
151 public void addUIListeners() {
152 allRbtn.addSelectionListener(new SelectionAdapter() {
154 public void widgetSelected(SelectionEvent e) {
155 // Update the visibility of controls
156 resourceTypeCmb.setEnabled(false);
157 resourceUriTxt.setEnabled(false);
159 deleteCategory = DeleteCategory.ALL;
160 deleteCandidate = null;
161 setPageComplete(isSelectionDone());
165 byTypeRbtn.addSelectionListener(new SelectionAdapter() {
167 public void widgetSelected(SelectionEvent e) {
168 // Update the visibility of controls
169 resourceTypeCmb.setEnabled(true);
170 resourceUriTxt.setEnabled(false);
172 deleteCategory = DeleteCategory.BY_TYPE;
173 setPageComplete(isSelectionDone());
177 byUriRbtn.addSelectionListener(new SelectionAdapter() {
179 public void widgetSelected(SelectionEvent e) {
180 // Update the visibility of controls
181 resourceUriTxt.setEnabled(true);
182 resourceUriTxt.setFocus();
183 resourceTypeCmb.setEnabled(false);
185 deleteCategory = DeleteCategory.BY_URI;
186 setPageComplete(isSelectionDone());
190 resourceTypeCmb.addModifyListener(new ModifyListener() {
192 public void modifyText(ModifyEvent arg0) {
193 setPageComplete(isSelectionDone());
197 resourceUriTxt.addModifyListener(new ModifyListener() {
199 public void modifyText(ModifyEvent arg0) {
200 setPageComplete(isSelectionDone());
205 public boolean isSelectionDone() {
206 boolean done = false;
207 if (deleteCategory == DeleteCategory.ALL) {
209 } else if (deleteCategory == DeleteCategory.BY_TYPE) {
210 int selectedItemIndex = resourceTypeCmb.getSelectionIndex();
211 if (selectedItemIndex >= 0) {
212 deleteCandidate = resourceTypeCmb.getItem(selectedItemIndex);
213 if (null != deleteCandidate && deleteCandidate.length() > 0) {
217 } else if (deleteCategory == DeleteCategory.BY_URI) {
218 deleteCandidate = resourceUriTxt.getText();
219 if (null != deleteCandidate && deleteCandidate.length() > 0) {
226 public DeleteCategory getDeleteCategory() {
227 return deleteCategory;
230 public String getDeleteCandidate() {
231 return deleteCandidate;
234 public void setFocusToTextBox() {
235 resourceUriTxt.setFocus();