Commit | Line | Data |
---|---|---|
002f9f07 | 1 | /******************************************************************************* |
45fc1883 | 2 | * Copyright (c) 2009, 2016 Ericsson and others. |
002f9f07 BH |
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 | * Francois Chouinard - Initial API and implementation | |
11 | * Francois Chouinard - Got rid of dependency on internal platform class | |
12 | * Francois Chouinard - Complete re-design | |
13 | * Anna Dushistova(Montavista) - [383047] NPE while importing a CFT trace | |
14 | * Matthew Khouzam - Moved out some common functions | |
15 | * Patrick Tasse - Add sorting of file system elements | |
252c602c | 16 | * Bernd Hufmann - Re-design of trace selection and trace validation |
0e1d517e | 17 | * Marc-Andre Laperle - Preserve folder structure on import |
480e9739 | 18 | * Marc-Andre Laperle - Extract archives during import |
7c62be2f | 19 | * Marc-Andre Laperle - Add support for Gzip (non-Tar) |
002f9f07 BH |
20 | *******************************************************************************/ |
21 | ||
2bdf0193 | 22 | package org.eclipse.tracecompass.internal.tmf.ui.project.wizards.importtrace; |
002f9f07 BH |
23 | |
24 | import java.io.File; | |
002f9f07 | 25 | import java.lang.reflect.InvocationTargetException; |
45fc1883 | 26 | import java.util.ArrayList; |
29ceb238 | 27 | import java.util.Collection; |
480e9739 | 28 | import java.util.LinkedList; |
002f9f07 | 29 | import java.util.List; |
002f9f07 BH |
30 | |
31 | import org.eclipse.core.resources.IContainer; | |
32 | import org.eclipse.core.resources.IFolder; | |
33 | import org.eclipse.core.resources.IProject; | |
45fc1883 BH |
34 | import org.eclipse.core.resources.IResource; |
35 | import org.eclipse.core.resources.IWorkspace; | |
002f9f07 BH |
36 | import org.eclipse.core.resources.ResourcesPlugin; |
37 | import org.eclipse.core.runtime.CoreException; | |
38 | import org.eclipse.core.runtime.IPath; | |
252c602c | 39 | import org.eclipse.core.runtime.IProgressMonitor; |
002f9f07 | 40 | import org.eclipse.core.runtime.IStatus; |
252c602c | 41 | import org.eclipse.core.runtime.NullProgressMonitor; |
002f9f07 BH |
42 | import org.eclipse.core.runtime.Path; |
43 | import org.eclipse.core.runtime.Platform; | |
252c602c BH |
44 | import org.eclipse.core.runtime.Status; |
45 | import org.eclipse.core.runtime.SubMonitor; | |
252c602c | 46 | import org.eclipse.jface.dialogs.IDialogSettings; |
c8cf44dc | 47 | import org.eclipse.jface.layout.PixelConverter; |
252c602c | 48 | import org.eclipse.jface.operation.IRunnableWithProgress; |
282218e9 MAL |
49 | import org.eclipse.jface.viewers.CheckStateChangedEvent; |
50 | import org.eclipse.jface.viewers.ICheckStateListener; | |
002f9f07 BH |
51 | import org.eclipse.jface.viewers.IStructuredSelection; |
52 | import org.eclipse.jface.viewers.ITreeContentProvider; | |
45fc1883 | 53 | import org.eclipse.osgi.util.NLS; |
002f9f07 BH |
54 | import org.eclipse.swt.SWT; |
55 | import org.eclipse.swt.custom.BusyIndicator; | |
c8cf44dc | 56 | import org.eclipse.swt.events.FocusAdapter; |
002f9f07 | 57 | import org.eclipse.swt.events.FocusEvent; |
2f7b3dd7 BH |
58 | import org.eclipse.swt.events.ModifyEvent; |
59 | import org.eclipse.swt.events.ModifyListener; | |
002f9f07 BH |
60 | import org.eclipse.swt.events.SelectionAdapter; |
61 | import org.eclipse.swt.events.SelectionEvent; | |
c8cf44dc MAL |
62 | import org.eclipse.swt.events.TraverseEvent; |
63 | import org.eclipse.swt.events.TraverseListener; | |
002f9f07 BH |
64 | import org.eclipse.swt.layout.GridData; |
65 | import org.eclipse.swt.layout.GridLayout; | |
66 | import org.eclipse.swt.widgets.Button; | |
67 | import org.eclipse.swt.widgets.Combo; | |
68 | import org.eclipse.swt.widgets.Composite; | |
69 | import org.eclipse.swt.widgets.DirectoryDialog; | |
70 | import org.eclipse.swt.widgets.Event; | |
c8cf44dc | 71 | import org.eclipse.swt.widgets.FileDialog; |
002f9f07 BH |
72 | import org.eclipse.swt.widgets.Group; |
73 | import org.eclipse.swt.widgets.Label; | |
45fc1883 | 74 | import org.eclipse.swt.widgets.Text; |
2bdf0193 | 75 | import org.eclipse.tracecompass.internal.tmf.ui.Activator; |
45fc1883 BH |
76 | import org.eclipse.tracecompass.internal.tmf.ui.project.operations.NewExperimentOperation; |
77 | import org.eclipse.tracecompass.internal.tmf.ui.project.operations.SelectTracesOperation; | |
2bdf0193 AM |
78 | import org.eclipse.tracecompass.tmf.core.TmfCommonConstants; |
79 | import org.eclipse.tracecompass.tmf.core.TmfProjectNature; | |
2bdf0193 | 80 | import org.eclipse.tracecompass.tmf.core.project.model.TmfTraceType; |
480e9739 | 81 | import org.eclipse.tracecompass.tmf.core.util.Pair; |
45fc1883 BH |
82 | import org.eclipse.tracecompass.tmf.ui.project.model.TmfExperimentElement; |
83 | import org.eclipse.tracecompass.tmf.ui.project.model.TmfExperimentFolder; | |
2bdf0193 AM |
84 | import org.eclipse.tracecompass.tmf.ui.project.model.TmfProjectElement; |
85 | import org.eclipse.tracecompass.tmf.ui.project.model.TmfProjectRegistry; | |
2bdf0193 | 86 | import org.eclipse.tracecompass.tmf.ui.project.model.TmfTraceFolder; |
2bdf0193 | 87 | import org.eclipse.tracecompass.tmf.ui.project.model.TmfTracesFolder; |
002f9f07 BH |
88 | import org.eclipse.ui.dialogs.FileSystemElement; |
89 | import org.eclipse.ui.dialogs.WizardResourceImportPage; | |
f17bb886 | 90 | import org.eclipse.ui.ide.dialogs.IElementFilter; |
73487f4b | 91 | import org.eclipse.ui.ide.dialogs.ResourceTreeAndListGroup; |
282218e9 | 92 | import org.eclipse.ui.internal.ide.DialogUtil; |
002f9f07 | 93 | import org.eclipse.ui.model.WorkbenchContentProvider; |
282218e9 MAL |
94 | import org.eclipse.ui.model.WorkbenchLabelProvider; |
95 | import org.eclipse.ui.model.WorkbenchViewerComparator; | |
002f9f07 BH |
96 | |
97 | /** | |
ba560b10 MK |
98 | * A variant of the standard resource import wizard for importing traces to |
99 | * given tracing project. If no project or tracing project was selected the | |
100 | * wizard imports it to the default tracing project which is created if | |
101 | * necessary. | |
252c602c BH |
102 | * |
103 | * In our case traces could be files or a directory structure. This wizard | |
ba560b10 MK |
104 | * supports both cases. It imports traces for a selected trace type or, if no |
105 | * trace type is selected, it tries to detect the trace type automatically. | |
106 | * However, the automatic detection is a best-effort and cannot guarantee that | |
107 | * the detection is successful. The reason for this is that there might be | |
108 | * multiple trace types that can be assigned to a single trace. | |
252c602c | 109 | * |
002f9f07 | 110 | * |
002f9f07 | 111 | * @author Francois Chouinard |
002f9f07 | 112 | */ |
29ceb238 | 113 | @SuppressWarnings("restriction") |
002f9f07 BH |
114 | public class ImportTraceWizardPage extends WizardResourceImportPage { |
115 | ||
002f9f07 BH |
116 | // ------------------------------------------------------------------------ |
117 | // Constants | |
118 | // ------------------------------------------------------------------------ | |
d0e34947 | 119 | private static final String IMPORT_WIZARD_PAGE_NAME = "ImportTraceWizardPage"; //$NON-NLS-1$ |
45fc1883 | 120 | private static final String IMPORT_WIZARD_ROOT_DIRECTORY_ID = ".import_root_directory_id"; //$NON-NLS-1$ ; |
d0e34947 MAL |
121 | private static final String IMPORT_WIZARD_ARCHIVE_FILE_NAME_ID = ".import_archive_file_name_id"; //$NON-NLS-1$ |
122 | private static final String IMPORT_WIZARD_IMPORT_UNRECOGNIZED_ID = ".import_unrecognized_traces_id"; //$NON-NLS-1$ | |
123 | private static final String IMPORT_WIZARD_PRESERVE_FOLDERS_ID = ".import_preserve_folders_id"; //$NON-NLS-1$ | |
124 | private static final String IMPORT_WIZARD_IMPORT_FROM_DIRECTORY_ID = ".import_from_directory"; //$NON-NLS-1$ | |
45fc1883 | 125 | private static final String IMPORT_WIZARD_CREATE_EXPERIMENT_ID = ".create_experiment"; //$NON-NLS-1$ |
002f9f07 | 126 | |
c8cf44dc | 127 | // constant from WizardArchiveFileResourceImportPage1 |
7c62be2f | 128 | private static final String[] FILE_IMPORT_MASK = { "*.jar;*.zip;*.tar;*.tar.gz;*.tgz;*.gz", "*.*" }; //$NON-NLS-1$ //$NON-NLS-2$ |
c8cf44dc | 129 | |
d0e34947 MAL |
130 | /** |
131 | * A special trace type value to communicate that automatic trace type | |
132 | * detection will occur instead of setting a specific trace type when | |
133 | * importing the traces. | |
134 | */ | |
9b3f4afe | 135 | public static final String TRACE_TYPE_AUTO_DETECT = Messages.ImportTraceWizard_AutoDetection; |
d0e34947 MAL |
136 | |
137 | /** | |
138 | * Preserve the folder structure of the import traces. | |
139 | */ | |
9b3f4afe | 140 | public static final int OPTION_PRESERVE_FOLDER_STRUCTURE = 1 << 1; |
d0e34947 MAL |
141 | /** |
142 | * Create links to the trace files instead of copies. | |
143 | */ | |
9b3f4afe | 144 | public static final int OPTION_CREATE_LINKS_IN_WORKSPACE = 1 << 2; |
d0e34947 MAL |
145 | /** |
146 | * Import files that were not recognized as the selected trace type. | |
147 | */ | |
9b3f4afe | 148 | public static final int OPTION_IMPORT_UNRECOGNIZED_TRACES = 1 << 3; |
d0e34947 MAL |
149 | /** |
150 | * Overwrite existing resources without prompting. | |
151 | */ | |
9b3f4afe | 152 | public static final int OPTION_OVERWRITE_EXISTING_RESOURCES = 1 << 4; |
45fc1883 BH |
153 | /** |
154 | * Create an experiment with imported traces. | |
155 | */ | |
156 | public static final int OPTION_CREATE_EXPERIMENT = 1 << 5; | |
d0e34947 | 157 | |
002f9f07 BH |
158 | // ------------------------------------------------------------------------ |
159 | // Attributes | |
160 | // ------------------------------------------------------------------------ | |
161 | ||
002f9f07 BH |
162 | // Target import directory ('Traces' folder) |
163 | private IFolder fTargetFolder; | |
16f91bd5 BH |
164 | // Target Trace folder element |
165 | private TmfTraceFolder fTraceFolderElement; | |
45fc1883 BH |
166 | // The workspace experiment folder |
167 | private TmfExperimentFolder fExperimentFolderElement; | |
168 | private String fPreviousSource; | |
252c602c BH |
169 | // Flag to handle destination folder change event |
170 | private Boolean fIsDestinationChanged = false; | |
28abf18d | 171 | private final Object fSyncObject = new Object(); |
252c602c BH |
172 | // Combo box containing trace types |
173 | private Combo fTraceTypes; | |
174 | // Button to ignore unrecognized traces or not | |
175 | private Button fImportUnrecognizedButton; | |
176 | // Button to overwrite existing resources or not | |
177 | private Button fOverwriteExistingResourcesCheckbox; | |
178 | // Button to link or copy traces to workspace | |
179 | private Button fCreateLinksInWorkspaceButton; | |
0e1d517e MAL |
180 | // Button to preserve folder structure |
181 | private Button fPreserveFolderStructureButton; | |
45fc1883 BH |
182 | // Button to create an experiment |
183 | private Button fCreateExperimentCheckbox; | |
184 | // Text box for experiment name | |
185 | private Text fExperimentNameText; | |
252c602c | 186 | private boolean entryChanged = false; |
c8cf44dc MAL |
187 | // The import from directory radio button |
188 | private Button fImportFromDirectoryRadio; | |
189 | // The import from archive radio button | |
190 | private Button fImportFromArchiveRadio; | |
191 | // Flag to remember the "create links" checkbox when it gets disabled by | |
192 | // the import from archive radio button | |
193 | private Boolean fPreviousCreateLinksValue = true; | |
d0e34947 | 194 | |
c8cf44dc | 195 | /** The archive name field */ |
d0e34947 | 196 | protected Combo fArchiveNameField; |
c8cf44dc MAL |
197 | /** The archive browse button. */ |
198 | protected Button fArchiveBrowseButton; | |
252c602c BH |
199 | /** The directory name field */ |
200 | protected Combo directoryNameField; | |
201 | /** The directory browse button. */ | |
202 | protected Button directoryBrowseButton; | |
002f9f07 | 203 | |
282218e9 MAL |
204 | private ResourceTreeAndListGroup fSelectionGroup; |
205 | ||
c8cf44dc MAL |
206 | // Keep trace of the selection root so that we can dispose its related |
207 | // resources | |
208 | private TraceFileSystemElement fSelectionGroupRoot; | |
209 | ||
002f9f07 BH |
210 | // ------------------------------------------------------------------------ |
211 | // Constructors | |
212 | // ------------------------------------------------------------------------ | |
213 | ||
214 | /** | |
215 | * Constructor. Creates the trace wizard page. | |
216 | * | |
217 | * @param name | |
218 | * The name of the page. | |
219 | * @param selection | |
220 | * The current selection | |
221 | */ | |
222 | protected ImportTraceWizardPage(String name, IStructuredSelection selection) { | |
223 | super(name, selection); | |
002f9f07 BH |
224 | setTitle(Messages.ImportTraceWizard_FileSystemTitle); |
225 | setDescription(Messages.ImportTraceWizard_ImportTrace); | |
226 | ||
227 | // Locate the target trace folder | |
228 | IFolder traceFolder = null; | |
229 | Object element = selection.getFirstElement(); | |
230 | ||
231 | if (element instanceof TmfTraceFolder) { | |
16f91bd5 | 232 | fTraceFolderElement = (TmfTraceFolder) element; |
16f91bd5 | 233 | traceFolder = fTraceFolderElement.getResource(); |
002f9f07 BH |
234 | } else if (element instanceof IProject) { |
235 | IProject project = (IProject) element; | |
236 | try { | |
237 | if (project.hasNature(TmfProjectNature.ID)) { | |
6ca50a1d BH |
238 | TmfProjectElement projectElement = TmfProjectRegistry.getProject(project, true); |
239 | fTraceFolderElement = projectElement.getTracesFolder(); | |
339d539c | 240 | traceFolder = project.getFolder(TmfTracesFolder.TRACES_FOLDER_NAME); |
002f9f07 BH |
241 | } |
242 | } catch (CoreException e) { | |
243 | } | |
244 | } | |
245 | ||
ba560b10 MK |
246 | // If no tracing project was selected or trace folder doesn't exist use |
247 | // default tracing project | |
252c602c BH |
248 | if (traceFolder == null) { |
249 | IProject project = TmfProjectRegistry.createProject( | |
250 | TmfCommonConstants.DEFAULT_TRACE_PROJECT_NAME, null, new NullProgressMonitor()); | |
6ca50a1d BH |
251 | TmfProjectElement projectElement = TmfProjectRegistry.getProject(project, true); |
252 | fTraceFolderElement = projectElement.getTracesFolder(); | |
339d539c | 253 | traceFolder = project.getFolder(TmfTracesFolder.TRACES_FOLDER_NAME); |
252c602c BH |
254 | } |
255 | ||
002f9f07 BH |
256 | // Set the target trace folder |
257 | if (traceFolder != null) { | |
258 | fTargetFolder = traceFolder; | |
1d6c9022 | 259 | String path = traceFolder.getFullPath().toString(); |
002f9f07 BH |
260 | setContainerFieldValue(path); |
261 | } | |
45fc1883 BH |
262 | |
263 | TmfProjectElement project = fTraceFolderElement.getProject(); | |
264 | fExperimentFolderElement = project.getExperimentsFolder(); | |
002f9f07 BH |
265 | } |
266 | ||
d0e34947 MAL |
267 | /** |
268 | * Constructor | |
269 | * | |
270 | * @param selection | |
271 | * The current selection | |
272 | */ | |
273 | public ImportTraceWizardPage(IStructuredSelection selection) { | |
274 | this(IMPORT_WIZARD_PAGE_NAME, selection); | |
275 | } | |
276 | ||
277 | /** | |
278 | * Create the import source selection widget. (Copied from | |
279 | * WizardResourceImportPage but instead always uses the internal | |
280 | * ResourceTreeAndListGroup to keep compatibility with Kepler) | |
281 | */ | |
282 | @Override | |
283 | protected void createFileSelectionGroup(Composite parent) { | |
284 | ||
285 | // Just create with a dummy root. | |
286 | fSelectionGroup = new ResourceTreeAndListGroup(parent, | |
45fc1883 | 287 | new FileSystemElement("Dummy", null, true), //$NON-NLS-1$ |
d0e34947 MAL |
288 | getFolderProvider(), new WorkbenchLabelProvider(), |
289 | getFileProvider(), new WorkbenchLabelProvider(), SWT.NONE, | |
290 | DialogUtil.inRegularFontMode(parent)); | |
291 | ||
292 | ICheckStateListener listener = new ICheckStateListener() { | |
293 | @Override | |
294 | public void checkStateChanged(CheckStateChangedEvent event) { | |
295 | updateWidgetEnablements(); | |
296 | } | |
297 | }; | |
298 | ||
299 | WorkbenchViewerComparator comparator = new WorkbenchViewerComparator(); | |
300 | fSelectionGroup.setTreeComparator(comparator); | |
301 | fSelectionGroup.setListComparator(comparator); | |
302 | fSelectionGroup.addCheckStateListener(listener); | |
303 | ||
304 | } | |
305 | ||
002f9f07 BH |
306 | // ------------------------------------------------------------------------ |
307 | // WizardResourceImportPage | |
308 | // ------------------------------------------------------------------------ | |
309 | ||
002f9f07 BH |
310 | @Override |
311 | protected void createSourceGroup(Composite parent) { | |
c8cf44dc | 312 | createSourceSelectionGroup(parent); |
002f9f07 BH |
313 | createFileSelectionGroup(parent); |
314 | createTraceTypeGroup(parent); | |
315 | validateSourceGroup(); | |
316 | } | |
317 | ||
318 | @Override | |
252c602c BH |
319 | protected ITreeContentProvider getFileProvider() { |
320 | return new WorkbenchContentProvider() { | |
002f9f07 | 321 | @Override |
252c602c BH |
322 | public Object[] getChildren(Object object) { |
323 | if (object instanceof TraceFileSystemElement) { | |
324 | TraceFileSystemElement element = (TraceFileSystemElement) object; | |
325 | return element.getFiles().getChildren(element); | |
002f9f07 | 326 | } |
252c602c | 327 | return new Object[0]; |
002f9f07 | 328 | } |
252c602c | 329 | }; |
002f9f07 BH |
330 | } |
331 | ||
332 | @Override | |
333 | protected ITreeContentProvider getFolderProvider() { | |
002f9f07 BH |
334 | return new WorkbenchContentProvider() { |
335 | @Override | |
336 | public Object[] getChildren(Object o) { | |
252c602c BH |
337 | if (o instanceof TraceFileSystemElement) { |
338 | TraceFileSystemElement element = (TraceFileSystemElement) o; | |
339 | return element.getFolders().getChildren(); | |
002f9f07 BH |
340 | } |
341 | return new Object[0]; | |
342 | } | |
002f9f07 | 343 | |
252c602c BH |
344 | @Override |
345 | public boolean hasChildren(Object o) { | |
346 | if (o instanceof TraceFileSystemElement) { | |
347 | TraceFileSystemElement element = (TraceFileSystemElement) o; | |
348 | if (element.isPopulated()) { | |
349 | return getChildren(element).length > 0; | |
350 | } | |
ba560b10 | 351 | // If we have not populated then wait until asked |
252c602c | 352 | return true; |
002f9f07 | 353 | } |
252c602c | 354 | return false; |
002f9f07 | 355 | } |
252c602c | 356 | }; |
002f9f07 BH |
357 | } |
358 | ||
359 | // ------------------------------------------------------------------------ | |
360 | // Directory Selection Group (forked WizardFileSystemResourceImportPage1) | |
361 | // ------------------------------------------------------------------------ | |
362 | ||
002f9f07 | 363 | /** |
c8cf44dc | 364 | * creates the source selection group. |
002f9f07 BH |
365 | * |
366 | * @param parent | |
367 | * the parent composite | |
368 | */ | |
d0e34947 | 369 | protected void createSourceSelectionGroup(Composite parent) { |
002f9f07 | 370 | |
d0e34947 | 371 | Composite sourceGroup = new Composite(parent, SWT.NONE); |
002f9f07 BH |
372 | GridLayout layout = new GridLayout(); |
373 | layout.numColumns = 3; | |
c8cf44dc MAL |
374 | layout.makeColumnsEqualWidth = false; |
375 | layout.marginWidth = 0; | |
376 | sourceGroup.setLayout(layout); | |
377 | sourceGroup.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); | |
378 | ||
379 | // import from directory radio button | |
380 | fImportFromDirectoryRadio = new Button(sourceGroup, SWT.RADIO); | |
45fc1883 | 381 | fImportFromDirectoryRadio.setText(Messages.ImportTraceWizard_DirectoryLocation); |
c8cf44dc MAL |
382 | |
383 | // import location entry combo | |
d0e34947 MAL |
384 | directoryNameField = createPathSelectionCombo(sourceGroup); |
385 | createDirectoryBrowseButton(sourceGroup); | |
c8cf44dc MAL |
386 | |
387 | // import from archive radio button | |
388 | fImportFromArchiveRadio = new Button(sourceGroup, SWT.RADIO); | |
45fc1883 | 389 | fImportFromArchiveRadio.setText(Messages.ImportTraceWizard_ArchiveLocation); |
c8cf44dc MAL |
390 | |
391 | // import location entry combo | |
d0e34947 MAL |
392 | fArchiveNameField = createPathSelectionCombo(sourceGroup); |
393 | createArchiveBrowseButton(sourceGroup); | |
c8cf44dc MAL |
394 | |
395 | fImportFromDirectoryRadio.setSelection(true); | |
396 | fArchiveNameField.setEnabled(false); | |
397 | fArchiveBrowseButton.setEnabled(false); | |
398 | ||
d0e34947 | 399 | fImportFromDirectoryRadio.addSelectionListener(new SelectionAdapter() { |
002f9f07 BH |
400 | @Override |
401 | public void widgetSelected(SelectionEvent e) { | |
d0e34947 | 402 | directoryRadioSelected(); |
002f9f07 | 403 | } |
c8cf44dc | 404 | }); |
002f9f07 | 405 | |
d0e34947 | 406 | fImportFromArchiveRadio.addSelectionListener(new SelectionAdapter() { |
002f9f07 | 407 | @Override |
c8cf44dc | 408 | public void widgetSelected(SelectionEvent e) { |
d0e34947 | 409 | archiveRadioSelected(); |
002f9f07 BH |
410 | } |
411 | }); | |
d0e34947 MAL |
412 | } |
413 | ||
414 | /** | |
415 | * Select or deselect all files in the file selection group | |
416 | * | |
417 | * @param checked | |
418 | * whether or not the files should be checked | |
419 | */ | |
420 | protected void setFileSelectionGroupChecked(boolean checked) { | |
421 | if (fSelectionGroup != null) { | |
422 | fSelectionGroup.setAllSelections(checked); | |
423 | } | |
424 | } | |
425 | ||
426 | /** | |
427 | * Create a combo that will be used to select a path to specify the source | |
428 | * of the import. The parent is assumed to have a GridLayout. | |
429 | * | |
430 | * @param parent | |
431 | * the parent composite | |
432 | * @return the created path selection combo | |
433 | */ | |
434 | protected Combo createPathSelectionCombo(Composite parent) { | |
435 | Combo pathSelectionCombo = new Combo(parent, SWT.BORDER); | |
436 | ||
437 | GridData layoutData = new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.GRAB_HORIZONTAL); | |
438 | layoutData.widthHint = new PixelConverter(pathSelectionCombo).convertWidthInCharsToPixels(25); | |
439 | pathSelectionCombo.setLayoutData(layoutData); | |
002f9f07 | 440 | |
c8cf44dc | 441 | TraverseListener traverseListener = new TraverseListener() { |
002f9f07 | 442 | @Override |
c8cf44dc MAL |
443 | public void keyTraversed(TraverseEvent e) { |
444 | if (e.detail == SWT.TRAVERSE_RETURN) { | |
445 | e.doit = false; | |
446 | entryChanged = false; | |
447 | updateFromSourceField(); | |
448 | } | |
002f9f07 | 449 | } |
c8cf44dc MAL |
450 | }; |
451 | ||
452 | FocusAdapter focusAdapter = new FocusAdapter() { | |
002f9f07 BH |
453 | @Override |
454 | public void focusLost(FocusEvent e) { | |
455 | // Clear the flag to prevent constant update | |
456 | if (entryChanged) { | |
457 | entryChanged = false; | |
458 | updateFromSourceField(); | |
459 | } | |
460 | } | |
c8cf44dc MAL |
461 | }; |
462 | ||
463 | SelectionAdapter selectionAdapter = new SelectionAdapter() { | |
464 | @Override | |
465 | public void widgetSelected(SelectionEvent e) { | |
466 | entryChanged = false; | |
467 | updateFromSourceField(); | |
468 | } | |
469 | }; | |
002f9f07 | 470 | |
c8cf44dc | 471 | ModifyListener modifyListner = new ModifyListener() { |
2f7b3dd7 BH |
472 | @Override |
473 | public void modifyText(ModifyEvent e) { | |
474 | entryChanged = true; | |
475 | } | |
c8cf44dc MAL |
476 | }; |
477 | ||
d0e34947 MAL |
478 | pathSelectionCombo.addModifyListener(modifyListner); |
479 | pathSelectionCombo.addTraverseListener(traverseListener); | |
480 | pathSelectionCombo.addFocusListener(focusAdapter); | |
481 | pathSelectionCombo.addSelectionListener(selectionAdapter); | |
c8cf44dc | 482 | |
d0e34947 MAL |
483 | return pathSelectionCombo; |
484 | } | |
485 | ||
486 | /** | |
487 | * Create the directory browse button. | |
488 | * | |
489 | * @param parent | |
490 | * the parent composite | |
491 | */ | |
492 | protected void createDirectoryBrowseButton(Composite parent) { | |
493 | directoryBrowseButton = createPathSelectionBrowseButton(parent); | |
494 | directoryBrowseButton.addSelectionListener(new SelectionAdapter() { | |
c8cf44dc MAL |
495 | @Override |
496 | public void widgetSelected(SelectionEvent e) { | |
d0e34947 | 497 | handleSourceDirectoryBrowseButtonPressed(); |
c8cf44dc | 498 | } |
2f7b3dd7 | 499 | }); |
d0e34947 | 500 | } |
2f7b3dd7 | 501 | |
d0e34947 MAL |
502 | /** |
503 | * Create the archive browse button. | |
504 | * | |
505 | * @param parent | |
506 | * the parent composite | |
507 | */ | |
508 | protected void createArchiveBrowseButton(Composite parent) { | |
509 | fArchiveBrowseButton = createPathSelectionBrowseButton(parent); | |
510 | fArchiveBrowseButton.addSelectionListener(new SelectionAdapter() { | |
c8cf44dc MAL |
511 | @Override |
512 | public void widgetSelected(SelectionEvent e) { | |
d0e34947 | 513 | handleArchiveBrowseButtonPressed(FILE_IMPORT_MASK); |
c8cf44dc MAL |
514 | } |
515 | }); | |
516 | } | |
517 | ||
d0e34947 MAL |
518 | /** |
519 | * Create a browse button that will be used to browse for a path to specify | |
520 | * the source of the import. The parent is assumed to have a GridLayout. | |
521 | * | |
522 | * @param parent | |
523 | * the parent composite | |
524 | * @return the created path selection combo | |
525 | */ | |
526 | protected Button createPathSelectionBrowseButton(Composite parent) { | |
527 | Button pathSelectionBrowseButton = new Button(parent, SWT.PUSH); | |
528 | pathSelectionBrowseButton.setText(Messages.ImportTraceWizard_BrowseButton); | |
529 | setButtonLayoutData(pathSelectionBrowseButton); | |
530 | ||
531 | return pathSelectionBrowseButton; | |
532 | } | |
533 | ||
c8cf44dc | 534 | private void archiveRadioSelected() { |
d0e34947 | 535 | if (!isImportFromDirectory()) { |
c8cf44dc MAL |
536 | directoryNameField.setEnabled(false); |
537 | directoryBrowseButton.setEnabled(false); | |
538 | fArchiveNameField.setEnabled(true); | |
539 | fArchiveBrowseButton.setEnabled(true); | |
540 | updateFromSourceField(); | |
541 | fArchiveNameField.setFocus(); | |
d0e34947 MAL |
542 | if (fCreateLinksInWorkspaceButton != null) { |
543 | fPreviousCreateLinksValue = fCreateLinksInWorkspaceButton.getSelection(); | |
544 | fCreateLinksInWorkspaceButton.setSelection(false); | |
545 | fCreateLinksInWorkspaceButton.setEnabled(false); | |
546 | } | |
c8cf44dc MAL |
547 | } |
548 | } | |
549 | ||
550 | private void directoryRadioSelected() { | |
d0e34947 | 551 | if (isImportFromDirectory()) { |
c8cf44dc MAL |
552 | directoryNameField.setEnabled(true); |
553 | directoryBrowseButton.setEnabled(true); | |
554 | fArchiveNameField.setEnabled(false); | |
555 | fArchiveBrowseButton.setEnabled(false); | |
556 | updateFromSourceField(); | |
557 | directoryNameField.setFocus(); | |
d0e34947 MAL |
558 | if (fCreateLinksInWorkspaceButton != null) { |
559 | fCreateLinksInWorkspaceButton.setSelection(fPreviousCreateLinksValue); | |
560 | fCreateLinksInWorkspaceButton.setEnabled(true); | |
561 | } | |
c8cf44dc | 562 | } |
002f9f07 BH |
563 | } |
564 | ||
565 | // ------------------------------------------------------------------------ | |
566 | // Browse for the source directory | |
567 | // ------------------------------------------------------------------------ | |
568 | ||
569 | @Override | |
570 | public void handleEvent(Event event) { | |
571 | if (event.widget == directoryBrowseButton) { | |
572 | handleSourceDirectoryBrowseButtonPressed(); | |
573 | } | |
252c602c BH |
574 | |
575 | // Avoid overwriting destination path without repeatedly trigger | |
576 | // call of handleEvent(); | |
28abf18d | 577 | synchronized (fSyncObject) { |
252c602c BH |
578 | if (fIsDestinationChanged == false) { |
579 | event.display.asyncExec(new Runnable() { | |
580 | @Override | |
581 | public void run() { | |
28abf18d | 582 | synchronized (fSyncObject) { |
252c602c | 583 | fIsDestinationChanged = true; |
1d6c9022 | 584 | String path = fTargetFolder.getFullPath().toString(); |
252c602c BH |
585 | setContainerFieldValue(path); |
586 | } | |
587 | } | |
588 | }); | |
589 | } else { | |
590 | fIsDestinationChanged = false; | |
591 | } | |
592 | } | |
002f9f07 BH |
593 | super.handleEvent(event); |
594 | } | |
595 | ||
252c602c BH |
596 | @Override |
597 | protected void handleContainerBrowseButtonPressed() { | |
598 | // Do nothing so that destination directory cannot be changed. | |
599 | } | |
600 | ||
002f9f07 BH |
601 | /** |
602 | * Handle the button pressed event | |
603 | */ | |
604 | protected void handleSourceDirectoryBrowseButtonPressed() { | |
605 | String currentSource = directoryNameField.getText(); | |
606 | DirectoryDialog dialog = new DirectoryDialog(directoryNameField.getShell(), SWT.SAVE | SWT.SHEET); | |
607 | dialog.setText(Messages.ImportTraceWizard_SelectTraceDirectoryTitle); | |
608 | dialog.setMessage(Messages.ImportTraceWizard_SelectTraceDirectoryMessage); | |
609 | dialog.setFilterPath(getSourceDirectoryName(currentSource)); | |
610 | ||
611 | String selectedDirectory = dialog.open(); | |
612 | if (selectedDirectory != null) { | |
613 | // Just quit if the directory is not valid | |
614 | if ((getSourceDirectory(selectedDirectory) == null) || selectedDirectory.equals(currentSource)) { | |
615 | return; | |
616 | } | |
617 | // If it is valid then proceed to populate | |
618 | setErrorMessage(null); | |
d0e34947 | 619 | setSourcePath(selectedDirectory); |
002f9f07 BH |
620 | } |
621 | } | |
622 | ||
c8cf44dc MAL |
623 | /** |
624 | * Handle the button pressed event | |
d0e34947 MAL |
625 | * |
626 | * @param extensions | |
627 | * file extensions used to filter files shown to the user | |
c8cf44dc | 628 | */ |
d0e34947 | 629 | protected void handleArchiveBrowseButtonPressed(String[] extensions) { |
c8cf44dc | 630 | FileDialog dialog = new FileDialog(fArchiveNameField.getShell(), SWT.SHEET); |
d0e34947 | 631 | dialog.setFilterExtensions(extensions); |
c8cf44dc MAL |
632 | dialog.setText(Messages.ImportTraceWizard_SelectTraceArchiveTitle); |
633 | String fileName = fArchiveNameField.getText().trim(); | |
634 | if (!fileName.isEmpty()) { | |
635 | File path = new File(fileName).getParentFile(); | |
636 | if (path != null && path.exists()) { | |
637 | dialog.setFilterPath(path.toString()); | |
638 | } | |
639 | } | |
640 | ||
641 | String selectedArchive = dialog.open(); | |
642 | if (selectedArchive != null) { | |
643 | setErrorMessage(null); | |
d0e34947 | 644 | setSourcePath(selectedArchive); |
c8cf44dc MAL |
645 | updateWidgetEnablements(); |
646 | } | |
647 | } | |
648 | ||
002f9f07 | 649 | private File getSourceDirectory() { |
d0e34947 MAL |
650 | if (directoryNameField == null) { |
651 | return null; | |
652 | } | |
002f9f07 BH |
653 | return getSourceDirectory(directoryNameField.getText()); |
654 | } | |
655 | ||
c8cf44dc | 656 | private File getSourceArchiveFile() { |
d0e34947 MAL |
657 | if (fArchiveNameField == null) { |
658 | return null; | |
659 | } | |
660 | ||
c8cf44dc MAL |
661 | return getSourceArchiveFile(fArchiveNameField.getText()); |
662 | } | |
663 | ||
664 | private String getSourceContainerPath() { | |
d0e34947 | 665 | if (isImportFromDirectory()) { |
c8cf44dc MAL |
666 | File sourceDirectory = getSourceDirectory(); |
667 | if (sourceDirectory != null) { | |
668 | return sourceDirectory.getAbsolutePath(); | |
669 | } | |
670 | } | |
671 | File sourceArchiveFile = getSourceArchiveFile(); | |
672 | if (sourceArchiveFile != null) { | |
673 | return sourceArchiveFile.getParent(); | |
674 | } | |
675 | return null; | |
676 | } | |
677 | ||
002f9f07 BH |
678 | private static File getSourceDirectory(String path) { |
679 | File sourceDirectory = new File(getSourceDirectoryName(path)); | |
680 | if (!sourceDirectory.exists() || !sourceDirectory.isDirectory()) { | |
681 | return null; | |
682 | } | |
683 | ||
684 | return sourceDirectory; | |
685 | } | |
686 | ||
c8cf44dc MAL |
687 | private static File getSourceArchiveFile(String path) { |
688 | File sourceArchiveFile = new File(path); | |
689 | if (!sourceArchiveFile.exists() || sourceArchiveFile.isDirectory()) { | |
690 | return null; | |
691 | } | |
692 | ||
693 | return sourceArchiveFile; | |
694 | } | |
695 | ||
002f9f07 BH |
696 | private static String getSourceDirectoryName(String sourceName) { |
697 | IPath result = new Path(sourceName.trim()); | |
698 | if (result.getDevice() != null && result.segmentCount() == 0) { | |
699 | result = result.addTrailingSeparator(); | |
700 | } else { | |
701 | result = result.removeTrailingSeparator(); | |
702 | } | |
703 | return result.toOSString(); | |
704 | } | |
705 | ||
002f9f07 | 706 | private void updateFromSourceField() { |
d0e34947 | 707 | setSourcePath(getSourceField().getText()); |
002f9f07 BH |
708 | updateWidgetEnablements(); |
709 | } | |
710 | ||
c8cf44dc | 711 | private Combo getSourceField() { |
d0e34947 MAL |
712 | if (directoryNameField == null) { |
713 | return fArchiveNameField; | |
714 | } | |
715 | ||
c8cf44dc MAL |
716 | return directoryNameField.isEnabled() ? directoryNameField : fArchiveNameField; |
717 | } | |
718 | ||
d0e34947 MAL |
719 | /** |
720 | * Set the source path that was selected by the user by various input | |
721 | * methods (Browse button, typing, etc). | |
722 | * | |
723 | * Clients can also call this to set the path programmatically (hard-coded | |
724 | * initial path) and this can also be overridden to be notified when the | |
725 | * source path changes. | |
726 | * | |
727 | * @param path | |
728 | * the source path | |
729 | */ | |
730 | protected void setSourcePath(String path) { | |
c8cf44dc | 731 | Combo sourceField = getSourceField(); |
d0e34947 MAL |
732 | if (sourceField == null) { |
733 | return; | |
734 | } | |
735 | ||
002f9f07 | 736 | if (path.length() > 0) { |
c8cf44dc | 737 | String[] currentItems = sourceField.getItems(); |
002f9f07 BH |
738 | int selectionIndex = -1; |
739 | for (int i = 0; i < currentItems.length; i++) { | |
740 | if (currentItems[i].equals(path)) { | |
741 | selectionIndex = i; | |
742 | } | |
743 | } | |
744 | if (selectionIndex < 0) { | |
745 | int oldLength = currentItems.length; | |
746 | String[] newItems = new String[oldLength + 1]; | |
747 | System.arraycopy(currentItems, 0, newItems, 0, oldLength); | |
748 | newItems[oldLength] = path; | |
c8cf44dc | 749 | sourceField.setItems(newItems); |
002f9f07 BH |
750 | selectionIndex = oldLength; |
751 | } | |
c8cf44dc | 752 | sourceField.select(selectionIndex); |
002f9f07 BH |
753 | } |
754 | resetSelection(); | |
755 | } | |
756 | ||
757 | // ------------------------------------------------------------------------ | |
758 | // File Selection Group (forked WizardFileSystemResourceImportPage1) | |
759 | // ------------------------------------------------------------------------ | |
002f9f07 | 760 | private void resetSelection() { |
45fc1883 | 761 | |
c8cf44dc MAL |
762 | if (fSelectionGroupRoot != null) { |
763 | disposeSelectionGroupRoot(); | |
764 | } | |
765 | fSelectionGroupRoot = getFileSystemTree(); | |
766 | fSelectionGroup.setRoot(fSelectionGroupRoot); | |
45fc1883 BH |
767 | |
768 | if (fCreateExperimentCheckbox != null) { | |
769 | File file = getSourceFile(); | |
770 | if (file != null) { | |
771 | String previousName = fExperimentNameText.getText().trim(); | |
772 | if (((fPreviousSource != null) && (previousName.equals(fPreviousSource))) || previousName.isEmpty()) { | |
773 | fExperimentNameText.setText(file.getName()); | |
774 | } | |
775 | fPreviousSource = file.getName(); | |
776 | } | |
777 | } | |
c8cf44dc MAL |
778 | } |
779 | ||
780 | private void disposeSelectionGroupRoot() { | |
781 | if (fSelectionGroupRoot != null && fSelectionGroupRoot.getProvider() != null) { | |
782 | FileSystemObjectImportStructureProvider provider = fSelectionGroupRoot.getProvider(); | |
783 | provider.dispose(); | |
784 | fSelectionGroupRoot = null; | |
785 | } | |
002f9f07 BH |
786 | } |
787 | ||
252c602c | 788 | private TraceFileSystemElement getFileSystemTree() { |
f17bb886 | 789 | Pair<IFileSystemObject, FileSystemObjectImportStructureProvider> rootObjectAndProvider = ArchiveUtil.getRootObjectAndProvider(getSourceFile(), getContainer().getShell()); |
480e9739 MAL |
790 | if (rootObjectAndProvider == null) { |
791 | return null; | |
792 | } | |
793 | return selectFiles(rootObjectAndProvider.getFirst(), rootObjectAndProvider.getSecond()); | |
794 | } | |
795 | ||
c8cf44dc MAL |
796 | private TraceFileSystemElement selectFiles(final IFileSystemObject rootFileSystemObject, |
797 | final FileSystemObjectImportStructureProvider structureProvider) { | |
252c602c | 798 | final TraceFileSystemElement[] results = new TraceFileSystemElement[1]; |
002f9f07 BH |
799 | BusyIndicator.showWhile(getShell().getDisplay(), new Runnable() { |
800 | @Override | |
801 | public void run() { | |
802 | // Create the root element from the supplied file system object | |
f17bb886 | 803 | results[0] = TraceFileSystemElement.createRootTraceFileElement(rootFileSystemObject, structureProvider); |
002f9f07 BH |
804 | } |
805 | }); | |
806 | return results[0]; | |
807 | } | |
808 | ||
002f9f07 BH |
809 | // ------------------------------------------------------------------------ |
810 | // Trace Type Group | |
811 | // ------------------------------------------------------------------------ | |
002f9f07 BH |
812 | private final void createTraceTypeGroup(Composite parent) { |
813 | Composite composite = new Composite(parent, SWT.NONE); | |
814 | GridLayout layout = new GridLayout(); | |
815 | layout.numColumns = 3; | |
816 | layout.makeColumnsEqualWidth = false; | |
817 | composite.setLayout(layout); | |
818 | composite.setFont(parent.getFont()); | |
819 | GridData buttonData = new GridData(SWT.FILL, SWT.FILL, true, false); | |
820 | composite.setLayoutData(buttonData); | |
821 | ||
822 | // Trace type label ("Trace Type:") | |
823 | Label typeLabel = new Label(composite, SWT.NONE); | |
824 | typeLabel.setText(Messages.ImportTraceWizard_TraceType); | |
825 | typeLabel.setFont(parent.getFont()); | |
826 | ||
827 | // Trace type combo | |
252c602c | 828 | fTraceTypes = new Combo(composite, SWT.BORDER | SWT.READ_ONLY); |
002f9f07 BH |
829 | GridData data = new GridData(SWT.FILL, SWT.FILL, true, false, 2, 1); |
830 | fTraceTypes.setLayoutData(data); | |
831 | fTraceTypes.setFont(parent.getFont()); | |
832 | ||
a4a116c3 | 833 | String[] availableTraceTypes = TmfTraceType.getAvailableTraceTypes(); |
252c602c | 834 | String[] traceTypeList = new String[availableTraceTypes.length + 1]; |
d0e34947 | 835 | traceTypeList[0] = TRACE_TYPE_AUTO_DETECT; |
252c602c BH |
836 | for (int i = 0; i < availableTraceTypes.length; i++) { |
837 | traceTypeList[i + 1] = availableTraceTypes[i]; | |
838 | } | |
839 | fTraceTypes.setItems(traceTypeList); | |
e2a50e26 | 840 | fTraceTypes.addSelectionListener(new SelectionAdapter() { |
002f9f07 BH |
841 | @Override |
842 | public void widgetSelected(SelectionEvent e) { | |
843 | updateWidgetEnablements(); | |
d0e34947 | 844 | boolean enabled = fTraceTypes.getText().equals(TRACE_TYPE_AUTO_DETECT); |
e2a50e26 | 845 | fImportUnrecognizedButton.setEnabled(enabled); |
002f9f07 BH |
846 | } |
847 | }); | |
252c602c BH |
848 | fTraceTypes.select(0); |
849 | ||
16f91bd5 | 850 | // Unrecognized checkbox |
252c602c BH |
851 | fImportUnrecognizedButton = new Button(composite, SWT.CHECK); |
852 | fImportUnrecognizedButton.setSelection(true); | |
853 | fImportUnrecognizedButton.setText(Messages.ImportTraceWizard_ImportUnrecognized); | |
002f9f07 BH |
854 | } |
855 | ||
856 | // ------------------------------------------------------------------------ | |
857 | // Options | |
858 | // ------------------------------------------------------------------------ | |
859 | ||
002f9f07 BH |
860 | @Override |
861 | protected void createOptionsGroupButtons(Group optionsGroup) { | |
862 | ||
863 | // Overwrite checkbox | |
252c602c BH |
864 | fOverwriteExistingResourcesCheckbox = new Button(optionsGroup, SWT.CHECK); |
865 | fOverwriteExistingResourcesCheckbox.setFont(optionsGroup.getFont()); | |
866 | fOverwriteExistingResourcesCheckbox.setText(Messages.ImportTraceWizard_OverwriteExistingTrace); | |
867 | fOverwriteExistingResourcesCheckbox.setSelection(false); | |
002f9f07 BH |
868 | |
869 | // Create links checkbox | |
252c602c BH |
870 | fCreateLinksInWorkspaceButton = new Button(optionsGroup, SWT.CHECK); |
871 | fCreateLinksInWorkspaceButton.setFont(optionsGroup.getFont()); | |
872 | fCreateLinksInWorkspaceButton.setText(Messages.ImportTraceWizard_CreateLinksInWorkspace); | |
873 | fCreateLinksInWorkspaceButton.setSelection(true); | |
002f9f07 | 874 | |
252c602c | 875 | fCreateLinksInWorkspaceButton.addSelectionListener(new SelectionAdapter() { |
002f9f07 BH |
876 | @Override |
877 | public void widgetSelected(SelectionEvent e) { | |
878 | updateWidgetEnablements(); | |
879 | } | |
880 | }); | |
881 | ||
0e1d517e MAL |
882 | fPreserveFolderStructureButton = new Button(optionsGroup, SWT.CHECK); |
883 | fPreserveFolderStructureButton.setFont(optionsGroup.getFont()); | |
884 | fPreserveFolderStructureButton.setText(Messages.ImportTraceWizard_PreserveFolderStructure); | |
885 | fPreserveFolderStructureButton.setSelection(true); | |
886 | ||
45fc1883 BH |
887 | Composite comp = new Composite(optionsGroup, SWT.NONE); |
888 | GridLayout layout = new GridLayout(2, false); | |
889 | layout.marginLeft = 0; | |
890 | layout.marginRight = 0; | |
891 | layout.marginBottom = 0; | |
892 | layout.marginTop = 0; | |
893 | layout.marginWidth = 0; | |
894 | comp.setLayout(layout); | |
895 | GridData data = new GridData(GridData.FILL, GridData.CENTER, true, false); | |
896 | comp.setLayoutData(data); | |
897 | ||
898 | fCreateExperimentCheckbox = new Button(comp, SWT.CHECK); | |
899 | fCreateExperimentCheckbox.setFont(comp.getFont()); | |
900 | fCreateExperimentCheckbox.setText(Messages.ImportTraceWizard_CreateExperiment); | |
901 | fCreateExperimentCheckbox.setSelection(false); | |
902 | data = new GridData(GridData.BEGINNING, GridData.CENTER, false, false); | |
903 | fCreateExperimentCheckbox.setLayoutData(data); | |
904 | ||
905 | fExperimentNameText = new Text(comp, SWT.BORDER); | |
906 | data = new GridData(GridData.FILL, GridData.CENTER, true, false); | |
907 | fExperimentNameText.setLayoutData(data); | |
908 | ||
909 | fExperimentNameText.addModifyListener(new ModifyListener() { | |
910 | @Override | |
911 | public void modifyText(ModifyEvent e) { | |
912 | updateWidgetEnablements(); | |
913 | } | |
914 | }); | |
915 | ||
916 | fCreateExperimentCheckbox.addSelectionListener(new SelectionAdapter() { | |
917 | @Override | |
918 | public void widgetSelected(SelectionEvent e) { | |
919 | fExperimentNameText.setEnabled(fCreateExperimentCheckbox.getSelection()); | |
920 | updateWidgetEnablements(); | |
921 | } | |
922 | }); | |
923 | ||
002f9f07 BH |
924 | updateWidgetEnablements(); |
925 | } | |
926 | ||
927 | // ------------------------------------------------------------------------ | |
928 | // Determine if the finish button can be enabled | |
929 | // ------------------------------------------------------------------------ | |
002f9f07 BH |
930 | @Override |
931 | public boolean validateSourceGroup() { | |
932 | ||
480e9739 | 933 | File source = getSourceFile(); |
c8cf44dc | 934 | if (source == null) { |
002f9f07 | 935 | setMessage(Messages.ImportTraceWizard_SelectTraceSourceEmpty); |
c8cf44dc | 936 | setErrorMessage(null); |
002f9f07 BH |
937 | return false; |
938 | } | |
939 | ||
c8cf44dc | 940 | if (sourceConflictsWithDestination(new Path(source.getPath()))) { |
002f9f07 BH |
941 | setMessage(null); |
942 | setErrorMessage(getSourceConflictMessage()); | |
943 | return false; | |
944 | } | |
945 | ||
5d5f933e | 946 | if (!isImportFromDirectory() && !ArchiveUtil.ensureTarSourceIsValid(source.getAbsolutePath()) && !ArchiveUtil.ensureZipSourceIsValid(source.getAbsolutePath(), getContainer().getShell()) |
45fc1883 | 947 | && !ArchiveUtil.ensureGzipSourceIsValid(source.getAbsolutePath())) { |
1fb9f55c MK |
948 | setMessage(null); |
949 | setErrorMessage(Messages.ImportTraceWizard_BadArchiveFormat); | |
950 | return false; | |
c8cf44dc MAL |
951 | } |
952 | ||
282218e9 | 953 | if (fSelectionGroup.getCheckedElementCount() == 0) { |
002f9f07 BH |
954 | setMessage(null); |
955 | setErrorMessage(Messages.ImportTraceWizard_SelectTraceNoneSelected); | |
956 | return false; | |
957 | } | |
958 | ||
959 | IContainer container = getSpecifiedContainer(); | |
960 | if (container != null && container.isVirtual()) { | |
961 | if (Platform.getPreferencesService().getBoolean(Activator.PLUGIN_ID, ResourcesPlugin.PREF_DISABLE_LINKING, false, null)) { | |
962 | setMessage(null); | |
963 | setErrorMessage(Messages.ImportTraceWizard_CannotImportFilesUnderAVirtualFolder); | |
964 | return false; | |
965 | } | |
252c602c | 966 | if (fCreateLinksInWorkspaceButton == null || !fCreateLinksInWorkspaceButton.getSelection()) { |
002f9f07 BH |
967 | setMessage(null); |
968 | setErrorMessage(Messages.ImportTraceWizard_HaveToCreateLinksUnderAVirtualFolder); | |
969 | return false; | |
970 | } | |
971 | } | |
45fc1883 BH |
972 | setErrorMessage(null); |
973 | return true; | |
974 | } | |
002f9f07 | 975 | |
45fc1883 BH |
976 | @Override |
977 | protected boolean validateOptionsGroup() { | |
978 | if (fCreateExperimentCheckbox != null && fCreateExperimentCheckbox.getSelection()) { | |
979 | String name = fExperimentNameText.getText().trim(); | |
980 | // verify if experiment name is empty | |
981 | if (name.isEmpty()) { | |
982 | setMessage(null); | |
983 | setErrorMessage(Messages.ImportTraceWizard_ErrorEmptyExperimentName); | |
984 | return false; | |
985 | } | |
986 | // verify that name is a valid resource name | |
987 | IWorkspace workspace = ResourcesPlugin.getWorkspace(); | |
988 | if ((workspace != null) && (!workspace.validateName(name, IResource.FILE).isOK())) { | |
989 | setMessage(null); | |
990 | setErrorMessage(NLS.bind(Messages.ImportTraceWizard_ErrorExperimentNameInvalid, name)); | |
991 | return false; | |
992 | } | |
993 | // verify if experiment already exists | |
994 | if (fExperimentFolderElement != null) { | |
995 | TmfExperimentElement element = fExperimentFolderElement.getExperiment(name); | |
996 | if (element != null) { | |
997 | setMessage(null); | |
998 | setErrorMessage(NLS.bind(Messages.ImportTraceWizard_ErrorExperimentAlreadyExists, name)); | |
999 | return false; | |
1000 | } | |
1001 | IFolder expResource = fExperimentFolderElement.getResource(); | |
1002 | IResource res = expResource.findMember(name); | |
1003 | if (res != null) { | |
1004 | setMessage(null); | |
1005 | setErrorMessage(NLS.bind(Messages.ImportTraceWizard_ErrorResourceAlreadyExists, name)); | |
1006 | return false; | |
1007 | } | |
1008 | } | |
1009 | } | |
002f9f07 BH |
1010 | setErrorMessage(null); |
1011 | return true; | |
1012 | } | |
1013 | ||
480e9739 MAL |
1014 | private File getSourceFile() { |
1015 | return isImportFromDirectory() ? getSourceDirectory() : getSourceArchiveFile(); | |
1016 | } | |
1017 | ||
d0e34947 MAL |
1018 | private boolean isImportFromDirectory() { |
1019 | return fImportFromDirectoryRadio != null && fImportFromDirectoryRadio.getSelection(); | |
1020 | } | |
1021 | ||
6781d5b9 BH |
1022 | @Override |
1023 | protected void restoreWidgetValues() { | |
1024 | super.restoreWidgetValues(); | |
1025 | ||
1026 | IDialogSettings settings = getDialogSettings(); | |
1027 | boolean value; | |
d0e34947 MAL |
1028 | if (fImportUnrecognizedButton != null) { |
1029 | if (settings.get(getPageStoreKey(IMPORT_WIZARD_IMPORT_UNRECOGNIZED_ID)) == null) { | |
1030 | value = true; | |
1031 | } else { | |
1032 | value = settings.getBoolean(getPageStoreKey(IMPORT_WIZARD_IMPORT_UNRECOGNIZED_ID)); | |
1033 | } | |
1034 | fImportUnrecognizedButton.setSelection(value); | |
6781d5b9 | 1035 | } |
6781d5b9 | 1036 | |
d0e34947 MAL |
1037 | if (fPreserveFolderStructureButton != null) { |
1038 | if (settings.get(getPageStoreKey(IMPORT_WIZARD_PRESERVE_FOLDERS_ID)) == null) { | |
1039 | value = true; | |
1040 | } else { | |
1041 | value = settings.getBoolean(getPageStoreKey(IMPORT_WIZARD_PRESERVE_FOLDERS_ID)); | |
1042 | } | |
1043 | fPreserveFolderStructureButton.setSelection(value); | |
6781d5b9 | 1044 | } |
6781d5b9 | 1045 | |
45fc1883 BH |
1046 | if (fCreateExperimentCheckbox != null) { |
1047 | if (settings.get(getPageStoreKey(IMPORT_WIZARD_CREATE_EXPERIMENT_ID)) == null) { | |
1048 | value = false; | |
1049 | } else { | |
1050 | value = settings.getBoolean(getPageStoreKey(IMPORT_WIZARD_CREATE_EXPERIMENT_ID)); | |
1051 | } | |
1052 | fCreateExperimentCheckbox.setSelection(value); | |
1053 | fExperimentNameText.setEnabled(fCreateExperimentCheckbox.getSelection()); | |
1054 | } | |
1055 | ||
d0e34947 | 1056 | if (settings.get(getPageStoreKey(IMPORT_WIZARD_IMPORT_FROM_DIRECTORY_ID)) == null) { |
c8cf44dc MAL |
1057 | value = true; |
1058 | } else { | |
d0e34947 | 1059 | value = settings.getBoolean(getPageStoreKey(IMPORT_WIZARD_IMPORT_FROM_DIRECTORY_ID)); |
c8cf44dc | 1060 | } |
c8cf44dc | 1061 | |
d0e34947 MAL |
1062 | if (directoryNameField != null) { |
1063 | restoreComboValues(directoryNameField, settings, getPageStoreKey(IMPORT_WIZARD_ROOT_DIRECTORY_ID)); | |
1064 | } | |
1065 | if (fArchiveNameField != null) { | |
1066 | restoreComboValues(fArchiveNameField, settings, getPageStoreKey(IMPORT_WIZARD_ARCHIVE_FILE_NAME_ID)); | |
1067 | } | |
1068 | ||
1069 | if (fImportFromDirectoryRadio != null) { | |
1070 | fImportFromDirectoryRadio.setSelection(value); | |
1071 | if (value) { | |
1072 | directoryRadioSelected(); | |
1073 | } | |
1074 | } | |
1075 | if (fImportFromArchiveRadio != null) { | |
1076 | fImportFromArchiveRadio.setSelection(!value); | |
1077 | if (!value) { | |
1078 | archiveRadioSelected(); | |
1079 | } | |
6781d5b9 BH |
1080 | } |
1081 | } | |
1082 | ||
1083 | @Override | |
1084 | protected void saveWidgetValues() { | |
1085 | // Persist dialog settings | |
1086 | IDialogSettings settings = getDialogSettings(); | |
d0e34947 MAL |
1087 | if (fImportUnrecognizedButton != null) { |
1088 | settings.put(getPageStoreKey(IMPORT_WIZARD_IMPORT_UNRECOGNIZED_ID), fImportUnrecognizedButton.getSelection()); | |
1089 | } | |
1090 | if (fPreserveFolderStructureButton != null) { | |
1091 | settings.put(getPageStoreKey(IMPORT_WIZARD_PRESERVE_FOLDERS_ID), fPreserveFolderStructureButton.getSelection()); | |
1092 | } | |
45fc1883 BH |
1093 | |
1094 | if (fCreateExperimentCheckbox != null) { | |
1095 | settings.put(getPageStoreKey(IMPORT_WIZARD_CREATE_EXPERIMENT_ID), fCreateExperimentCheckbox.getSelection()); | |
1096 | } | |
1097 | ||
d0e34947 MAL |
1098 | settings.put(getPageStoreKey(IMPORT_WIZARD_IMPORT_FROM_DIRECTORY_ID), isImportFromDirectory()); |
1099 | ||
1100 | if (directoryNameField != null) { | |
1101 | saveComboValues(directoryNameField, settings, getPageStoreKey(IMPORT_WIZARD_ROOT_DIRECTORY_ID)); | |
1102 | } | |
1103 | if (fArchiveNameField != null) { | |
1104 | saveComboValues(fArchiveNameField, settings, getPageStoreKey(IMPORT_WIZARD_ARCHIVE_FILE_NAME_ID)); | |
1105 | } | |
1106 | } | |
c8cf44dc | 1107 | |
d0e34947 MAL |
1108 | private String getPageStoreKey(String key) { |
1109 | return getName() + key; | |
c8cf44dc MAL |
1110 | } |
1111 | ||
1112 | private static void restoreComboValues(Combo combo, IDialogSettings settings, String key) { | |
1113 | String[] directoryNames = settings.getArray(key); | |
1114 | if ((directoryNames != null) && (directoryNames.length != 0)) { | |
1115 | for (int i = 0; i < directoryNames.length; i++) { | |
1116 | combo.add(directoryNames[i]); | |
1117 | } | |
1118 | } | |
1119 | } | |
6781d5b9 | 1120 | |
c8cf44dc MAL |
1121 | private void saveComboValues(Combo combo, IDialogSettings settings, String key) { |
1122 | // update names history | |
1123 | String[] directoryNames = settings.getArray(key); | |
6781d5b9 BH |
1124 | if (directoryNames == null) { |
1125 | directoryNames = new String[0]; | |
1126 | } | |
1127 | ||
c8cf44dc | 1128 | String items[] = combo.getItems(); |
6781d5b9 BH |
1129 | for (int i = 0; i < items.length; i++) { |
1130 | directoryNames = addToHistory(directoryNames, items[i]); | |
1131 | } | |
c8cf44dc | 1132 | settings.put(key, directoryNames); |
6781d5b9 BH |
1133 | } |
1134 | ||
002f9f07 BH |
1135 | // ------------------------------------------------------------------------ |
1136 | // Import the trace(s) | |
1137 | // ------------------------------------------------------------------------ | |
1138 | ||
1139 | /** | |
1140 | * Finish the import. | |
1141 | * | |
252c602c | 1142 | * @return <code>true</code> if successful else <code>false</code> |
002f9f07 BH |
1143 | */ |
1144 | public boolean finish() { | |
2b0005f0 | 1145 | String traceTypeLabel = getImportTraceTypeId(); |
f17bb886 | 1146 | final String traceId = !TRACE_TYPE_AUTO_DETECT.equals(traceTypeLabel) ? TmfTraceType.getTraceTypeId(traceTypeLabel) : null; |
002f9f07 | 1147 | |
6781d5b9 BH |
1148 | // Save dialog settings |
1149 | saveWidgetValues(); | |
002f9f07 | 1150 | |
f17bb886 MAL |
1151 | final IPath baseSourceContainerPath = new Path(getSourceContainerPath()); |
1152 | final boolean importFromArchive = getSourceArchiveFile() != null; | |
1153 | final int importOptionFlags = getImportOptionFlags(); | |
1154 | final IPath destinationContainerPath = getContainerFullPath(); | |
002f9f07 | 1155 | |
f17bb886 MAL |
1156 | final IStatus[] operationStatus = new IStatus[1]; |
1157 | operationStatus[0] = Status.OK_STATUS; | |
45fc1883 | 1158 | final List<IResource> traceResources = new ArrayList<>(); |
252c602c BH |
1159 | try { |
1160 | getContainer().run(true, true, new IRunnableWithProgress() { | |
1161 | @Override | |
1162 | public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { | |
f17bb886 MAL |
1163 | |
1164 | final List<TraceFileSystemElement> selectedFileSystemElements = new LinkedList<>(); | |
1165 | IElementFilter passThroughFilter = new IElementFilter() { | |
1166 | ||
1167 | @Override | |
1168 | public void filterElements(Collection elements, IProgressMonitor m) { | |
1169 | selectedFileSystemElements.addAll(elements); | |
1170 | } | |
1171 | ||
1172 | @Override | |
1173 | public void filterElements(Object[] elements, IProgressMonitor m) { | |
1174 | for (int i = 0; i < elements.length; i++) { | |
1175 | selectedFileSystemElements.add((TraceFileSystemElement) elements[i]); | |
1176 | } | |
1177 | } | |
1178 | }; | |
1179 | ||
1180 | // List fileSystemElements will be filled using the | |
1181 | // passThroughFilter | |
1182 | SubMonitor subMonitor = SubMonitor.convert(monitor, 1); | |
1183 | fSelectionGroup.getAllCheckedListItems(passThroughFilter, subMonitor); | |
1184 | ||
1185 | final TraceValidateAndImportOperation operation = new TraceValidateAndImportOperation(getContainer().getShell(), selectedFileSystemElements, traceId, baseSourceContainerPath, destinationContainerPath, importFromArchive, | |
1186 | importOptionFlags, fTraceFolderElement); | |
252c602c BH |
1187 | operation.run(monitor); |
1188 | monitor.done(); | |
f17bb886 | 1189 | operationStatus[0] = operation.getStatus(); |
45fc1883 | 1190 | traceResources.addAll(operation.getImportedResources()); |
002f9f07 | 1191 | } |
252c602c | 1192 | }); |
002f9f07 | 1193 | |
45fc1883 BH |
1194 | // Only create experiment when option is selected and |
1195 | // if there has been at least one trace imported | |
1196 | if (((importOptionFlags & OPTION_CREATE_EXPERIMENT) != 0) && (traceResources.size() > 0)) { | |
1197 | final IFolder[] experimentFolders = new IFolder[1]; | |
1198 | final TmfExperimentFolder root = fExperimentFolderElement; | |
1199 | final String experimentName = fExperimentNameText.getText().trim(); | |
1200 | // just safety guards | |
1201 | if ((root == null) || (experimentName == null)) { | |
1202 | return true; | |
1203 | } | |
1204 | if ((operationStatus[0] != null) && (operationStatus[0].isOK())) { | |
1205 | getContainer().run(true, true, new IRunnableWithProgress() { | |
1206 | @Override | |
1207 | public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { | |
1208 | operationStatus[0] = null; | |
1209 | final NewExperimentOperation operation = new NewExperimentOperation(root, experimentName); | |
1210 | operation.run(monitor); | |
1211 | monitor.done(); | |
1212 | operationStatus[0] = operation.getStatus(); | |
1213 | experimentFolders[0] = operation.getExperimentFolder(); | |
1214 | } | |
1215 | }); | |
1216 | ||
1217 | final IFolder expFolder = experimentFolders[0]; | |
1218 | final TmfTraceFolder parentTraceFolder = fTraceFolderElement; | |
1219 | // just safety guards | |
1220 | if ((expFolder == null) || (parentTraceFolder == null)) { | |
1221 | return true; | |
1222 | } | |
1223 | if ((operationStatus[0] != null) && (operationStatus[0].isOK())) { | |
1224 | getContainer().run(true, true, new IRunnableWithProgress() { | |
1225 | @Override | |
1226 | public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { | |
1227 | operationStatus[0] = null; | |
1228 | final SelectTracesOperation operation = new SelectTracesOperation(root, expFolder, parentTraceFolder, traceResources); | |
1229 | operation.run(monitor); | |
1230 | monitor.done(); | |
1231 | operationStatus[0] = operation.getStatus(); | |
1232 | } | |
1233 | }); | |
1234 | } | |
1235 | } | |
1236 | } | |
252c602c | 1237 | } catch (InvocationTargetException e) { |
f17bb886 | 1238 | operationStatus[0] = new Status(IStatus.ERROR, Activator.PLUGIN_ID, Messages.ImportTraceWizard_ImportProblem, e.getTargetException()); |
252c602c | 1239 | } catch (InterruptedException e) { |
f17bb886 | 1240 | operationStatus[0] = Status.CANCEL_STATUS; |
ba560b10 | 1241 | } |
f17bb886 MAL |
1242 | if (!operationStatus[0].isOK()) { |
1243 | if (operationStatus[0].getSeverity() == IStatus.CANCEL) { | |
ba560b10 MK |
1244 | setMessage(Messages.ImportTraceWizard_ImportOperationCancelled); |
1245 | setErrorMessage(null); | |
1246 | } else { | |
f17bb886 MAL |
1247 | Throwable exception = operationStatus[0].getException(); |
1248 | if (exception != null) { | |
1249 | Activator.getDefault().logError(exception.getMessage(), exception); | |
1250 | displayErrorDialog(operationStatus[0].getMessage() + ": " + exception); //$NON-NLS-1$ | |
002f9f07 | 1251 | } |
ba560b10 MK |
1252 | setMessage(null); |
1253 | setErrorMessage(Messages.ImportTraceWizard_ImportProblem); | |
252c602c | 1254 | } |
ba560b10 | 1255 | return false; |
252c602c | 1256 | } |
252c602c BH |
1257 | setErrorMessage(null); |
1258 | return true; | |
1259 | } | |
002f9f07 | 1260 | |
d0e34947 MAL |
1261 | /** |
1262 | * Get the trace type id to import as. This can also return | |
1263 | * {@link #TRACE_TYPE_AUTO_DETECT} to communicate that automatic trace type | |
1264 | * detection will occur instead of setting a specific trace type when | |
1265 | * importing the traces. | |
1266 | * | |
1267 | * @return the trace type id or {@link #TRACE_TYPE_AUTO_DETECT} | |
1268 | */ | |
1269 | protected String getImportTraceTypeId() { | |
1270 | return fTraceTypes.getText(); | |
1271 | } | |
1272 | ||
1273 | /** | |
1274 | * Get import options in the form of flags (bits). | |
1275 | * | |
1276 | * @return the import flags. | |
1277 | * @see #OPTION_CREATE_LINKS_IN_WORKSPACE | |
1278 | * @see #OPTION_IMPORT_UNRECOGNIZED_TRACES | |
1279 | * @see #OPTION_OVERWRITE_EXISTING_RESOURCES | |
1280 | * @see #OPTION_PRESERVE_FOLDER_STRUCTURE | |
45fc1883 | 1281 | * @see #OPTION_CREATE_EXPERIMENT |
d0e34947 MAL |
1282 | */ |
1283 | protected int getImportOptionFlags() { | |
1284 | int flags = 0; | |
1285 | if (fCreateLinksInWorkspaceButton != null && fCreateLinksInWorkspaceButton.getSelection()) { | |
1286 | flags |= OPTION_CREATE_LINKS_IN_WORKSPACE; | |
1287 | } | |
1288 | if (fImportUnrecognizedButton != null && fImportUnrecognizedButton.getSelection()) { | |
1289 | flags |= OPTION_IMPORT_UNRECOGNIZED_TRACES; | |
1290 | } | |
1291 | if (fOverwriteExistingResourcesCheckbox != null && fOverwriteExistingResourcesCheckbox.getSelection()) { | |
1292 | flags |= OPTION_OVERWRITE_EXISTING_RESOURCES; | |
1293 | } | |
1294 | if (fPreserveFolderStructureButton != null && fPreserveFolderStructureButton.getSelection()) { | |
1295 | flags |= OPTION_PRESERVE_FOLDER_STRUCTURE; | |
1296 | } | |
45fc1883 BH |
1297 | if (fCreateExperimentCheckbox != null && fCreateExperimentCheckbox.getSelection()) { |
1298 | flags |= OPTION_CREATE_EXPERIMENT; | |
1299 | } | |
d0e34947 MAL |
1300 | return flags; |
1301 | } | |
1302 | ||
c8cf44dc MAL |
1303 | @Override |
1304 | public void dispose() { | |
1305 | super.dispose(); | |
1306 | disposeSelectionGroupRoot(); | |
1307 | } | |
002f9f07 | 1308 | } |