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