Add support for importing traces to tracing project
[deliverable/tracecompass.git] / org.eclipse.linuxtools.lttng2.ui / src / org / eclipse / linuxtools / internal / lttng2 / ui / views / control / dialogs / CreateSessionDialog.java
CommitLineData
bbb3538a
BH
1/**********************************************************************
2 * Copyright (c) 2012 Ericsson
3 *
4 * All rights reserved. This program and the accompanying materials are
5 * made available under the terms of the Eclipse Public License v1.0 which
6 * accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
8 *
9 * Contributors:
10 * Bernd Hufmann - Initial API and implementation
11 **********************************************************************/
115b4a01 12package org.eclipse.linuxtools.internal.lttng2.ui.views.control.dialogs;
bbb3538a
BH
13
14import org.eclipse.core.runtime.NullProgressMonitor;
15import org.eclipse.jface.dialogs.Dialog;
16import org.eclipse.jface.dialogs.IDialogConstants;
17import org.eclipse.jface.dialogs.MessageDialog;
115b4a01
BH
18import org.eclipse.linuxtools.internal.lttng2.ui.Activator;
19import org.eclipse.linuxtools.internal.lttng2.ui.views.control.Messages;
20import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TargetNodeComponent;
21import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TraceSessionGroup;
22import org.eclipse.linuxtools.internal.lttng2.ui.views.control.remote.IRemoteSystemProxy;
bbb3538a
BH
23import org.eclipse.rse.services.clientserver.messages.SystemMessageException;
24import org.eclipse.rse.subsystems.files.core.servicesubsystem.IFileServiceSubSystem;
25import org.eclipse.rse.subsystems.files.core.subsystems.IRemoteFile;
26import org.eclipse.swt.SWT;
27import org.eclipse.swt.graphics.Point;
28import org.eclipse.swt.layout.GridData;
29import org.eclipse.swt.layout.GridLayout;
30import org.eclipse.swt.widgets.Composite;
31import org.eclipse.swt.widgets.Control;
32import org.eclipse.swt.widgets.Label;
33import org.eclipse.swt.widgets.Shell;
34import org.eclipse.swt.widgets.Text;
35
36/**
37 * <b><u>CreateSessionDialog</u></b>
38 * <p>
39 * Dialog box for collecting session creation information.
40 * </p>
41 */
42public class CreateSessionDialog extends Dialog implements ICreateSessionDialog {
43
44 // ------------------------------------------------------------------------
45 // Constants
46 // ------------------------------------------------------------------------
47 /**
48 * The icon file for this dialog box.
49 */
50 public static final String CREATE_SESSION_ICON_FILE = "icons/elcl16/add_button.gif"; //$NON-NLS-1$
51
52 // ------------------------------------------------------------------------
53 // Attributes
54 // ------------------------------------------------------------------------
55 /**
56 * The dialog composite.
57 */
58 private Composite fDialogComposite = null;
59 /**
60 * The text widget for the session name
61 */
62 private Text fSessionNameText = null;
63 /**
64 * The text widget for the session path
65 */
66 private Text fSessionPathText = null;
67 /**
68 * The parent where the new node should be added.
69 */
c56972bb 70 private TraceSessionGroup fParent = null;
bbb3538a
BH
71 /**
72 * The session name string.
73 */
74 private String fSessionName = null;
75 /**
76 * The session path string.
77 */
78 private String fSessionPath = null;
79 /**
80 * Flag whether default location (path) shall be used or not
81 */
82 private boolean fIsDefaultPath = true;
83
84 // ------------------------------------------------------------------------
85 // Constructors
86 // ------------------------------------------------------------------------
87 /**
88 * Constructor
89 * @param shell - a shell for the display of the dialog
bbb3538a 90 */
d132bcc7 91 public CreateSessionDialog(Shell shell) {
bbb3538a 92 super(shell);
5f1f22f8 93 setShellStyle(SWT.RESIZE);
bbb3538a
BH
94 }
95
96 // ------------------------------------------------------------------------
97 // Accessors
98 // ------------------------------------------------------------------------
99 /*
100 * (non-Javadoc)
115b4a01 101 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.dialogs.ICreateSessionDialog#getSessionName()
bbb3538a
BH
102 */
103 @Override
104 public String getSessionName() {
105 return fSessionName;
106 }
107
108 /*
109 * (non-Javadoc)
115b4a01 110 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.dialogs.ICreateSessionDialog#getSessionPath()
bbb3538a
BH
111 */
112 @Override
113 public String getSessionPath() {
114 return fSessionPath;
115 }
116
117 /*
118 * (non-Javadoc)
115b4a01 119 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.dialogs.ICreateSessionDialog#isDefaultSessionPath()
bbb3538a
BH
120 */
121 @Override
122 public boolean isDefaultSessionPath() {
123 return fIsDefaultPath;
124 }
125
d132bcc7
BH
126 /*
127 * (non-Javadoc)
115b4a01 128 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.dialogs.ICreateSessionDialog#setTraceSessionGroup(org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TraceSessionGroup)
d132bcc7
BH
129 */
130 @Override
131 public void setTraceSessionGroup(TraceSessionGroup group) {
132 fParent = group;
133 }
134
bbb3538a
BH
135 // ------------------------------------------------------------------------
136 // Operations
137 // ------------------------------------------------------------------------
138 /*
139 * (non-Javadoc)
140 * @see org.eclipse.jface.window.Window#configureShell(org.eclipse.swt.widgets.Shell)
141 */
142 @Override
143 protected void configureShell(Shell newShell) {
144 super.configureShell(newShell);
145 newShell.setText(Messages.TraceControl_CreateSessionDialogTitle);
31a6a4e4 146 newShell.setImage(Activator.getDefault().loadIcon(CREATE_SESSION_ICON_FILE));
bbb3538a
BH
147 }
148
149 /*
150 * (non-Javadoc)
151 * @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite)
152 */
153 @Override
154 protected Control createDialogArea(Composite parent) {
155
156 // Main dialog panel
157 fDialogComposite = new Composite(parent, SWT.NONE);
5f1f22f8
BH
158 GridLayout layout = new GridLayout(4, true);
159 fDialogComposite.setLayout(layout);
160 fDialogComposite.setLayoutData(new GridData(GridData.FILL_BOTH));
bbb3538a
BH
161
162 Label sessionNameLabel = new Label(fDialogComposite, SWT.RIGHT);
163 sessionNameLabel.setText(Messages.TraceControl_CreateSessionNameLabel);
164 fSessionNameText = new Text(fDialogComposite, SWT.NONE);
165 fSessionNameText.setToolTipText(Messages.TraceControl_CreateSessionNameTooltip);
166
167 Label sessionPath = new Label(fDialogComposite, SWT.RIGHT);
168 sessionPath.setText(Messages.TraceControl_CreateSessionPathLabel);
169 fSessionPathText = new Text(fDialogComposite, SWT.NONE);
170 fSessionPathText.setToolTipText(Messages.TraceControl_CreateSessionPathTooltip);
171
172 // layout widgets
5f1f22f8
BH
173 GridData data = new GridData(GridData.FILL_HORIZONTAL);
174 data.horizontalSpan = 3;
bbb3538a
BH
175
176 fSessionNameText.setLayoutData(data);
177 fSessionPathText.setLayoutData(data);
bbb3538a 178
5f1f22f8
BH
179 getShell().setMinimumSize(new Point(300, 150));
180
bbb3538a
BH
181 return fDialogComposite;
182 }
183
184 /*
185 * (non-Javadoc)
186 * @see org.eclipse.jface.dialogs.Dialog#createButtonsForButtonBar(org.eclipse.swt.widgets.Composite)
187 */
188 @Override
189 protected void createButtonsForButtonBar(Composite parent) {
190 createButton(parent, IDialogConstants.OK_ID, "&Ok", true); //$NON-NLS-1$
191 }
192
193 /*
194 * (non-Javadoc)
195 * @see org.eclipse.jface.dialogs.Dialog#okPressed()
196 */
197 @Override
198 protected void okPressed() {
199 // Validate input data
200 fSessionName = fSessionNameText.getText();
201 fSessionPath = fSessionPathText.getText();
202
203 if (!"".equals(fSessionPath)) { //$NON-NLS-1$
204 // validate sessionPath
205
206 TargetNodeComponent node = (TargetNodeComponent)fParent.getParent();
207 IRemoteSystemProxy proxy = node.getRemoteSystemProxy();
208 IFileServiceSubSystem fsss = proxy.getFileServiceSubSystem();
209 if (fsss != null) {
210 try {
211 IRemoteFile remoteFolder = fsss.getRemoteFileObject(fSessionPath, new NullProgressMonitor());
212 if (remoteFolder.exists()) {
213 MessageDialog.openError(getShell(),
214 Messages.TraceControl_CreateSessionDialogTitle,
215 Messages.TraceControl_SessionPathAlreadyExistsError + " (" + fSessionPath + ") \n"); //$NON-NLS-1$ //$NON-NLS-2$
216 return;
217 }
218 } catch (SystemMessageException e) {
219 MessageDialog.openError(getShell(),
220 Messages.TraceControl_CreateSessionDialogTitle,
221 Messages.TraceControl_FileSubSystemError + "\n" + e); //$NON-NLS-1$
222 return;
223 }
224 }
225 fIsDefaultPath = false;
226 }
227
228 // If no session name is specified use default name auto
229 if ("".equals(fSessionName)) { //$NON-NLS-1$
230 fSessionName = "auto"; //$NON-NLS-1$
231 }
232
233 // Check for invalid names
498704b3 234 if (!fSessionName.matches("^[a-zA-Z0-9\\-\\_]{1,}$")) { //$NON-NLS-1$
bbb3538a
BH
235 MessageDialog.openError(getShell(),
236 Messages.TraceControl_CreateSessionDialogTitle,
237 Messages.TraceControl_InvalidSessionNameError + " (" + fSessionName + ") \n"); //$NON-NLS-1$ //$NON-NLS-2$
238 return;
239 }
240
241 // Check if node with name already exists in parent
242 if(fParent.containsChild(fSessionName)) {
243 MessageDialog.openError(getShell(),
244 Messages.TraceControl_CreateSessionDialogTitle,
245 Messages.TraceControl_SessionAlreadyExistsError + " (" + fSessionName + ")"); //$NON-NLS-1$ //$NON-NLS-2$
246 return;
247 }
248
249 // validation successful -> call super.okPressed()
250 super.okPressed();
251 }
252}
This page took 0.03568 seconds and 5 git commands to generate.