Drag and drop enhancements
authorPatrick Tasse <patrick.tasse@gmail.com>
Tue, 26 Feb 2013 20:27:08 +0000 (15:27 -0500)
committerPatrick Tasse <patrick.tasse@gmail.com>
Wed, 27 Feb 2013 15:12:10 +0000 (10:12 -0500)
- Add support for DROP_LINK
- Add rename prompt on name collision with automatic name resolution
- Add support for unknown trace type icon
- Fix propagation of selected trace type to experiment traces
- Updated user guide

Change-Id: I1eb7c7bcbe5566a0fc507aef1554780515d62eb5
Signed-off-by: Patrick Tasse <patrick.tasse@gmail.com>
Reviewed-on: https://git.eclipse.org/r/10667
Tested-by: Hudson CI
Reviewed-by: Bernd Hufmann <bhufmann@gmail.com>
IP-Clean: Bernd Hufmann <bhufmann@gmail.com>
Tested-by: Bernd Hufmann <bhufmann@gmail.com>
org.eclipse.linuxtools.lttng.help/doc/User-Guide.mediawiki
org.eclipse.linuxtools.lttng.help/doc/images/unknown_parser.gif [new file with mode: 0644]
org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/handlers/DropAdapterAssistant.java
org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/handlers/Messages.java
org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/handlers/SelectTraceTypeHandler.java
org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/handlers/messages.properties
org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/project/model/TmfNavigatorLabelProvider.java

index 3efcbcdfbb10afe53afe4d3e51926f559bc8f94b..eecefa7a3ef7590e174d098a985d78e2864d2f1f 100644 (file)
@@ -198,7 +198,7 @@ Note, that traces of certain types (e.g. LTTng Kernel) are actually a composite
 
 [[Image:images/ProjectImportTraceDialog.png]]
 
-Upon successful importing the traces will be stored in the '''Traces''' folder. If a trace type was selected in the import dialog, then the corresponding icon will be displayed. Linked traces will have a little arrow as decorator on the right bottom corner.
+Upon successful importing the traces will be stored in the '''Traces''' folder. If a trace type was selected in the import dialog, then the corresponding icon will be displayed. If no trace type is selected the unknown icon [[Image:images/unknown_parser.gif]] will be displayed. Linked traces will have a little arrow as decorator on the right bottom corner.
 
 Note that trace type is an extension point of the '''Tracing and Monitoring Framework (TMF)'''. Depending on the which features are loaded, the list of trace types can vary.
 
@@ -330,6 +330,8 @@ Traces can be also be imported to a project by dragging from another tracing pro
 
 Any resource can be dragged and dropped from a non-tracing project, and any file or folder can be dragged from an external tool, into a tracing project's trace folder. The resource will be copied or imported as a new trace, however the trace type will be unknown and need to be set manually by the user.
 
+To import the trace as a link, use the platform-specific key modifier while dragging the source trace. A link will be created in the target project to the trace's location on the file system.
+
 It is also possible to drop a trace, resource, file or folder into an existing experiment. If the item does not already exist as a trace in the project's trace folder, it will first be copied or imported, then the trace will be added to the experiment.
 
 == Events Editor ==
diff --git a/org.eclipse.linuxtools.lttng.help/doc/images/unknown_parser.gif b/org.eclipse.linuxtools.lttng.help/doc/images/unknown_parser.gif
new file mode 100644 (file)
index 0000000..b472212
Binary files /dev/null and b/org.eclipse.linuxtools.lttng.help/doc/images/unknown_parser.gif differ
index 41986434adfa0e6ab6ae5c61e05fb73159227a44..0a70cc02ccae674e7f11616550e08bd0162753ce 100644 (file)
@@ -1,5 +1,5 @@
 /*******************************************************************************
-* Copyright (c) 2012 Ericsson
+* Copyright (c) 2012, 2013 Ericsson
  *
  * All rights reserved. This program and the accompanying materials are
  * made available under the terms of the Eclipse Public License v1.0 which
@@ -8,13 +8,17 @@
  *
  * Contributors:
  *   Patrick Tasse - Initial API and implementation
+ *   Patrick Tasse - Add support for DROP_LINK and rename prompt on name clash
  *******************************************************************************/
 
 package org.eclipse.linuxtools.internal.tmf.ui.project.handlers;
 
 import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.InputStream;
 import java.lang.reflect.InvocationTargetException;
-import java.util.LinkedList;
+import java.util.Arrays;
 import java.util.List;
 import java.util.Map;
 
