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 java.util.ArrayList;
23 import oic.simulator.clientcontroller.Activator;
24 import oic.simulator.clientcontroller.manager.ResourceManager;
25 import oic.simulator.clientcontroller.utils.Constants;
27 import org.eclipse.jface.dialogs.IDialogConstants;
28 import org.eclipse.jface.dialogs.MessageDialog;
29 import org.eclipse.jface.dialogs.TrayDialog;
30 import org.eclipse.swt.SWT;
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.Control;
38 import org.eclipse.swt.widgets.Display;
39 import org.eclipse.swt.widgets.Group;
40 import org.eclipse.swt.widgets.Shell;
43 * Dialog for starting and stopping the automatic verifications.
45 public class VerificationDialog extends TrayDialog {
46 private Map<String, Boolean> automationStatus;
48 public VerificationDialog(Shell shell, Map<String, Boolean> automationStatus) {
50 this.automationStatus = automationStatus;
54 protected void configureShell(Shell shell) {
55 super.configureShell(shell);
59 protected Control createDialogArea(Composite parent) {
60 Composite composite = (Composite) super.createDialogArea(parent);
61 createAutomationGroup(composite);
62 getShell().setText("Automation Settings");
67 * Dynamically creates a check-box list for enabling/disabling different
70 private void createAutomationGroup(Composite parent) {
71 Group group = new Group(parent, SWT.NONE);
72 group.setLayout(new GridLayout());
73 GridData gd = new GridData(GridData.FILL_HORIZONTAL);
75 group.setLayoutData(gd);
76 group.setText("Automation Levels");
78 Set<String> keySet = automationStatus.keySet();
82 ArrayList<String> list = new ArrayList<String>(
83 automationStatus.keySet());
84 for (final String str : list) {
85 final Button checkbox = new Button(group, SWT.CHECK);
86 checkbox.setText(str);
87 checkbox.setSelection(automationStatus.get(str));
88 checkbox.addSelectionListener(new SelectionAdapter() {
91 public void widgetSelected(SelectionEvent e) {
92 boolean checked = checkbox.getSelection();
93 boolean answer = MessageDialog.openQuestion(Display
94 .getDefault().getActiveShell(), "Verification",
96 + (checked ? "enable" : "disable")
97 + " the verification?");
99 checkbox.setSelection(!checked);
102 ResourceManager resourceManager = Activator
103 .getDefault().getResourceManager();
104 String reqTypeTxt = checkbox.getText();
106 if (reqTypeTxt.equals("Get")) {
107 reqType = Constants.GET_AUTOMATION_INDEX;
108 } else if (reqTypeTxt.equals("Put")) {
109 reqType = Constants.PUT_AUTOMATION_INDEX;
110 } else {// if(reqTypeTxt.equals("Post")) {
111 reqType = Constants.POST_AUTOMATION_INDEX;
114 resourceManager.startAutomationRequest(reqType,
116 .getCurrentResourceInSelection());
118 resourceManager.stopAutomationRequest(reqType,
120 .getCurrentResourceInSelection());
123 automationStatus.put(str, checked);
130 protected Button createButton(Composite parent, int id, String label,
131 boolean defaultButton) {
132 if (id == IDialogConstants.CANCEL_ID) {
135 return super.createButton(parent, id, label, defaultButton);
139 public boolean isHelpAvailable() {