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.MessageDialog;
20 import org.eclipse.jface.dialogs.TitleAreaDialog;
21 import org.eclipse.swt.SWT;
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.Button;
27 import org.eclipse.swt.widgets.Composite;
28 import org.eclipse.swt.widgets.Control;
29 import org.eclipse.swt.widgets.FileDialog;
30 import org.eclipse.swt.widgets.Label;
31 import org.eclipse.swt.widgets.Shell;
32 import org.eclipse.swt.widgets.Text;
33 import org.eclipse.ui.PlatformUI;
35 import java.io.FileInputStream;
36 import java.io.IOException;
37 import java.util.Date;
39 import org.oic.simulator.ILogger.Level;
41 import oic.simulator.clientcontroller.Activator;
42 import oic.simulator.clientcontroller.utils.Constants;
43 import oic.simulator.clientcontroller.utils.Utility;
46 * This dialog is used for loading the RAML file.
48 public class LoadRAMLDialog extends TitleAreaDialog {
50 private Text locationTxt;
51 private Button btnBrowse;
52 private String configFilePath;
54 public LoadRAMLDialog(Shell parentShell) {
59 public void create() {
61 setTitle("Load Remote Resource Configuration");
62 setMessage("Select the RAML Configuration file of the resource to enable Automation.");
66 protected Control createDialogArea(Composite parent) {
67 Composite compLayout = (Composite) super.createDialogArea(parent);
68 Composite container = new Composite(compLayout, SWT.NONE);
69 container.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
70 GridLayout layout = new GridLayout(3, false);
71 layout.verticalSpacing = 10;
72 layout.marginTop = 10;
73 container.setLayout(layout);
75 Label loadRamlLbl = new Label(container, SWT.NONE);
76 loadRamlLbl.setText("Load RAML File");
79 gd.horizontalSpan = 3;
80 loadRamlLbl.setLayoutData(gd);
82 Label locationLbl = new Label(container, SWT.NONE);
83 locationLbl.setText("Location:");
85 locationTxt = new Text(container, SWT.BORDER);
87 gd.minimumWidth = 300;
88 gd.horizontalAlignment = SWT.FILL;
89 gd.grabExcessHorizontalSpace = true;
90 locationTxt.setLayoutData(gd);
92 btnBrowse = new Button(container, SWT.NONE);
93 btnBrowse.setText("Browse");
96 gd.horizontalAlignment = SWT.FILL;
97 btnBrowse.setLayoutData(gd);
104 private void addUIListeners() {
105 btnBrowse.addSelectionListener(new SelectionAdapter() {
107 public void widgetSelected(SelectionEvent e) {
108 FileDialog fileDialog = new FileDialog(PlatformUI
109 .getWorkbench().getDisplay().getActiveShell(), SWT.NONE);
111 .setFilterExtensions(Constants.BROWSE_RAML_FILTER_EXTENSIONS);
112 String path = fileDialog.open();
116 configFilePath = path;
118 locationTxt.setText(configFilePath);
123 public String getConfigFilePath() {
124 return configFilePath;
128 protected void okPressed() {
129 configFilePath = locationTxt.getText();
130 if (null == configFilePath) {
134 FileInputStream fileStream = null;
136 fileStream = new FileInputStream(configFilePath);
137 } catch (Exception e) {
139 .openError(getShell(), "Invalid File",
140 "File doesn't exist. Either the file path or file name is invalid.");
143 if (null != fileStream) {
146 } catch (IOException e) {
150 .log(Level.ERROR.ordinal(),
152 "There is an error while closing the file stream.\n"
153 + Utility.getSimulatorErrorString(
162 public boolean isHelpAvailable() {