Updated the order of imports in the source files of simulator plugins.
[platform/upstream/iotivity.git] / service / simulator / java / eclipse-plugin / ClientControllerPlugin / src / oic / simulator / clientcontroller / view / dialogs / GetRequestDialog.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.TitleAreaDialog;
21 import org.eclipse.swt.SWT;
22 import org.eclipse.swt.events.ModifyEvent;
23 import org.eclipse.swt.events.ModifyListener;
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.Combo;
28 import org.eclipse.swt.widgets.Composite;
29 import org.eclipse.swt.widgets.Control;
30 import org.eclipse.swt.widgets.Group;
31 import org.eclipse.swt.widgets.Label;
32 import org.eclipse.swt.widgets.Shell;
33 import org.eclipse.swt.widgets.Text;
34
35 import java.util.HashMap;
36 import java.util.Map;
37
38 import oic.simulator.clientcontroller.utils.Utility;
39
40 /**
41  * This dialog is used for generating a PUT request.
42  */
43 public class GetRequestDialog extends TitleAreaDialog {
44     private Text                queryTxt;
45     private Combo               ifTypesCmb;
46
47     private String              otherFilters;
48     private String              ifType;
49
50     private Map<String, String> ifTypes;
51
52     public GetRequestDialog(Shell parentShell) {
53         super(parentShell);
54     }
55
56     @Override
57     public void create() {
58         super.create();
59         setTitle("Generate GET Request");
60         setMessage("Dialog which takes query filters and generates a GET request.");
61     }
62
63     @Override
64     protected Control createDialogArea(Composite parent) {
65         Composite compLayout = (Composite) super.createDialogArea(parent);
66
67         Group paramsGrp = new Group(compLayout, SWT.NONE);
68         paramsGrp.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
69         GridLayout layout = new GridLayout(2, false);
70         layout.verticalSpacing = 10;
71         layout.marginTop = 10;
72         paramsGrp.setLayout(layout);
73
74         Label ifTypeLbl = new Label(paramsGrp, SWT.NONE);
75         ifTypeLbl.setText("Interface Type");
76
77         ifTypesCmb = new Combo(paramsGrp, SWT.NULL);
78         GridData gd = new GridData();
79         gd.grabExcessHorizontalSpace = true;
80         gd.horizontalAlignment = SWT.FILL;
81         ifTypesCmb.setLayoutData(gd);
82         ifTypesCmb.addModifyListener(new ModifyListener() {
83             @Override
84             public void modifyText(ModifyEvent e) {
85                 ifType = ifTypesCmb.getText();
86             }
87         });
88
89         // Set the interface types.
90         Map<String, String> ifTypes = Utility.getResourceInterfaces();
91         if (null != ifTypes && !ifTypes.isEmpty()) {
92             this.ifTypes = new HashMap<String, String>();
93             String key;
94             for (Map.Entry<String, String> entry : ifTypes.entrySet()) {
95                 key = entry.getValue() + " (" + entry.getKey() + ")";
96                 this.ifTypes.put(key, entry.getKey());
97                 ifTypesCmb.add(key);
98             }
99         }
100
101         Label otherFilterLbl = new Label(paramsGrp, SWT.NONE);
102         otherFilterLbl.setText("Other filters");
103
104         queryTxt = new Text(paramsGrp, SWT.BORDER);
105         gd = new GridData();
106         gd.grabExcessHorizontalSpace = true;
107         gd.horizontalAlignment = SWT.FILL;
108         queryTxt.setLayoutData(gd);
109         queryTxt.addModifyListener(new ModifyListener() {
110             @Override
111             public void modifyText(ModifyEvent e) {
112                 otherFilters = queryTxt.getText();
113             }
114         });
115
116         return compLayout;
117     }
118
119     @Override
120     protected boolean isResizable() {
121         return true;
122     }
123
124     @Override
125     public boolean isHelpAvailable() {
126         return false;
127     }
128
129     @Override
130     protected Button createButton(Composite parent, int id, String label,
131             boolean defaultButton) {
132         if (id == IDialogConstants.OK_ID) {
133             label = "GET";
134         }
135         return super.createButton(parent, id, label, defaultButton);
136     }
137
138     public String getOtherFilters() {
139         return otherFilters;
140     }
141
142     public String getIfType() {
143         if (ifTypes.containsKey(ifType)) {
144             return ifTypes.get(ifType);
145         }
146         return ifType;
147     }
148
149 }