1 /*******************************************************************************
2 * Copyright (c) 2009, 2015 Ericsson and others.
4 * All rights reserved. This program and the accompanying materials are
5 * made available under the terms of the Eclipse Public License v1.0 which
6 * accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
10 * 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
16 * Bernd Hufmann - Re-design of trace selection and trace validation
17 * Marc-Andre Laperle - Preserve folder structure on import
18 *******************************************************************************/
20 package org
.eclipse
.tracecompass
.internal
.tmf
.ui
.project
.wizards
.importtrace
;
23 import java
.io
.IOException
;
24 import java
.io
.InputStream
;
25 import java
.lang
.reflect
.InvocationTargetException
;
27 import java
.util
.ArrayList
;
28 import java
.util
.Collection
;
29 import java
.util
.HashMap
;
30 import java
.util
.Iterator
;
31 import java
.util
.List
;
33 import java
.util
.zip
.ZipEntry
;
34 import java
.util
.zip
.ZipException
;
35 import java
.util
.zip
.ZipFile
;
37 import org
.eclipse
.core
.resources
.IContainer
;
38 import org
.eclipse
.core
.resources
.IFolder
;
39 import org
.eclipse
.core
.resources
.IProject
;
40 import org
.eclipse
.core
.resources
.IResource
;
41 import org
.eclipse
.core
.resources
.ResourcesPlugin
;
42 import org
.eclipse
.core
.runtime
.CoreException
;
43 import org
.eclipse
.core
.runtime
.IPath
;
44 import org
.eclipse
.core
.runtime
.IProgressMonitor
;
45 import org
.eclipse
.core
.runtime
.IStatus
;
46 import org
.eclipse
.core
.runtime
.NullProgressMonitor
;
47 import org
.eclipse
.core
.runtime
.Path
;
48 import org
.eclipse
.core
.runtime
.Platform
;
49 import org
.eclipse
.core
.runtime
.Status
;
50 import org
.eclipse
.core
.runtime
.SubMonitor
;
51 import org
.eclipse
.core
.runtime
.SubProgressMonitor
;
52 import org
.eclipse
.core
.runtime
.URIUtil
;
53 import org
.eclipse
.jface
.dialogs
.IDialogSettings
;
54 import org
.eclipse
.jface
.layout
.PixelConverter
;
55 import org
.eclipse
.jface
.operation
.IRunnableWithProgress
;
56 import org
.eclipse
.jface
.operation
.ModalContext
;
57 import org
.eclipse
.jface
.viewers
.CheckStateChangedEvent
;
58 import org
.eclipse
.jface
.viewers
.ICheckStateListener
;
59 import org
.eclipse
.jface
.viewers
.IStructuredSelection
;
60 import org
.eclipse
.jface
.viewers
.ITreeContentProvider
;
61 import org
.eclipse
.swt
.SWT
;
62 import org
.eclipse
.swt
.custom
.BusyIndicator
;
63 import org
.eclipse
.swt
.events
.FocusAdapter
;
64 import org
.eclipse
.swt
.events
.FocusEvent
;
65 import org
.eclipse
.swt
.events
.ModifyEvent
;
66 import org
.eclipse
.swt
.events
.ModifyListener
;
67 import org
.eclipse
.swt
.events
.SelectionAdapter
;
68 import org
.eclipse
.swt
.events
.SelectionEvent
;
69 import org
.eclipse
.swt
.events
.TraverseEvent
;
70 import org
.eclipse
.swt
.events
.TraverseListener
;
71 import org
.eclipse
.swt
.layout
.GridData
;
72 import org
.eclipse
.swt
.layout
.GridLayout
;
73 import org
.eclipse
.swt
.widgets
.Button
;
74 import org
.eclipse
.swt
.widgets
.Combo
;
75 import org
.eclipse
.swt
.widgets
.Composite
;
76 import org
.eclipse
.swt
.widgets
.DirectoryDialog
;
77 import org
.eclipse
.swt
.widgets
.Event
;
78 import org
.eclipse
.swt
.widgets
.FileDialog
;
79 import org
.eclipse
.swt
.widgets
.Group
;
80 import org
.eclipse
.swt
.widgets
.Label
;
81 import org
.eclipse
.tracecompass
.internal
.tmf
.ui
.Activator
;
82 import org
.eclipse
.tracecompass
.tmf
.core
.TmfCommonConstants
;
83 import org
.eclipse
.tracecompass
.tmf
.core
.TmfProjectNature
;
84 import org
.eclipse
.tracecompass
.tmf
.core
.project
.model
.TmfTraceImportException
;
85 import org
.eclipse
.tracecompass
.tmf
.core
.project
.model
.TmfTraceType
;
86 import org
.eclipse
.tracecompass
.tmf
.core
.project
.model
.TraceTypeHelper
;
87 import org
.eclipse
.tracecompass
.tmf
.ui
.project
.model
.TmfProjectElement
;
88 import org
.eclipse
.tracecompass
.tmf
.ui
.project
.model
.TmfProjectRegistry
;
89 import org
.eclipse
.tracecompass
.tmf
.ui
.project
.model
.TmfTraceFolder
;
90 import org
.eclipse
.tracecompass
.tmf
.ui
.project
.model
.TmfTraceTypeUIUtils
;
91 import org
.eclipse
.tracecompass
.tmf
.ui
.project
.model
.TmfTracesFolder
;
92 import org
.eclipse
.ui
.dialogs
.FileSystemElement
;
93 import org
.eclipse
.ui
.dialogs
.IOverwriteQuery
;
94 import org
.eclipse
.ui
.dialogs
.WizardResourceImportPage
;
95 import org
.eclipse
.ui
.internal
.ide
.DialogUtil
;
96 import org
.eclipse
.ui
.internal
.ide
.dialogs
.IElementFilter
;
97 import org
.eclipse
.ui
.internal
.wizards
.datatransfer
.ArchiveFileManipulations
;
98 import org
.eclipse
.ui
.internal
.wizards
.datatransfer
.ILeveledImportStructureProvider
;
99 import org
.eclipse
.ui
.internal
.wizards
.datatransfer
.TarEntry
;
100 import org
.eclipse
.ui
.internal
.wizards
.datatransfer
.TarException
;
101 import org
.eclipse
.ui
.internal
.wizards
.datatransfer
.TarFile
;
102 import org
.eclipse
.ui
.internal
.wizards
.datatransfer
.TarLeveledStructureProvider
;
103 import org
.eclipse
.ui
.internal
.wizards
.datatransfer
.ZipLeveledStructureProvider
;
104 import org
.eclipse
.ui
.model
.AdaptableList
;
105 import org
.eclipse
.ui
.model
.WorkbenchContentProvider
;
106 import org
.eclipse
.ui
.model
.WorkbenchLabelProvider
;
107 import org
.eclipse
.ui
.model
.WorkbenchViewerComparator
;
108 import org
.eclipse
.ui
.wizards
.datatransfer
.FileSystemStructureProvider
;
109 import org
.eclipse
.ui
.wizards
.datatransfer
.IImportStructureProvider
;
110 import org
.eclipse
.ui
.wizards
.datatransfer
.ImportOperation
;
113 * A variant of the standard resource import wizard for importing traces to
114 * given tracing project. If no project or tracing project was selected the
115 * wizard imports it to the default tracing project which is created if
118 * In our case traces could be files or a directory structure. This wizard
119 * supports both cases. It imports traces for a selected trace type or, if no
120 * trace type is selected, it tries to detect the trace type automatically.
121 * However, the automatic detection is a best-effort and cannot guarantee that
122 * the detection is successful. The reason for this is that there might be
123 * multiple trace types that can be assigned to a single trace.
126 * @author Francois Chouinard
128 @SuppressWarnings("restriction")
129 public class ImportTraceWizardPage
extends WizardResourceImportPage
{
131 // ------------------------------------------------------------------------
133 // ------------------------------------------------------------------------
134 private static final String IMPORT_WIZARD_PAGE_NAME
= "ImportTraceWizardPage"; //$NON-NLS-1$
135 private static final String IMPORT_WIZARD_ROOT_DIRECTORY_ID
= ".import_root_directory_id"; //$NON-NLS-1$;
136 private static final String IMPORT_WIZARD_ARCHIVE_FILE_NAME_ID
= ".import_archive_file_name_id"; //$NON-NLS-1$
137 private static final String IMPORT_WIZARD_IMPORT_UNRECOGNIZED_ID
= ".import_unrecognized_traces_id"; //$NON-NLS-1$
138 private static final String IMPORT_WIZARD_PRESERVE_FOLDERS_ID
= ".import_preserve_folders_id"; //$NON-NLS-1$
139 private static final String IMPORT_WIZARD_IMPORT_FROM_DIRECTORY_ID
= ".import_from_directory"; //$NON-NLS-1$
141 // constant from WizardArchiveFileResourceImportPage1
142 private static final String
[] FILE_IMPORT_MASK
= { "*.jar;*.zip;*.tar;*.tar.gz;*.tgz", "*.*" }; //$NON-NLS-1$ //$NON-NLS-2$
143 private static final String TRACE_IMPORT_TEMP_FOLDER
= ".traceImport"; //$NON-NLS-1$
146 * A special trace type value to communicate that automatic trace type
147 * detection will occur instead of setting a specific trace type when
148 * importing the traces.
150 public static final String TRACE_TYPE_AUTO_DETECT
= Messages
.ImportTraceWizard_AutoDetection
;
153 * Preserve the folder structure of the import traces.
155 public static final int OPTION_PRESERVE_FOLDER_STRUCTURE
= 1 << 1;
157 * Create links to the trace files instead of copies.
159 public static final int OPTION_CREATE_LINKS_IN_WORKSPACE
= 1 << 2;
161 * Import files that were not recognized as the selected trace type.
163 public static final int OPTION_IMPORT_UNRECOGNIZED_TRACES
= 1 << 3;
165 * Overwrite existing resources without prompting.
167 public static final int OPTION_OVERWRITE_EXISTING_RESOURCES
= 1 << 4;
169 // ------------------------------------------------------------------------
171 // ------------------------------------------------------------------------
173 // Target import directory ('Traces' folder)
174 private IFolder fTargetFolder
;
175 // Target Trace folder element
176 private TmfTraceFolder fTraceFolderElement
;
177 // Flag to handle destination folder change event
178 private Boolean fIsDestinationChanged
= false;
179 // Combo box containing trace types
180 private Combo fTraceTypes
;
181 // Button to ignore unrecognized traces or not
182 private Button fImportUnrecognizedButton
;
183 // Button to overwrite existing resources or not
184 private Button fOverwriteExistingResourcesCheckbox
;
185 // Button to link or copy traces to workspace
186 private Button fCreateLinksInWorkspaceButton
;
187 // Button to preserve folder structure
188 private Button fPreserveFolderStructureButton
;
189 private boolean entryChanged
= false;
190 // The import from directory radio button
191 private Button fImportFromDirectoryRadio
;
192 // The import from archive radio button
193 private Button fImportFromArchiveRadio
;
194 // Flag to remember the "create links" checkbox when it gets disabled by
195 // the import from archive radio button
196 private Boolean fPreviousCreateLinksValue
= true;
198 /** The archive name field */
199 protected Combo fArchiveNameField
;
200 /** The archive browse button. */
201 protected Button fArchiveBrowseButton
;
202 /** The directory name field */
203 protected Combo directoryNameField
;
204 /** The directory browse button. */
205 protected Button directoryBrowseButton
;
208 * ResourceTreeAndListGroup was internal in Kepler and we referenced it. It
209 * is now removed in Luna. To keep our builds compatible with Kepler, we
210 * need to have our own version of this class. Once we stop supporting
211 * Kepler, we can delete this class and use the public one from the
214 private ResourceTreeAndListGroup fSelectionGroup
;
216 // Keep trace of the selection root so that we can dispose its related
218 private TraceFileSystemElement fSelectionGroupRoot
;
220 // ------------------------------------------------------------------------
222 // ------------------------------------------------------------------------
225 * Constructor. Creates the trace wizard page.
228 * The name of the page.
230 * The current selection
232 protected ImportTraceWizardPage(String name
, IStructuredSelection selection
) {
233 super(name
, selection
);
234 setTitle(Messages
.ImportTraceWizard_FileSystemTitle
);
235 setDescription(Messages
.ImportTraceWizard_ImportTrace
);
237 // Locate the target trace folder
238 IFolder traceFolder
= null;
239 Object element
= selection
.getFirstElement();
241 if (element
instanceof TmfTraceFolder
) {
242 fTraceFolderElement
= (TmfTraceFolder
) element
;
243 traceFolder
= fTraceFolderElement
.getResource();
244 } else if (element
instanceof IProject
) {
245 IProject project
= (IProject
) element
;
247 if (project
.hasNature(TmfProjectNature
.ID
)) {
248 TmfProjectElement projectElement
= TmfProjectRegistry
.getProject(project
, true);
249 fTraceFolderElement
= projectElement
.getTracesFolder();
250 traceFolder
= project
.getFolder(TmfTracesFolder
.TRACES_FOLDER_NAME
);
252 } catch (CoreException e
) {
256 // If no tracing project was selected or trace folder doesn't exist use
257 // default tracing project
258 if (traceFolder
== null) {
259 IProject project
= TmfProjectRegistry
.createProject(
260 TmfCommonConstants
.DEFAULT_TRACE_PROJECT_NAME
, null, new NullProgressMonitor());
261 TmfProjectElement projectElement
= TmfProjectRegistry
.getProject(project
, true);
262 fTraceFolderElement
= projectElement
.getTracesFolder();
263 traceFolder
= project
.getFolder(TmfTracesFolder
.TRACES_FOLDER_NAME
);
266 // Set the target trace folder
267 if (traceFolder
!= null) {
268 fTargetFolder
= traceFolder
;
269 String path
= traceFolder
.getFullPath().toString();
270 setContainerFieldValue(path
);
278 * The current selection
280 public ImportTraceWizardPage(IStructuredSelection selection
) {
281 this(IMPORT_WIZARD_PAGE_NAME
, selection
);
285 * Create the import source selection widget. (Copied from
286 * WizardResourceImportPage but instead always uses the internal
287 * ResourceTreeAndListGroup to keep compatibility with Kepler)
290 protected void createFileSelectionGroup(Composite parent
) {
292 // Just create with a dummy root.
293 fSelectionGroup
= new ResourceTreeAndListGroup(parent
,
294 new FileSystemElement("Dummy", null, true),//$NON-NLS-1$
295 getFolderProvider(), new WorkbenchLabelProvider(),
296 getFileProvider(), new WorkbenchLabelProvider(), SWT
.NONE
,
297 DialogUtil
.inRegularFontMode(parent
));
299 ICheckStateListener listener
= new ICheckStateListener() {
301 public void checkStateChanged(CheckStateChangedEvent event
) {
302 updateWidgetEnablements();
306 WorkbenchViewerComparator comparator
= new WorkbenchViewerComparator();
307 fSelectionGroup
.setTreeComparator(comparator
);
308 fSelectionGroup
.setListComparator(comparator
);
309 fSelectionGroup
.addCheckStateListener(listener
);
313 // ------------------------------------------------------------------------
314 // WizardResourceImportPage
315 // ------------------------------------------------------------------------
318 protected void createSourceGroup(Composite parent
) {
319 createSourceSelectionGroup(parent
);
320 createFileSelectionGroup(parent
);
321 createTraceTypeGroup(parent
);
322 validateSourceGroup();
326 protected ITreeContentProvider
getFileProvider() {
327 return new WorkbenchContentProvider() {
329 public Object
[] getChildren(Object object
) {
330 if (object
instanceof TraceFileSystemElement
) {
331 TraceFileSystemElement element
= (TraceFileSystemElement
) object
;
332 return element
.getFiles().getChildren(element
);
334 return new Object
[0];
340 protected ITreeContentProvider
getFolderProvider() {
341 return new WorkbenchContentProvider() {
343 public Object
[] getChildren(Object o
) {
344 if (o
instanceof TraceFileSystemElement
) {
345 TraceFileSystemElement element
= (TraceFileSystemElement
) o
;
346 return element
.getFolders().getChildren();
348 return new Object
[0];
352 public boolean hasChildren(Object o
) {
353 if (o
instanceof TraceFileSystemElement
) {
354 TraceFileSystemElement element
= (TraceFileSystemElement
) o
;
355 if (element
.isPopulated()) {
356 return getChildren(element
).length
> 0;
358 // If we have not populated then wait until asked
366 // ------------------------------------------------------------------------
367 // Directory Selection Group (forked WizardFileSystemResourceImportPage1)
368 // ------------------------------------------------------------------------
371 * creates the source selection group.
374 * the parent composite
376 protected void createSourceSelectionGroup(Composite parent
) {
378 Composite sourceGroup
= new Composite(parent
, SWT
.NONE
);
379 GridLayout layout
= new GridLayout();
380 layout
.numColumns
= 3;
381 layout
.makeColumnsEqualWidth
= false;
382 layout
.marginWidth
= 0;
383 sourceGroup
.setLayout(layout
);
384 sourceGroup
.setLayoutData(new GridData(GridData
.FILL_HORIZONTAL
));
386 // import from directory radio button
387 fImportFromDirectoryRadio
= new Button(sourceGroup
, SWT
.RADIO
);
388 fImportFromDirectoryRadio
389 .setText(Messages
.ImportTraceWizard_DirectoryLocation
);
391 // import location entry combo
392 directoryNameField
= createPathSelectionCombo(sourceGroup
);
393 createDirectoryBrowseButton(sourceGroup
);
395 // import from archive radio button
396 fImportFromArchiveRadio
= new Button(sourceGroup
, SWT
.RADIO
);
397 fImportFromArchiveRadio
398 .setText(Messages
.ImportTraceWizard_ArchiveLocation
);
400 // import location entry combo
401 fArchiveNameField
= createPathSelectionCombo(sourceGroup
);
402 createArchiveBrowseButton(sourceGroup
);
404 fImportFromDirectoryRadio
.setSelection(true);
405 fArchiveNameField
.setEnabled(false);
406 fArchiveBrowseButton
.setEnabled(false);
408 fImportFromDirectoryRadio
.addSelectionListener(new SelectionAdapter() {
410 public void widgetSelected(SelectionEvent e
) {
411 directoryRadioSelected();
415 fImportFromArchiveRadio
.addSelectionListener(new SelectionAdapter() {
417 public void widgetSelected(SelectionEvent e
) {
418 archiveRadioSelected();
424 * Select or deselect all files in the file selection group
427 * whether or not the files should be checked
429 protected void setFileSelectionGroupChecked(boolean checked
) {
430 if (fSelectionGroup
!= null) {
431 fSelectionGroup
.setAllSelections(checked
);
436 * Create a combo that will be used to select a path to specify the source
437 * of the import. The parent is assumed to have a GridLayout.
440 * the parent composite
441 * @return the created path selection combo
443 protected Combo
createPathSelectionCombo(Composite parent
) {
444 Combo pathSelectionCombo
= new Combo(parent
, SWT
.BORDER
);
446 GridData layoutData
= new GridData(GridData
.HORIZONTAL_ALIGN_FILL
| GridData
.GRAB_HORIZONTAL
);
447 layoutData
.widthHint
= new PixelConverter(pathSelectionCombo
).convertWidthInCharsToPixels(25);
448 pathSelectionCombo
.setLayoutData(layoutData
);
450 TraverseListener traverseListener
= new TraverseListener() {
452 public void keyTraversed(TraverseEvent e
) {
453 if (e
.detail
== SWT
.TRAVERSE_RETURN
) {
455 entryChanged
= false;
456 updateFromSourceField();
461 FocusAdapter focusAdapter
= new FocusAdapter() {
463 public void focusLost(FocusEvent e
) {
464 // Clear the flag to prevent constant update
466 entryChanged
= false;
467 updateFromSourceField();
472 SelectionAdapter selectionAdapter
= new SelectionAdapter() {
474 public void widgetSelected(SelectionEvent e
) {
475 entryChanged
= false;
476 updateFromSourceField();
480 ModifyListener modifyListner
= new ModifyListener() {
482 public void modifyText(ModifyEvent e
) {
487 pathSelectionCombo
.addModifyListener(modifyListner
);
488 pathSelectionCombo
.addTraverseListener(traverseListener
);
489 pathSelectionCombo
.addFocusListener(focusAdapter
);
490 pathSelectionCombo
.addSelectionListener(selectionAdapter
);
492 return pathSelectionCombo
;
496 * Create the directory browse button.
499 * the parent composite
501 protected void createDirectoryBrowseButton(Composite parent
) {
502 directoryBrowseButton
= createPathSelectionBrowseButton(parent
);
503 directoryBrowseButton
.addSelectionListener(new SelectionAdapter() {
505 public void widgetSelected(SelectionEvent e
) {
506 handleSourceDirectoryBrowseButtonPressed();
512 * Create the archive browse button.
515 * the parent composite
517 protected void createArchiveBrowseButton(Composite parent
) {
518 fArchiveBrowseButton
= createPathSelectionBrowseButton(parent
);
519 fArchiveBrowseButton
.addSelectionListener(new SelectionAdapter() {
521 public void widgetSelected(SelectionEvent e
) {
522 handleArchiveBrowseButtonPressed(FILE_IMPORT_MASK
);
528 * Create a browse button that will be used to browse for a path to specify
529 * the source of the import. The parent is assumed to have a GridLayout.
532 * the parent composite
533 * @return the created path selection combo
535 protected Button
createPathSelectionBrowseButton(Composite parent
) {
536 Button pathSelectionBrowseButton
= new Button(parent
, SWT
.PUSH
);
537 pathSelectionBrowseButton
.setText(Messages
.ImportTraceWizard_BrowseButton
);
538 setButtonLayoutData(pathSelectionBrowseButton
);
540 return pathSelectionBrowseButton
;
543 private void archiveRadioSelected() {
544 if (!isImportFromDirectory()) {
545 directoryNameField
.setEnabled(false);
546 directoryBrowseButton
.setEnabled(false);
547 fArchiveNameField
.setEnabled(true);
548 fArchiveBrowseButton
.setEnabled(true);
549 updateFromSourceField();
550 fArchiveNameField
.setFocus();
551 if (fCreateLinksInWorkspaceButton
!= null) {
552 fPreviousCreateLinksValue
= fCreateLinksInWorkspaceButton
.getSelection();
553 fCreateLinksInWorkspaceButton
.setSelection(false);
554 fCreateLinksInWorkspaceButton
.setEnabled(false);
559 private void directoryRadioSelected() {
560 if (isImportFromDirectory()) {
561 directoryNameField
.setEnabled(true);
562 directoryBrowseButton
.setEnabled(true);
563 fArchiveNameField
.setEnabled(false);
564 fArchiveBrowseButton
.setEnabled(false);
565 updateFromSourceField();
566 directoryNameField
.setFocus();
567 if (fCreateLinksInWorkspaceButton
!= null) {
568 fCreateLinksInWorkspaceButton
.setSelection(fPreviousCreateLinksValue
);
569 fCreateLinksInWorkspaceButton
.setEnabled(true);
574 // ------------------------------------------------------------------------
575 // Browse for the source directory
576 // ------------------------------------------------------------------------
579 public void handleEvent(Event event
) {
580 if (event
.widget
== directoryBrowseButton
) {
581 handleSourceDirectoryBrowseButtonPressed();
584 // Avoid overwriting destination path without repeatedly trigger
585 // call of handleEvent();
586 synchronized (fIsDestinationChanged
) {
587 if (fIsDestinationChanged
== false) {
588 event
.display
.asyncExec(new Runnable() {
591 synchronized (fIsDestinationChanged
) {
592 fIsDestinationChanged
= true;
593 String path
= fTargetFolder
.getFullPath().toString();
594 setContainerFieldValue(path
);
599 fIsDestinationChanged
= false;
602 super.handleEvent(event
);
606 protected void handleContainerBrowseButtonPressed() {
607 // Do nothing so that destination directory cannot be changed.
611 * Handle the button pressed event
613 protected void handleSourceDirectoryBrowseButtonPressed() {
614 String currentSource
= directoryNameField
.getText();
615 DirectoryDialog dialog
= new DirectoryDialog(directoryNameField
.getShell(), SWT
.SAVE
| SWT
.SHEET
);
616 dialog
.setText(Messages
.ImportTraceWizard_SelectTraceDirectoryTitle
);
617 dialog
.setMessage(Messages
.ImportTraceWizard_SelectTraceDirectoryMessage
);
618 dialog
.setFilterPath(getSourceDirectoryName(currentSource
));
620 String selectedDirectory
= dialog
.open();
621 if (selectedDirectory
!= null) {
622 // Just quit if the directory is not valid
623 if ((getSourceDirectory(selectedDirectory
) == null) || selectedDirectory
.equals(currentSource
)) {
626 // If it is valid then proceed to populate
627 setErrorMessage(null);
628 setSourcePath(selectedDirectory
);
633 * Handle the button pressed event
636 * file extensions used to filter files shown to the user
638 protected void handleArchiveBrowseButtonPressed(String
[] extensions
) {
639 FileDialog dialog
= new FileDialog(fArchiveNameField
.getShell(), SWT
.SHEET
);
640 dialog
.setFilterExtensions(extensions
);
641 dialog
.setText(Messages
.ImportTraceWizard_SelectTraceArchiveTitle
);
642 String fileName
= fArchiveNameField
.getText().trim();
643 if (!fileName
.isEmpty()) {
644 File path
= new File(fileName
).getParentFile();
645 if (path
!= null && path
.exists()) {
646 dialog
.setFilterPath(path
.toString());
650 String selectedArchive
= dialog
.open();
651 if (selectedArchive
!= null) {
652 setErrorMessage(null);
653 setSourcePath(selectedArchive
);
654 updateWidgetEnablements();
658 private File
getSourceDirectory() {
659 if (directoryNameField
== null) {
662 return getSourceDirectory(directoryNameField
.getText());
665 private File
getSourceArchiveFile() {
666 if (fArchiveNameField
== null) {
670 return getSourceArchiveFile(fArchiveNameField
.getText());
673 private String
getSourceContainerPath() {
674 if (isImportFromDirectory()) {
675 File sourceDirectory
= getSourceDirectory();
676 if (sourceDirectory
!= null) {
677 return sourceDirectory
.getAbsolutePath();
680 File sourceArchiveFile
= getSourceArchiveFile();
681 if (sourceArchiveFile
!= null) {
682 return sourceArchiveFile
.getParent();
687 private static File
getSourceDirectory(String path
) {
688 File sourceDirectory
= new File(getSourceDirectoryName(path
));
689 if (!sourceDirectory
.exists() || !sourceDirectory
.isDirectory()) {
693 return sourceDirectory
;
696 private static File
getSourceArchiveFile(String path
) {
697 File sourceArchiveFile
= new File(path
);
698 if (!sourceArchiveFile
.exists() || sourceArchiveFile
.isDirectory()) {
702 return sourceArchiveFile
;
705 private static String
getSourceDirectoryName(String sourceName
) {
706 IPath result
= new Path(sourceName
.trim());
707 if (result
.getDevice() != null && result
.segmentCount() == 0) {
708 result
= result
.addTrailingSeparator();
710 result
= result
.removeTrailingSeparator();
712 return result
.toOSString();
715 private void updateFromSourceField() {
716 setSourcePath(getSourceField().getText());
717 updateWidgetEnablements();
720 private Combo
getSourceField() {
721 if (directoryNameField
== null) {
722 return fArchiveNameField
;
725 return directoryNameField
.isEnabled() ? directoryNameField
: fArchiveNameField
;
729 * Set the source path that was selected by the user by various input
730 * methods (Browse button, typing, etc).
732 * Clients can also call this to set the path programmatically (hard-coded
733 * initial path) and this can also be overridden to be notified when the
734 * source path changes.
739 protected void setSourcePath(String path
) {
740 Combo sourceField
= getSourceField();
741 if (sourceField
== null) {
745 if (path
.length() > 0) {
746 String
[] currentItems
= sourceField
.getItems();
747 int selectionIndex
= -1;
748 for (int i
= 0; i
< currentItems
.length
; i
++) {
749 if (currentItems
[i
].equals(path
)) {
753 if (selectionIndex
< 0) {
754 int oldLength
= currentItems
.length
;
755 String
[] newItems
= new String
[oldLength
+ 1];
756 System
.arraycopy(currentItems
, 0, newItems
, 0, oldLength
);
757 newItems
[oldLength
] = path
;
758 sourceField
.setItems(newItems
);
759 selectionIndex
= oldLength
;
761 sourceField
.select(selectionIndex
);
766 // ------------------------------------------------------------------------
767 // File Selection Group (forked WizardFileSystemResourceImportPage1)
768 // ------------------------------------------------------------------------
769 private void resetSelection() {
770 if (fSelectionGroupRoot
!= null) {
771 disposeSelectionGroupRoot();
773 fSelectionGroupRoot
= getFileSystemTree();
774 fSelectionGroup
.setRoot(fSelectionGroupRoot
);
777 private void disposeSelectionGroupRoot() {
778 if (fSelectionGroupRoot
!= null && fSelectionGroupRoot
.getProvider() != null) {
779 FileSystemObjectImportStructureProvider provider
= fSelectionGroupRoot
.getProvider();
781 fSelectionGroupRoot
= null;
785 private TraceFileSystemElement
getFileSystemTree() {
786 IFileSystemObject rootElement
= null;
787 FileSystemObjectImportStructureProvider importStructureProvider
= null;
789 // Import from directory
790 if (isImportFromDirectory()) {
791 importStructureProvider
= new FileSystemObjectImportStructureProvider(FileSystemStructureProvider
.INSTANCE
, null);
792 File sourceDirectory
= getSourceDirectory();
793 if (sourceDirectory
== null) {
796 rootElement
= importStructureProvider
.getIFileSystemObject(sourceDirectory
);
798 // Import from archive
799 FileSystemObjectLeveledImportStructureProvider leveledImportStructureProvider
= null;
800 String archivePath
= getSourceArchiveFile() != null ?
getSourceArchiveFile().getAbsolutePath() : ""; //$NON-NLS-1$
801 if (ArchiveFileManipulations
.isTarFile(archivePath
)) {
802 if (ensureTarSourceIsValid(archivePath
)) {
803 // We close the file when we dispose the import provider,
804 // see disposeSelectionGroupRoot
805 TarFile tarFile
= getSpecifiedTarSourceFile(archivePath
);
806 leveledImportStructureProvider
= new FileSystemObjectLeveledImportStructureProvider(new TarLeveledStructureProvider(tarFile
), archivePath
);
808 } else if (ensureZipSourceIsValid(archivePath
)) {
809 // We close the file when we dispose the import provider, see
810 // disposeSelectionGroupRoot
811 @SuppressWarnings("resource")
812 ZipFile zipFile
= getSpecifiedZipSourceFile(archivePath
);
813 leveledImportStructureProvider
= new FileSystemObjectLeveledImportStructureProvider(new ZipLeveledStructureProvider(zipFile
), archivePath
);
815 if (leveledImportStructureProvider
== null) {
818 rootElement
= leveledImportStructureProvider
.getRoot();
819 importStructureProvider
= leveledImportStructureProvider
;
822 if (rootElement
== null) {
826 return selectFiles(rootElement
, importStructureProvider
);
830 * An import provider that makes use of the IFileSystemObject abstraction
831 * instead of using plain file system objects (File, TarEntry, ZipEntry)
833 private static class FileSystemObjectImportStructureProvider
implements IImportStructureProvider
{
835 private IImportStructureProvider fImportProvider
;
836 private String fArchivePath
;
838 private FileSystemObjectImportStructureProvider(IImportStructureProvider importStructureProvider
, String archivePath
) {
839 fImportProvider
= importStructureProvider
;
840 fArchivePath
= archivePath
;
844 public List
<IFileSystemObject
> getChildren(Object element
) {
845 @SuppressWarnings("rawtypes")
846 List children
= fImportProvider
.getChildren(((IFileSystemObject
) element
).getRawFileSystemObject());
847 List
<IFileSystemObject
> adapted
= new ArrayList
<>(children
.size());
848 for (Object o
: children
) {
849 adapted
.add(getIFileSystemObject(o
));
854 public IFileSystemObject
getIFileSystemObject(Object o
) {
859 if (o
instanceof File
) {
860 return new FileFileSystemObject((File
) o
);
861 } else if (o
instanceof TarEntry
) {
862 return new TarFileSystemObject((TarEntry
) o
, fArchivePath
);
863 } else if (o
instanceof ZipEntry
) {
864 return new ZipFileSystemObject((ZipEntry
) o
, fArchivePath
);
867 throw new IllegalArgumentException("Object type not handled"); //$NON-NLS-1$
871 public InputStream
getContents(Object element
) {
872 return fImportProvider
.getContents(((IFileSystemObject
) element
).getRawFileSystemObject());
876 public String
getFullPath(Object element
) {
877 return fImportProvider
.getFullPath(((IFileSystemObject
) element
).getRawFileSystemObject());
881 public String
getLabel(Object element
) {
882 return fImportProvider
.getLabel(((IFileSystemObject
) element
).getRawFileSystemObject());
886 public boolean isFolder(Object element
) {
887 return fImportProvider
.isFolder(((IFileSystemObject
) element
).getRawFileSystemObject());
891 * Disposes of the resources associated with the provider.
893 public void dispose() {
898 * An import provider that both supports using IFileSystemObject and adds
899 * "archive functionality" by delegating to a leveled import provider
900 * (TarLeveledStructureProvider, ZipLeveledStructureProvider)
902 private static class FileSystemObjectLeveledImportStructureProvider
extends FileSystemObjectImportStructureProvider
implements ILeveledImportStructureProvider
{
904 private ILeveledImportStructureProvider fLeveledImportProvider
;
906 private FileSystemObjectLeveledImportStructureProvider(ILeveledImportStructureProvider importStructureProvider
, String archivePath
) {
907 super(importStructureProvider
, archivePath
);
908 fLeveledImportProvider
= importStructureProvider
;
912 public IFileSystemObject
getRoot() {
913 return getIFileSystemObject(fLeveledImportProvider
.getRoot());
917 public void setStrip(int level
) {
918 fLeveledImportProvider
.setStrip(level
);
922 public int getStrip() {
923 return fLeveledImportProvider
.getStrip();
927 public boolean closeArchive() {
928 return fLeveledImportProvider
.closeArchive();
932 @SuppressWarnings("resource")
933 private boolean ensureZipSourceIsValid(String archivePath
) {
934 ZipFile specifiedFile
= getSpecifiedZipSourceFile(archivePath
);
935 if (specifiedFile
== null) {
938 return ArchiveFileManipulations
.closeZipFile(specifiedFile
, getShell());
941 private boolean ensureTarSourceIsValid(String archivePath
) {
942 TarFile specifiedFile
= getSpecifiedTarSourceFile(archivePath
);
943 if (specifiedFile
== null) {
946 return ArchiveFileManipulations
.closeTarFile(specifiedFile
, getShell());
949 private static ZipFile
getSpecifiedZipSourceFile(String fileName
) {
950 if (fileName
.length() == 0) {
955 return new ZipFile(fileName
);
956 } catch (ZipException e
) {
958 } catch (IOException e
) {
965 private static TarFile
getSpecifiedTarSourceFile(String fileName
) {
966 if (fileName
.length() == 0) {
971 return new TarFile(fileName
);
972 } catch (TarException e
) {
974 } catch (IOException e
) {
981 private TraceFileSystemElement
selectFiles(final IFileSystemObject rootFileSystemObject
,
982 final FileSystemObjectImportStructureProvider structureProvider
) {
983 final TraceFileSystemElement
[] results
= new TraceFileSystemElement
[1];
984 BusyIndicator
.showWhile(getShell().getDisplay(), new Runnable() {
987 // Create the root element from the supplied file system object
988 results
[0] = createRootElement(rootFileSystemObject
, structureProvider
);
994 private static TraceFileSystemElement
createRootElement(IFileSystemObject element
,
995 FileSystemObjectImportStructureProvider provider
) {
996 boolean isContainer
= provider
.isFolder(element
);
997 String elementLabel
= provider
.getLabel(element
);
999 // Use an empty label so that display of the element's full name
1000 // doesn't include a confusing label
1001 TraceFileSystemElement dummyParent
= new TraceFileSystemElement("", null, true, provider
);//$NON-NLS-1$
1002 Object dummyParentFileSystemObject
= element
;
1003 Object rawFileSystemObject
= element
.getRawFileSystemObject();
1004 if (rawFileSystemObject
instanceof File
) {
1005 dummyParentFileSystemObject
= provider
.getIFileSystemObject(((File
) rawFileSystemObject
).getParentFile());
1007 dummyParent
.setFileSystemObject(dummyParentFileSystemObject
);
1008 dummyParent
.setPopulated();
1009 TraceFileSystemElement result
= new TraceFileSystemElement(
1010 elementLabel
, dummyParent
, isContainer
, provider
);
1011 result
.setFileSystemObject(element
);
1013 // Get the files for the element so as to build the first level
1019 // ------------------------------------------------------------------------
1021 // ------------------------------------------------------------------------
1022 private final void createTraceTypeGroup(Composite parent
) {
1023 Composite composite
= new Composite(parent
, SWT
.NONE
);
1024 GridLayout layout
= new GridLayout();
1025 layout
.numColumns
= 3;
1026 layout
.makeColumnsEqualWidth
= false;
1027 composite
.setLayout(layout
);
1028 composite
.setFont(parent
.getFont());
1029 GridData buttonData
= new GridData(SWT
.FILL
, SWT
.FILL
, true, false);
1030 composite
.setLayoutData(buttonData
);
1032 // Trace type label ("Trace Type:")
1033 Label typeLabel
= new Label(composite
, SWT
.NONE
);
1034 typeLabel
.setText(Messages
.ImportTraceWizard_TraceType
);
1035 typeLabel
.setFont(parent
.getFont());
1038 fTraceTypes
= new Combo(composite
, SWT
.BORDER
| SWT
.READ_ONLY
);
1039 GridData data
= new GridData(SWT
.FILL
, SWT
.FILL
, true, false, 2, 1);
1040 fTraceTypes
.setLayoutData(data
);
1041 fTraceTypes
.setFont(parent
.getFont());
1043 String
[] availableTraceTypes
= TmfTraceType
.getAvailableTraceTypes();
1044 String
[] traceTypeList
= new String
[availableTraceTypes
.length
+ 1];
1045 traceTypeList
[0] = TRACE_TYPE_AUTO_DETECT
;
1046 for (int i
= 0; i
< availableTraceTypes
.length
; i
++) {
1047 traceTypeList
[i
+ 1] = availableTraceTypes
[i
];
1049 fTraceTypes
.setItems(traceTypeList
);
1050 fTraceTypes
.addSelectionListener(new SelectionAdapter() {
1052 public void widgetSelected(SelectionEvent e
) {
1053 updateWidgetEnablements();
1054 boolean enabled
= fTraceTypes
.getText().equals(TRACE_TYPE_AUTO_DETECT
);
1055 fImportUnrecognizedButton
.setEnabled(enabled
);
1058 fTraceTypes
.select(0);
1060 // Unrecognized checkbox
1061 fImportUnrecognizedButton
= new Button(composite
, SWT
.CHECK
);
1062 fImportUnrecognizedButton
.setSelection(true);
1063 fImportUnrecognizedButton
.setText(Messages
.ImportTraceWizard_ImportUnrecognized
);
1066 // ------------------------------------------------------------------------
1068 // ------------------------------------------------------------------------
1071 protected void createOptionsGroupButtons(Group optionsGroup
) {
1073 // Overwrite checkbox
1074 fOverwriteExistingResourcesCheckbox
= new Button(optionsGroup
, SWT
.CHECK
);
1075 fOverwriteExistingResourcesCheckbox
.setFont(optionsGroup
.getFont());
1076 fOverwriteExistingResourcesCheckbox
.setText(Messages
.ImportTraceWizard_OverwriteExistingTrace
);
1077 fOverwriteExistingResourcesCheckbox
.setSelection(false);
1079 // Create links checkbox
1080 fCreateLinksInWorkspaceButton
= new Button(optionsGroup
, SWT
.CHECK
);
1081 fCreateLinksInWorkspaceButton
.setFont(optionsGroup
.getFont());
1082 fCreateLinksInWorkspaceButton
.setText(Messages
.ImportTraceWizard_CreateLinksInWorkspace
);
1083 fCreateLinksInWorkspaceButton
.setSelection(true);
1085 fCreateLinksInWorkspaceButton
.addSelectionListener(new SelectionAdapter() {
1087 public void widgetSelected(SelectionEvent e
) {
1088 updateWidgetEnablements();
1092 fPreserveFolderStructureButton
= new Button(optionsGroup
, SWT
.CHECK
);
1093 fPreserveFolderStructureButton
.setFont(optionsGroup
.getFont());
1094 fPreserveFolderStructureButton
.setText(Messages
.ImportTraceWizard_PreserveFolderStructure
);
1095 fPreserveFolderStructureButton
.setSelection(true);
1097 updateWidgetEnablements();
1100 // ------------------------------------------------------------------------
1101 // Determine if the finish button can be enabled
1102 // ------------------------------------------------------------------------
1104 public boolean validateSourceGroup() {
1106 File source
= isImportFromDirectory() ?
getSourceDirectory() : getSourceArchiveFile();
1107 if (source
== null) {
1108 setMessage(Messages
.ImportTraceWizard_SelectTraceSourceEmpty
);
1109 setErrorMessage(null);
1113 if (sourceConflictsWithDestination(new Path(source
.getPath()))) {
1115 setErrorMessage(getSourceConflictMessage());
1119 if (!isImportFromDirectory()) {
1120 if (!ensureTarSourceIsValid(source
.getAbsolutePath()) && !ensureZipSourceIsValid(source
.getAbsolutePath())) {
1122 setErrorMessage(Messages
.ImportTraceWizard_BadArchiveFormat
);
1127 if (fSelectionGroup
.getCheckedElementCount() == 0) {
1129 setErrorMessage(Messages
.ImportTraceWizard_SelectTraceNoneSelected
);
1133 IContainer container
= getSpecifiedContainer();
1134 if (container
!= null && container
.isVirtual()) {
1135 if (Platform
.getPreferencesService().getBoolean(Activator
.PLUGIN_ID
, ResourcesPlugin
.PREF_DISABLE_LINKING
, false, null)) {
1137 setErrorMessage(Messages
.ImportTraceWizard_CannotImportFilesUnderAVirtualFolder
);
1140 if (fCreateLinksInWorkspaceButton
== null || !fCreateLinksInWorkspaceButton
.getSelection()) {
1142 setErrorMessage(Messages
.ImportTraceWizard_HaveToCreateLinksUnderAVirtualFolder
);
1147 setErrorMessage(null);
1151 private boolean isImportFromDirectory() {
1152 return fImportFromDirectoryRadio
!= null && fImportFromDirectoryRadio
.getSelection();
1156 protected void restoreWidgetValues() {
1157 super.restoreWidgetValues();
1159 IDialogSettings settings
= getDialogSettings();
1161 if (fImportUnrecognizedButton
!= null) {
1162 if (settings
.get(getPageStoreKey(IMPORT_WIZARD_IMPORT_UNRECOGNIZED_ID
)) == null) {
1165 value
= settings
.getBoolean(getPageStoreKey(IMPORT_WIZARD_IMPORT_UNRECOGNIZED_ID
));
1167 fImportUnrecognizedButton
.setSelection(value
);
1170 if (fPreserveFolderStructureButton
!= null) {
1171 if (settings
.get(getPageStoreKey(IMPORT_WIZARD_PRESERVE_FOLDERS_ID
)) == null) {
1174 value
= settings
.getBoolean(getPageStoreKey(IMPORT_WIZARD_PRESERVE_FOLDERS_ID
));
1176 fPreserveFolderStructureButton
.setSelection(value
);
1179 if (settings
.get(getPageStoreKey(IMPORT_WIZARD_IMPORT_FROM_DIRECTORY_ID
)) == null) {
1182 value
= settings
.getBoolean(getPageStoreKey(IMPORT_WIZARD_IMPORT_FROM_DIRECTORY_ID
));
1185 if (directoryNameField
!= null) {
1186 restoreComboValues(directoryNameField
, settings
, getPageStoreKey(IMPORT_WIZARD_ROOT_DIRECTORY_ID
));
1188 if (fArchiveNameField
!= null) {
1189 restoreComboValues(fArchiveNameField
, settings
, getPageStoreKey(IMPORT_WIZARD_ARCHIVE_FILE_NAME_ID
));
1192 if (fImportFromDirectoryRadio
!= null) {
1193 fImportFromDirectoryRadio
.setSelection(value
);
1195 directoryRadioSelected();
1198 if (fImportFromArchiveRadio
!= null) {
1199 fImportFromArchiveRadio
.setSelection(!value
);
1201 archiveRadioSelected();
1207 protected void saveWidgetValues() {
1208 // Persist dialog settings
1209 IDialogSettings settings
= getDialogSettings();
1210 if (fImportUnrecognizedButton
!= null) {
1211 settings
.put(getPageStoreKey(IMPORT_WIZARD_IMPORT_UNRECOGNIZED_ID
), fImportUnrecognizedButton
.getSelection());
1213 if (fPreserveFolderStructureButton
!= null) {
1214 settings
.put(getPageStoreKey(IMPORT_WIZARD_PRESERVE_FOLDERS_ID
), fPreserveFolderStructureButton
.getSelection());
1216 settings
.put(getPageStoreKey(IMPORT_WIZARD_IMPORT_FROM_DIRECTORY_ID
), isImportFromDirectory());
1218 if (directoryNameField
!= null) {
1219 saveComboValues(directoryNameField
, settings
, getPageStoreKey(IMPORT_WIZARD_ROOT_DIRECTORY_ID
));
1221 if (fArchiveNameField
!= null) {
1222 saveComboValues(fArchiveNameField
, settings
, getPageStoreKey(IMPORT_WIZARD_ARCHIVE_FILE_NAME_ID
));
1226 private String
getPageStoreKey(String key
) {
1227 return getName() + key
;
1230 private static void restoreComboValues(Combo combo
, IDialogSettings settings
, String key
) {
1231 String
[] directoryNames
= settings
.getArray(key
);
1232 if ((directoryNames
!= null) && (directoryNames
.length
!= 0)) {
1233 for (int i
= 0; i
< directoryNames
.length
; i
++) {
1234 combo
.add(directoryNames
[i
]);
1239 private void saveComboValues(Combo combo
, IDialogSettings settings
, String key
) {
1240 // update names history
1241 String
[] directoryNames
= settings
.getArray(key
);
1242 if (directoryNames
== null) {
1243 directoryNames
= new String
[0];
1246 String items
[] = combo
.getItems();
1247 for (int i
= 0; i
< items
.length
; i
++) {
1248 directoryNames
= addToHistory(directoryNames
, items
[i
]);
1250 settings
.put(key
, directoryNames
);
1253 // ------------------------------------------------------------------------
1254 // Import the trace(s)
1255 // ------------------------------------------------------------------------
1258 * Finish the import.
1260 * @return <code>true</code> if successful else <code>false</code>
1262 public boolean finish() {
1263 String traceTypeLabel
= getImportTraceTypeId();
1264 String traceId
= null;
1265 if (!TRACE_TYPE_AUTO_DETECT
.equals(traceTypeLabel
)) {
1266 traceId
= TmfTraceType
.getTraceTypeId(traceTypeLabel
);
1269 // Save dialog settings
1272 IPath baseSourceContainerPath
= new Path(getSourceContainerPath());
1273 boolean importFromArchive
= getSourceArchiveFile() != null;
1274 int importOptionFlags
= getImportOptionFlags();
1276 final TraceValidateAndImportOperation operation
= new TraceValidateAndImportOperation(traceId
, baseSourceContainerPath
, getContainerFullPath(), importFromArchive
,
1279 IStatus status
= Status
.OK_STATUS
;
1281 getContainer().run(true, true, new IRunnableWithProgress() {
1283 public void run(IProgressMonitor monitor
) throws InvocationTargetException
, InterruptedException
{
1284 operation
.run(monitor
);
1289 status
= operation
.getStatus();
1290 } catch (InvocationTargetException e
) {
1291 status
= new Status(IStatus
.ERROR
, Activator
.PLUGIN_ID
, Messages
.ImportTraceWizard_ImportProblem
, e
);
1292 } catch (InterruptedException e
) {
1293 status
= Status
.CANCEL_STATUS
;
1295 if (!status
.isOK()) {
1296 if (status
.getSeverity() == IStatus
.CANCEL
) {
1297 setMessage(Messages
.ImportTraceWizard_ImportOperationCancelled
);
1298 setErrorMessage(null);
1300 if (status
.getException() != null) {
1301 displayErrorDialog(status
.getMessage() + ": " + status
.getException()); //$NON-NLS-1$
1304 setErrorMessage(Messages
.ImportTraceWizard_ImportProblem
);
1308 setErrorMessage(null);
1313 * Get the trace type id to import as. This can also return
1314 * {@link #TRACE_TYPE_AUTO_DETECT} to communicate that automatic trace type
1315 * detection will occur instead of setting a specific trace type when
1316 * importing the traces.
1318 * @return the trace type id or {@link #TRACE_TYPE_AUTO_DETECT}
1320 protected String
getImportTraceTypeId() {
1321 return fTraceTypes
.getText();
1325 * Get import options in the form of flags (bits).
1327 * @return the import flags.
1328 * @see #OPTION_CREATE_LINKS_IN_WORKSPACE
1329 * @see #OPTION_IMPORT_UNRECOGNIZED_TRACES
1330 * @see #OPTION_OVERWRITE_EXISTING_RESOURCES
1331 * @see #OPTION_PRESERVE_FOLDER_STRUCTURE
1333 protected int getImportOptionFlags() {
1335 if (fCreateLinksInWorkspaceButton
!= null && fCreateLinksInWorkspaceButton
.getSelection()) {
1336 flags
|= OPTION_CREATE_LINKS_IN_WORKSPACE
;
1338 if (fImportUnrecognizedButton
!= null && fImportUnrecognizedButton
.getSelection()) {
1339 flags
|= OPTION_IMPORT_UNRECOGNIZED_TRACES
;
1341 if (fOverwriteExistingResourcesCheckbox
!= null && fOverwriteExistingResourcesCheckbox
.getSelection()) {
1342 flags
|= OPTION_OVERWRITE_EXISTING_RESOURCES
;
1344 if (fPreserveFolderStructureButton
!= null && fPreserveFolderStructureButton
.getSelection()) {
1345 flags
|= OPTION_PRESERVE_FOLDER_STRUCTURE
;
1351 public void dispose() {
1353 disposeSelectionGroupRoot();
1356 // ------------------------------------------------------------------------
1358 // ------------------------------------------------------------------------
1360 private class TraceValidateAndImportOperation
{
1361 private IStatus fStatus
;
1362 private String fTraceType
;
1363 private IPath fDestinationContainerPath
;
1364 private IPath fBaseSourceContainerPath
;
1365 private boolean fImportFromArchive
;
1366 private int fImportOptionFlags
;
1367 private ImportConflictHandler fConflictHandler
;
1369 private TraceValidateAndImportOperation(String traceId
, IPath baseSourceContainerPath
, IPath destinationContainerPath
, boolean importFromArchive
, int importOptionFlags
) {
1370 fTraceType
= traceId
;
1371 fBaseSourceContainerPath
= baseSourceContainerPath
;
1372 fDestinationContainerPath
= destinationContainerPath
;
1373 fImportOptionFlags
= importOptionFlags
;
1374 fImportFromArchive
= importFromArchive
;
1376 boolean overwriteExistingResources
= (importOptionFlags
& OPTION_OVERWRITE_EXISTING_RESOURCES
) != 0;
1377 if (overwriteExistingResources
) {
1378 fConflictHandler
= new ImportConflictHandler(getContainer().getShell(), fTraceFolderElement
, ImportConfirmation
.OVERWRITE_ALL
);
1380 fConflictHandler
= new ImportConflictHandler(getContainer().getShell(), fTraceFolderElement
, ImportConfirmation
.SKIP
);
1384 public void run(IProgressMonitor progressMonitor
) {
1385 String currentPath
= null;
1388 final ArrayList
<TraceFileSystemElement
> fileSystemElements
= new ArrayList
<>();
1389 IElementFilter passThroughFilter
= new IElementFilter() {
1392 public void filterElements(Collection elements
, IProgressMonitor monitor
) {
1393 fileSystemElements
.addAll(elements
);
1397 public void filterElements(Object
[] elements
, IProgressMonitor monitor
) {
1398 for (int i
= 0; i
< elements
.length
; i
++) {
1399 fileSystemElements
.add((TraceFileSystemElement
) elements
[i
]);
1404 // List fileSystemElements will be filled using the
1405 // passThroughFilter
1406 SubMonitor subMonitor
= SubMonitor
.convert(progressMonitor
, 1);
1407 fSelectionGroup
.getAllCheckedListItems(passThroughFilter
, subMonitor
);
1409 // Check if operation was cancelled.
1410 ModalContext
.checkCanceled(subMonitor
);
1412 Iterator
<TraceFileSystemElement
> fileSystemElementsIter
= fileSystemElements
.iterator();
1413 IFolder destTempFolder
= null;
1414 subMonitor
= SubMonitor
.convert(progressMonitor
, fileSystemElements
.size());
1415 if (fImportFromArchive
) {
1416 // When importing from archive, we first extract the
1417 // *selected* files to a temporary folder then create a new
1418 // Iterator<TraceFileSystemElement> that points to the
1419 // extracted files. This way, the import operator can
1420 // continue as it normally would.
1422 subMonitor
= SubMonitor
.convert(progressMonitor
, fileSystemElements
.size() * 2);
1423 destTempFolder
= fTargetFolder
.getProject().getFolder(TRACE_IMPORT_TEMP_FOLDER
);
1424 if (destTempFolder
.exists()) {
1425 SubProgressMonitor monitor
= new SubProgressMonitor(subMonitor
, 1, SubProgressMonitor
.PREPEND_MAIN_LABEL_TO_SUBTASK
);
1426 destTempFolder
.delete(true, monitor
);
1428 SubProgressMonitor monitor
= new SubProgressMonitor(subMonitor
, 1, SubProgressMonitor
.PREPEND_MAIN_LABEL_TO_SUBTASK
);
1429 destTempFolder
.create(IResource
.HIDDEN
, true, monitor
);
1431 fileSystemElementsIter
= extractSelectedFiles(fileSystemElementsIter
, destTempFolder
, subMonitor
);
1432 // We need to update the source container path because the
1433 // "preserve folder structure" option would create the
1434 // wrong folders otherwise.
1435 fBaseSourceContainerPath
= destTempFolder
.getLocation();
1438 // Map to remember already imported directory traces
1439 final Map
<String
, TraceFileSystemElement
> directoryTraces
= new HashMap
<>();
1440 while (fileSystemElementsIter
.hasNext()) {
1441 ModalContext
.checkCanceled(progressMonitor
);
1443 TraceFileSystemElement element
= fileSystemElementsIter
.next();
1444 IFileSystemObject fileSystemObject
= element
.getFileSystemObject();
1445 String resourcePath
= element
.getFileSystemObject().getAbsolutePath(fBaseSourceContainerPath
.toOSString());
1446 element
.setDestinationContainerPath(computeDestinationContainerPath(new Path(resourcePath
)));
1448 currentPath
= resourcePath
;
1449 SubMonitor sub
= subMonitor
.newChild(1);
1450 if (element
.isDirectory()) {
1451 if (!directoryTraces
.containsKey(resourcePath
)) {
1452 if (isDirectoryTrace(element
)) {
1453 directoryTraces
.put(resourcePath
, element
);
1454 validateAndImportTrace(element
, sub
);
1458 TraceFileSystemElement parentElement
= (TraceFileSystemElement
) element
.getParent();
1459 String parentPath
= parentElement
.getFileSystemObject().getAbsolutePath(fBaseSourceContainerPath
.toOSString());
1460 parentElement
.setDestinationContainerPath(computeDestinationContainerPath(new Path(parentPath
)));
1461 currentPath
= parentPath
;
1462 if (!directoryTraces
.containsKey(parentPath
)) {
1463 if (isDirectoryTrace(parentElement
)) {
1464 directoryTraces
.put(parentPath
, parentElement
);
1465 validateAndImportTrace(parentElement
, sub
);
1467 boolean validateFile
= true;
1468 TraceFileSystemElement grandParentElement
= (TraceFileSystemElement
) parentElement
.getParent();
1469 // Special case for LTTng trace that may contain index directory and files
1470 if (grandParentElement
!= null) {
1471 String grandParentPath
= grandParentElement
.getFileSystemObject().getAbsolutePath(fBaseSourceContainerPath
.toOSString());
1472 grandParentElement
.setDestinationContainerPath(computeDestinationContainerPath(new Path(parentPath
)));
1473 currentPath
= grandParentPath
;
1474 if (directoryTraces
.containsKey(grandParentPath
)) {
1475 validateFile
= false;
1476 } else if (isDirectoryTrace(grandParentElement
)) {
1477 directoryTraces
.put(grandParentPath
, grandParentElement
);
1478 validateAndImportTrace(grandParentElement
, sub
);
1479 validateFile
= false;
1482 if (validateFile
&& (fileSystemObject
.exists())) {
1483 validateAndImportTrace(element
, sub
);
1490 if (destTempFolder
!= null && destTempFolder
.exists()) {
1491 destTempFolder
.delete(true, progressMonitor
);
1494 setStatus(Status
.OK_STATUS
);
1495 } catch (InterruptedException e
) {
1496 setStatus(Status
.CANCEL_STATUS
);
1497 } catch (Exception e
) {
1498 String errorMessage
= Messages
.ImportTraceWizard_ImportProblem
+ ": " + //$NON-NLS-1$
1499 (currentPath
!= null ? currentPath
: ""); //$NON-NLS-1$
1500 Activator
.getDefault().logError(errorMessage
, e
);
1501 setStatus(new Status(IStatus
.ERROR
, Activator
.PLUGIN_ID
, errorMessage
, e
));
1505 private Iterator
<TraceFileSystemElement
> extractSelectedFiles(Iterator
<TraceFileSystemElement
> fileSystemElementsIter
, IFolder tempFolder
, IProgressMonitor progressMonitor
) throws InterruptedException
,
1506 InvocationTargetException
{
1507 List
<TraceFileSystemElement
> subList
= new ArrayList
<>();
1508 Map
<IPath
, String
> sourceLocationMap
= new HashMap
<>();
1509 // Collect all the elements
1510 while (fileSystemElementsIter
.hasNext()) {
1511 ModalContext
.checkCanceled(progressMonitor
);
1512 TraceFileSystemElement element
= fileSystemElementsIter
.next();
1513 sourceLocationMap
.put(new Path(element
.getFileSystemObject().getName()).removeTrailingSeparator(), element
.getSourceLocation());
1514 TraceFileSystemElement parentElement
= (TraceFileSystemElement
) element
.getParent();
1515 sourceLocationMap
.put(new Path(parentElement
.getFileSystemObject().getName()).removeTrailingSeparator(), parentElement
.getSourceLocation());
1516 if (element
.isDirectory()) {
1517 Object
[] array
= element
.getFiles().getChildren();
1518 for (int i
= 0; i
< array
.length
; i
++) {
1519 subList
.add((TraceFileSystemElement
) array
[i
]);
1522 subList
.add(element
);
1525 // Find a sensible root element
1526 TraceFileSystemElement root
= subList
.get(0);
1527 while (root
.getParent() != null) {
1528 root
= (TraceFileSystemElement
) root
.getParent();
1531 ImportProvider fileSystemStructureProvider
= new ImportProvider();
1533 IOverwriteQuery myQueryImpl
= new IOverwriteQuery() {
1535 public String
queryOverwrite(String file
) {
1536 return IOverwriteQuery
.NO_ALL
;
1540 progressMonitor
.setTaskName(Messages
.ImportTraceWizard_ExtractImportOperationTaskName
);
1541 IPath containerPath
= tempFolder
.getFullPath();
1542 ImportOperation operation
= new ImportOperation(containerPath
, root
, fileSystemStructureProvider
, myQueryImpl
, subList
);
1543 operation
.setContext(getShell());
1545 operation
.setCreateContainerStructure(true);
1546 operation
.setOverwriteResources(false);
1547 operation
.setVirtualFolders(false);
1549 operation
.run(new SubProgressMonitor(progressMonitor
, subList
.size(), SubProgressMonitor
.PREPEND_MAIN_LABEL_TO_SUBTASK
));
1551 // Create the new import provider and root element based on the
1552 // extracted temp folder
1553 FileSystemObjectImportStructureProvider importStructureProvider
= new FileSystemObjectImportStructureProvider(FileSystemStructureProvider
.INSTANCE
, null);
1554 IFileSystemObject rootElement
= importStructureProvider
.getIFileSystemObject(new File(tempFolder
.getLocation().toOSString()));
1555 TraceFileSystemElement createRootElement
= createRootElement(rootElement
, importStructureProvider
);
1556 List
<TraceFileSystemElement
> list
= new ArrayList
<>();
1557 getAllChildren(list
, createRootElement
);
1558 Iterator
<TraceFileSystemElement
> extractedElementsIter
= list
.iterator();
1559 IPath tempPath
= new Path(tempFolder
.getLocation().toOSString());
1560 for (TraceFileSystemElement element
: list
) {
1561 IPath path
= new Path(((File
) element
.getFileSystemObject().getRawFileSystemObject()).getAbsolutePath()).makeRelativeTo(tempPath
);
1562 element
.setSourceLocation(sourceLocationMap
.get(path
));
1563 TraceFileSystemElement parentElement
= (TraceFileSystemElement
) element
.getParent();
1564 IPath parentPath
= new Path(((File
) parentElement
.getFileSystemObject().getRawFileSystemObject()).getAbsolutePath()).makeRelativeTo(tempPath
);
1565 parentElement
.setSourceLocation(sourceLocationMap
.get(parentPath
));
1567 return extractedElementsIter
;
1571 * Get all the TraceFileSystemElements recursively.
1574 * the list accumulating the result
1575 * @param rootElement
1576 * the root element of the file system to be imported
1578 private void getAllChildren(List
<TraceFileSystemElement
> result
, TraceFileSystemElement rootElement
) {
1579 AdaptableList files
= rootElement
.getFiles();
1580 for (Object file
: files
.getChildren()) {
1581 result
.add((TraceFileSystemElement
) file
);
1584 AdaptableList folders
= rootElement
.getFolders();
1585 for (Object folder
: folders
.getChildren()) {
1586 getAllChildren(result
, (TraceFileSystemElement
) folder
);
1590 private IPath
computeDestinationContainerPath(Path resourcePath
) {
1591 IPath destinationContainerPath
= fDestinationContainerPath
;
1593 // We need to figure out the new destination path relative to the
1594 // selected "base" source directory.
1595 // Here for example, the selected source directory is /home/user
1596 if ((fImportOptionFlags
& OPTION_PRESERVE_FOLDER_STRUCTURE
) != 0) {
1597 // /home/user/bar/foo/trace -> /home/user/bar/foo
1598 IPath sourceContainerPath
= resourcePath
.removeLastSegments(1);
1599 if (fBaseSourceContainerPath
.equals(resourcePath
)) {
1600 // Use resourcePath directory if fBaseSourceContainerPath
1601 // points to a directory trace
1602 sourceContainerPath
= resourcePath
;
1604 // /home/user/bar/foo, /home/user -> bar/foo
1605 IPath relativeContainerPath
= sourceContainerPath
.makeRelativeTo(fBaseSourceContainerPath
);
1606 // project/Traces + bar/foo -> project/Traces/bar/foo
1607 destinationContainerPath
= fDestinationContainerPath
.append(relativeContainerPath
);
1609 return destinationContainerPath
;
1612 private void validateAndImportTrace(TraceFileSystemElement fileSystemElement
, IProgressMonitor monitor
)
1613 throws TmfTraceImportException
, CoreException
, InvocationTargetException
, InterruptedException
{
1614 String parentContainerPath
= fBaseSourceContainerPath
.toOSString();
1615 String path
= fileSystemElement
.getFileSystemObject().getAbsolutePath(parentContainerPath
);
1616 TraceTypeHelper traceTypeHelper
= null;
1618 if (fTraceType
== null) {
1621 traceTypeHelper
= TmfTraceTypeUIUtils
.selectTraceType(path
, null, null);
1622 } catch (TmfTraceImportException e
) {
1623 // the trace did not match any trace type
1625 if (traceTypeHelper
== null) {
1626 if ((fImportOptionFlags
& OPTION_IMPORT_UNRECOGNIZED_TRACES
) != 0) {
1627 importResource(fileSystemElement
, monitor
);
1632 boolean isDirectoryTraceType
= TmfTraceType
.isDirectoryTraceType(fTraceType
);
1633 if (fileSystemElement
.isDirectory() != isDirectoryTraceType
) {
1636 traceTypeHelper
= TmfTraceType
.getTraceType(fTraceType
);
1638 if (traceTypeHelper
== null) {
1639 // Trace type not found
1640 throw new TmfTraceImportException(Messages
.ImportTraceWizard_TraceTypeNotFound
);
1643 if (!traceTypeHelper
.validate(path
).isOK()) {
1644 // Trace type exist but doesn't validate for given trace.
1649 // Finally import trace
1650 IResource importedResource
= importResource(fileSystemElement
, monitor
);
1651 if (importedResource
!= null) {
1652 TmfTraceTypeUIUtils
.setTraceType(importedResource
, traceTypeHelper
);
1658 * Imports a trace resource to project. In case of name collision the
1659 * user will be asked to confirm overwriting the existing trace,
1660 * overwriting or skipping the trace to be imported.
1662 * @param fileSystemElement
1663 * trace file system object to import
1665 * a progress monitor
1666 * @return the imported resource or null if no resource was imported
1668 * @throws InvocationTargetException
1669 * if problems during import operation
1670 * @throws InterruptedException
1672 * @throws CoreException
1673 * if problems with workspace
1675 private IResource
importResource(TraceFileSystemElement fileSystemElement
, IProgressMonitor monitor
)
1676 throws InvocationTargetException
, InterruptedException
, CoreException
{
1678 IPath tracePath
= getInitialDestinationPath(fileSystemElement
);
1679 String newName
= fConflictHandler
.checkAndHandleNameClash(tracePath
, monitor
);
1680 if (newName
== null) {
1683 fileSystemElement
.setLabel(newName
);
1685 List
<TraceFileSystemElement
> subList
= new ArrayList
<>();
1687 FileSystemElement parentFolder
= fileSystemElement
.getParent();
1689 IPath containerPath
= fileSystemElement
.getDestinationContainerPath();
1690 tracePath
= containerPath
.addTrailingSeparator().append(fileSystemElement
.getLabel());
1691 boolean createLinksInWorkspace
= (fImportOptionFlags
& OPTION_CREATE_LINKS_IN_WORKSPACE
) != 0;
1692 if (fileSystemElement
.isDirectory() && !createLinksInWorkspace
) {
1693 containerPath
= tracePath
;
1695 Object
[] array
= fileSystemElement
.getFiles().getChildren();
1696 for (int i
= 0; i
< array
.length
; i
++) {
1697 subList
.add((TraceFileSystemElement
) array
[i
]);
1699 parentFolder
= fileSystemElement
;
1702 subList
.add(fileSystemElement
);
1705 ImportProvider fileSystemStructureProvider
= new ImportProvider();
1707 IOverwriteQuery myQueryImpl
= new IOverwriteQuery() {
1709 public String
queryOverwrite(String file
) {
1710 return IOverwriteQuery
.NO_ALL
;
1714 monitor
.setTaskName(Messages
.ImportTraceWizard_ImportOperationTaskName
+ " " + fileSystemElement
.getFileSystemObject().getAbsolutePath(fBaseSourceContainerPath
.toOSString())); //$NON-NLS-1$
1715 ImportOperation operation
= new ImportOperation(containerPath
, parentFolder
, fileSystemStructureProvider
, myQueryImpl
, subList
);
1716 operation
.setContext(getShell());
1718 operation
.setCreateContainerStructure(false);
1719 operation
.setOverwriteResources(false);
1720 operation
.setCreateLinks(createLinksInWorkspace
);
1721 operation
.setVirtualFolders(false);
1723 operation
.run(new SubProgressMonitor(monitor
, 1, SubProgressMonitor
.PREPEND_MAIN_LABEL_TO_SUBTASK
));
1724 String sourceLocation
= fileSystemElement
.getSourceLocation();
1725 IResource resource
= ResourcesPlugin
.getWorkspace().getRoot().findMember(tracePath
);
1726 if (sourceLocation
!= null) {
1727 resource
.setPersistentProperty(TmfCommonConstants
.SOURCE_LOCATION
, sourceLocation
);
1733 private boolean isDirectoryTrace(TraceFileSystemElement fileSystemElement
) {
1734 String path
= fileSystemElement
.getFileSystemObject().getAbsolutePath(fBaseSourceContainerPath
.toOSString());
1735 if (TmfTraceType
.isDirectoryTrace(path
)) {
1742 * @return the initial destination path, before rename, if any
1744 private IPath
getInitialDestinationPath(TraceFileSystemElement fileSystemElement
) {
1745 IPath traceFolderPath
= fileSystemElement
.getDestinationContainerPath();
1746 return traceFolderPath
.append(fileSystemElement
.getFileSystemObject().getLabel());
1750 * Set the status for this operation
1755 protected void setStatus(IStatus status
) {
1759 public IStatus
getStatus() {
1765 * The <code>TraceFileSystemElement</code> is a
1766 * <code>FileSystemElement</code> that knows if it has been populated or
1769 private static class TraceFileSystemElement
extends FileSystemElement
{
1771 private boolean fIsPopulated
= false;
1772 private String fLabel
= null;
1773 private IPath fDestinationContainerPath
;
1774 private FileSystemObjectImportStructureProvider fProvider
;
1775 private String fSourceLocation
;
1777 public TraceFileSystemElement(String name
, FileSystemElement parent
, boolean isDirectory
, FileSystemObjectImportStructureProvider provider
) {
1778 super(name
, parent
, isDirectory
);
1779 fProvider
= provider
;
1782 public void setDestinationContainerPath(IPath destinationContainerPath
) {
1783 fDestinationContainerPath
= destinationContainerPath
;
1786 public void setPopulated() {
1787 fIsPopulated
= true;
1790 public boolean isPopulated() {
1791 return fIsPopulated
;
1795 public AdaptableList
getFiles() {
1796 if (!fIsPopulated
) {
1797 populateElementChildren();
1799 return super.getFiles();
1803 public AdaptableList
getFolders() {
1804 if (!fIsPopulated
) {
1805 populateElementChildren();
1807 return super.getFolders();
1811 * Sets the label for the trace to be used when importing at trace.
1814 * the label for the trace
1816 public void setLabel(String name
) {
1821 * Returns the label for the trace to be used when importing at trace.
1823 * @return the label of trace resource
1825 public String
getLabel() {
1826 if (fLabel
== null) {
1827 return getFileSystemObject().getLabel();
1833 * The full path to the container that will contain the trace
1835 * @return the destination container path
1837 public IPath
getDestinationContainerPath() {
1838 return fDestinationContainerPath
;
1842 * Populates the children of the specified parent
1843 * <code>FileSystemElement</code>
1845 private void populateElementChildren() {
1846 List
<IFileSystemObject
> allchildren
= fProvider
.getChildren(this.getFileSystemObject());
1847 Object child
= null;
1848 TraceFileSystemElement newelement
= null;
1849 Iterator
<IFileSystemObject
> iter
= allchildren
.iterator();
1850 while (iter
.hasNext()) {
1851 child
= iter
.next();
1852 newelement
= new TraceFileSystemElement(fProvider
.getLabel(child
), this, fProvider
.isFolder(child
), fProvider
);
1853 newelement
.setFileSystemObject(child
);
1858 public FileSystemObjectImportStructureProvider
getProvider() {
1863 public IFileSystemObject
getFileSystemObject() {
1864 Object fileSystemObject
= super.getFileSystemObject();
1865 return (IFileSystemObject
) fileSystemObject
;
1868 public String
getSourceLocation() {
1869 if (fSourceLocation
== null) {
1870 fSourceLocation
= getFileSystemObject().getSourceLocation();
1872 return fSourceLocation
;
1875 public void setSourceLocation(String sourceLocation
) {
1876 fSourceLocation
= sourceLocation
;
1881 * This interface abstracts the differences between different kinds of
1882 * FileSystemObjects such as File, TarEntry and ZipEntry. This allows
1883 * clients (TraceFileSystemElement, TraceValidateAndImportOperation) to
1884 * handle all the types transparently.
1886 private interface IFileSystemObject
{
1891 String
getAbsolutePath(String parentContainerPath
);
1893 String
getSourceLocation();
1895 Object
getRawFileSystemObject();
1901 * The "File" implementation of an IFileSystemObject
1903 private static class FileFileSystemObject
implements IFileSystemObject
{
1905 private File fFileSystemObject
;
1907 private FileFileSystemObject(File fileSystemObject
) {
1908 fFileSystemObject
= fileSystemObject
;
1912 public String
getLabel() {
1913 String name
= fFileSystemObject
.getName();
1914 if (name
.length() == 0) {
1915 return fFileSystemObject
.getPath();
1921 public String
getName() {
1922 return fFileSystemObject
.getName();
1926 public String
getAbsolutePath(String parentContainerPath
) {
1927 return fFileSystemObject
.getAbsolutePath();
1931 public boolean exists() {
1932 return fFileSystemObject
.exists();
1936 public String
getSourceLocation() {
1937 IResource sourceResource
;
1938 String sourceLocation
= null;
1939 if (fFileSystemObject
.isDirectory()) {
1940 sourceResource
= ResourcesPlugin
.getWorkspace().getRoot().getContainerForLocation(Path
.fromOSString(fFileSystemObject
.getAbsolutePath()));
1942 sourceResource
= ResourcesPlugin
.getWorkspace().getRoot().getFileForLocation(Path
.fromOSString(fFileSystemObject
.getAbsolutePath()));
1944 if (sourceResource
!= null && sourceResource
.exists()) {
1946 sourceLocation
= sourceResource
.getPersistentProperty(TmfCommonConstants
.SOURCE_LOCATION
);
1947 } catch (CoreException e
) {
1948 // Something went wrong with the already existing resource.
1949 // This is not a problem, we'll assign a new location below.
1952 if (sourceLocation
== null) {
1953 sourceLocation
= URIUtil
.toUnencodedString(fFileSystemObject
.toURI());
1955 return sourceLocation
;
1959 public Object
getRawFileSystemObject() {
1960 return fFileSystemObject
;
1965 * The "Tar" implementation of an IFileSystemObject
1967 private static class TarFileSystemObject
implements IFileSystemObject
{
1969 private TarEntry fFileSystemObject
;
1970 private String fArchivePath
;
1972 private TarFileSystemObject(TarEntry fileSystemObject
, String archivePath
) {
1973 fFileSystemObject
= fileSystemObject
;
1974 fArchivePath
= archivePath
;
1978 public String
getLabel() {
1979 return new Path(fFileSystemObject
.getName()).lastSegment();
1983 public String
getName() {
1984 return fFileSystemObject
.getName();
1988 public String
getAbsolutePath(String parentContainerPath
) {
1989 return new Path(parentContainerPath
).append(fFileSystemObject
.getName()).toOSString();
1993 public boolean exists() {
1998 public String
getSourceLocation() {
1999 URI uri
= new File(fArchivePath
).toURI();
2000 IPath entryPath
= new Path(fFileSystemObject
.getName());
2001 return URIUtil
.toUnencodedString(URIUtil
.toJarURI(uri
, entryPath
));
2005 public Object
getRawFileSystemObject() {
2006 return fFileSystemObject
;
2011 * The "Zip" implementation of an IFileSystemObject
2013 private static class ZipFileSystemObject
implements IFileSystemObject
{
2015 private ZipEntry fFileSystemObject
;
2016 private String fArchivePath
;
2018 private ZipFileSystemObject(ZipEntry fileSystemObject
, String archivePath
) {
2019 fFileSystemObject
= fileSystemObject
;
2020 fArchivePath
= archivePath
;
2024 public String
getLabel() {
2025 return new Path(fFileSystemObject
.getName()).lastSegment();
2029 public String
getName() {
2030 return fFileSystemObject
.getName();
2034 public String
getAbsolutePath(String parentContainerPath
) {
2035 return new Path(parentContainerPath
).append(fFileSystemObject
.getName()).toOSString();
2039 public boolean exists() {
2044 public String
getSourceLocation() {
2045 URI uri
= new File(fArchivePath
).toURI();
2046 IPath entryPath
= new Path(fFileSystemObject
.getName());
2047 return URIUtil
.toUnencodedString(URIUtil
.toJarURI(uri
, entryPath
));
2051 public Object
getRawFileSystemObject() {
2052 return fFileSystemObject
;
2056 private class ImportProvider
implements IImportStructureProvider
{
2062 public String
getLabel(Object element
) {
2063 TraceFileSystemElement resource
= (TraceFileSystemElement
) element
;
2064 return resource
.getLabel();
2068 public List
getChildren(Object element
) {
2069 TraceFileSystemElement resource
= (TraceFileSystemElement
) element
;
2070 Object
[] array
= resource
.getFiles().getChildren();
2071 List
<Object
> list
= new ArrayList
<>();
2072 for (int i
= 0; i
< array
.length
; i
++) {
2079 public InputStream
getContents(Object element
) {
2080 TraceFileSystemElement resource
= (TraceFileSystemElement
) element
;
2081 return resource
.getProvider().getContents(resource
.getFileSystemObject());
2085 public String
getFullPath(Object element
) {
2086 TraceFileSystemElement resource
= (TraceFileSystemElement
) element
;
2087 return resource
.getProvider().getFullPath(resource
.getFileSystemObject());
2091 public boolean isFolder(Object element
) {
2092 TraceFileSystemElement resource
= (TraceFileSystemElement
) element
;
2093 return resource
.isDirectory();