From ab37ff41b8435171b6c2fb2a1d05bb780c59daaa Mon Sep 17 00:00:00 2001 From: Patrick Tasse Date: Tue, 26 Feb 2013 15:27:08 -0500 Subject: [PATCH] Drag and drop enhancements - 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 Reviewed-on: https://git.eclipse.org/r/10667 Tested-by: Hudson CI Reviewed-by: Bernd Hufmann IP-Clean: Bernd Hufmann Tested-by: Bernd Hufmann --- .../doc/User-Guide.mediawiki | 4 +- .../doc/images/unknown_parser.gif | Bin 0 -> 259 bytes .../handlers/DropAdapterAssistant.java | 384 ++++++++++++------ .../tmf/ui/project/handlers/Messages.java | 7 +- .../handlers/SelectTraceTypeHandler.java | 5 +- .../ui/project/handlers/messages.properties | 6 +- .../model/TmfNavigatorLabelProvider.java | 12 +- 7 files changed, 271 insertions(+), 147 deletions(-) create mode 100644 org.eclipse.linuxtools.lttng.help/doc/images/unknown_parser.gif diff --git a/org.eclipse.linuxtools.lttng.help/doc/User-Guide.mediawiki b/org.eclipse.linuxtools.lttng.help/doc/User-Guide.mediawiki index 3efcbcdfbb..eecefa7a3e 100644 --- a/org.eclipse.linuxtools.lttng.help/doc/User-Guide.mediawiki +++ b/org.eclipse.linuxtools.lttng.help/doc/User-Guide.mediawiki @@ -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 index 0000000000000000000000000000000000000000..b47221293341e562a8326192231a2b0e7389bef8 GIT binary patch literal 259 zcmV+e0sQ_)Nk%w1VGsZi0E8a^|Nj2<@$vQY^4`qM?%Uh{{r#3GD5OM0v0YuUUthOs zYPf7{zIl1fm6g+?qN-3(|Mm6%`ug?g=>PQe|M&Ox?d|{e_Vw)S|M~g<{QUp*_5b+z z|M&O*`}_a)_W%F?A^8LW0018VEC2ui01yBW000Gm;3tk`X+Do(pr)8Mgb)zTT0U^W z?HoWqBm<#9IH-g~!w8q*Bn*q1fs<(fKMz8r<6!JkoDSh?xL`1m9m0T!L@LTpc|+%{ z6&U&@o~2NBDm#AzS2%uu4h|L`78F(^LK+$zDjF6V1aU4f5IhhQKQ{(25)w2vEhs81 JEv+RX06S(KetQ4_ literal 0 HcmV?d00001 diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/handlers/DropAdapterAssistant.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/handlers/DropAdapterAssistant.java index 41986434ad..0a70cc02cc 100644 --- a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/handlers/DropAdapterAssistant.java +++ b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/handlers/DropAdapterAssistant.java @@ -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 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 filesToImport = new LinkedList(); - 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 */ diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/handlers/Messages.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/handlers/Messages.java index 049315a051..be34c4314e 100644 --- a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/handlers/Messages.java +++ b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/handlers/Messages.java @@ -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 diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/handlers/SelectTraceTypeHandler.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/handlers/SelectTraceTypeHandler.java index 7cce3077b5..e434c081be 100644 --- a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/handlers/SelectTraceTypeHandler.java +++ b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/handlers/SelectTraceTypeHandler.java @@ -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(); diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/handlers/messages.properties b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/handlers/messages.properties index ba70355e9b..26ec1bfaa9 100644 --- a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/handlers/messages.properties +++ b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/handlers/messages.properties @@ -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? diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/project/model/TmfNavigatorLabelProvider.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/project/model/TmfNavigatorLabelProvider.java index 951b15de52..be8b0a3780 100644 --- a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/project/model/TmfNavigatorLabelProvider.java +++ b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/project/model/TmfNavigatorLabelProvider.java @@ -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); -- 2.34.1