@@ -26,11 +30,13 @@ import org.eclipse.core.resources.IWorkspace;
 import org.eclipse.core.resources.ResourcesPlugin;
 import org.eclipse.core.runtime.CoreException;
 import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.IProgressMonitor;
 import org.eclipse.core.runtime.IStatus;
 import org.eclipse.core.runtime.NullProgressMonitor;
 import org.eclipse.core.runtime.Path;
 import org.eclipse.core.runtime.QualifiedName;
 import org.eclipse.core.runtime.Status;
+import org.eclipse.jface.operation.IRunnableWithProgress;
 import org.eclipse.jface.viewers.IStructuredSelection;
 import org.eclipse.linuxtools.internal.tmf.ui.Activator;
 import org.eclipse.linuxtools.tmf.core.TmfCommonConstants;
@@ -41,12 +47,15 @@ import org.eclipse.linuxtools.tmf.ui.project.model.TmfProjectElement;
 import org.eclipse.linuxtools.tmf.ui.project.model.TmfProjectRegistry;
 import org.eclipse.linuxtools.tmf.ui.project.model.TmfTraceElement;
 import org.eclipse.linuxtools.tmf.ui.project.model.TmfTraceFolder;
+import org.eclipse.osgi.util.NLS;
+import org.eclipse.swt.SWT;
 import org.eclipse.swt.dnd.DND;
 import org.eclipse.swt.dnd.DropTargetEvent;
 import org.eclipse.swt.dnd.FileTransfer;
 import org.eclipse.swt.dnd.TransferData;
 import org.eclipse.swt.widgets.MessageBox;
 import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.actions.WorkspaceModifyDelegatingOperation;
 import org.eclipse.ui.dialogs.IOverwriteQuery;
 import org.eclipse.ui.navigator.CommonDropAdapter;
 import org.eclipse.ui.navigator.CommonDropAdapterAssistant;
