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.resource.AutomationSettingHelper;
23 import oic.simulator.serviceprovider.utils.Constants;
25 import org.eclipse.jface.dialogs.TitleAreaDialog;
26 import org.eclipse.swt.SWT;
27 import org.eclipse.swt.custom.CCombo;
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.Composite;
33 import org.eclipse.swt.widgets.Control;
34 import org.eclipse.swt.widgets.Label;
35 import org.eclipse.swt.widgets.Shell;
38 * This class manages and shows the automation settings dialog from the
41 public class AutomationSettingDialog extends TitleAreaDialog {
43 private CCombo autoTypeCmb;
44 private CCombo updateFreqCmb;
46 private String automationType;
47 private String updateFrequencyInMillis;
48 private List<AutomationSettingHelper> automationSettings;
50 public AutomationSettingDialog(Shell parentShell,
51 List<AutomationSettingHelper> automationSettings) {
53 this.automationSettings = automationSettings;
57 public void create() {
59 setTitle("Automation Settings");
60 setMessage("Fill the automation settings for the attribute");
64 protected Control createDialogArea(Composite parent) {
65 Composite compLayout = (Composite) super.createDialogArea(parent);
66 Composite container = new Composite(compLayout, SWT.NONE);
67 container.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
68 GridLayout layout = new GridLayout(2, false);
69 layout.verticalSpacing = 10;
70 layout.marginTop = 10;
71 container.setLayout(layout);
75 Label autoTypeLbl = new Label(container, SWT.NONE);
76 autoTypeLbl.setText("Automation Type");
78 autoTypeCmb = new CCombo(container, SWT.READ_ONLY | SWT.BORDER);
80 gd.horizontalAlignment = SWT.FILL;
81 gd.grabExcessHorizontalSpace = true;
82 autoTypeCmb.setLayoutData(gd);
84 Label updateFreqLbl = new Label(container, SWT.NONE);
85 updateFreqLbl.setText("Update Frequency(ms)");
87 updateFreqCmb = new CCombo(container, SWT.READ_ONLY | SWT.BORDER);
89 gd.horizontalAlignment = SWT.FILL;
90 gd.grabExcessHorizontalSpace = true;
91 updateFreqCmb.setLayoutData(gd);
93 populateSettingsData();
102 public void populateSettingsData() {
103 Iterator<AutomationSettingHelper> settingItr = automationSettings
105 AutomationSettingHelper setting;
108 List<String> allowedValues;
109 Iterator<String> itr;
110 while (settingItr.hasNext()) {
111 setting = settingItr.next();
112 settingId = setting.getSettingID();
113 value = setting.getSettingValue();
114 allowedValues = setting.getAllowedValues();
115 if (settingId.equals(Constants.AUTOMATION_TYPE)) {
116 itr = allowedValues.iterator();
117 while (itr.hasNext()) {
118 autoTypeCmb.add(itr.next());
120 // Select the default value
121 autoTypeCmb.select(autoTypeCmb.indexOf(value));
122 } else if (settingId.equals(Constants.UPDATE_INTERVAL_IN_MS)) {
123 itr = allowedValues.iterator();
124 while (itr.hasNext()) {
125 updateFreqCmb.add(itr.next());
127 // Select the default value
128 updateFreqCmb.select(updateFreqCmb.indexOf(value));
133 public void addUIListeners() {
134 autoTypeCmb.addSelectionListener(new SelectionAdapter() {
136 public void widgetSelected(SelectionEvent e) {
137 automationType = autoTypeCmb.getText();
141 updateFreqCmb.addSelectionListener(new SelectionAdapter() {
143 public void widgetSelected(SelectionEvent e) {
144 updateFrequencyInMillis = updateFreqCmb.getText();
149 public void setInitialSettings() {
150 automationType = autoTypeCmb.getText();
151 updateFrequencyInMillis = updateFreqCmb.getText();
154 public String getAutomationType() {
155 return automationType;
158 public String getUpdateFrequency() {
159 return updateFrequencyInMillis;
163 protected boolean isResizable() {
168 public boolean isHelpAvailable() {