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 org.eclipse.jface.dialogs.IDialogConstants;
20 import org.eclipse.jface.dialogs.TrayDialog;
21 import org.eclipse.jface.window.Window;
22 import org.eclipse.swt.SWT;
23 import org.eclipse.swt.events.SelectionAdapter;
24 import org.eclipse.swt.events.SelectionEvent;
25 import org.eclipse.swt.graphics.Point;
26 import org.eclipse.swt.layout.GridData;
27 import org.eclipse.swt.layout.GridLayout;
28 import org.eclipse.swt.widgets.Button;
29 import org.eclipse.swt.widgets.Composite;
30 import org.eclipse.swt.widgets.Control;
31 import org.eclipse.swt.widgets.Display;
32 import org.eclipse.swt.widgets.List;
33 import org.eclipse.swt.widgets.Shell;
35 import java.util.ArrayList;
39 * Dialog for starting and stopping the automatic verifications.
41 public class UpdateResourceInterfaceDialog extends TrayDialog {
43 private Button addIfTypeBtn;
44 private Button removeIfTypeBtn;
46 private List ifTypesList;
48 private Map<String, String> supportedResInterfaces;
49 private Map<String, String> updatedResInterfaces;
51 public UpdateResourceInterfaceDialog(Shell shell,
52 Map<String, String> updatedResInterfaces,
53 Map<String, String> supportedResInterfaces) {
55 this.updatedResInterfaces = updatedResInterfaces;
56 this.supportedResInterfaces = supportedResInterfaces;
60 protected void configureShell(Shell shell) {
61 super.configureShell(shell);
65 protected Control createDialogArea(Composite parent) {
66 Composite composite = (Composite) super.createDialogArea(parent);
67 getShell().setText("Resource Interfaces");
69 Composite content = new Composite(parent, SWT.NULL);
70 GridLayout gridLayout = new GridLayout(3, false);
71 content.setLayout(gridLayout);
72 GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true);
73 content.setLayoutData(gd);
75 ifTypesList = new List(content, SWT.BORDER | SWT.MULTI | SWT.V_SCROLL
78 gd.horizontalAlignment = SWT.FILL;
79 gd.grabExcessHorizontalSpace = true;
80 gd.verticalAlignment = SWT.FILL;
81 gd.grabExcessHorizontalSpace = true;
82 gd.horizontalSpan = 2;
83 ifTypesList.setLayoutData(gd);
84 ifTypesList.setBackground(Display.getDefault().getSystemColor(
87 Composite ifTypesOpComp = new Composite(content, SWT.NONE);
88 gridLayout = new GridLayout();
89 ifTypesOpComp.setLayout(gridLayout);
91 gd.verticalAlignment = SWT.TOP;
92 ifTypesOpComp.setLayoutData(gd);
94 addIfTypeBtn = new Button(ifTypesOpComp, SWT.PUSH);
95 addIfTypeBtn.setText("Add");
98 addIfTypeBtn.setLayoutData(gd);
99 if (null != updatedResInterfaces && null != supportedResInterfaces
100 && updatedResInterfaces.size() == supportedResInterfaces.size()) {
101 addIfTypeBtn.setEnabled(false);
104 removeIfTypeBtn = new Button(ifTypesOpComp, SWT.PUSH);
105 removeIfTypeBtn.setText("Remove");
108 removeIfTypeBtn.setLayoutData(gd);
109 removeIfTypeBtn.setEnabled(false);
118 private void initInterfaceList() {
119 if (null != updatedResInterfaces) {
120 for (Map.Entry<String, String> entry : updatedResInterfaces
122 ifTypesList.add(entry.getKey());
127 private void addUiListeners() {
128 addIfTypeBtn.addSelectionListener(new SelectionAdapter() {
130 public void widgetSelected(SelectionEvent e) {
131 boolean addAll = false;
132 int itemsAddedCount = ifTypesList.getItemCount();
133 if (itemsAddedCount < supportedResInterfaces.size()) {
135 ArrayList<String> pendingItems = new ArrayList<String>();
136 if (0 == itemsAddedCount) {
139 for (Map.Entry<String, String> entry : supportedResInterfaces
141 key = entry.getKey();
142 if (addAll || -1 == ifTypesList.indexOf(key)) {
143 pendingItems.add(key);
147 AddInterfaceTypeDialog addIfTypeDlg = new AddInterfaceTypeDialog(
148 getShell(), pendingItems);
149 if (Window.CANCEL == addIfTypeDlg.open()) {
152 String ifType = addIfTypeDlg.getValue();
153 if (null == ifType || ifType.isEmpty()) {
157 ifTypesList.add(ifType);
158 ifTypesList.deselectAll();
159 ifTypesList.select(ifTypesList.getItemCount() - 1);
160 ifTypesList.showSelection();
161 removeIfTypeBtn.setEnabled(true);
163 if (itemsAddedCount + 1 == supportedResInterfaces.size()) {
164 addIfTypeBtn.setEnabled(false);
170 removeIfTypeBtn.addSelectionListener(new SelectionAdapter() {
172 public void widgetSelected(SelectionEvent e) {
173 int[] selection = ifTypesList.getSelectionIndices();
174 if (null != selection && selection.length > 0) {
175 ifTypesList.remove(selection);
178 ifTypesList.deselectAll();
179 removeIfTypeBtn.setEnabled(false);
180 addIfTypeBtn.setEnabled(true);
184 ifTypesList.addSelectionListener(new SelectionAdapter() {
186 public void widgetSelected(SelectionEvent e) {
187 int[] selection = ifTypesList.getSelectionIndices();
188 if (null != selection && selection.length > 0) {
189 removeIfTypeBtn.setEnabled(true);
196 protected void okPressed() {
197 // Clearing the map to freshly add selected items.
198 updatedResInterfaces.clear();
200 String[] items = ifTypesList.getItems();
201 if (null != items && items.length > 0) {
202 for (String item : items) {
203 String value = supportedResInterfaces.get(item);
204 updatedResInterfaces.put(item, value);
211 protected Point getInitialSize() {
212 Point actualSize = super.getInitialSize();
213 return new Point(actualSize.x + 100, actualSize.y);
217 protected Button createButton(Composite parent, int id, String label,
218 boolean defaultButton) {
219 if (id == IDialogConstants.CANCEL_ID) {
222 return super.createButton(parent, id, label, defaultButton);
226 public boolean isHelpAvailable() {