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 java.io.FileInputStream;
21 import oic.simulator.clientcontroller.utils.Constants;
23 import org.eclipse.jface.dialogs.MessageDialog;
24 import org.eclipse.jface.dialogs.TitleAreaDialog;
25 import org.eclipse.swt.SWT;
26 import org.eclipse.swt.events.SelectionAdapter;
27 import org.eclipse.swt.events.SelectionEvent;
28 import org.eclipse.swt.layout.GridData;
29 import org.eclipse.swt.layout.GridLayout;
30 import org.eclipse.swt.widgets.Button;
31 import org.eclipse.swt.widgets.Composite;
32 import org.eclipse.swt.widgets.Control;
33 import org.eclipse.swt.widgets.FileDialog;
34 import org.eclipse.swt.widgets.Label;
35 import org.eclipse.swt.widgets.Shell;
36 import org.eclipse.swt.widgets.Text;
37 import org.eclipse.ui.PlatformUI;
40 * This dialog is used for loading the RAML file.
42 public class LoadRAMLDialog extends TitleAreaDialog {
44 private Text locationTxt;
45 private Button btnBrowse;
46 private String configFilePath;
48 public LoadRAMLDialog(Shell parentShell) {
53 public void create() {
55 setTitle("Load Remote Resource Configuration");
56 setMessage("Select the RAML Configuration file of the resource to enable Automation.");
60 protected Control createDialogArea(Composite parent) {
61 Composite compLayout = (Composite) super.createDialogArea(parent);
62 Composite container = new Composite(compLayout, SWT.NONE);
63 container.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
64 GridLayout layout = new GridLayout(3, false);
65 layout.verticalSpacing = 10;
66 layout.marginTop = 10;
67 container.setLayout(layout);
69 Label loadRamlLbl = new Label(container, SWT.NONE);
70 loadRamlLbl.setText("Load RAML File");
73 gd.horizontalSpan = 3;
74 loadRamlLbl.setLayoutData(gd);
76 Label locationLbl = new Label(container, SWT.NONE);
77 locationLbl.setText("Location:");
79 locationTxt = new Text(container, SWT.BORDER);
81 gd.minimumWidth = 300;
82 gd.horizontalAlignment = SWT.FILL;
83 gd.grabExcessHorizontalSpace = true;
84 locationTxt.setLayoutData(gd);
86 btnBrowse = new Button(container, SWT.NONE);
87 btnBrowse.setText("Browse");
90 gd.horizontalAlignment = SWT.FILL;
91 btnBrowse.setLayoutData(gd);
98 private void addUIListeners() {
99 btnBrowse.addSelectionListener(new SelectionAdapter() {
101 public void widgetSelected(SelectionEvent e) {
102 FileDialog fileDialog = new FileDialog(PlatformUI
103 .getWorkbench().getDisplay().getActiveShell(), SWT.NONE);
105 .setFilterExtensions(Constants.BROWSE_RAML_FILTER_EXTENSIONS);
106 String path = fileDialog.open();
110 configFilePath = path;
112 locationTxt.setText(configFilePath);
117 public String getConfigFilePath() {
118 return configFilePath;
122 protected void okPressed() {
123 configFilePath = locationTxt.getText();
124 if (null == configFilePath) {
128 new FileInputStream(configFilePath);
129 } catch (Exception e) {
131 .openError(getShell(), "Invalid File",
132 "File doesn't exist. Either the file path or file name is invalid.");
139 public boolean isHelpAvailable() {