@@ -78,26 +87,21 @@ public class DropAdapterAssistant extends CommonDropAdapterAssistant {
     @Override
     public IStatus validateDrop(Object target, int operation, TransferData transferType) {
         if (target instanceof TmfTraceFolder) {
-            getCommonDropAdapter().overrideOperation(DND.DROP_COPY);
             return Status.OK_STATUS;
         }
         if (target instanceof TmfExperimentElement) {
-            getCommonDropAdapter().overrideOperation(DND.DROP_LINK);
             return Status.OK_STATUS;
         }
         if (target instanceof TmfTraceElement) {
             ITmfProjectModelElement parent = ((TmfTraceElement) target).getParent();
             if (parent instanceof TmfTraceFolder) {
-                getCommonDropAdapter().overrideOperation(DND.DROP_COPY);
                 return Status.OK_STATUS;
             }
             if (parent instanceof TmfExperimentElement) {
-                getCommonDropAdapter().overrideOperation(DND.DROP_LINK);
                 return Status.OK_STATUS;
             }
         }
         if (target instanceof IProject) {
-            getCommonDropAdapter().overrideOperation(DND.DROP_COPY);
             return Status.OK_STATUS;
         }
         return Status.CANCEL_STATUS;
@@ -113,6 +117,11 @@ public class DropAdapterAssistant extends CommonDropAdapterAssistant {
         // Use local variable to avoid parameter assignment
         Object targetToUse = aTarget;
 
+        int operation = aDropTargetEvent.detail;
+        if (operation != DND.DROP_LINK) {
+            operation = DND.DROP_COPY;
+        }
+
         // If target is a trace, use its parent (either trace folder or experiment)
         if (targetToUse instanceof TmfTraceElement) {
             targetToUse = ((TmfTraceElement) targetToUse).getParent();
@@ -145,20 +154,13 @@ public class DropAdapterAssistant extends CommonDropAdapterAssistant {
                 if (source instanceof TmfTraceElement) {
                     TmfTraceElement sourceTrace = (TmfTraceElement) source;
                     // If source trace is under an experiment, use the original trace from the traces folder
-                    if (sourceTrace.getParent() instanceof TmfExperimentElement) {
-                        for (TmfTraceElement trace : sourceTrace.getProject().getTracesFolder().getTraces()) {
-                            if (trace.getName().equals(sourceTrace.getName())) {
-                                sourceTrace = trace;
-                                break;
-                            }
-                        }
-                    }
+                    sourceTrace = sourceTrace.getElementUnderTraceFolder();
                     if (targetToUse instanceof TmfExperimentElement) {
                         TmfExperimentElement targetExperiment = (TmfExperimentElement) targetToUse;
-                        ok |= drop(sourceTrace, targetExperiment);
+                        ok |= drop(sourceTrace, targetExperiment, operation);
                     } else if (targetToUse instanceof TmfTraceFolder) {
                         TmfTraceFolder traceFolder = (TmfTraceFolder) targetToUse;
-                        ok |= drop(sourceTrace, traceFolder);
+                        ok |= drop(sourceTrace, traceFolder, operation);
                     }
                 } else if (source instanceof IResource) {
                     IResource sourceResource = (IResource) source;
@@ -167,10 +169,10 @@ public class DropAdapterAssistant extends CommonDropAdapterAssistant {
                     }
                     if (targetToUse instanceof TmfExperimentElement) {
                         TmfExperimentElement targetExperiment = (TmfExperimentElement) targetToUse;
-                        ok |= drop(sourceResource, targetExperiment);
+                        ok |= (drop(sourceResource, targetExperiment, operation) != null);
                     } else if (targetToUse instanceof TmfTraceFolder) {
                         TmfTraceFolder traceFolder = (TmfTraceFolder) targetToUse;
-                        ok |= drop(sourceResource, traceFolder);
+                        ok |= (drop(sourceResource, traceFolder, operation) != null);
                     }
                 }
             }
@@ -180,10 +182,10 @@ public class DropAdapterAssistant extends CommonDropAdapterAssistant {
                 Path path = new Path(source);
                 if (targetToUse instanceof TmfExperimentElement) {
                     TmfExperimentElement targetExperiment = (TmfExperimentElement) targetToUse;
-                    ok |= drop(path, targetExperiment);
+                    ok |= drop(path, targetExperiment, operation);
                 } else if (targetToUse instanceof TmfTraceFolder) {
                     TmfTraceFolder traceFolder = (TmfTraceFolder) targetToUse;
-                    ok |= drop(path, traceFolder);
+                    ok |= drop(path, traceFolder, operation);
                 }
             }
         }
@@ -192,92 +194,102 @@ public class DropAdapterAssistant extends CommonDropAdapterAssistant {
 
 
     /**
-     * Drop a trace by copying a resource in a target experiment
+     * Drop a trace by copying/linking a trace element in a target experiment
      *
      * @param sourceTrace the source trace element to copy
      * @param targetExperiment the target experiment
+     * @param operation the drop operation (DND.DROP_COPY | DND.DROP_LINK)
      * @return true if successful
      */
     private static boolean drop(TmfTraceElement sourceTrace,
-            TmfExperimentElement targetExperiment) {
+            TmfExperimentElement targetExperiment,
+            int operation) {
 
         IResource sourceResource = sourceTrace.getResource();
+        IResource targetResource = drop(sourceResource, targetExperiment, operation);
 
-        if (drop(sourceResource, targetExperiment)) {
-            IFolder destinationSupplementaryFolder = targetExperiment.getTraceSupplementaryFolder(sourceResource.getName());
-            if (!destinationSupplementaryFolder.exists()) {
-                sourceTrace.copySupplementaryFolder(destinationSupplementaryFolder);
-            }
+        if (targetResource != null) {
+            IFolder destinationSupplementaryFolder = targetExperiment.getTraceSupplementaryFolder(targetResource.getName());
+            sourceTrace.copySupplementaryFolder(destinationSupplementaryFolder);
             return true;
         }
         return false;
     }
 
     /**
-     * Drop a trace by copying a resource in a target experiment
+     * Drop a trace by copying/linking a resource in a target experiment
      *
      * @param sourceResource the source resource
      * @param targetExperiment the target experiment
-     * @return true if successful
+     * @param operation the drop operation (DND.DROP_COPY | DND.DROP_LINK)
+     * @return the target resource or null if unsuccessful
      */
-    private static boolean drop(IResource sourceResource,
-            TmfExperimentElement targetExperiment) {
-        boolean doit = true;
+    private static IResource drop(IResource sourceResource,
+            TmfExperimentElement targetExperiment,
+            int operation) {
 
-        //Use local variable to avoid parameter assignment
-        IResource sourceResourceToUse = sourceResource;
+        IResource traceResource = sourceResource;
 
-        TmfProjectElement projectElement = TmfProjectRegistry.getProject(sourceResourceToUse.getProject());
+        TmfProjectElement projectElement = TmfProjectRegistry.getProject(sourceResource.getProject());
         for (TmfTraceElement trace : targetExperiment.getTraces()) {
-            if (trace.getName().equals(sourceResourceToUse.getName())) {
-                doit = false;
-                break;
+            if (trace.getName().equals(sourceResource.getName()) && targetExperiment.getProject().equals(projectElement)) {
+                return null;
             }
         }
-        if (doit && !targetExperiment.getProject().equals(projectElement)) {
+        if (!targetExperiment.getProject().equals(projectElement)) {
+            String targetName = sourceResource.getName();
             for (TmfTraceElement trace : targetExperiment.getProject().getTracesFolder().getTraces()) {
-                if (trace.getName().equals(sourceResourceToUse.getName())) {
-                    doit = false;
+                if (trace.getName().equals(targetName)) {
+                    targetName = promptRename(trace);
+                    if (targetName == null) {
+                        return null;
+                    }
                     break;
                 }
             }
-            if (doit) {
-                try {
-                    IPath destination = targetExperiment.getProject().getTracesFolder().getResource().getFullPath().addTrailingSeparator().append(sourceResourceToUse.getName());
-                    sourceResourceToUse.copy(destination, false, null);
+            try {
+                if (operation == DND.DROP_COPY) {
+                    IPath destination = targetExperiment.getProject().getTracesFolder().getResource().getFullPath().addTrailingSeparator().append(targetName);
+                    sourceResource.copy(destination, false, null);
                     cleanupBookmarks(destination);
-                    // use the copied resource for the experiment
-                    if (sourceResourceToUse.getType() == IResource.FILE) {
-                        sourceResourceToUse = targetExperiment.getProject().getTracesFolder().getResource().getFile(sourceResourceToUse.getName());
-                    } else if (sourceResourceToUse.getType() == IResource.FOLDER) {
-                        sourceResourceToUse = targetExperiment.getProject().getTracesFolder().getResource().getFolder(sourceResourceToUse.getName());
-                    }
-                } catch (CoreException e) {
-                    doit = false;
-                    displayException(e);
+                } else {
+                    createLink(targetExperiment.getProject().getTracesFolder().getResource(), sourceResource, targetName);
+                }
+                // use the copied resource for the experiment
+                if (sourceResource.getType() == IResource.FILE) {
+                    traceResource = targetExperiment.getProject().getTracesFolder().getResource().getFile(targetName);
+                } else if (sourceResource.getType() == IResource.FOLDER) {
+                    traceResource = targetExperiment.getProject().getTracesFolder().getResource().getFolder(targetName);
                 }
+            } catch (CoreException e) {
+                displayException(e);
+                return null;
             }
         }
-        if (doit) {
-            if (sourceResourceToUse != null && sourceResourceToUse.exists()) {
-                createLink(targetExperiment.getResource(), sourceResourceToUse);
-                return true;
-            }
+        if (traceResource != null && traceResource.exists()) {
+            createLink(targetExperiment.getResource(), traceResource, traceResource.getName());
+            return traceResource;
         }
-        return false;
+        return null;
     }
 
     /**
-     * Drop a trace by copying it's a trace element in a trace folder
+     * Drop a trace by copying/linking a trace element in a trace folder
      *
      * @param sourceTrace the source trace
      * @param traceFolder the target trace folder
+     * @param operation the drop operation (DND.DROP_COPY | DND.DROP_LINK)
      * @return true if successful
      */
-    private static boolean drop(TmfTraceElement sourceTrace, TmfTraceFolder traceFolder) {
+    private static boolean drop(TmfTraceElement sourceTrace,
+            TmfTraceFolder traceFolder,
+            int operation) {
+
         IResource sourceResource = sourceTrace.getResource();
-        if (drop(sourceResource, traceFolder)) {
-            IFolder destinationSupplementaryFolder = traceFolder.getTraceSupplementaryFolder(sourceResource.getName());
+        IResource targetResource = drop(sourceResource, traceFolder, operation);
+
+        if (targetResource != null) {
+            IFolder destinationSupplementaryFolder = traceFolder.getTraceSupplementaryFolder(targetResource.getName());
             sourceTrace.copySupplementaryFolder(destinationSupplementaryFolder);
             return true;
         }
@@ -285,77 +297,91 @@ public class DropAdapterAssistant extends CommonDropAdapterAssistant {
     }
 
     /**
-     * Drop a trace by copying a resource in a trace folder
+     * Drop a trace by copying/linking a resource in a trace folder
      *
      * @param sourceResource the source resource
      * @param traceFolder the target trace folder
-     * @return true if successful
+     * @param operation the drop operation (DND.DROP_COPY | DND.DROP_LINK)
+     * @return the target resource or null if unsuccessful
      */
-    private static boolean drop(IResource sourceResource, TmfTraceFolder traceFolder) {
-        boolean doit = true;
+    private static IResource drop(IResource sourceResource,
+            TmfTraceFolder traceFolder,
+            int operation) {
 
+        if (sourceResource.getProject().equals(traceFolder.getResource().getProject())) {
+            return null;
+        }
+        String targetName = sourceResource.getName();
         for (TmfTraceElement trace : traceFolder.getTraces()) {
-            if (trace.getName().equals(sourceResource.getName())) {
-                doit = false;
+            if (trace.getName().equals(targetName)) {
+                targetName = promptRename(trace);
+                if (targetName == null) {
+                    return null;
+                }
                 break;
             }
         }
-        if (doit) {
-            try {
-                IPath destination = traceFolder.getResource().getFullPath().addTrailingSeparator().append(sourceResource.getName());
+        try {
+            if (operation == DND.DROP_COPY) {
+                IPath destination = traceFolder.getResource().getFullPath().addTrailingSeparator().append(targetName);
                 sourceResource.copy(destination, false, null);
-
                 cleanupBookmarks(destination);
-                return true;
-            } catch (CoreException e) {
-                displayException(e);
+            } else {
+                createLink(traceFolder.getResource(), sourceResource, targetName);
             }
+            return traceFolder.getResource().findMember(targetName);
+        } catch (CoreException e) {
+            displayException(e);
         }
-        return false;
+        return null;
     }
 
     /**
-     * Drop a trace by importing a path in a target experiment
+     * Drop a trace by importing/linking a path in a target experiment
      *
      * @param path the source path
      * @param targetExperiment the target experiment
+     * @param operation the drop operation (DND.DROP_COPY | DND.DROP_LINK)
      * @return true if successful
      */
-    private static boolean drop(Path path, TmfExperimentElement targetExperiment) {
-        boolean doit = true;
+    private static boolean drop(Path path,
+            TmfExperimentElement targetExperiment,
+            int operation) {
 
         // Use local variable to avoid parameter assignment
         Path pathToUse = path;
 
         for (TmfTraceElement trace : targetExperiment.getTraces()) {
-            if (trace.getName().equals(pathToUse.lastSegment())) {
-                doit = false;
-                break;
+            if (trace.getName().equals(pathToUse.lastSegment()) && pathToUse.toString().startsWith(targetExperiment.getProject().getResource().getLocation().toString())) {
+                return false;
             }
         }
-        if (doit && !pathToUse.toString().startsWith(targetExperiment.getProject().getResource().getLocation().toString())) {
+        if (!pathToUse.toString().startsWith(targetExperiment.getProject().getResource().getLocation().toString())) {
+            String targetName = pathToUse.lastSegment();
             for (TmfTraceElement trace : targetExperiment.getProject().getTracesFolder().getTraces()) {
-                if (trace.getName().equals(pathToUse.lastSegment())) {
-                    doit = false;
+                if (trace.getName().equals(targetName)) {
+                    targetName = promptRename(trace);
+                    if (targetName == null) {
+                        return false;
+                    }
                     break;
                 }
             }
-            if (doit) {
-                importTrace(targetExperiment.getProject().getTracesFolder().getResource(), pathToUse);
-                // use the imported trace for the experiment
-                pathToUse = new Path(targetExperiment.getProject().getTracesFolder().getResource().getFile(pathToUse.lastSegment()).getLocation().toString());
+            if (operation == DND.DROP_COPY) {
+                importTrace(targetExperiment.getProject().getTracesFolder().getResource(), pathToUse, targetName);
+            } else {
+                createLink(targetExperiment.getProject().getTracesFolder().getResource(), pathToUse, targetName);
             }
-        }
-        if (doit) {
+            // use the copied resource for the experiment
             IResource resource = null;
             File file = new File(pathToUse.toString());
             if (file.exists() && file.isFile()) {
-                resource = targetExperiment.getProject().getTracesFolder().getResource().getFile(pathToUse.lastSegment());
+                resource = targetExperiment.getProject().getTracesFolder().getResource().getFile(targetName);
             } else if (file.exists() && file.isDirectory()) {
-                resource = targetExperiment.getProject().getTracesFolder().getResource().getFolder(pathToUse.lastSegment());
+                resource = targetExperiment.getProject().getTracesFolder().getResource().getFolder(targetName);
             }
             if (resource != null && resource.exists()) {
-                createLink(targetExperiment.getResource(), resource);
+                createLink(targetExperiment.getResource(), resource, resource.getName());
                 return true;
             }
         }
@@ -363,58 +389,90 @@ public class DropAdapterAssistant extends CommonDropAdapterAssistant {
     }
 
     /**
-     * Drop a trace by importing a path in a trace folder
+     * Drop a trace by importing/linking a path in a trace folder
      *
      * @param path the source path
      * @param traceFolder the target trace folder
+     * @param operation the drop operation (DND.DROP_COPY | DND.DROP_LINK)
      * @return true if successful
      */
-    private static boolean drop(Path path, TmfTraceFolder traceFolder) {
-        boolean doit = true;
+    private static boolean drop(Path path,
+            TmfTraceFolder traceFolder,
+            int operation) {
+
+        String targetName = path.lastSegment();
         for (TmfTraceElement trace : traceFolder.getTraces()) {
-            if (trace.getName().equals(path.lastSegment())) {
-                doit = false;
+            if (trace.getName().equals(targetName)) {
+                targetName = promptRename(trace);
+                if (targetName == null) {
+                    return false;
+                }
                 break;
             }
         }
-        if (doit) {
-            importTrace(traceFolder.getResource(), path);
-            return true;
+        if (operation == DND.DROP_COPY) {
+            importTrace(traceFolder.getResource(), path, targetName);
+        } else {
+            createLink(traceFolder.getResource(), path, targetName);
         }
-        return false;
+        return true;
     }
 
     /**
      * Import a trace to the trace folder
      *
-     * @param resource the trace folder resource
+     * @param folder the trace folder resource
      * @param path the path to the trace to import
+     * @param targetName the target name
      */
-    private static void importTrace(IFolder resource, Path path) {
-        IPath containerPath = resource.getFullPath();
-        File file = new File(path.toString());
-        File source = file.getParentFile();
-        IOverwriteQuery overwriteImplementor = new IOverwriteQuery() {
-            @Override
-            public String queryOverwrite(String pathString) {
-                return IOverwriteQuery.NO_ALL;
+    private static void importTrace(final IFolder folder, final Path path, final String targetName) {
+        final File source = new File(path.toString());
+        if (source.isDirectory()) {
+            IPath containerPath = folder.getFullPath().addTrailingSeparator().append(targetName);
+            IOverwriteQuery overwriteImplementor = new IOverwriteQuery() {
+                @Override
+                public String queryOverwrite(String pathString) {
+                    return IOverwriteQuery.NO_ALL;
+                }
+            };
+            List<File> filesToImport = Arrays.asList(source.listFiles());
+            ImportOperation operation = new ImportOperation(
+                    containerPath,
+                    source,
+                    FileSystemStructureProvider.INSTANCE,
+                    overwriteImplementor,
+                    filesToImport);
+            operation.setCreateContainerStructure(false);
+            try {
+                operation.run(new NullProgressMonitor());
+            } catch (InvocationTargetException e) {
+                displayException(e);
+            } catch (InterruptedException e) {
+                displayException(e);
+            }
+        } else {
+            IRunnableWithProgress runnable = new IRunnableWithProgress() {
+                @Override
+                public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
+                    try {
+                        InputStream inputStream = new FileInputStream(source);
+                        IFile targetFile = folder.getFile(targetName);
+                        targetFile.create(inputStream, IResource.NONE, monitor);
+                    } catch (CoreException e) {
+                        displayException(e);
+                    } catch (FileNotFoundException e) {
+                        displayException(e);
+                    }
+                }
+            };
+            WorkspaceModifyDelegatingOperation operation = new WorkspaceModifyDelegatingOperation(runnable);
+            try {
+                operation.run(new NullProgressMonitor());
+            } catch (InvocationTargetException e) {
+                displayException(e);
+            } catch (InterruptedException e) {
+                displayException(e);
             }
-        };
-        List<File> filesToImport = new LinkedList<File>();
-        filesToImport.add(file);
-        ImportOperation operation = new ImportOperation(
-                containerPath,
-                source,
-                FileSystemStructureProvider.INSTANCE,
-                overwriteImplementor,
-                filesToImport);
-        operation.setCreateContainerStructure(false);
-        try {
-            operation.run(new NullProgressMonitor());
-        } catch (InvocationTargetException e) {
-            displayException(e);
-        } catch (InterruptedException e) {
-            displayException(e);
         }
     }
 
@@ -423,8 +481,9 @@ public class DropAdapterAssistant extends CommonDropAdapterAssistant {
      *
      * @param parentFolder the parent folder
      * @param resource the resource
+     * @param targetName the target name
      */
-    private static void createLink(IFolder parentFolder, IResource resource) {
+    private static void createLink(IFolder parentFolder, IResource resource, String targetName) {
         IPath location = resource.getLocation();
         IWorkspace workspace = ResourcesPlugin.getWorkspace();
         try {
@@ -435,7 +494,7 @@ public class DropAdapterAssistant extends CommonDropAdapterAssistant {
             String supplFolder = properties.get(TmfCommonConstants.TRACE_SUPPLEMENTARY_FOLDER);
 
             if (resource instanceof IFolder) {
-                IFolder folder = parentFolder.getFolder(resource.getName());
+                IFolder folder = parentFolder.getFolder(targetName);
                 if (workspace.validateLinkLocation(folder, location).isOK()) {
                     folder.createLink(location, IResource.REPLACE, null);
                     setProperties(folder, bundleName, traceType, iconUrl, supplFolder);
@@ -444,8 +503,7 @@ public class DropAdapterAssistant extends CommonDropAdapterAssistant {
                     Activator.getDefault().logError("Invalid Trace Location"); //$NON-NLS-1$
                 }
             } else {
-                IFile file = parentFolder.getFile(resource.getName());
-
+                IFile file = parentFolder.getFile(targetName);
                 if (workspace.validateLinkLocation(file, location).isOK()) {
                     file.createLink(location, IResource.REPLACE, null);
                     setProperties(file, bundleName, traceType, iconUrl, supplFolder);
@@ -458,6 +516,62 @@ public class DropAdapterAssistant extends CommonDropAdapterAssistant {
         }
     }
 
+    /**
+     * Create a link to a file or folder
+     *
+     * @param parentFolder the parent folder
+     * @param source the file or folder
+     * @param targetName the target name
+     */
+    private static void createLink(IFolder parentFolder, IPath location, String targetName) {
+        File source = new File(location.toString());
+        IWorkspace workspace = ResourcesPlugin.getWorkspace();
+        try {
+
+            if (source.isDirectory()) {
+                IFolder folder = parentFolder.getFolder(targetName);
+                if (workspace.validateLinkLocation(folder, location).isOK()) {
+                    folder.createLink(location, IResource.REPLACE, null);
+                } else {
+                    Activator.getDefault().logError("Invalid Trace Location"); //$NON-NLS-1$
+                }
+            } else {
+                IFile file = parentFolder.getFile(targetName);
+                if (workspace.validateLinkLocation(file, location).isOK()) {
+                    file.createLink(location, IResource.REPLACE, null);
+                } else {
+                    Activator.getDefault().logError("Invalid Trace Location"); //$NON-NLS-1$
+                }
+            }
+        } catch (CoreException e) {
+            displayException(e);
+        }
+    }
+
+    /**
+     * Prompts the user to rename a trace
+     *
+     * @param trace the existing trace
+     * @return the new name to use or null if rename is canceled
+     */
+    private static String promptRename(TmfTraceElement trace) {
+        MessageBox mb = new MessageBox(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), SWT.ICON_QUESTION | SWT.CANCEL | SWT.OK);
+        mb.setText(Messages.DropAdapterAssistant_RenameTraceTitle);
+        mb.setMessage(NLS.bind(Messages.DropAdapterAssistant_RenameTraceMessage, trace.getName()));
+        if (mb.open() != SWT.OK) {
+            return null;
+        }
+        IFolder folder = trace.getProject().getTracesFolder().getResource();
+        int i = 2;
+        while (true) {
+            String name = trace.getName() + '-' + Integer.toString(i++);
+            IResource resource = folder.findMember(name);
+            if (resource == null) {
+                return name;
+            }
+        }
+    }
+
     /**
      * Cleanup bookmarks file in copied trace
      */
index 049315a051f54fe6b1166301ca0d8f4587041e43..be34c4314e1fe58470334d3c92d2bc3c58c2717c 100644 (file)
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2011, 2012 Ericsson
+ * Copyright (c) 2011, 2012, 2013 Ericsson
  *
  * All rights reserved. This program and the accompanying materials are
  * made available under the terms of the Eclipse Public License v1.0 which
@@ -8,6 +8,7 @@
  *
  * Contributors:
  *   Francois Chouinard - Initial API and implementation
+ *   Patrick Tasse - Added drag and drop messages
  *******************************************************************************/
 
 package org.eclipse.linuxtools.internal.tmf.ui.project.handlers;
@@ -44,8 +45,8 @@ public class Messages extends NLS {
     public static String SelectTraceTypeHandler_Title;
     public static String SelectTraceTypeHandler_InvalidTraceType;
 
-    public static String ClearViewsHandler_message;
-    public static String ClearViewsHandler_title;
+    public static String DropAdapterAssistant_RenameTraceTitle;
+    public static String DropAdapterAssistant_RenameTraceMessage;
 
     static {
         // initialize resource bundle
index 7cce3077b51f7cfcc43ba21b54a95e0cf48aa188..e434c081befad413d2b755bccf45dd5a1b0f36f2 100644 (file)
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2011 Ericsson
+ * Copyright (c) 2011, 2013 Ericsson
  *
  * All rights reserved. This program and the accompanying materials are
  * made available under the terms of the Eclipse Public License v1.0 which
@@ -8,6 +8,7 @@
  *
  * Contributors:
  *   Francois Chouinard - Initial API and implementation
+ *   Patrick Tasse - Fix propagation to experiment traces
  *******************************************************************************/
 
 package org.eclipse.linuxtools.internal.tmf.ui.project.handlers;
@@ -166,7 +167,7 @@ public class SelectTraceTypeHandler extends AbstractHandler {
                 for (final ITmfProjectModelElement child : experiment.getChildren()) {
                     if (child instanceof TmfTraceElement) {
                         TmfTraceElement linkedTrace = (TmfTraceElement) child;
-                        if (linkedTrace.equals(trace)) {
+                        if (linkedTrace.getName().equals(trace.getName())) {
                             IResource resource = linkedTrace.getResource();
                             setProperties(resource, bundleName, traceType, iconUrl);
                             linkedTrace.refreshTraceType();
index ba70355e9bb0663fb683beed097205be17552532..26ec1bfaa97d715c29c198d904ccef03c2abe6ce 100644 (file)
@@ -21,6 +21,6 @@ DeleteExperimentHandler_Error = Error deleting experiment
 SelectTraceTypeHandler_Title = Validation Error
 SelectTraceTypeHandler_InvalidTraceType =  Type could not be set for one or more traces
 
-# Clear tracing views
-ClearViewsHandler_title=Clear Views
-ClearViewsHandler_message=Clear the tracing views
+# Drag and drop
+DropAdapterAssistant_RenameTraceTitle=Confirm rename trace
+DropAdapterAssistant_RenameTraceMessage=A trace with the name ''{0}'' already exists in the target project.\nRename the dropped trace?
index 951b15de52e3a71a8bcbfbd48db9aa748b2c0cac..be8b0a3780c701330039d54be6fdbbe36110f4b7 100644 (file)
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2011, 2012 Ericsson
+ * Copyright (c) 2011, 2012, 2013 Ericsson
  *
  * All rights reserved. This program and the accompanying materials are
  * made available under the terms of the Eclipse Public License v1.0 which
@@ -8,6 +8,7 @@
  *
  * Contributors:
  *   Francois Chouinard - Initial API and implementation
+ *   Patrick Tasse - Add support for unknown trace type icon
  *******************************************************************************/
 
 package org.eclipse.linuxtools.tmf.ui.project.model;
@@ -42,6 +43,7 @@ public class TmfNavigatorLabelProvider implements ICommonLabelProvider {
 
     private static final Image fFolderIcon = PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_OBJ_FOLDER);
     private static final String fTraceIconFile = "icons/elcl16/trace.gif"; //$NON-NLS-1$
+    private static final String fUnknownIconFile = "icons/elcl16/unknown_parser.gif"; //$NON-NLS-1$
     private static final String fExperimentIconFile = "icons/elcl16/experiment.gif"; //$NON-NLS-1$
 
     // ------------------------------------------------------------------------
@@ -52,6 +54,7 @@ public class TmfNavigatorLabelProvider implements ICommonLabelProvider {
     private final Image fExperimentFolderIcon = fFolderIcon;
 
     private final Image fDefaultTraceIcon;
+    private final Image fUnknownTraceIcon;
     private final Image fExperimentIcon;
 
     // ------------------------------------------------------------------------
@@ -66,6 +69,7 @@ public class TmfNavigatorLabelProvider implements ICommonLabelProvider {
     public TmfNavigatorLabelProvider() {
         Bundle bundle = Activator.getDefault().getBundle();
         fDefaultTraceIcon = loadIcon(bundle, fTraceIconFile);
+        fUnknownTraceIcon = loadIcon(bundle, fUnknownIconFile);
         fExperimentIcon = loadIcon(bundle, fExperimentIconFile);
     }
 
@@ -94,10 +98,12 @@ public class TmfNavigatorLabelProvider implements ICommonLabelProvider {
 
         if (element instanceof TmfTraceElement) {
             TmfTraceElement trace = (TmfTraceElement) element;
-            String icon = null;
             try {
+                if (trace.getResource().getPersistentProperty(TmfCommonConstants.TRACETYPE) == null) {
+                    return fUnknownTraceIcon;
+                }
                 String name = trace.getResource().getPersistentProperty(TmfCommonConstants.TRACEBUNDLE);
-                icon = trace.getResource().getPersistentProperty(TmfCommonConstants.TRACEICON);
+                String icon = trace.getResource().getPersistentProperty(TmfCommonConstants.TRACEICON);
                 if (name != null && icon != null) {
                     Bundle bundle = Platform.getBundle(name);
                     return loadIcon(bundle, icon);
This page took 0.04175 seconds and 5 git commands to generate.