1 /**********************************************************************
2 * Copyright (c) 2012 Ericsson
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
10 * Bernd Hufmann - Initial API and implementation
11 **********************************************************************/
12 package org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.dialogs
;
14 import org
.eclipse
.core
.runtime
.NullProgressMonitor
;
15 import org
.eclipse
.jface
.dialogs
.Dialog
;
16 import org
.eclipse
.jface
.dialogs
.IDialogConstants
;
17 import org
.eclipse
.jface
.dialogs
.MessageDialog
;
18 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.Activator
;
19 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.Messages
;
20 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.model
.impl
.TargetNodeComponent
;
21 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.model
.impl
.TraceSessionGroup
;
22 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.remote
.IRemoteSystemProxy
;
23 import org
.eclipse
.rse
.services
.clientserver
.messages
.SystemMessageException
;
24 import org
.eclipse
.rse
.subsystems
.files
.core
.servicesubsystem
.IFileServiceSubSystem
;
25 import org
.eclipse
.rse
.subsystems
.files
.core
.subsystems
.IRemoteFile
;
26 import org
.eclipse
.swt
.SWT
;
27 import org
.eclipse
.swt
.graphics
.Point
;
28 import org
.eclipse
.swt
.layout
.GridData
;
29 import org
.eclipse
.swt
.layout
.GridLayout
;
30 import org
.eclipse
.swt
.widgets
.Composite
;
31 import org
.eclipse
.swt
.widgets
.Control
;
32 import org
.eclipse
.swt
.widgets
.Label
;
33 import org
.eclipse
.swt
.widgets
.Shell
;
34 import org
.eclipse
.swt
.widgets
.Text
;
37 * <b><u>CreateSessionDialog</u></b>
39 * Dialog box for collecting session creation information.
42 public class CreateSessionDialog
extends Dialog
implements ICreateSessionDialog
{
44 // ------------------------------------------------------------------------
46 // ------------------------------------------------------------------------
48 * The icon file for this dialog box.
50 public static final String CREATE_SESSION_ICON_FILE
= "icons/elcl16/add_button.gif"; //$NON-NLS-1$
52 // ------------------------------------------------------------------------
54 // ------------------------------------------------------------------------
56 * The dialog composite.
58 private Composite fDialogComposite
= null;
60 * The text widget for the session name
62 private Text fSessionNameText
= null;
64 * The text widget for the session path
66 private Text fSessionPathText
= null;
68 * The parent where the new node should be added.
70 private TraceSessionGroup fParent
= null;
72 * The session name string.
74 private String fSessionName
= null;
76 * The session path string.
78 private String fSessionPath
= null;
80 * Flag whether default location (path) shall be used or not
82 private boolean fIsDefaultPath
= true;
84 // ------------------------------------------------------------------------
86 // ------------------------------------------------------------------------
89 * @param shell - a shell for the display of the dialog
91 public CreateSessionDialog(Shell shell
) {
93 setShellStyle(SWT
.RESIZE
);
96 // ------------------------------------------------------------------------
98 // ------------------------------------------------------------------------
101 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.dialogs.ICreateSessionDialog#getSessionName()
104 public String
getSessionName() {
110 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.dialogs.ICreateSessionDialog#getSessionPath()
113 public String
getSessionPath() {
119 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.dialogs.ICreateSessionDialog#isDefaultSessionPath()
122 public boolean isDefaultSessionPath() {
123 return fIsDefaultPath
;
128 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.dialogs.ICreateSessionDialog#setTraceSessionGroup(org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TraceSessionGroup)
131 public void setTraceSessionGroup(TraceSessionGroup group
) {
135 // ------------------------------------------------------------------------
137 // ------------------------------------------------------------------------
140 * @see org.eclipse.jface.window.Window#configureShell(org.eclipse.swt.widgets.Shell)
143 protected void configureShell(Shell newShell
) {
144 super.configureShell(newShell
);
145 newShell
.setText(Messages
.TraceControl_CreateSessionDialogTitle
);
146 newShell
.setImage(Activator
.getDefault().loadIcon(CREATE_SESSION_ICON_FILE
));
151 * @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite)
154 protected Control
createDialogArea(Composite parent
) {
157 fDialogComposite
= new Composite(parent
, SWT
.NONE
);
158 GridLayout layout
= new GridLayout(4, true);
159 fDialogComposite
.setLayout(layout
);
160 fDialogComposite
.setLayoutData(new GridData(GridData
.FILL_BOTH
));
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
);
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
);
173 GridData data
= new GridData(GridData
.FILL_HORIZONTAL
);
174 data
.horizontalSpan
= 3;
176 fSessionNameText
.setLayoutData(data
);
177 fSessionPathText
.setLayoutData(data
);
179 getShell().setMinimumSize(new Point(300, 150));
181 return fDialogComposite
;
186 * @see org.eclipse.jface.dialogs.Dialog#createButtonsForButtonBar(org.eclipse.swt.widgets.Composite)
189 protected void createButtonsForButtonBar(Composite parent
) {
190 createButton(parent
, IDialogConstants
.CANCEL_ID
, "&Cancel", true); //$NON-NLS-1$
191 createButton(parent
, IDialogConstants
.OK_ID
, "&Ok", true); //$NON-NLS-1$
196 * @see org.eclipse.jface.dialogs.Dialog#okPressed()
199 protected void okPressed() {
200 // Validate input data
201 fSessionName
= fSessionNameText
.getText();
202 fSessionPath
= fSessionPathText
.getText();
204 if (!"".equals(fSessionPath
)) { //$NON-NLS-1$
205 // validate sessionPath
207 TargetNodeComponent node
= (TargetNodeComponent
)fParent
.getParent();
208 IRemoteSystemProxy proxy
= node
.getRemoteSystemProxy();
209 IFileServiceSubSystem fsss
= proxy
.getFileServiceSubSystem();
212 IRemoteFile remoteFolder
= fsss
.getRemoteFileObject(fSessionPath
, new NullProgressMonitor());
213 if (remoteFolder
.exists()) {
214 MessageDialog
.openError(getShell(),
215 Messages
.TraceControl_CreateSessionDialogTitle
,
216 Messages
.TraceControl_SessionPathAlreadyExistsError
+ " (" + fSessionPath
+ ") \n"); //$NON-NLS-1$ //$NON-NLS-2$
219 } catch (SystemMessageException e
) {
220 MessageDialog
.openError(getShell(),
221 Messages
.TraceControl_CreateSessionDialogTitle
,
222 Messages
.TraceControl_FileSubSystemError
+ "\n" + e
); //$NON-NLS-1$
226 fIsDefaultPath
= false;
229 // If no session name is specified use default name auto
230 if ("".equals(fSessionName
)) { //$NON-NLS-1$
231 fSessionName
= "auto"; //$NON-NLS-1$
234 // Check for invalid names
235 if (!fSessionName
.matches("^[a-zA-Z0-9\\-\\_]{1,}$")) { //$NON-NLS-1$
236 MessageDialog
.openError(getShell(),
237 Messages
.TraceControl_CreateSessionDialogTitle
,
238 Messages
.TraceControl_InvalidSessionNameError
+ " (" + fSessionName
+ ") \n"); //$NON-NLS-1$ //$NON-NLS-2$
242 // Check if node with name already exists in parent
243 if(fParent
.containsChild(fSessionName
)) {
244 MessageDialog
.openError(getShell(),
245 Messages
.TraceControl_CreateSessionDialogTitle
,
246 Messages
.TraceControl_SessionAlreadyExistsError
+ " (" + fSessionName
+ ")"); //$NON-NLS-1$ //$NON-NLS-2$
250 // validation successful -> call super.okPressed()