Java SDK and Eclipse plugin for simulator.
[platform/upstream/iotivity.git] / service / simulator / java / eclipse-plugin / ClientControllerPlugin / src / oic / simulator / clientcontroller / view / dialogs / LoadRAMLDialog.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 oic.simulator.clientcontroller.utils.Constants;
20
21 import org.eclipse.jface.dialogs.TitleAreaDialog;
22 import org.eclipse.swt.SWT;
23 import org.eclipse.swt.events.SelectionAdapter;
24 import org.eclipse.swt.events.SelectionEvent;
25 import org.eclipse.swt.layout.GridData;
26 import org.eclipse.swt.layout.GridLayout;
27 import org.eclipse.swt.widgets.Button;
28 import org.eclipse.swt.widgets.Composite;
29 import org.eclipse.swt.widgets.Control;
30 import org.eclipse.swt.widgets.FileDialog;
31 import org.eclipse.swt.widgets.Label;
32 import org.eclipse.swt.widgets.Shell;
33 import org.eclipse.swt.widgets.Text;
34 import org.eclipse.ui.PlatformUI;
35
36 /**
37  * This dialog is used for loading the RAML file.
38  */
39 public class LoadRAMLDialog extends TitleAreaDialog {
40
41     private Text   locationTxt;
42     private Button btnBrowse;
43     private String configFilePath;
44
45     public LoadRAMLDialog(Shell parentShell) {
46         super(parentShell);
47     }
48
49     @Override
50     public void create() {
51         super.create();
52         setTitle("Load Remote Resource Configuration");
53         setMessage("Select the RAML Configuration file of the resource to enable Automation.");
54     }
55
56     @Override
57     protected Control createDialogArea(Composite parent) {
58         Composite compLayout = (Composite) super.createDialogArea(parent);
59         Composite container = new Composite(compLayout, SWT.NONE);
60         container.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
61         GridLayout layout = new GridLayout(3, false);
62         layout.verticalSpacing = 10;
63         layout.marginTop = 10;
64         container.setLayout(layout);
65
66         Label loadRamlLbl = new Label(container, SWT.NONE);
67         loadRamlLbl.setText("Load RAML File");
68         GridData gd;
69         gd = new GridData();
70         gd.horizontalSpan = 3;
71         loadRamlLbl.setLayoutData(gd);
72
73         Label locationLbl = new Label(container, SWT.NONE);
74         locationLbl.setText("Location:");
75
76         locationTxt = new Text(container, SWT.BORDER);
77         gd = new GridData();
78         gd.minimumWidth = 300;
79         gd.horizontalAlignment = SWT.FILL;
80         gd.grabExcessHorizontalSpace = true;
81         locationTxt.setLayoutData(gd);
82
83         btnBrowse = new Button(container, SWT.NONE);
84         btnBrowse.setText("Browse");
85         gd = new GridData();
86         gd.widthHint = 80;
87         gd.horizontalAlignment = SWT.FILL;
88         btnBrowse.setLayoutData(gd);
89
90         addUIListeners();
91
92         return compLayout;
93     }
94
95     private void addUIListeners() {
96         btnBrowse.addSelectionListener(new SelectionAdapter() {
97             @Override
98             public void widgetSelected(SelectionEvent e) {
99                 FileDialog fileDialog = new FileDialog(PlatformUI
100                         .getWorkbench().getDisplay().getActiveShell(), SWT.NONE);
101                 fileDialog
102                         .setFilterExtensions(Constants.BROWSE_RAML_FILTER_EXTENSIONS);
103                 configFilePath = fileDialog.open();
104                 if (null == configFilePath) {
105                     System.out.println("Config file path is null");
106                     configFilePath = "";
107                 }
108                 locationTxt.setText(configFilePath);
109             }
110         });
111     }
112
113     public String getConfigFilePath() {
114         return configFilePath;
115     }
116
117     @Override
118     public boolean isHelpAvailable() {
119         return false;
120     }
121 }