a0d1b7cc7cc172e137bcb708b775d89547260fb4
[platform/upstream/iotivity.git] / service / simulator / java / eclipse-plugin / ServiceProviderPlugin / src / oic / simulator / serviceprovider / view / dialogs / UpdateResourceInterfaceDialog.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 java.util.ArrayList;
20 import java.util.Map;
21 import java.util.Set;
22
23 import oic.simulator.serviceprovider.utils.Constants;
24
25 import org.eclipse.jface.dialogs.IDialogConstants;
26 import org.eclipse.jface.dialogs.TrayDialog;
27 import org.eclipse.swt.SWT;
28 import org.eclipse.swt.events.SelectionAdapter;
29 import org.eclipse.swt.events.SelectionEvent;
30 import org.eclipse.swt.layout.GridData;
31 import org.eclipse.swt.layout.GridLayout;
32 import org.eclipse.swt.widgets.Button;
33 import org.eclipse.swt.widgets.Composite;
34 import org.eclipse.swt.widgets.Control;
35 import org.eclipse.swt.widgets.Group;
36 import org.eclipse.swt.widgets.Shell;
37
38 /**
39  * Dialog for starting and stopping the automatic verifications.
40  */
41 public class UpdateResourceInterfaceDialog extends TrayDialog {
42     private Map<String, Boolean> resourceIfStatus;
43
44     public UpdateResourceInterfaceDialog(Shell shell,
45             Map<String, Boolean> resourceIfStatus) {
46         super(shell);
47         this.resourceIfStatus = resourceIfStatus;
48     }
49
50     @Override
51     protected void configureShell(Shell shell) {
52         super.configureShell(shell);
53     }
54
55     @Override
56     protected Control createDialogArea(Composite parent) {
57         Composite composite = (Composite) super.createDialogArea(parent);
58         createAutomationGroup(composite);
59         getShell().setText("Resource Interfaces");
60         return composite;
61     }
62
63     /**
64      * Dynamically creates a check-box list for changing the resource interface
65      * selection.
66      */
67     private void createAutomationGroup(Composite parent) {
68         Group group = new Group(parent, SWT.NONE);
69         group.setLayout(new GridLayout());
70         GridData gd = new GridData(GridData.FILL_HORIZONTAL);
71         gd.widthHint = 275;
72         group.setLayoutData(gd);
73         group.setText("Resource Interfaces");
74
75         Set<String> keySet = resourceIfStatus.keySet();
76         if (null == keySet) {
77             return;
78         }
79         ArrayList<String> list = new ArrayList<String>(keySet);
80         for (final String str : list) {
81             final Button checkbox = new Button(group, SWT.CHECK);
82             checkbox.setText(str);
83             checkbox.setSelection(resourceIfStatus.get(str));
84
85             // Disabling the check-box for baseline interface.
86             if (str.contains(Constants.DEFAULT_SINGLE_RESOURCE_INTERFACE)) {
87                 checkbox.setEnabled(false);
88             }
89
90             checkbox.addSelectionListener(new SelectionAdapter() {
91
92                 @Override
93                 public void widgetSelected(SelectionEvent e) {
94                     Button btn = (Button) e.getSource();
95                     if (null == btn) {
96                         return;
97                     }
98                     String btnText = btn.getText();
99                     resourceIfStatus.put(btnText, btn.getSelection());
100                 }
101             });
102         }
103     }
104
105     @Override
106     protected Button createButton(Composite parent, int id, String label,
107             boolean defaultButton) {
108         if (id == IDialogConstants.CANCEL_ID) {
109             return null;
110         }
111         return super.createButton(parent, id, label, defaultButton);
112     }
113
114     @Override
115     public boolean isHelpAvailable() {
116         return false;
117     }
118
119     public Map<String, Boolean> getResourceInterfaceStatus() {
120         return resourceIfStatus;
121     }
122 }