Imported Upstream version 1.1.0
[platform/upstream/iotivity.git] / service / simulator / java / eclipse-plugin / ClientControllerPlugin / src / oic / simulator / clientcontroller / view / dialogs / VerificationDialog.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.dialogs.IDialogConstants;
20 import org.eclipse.jface.dialogs.TrayDialog;
21 import org.eclipse.swt.SWT;
22 import org.eclipse.swt.events.SelectionAdapter;
23 import org.eclipse.swt.events.SelectionEvent;
24 import org.eclipse.swt.layout.GridData;
25 import org.eclipse.swt.layout.GridLayout;
26 import org.eclipse.swt.widgets.Button;
27 import org.eclipse.swt.widgets.Composite;
28 import org.eclipse.swt.widgets.Control;
29 import org.eclipse.swt.widgets.Group;
30 import org.eclipse.swt.widgets.Shell;
31
32 import java.util.ArrayList;
33 import java.util.Map;
34 import java.util.Set;
35
36 import oic.simulator.clientcontroller.utils.Constants;
37
38 /**
39  * Dialog for starting and stopping the automatic verifications.
40  */
41 public class VerificationDialog extends TrayDialog {
42     private Map<String, Boolean> automationStatus;
43
44     public VerificationDialog(Shell shell, Map<String, Boolean> automationStatus) {
45         super(shell);
46         this.automationStatus = automationStatus;
47     }
48
49     @Override
50     protected void configureShell(Shell shell) {
51         super.configureShell(shell);
52     }
53
54     @Override
55     protected Control createDialogArea(Composite parent) {
56         Composite composite = (Composite) super.createDialogArea(parent);
57         createAutomationGroup(composite);
58         getShell().setText("Automation Settings");
59         return composite;
60     }
61
62     /**
63      * Dynamically creates a check-box list for enabling/disabling different
64      * types of automation
65      */
66     private void createAutomationGroup(Composite parent) {
67         Group group = new Group(parent, SWT.NONE);
68         group.setLayout(new GridLayout());
69         GridData gd = new GridData(GridData.FILL_HORIZONTAL);
70         gd.widthHint = 275;
71         group.setLayoutData(gd);
72         group.setText("Automation Levels");
73
74         Set<String> keySet = automationStatus.keySet();
75         if (null == keySet) {
76             return;
77         }
78         ArrayList<String> list = new ArrayList<String>(
79                 automationStatus.keySet());
80         for (final String str : list) {
81             final Button checkbox = new Button(group, SWT.CHECK);
82             checkbox.setText(str);
83             checkbox.setSelection(automationStatus.get(str));
84             checkbox.addSelectionListener(new SelectionAdapter() {
85
86                 @Override
87                 public void widgetSelected(SelectionEvent e) {
88                     Button btn = (Button) e.getSource();
89                     if (null == btn) {
90                         return;
91                     }
92                     String btnText = btn.getText();
93                     if (btnText.equalsIgnoreCase(Constants.GET)) {
94                         automationStatus.put(Constants.GET, btn.getSelection());
95                     } else if (btnText.equalsIgnoreCase(Constants.PUT)) {
96                         automationStatus.put(Constants.PUT, btn.getSelection());
97                     } else if (btnText.equalsIgnoreCase(Constants.POST)) {
98                         automationStatus.put(Constants.POST, btn.getSelection());
99                     }
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> getAutomationStatus() {
120         return automationStatus;
121     }
122 }