Add further support for enabling kernel events
[deliverable/tracecompass.git] / org.eclipse.linuxtools.lttng.ui / src / org / eclipse / linuxtools / lttng / ui / views / control / dialogs / CreateSessionDialog.java
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 **********************************************************************/
12 package org.eclipse.linuxtools.lttng.ui.views.control.dialogs;
13
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.lttng.ui.LTTngUiPlugin;
19 import org.eclipse.linuxtools.lttng.ui.views.control.Messages;
20 import org.eclipse.linuxtools.lttng.ui.views.control.model.impl.TargetNodeComponent;
21 import org.eclipse.linuxtools.lttng.ui.views.control.model.impl.TraceSessionGroup;
22 import org.eclipse.linuxtools.lttng.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;
35
36 /**
37 * <b><u>CreateSessionDialog</u></b>
38 * <p>
39 * Dialog box for collecting session creation information.
40 * </p>
41 */
42 public 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 */
70 private TraceSessionGroup fParent;
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
90 * @param parent - trace control parent for validation of session name
91 */
92 public CreateSessionDialog(Shell shell, TraceSessionGroup parent) {
93 super(shell);
94 fParent = parent;
95 }
96
97 // ------------------------------------------------------------------------
98 // Accessors
99 // ------------------------------------------------------------------------
100 /*
101 * (non-Javadoc)
102 * @see org.eclipse.linuxtools.lttng.ui.views.control.dialogs.ICreateSessionDialog#getSessionName()
103 */
104 @Override
105 public String getSessionName() {
106 return fSessionName;
107 }
108
109 /*
110 * (non-Javadoc)
111 * @see org.eclipse.linuxtools.lttng.ui.views.control.dialogs.ICreateSessionDialog#getSessionPath()
112 */
113 @Override
114 public String getSessionPath() {
115 return fSessionPath;
116 }
117
118 /*
119 * (non-Javadoc)
120 * @see org.eclipse.linuxtools.lttng.ui.views.control.dialogs.ICreateSessionDialog#isDefaultSessionPath()
121 */
122 @Override
123 public boolean isDefaultSessionPath() {
124 return fIsDefaultPath;
125 }
126
127 // ------------------------------------------------------------------------
128 // Operations
129 // ------------------------------------------------------------------------
130 /*
131 * (non-Javadoc)
132 * @see org.eclipse.jface.window.Window#configureShell(org.eclipse.swt.widgets.Shell)
133 */
134 @Override
135 protected void configureShell(Shell newShell) {
136 super.configureShell(newShell);
137 newShell.setText(Messages.TraceControl_CreateSessionDialogTitle);
138 newShell.setImage(LTTngUiPlugin.getDefault().loadIcon(CREATE_SESSION_ICON_FILE));
139 }
140
141 /*
142 * (non-Javadoc)
143 * @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite)
144 */
145 @Override
146 protected Control createDialogArea(Composite parent) {
147
148 // Main dialog panel
149 fDialogComposite = new Composite(parent, SWT.NONE);
150 GridLayout layout = new GridLayout(2, true);
151 fDialogComposite.setLayout(layout);
152
153 Label sessionNameLabel = new Label(fDialogComposite, SWT.RIGHT);
154 sessionNameLabel.setText(Messages.TraceControl_CreateSessionNameLabel);
155 fSessionNameText = new Text(fDialogComposite, SWT.NONE);
156 fSessionNameText.setToolTipText(Messages.TraceControl_CreateSessionNameTooltip);
157
158 Label sessionPath = new Label(fDialogComposite, SWT.RIGHT);
159 sessionPath.setText(Messages.TraceControl_CreateSessionPathLabel);
160 fSessionPathText = new Text(fDialogComposite, SWT.NONE);
161 fSessionPathText.setToolTipText(Messages.TraceControl_CreateSessionPathTooltip);
162
163 // layout widgets
164 GridData data = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
165 fSessionPathText.setText("666.666.666.666"); //$NON-NLS-1$
166 Point minSize = fSessionPathText.computeSize(SWT.DEFAULT, SWT.DEFAULT, true);
167 data.widthHint = minSize.x + 5;
168
169 fSessionNameText.setLayoutData(data);
170 fSessionPathText.setLayoutData(data);
171
172 fSessionPathText.setText(""); //$NON-NLS-1$
173
174 return fDialogComposite;
175 }
176
177 /*
178 * (non-Javadoc)
179 * @see org.eclipse.jface.dialogs.Dialog#createButtonsForButtonBar(org.eclipse.swt.widgets.Composite)
180 */
181 @Override
182 protected void createButtonsForButtonBar(Composite parent) {
183 createButton(parent, IDialogConstants.OK_ID, "&Ok", true); //$NON-NLS-1$
184 }
185
186 /*
187 * (non-Javadoc)
188 * @see org.eclipse.jface.dialogs.Dialog#okPressed()
189 */
190 @Override
191 protected void okPressed() {
192 // Validate input data
193 fSessionName = fSessionNameText.getText();
194 fSessionPath = fSessionPathText.getText();
195
196 if (!"".equals(fSessionPath)) { //$NON-NLS-1$
197 // validate sessionPath
198
199 TargetNodeComponent node = (TargetNodeComponent)fParent.getParent();
200 IRemoteSystemProxy proxy = node.getRemoteSystemProxy();
201 IFileServiceSubSystem fsss = proxy.getFileServiceSubSystem();
202 if (fsss != null) {
203 try {
204 IRemoteFile remoteFolder = fsss.getRemoteFileObject(fSessionPath, new NullProgressMonitor());
205 if (remoteFolder.exists()) {
206 MessageDialog.openError(getShell(),
207 Messages.TraceControl_CreateSessionDialogTitle,
208 Messages.TraceControl_SessionPathAlreadyExistsError + " (" + fSessionPath + ") \n"); //$NON-NLS-1$ //$NON-NLS-2$
209 return;
210 }
211 } catch (SystemMessageException e) {
212 MessageDialog.openError(getShell(),
213 Messages.TraceControl_CreateSessionDialogTitle,
214 Messages.TraceControl_FileSubSystemError + "\n" + e); //$NON-NLS-1$
215 return;
216 }
217 }
218 fIsDefaultPath = false;
219 }
220
221 // If no session name is specified use default name auto
222 if ("".equals(fSessionName)) { //$NON-NLS-1$
223 fSessionName = "auto"; //$NON-NLS-1$
224 }
225
226 // Check for invalid names
227 if (!fSessionName.matches("^[a-zA-Z0-9\\-\\_]{1,}$")) { //$NON-NLS-1$
228 MessageDialog.openError(getShell(),
229 Messages.TraceControl_CreateSessionDialogTitle,
230 Messages.TraceControl_InvalidSessionNameError + " (" + fSessionName + ") \n"); //$NON-NLS-1$ //$NON-NLS-2$
231 return;
232 }
233
234 // Check if node with name already exists in parent
235 if(fParent.containsChild(fSessionName)) {
236 MessageDialog.openError(getShell(),
237 Messages.TraceControl_CreateSessionDialogTitle,
238 Messages.TraceControl_SessionAlreadyExistsError + " (" + fSessionName + ")"); //$NON-NLS-1$ //$NON-NLS-2$
239 return;
240 }
241
242 // validation successful -> call super.okPressed()
243 super.okPressed();
244 }
245 }
This page took 0.036217 seconds and 5 git commands to generate.