Updated the order of imports in the source files of simulator plugins.
[platform/upstream/iotivity.git] / service / simulator / java / eclipse-plugin / ServiceProviderPlugin / src / oic / simulator / serviceprovider / view / dialogs / AutomationSettingDialog.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 org.eclipse.jface.dialogs.TitleAreaDialog;
20 import org.eclipse.swt.SWT;
21 import org.eclipse.swt.custom.CCombo;
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.Composite;
27 import org.eclipse.swt.widgets.Control;
28 import org.eclipse.swt.widgets.Label;
29 import org.eclipse.swt.widgets.Shell;
30
31 import java.util.Iterator;
32 import java.util.List;
33
34 import oic.simulator.serviceprovider.model.AutomationSettingHelper;
35 import oic.simulator.serviceprovider.utils.Constants;
36
37 /**
38  * This class manages and shows the automation settings dialog from the
39  * attribute view.
40  */
41 public class AutomationSettingDialog extends TitleAreaDialog {
42
43     private CCombo                        autoTypeCmb;
44     private CCombo                        updateFreqCmb;
45
46     private String                        automationType;
47     private String                        updateFrequencyInMillis;
48     private List<AutomationSettingHelper> automationSettings;
49
50     public AutomationSettingDialog(Shell parentShell,
51             List<AutomationSettingHelper> automationSettings) {
52         super(parentShell);
53         this.automationSettings = automationSettings;
54     }
55
56     @Override
57     public void create() {
58         super.create();
59         setTitle("Automation Settings");
60         setMessage("Fill the automation settings for the attribute");
61     }
62
63     @Override
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);
72
73         GridData gd;
74
75         Label autoTypeLbl = new Label(container, SWT.NONE);
76         autoTypeLbl.setText("Automation Type");
77
78         autoTypeCmb = new CCombo(container, SWT.READ_ONLY | SWT.BORDER);
79         gd = new GridData();
80         gd.horizontalAlignment = SWT.FILL;
81         gd.grabExcessHorizontalSpace = true;
82         autoTypeCmb.setLayoutData(gd);
83
84         Label updateFreqLbl = new Label(container, SWT.NONE);
85         updateFreqLbl.setText("Update Frequency(ms)");
86
87         updateFreqCmb = new CCombo(container, SWT.READ_ONLY | SWT.BORDER);
88         gd = new GridData();
89         gd.horizontalAlignment = SWT.FILL;
90         gd.grabExcessHorizontalSpace = true;
91         updateFreqCmb.setLayoutData(gd);
92
93         populateSettingsData();
94
95         addUIListeners();
96
97         setInitialSettings();
98
99         return compLayout;
100     }
101
102     public void populateSettingsData() {
103         Iterator<AutomationSettingHelper> settingItr = automationSettings
104                 .iterator();
105         AutomationSettingHelper setting;
106         String settingId;
107         String value;
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());
119                 }
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());
126                 }
127                 // Select the default value
128                 updateFreqCmb.select(updateFreqCmb.indexOf(value));
129             }
130         }
131     }
132
133     public void addUIListeners() {
134         autoTypeCmb.addSelectionListener(new SelectionAdapter() {
135             @Override
136             public void widgetSelected(SelectionEvent e) {
137                 automationType = autoTypeCmb.getText();
138             }
139         });
140
141         updateFreqCmb.addSelectionListener(new SelectionAdapter() {
142             @Override
143             public void widgetSelected(SelectionEvent e) {
144                 updateFrequencyInMillis = updateFreqCmb.getText();
145             }
146         });
147     }
148
149     public void setInitialSettings() {
150         automationType = autoTypeCmb.getText();
151         updateFrequencyInMillis = updateFreqCmb.getText();
152     }
153
154     public String getAutomationType() {
155         return automationType;
156     }
157
158     public String getUpdateFrequency() {
159         return updateFrequencyInMillis;
160     }
161
162     @Override
163     protected boolean isResizable() {
164         return true;
165     }
166
167     @Override
168     public boolean isHelpAvailable() {
169         return false;
170     }
171 }