1 /*******************************************************************************
2 * Copyright (c) 2012, 2014 Ericsson
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 * Patrick Tasse - Initial API and implementation
11 * Patrick Tasse - Add support for DROP_LINK and rename prompt on name clash
12 *******************************************************************************/
14 package org
.eclipse
.linuxtools
.internal
.tmf
.ui
.project
.handlers
;
17 import java
.io
.FileInputStream
;
18 import java
.io
.FileNotFoundException
;
19 import java
.io
.InputStream
;
20 import java
.lang
.reflect
.InvocationTargetException
;
21 import java
.util
.Arrays
;
22 import java
.util
.List
;
25 import org
.eclipse
.core
.resources
.IContainer
;
26 import org
.eclipse
.core
.resources
.IFile
;
27 import org
.eclipse
.core
.resources
.IFolder
;
28 import org
.eclipse
.core
.resources
.IProject
;
29 import org
.eclipse
.core
.resources
.IResource
;
30 import org
.eclipse
.core
.resources
.IWorkspace
;
31 import org
.eclipse
.core
.resources
.ResourcesPlugin
;
32 import org
.eclipse
.core
.runtime
.CoreException
;
33 import org
.eclipse
.core
.runtime
.IPath
;
34 import org
.eclipse
.core
.runtime
.IProgressMonitor
;
35 import org
.eclipse
.core
.runtime
.IStatus
;
36 import org
.eclipse
.core
.runtime
.NullProgressMonitor
;
37 import org
.eclipse
.core
.runtime
.Path
;
38 import org
.eclipse
.core
.runtime
.QualifiedName
;
39 import org
.eclipse
.core
.runtime
.Status
;
40 import org
.eclipse
.core
.runtime
.URIUtil
;
41 import org
.eclipse
.jface
.operation
.IRunnableWithProgress
;
42 import org
.eclipse
.jface
.viewers
.IStructuredSelection
;
43 import org
.eclipse
.linuxtools
.internal
.tmf
.ui
.Activator
;
44 import org
.eclipse
.linuxtools
.tmf
.core
.TmfCommonConstants
;
45 import org
.eclipse
.linuxtools
.tmf
.core
.project
.model
.TmfTraceImportException
;
46 import org
.eclipse
.linuxtools
.tmf
.core
.project
.model
.TmfTraceType
;
47 import org
.eclipse
.linuxtools
.tmf
.core
.project
.model
.TraceTypeHelper
;
48 import org
.eclipse
.linuxtools
.tmf
.core
.trace
.TmfTrace
;
49 import org
.eclipse
.linuxtools
.tmf
.ui
.project
.model
.ITmfProjectModelElement
;
50 import org
.eclipse
.linuxtools
.tmf
.ui
.project
.model
.TmfExperimentElement
;
51 import org
.eclipse
.linuxtools
.tmf
.ui
.project
.model
.TmfProjectElement
;
52 import org
.eclipse
.linuxtools
.tmf
.ui
.project
.model
.TmfProjectRegistry
;
53 import org
.eclipse
.linuxtools
.tmf
.ui
.project
.model
.TmfTraceElement
;
54 import org
.eclipse
.linuxtools
.tmf
.ui
.project
.model
.TmfTraceFolder
;
55 import org
.eclipse
.linuxtools
.tmf
.ui
.project
.model
.TmfTraceTypeUIUtils
;
56 import org
.eclipse
.osgi
.util
.NLS
;
57 import org
.eclipse
.swt
.SWT
;
58 import org
.eclipse
.swt
.dnd
.DND
;
59 import org
.eclipse
.swt
.dnd
.DropTargetEvent
;
60 import org
.eclipse
.swt
.dnd
.FileTransfer
;
61 import org
.eclipse
.swt
.dnd
.TransferData
;
62 import org
.eclipse
.swt
.widgets
.MessageBox
;
63 import org
.eclipse
.ui
.PlatformUI
;
64 import org
.eclipse
.ui
.actions
.WorkspaceModifyDelegatingOperation
;
65 import org
.eclipse
.ui
.dialogs
.IOverwriteQuery
;
66 import org
.eclipse
.ui
.navigator
.CommonDropAdapter
;
67 import org
.eclipse
.ui
.navigator
.CommonDropAdapterAssistant
;
68 import org
.eclipse
.ui
.wizards
.datatransfer
.FileSystemStructureProvider
;
69 import org
.eclipse
.ui
.wizards
.datatransfer
.ImportOperation
;
72 * Drop adapter assistant for project explorer
74 public class DropAdapterAssistant
extends CommonDropAdapterAssistant
{
79 public DropAdapterAssistant() {
83 public boolean isSupportedType(TransferData aTransferType
) {
84 return super.isSupportedType(aTransferType
) || FileTransfer
.getInstance().isSupportedType(aTransferType
);
88 public IStatus
validateDrop(Object target
, int operation
, TransferData transferType
) {
89 if (target
instanceof TmfTraceFolder
) {
90 return Status
.OK_STATUS
;
92 if (target
instanceof TmfExperimentElement
) {
93 return Status
.OK_STATUS
;
95 if (target
instanceof TmfTraceElement
) {
96 ITmfProjectModelElement parent
= ((TmfTraceElement
) target
).getParent();
97 if (parent
instanceof TmfTraceFolder
) {
98 return Status
.OK_STATUS
;
100 if (parent
instanceof TmfExperimentElement
) {
101 return Status
.OK_STATUS
;
104 if (target
instanceof IProject
) {
105 return Status
.OK_STATUS
;
107 return Status
.CANCEL_STATUS
;
111 public IStatus
handleDrop(CommonDropAdapter aDropAdapter
, DropTargetEvent aDropTargetEvent
, Object aTarget
) {
114 // Use local variable to avoid parameter assignment
115 Object targetToUse
= aTarget
;
117 int operation
= aDropTargetEvent
.detail
;
118 if (operation
!= DND
.DROP_LINK
) {
119 operation
= DND
.DROP_COPY
;
122 // If target is a trace, use its parent (either trace folder or experiment)
123 if (targetToUse
instanceof TmfTraceElement
) {
124 targetToUse
= ((TmfTraceElement
) targetToUse
).getParent();
127 // If target is a project, use its trace folder
128 if (targetToUse
instanceof IProject
) {
129 TmfProjectElement projectElement
= TmfProjectRegistry
.getProject((IProject
) targetToUse
, true);
130 if (projectElement
!= null) {
131 targetToUse
= projectElement
.getTracesFolder();
135 if (aDropTargetEvent
.data
instanceof IStructuredSelection
) {
136 IStructuredSelection selection
= (IStructuredSelection
) aDropTargetEvent
.data
;
137 for (Object source
: selection
.toArray()) {
138 if (source
instanceof IResource
) {
139 // If source resource is a trace, use the trace element
140 IResource sourceResource
= (IResource
) source
;
141 TmfProjectElement projectElement
= TmfProjectRegistry
.getProject(sourceResource
.getProject());
142 if (projectElement
!= null && projectElement
.getTracesFolder() != null) {
143 for (TmfTraceElement trace
: projectElement
.getTracesFolder().getTraces()) {
144 if (trace
.getResource().equals(sourceResource
)) {
151 if (source
instanceof TmfTraceElement
) {
152 TmfTraceElement sourceTrace
= (TmfTraceElement
) source
;
153 // If source trace is under an experiment, use the original trace from the traces folder
154 sourceTrace
= sourceTrace
.getElementUnderTraceFolder();
155 if (targetToUse
instanceof TmfExperimentElement
) {
156 TmfExperimentElement targetExperiment
= (TmfExperimentElement
) targetToUse
;
157 ok
|= drop(sourceTrace
, targetExperiment
, operation
);
158 } else if (targetToUse
instanceof TmfTraceFolder
) {
159 TmfTraceFolder traceFolder
= (TmfTraceFolder
) targetToUse
;
160 ok
|= drop(sourceTrace
, traceFolder
, operation
);
162 } else if (source
instanceof IResource
) {
163 IResource sourceResource
= (IResource
) source
;
164 if (sourceResource
.getType() != IResource
.FILE
&& sourceResource
.getType() != IResource
.FOLDER
) {
167 if (targetToUse
instanceof TmfExperimentElement
) {
168 TmfExperimentElement targetExperiment
= (TmfExperimentElement
) targetToUse
;
169 ok
|= (drop(sourceResource
, targetExperiment
, operation
) != null);
170 } else if (targetToUse
instanceof TmfTraceFolder
) {
171 TmfTraceFolder traceFolder
= (TmfTraceFolder
) targetToUse
;
172 ok
|= (drop(sourceResource
, traceFolder
, operation
) != null);
176 } else if (aDropTargetEvent
.data
instanceof String
[]) {
177 String
[] sources
= (String
[]) aDropTargetEvent
.data
;
178 for (String source
: sources
) {
179 Path path
= new Path(source
);
180 if (targetToUse
instanceof TmfExperimentElement
) {
181 TmfExperimentElement targetExperiment
= (TmfExperimentElement
) targetToUse
;
182 ok
|= drop(path
, targetExperiment
, operation
);
183 } else if (targetToUse
instanceof TmfTraceFolder
) {
184 TmfTraceFolder traceFolder
= (TmfTraceFolder
) targetToUse
;
185 ok
|= drop(path
, traceFolder
, operation
);
189 return (ok ? Status
.OK_STATUS
: Status
.CANCEL_STATUS
);
194 * Drop a trace by copying/linking a trace element in a target experiment
196 * @param sourceTrace the source trace element to copy
197 * @param targetExperiment the target experiment
198 * @param operation the drop operation (DND.DROP_COPY | DND.DROP_LINK)
199 * @return true if successful
201 private static boolean drop(TmfTraceElement sourceTrace
,
202 TmfExperimentElement targetExperiment
,
205 IResource sourceResource
= sourceTrace
.getResource();
206 IResource targetResource
= drop(sourceResource
, targetExperiment
, operation
);
208 if (targetResource
!= null) {
209 if (! sourceTrace
.getProject().equals(targetExperiment
.getProject())) {
210 IFolder destinationSupplementaryFolder
= targetExperiment
.getTraceSupplementaryFolder(targetResource
.getName());
211 sourceTrace
.copySupplementaryFolder(destinationSupplementaryFolder
);
219 * Drop a trace by copying/linking a resource in a target experiment
221 * @param sourceResource the source resource
222 * @param targetExperiment the target experiment
223 * @param operation the drop operation (DND.DROP_COPY | DND.DROP_LINK)
224 * @return the target resource or null if unsuccessful
226 private static IResource
drop(IResource sourceResource
,
227 TmfExperimentElement targetExperiment
,
230 IResource traceResource
= sourceResource
;
232 IPath tracesFolderPath
= targetExperiment
.getProject().getTracesFolder().getPath();
233 if (tracesFolderPath
.isPrefixOf(sourceResource
.getFullPath())) {
234 String elementPath
= sourceResource
.getFullPath().makeRelativeTo(tracesFolderPath
).toString();
235 for (TmfTraceElement trace
: targetExperiment
.getTraces()) {
236 if (trace
.getElementPath().equals(elementPath
)) {
241 String targetName
= sourceResource
.getName();
242 for (ITmfProjectModelElement element
: targetExperiment
.getProject().getTracesFolder().getChildren()) {
243 if (element
.getName().equals(targetName
)) {
244 targetName
= promptRename(element
);
245 if (targetName
== null) {
252 if (operation
== DND
.DROP_COPY
&& !sourceResource
.isLinked()) {
253 IPath destination
= targetExperiment
.getProject().getTracesFolder().getResource().getFullPath().addTrailingSeparator().append(targetName
);
254 sourceResource
.copy(destination
, false, null);
255 cleanupBookmarks(destination
);
257 createLink(targetExperiment
.getProject().getTracesFolder().getResource(), sourceResource
, targetName
);
259 // use the copied resource for the experiment
260 if (sourceResource
.getType() == IResource
.FILE
) {
261 traceResource
= targetExperiment
.getProject().getTracesFolder().getResource().getFile(targetName
);
262 } else if (sourceResource
.getType() == IResource
.FOLDER
) {
263 traceResource
= targetExperiment
.getProject().getTracesFolder().getResource().getFolder(targetName
);
265 String sourceLocation
= sourceResource
.getPersistentProperty(TmfCommonConstants
.SOURCE_LOCATION
);
266 if (sourceLocation
== null) {
267 sourceLocation
= URIUtil
.toUnencodedString(new File(sourceResource
.getLocationURI()).toURI());
269 traceResource
.setPersistentProperty(TmfCommonConstants
.SOURCE_LOCATION
, sourceLocation
);
270 } catch (CoreException e
) {
275 if (traceResource
!= null && traceResource
.exists()) {
276 setTraceType(traceResource
);
277 for (TmfTraceElement trace
: targetExperiment
.getProject().getTracesFolder().getTraces()) {
278 if (trace
.getResource().equals(traceResource
)) {
279 targetExperiment
.addTrace(trace
);
280 targetExperiment
.closeEditors();
281 targetExperiment
.deleteSupplementaryResources();
285 return traceResource
;
291 * Drop a trace by copying/linking a trace element in a trace folder
293 * @param sourceTrace the source trace
294 * @param traceFolder the target trace folder
295 * @param operation the drop operation (DND.DROP_COPY | DND.DROP_LINK)
296 * @return true if successful
298 private static boolean drop(TmfTraceElement sourceTrace
,
299 TmfTraceFolder traceFolder
,
302 IResource sourceResource
= sourceTrace
.getResource();
303 IResource targetResource
= drop(sourceResource
, traceFolder
, operation
);
305 if (targetResource
!= null) {
306 String elementPath
= targetResource
.getFullPath().makeRelativeTo(traceFolder
.getProject().getTracesFolder().getPath()).toString();
307 IFolder destinationSupplementaryFolder
= traceFolder
.getTraceSupplementaryFolder(elementPath
);
308 sourceTrace
.copySupplementaryFolder(destinationSupplementaryFolder
);
315 * Drop a trace by copying/linking a resource in a trace folder
317 * @param sourceResource the source resource
318 * @param traceFolder the target trace folder
319 * @param operation the drop operation (DND.DROP_COPY | DND.DROP_LINK)
320 * @return the target resource or null if unsuccessful
322 private static IResource
drop(IResource sourceResource
,
323 TmfTraceFolder traceFolder
,
326 if (sourceResource
.getParent().equals(traceFolder
.getResource())) {
329 String targetName
= sourceResource
.getName();
330 for (ITmfProjectModelElement element
: traceFolder
.getChildren()) {
331 if (element
.getName().equals(targetName
)) {
332 targetName
= promptRename(element
);
333 if (targetName
== null) {
340 if (operation
== DND
.DROP_COPY
&& !sourceResource
.isLinked()) {
341 IPath destination
= traceFolder
.getResource().getFullPath().addTrailingSeparator().append(targetName
);
342 sourceResource
.copy(destination
, false, null);
343 cleanupBookmarks(destination
);
345 createLink(traceFolder
.getResource(), sourceResource
, targetName
);
347 IResource traceResource
= traceFolder
.getResource().findMember(targetName
);
348 if (traceResource
!= null && traceResource
.exists()) {
349 String sourceLocation
= sourceResource
.getPersistentProperty(TmfCommonConstants
.SOURCE_LOCATION
);
350 if (sourceLocation
== null) {
351 sourceLocation
= URIUtil
.toUnencodedString(new File(sourceResource
.getLocationURI()).toURI());
353 traceResource
.setPersistentProperty(TmfCommonConstants
.SOURCE_LOCATION
, sourceLocation
);
354 setTraceType(traceResource
);
356 return traceResource
;
357 } catch (CoreException e
) {
364 * Drop a trace by importing/linking a path in a target experiment
366 * @param path the source path
367 * @param targetExperiment the target experiment
368 * @param operation the drop operation (DND.DROP_COPY | DND.DROP_LINK)
369 * @return true if successful
371 private static boolean drop(Path path
,
372 TmfExperimentElement targetExperiment
,
375 IPath tracesFolderPath
= targetExperiment
.getProject().getTracesFolder().getResource().getLocation();
376 IResource traceResource
= null;
377 if (tracesFolderPath
.isPrefixOf(path
)) {
378 String elementPath
= path
.makeRelativeTo(tracesFolderPath
).toString();
379 for (TmfTraceElement trace
: targetExperiment
.getTraces()) {
380 if (trace
.getElementPath().equals(elementPath
)) {
384 traceResource
= targetExperiment
.getProject().getTracesFolder().getResource().findMember(elementPath
);
386 String targetName
= path
.lastSegment();
387 for (ITmfProjectModelElement element
: targetExperiment
.getProject().getTracesFolder().getChildren()) {
388 if (element
.getName().equals(targetName
)) {
389 targetName
= promptRename(element
);
390 if (targetName
== null) {
396 if (operation
== DND
.DROP_COPY
) {
397 importTrace(targetExperiment
.getProject().getTracesFolder().getResource(), path
, targetName
);
399 createLink(targetExperiment
.getProject().getTracesFolder().getResource(), path
, targetName
);
401 // use the copied resource for the experiment
402 File file
= new File(path
.toString());
403 if (file
.exists() && file
.isFile()) {
404 traceResource
= targetExperiment
.getProject().getTracesFolder().getResource().getFile(targetName
);
405 } else if (file
.exists() && file
.isDirectory()) {
406 traceResource
= targetExperiment
.getProject().getTracesFolder().getResource().getFolder(targetName
);
409 if (traceResource
!= null && traceResource
.exists()) {
411 String sourceLocation
= URIUtil
.toUnencodedString(path
.toFile().toURI());
412 traceResource
.setPersistentProperty(TmfCommonConstants
.SOURCE_LOCATION
, sourceLocation
);
413 } catch (CoreException e
) {
416 setTraceType(traceResource
);
417 for (TmfTraceElement trace
: targetExperiment
.getProject().getTracesFolder().getTraces()) {
418 if (trace
.getResource().equals(traceResource
)) {
419 targetExperiment
.addTrace(trace
);
420 targetExperiment
.closeEditors();
421 targetExperiment
.deleteSupplementaryResources();
431 * Drop a trace by importing/linking a path in a trace folder
433 * @param path the source path
434 * @param traceFolder the target trace folder
435 * @param operation the drop operation (DND.DROP_COPY | DND.DROP_LINK)
436 * @return true if successful
438 private static boolean drop(Path path
,
439 TmfTraceFolder traceFolder
,
442 String targetName
= path
.lastSegment();
443 for (ITmfProjectModelElement element
: traceFolder
.getChildren()) {
444 if (element
.getName().equals(targetName
)) {
445 targetName
= promptRename(element
);
446 if (targetName
== null) {
452 if (operation
== DND
.DROP_COPY
) {
453 importTrace(traceFolder
.getResource(), path
, targetName
);
455 createLink(traceFolder
.getResource(), path
, targetName
);
457 IResource traceResource
= traceFolder
.getResource().findMember(targetName
);
458 if (traceResource
!= null && traceResource
.exists()) {
460 String sourceLocation
= URIUtil
.toUnencodedString(path
.toFile().toURI());
461 traceResource
.setPersistentProperty(TmfCommonConstants
.SOURCE_LOCATION
, sourceLocation
);
462 } catch (CoreException e
) {
465 setTraceType(traceResource
);
471 * Import a trace to the trace folder
473 * @param folder the trace folder resource
474 * @param path the path to the trace to import
475 * @param targetName the target name
477 private static void importTrace(final IFolder folder
, final Path path
, final String targetName
) {
478 final File source
= new File(path
.toString());
479 if (source
.isDirectory()) {
480 IPath containerPath
= folder
.getFullPath().addTrailingSeparator().append(targetName
);
481 IOverwriteQuery overwriteImplementor
= new IOverwriteQuery() {
483 public String
queryOverwrite(String pathString
) {
484 return IOverwriteQuery
.NO_ALL
;
487 List
<File
> filesToImport
= Arrays
.asList(source
.listFiles());
488 ImportOperation operation
= new ImportOperation(
491 FileSystemStructureProvider
.INSTANCE
,
492 overwriteImplementor
,
494 operation
.setCreateContainerStructure(false);
496 operation
.run(new NullProgressMonitor());
497 } catch (InvocationTargetException e
) {
499 } catch (InterruptedException e
) {
503 IRunnableWithProgress runnable
= new IRunnableWithProgress() {
505 public void run(IProgressMonitor monitor
) throws InvocationTargetException
, InterruptedException
{
507 InputStream inputStream
= new FileInputStream(source
);
508 IFile targetFile
= folder
.getFile(targetName
);
509 targetFile
.create(inputStream
, IResource
.NONE
, monitor
);
510 } catch (CoreException e
) {
512 } catch (FileNotFoundException e
) {
517 WorkspaceModifyDelegatingOperation operation
= new WorkspaceModifyDelegatingOperation(runnable
);
519 operation
.run(new NullProgressMonitor());
520 } catch (InvocationTargetException e
) {
522 } catch (InterruptedException e
) {
529 * Create a link to the actual trace and set the trace type
531 * @param parentFolder the parent folder
532 * @param resource the resource
533 * @param targetName the target name
535 private static void createLink(IFolder parentFolder
, IResource resource
, String targetName
) {
536 IPath location
= resource
.getLocation();
537 IWorkspace workspace
= ResourcesPlugin
.getWorkspace();
539 Map
<QualifiedName
, String
> properties
= resource
.getPersistentProperties();
540 String traceType
= properties
.get(TmfCommonConstants
.TRACETYPE
);
541 TraceTypeHelper traceTypeHelper
= TmfTraceType
.getTraceType(traceType
);
543 if (resource
instanceof IFolder
) {
544 IFolder folder
= parentFolder
.getFolder(targetName
);
545 IStatus result
= workspace
.validateLinkLocation(folder
, location
);
546 if (result
.isOK() || result
.matches(IStatus
.INFO
| IStatus
.WARNING
)) {
547 folder
.createLink(location
, IResource
.REPLACE
, null);
548 if (traceTypeHelper
!= null) {
549 TmfTraceTypeUIUtils
.setTraceType(folder
, traceTypeHelper
);
552 Activator
.getDefault().logError("Invalid Trace Location"); //$NON-NLS-1$
555 IFile file
= parentFolder
.getFile(targetName
);
556 IStatus result
= workspace
.validateLinkLocation(file
, location
);
557 if (result
.isOK() || result
.matches(IStatus
.INFO
| IStatus
.WARNING
)) {
558 file
.createLink(location
, IResource
.REPLACE
, null);
559 if (traceTypeHelper
!= null) {
560 TmfTraceTypeUIUtils
.setTraceType(file
, traceTypeHelper
);
563 Activator
.getDefault().logError("Invalid Trace Location"); //$NON-NLS-1$
566 } catch (CoreException e
) {
572 * Create a link to a file or folder
574 * @param parentFolder the parent folder
575 * @param source the file or folder
576 * @param targetName the target name
578 private static void createLink(IFolder parentFolder
, IPath location
, String targetName
) {
579 File source
= new File(location
.toString());
580 IWorkspace workspace
= ResourcesPlugin
.getWorkspace();
583 if (source
.isDirectory()) {
584 IFolder folder
= parentFolder
.getFolder(targetName
);
585 IStatus result
= workspace
.validateLinkLocation(folder
, location
);
586 if (result
.isOK() || result
.matches(IStatus
.INFO
| IStatus
.WARNING
)) {
587 folder
.createLink(location
, IResource
.REPLACE
, null);
589 Activator
.getDefault().logError("Invalid Trace Location"); //$NON-NLS-1$
592 IFile file
= parentFolder
.getFile(targetName
);
593 IStatus result
= workspace
.validateLinkLocation(file
, location
);
594 if (result
.isOK() || result
.matches(IStatus
.INFO
| IStatus
.WARNING
)) {
595 file
.createLink(location
, IResource
.REPLACE
, null);
597 Activator
.getDefault().logError("Invalid Trace Location"); //$NON-NLS-1$
600 } catch (CoreException e
) {
606 * Prompts the user to rename a trace
608 * @param element the conflicting element
609 * @return the new name to use or null if rename is canceled
611 private static String
promptRename(ITmfProjectModelElement element
) {
612 MessageBox mb
= new MessageBox(PlatformUI
.getWorkbench().getActiveWorkbenchWindow().getShell(), SWT
.ICON_QUESTION
| SWT
.CANCEL
| SWT
.OK
);
613 mb
.setText(Messages
.DropAdapterAssistant_RenameTraceTitle
);
614 mb
.setMessage(NLS
.bind(Messages
.DropAdapterAssistant_RenameTraceMessage
, element
.getName()));
615 if (mb
.open() != SWT
.OK
) {
618 IContainer folder
= element
.getResource().getParent();
621 String name
= element
.getName() + '(' + Integer
.toString(i
++) + ')';
622 IResource resource
= folder
.findMember(name
);
623 if (resource
== null) {
630 * Cleanup bookmarks file in copied trace
632 private static void cleanupBookmarks(IPath path
) {
633 IFolder folder
= ResourcesPlugin
.getWorkspace().getRoot().getFolder(path
);
634 if (folder
.exists()) {
636 for (IResource member
: folder
.members()) {
637 if (TmfTrace
.class.getCanonicalName().equals(member
.getPersistentProperty(TmfCommonConstants
.TRACETYPE
))) {
638 member
.delete(true, null);
641 } catch (CoreException e
) {
647 private static void setTraceType(IResource traceResource
) {
649 String traceType
= traceResource
.getPersistentProperties().get(TmfCommonConstants
.TRACETYPE
);
650 TraceTypeHelper traceTypeHelper
= TmfTraceType
.getTraceType(traceType
);
651 if (traceTypeHelper
== null) {
652 traceTypeHelper
= TmfTraceTypeUIUtils
.selectTraceType(traceResource
.getLocationURI().getPath(), null, null);
654 if (traceTypeHelper
!= null) {
655 TmfTraceTypeUIUtils
.setTraceType(traceResource
, traceTypeHelper
);
657 } catch (TmfTraceImportException e
) {
658 } catch (CoreException e
) {
664 * Display an exception in a message box
666 * @param e the exception
668 private static void displayException(Exception e
) {
669 MessageBox mb
= new MessageBox(PlatformUI
.getWorkbench().getActiveWorkbenchWindow().getShell());
670 mb
.setText(e
.getClass().getName());
671 mb
.setMessage(e
.getMessage());