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 BH |
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; | |
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 | /** | |
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 | */ | |
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); |
bbb3538a BH |
93 | } |
94 | ||
95 | // ------------------------------------------------------------------------ | |
96 | // Accessors | |
97 | // ------------------------------------------------------------------------ | |
98 | /* | |
99 | * (non-Javadoc) | |
115b4a01 | 100 | * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.dialogs.ICreateSessionDialog#getSessionName() |
bbb3538a BH |
101 | */ |
102 | @Override | |
103 | public String getSessionName() { | |
104 | return fSessionName; | |
105 | } | |
106 | ||
107 | /* | |
108 | * (non-Javadoc) | |
115b4a01 | 109 | * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.dialogs.ICreateSessionDialog#getSessionPath() |
bbb3538a BH |
110 | */ |
111 | @Override | |
112 | public String getSessionPath() { | |
113 | return fSessionPath; | |
114 | } | |
115 | ||
116 | /* | |
117 | * (non-Javadoc) | |
115b4a01 | 118 | * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.dialogs.ICreateSessionDialog#isDefaultSessionPath() |
bbb3538a BH |
119 | */ |
120 | @Override | |
121 | public boolean isDefaultSessionPath() { | |
122 | return fIsDefaultPath; | |
123 | } | |
124 | ||
d132bcc7 BH |
125 | /* |
126 | * (non-Javadoc) | |
115b4a01 | 127 | * @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 |
128 | */ |
129 | @Override | |
130 | public void setTraceSessionGroup(TraceSessionGroup group) { | |
131 | fParent = group; | |
132 | } | |
133 | ||
bbb3538a BH |
134 | // ------------------------------------------------------------------------ |
135 | // Operations | |
136 | // ------------------------------------------------------------------------ | |
137 | /* | |
138 | * (non-Javadoc) | |
139 | * @see org.eclipse.jface.window.Window#configureShell(org.eclipse.swt.widgets.Shell) | |
140 | */ | |
141 | @Override | |
142 | protected void configureShell(Shell newShell) { | |
143 | super.configureShell(newShell); | |
144 | newShell.setText(Messages.TraceControl_CreateSessionDialogTitle); | |
31a6a4e4 | 145 | newShell.setImage(Activator.getDefault().loadIcon(CREATE_SESSION_ICON_FILE)); |
bbb3538a BH |
146 | } |
147 | ||
148 | /* | |
149 | * (non-Javadoc) | |
150 | * @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite) | |
151 | */ | |
152 | @Override | |
153 | protected Control createDialogArea(Composite parent) { | |
154 | ||
155 | // Main dialog panel | |
156 | fDialogComposite = new Composite(parent, SWT.NONE); | |
157 | GridLayout layout = new GridLayout(2, true); | |
158 | fDialogComposite.setLayout(layout); | |
159 | ||
160 | Label sessionNameLabel = new Label(fDialogComposite, SWT.RIGHT); | |
161 | sessionNameLabel.setText(Messages.TraceControl_CreateSessionNameLabel); | |
162 | fSessionNameText = new Text(fDialogComposite, SWT.NONE); | |
163 | fSessionNameText.setToolTipText(Messages.TraceControl_CreateSessionNameTooltip); | |
164 | ||
165 | Label sessionPath = new Label(fDialogComposite, SWT.RIGHT); | |
166 | sessionPath.setText(Messages.TraceControl_CreateSessionPathLabel); | |
167 | fSessionPathText = new Text(fDialogComposite, SWT.NONE); | |
168 | fSessionPathText.setToolTipText(Messages.TraceControl_CreateSessionPathTooltip); | |
169 | ||
170 | // layout widgets | |
171 | GridData data = new GridData(GridData.HORIZONTAL_ALIGN_FILL); | |
172 | fSessionPathText.setText("666.666.666.666"); //$NON-NLS-1$ | |
173 | Point minSize = fSessionPathText.computeSize(SWT.DEFAULT, SWT.DEFAULT, true); | |
174 | data.widthHint = minSize.x + 5; | |
175 | ||
176 | fSessionNameText.setLayoutData(data); | |
177 | fSessionPathText.setLayoutData(data); | |
178 | ||
179 | fSessionPathText.setText(""); //$NON-NLS-1$ | |
180 | ||
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 | } |