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 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;
35 import java.util.HashMap;
36 import java.util.Iterator;
38 import java.util.Vector;
40 import oic.simulator.clientcontroller.Activator;
41 import oic.simulator.clientcontroller.remoteresource.RemoteResource;
42 import oic.simulator.clientcontroller.utils.Constants;
43 import oic.simulator.clientcontroller.utils.Utility;
46 * This dialog is used for generating a PUT request.
48 public class GetRequestDialog extends TitleAreaDialog {
49 private Text queryTxt;
50 private Combo ifTypesCmb;
52 private String otherFilters;
53 private String ifType;
55 private Map<String, String> ifTypes;
57 public GetRequestDialog(Shell parentShell) {
62 public void create() {
64 setTitle("Generate GET Request");
65 setMessage("Dialog which takes query filters and generates a GET request.");
69 protected Control createDialogArea(Composite parent) {
70 Composite compLayout = (Composite) super.createDialogArea(parent);
72 Group paramsGrp = new Group(compLayout, SWT.NONE);
73 paramsGrp.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
74 GridLayout layout = new GridLayout(2, false);
75 layout.verticalSpacing = 10;
76 layout.marginTop = 10;
77 paramsGrp.setLayout(layout);
79 Label ifTypeLbl = new Label(paramsGrp, SWT.NONE);
80 ifTypeLbl.setText("Interface Type");
82 ifTypesCmb = new Combo(paramsGrp, SWT.NULL);
83 GridData gd = new GridData();
84 gd.grabExcessHorizontalSpace = true;
85 gd.horizontalAlignment = SWT.FILL;
86 ifTypesCmb.setLayoutData(gd);
87 ifTypesCmb.addModifyListener(new ModifyListener() {
89 public void modifyText(ModifyEvent e) {
90 ifType = ifTypesCmb.getText();
94 RemoteResource resource = Activator.getDefault().getResourceManager()
95 .getCurrentResourceInSelection();
97 // Set the interface types in combo box.
98 Map<String, String> ifTypes = Utility.getResourceInterfaces();
99 this.ifTypes = new HashMap<String, String>();
101 for (Map.Entry<String, String> entry : ifTypes.entrySet()) {
102 key = entry.getValue() + " (" + entry.getKey() + ")";
103 this.ifTypes.put(key, entry.getKey());
107 // Select the default value to be shown in the interface types combo.
108 Vector<String> ifTypesSupportedByResource = resource
109 .getRemoteResourceRef().getResourceInterfaces();
110 if (null != ifTypesSupportedByResource) {
112 if (ifTypesSupportedByResource
113 .contains(Constants.BASELINE_INTERFACE)
114 && ifTypes.containsKey(Constants.BASELINE_INTERFACE)) {
115 // Baseline interface is given preference to be shown in the if
117 String value = ifTypes.get(Constants.BASELINE_INTERFACE);
118 index = ifTypesCmb.indexOf(value + " ("
119 + Constants.BASELINE_INTERFACE + ")");
121 ifTypesCmb.select(index);
124 // Baseline interface is not selected so selecting some other
125 // interface supported by the resource.
126 Iterator<String> itr = ifTypesSupportedByResource.iterator();
127 while (itr.hasNext() && index == -1) {
129 if (ifTypes.containsKey(key)) {
130 String value = ifTypes.get(key);
131 index = ifTypesCmb.indexOf(value + " (" + key + ")");
133 ifTypesCmb.select(index);
138 if (index == -1 && !ifTypesSupportedByResource.isEmpty()) {
139 // Resource has custom interfaces.
140 ifTypesCmb.setText(ifTypesSupportedByResource.get(0));
145 Label otherFilterLbl = new Label(paramsGrp, SWT.NONE);
146 otherFilterLbl.setText("Other filters");
148 queryTxt = new Text(paramsGrp, SWT.BORDER);
150 gd.grabExcessHorizontalSpace = true;
151 gd.horizontalAlignment = SWT.FILL;
152 queryTxt.setLayoutData(gd);
153 queryTxt.addModifyListener(new ModifyListener() {
155 public void modifyText(ModifyEvent e) {
156 otherFilters = queryTxt.getText();
164 protected boolean isResizable() {
169 public boolean isHelpAvailable() {
174 protected Button createButton(Composite parent, int id, String label,
175 boolean defaultButton) {
176 if (id == IDialogConstants.OK_ID) {
179 return super.createButton(parent, id, label, defaultButton);
182 public String getOtherFilters() {
186 public String getIfType() {
187 if (ifTypes.containsKey(ifType)) {
188 return ifTypes.get(ifType);