From e12ecd303ea111505ad84a9baeaf40140b87ccad Mon Sep 17 00:00:00 2001 From: Bernd Hufmann Date: Mon, 14 May 2012 12:07:20 -0400 Subject: [PATCH] Use supplementary directory for state history tree --- .../tracecontrol/actions/ImportToProject.java | 8 +- .../kernel/core/trace/CtfKernelTrace.java | 24 ++- .../ui/views/control/messages/Messages.java | 2 +- .../control/messages/messages.properties | 12 ++ .../plugin.properties | 4 +- org.eclipse.linuxtools.tmf.ui/plugin.xml | 6 +- .../tmf/ui/project/dialogs/Messages.java | 31 +++ .../SelectSupplementaryResourcesDialog.java | 177 +++++++++++++++ .../ui/project/dialogs/messages.properties | 13 ++ ...teExperimentSupplementaryFilesHandler.java | 33 ++- .../project/handlers/DeleteTraceHandler.java | 2 +- .../DeleteTraceSupplementaryFilesHandler.java | 20 +- .../handlers/DropAdapterAssistant.java | 73 +++++-- .../handlers/OpenExperimentHandler.java | 3 +- .../ui/project/handlers/OpenTraceHandler.java | 15 +- .../project/handlers/RenameTraceHandler.java | 20 +- .../handlers/SelectTraceTypeHandler.java | 25 +-- .../project/handlers/TracePropertyTester.java | 17 +- .../tmf/ui/editors/EventsViewEditor.java | 3 +- .../tmf/ui/editors/TmfEventsEditor.java | 9 +- .../model/TmfNavigatorContentProvider.java | 8 +- .../model/TmfNavigatorLabelProvider.java | 5 +- .../project/model/TmfProjectModelElement.java | 40 ++++ .../tmf/ui/project/model/TmfTraceElement.java | 202 ++++++++++++------ .../project/wizards/CopyExperimentDialog.java | 4 +- .../ui/project/wizards/CopyTraceDialog.java | 5 +- .../wizards/ImportTraceWizardPage.java | 7 +- .../tmf/ui/project/wizards/Messages.java | 12 +- .../project/wizards/NewTmfProjectWizard.java | 7 + .../ui/project/wizards/RenameTraceDialog.java | 2 +- .../wizards/SelectTracesWizardPage.java | 13 +- .../tmf/ui/views/events/TmfEventsView.java | 4 +- 32 files changed, 624 insertions(+), 182 deletions(-) create mode 100644 org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/dialogs/Messages.java create mode 100644 org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/dialogs/SelectSupplementaryResourcesDialog.java create mode 100644 org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/dialogs/messages.properties diff --git a/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/internal/lttng/ui/tracecontrol/actions/ImportToProject.java b/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/internal/lttng/ui/tracecontrol/actions/ImportToProject.java index 34bb52653e..75329030c5 100644 --- a/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/internal/lttng/ui/tracecontrol/actions/ImportToProject.java +++ b/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/internal/lttng/ui/tracecontrol/actions/ImportToProject.java @@ -33,7 +33,7 @@ import org.eclipse.linuxtools.internal.lttng.core.tracecontrol.model.TraceResour import org.eclipse.linuxtools.internal.lttng.ui.Activator; import org.eclipse.linuxtools.internal.lttng.ui.tracecontrol.Messages; import org.eclipse.linuxtools.internal.lttng.ui.tracecontrol.dialogs.ImportTraceDialog; -import org.eclipse.linuxtools.tmf.ui.project.model.TmfTraceElement; +import org.eclipse.linuxtools.tmf.core.TmfCommonConstants; import org.eclipse.rse.core.RSECorePlugin; import org.eclipse.rse.core.model.IHost; import org.eclipse.rse.core.subsystems.ISubSystem; @@ -271,9 +271,9 @@ public class ImportToProject implements IObjectActionDelegate, IWorkbenchWindowA folder.createLink(sourceFolder.toURI(), IResource.REPLACE, null); // Set the trace properties for this resource // FIXME: update from extension point properties - folder.setPersistentProperty(TmfTraceElement.TRACEBUNDLE, Activator.PLUGIN_ID); - folder.setPersistentProperty(TmfTraceElement.TRACETYPE, "org.eclipse.linuxtools.lttng.tracetype.kernel"); //$NON-NLS-1$ - folder.setPersistentProperty(TmfTraceElement.TRACEICON, "icons/obj16/tux2.png"); //$NON-NLS-1$ + folder.setPersistentProperty(TmfCommonConstants.TRACEBUNDLE, Activator.PLUGIN_ID); + folder.setPersistentProperty(TmfCommonConstants.TRACETYPE, "org.eclipse.linuxtools.lttng.tracetype.kernel"); //$NON-NLS-1$ + folder.setPersistentProperty(TmfCommonConstants.TRACEICON, "icons/obj16/tux2.png"); //$NON-NLS-1$ } catch (CoreException e) { MessageDialog.openWarning(shell, Messages.ImportToProject_ImportFailed, diff --git a/org.eclipse.linuxtools.lttng2.kernel.core/src/org/eclipse/linuxtools/lttng2/kernel/core/trace/CtfKernelTrace.java b/org.eclipse.linuxtools.lttng2.kernel.core/src/org/eclipse/linuxtools/lttng2/kernel/core/trace/CtfKernelTrace.java index d0da1ddf67..07da6e72c9 100644 --- a/org.eclipse.linuxtools.lttng2.kernel.core/src/org/eclipse/linuxtools/lttng2/kernel/core/trace/CtfKernelTrace.java +++ b/org.eclipse.linuxtools.lttng2.kernel.core/src/org/eclipse/linuxtools/lttng2/kernel/core/trace/CtfKernelTrace.java @@ -15,11 +15,11 @@ package org.eclipse.linuxtools.lttng2.kernel.core.trace; import java.io.File; import java.io.IOException; -import org.eclipse.core.resources.IFile; -import org.eclipse.core.resources.IFolder; import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IResource; +import org.eclipse.core.runtime.CoreException; import org.eclipse.linuxtools.internal.lttng2.kernel.core.stateprovider.CtfKernelStateInput; +import org.eclipse.linuxtools.tmf.core.TmfCommonConstants; import org.eclipse.linuxtools.tmf.core.ctfadaptor.CtfTmfTrace; import org.eclipse.linuxtools.tmf.core.exceptions.TmfTraceException; import org.eclipse.linuxtools.tmf.core.statesystem.HistoryBuilder; @@ -37,6 +37,11 @@ import org.eclipse.linuxtools.tmf.core.statesystem.backend.historytree.ThreadedH */ public class CtfKernelTrace extends CtfTmfTrace { + /** + * The file name of the History Tree + */ + public final static String HISTORY_TREE_FILE_NAME = "stateHistory.ht"; //$NON-NLS-1$ + /** Size of the blocking queue to use when building a state history */ private final static int QUEUE_SIZE = 10000; @@ -57,12 +62,17 @@ public class CtfKernelTrace extends CtfTmfTrace { protected void buildStateSystem() throws TmfTraceException { /* Set up the path to the history tree file we'll use */ IResource resource = getResource(); - String name = '.' + resource.getName() + ".ht"; //$NON-NLS-1$ - IFolder folder = (IFolder)resource.getParent(); - IFile file = folder.getFile(name); + String supplDirectory = null; + + try { + // get the directory where the history file will be stored. + supplDirectory = resource.getPersistentProperty(TmfCommonConstants.TRACE_SUPPLEMENTARY_FOLDER); + } catch (CoreException e) { + throw new TmfTraceException(e.getMessage()); + } + + final File htFile = new File(supplDirectory + File.separator + HISTORY_TREE_FILE_NAME); - final File htFile = new File(file.getLocationURI()); - IStateHistoryBackend htBackend; IStateChangeInput htInput; HistoryBuilder builder; diff --git a/org.eclipse.linuxtools.lttng2.ui/src/org/eclipse/linuxtools/internal/lttng2/ui/views/control/messages/Messages.java b/org.eclipse.linuxtools.lttng2.ui/src/org/eclipse/linuxtools/internal/lttng2/ui/views/control/messages/Messages.java index ec5058a93e..e9ecdf0944 100644 --- a/org.eclipse.linuxtools.lttng2.ui/src/org/eclipse/linuxtools/internal/lttng2/ui/views/control/messages/Messages.java +++ b/org.eclipse.linuxtools.lttng2.ui/src/org/eclipse/linuxtools/internal/lttng2/ui/views/control/messages/Messages.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 201s Ericsson + * Copyright (c) 2012 Ericsson * * All rights reserved. This program and the accompanying materials are * made available under the terms of the Eclipse Public License v1.0 which diff --git a/org.eclipse.linuxtools.lttng2.ui/src/org/eclipse/linuxtools/internal/lttng2/ui/views/control/messages/messages.properties b/org.eclipse.linuxtools.lttng2.ui/src/org/eclipse/linuxtools/internal/lttng2/ui/views/control/messages/messages.properties index a3355f528c..ec3706ad58 100644 --- a/org.eclipse.linuxtools.lttng2.ui/src/org/eclipse/linuxtools/internal/lttng2/ui/views/control/messages/messages.properties +++ b/org.eclipse.linuxtools.lttng2.ui/src/org/eclipse/linuxtools/internal/lttng2/ui/views/control/messages/messages.properties @@ -1,3 +1,15 @@ +############################################################################### +# Copyright (c) 2012 Ericsson. +# +# All rights reserved. This program and the accompanying materials +# are made available under the terms of the Eclipse Public License v1.0 +# which accompanies this distribution, and is available at +# http://www.eclipse.org/legal/epl-v10.html +# +# Contributors: +# Bernd Hufmann - initial API and implementation +############################################################################### + TraceControl_ConnectionFailure=Connecting to host failed TraceControl_DisconnectionFailure=Disconnection to host failed TraceControl_ExecutionCancelled=Command Execution cancelled diff --git a/org.eclipse.linuxtools.tmf.ui/plugin.properties b/org.eclipse.linuxtools.tmf.ui/plugin.properties index ad451401b1..a30e10be8e 100644 --- a/org.eclipse.linuxtools.tmf.ui/plugin.properties +++ b/org.eclipse.linuxtools.tmf.ui/plugin.properties @@ -70,7 +70,7 @@ commands.trace.remove = Remove commands.trace.remove.mnemonic = D commands.trace.remove.description = Remove a Trace from Experiment -commands.trace.deleteSupplementaryFiles = Delete Supplementary Files +commands.trace.deleteSupplementaryFiles = Delete Supplementary Files... commands.trace.deleteSupplementaryFiles.mnemonic = S commands.trace.deleteSupplementaryFiles.description = Delete Supplementary Files @@ -121,7 +121,7 @@ commands.experiment.refresh = Refresh commands.experiment.refresh.mnemonic = F commands.experiment.refresh.description = Refresh the Experiment -commands.experiment.deleteSupplementaryFiles = Delete Supplementary Files +commands.experiment.deleteSupplementaryFiles = Delete Supplementary Files... commands.experiment.deleteSupplementaryFiles.mnemonic = S commands.experiment.deleteSupplementaryFiles.description = Delete Supplementary Files of Each Trace diff --git a/org.eclipse.linuxtools.tmf.ui/plugin.xml b/org.eclipse.linuxtools.tmf.ui/plugin.xml index 5c3e9a0a2a..577b2b061e 100644 --- a/org.eclipse.linuxtools.tmf.ui/plugin.xml +++ b/org.eclipse.linuxtools.tmf.ui/plugin.xml @@ -538,7 +538,7 @@ + property="org.eclipse.linuxtools.tmf.ui.hasSupplementaryFiles"> @@ -771,7 +771,7 @@ + property="org.eclipse.linuxtools.tmf.ui.hasSupplementaryFiles"> @@ -1193,7 +1193,7 @@ class="org.eclipse.linuxtools.internal.tmf.ui.project.handlers.TracePropertyTester" id="org.eclipse.linuxtools.tmf.ui.tracePropertyTester" namespace="org.eclipse.linuxtools.tmf.ui" - properties="isExperimentTrace,hasHistoryFile" + properties="isExperimentTrace,hasSupplementaryFiles" type="org.eclipse.linuxtools.tmf.ui.project.model.TmfProjectModelElement"> diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/dialogs/Messages.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/dialogs/Messages.java new file mode 100644 index 0000000000..2a120b14ec --- /dev/null +++ b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/dialogs/Messages.java @@ -0,0 +1,31 @@ +/******************************************************************************* + * Copyright (c) 2011 Ericsson + * + * All rights reserved. This program and the accompanying materials are + * made available under the terms of the Eclipse Public License v1.0 which + * accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Francois Chouinard - Initial API and implementation + *******************************************************************************/ + +package org.eclipse.linuxtools.internal.tmf.ui.project.dialogs; + +import org.eclipse.osgi.util.NLS; + +public class Messages extends NLS { + + private static final String BUNDLE_NAME = "org.eclipse.linuxtools.internal.tmf.ui.project.dialogs.messages"; //$NON-NLS-1$ + + public static String SelectSpplementaryResources_DialogTitle; + public static String SelectSpplementaryResources_ResourcesGroupTitle; + + static { + // initialize resource bundle + NLS.initializeMessages(BUNDLE_NAME, Messages.class); + } + + private Messages() { + } +} diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/dialogs/SelectSupplementaryResourcesDialog.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/dialogs/SelectSupplementaryResourcesDialog.java new file mode 100644 index 0000000000..4fc9e796db --- /dev/null +++ b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/dialogs/SelectSupplementaryResourcesDialog.java @@ -0,0 +1,177 @@ +/******************************************************************************* + * Copyright (c) 2009, 2011 Ericsson + * + * All rights reserved. This program and the accompanying materials are + * made available under the terms of the Eclipse Public License v1.0 which + * accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Francois Chouinard - Copied and adapted from NewFolderDialog + *******************************************************************************/ + +package org.eclipse.linuxtools.internal.tmf.ui.project.dialogs; + +import java.io.File; +import java.util.Arrays; + +import org.eclipse.core.resources.IResource; +import org.eclipse.jface.dialogs.Dialog; +import org.eclipse.jface.dialogs.IDialogConstants; +import org.eclipse.jface.viewers.CheckboxTreeViewer; +import org.eclipse.jface.viewers.ITreeContentProvider; +import org.eclipse.jface.viewers.LabelProvider; +import org.eclipse.jface.viewers.Viewer; +import org.eclipse.swt.SWT; +import org.eclipse.swt.graphics.Point; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Group; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.swt.widgets.Tree; +import org.eclipse.ui.ISharedImages; +import org.eclipse.ui.PlatformUI; + +/** + * SelectSupplementaryResourcesDialog + *

+ */ +public class SelectSupplementaryResourcesDialog extends Dialog { + + // ------------------------------------------------------------------------ + // Members + // ------------------------------------------------------------------------ + private CheckboxTreeViewer fTreeViewer; + private final IResource[] fAvailableResources; + private IResource[] fReturndResources; + + // ------------------------------------------------------------------------ + // Constructor + // ------------------------------------------------------------------------ + + public SelectSupplementaryResourcesDialog(Shell shell, IResource[] resources) { + super(shell); + fAvailableResources = Arrays.copyOf(resources, resources.length); + setShellStyle(SWT.RESIZE); + } + + // ------------------------------------------------------------------------ + // Getters/Setters + // ------------------------------------------------------------------------ + + public IResource[] getResources() { + return Arrays.copyOf(fReturndResources, fReturndResources.length); + } + + // ------------------------------------------------------------------------ + // Dialog + // ------------------------------------------------------------------------ + + /* + * (non-Javadoc) + * @see org.eclipse.jface.window.Window#configureShell(org.eclipse.swt.widgets.Shell) + */ + @Override + protected void configureShell(Shell newShell) { + super.configureShell(newShell); + newShell.setText(Messages.SelectSpplementaryResources_DialogTitle); + newShell.setImage(PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_ETOOL_DELETE)); + } + + @Override + protected Control createDialogArea(Composite parent) { + Composite composite = (Composite) super.createDialogArea(parent); + composite.setLayout(new GridLayout()); + composite.setLayoutData(new GridData(GridData.FILL_BOTH)); + + Group contextGroup = new Group(composite, SWT.SHADOW_NONE); + contextGroup.setText(Messages.SelectSpplementaryResources_ResourcesGroupTitle); + contextGroup.setLayout(new GridLayout()); + contextGroup.setLayoutData(new GridData(GridData.FILL_BOTH)); + + fTreeViewer = new CheckboxTreeViewer(contextGroup, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL); + GridData data = new GridData(GridData.FILL_BOTH); + Tree tree = fTreeViewer.getTree(); + tree.setLayoutData(data); + fTreeViewer.setContentProvider(new ITreeContentProvider() { + + @Override + public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { + } + + @Override + public void dispose() { + } + + @Override + public boolean hasChildren(Object element) { + if (element instanceof IResource[]) { + return true; + } + return false; + } + + @Override + public Object getParent(Object element) { + return null; + } + + @Override + public Object[] getElements(Object inputElement) { + return getChildren(inputElement); + } + + @Override + public Object[] getChildren(Object parentElement) { + if (parentElement instanceof IResource[]) { + return (Object[]) parentElement; + } + return null; + } + }); + +// fTreeViewer.setLabelProvider(new WorkbenchLabelProvider()); + + fTreeViewer.setLabelProvider(new LabelProvider() { + @Override + public String getText(Object element) { + if (element instanceof IResource) { + IResource resource = (IResource) element; + // show also trace name + return resource.getParent().getName() + File.separator + resource.getName(); + } + return super.getText(element); + } + }); + fTreeViewer.setInput(fAvailableResources); + + getShell().setMinimumSize(new Point(300, 150)); + + return composite; + } + + /* + * (non-Javadoc) + * @see org.eclipse.jface.dialogs.Dialog#createButtonsForButtonBar(org.eclipse.swt.widgets.Composite) + */ + @Override + protected void createButtonsForButtonBar(Composite parent) { + createButton(parent, IDialogConstants.CANCEL_ID, "&Cancel", true); //$NON-NLS-1$ + createButton(parent, IDialogConstants.OK_ID, "&Ok", true); //$NON-NLS-1$ + } + + @Override + protected void okPressed() { + Object[] checked = fTreeViewer.getCheckedElements(); + + fReturndResources = new IResource[checked.length]; + for (int i = 0; i < checked.length; i++) { + fReturndResources[i] = (IResource) checked[i]; + } + super.okPressed(); + } + + +} diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/dialogs/messages.properties b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/dialogs/messages.properties new file mode 100644 index 0000000000..41cde04205 --- /dev/null +++ b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/dialogs/messages.properties @@ -0,0 +1,13 @@ +############################################################################### +# Copyright (c) 2012 Ericsson +# +# All rights reserved. This program and the accompanying materials +# are made available under the terms of the Eclipse Public License v1.0 +# which accompanies this distribution, and is available at +# http://www.eclipse.org/legal/epl-v10.html +# +# Contributors: +# Bernd Hufmann - initial API and implementation +############################################################################### +SelectSpplementaryResources_DialogTitle=Delete Resources +SelectSpplementaryResources_ResourcesGroupTitle=Select resources to delete diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/handlers/DeleteExperimentSupplementaryFilesHandler.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/handlers/DeleteExperimentSupplementaryFilesHandler.java index 8e7374a13a..d22ca3bf3f 100644 --- a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/handlers/DeleteExperimentSupplementaryFilesHandler.java +++ b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/handlers/DeleteExperimentSupplementaryFilesHandler.java @@ -12,17 +12,24 @@ package org.eclipse.linuxtools.internal.tmf.ui.project.handlers; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + import org.eclipse.core.commands.AbstractHandler; import org.eclipse.core.commands.ExecutionEvent; import org.eclipse.core.commands.ExecutionException; import org.eclipse.core.resources.IResource; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.NullProgressMonitor; import org.eclipse.core.runtime.Status; import org.eclipse.jface.viewers.ISelection; import org.eclipse.jface.viewers.ISelectionProvider; import org.eclipse.jface.viewers.TreeSelection; +import org.eclipse.jface.window.Window; import org.eclipse.linuxtools.internal.tmf.ui.TmfUiPlugin; +import org.eclipse.linuxtools.internal.tmf.ui.project.dialogs.SelectSupplementaryResourcesDialog; import org.eclipse.linuxtools.tmf.ui.project.model.TmfExperimentElement; import org.eclipse.linuxtools.tmf.ui.project.model.TmfTraceElement; import org.eclipse.ui.IWorkbenchPage; @@ -65,16 +72,36 @@ public class DeleteExperimentSupplementaryFilesHandler extends AbstractHandler { TreeSelection sel = (TreeSelection) selection; // There should be only one item selected as per the plugin.xml Object element = sel.getFirstElement(); + List resourcesList = new ArrayList(); + if (element instanceof TmfExperimentElement) { TmfExperimentElement trace = (TmfExperimentElement) element; for (TmfTraceElement aTrace : trace.getTraces()) { - + // If trace is under an experiment, use the original trace from the traces folder aTrace = aTrace.getElementUnderTraceFolder(); - - aTrace.deleteSupplementaryFiles(); + + // Delete the selected resources + IResource[] resources = aTrace.getSupplementaryResources(); + resourcesList.addAll(Arrays.asList(resources)); + } + + SelectSupplementaryResourcesDialog dialog = new SelectSupplementaryResourcesDialog(window.getShell(), resourcesList.toArray(new IResource[resourcesList.size()])); + + if (dialog.open() != Window.OK) { + return null; + } + + IResource[] resourcesToDelete = dialog.getResources(); + + for (int i = 0; i < resourcesToDelete.length; i++) { + try { + resourcesToDelete[i].delete(true, new NullProgressMonitor()); + } catch (CoreException e) { + TmfUiPlugin.getDefault().getLog().log(new Status(IStatus.ERROR, TmfUiPlugin.PLUGIN_ID, "Error deleting supplementary resource " + resourcesToDelete[i], e)); //$NON-NLS-1$ + } } IResource resource = trace.getProject().getResource(); diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/handlers/DeleteTraceHandler.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/handlers/DeleteTraceHandler.java index c3895aea2a..b3d85d6fdf 100644 --- a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/handlers/DeleteTraceHandler.java +++ b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/handlers/DeleteTraceHandler.java @@ -137,7 +137,7 @@ public class DeleteTraceHandler extends AbstractHandler { resource.delete(true, new NullProgressMonitor()); // Delete supplementary files - trace.deleteSupplementaryFiles(); + trace.deleteSupplementaryFolder(); // Refresh the project trace.getProject().refresh(); diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/handlers/DeleteTraceSupplementaryFilesHandler.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/handlers/DeleteTraceSupplementaryFilesHandler.java index 2e3a567863..57b0feacd3 100644 --- a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/handlers/DeleteTraceSupplementaryFilesHandler.java +++ b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/handlers/DeleteTraceSupplementaryFilesHandler.java @@ -22,7 +22,9 @@ import org.eclipse.core.runtime.Status; import org.eclipse.jface.viewers.ISelection; import org.eclipse.jface.viewers.ISelectionProvider; import org.eclipse.jface.viewers.TreeSelection; +import org.eclipse.jface.window.Window; import org.eclipse.linuxtools.internal.tmf.ui.TmfUiPlugin; +import org.eclipse.linuxtools.internal.tmf.ui.project.dialogs.SelectSupplementaryResourcesDialog; import org.eclipse.linuxtools.tmf.ui.project.model.TmfTraceElement; import org.eclipse.ui.IWorkbenchPage; import org.eclipse.ui.IWorkbenchPart; @@ -55,6 +57,7 @@ public class DeleteTraceSupplementaryFilesHandler extends AbstractHandler { if (selectionProvider == null) { return false; } + ISelection selection = selectionProvider.getSelection(); // Make sure there is only selection and that it is an experiment @@ -66,9 +69,20 @@ public class DeleteTraceSupplementaryFilesHandler extends AbstractHandler { TmfTraceElement trace = (TmfTraceElement) element; // If trace is under an experiment, use the original trace from the traces folder trace = trace.getElementUnderTraceFolder(); - trace.deleteSupplementaryFiles(); - // Refresh folder - IResource resource = trace.getParent().getResource(); + + // Delete the selected resources + IResource[] resources = trace.getSupplementaryResources(); + + SelectSupplementaryResourcesDialog dialog = new SelectSupplementaryResourcesDialog(window.getShell(), resources); + if (dialog.open() != Window.OK) { + return null; + } + + trace.deleteSupplementaryResources(dialog.getResources()); + + // Refresh project + IResource resource = trace.getProject().getResource(); + if (resource != null) { try { if (resource != null) { 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 8139af18a0..be82fff1e8 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 @@ -32,6 +32,7 @@ import org.eclipse.core.runtime.Path; import org.eclipse.core.runtime.QualifiedName; import org.eclipse.core.runtime.Status; import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.linuxtools.tmf.core.TmfCommonConstants; import org.eclipse.linuxtools.tmf.core.trace.TmfTrace; import org.eclipse.linuxtools.tmf.ui.project.model.ITmfProjectModelElement; import org.eclipse.linuxtools.tmf.ui.project.model.TmfExperimentElement; @@ -148,13 +149,12 @@ public class DropAdapterAssistant extends CommonDropAdapterAssistant { } } } - IResource sourceResource = sourceTrace.getResource(); if (aTarget instanceof TmfExperimentElement) { TmfExperimentElement targetExperiment = (TmfExperimentElement) aTarget; - ok |= drop(sourceResource, targetExperiment); + ok |= drop(sourceTrace, targetExperiment); } else if (aTarget instanceof TmfTraceFolder) { TmfTraceFolder traceFolder = (TmfTraceFolder) aTarget; - ok |= drop(sourceResource, traceFolder); + ok |= drop(sourceTrace, traceFolder); } } else if (source instanceof IResource) { IResource sourceResource = (IResource) source; @@ -186,6 +186,26 @@ public class DropAdapterAssistant extends CommonDropAdapterAssistant { return (ok ? Status.OK_STATUS : Status.CANCEL_STATUS); } + + /** + * Drop a trace by copying a resource in a target experiment + * + * @param sourceTrace the source trace element to copy + * @param targetExperiment the target experiment + * @return true if successful + */ + private boolean drop(TmfTraceElement sourceTrace, TmfExperimentElement targetExperiment) { + + IResource sourceResource = sourceTrace.getResource(); + + if (drop(sourceResource, targetExperiment)) { + IFolder destinationSupplementaryFolder = targetExperiment.getTraceSupplementaryFolder(sourceResource.getName()); + sourceTrace.copySupplementaryFolder(destinationSupplementaryFolder); + return true; + } + return false; + } + /** * Drop a trace by copying a resource in a target experiment * @@ -235,6 +255,23 @@ public class DropAdapterAssistant extends CommonDropAdapterAssistant { return false; } + /** + * Drop a trace by copying it's a trace element in a trace folder + * + * @param sourceTrace the source trace + * @param traceFolder the target trace folder + * @return true if successful + */ + private boolean drop(TmfTraceElement sourceTrace, TmfTraceFolder traceFolder) { + IResource sourceResource = sourceTrace.getResource(); + if (drop(sourceResource, traceFolder)) { + IFolder destinationSupplementaryFolder = traceFolder.getTraceSupplementaryFolder(sourceResource.getName()); + sourceTrace.copySupplementaryFolder(destinationSupplementaryFolder); + return true; + } + return false; + } + /** * Drop a trace by copying a resource in a trace folder * @@ -244,6 +281,7 @@ public class DropAdapterAssistant extends CommonDropAdapterAssistant { */ private boolean drop(IResource sourceResource, TmfTraceFolder traceFolder) { boolean doit = true; + for (TmfTraceElement trace : traceFolder.getTraces()) { if (trace.getName().equals(sourceResource.getName())) { doit = false; @@ -254,6 +292,7 @@ public class DropAdapterAssistant extends CommonDropAdapterAssistant { try { IPath destination = traceFolder.getResource().getFullPath().addTrailingSeparator().append(sourceResource.getName()); sourceResource.copy(destination, false, null); + cleanupBookmarks(destination); return true; } catch (CoreException e) { @@ -262,7 +301,7 @@ public class DropAdapterAssistant extends CommonDropAdapterAssistant { } return false; } - + /** * Drop a trace by importing a path in a target experiment * @@ -374,24 +413,26 @@ public class DropAdapterAssistant extends CommonDropAdapterAssistant { IWorkspace workspace = ResourcesPlugin.getWorkspace(); try { Map properties = resource.getPersistentProperties(); - String bundleName = properties.get(TmfTraceElement.TRACEBUNDLE); - String traceType = properties.get(TmfTraceElement.TRACETYPE); - String iconUrl = properties.get(TmfTraceElement.TRACEICON); - + String bundleName = properties.get(TmfCommonConstants.TRACEBUNDLE); + String traceType = properties.get(TmfCommonConstants.TRACETYPE); + String iconUrl = properties.get(TmfCommonConstants.TRACEICON); + String supplFolder = properties.get(TmfCommonConstants.TRACE_SUPPLEMENTARY_FOLDER); + if (resource instanceof IFolder) { IFolder folder = parentFolder.getFolder(resource.getName()); if (workspace.validateLinkLocation(folder, location).isOK()) { folder.createLink(location, IResource.REPLACE, null); - setProperties(folder, bundleName, traceType, iconUrl); + setProperties(folder, bundleName, traceType, iconUrl, supplFolder); } else { System.out.println("Invalid Trace Location"); //$NON-NLS-1$ } } else { IFile file = parentFolder.getFile(resource.getName()); + if (workspace.validateLinkLocation(file, location).isOK()) { file.createLink(location, IResource.REPLACE, null); - setProperties(file, bundleName, traceType, iconUrl); + setProperties(file, bundleName, traceType, iconUrl, supplFolder); } else { System.out.println("Invalid Trace Location"); //$NON-NLS-1$ } @@ -409,7 +450,7 @@ public class DropAdapterAssistant extends CommonDropAdapterAssistant { if (folder.exists()) { try { for (IResource member : folder.members()) { - if (TmfTrace.class.getCanonicalName().equals(member.getPersistentProperty(TmfTraceElement.TRACETYPE))) { + if (TmfTrace.class.getCanonicalName().equals(member.getPersistentProperty(TmfCommonConstants.TRACETYPE))) { member.delete(true, null); } } @@ -426,12 +467,14 @@ public class DropAdapterAssistant extends CommonDropAdapterAssistant { * @param bundleName the bundle name * @param traceType the trace type * @param iconUrl the icon URL + * @param supplFolder the directory of the directory for supplementary information or null to ignore the property * @throws CoreException */ - private void setProperties(IResource resource, String bundleName, String traceType, String iconUrl) throws CoreException { - resource.setPersistentProperty(TmfTraceElement.TRACEBUNDLE, bundleName); - resource.setPersistentProperty(TmfTraceElement.TRACETYPE, traceType); - resource.setPersistentProperty(TmfTraceElement.TRACEICON, iconUrl); + private void setProperties(IResource resource, String bundleName, String traceType, String iconUrl, String supplFolder) throws CoreException { + resource.setPersistentProperty(TmfCommonConstants.TRACEBUNDLE, bundleName); + resource.setPersistentProperty(TmfCommonConstants.TRACETYPE, traceType); + resource.setPersistentProperty(TmfCommonConstants.TRACEICON, iconUrl); + resource.setPersistentProperty(TmfCommonConstants.TRACE_SUPPLEMENTARY_FOLDER, supplFolder); } /** diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/handlers/OpenExperimentHandler.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/handlers/OpenExperimentHandler.java index 8a6186ee81..b8071d315e 100644 --- a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/handlers/OpenExperimentHandler.java +++ b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/handlers/OpenExperimentHandler.java @@ -25,6 +25,7 @@ import org.eclipse.core.runtime.CoreException; import org.eclipse.jface.viewers.ISelection; import org.eclipse.jface.viewers.ISelectionProvider; import org.eclipse.jface.viewers.TreeSelection; +import org.eclipse.linuxtools.tmf.core.TmfCommonConstants; import org.eclipse.linuxtools.tmf.core.event.ITmfEvent; import org.eclipse.linuxtools.tmf.core.exceptions.TmfTraceException; import org.eclipse.linuxtools.tmf.core.experiment.TmfExperiment; @@ -117,7 +118,7 @@ public class OpenExperimentHandler extends AbstractHandler { if (!file.exists()) file.createLink(bookmarksFile.getLocation(), IResource.REPLACE, null); file.setHidden(true); - file.setPersistentProperty(TmfTraceElement.TRACETYPE, TmfExperiment.class.getCanonicalName()); + file.setPersistentProperty(TmfCommonConstants.TRACETYPE, TmfExperiment.class.getCanonicalName()); // Instantiate the experiment's traces final List traceEntries = fExperiment.getTraces(); diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/handlers/OpenTraceHandler.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/handlers/OpenTraceHandler.java index e0a8e91c3e..c3e5701092 100644 --- a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/handlers/OpenTraceHandler.java +++ b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/handlers/OpenTraceHandler.java @@ -25,6 +25,7 @@ import org.eclipse.core.runtime.CoreException; import org.eclipse.jface.viewers.ISelection; import org.eclipse.jface.viewers.ISelectionProvider; import org.eclipse.jface.viewers.TreeSelection; +import org.eclipse.linuxtools.tmf.core.TmfCommonConstants; import org.eclipse.linuxtools.tmf.core.event.ITmfEvent; import org.eclipse.linuxtools.tmf.core.exceptions.TmfTraceException; import org.eclipse.linuxtools.tmf.core.experiment.TmfExperiment; @@ -34,7 +35,6 @@ import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace; import org.eclipse.linuxtools.tmf.core.trace.TmfTrace; import org.eclipse.linuxtools.tmf.ui.editors.EventsViewEditor; import org.eclipse.linuxtools.tmf.ui.editors.TmfEditorInput; -import org.eclipse.linuxtools.tmf.ui.project.model.TmfExperimentElement; import org.eclipse.linuxtools.tmf.ui.project.model.TmfTraceElement; import org.eclipse.swt.widgets.MessageBox; import org.eclipse.ui.IEditorInput; @@ -116,12 +116,7 @@ public class OpenTraceHandler extends AbstractHandler { return null; // If trace is under an experiment, use the original trace from the traces folder - if (fTrace.getParent() instanceof TmfExperimentElement) - for (final TmfTraceElement trace : fTrace.getProject().getTracesFolder().getTraces()) - if (trace.getName().equals(fTrace.getName())) { - fTrace = trace; - break; - } + fTrace = fTrace.getElementUnderTraceFolder(); final ITmfTrace trace = fTrace.instantiateTrace(); final ITmfEvent traceEvent = fTrace.instantiateEvent(); @@ -137,7 +132,7 @@ public class OpenTraceHandler extends AbstractHandler { try { trace.initTrace(fTrace.getResource(), fTrace.getLocation().getPath(), traceEvent.getClass()); } catch (final TmfTraceException e) { - displayErrorMsg(Messages.OpenTraceHandler_NoTrace); + displayErrorMsg(Messages.OpenTraceHandler_NoTrace + "\n\n" + e); //$NON-NLS-1$ return null; } @@ -160,9 +155,9 @@ public class OpenTraceHandler extends AbstractHandler { file.createLink(bookmarksFile.getLocation(), IResource.REPLACE, null); file.setHidden(true); if (usesEditor) - file.setPersistentProperty(TmfTraceElement.TRACETYPE, fTrace.getTraceType()); + file.setPersistentProperty(TmfCommonConstants.TRACETYPE, fTrace.getTraceType()); else - file.setPersistentProperty(TmfTraceElement.TRACETYPE, TmfTrace.class.getCanonicalName()); + file.setPersistentProperty(TmfCommonConstants.TRACETYPE, TmfTrace.class.getCanonicalName()); } catch (final CoreException e) { e.printStackTrace(); } diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/handlers/RenameTraceHandler.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/handlers/RenameTraceHandler.java index 9fad002f06..5f54c59014 100644 --- a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/handlers/RenameTraceHandler.java +++ b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/handlers/RenameTraceHandler.java @@ -30,8 +30,8 @@ import org.eclipse.jface.viewers.ISelection; import org.eclipse.jface.viewers.ISelectionProvider; import org.eclipse.jface.viewers.TreeSelection; import org.eclipse.jface.window.Window; +import org.eclipse.linuxtools.tmf.core.TmfCommonConstants; import org.eclipse.linuxtools.tmf.ui.project.model.ITmfProjectModelElement; -import org.eclipse.linuxtools.tmf.ui.project.model.TmfExperimentElement; import org.eclipse.linuxtools.tmf.ui.project.model.TmfExperimentFolder; import org.eclipse.linuxtools.tmf.ui.project.model.TmfTraceElement; import org.eclipse.linuxtools.tmf.ui.project.model.TmfTraceFolder; @@ -162,16 +162,16 @@ public class RenameTraceHandler extends AbstractHandler { IResource resource = trace.getResource(); IPath location = resource.getLocation(); // Get the trace properties for this resource - String traceBundle = resource.getPersistentProperty(TmfTraceElement.TRACEBUNDLE); - String traceTypeId = resource.getPersistentProperty(TmfTraceElement.TRACETYPE); - String traceIcon = resource.getPersistentProperty(TmfTraceElement.TRACEICON); + String traceBundle = resource.getPersistentProperty(TmfCommonConstants.TRACEBUNDLE); + String traceTypeId = resource.getPersistentProperty(TmfCommonConstants.TRACETYPE); + String traceIcon = resource.getPersistentProperty(TmfCommonConstants.TRACEICON); if (resource instanceof IFolder) { IFolder folder = ((IFolder) experiment.getResource()).getFolder(trace.getName()); if (ResourcesPlugin.getWorkspace().validateLinkLocation(folder, location).isOK()) { folder.createLink(location, IResource.REPLACE, null); - folder.setPersistentProperty(TmfTraceElement.TRACEBUNDLE, traceBundle); - folder.setPersistentProperty(TmfTraceElement.TRACETYPE, traceTypeId); - folder.setPersistentProperty(TmfTraceElement.TRACEICON, traceIcon); + folder.setPersistentProperty(TmfCommonConstants.TRACEBUNDLE, traceBundle); + folder.setPersistentProperty(TmfCommonConstants.TRACETYPE, traceTypeId); + folder.setPersistentProperty(TmfCommonConstants.TRACEICON, traceIcon); } else { System.out.println("Invalid Trace Location"); //$NON-NLS-1$ @@ -181,9 +181,9 @@ public class RenameTraceHandler extends AbstractHandler { IFile file = ((IFolder) experiment.getResource()).getFile(trace.getName()); if (ResourcesPlugin.getWorkspace().validateLinkLocation(file, location).isOK()) { file.createLink(location, IResource.REPLACE, null); - file.setPersistentProperty(TmfTraceElement.TRACEBUNDLE, traceBundle); - file.setPersistentProperty(TmfTraceElement.TRACETYPE, traceTypeId); - file.setPersistentProperty(TmfTraceElement.TRACEICON, traceIcon); + file.setPersistentProperty(TmfCommonConstants.TRACEBUNDLE, traceBundle); + file.setPersistentProperty(TmfCommonConstants.TRACETYPE, traceTypeId); + file.setPersistentProperty(TmfCommonConstants.TRACEICON, traceIcon); } else { System.out.println("Invalid Trace Location"); //$NON-NLS-1$ 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 9b0eb92067..31284ea4a1 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 @@ -23,9 +23,9 @@ import org.eclipse.core.runtime.CoreException; import org.eclipse.jface.viewers.ISelection; import org.eclipse.jface.viewers.ISelectionProvider; import org.eclipse.jface.viewers.TreeSelection; +import org.eclipse.linuxtools.tmf.core.TmfCommonConstants; import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace; import org.eclipse.linuxtools.tmf.ui.project.model.ITmfProjectModelElement; -import org.eclipse.linuxtools.tmf.ui.project.model.TmfExperimentElement; import org.eclipse.linuxtools.tmf.ui.project.model.TmfExperimentFolder; import org.eclipse.linuxtools.tmf.ui.project.model.TmfTraceElement; import org.eclipse.linuxtools.tmf.ui.project.model.TmfTraceFolder; @@ -109,16 +109,7 @@ public class SelectTraceTypeHandler extends AbstractHandler { boolean ok = true; for (Object element : fSelection.toList()) { TmfTraceElement trace = (TmfTraceElement) element; - // If trace is under an experiment, use the original trace from the traces folder - if (trace.getParent() instanceof TmfExperimentElement) { - for (TmfTraceElement aTrace : trace.getProject().getTracesFolder().getTraces()) { - if (aTrace.getName().equals(trace.getName())) { - trace = aTrace; - break; - } - } - } - + trace = trace.getElementUnderTraceFolder(); IResource resource = trace.getResource(); if (resource != null) { try { @@ -147,9 +138,9 @@ public class SelectTraceTypeHandler extends AbstractHandler { private boolean propagateProperties(TmfTraceElement trace, String bundleName, String traceType, String iconUrl) throws CoreException { IResource svResource = trace.getResource(); - String svBundleName = svResource.getPersistentProperty(TmfTraceElement.TRACEBUNDLE); - String svTraceType = svResource.getPersistentProperty(TmfTraceElement.TRACETYPE); - String svIconUrl = svResource.getPersistentProperty(TmfTraceElement.TRACEICON); + String svBundleName = svResource.getPersistentProperty(TmfCommonConstants.TRACEBUNDLE); + String svTraceType = svResource.getPersistentProperty(TmfCommonConstants.TRACETYPE); + String svIconUrl = svResource.getPersistentProperty(TmfCommonConstants.TRACEICON); setProperties(trace.getResource(), bundleName, traceType, iconUrl); trace.refreshTraceType(); @@ -181,9 +172,9 @@ public class SelectTraceTypeHandler extends AbstractHandler { } private void setProperties(IResource resource, String bundleName, String traceType, String iconUrl) throws CoreException { - resource.setPersistentProperty(TmfTraceElement.TRACEBUNDLE, bundleName); - resource.setPersistentProperty(TmfTraceElement.TRACETYPE, traceType); - resource.setPersistentProperty(TmfTraceElement.TRACEICON, iconUrl); + resource.setPersistentProperty(TmfCommonConstants.TRACEBUNDLE, bundleName); + resource.setPersistentProperty(TmfCommonConstants.TRACETYPE, traceType); + resource.setPersistentProperty(TmfCommonConstants.TRACEICON, iconUrl); } private boolean validateTraceType(TmfTraceElement trace) { diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/handlers/TracePropertyTester.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/handlers/TracePropertyTester.java index 5bdb993bec..5ae8a79680 100644 --- a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/handlers/TracePropertyTester.java +++ b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/handlers/TracePropertyTester.java @@ -32,7 +32,7 @@ public class TracePropertyTester extends PropertyTester { private static String isInTraceFolder = "isInTraceFolder"; //$NON-NLS-1$ private static String isExperimentTrace = "isExperimentTrace"; //$NON-NLS-1$ - private static String hasHistoryFile = "hasHistoryFile"; //$NON-NLS-1$ + private static String hasSupplementaryFiles = "hasSupplementaryFiles"; //$NON-NLS-1$ // ------------------------------------------------------------------------ // Constructor @@ -81,24 +81,23 @@ public class TracePropertyTester extends PropertyTester { } return false; } - - if (hasHistoryFile.equals(property)) { + + // Check if traces has supplementary files + if (hasSupplementaryFiles.equals(property)) { if (receiver == null) { return false; } if (receiver instanceof TmfTraceElement) { TmfTraceElement trace = (TmfTraceElement) receiver; - // If trace is under an experiment, use the original trace from the traces folder - trace = trace.getElementUnderTraceFolder(); - return trace.hasSupplementaryFiles(); + return trace.hasSupplementaryResources(); } else if (receiver instanceof TmfExperimentElement) { TmfExperimentElement trace = (TmfExperimentElement) receiver; + boolean hasHistory = false; for (TmfTraceElement aTrace : trace.getTraces()) { - // Since trace is under an experiment, use the original trace from the traces folder - aTrace = aTrace.getElementUnderTraceFolder(); - return aTrace.hasSupplementaryFiles(); + hasHistory |= aTrace.hasSupplementaryResources(); } + return hasHistory; } return false; } diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/editors/EventsViewEditor.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/editors/EventsViewEditor.java index 7cd3f7971e..b0e163afd2 100644 --- a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/editors/EventsViewEditor.java +++ b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/editors/EventsViewEditor.java @@ -20,6 +20,7 @@ import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.InvalidRegistryObjectException; import org.eclipse.linuxtools.internal.tmf.ui.project.handlers.Messages; +import org.eclipse.linuxtools.tmf.core.TmfCommonConstants; import org.eclipse.linuxtools.tmf.core.event.ITmfEvent; import org.eclipse.linuxtools.tmf.core.exceptions.TmfTraceException; import org.eclipse.linuxtools.tmf.core.experiment.TmfExperiment; @@ -103,7 +104,7 @@ public class EventsViewEditor extends TmfEditor { return; } try { - final String traceTypeId = fFile.getPersistentProperty(TmfTraceElement.TRACETYPE); + final String traceTypeId = fFile.getPersistentProperty(TmfCommonConstants.TRACETYPE); if (traceTypeId == null) throw new PartInitException(Messages.OpenTraceHandler_NoTraceType); if (traceTypeId.equals(TmfExperiment.class.getCanonicalName())) { diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/editors/TmfEventsEditor.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/editors/TmfEventsEditor.java index 8af891cad4..07bf39a708 100644 --- a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/editors/TmfEventsEditor.java +++ b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/editors/TmfEventsEditor.java @@ -33,6 +33,7 @@ import org.eclipse.linuxtools.internal.tmf.ui.parsers.custom.CustomEventsTable; import org.eclipse.linuxtools.internal.tmf.ui.parsers.custom.CustomTxtTrace; import org.eclipse.linuxtools.internal.tmf.ui.parsers.custom.CustomXmlTrace; import org.eclipse.linuxtools.internal.tmf.ui.project.handlers.Messages; +import org.eclipse.linuxtools.tmf.core.TmfCommonConstants; import org.eclipse.linuxtools.tmf.core.event.ITmfEvent; import org.eclipse.linuxtools.tmf.core.event.TmfEvent; import org.eclipse.linuxtools.tmf.core.exceptions.TmfTraceException; @@ -98,7 +99,7 @@ public class TmfEventsEditor extends TmfEditor implements ITmfTraceEditor, IReus if (fFile == null) throw new PartInitException("Invalid IFileEditorInput: " + input); //$NON-NLS-1$ try { - final String traceTypeId = fFile.getPersistentProperty(TmfTraceElement.TRACETYPE); + final String traceTypeId = fFile.getPersistentProperty(TmfCommonConstants.TRACETYPE); if (traceTypeId == null) throw new PartInitException(Messages.OpenTraceHandler_NoTraceType); if (traceTypeId.equals(TmfExperiment.class.getCanonicalName())) { @@ -274,7 +275,7 @@ public class TmfEventsEditor extends TmfEditor implements ITmfTraceEditor, IReus try { if (fTrace.getResource() == null) return null; - final String traceType = fTrace.getResource().getPersistentProperty(TmfTraceElement.TRACETYPE); + final String traceType = fTrace.getResource().getPersistentProperty(TmfCommonConstants.TRACETYPE); if (traceType == null) return null; if (traceType.startsWith(CustomTxtTrace.class.getCanonicalName())) @@ -336,7 +337,7 @@ public class TmfEventsEditor extends TmfEditor implements ITmfTraceEditor, IReus final IResource resource = trace.getResource(); if (resource == null) return null; - final String traceType = resource.getPersistentProperty(TmfTraceElement.TRACETYPE); + final String traceType = resource.getPersistentProperty(TmfCommonConstants.TRACETYPE); if ((commonTraceType != null) && !commonTraceType.equals(traceType)) return null; commonTraceType = traceType; @@ -452,7 +453,7 @@ public class TmfEventsEditor extends TmfEditor implements ITmfTraceEditor, IReus try { fTrace.getName(); fTrace = null; - final String traceTypeId = fFile.getPersistentProperty(TmfTraceElement.TRACETYPE); + final String traceTypeId = fFile.getPersistentProperty(TmfCommonConstants.TRACETYPE); if (traceTypeId != null) for (final IConfigurationElement ce : TmfTraceType.getTypeElements()) if (traceTypeId.equals(ce.getAttribute(TmfTraceType.ID_ATTR))) { diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/project/model/TmfNavigatorContentProvider.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/project/model/TmfNavigatorContentProvider.java index 2457a51e82..8d02c9a698 100644 --- a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/project/model/TmfNavigatorContentProvider.java +++ b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/project/model/TmfNavigatorContentProvider.java @@ -193,12 +193,10 @@ public class TmfNavigatorContentProvider implements ICommonContentProvider, IPip for (IResource resource : members) { String name = resource.getName(); ITmfProjectModelElement trace = childrenMap.get(name); - if (!name.startsWith(TmfTraceElement.SUPPLEMENATARY_FILES_PREFIX)) { - if (trace == null) { - trace = new TmfTraceElement(name, resource, tmfTraceFolder); - } - children.add(trace); + if (trace == null) { + trace = new TmfTraceElement(name, resource, tmfTraceFolder); } + children.add(trace); childrenMap.remove(name); } } catch (CoreException e) { 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 0ae13ec9dc..3ba2029189 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 @@ -19,6 +19,7 @@ import org.eclipse.core.runtime.Platform; import org.eclipse.jface.resource.ImageDescriptor; import org.eclipse.jface.viewers.ILabelProviderListener; import org.eclipse.linuxtools.internal.tmf.ui.TmfUiPlugin; +import org.eclipse.linuxtools.tmf.core.TmfCommonConstants; import org.eclipse.swt.graphics.Image; import org.eclipse.ui.IMemento; import org.eclipse.ui.ISharedImages; @@ -85,8 +86,8 @@ public class TmfNavigatorLabelProvider implements ICommonLabelProvider { TmfTraceElement trace = (TmfTraceElement) element; String icon = null; try { - String name = trace.getResource().getPersistentProperty(TmfTraceElement.TRACEBUNDLE); - icon = trace.getResource().getPersistentProperty(TmfTraceElement.TRACEICON); + String name = trace.getResource().getPersistentProperty(TmfCommonConstants.TRACEBUNDLE); + icon = trace.getResource().getPersistentProperty(TmfCommonConstants.TRACEICON); if (name != null && icon != null) { Bundle bundle = Platform.getBundle(name); return loadIcon(bundle, icon); diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/project/model/TmfProjectModelElement.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/project/model/TmfProjectModelElement.java index 6b78422289..0a596b6f1b 100644 --- a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/project/model/TmfProjectModelElement.java +++ b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/project/model/TmfProjectModelElement.java @@ -16,11 +16,19 @@ import java.net.URI; import java.util.ArrayList; import java.util.List; +import org.eclipse.core.resources.IFolder; +import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IResource; import org.eclipse.core.resources.IResourceChangeEvent; import org.eclipse.core.resources.IResourceChangeListener; import org.eclipse.core.resources.ResourcesPlugin; +import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.NullProgressMonitor; +import org.eclipse.core.runtime.Status; +import org.eclipse.linuxtools.internal.tmf.ui.TmfUiPlugin; +import org.eclipse.linuxtools.tmf.core.TmfCommonConstants; /** * TmfProjectModelElement @@ -145,4 +153,36 @@ public abstract class TmfProjectModelElement implements ITmfProjectModelElement, return element.fName.equals(fName) && element.fLocation.equals(fLocation); } + + /** + * Returns the trace specific supplementary directory under the project's supplementary folder. + * The folder will be created if it doesn't exist. + * + * @param supplFoldername - folder name. + * @return returns the trace specific supplementary directory + */ + public IFolder getTraceSupplementaryFolder(String supplFoldername) { + IFolder supplFolderParent = getSupplementaryFolderParent(); + return supplFolderParent.getFolder(supplFoldername); + } + + /** + * Returns the supplementary folder for this project + * + * @return the supplementary folder for this project + */ + public IFolder getSupplementaryFolderParent() { + TmfProjectElement project = getProject(); + IProject projectResource = (IProject)project.getResource(); + IFolder supplFolderParent = projectResource.getFolder(TmfCommonConstants.TRACE_SUPPLEMENATARY_FOLDER_NAME); + + if (!supplFolderParent.exists()) { + try { + supplFolderParent.create(true, true, new NullProgressMonitor()); + } catch (CoreException e) { + TmfUiPlugin.getDefault().getLog().log(new Status(IStatus.ERROR, TmfUiPlugin.PLUGIN_ID, "Error creating project specific supplementary folder " + supplFolderParent, e)); //$NON-NLS-1$ + } + } + return supplFolderParent; + } } diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/project/model/TmfTraceElement.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/project/model/TmfTraceElement.java index c465ea79e3..8df3310b6d 100644 --- a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/project/model/TmfTraceElement.java +++ b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/project/model/TmfTraceElement.java @@ -16,7 +16,6 @@ import java.util.Arrays; import java.util.HashMap; import java.util.Map; -import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IFolder; import org.eclipse.core.resources.IResource; import org.eclipse.core.runtime.CoreException; @@ -24,7 +23,6 @@ import org.eclipse.core.runtime.IConfigurationElement; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.NullProgressMonitor; import org.eclipse.core.runtime.Platform; -import org.eclipse.core.runtime.QualifiedName; import org.eclipse.core.runtime.Status; import org.eclipse.linuxtools.internal.tmf.ui.TmfUiPlugin; import org.eclipse.linuxtools.internal.tmf.ui.parsers.custom.CustomTxtEvent; @@ -33,6 +31,7 @@ import org.eclipse.linuxtools.internal.tmf.ui.parsers.custom.CustomTxtTraceDefin import org.eclipse.linuxtools.internal.tmf.ui.parsers.custom.CustomXmlEvent; import org.eclipse.linuxtools.internal.tmf.ui.parsers.custom.CustomXmlTrace; import org.eclipse.linuxtools.internal.tmf.ui.parsers.custom.CustomXmlTraceDefinition; +import org.eclipse.linuxtools.tmf.core.TmfCommonConstants; import org.eclipse.linuxtools.tmf.core.event.ITmfEvent; import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace; import org.eclipse.linuxtools.tmf.ui.editors.TmfEventsEditor; @@ -51,11 +50,6 @@ public class TmfTraceElement extends TmfProjectModelElement implements IActionFi // Constants // ------------------------------------------------------------------------ - // Property keys - public static final QualifiedName TRACEBUNDLE = new QualifiedName("org.eclipse.linuxtools.tmf", "tracetype.bundle"); //$NON-NLS-1$//$NON-NLS-2$ - public static final QualifiedName TRACETYPE = new QualifiedName("org.eclipse.linuxtools.tmf", "tracetype.id"); //$NON-NLS-1$//$NON-NLS-2$ - public static final QualifiedName TRACEICON = new QualifiedName("org.eclipse.linuxtools.tmf", "tracetype.icon"); //$NON-NLS-1$//$NON-NLS-2$ - // Other attributes public static final String BUNDLE = "bundle"; //$NON-NLS-1$ public static final String IS_LINKED = "isLinked"; //$NON-NLS-1$ @@ -84,9 +78,6 @@ public class TmfTraceElement extends TmfProjectModelElement implements IActionFi sfTypeDescriptor.setCategory(sfInfoCategory); sfIsLinkedDescriptor.setCategory(sfInfoCategory); } - - private static final String[] SUPPLEMENATARY_FILES_EXTENSIONS = { ".ht" }; //$NON-NLS-1$ - public static final String SUPPLEMENATARY_FILES_PREFIX = "."; //$NON-NLS-1$ // ------------------------------------------------------------------------ // Attributes @@ -146,7 +137,7 @@ public class TmfTraceElement extends TmfProjectModelElement implements IActionFi public void refreshTraceType() { try { - fTraceTypeId = getResource().getPersistentProperty(TRACETYPE); + fTraceTypeId = getResource().getPersistentProperty(TmfCommonConstants.TRACETYPE); } catch (CoreException e) { e.printStackTrace(); } @@ -154,6 +145,10 @@ public class TmfTraceElement extends TmfProjectModelElement implements IActionFi public ITmfTrace instantiateTrace() { try { + + // make sure that supplementary folder exists + refreshSupplementaryFolder(); + if (fTraceTypeId != null) { if (fTraceTypeId.startsWith(CustomTxtTrace.class.getCanonicalName())) { for (CustomTxtTraceDefinition def : CustomTxtTraceDefinition.loadAll()) { @@ -222,9 +217,16 @@ public class TmfTraceElement extends TmfProjectModelElement implements IActionFi } return null; } - + + /** + * Returns the TmfTraceElement located under the TmfTracesFolder. + * + * @return this if this element is under the TmfTracesFolder + * else the corresponding TmfTraceElement if this element is under + * TmfExperimentElement. + */ public TmfTraceElement getElementUnderTraceFolder() { - + // If trace is under an experiment, return original trace from the traces folder if (getParent() instanceof TmfExperimentElement) { for (TmfTraceElement aTrace : getProject().getTracesFolder().getTraces()) { @@ -235,71 +237,147 @@ public class TmfTraceElement extends TmfProjectModelElement implements IActionFi } return this; } - - public boolean hasSupplementaryFiles() { - // Check for all supplementary files - for (int i = 0; i < SUPPLEMENATARY_FILES_EXTENSIONS.length; i++) { - IFile supplFile = createSupplemenatryFile(fResource.getName(), SUPPLEMENATARY_FILES_EXTENSIONS[i]); - - if (supplFile.exists()) { - return true; + + /** + * Deletes the trace specific supplementary folder. + */ + public void deleteSupplementaryFolder() { + IFolder supplFolder = getTraceSupplementaryFolder(fResource.getName()); + if (supplFolder.exists()) { + try { + supplFolder.delete(true, new NullProgressMonitor()); + } catch (CoreException e) { + TmfUiPlugin.getDefault().getLog().log(new Status(IStatus.ERROR, TmfUiPlugin.PLUGIN_ID, "Error deleting supplementary folder " + supplFolder, e)); //$NON-NLS-1$ } } - return false; } - - public void deleteSupplementaryFiles() { - // Delete all supplementary files - for (int i = 0; i < SUPPLEMENATARY_FILES_EXTENSIONS.length; i++) { - IFile supplFile = createSupplemenatryFile(fResource.getName(), SUPPLEMENATARY_FILES_EXTENSIONS[i]); - if (supplFile.exists()) { - try { - supplFile.delete(true, new NullProgressMonitor()); - } catch (CoreException e) { - TmfUiPlugin.getDefault().getLog().log(new Status(IStatus.ERROR, TmfUiPlugin.PLUGIN_ID, "Error deleting resource supplementary file " + supplFile, e)); //$NON-NLS-1$ - } + + /** + * Renames the trace specific supplementary folder according to the new trace name. + * + * @param newTraceName The new trace name + */ + public void renameSupplementaryFolder(String newTraceName) { + IFolder oldSupplFolder = getTraceSupplementaryFolder(fResource.getName()); + IFolder newSupplFolder = getTraceSupplementaryFolder(newTraceName); + + // Rename supplementary folder + if (oldSupplFolder.exists()) { + try { + oldSupplFolder.move(newSupplFolder.getFullPath(), true, new NullProgressMonitor()); + } catch (CoreException e) { + TmfUiPlugin.getDefault().getLog().log(new Status(IStatus.ERROR, TmfUiPlugin.PLUGIN_ID, "Error renaming supplementary folder " + oldSupplFolder, e)); //$NON-NLS-1$ } } } - public void renameSupplementaryFiles(String newTraceName) { - // Rename all supplementary files - for (int i = 0; i < SUPPLEMENATARY_FILES_EXTENSIONS.length; i++) { - IFile oldSupplFile = createSupplemenatryFile(fResource.getName(), SUPPLEMENATARY_FILES_EXTENSIONS[i]); - IFile newSupplFile = createSupplemenatryFile(newTraceName, SUPPLEMENATARY_FILES_EXTENSIONS[i]); - - if (oldSupplFile.exists()) { - try { - oldSupplFile.move(newSupplFile.getFullPath(), true, new NullProgressMonitor()); - } catch (CoreException e) { - TmfUiPlugin.getDefault().getLog().log(new Status(IStatus.ERROR, TmfUiPlugin.PLUGIN_ID, "Error renaming resource supplementary file " + oldSupplFile, e)); //$NON-NLS-1$ - } + /** + * Copies the trace specific supplementary folder to the new trace name. + * + * @param newTraceName The new trace name + */ + public void copySupplementaryFolder(String newTraceName) { + IFolder oldSupplFolder = getTraceSupplementaryFolder(fResource.getName()); + IFolder newSupplFolder = getTraceSupplementaryFolder(newTraceName); + + // copy supplementary folder + if (oldSupplFolder.exists()) { + try { + oldSupplFolder.copy(newSupplFolder.getFullPath(), true, new NullProgressMonitor()); + } catch (CoreException e) { + TmfUiPlugin.getDefault().getLog().log(new Status(IStatus.ERROR, TmfUiPlugin.PLUGIN_ID, "Error renaming supplementary folder " + oldSupplFolder, e)); //$NON-NLS-1$ } } } - - public void copySupplementaryFiles(String newTraceName) { - // Copy all supplementary files - for (int i = 0; i < SUPPLEMENATARY_FILES_EXTENSIONS.length; i++) { - IFile oldSupplFile = createSupplemenatryFile(fResource.getName(), SUPPLEMENATARY_FILES_EXTENSIONS[i]); - IFile newSupplFile = createSupplemenatryFile(newTraceName, SUPPLEMENATARY_FILES_EXTENSIONS[i]); - - if (oldSupplFile.exists()) { - try { - oldSupplFile.copy(newSupplFile.getFullPath(), true, new NullProgressMonitor()); - } catch (CoreException e) { - TmfUiPlugin.getDefault().getLog().log(new Status(IStatus.ERROR, TmfUiPlugin.PLUGIN_ID, "Error copying resource supplementary file " + oldSupplFile, e)); //$NON-NLS-1$ - } + + /** + * Copies the trace specific supplementary folder a new folder. + * + * @param destination The destination folder to copy to. + */ + public void copySupplementaryFolder(IFolder destination) { + IFolder oldSupplFolder = getTraceSupplementaryFolder(fResource.getName()); + + // copy supplementary folder + if (oldSupplFolder.exists()) { + try { + oldSupplFolder.copy(destination.getFullPath(), true, new NullProgressMonitor()); + } catch (CoreException e) { + TmfUiPlugin.getDefault().getLog().log(new Status(IStatus.ERROR, TmfUiPlugin.PLUGIN_ID, "Error renaming supplementary folder " + oldSupplFolder, e)); //$NON-NLS-1$ } } } + - private IFile createSupplemenatryFile(String fileName, String extension) { - String name = SUPPLEMENATARY_FILES_PREFIX + fileName + extension; - IFolder folder = (IFolder)fResource.getParent(); - return folder.getFile(name); + /** + * Refreshes the trace specific supplementary folder information. It creates the folder if not exists. + * It sets the persistence property of the trace resource + */ + public void refreshSupplementaryFolder() { + createSupplementaryDirectory(); + } + + /** + * Checks if supplementary resource exist or not. + * + * @return true if one or more files are under the trace supplementary folder + */ + public boolean hasSupplementaryResources() { + IResource[] resources = getSupplementaryResources(); + return (resources.length > 0); } + /** + * Returns the supplementary resources under the trace supplementary folder. + * + * @return array of resources under the trace supplementary folder. + */ + public IResource[] getSupplementaryResources() { + IFolder supplFolder = getTraceSupplementaryFolder(fResource.getName()); + if (supplFolder.exists()) { + try { + return supplFolder.members(); + } catch (CoreException e) { + TmfUiPlugin.getDefault().getLog().log(new Status(IStatus.ERROR, TmfUiPlugin.PLUGIN_ID, "Error deleting supplementary folder " + supplFolder, e)); //$NON-NLS-1$ + } + } + return new IResource[0]; + } + + /** + * Deletes the given resources. + * + * @param resources array of resources to delete. + */ + public void deleteSupplementaryResources(IResource[] resources) { + + for (int i = 0; i < resources.length; i++) { + try { + resources[i].delete(true, new NullProgressMonitor()); + } catch (CoreException e) { + TmfUiPlugin.getDefault().getLog().log(new Status(IStatus.ERROR, TmfUiPlugin.PLUGIN_ID, "Error deleting supplementary resource " + resources[i], e)); //$NON-NLS-1$ + } + } + } + + private void createSupplementaryDirectory() { + IFolder supplFolder = getTraceSupplementaryFolder(fResource.getName()); + if (!supplFolder.exists()) { + try { + supplFolder.create(true, true, new NullProgressMonitor()); + } catch (CoreException e) { + TmfUiPlugin.getDefault().getLog().log(new Status(IStatus.ERROR, TmfUiPlugin.PLUGIN_ID, "Error creating resource supplementary file " + supplFolder, e)); //$NON-NLS-1$ + } + } + + try { + fResource.setPersistentProperty(TmfCommonConstants.TRACE_SUPPLEMENTARY_FOLDER, supplFolder.getLocationURI().getPath()); + } catch (CoreException e) { + TmfUiPlugin.getDefault().getLog().log(new Status(IStatus.ERROR, TmfUiPlugin.PLUGIN_ID, "Error setting persistant property " + TmfCommonConstants.TRACE_SUPPLEMENTARY_FOLDER, e)); //$NON-NLS-1$ + } + + } + // ------------------------------------------------------------------------ // IActionFilter // ------------------------------------------------------------------------ diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/project/wizards/CopyExperimentDialog.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/project/wizards/CopyExperimentDialog.java index 03e7b5dfd1..2911c83e17 100644 --- a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/project/wizards/CopyExperimentDialog.java +++ b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/project/wizards/CopyExperimentDialog.java @@ -27,11 +27,11 @@ import org.eclipse.core.runtime.Status; import org.eclipse.jface.dialogs.IDialogConstants; import org.eclipse.jface.dialogs.MessageDialog; import org.eclipse.linuxtools.internal.tmf.ui.TmfUiPlugin; +import org.eclipse.linuxtools.tmf.core.TmfCommonConstants; import org.eclipse.linuxtools.tmf.core.experiment.TmfExperiment; import org.eclipse.linuxtools.tmf.ui.project.model.TmfExperimentElement; import org.eclipse.linuxtools.tmf.ui.project.model.TmfExperimentFolder; import org.eclipse.linuxtools.tmf.ui.project.model.TmfProjectElement; -import org.eclipse.linuxtools.tmf.ui.project.model.TmfTraceElement; import org.eclipse.osgi.util.NLS; import org.eclipse.swt.SWT; import org.eclipse.swt.graphics.Font; @@ -203,7 +203,7 @@ public class CopyExperimentDialog extends SelectionStatusDialog { IFolder folder = fExperimentFolder.getFolder(newName); if (folder.exists()) { for (IResource member : folder.members()) { - if (TmfExperiment.class.getCanonicalName().equals(member.getPersistentProperty(TmfTraceElement.TRACETYPE))) { + if (TmfExperiment.class.getCanonicalName().equals(member.getPersistentProperty(TmfCommonConstants.TRACETYPE))) { member.delete(true, null); } } diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/project/wizards/CopyTraceDialog.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/project/wizards/CopyTraceDialog.java index d79c45d28c..3eaa03746c 100644 --- a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/project/wizards/CopyTraceDialog.java +++ b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/project/wizards/CopyTraceDialog.java @@ -27,6 +27,7 @@ import org.eclipse.core.runtime.Status; import org.eclipse.jface.dialogs.IDialogConstants; import org.eclipse.jface.dialogs.MessageDialog; import org.eclipse.linuxtools.internal.tmf.ui.TmfUiPlugin; +import org.eclipse.linuxtools.tmf.core.TmfCommonConstants; import org.eclipse.linuxtools.tmf.core.trace.TmfTrace; import org.eclipse.linuxtools.tmf.ui.project.model.TmfProjectElement; import org.eclipse.linuxtools.tmf.ui.project.model.TmfTraceElement; @@ -200,14 +201,14 @@ public class CopyTraceDialog extends SelectionStatusDialog { throw new OperationCanceledException(); } // Copy supplementary files first - fTrace.copySupplementaryFiles(newName); + fTrace.copySupplementaryFolder(newName); // Copy the trace fTrace.getResource().copy(newPath, IResource.FORCE | IResource.SHALLOW, null); // Delete any bookmarks file found in copied trace folder IFolder folder = fTraceFolder.getFolder(newName); if (folder.exists()) { for (IResource member : folder.members()) { - if (TmfTrace.class.getCanonicalName().equals(member.getPersistentProperty(TmfTraceElement.TRACETYPE))) { + if (TmfTrace.class.getCanonicalName().equals(member.getPersistentProperty(TmfCommonConstants.TRACETYPE))) { member.delete(true, null); } } diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/project/wizards/ImportTraceWizardPage.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/project/wizards/ImportTraceWizardPage.java index 19bb7a8652..bb7e3970b3 100644 --- a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/project/wizards/ImportTraceWizardPage.java +++ b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/project/wizards/ImportTraceWizardPage.java @@ -49,6 +49,7 @@ import org.eclipse.linuxtools.internal.tmf.ui.parsers.custom.CustomTxtTrace; import org.eclipse.linuxtools.internal.tmf.ui.parsers.custom.CustomTxtTraceDefinition; import org.eclipse.linuxtools.internal.tmf.ui.parsers.custom.CustomXmlTrace; import org.eclipse.linuxtools.internal.tmf.ui.parsers.custom.CustomXmlTraceDefinition; +import org.eclipse.linuxtools.tmf.core.TmfCommonConstants; import org.eclipse.linuxtools.tmf.core.TmfProjectNature; import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace; import org.eclipse.linuxtools.tmf.ui.project.model.TmfProjectRegistry; @@ -814,9 +815,9 @@ public class ImportTraceWizardPage extends WizardResourceImportPage implements L if (resource != null) { try { // Set the trace properties for this resource - resource.setPersistentProperty(TmfTraceElement.TRACEBUNDLE, traceBundle); - resource.setPersistentProperty(TmfTraceElement.TRACETYPE, traceTypeId); - resource.setPersistentProperty(TmfTraceElement.TRACEICON, traceIcon); + resource.setPersistentProperty(TmfCommonConstants.TRACEBUNDLE, traceBundle); + resource.setPersistentProperty(TmfCommonConstants.TRACETYPE, traceTypeId); + resource.setPersistentProperty(TmfCommonConstants.TRACEICON, traceIcon); for (TmfTraceElement traceElement : TmfProjectRegistry.getProject(resource.getProject()).getTracesFolder().getTraces()) { if (traceElement.getName().equals(resource.getName())) { traceElement.refreshTraceType(); diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/project/wizards/Messages.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/project/wizards/Messages.java index b0ada6757c..215bc8b358 100644 --- a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/project/wizards/Messages.java +++ b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/project/wizards/Messages.java @@ -45,7 +45,7 @@ public class Messages extends NLS { public static String SelectTracesWizardPage_WindowTitle; public static String SelectTracesWizardPage_Description; - public static String Dialog_EmptyNameError; + public static String Dialog_EmptyNameError; public static String Dialog_ExistingNameError; public static String NewExperimentDialog_DialogTitle; @@ -68,10 +68,10 @@ public class Messages extends NLS { public static String CopyTraceDialog_TraceNewName; static { - // initialize resource bundle - NLS.initializeMessages(BUNDLE_NAME, Messages.class); - } + // initialize resource bundle + NLS.initializeMessages(BUNDLE_NAME, Messages.class); + } - private Messages() { - } + private Messages() { + } } diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/project/wizards/NewTmfProjectWizard.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/project/wizards/NewTmfProjectWizard.java index dbedb42dbc..7c532c73ad 100644 --- a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/project/wizards/NewTmfProjectWizard.java +++ b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/project/wizards/NewTmfProjectWizard.java @@ -28,6 +28,7 @@ import org.eclipse.core.runtime.NullProgressMonitor; import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.jface.wizard.Wizard; import org.eclipse.linuxtools.internal.tmf.ui.TmfUiPlugin; +import org.eclipse.linuxtools.tmf.core.TmfCommonConstants; import org.eclipse.linuxtools.tmf.core.TmfProjectNature; import org.eclipse.linuxtools.tmf.ui.project.model.TmfExperimentFolder; import org.eclipse.linuxtools.tmf.ui.project.model.TmfTraceFolder; @@ -141,6 +142,12 @@ public class NewTmfProjectWizard extends Wizard implements INewWizard, IExecutab folder.create(true, true, null); folder = project.getFolder(TmfExperimentFolder.EXPER_FOLDER_NAME); + if (!folder.exists()) + folder.create(true, true, null); + + // create folder for supplementary tracing files + folder = project.getFolder(TmfCommonConstants.TRACE_SUPPLEMENATARY_FOLDER_NAME); + if (!folder.exists()) folder.create(true, true, null); diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/project/wizards/RenameTraceDialog.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/project/wizards/RenameTraceDialog.java index 026a660e75..80e555c0ac 100644 --- a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/project/wizards/RenameTraceDialog.java +++ b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/project/wizards/RenameTraceDialog.java @@ -217,7 +217,7 @@ public class RenameTraceDialog extends SelectionStatusDialog { } } - fTrace.renameSupplementaryFiles(newName); + fTrace.renameSupplementaryFolder(newName); fTrace.getResource().move(newPath, IResource.FORCE | IResource.SHALLOW, null); if (monitor.isCanceled()) { throw new OperationCanceledException(); diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/project/wizards/SelectTracesWizardPage.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/project/wizards/SelectTracesWizardPage.java index c8959787ec..5eac5217ca 100644 --- a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/project/wizards/SelectTracesWizardPage.java +++ b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/project/wizards/SelectTracesWizardPage.java @@ -27,6 +27,7 @@ import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.QualifiedName; import org.eclipse.jface.viewers.CheckboxTableViewer; import org.eclipse.jface.wizard.WizardPage; +import org.eclipse.linuxtools.tmf.core.TmfCommonConstants; import org.eclipse.linuxtools.tmf.ui.project.model.ITmfProjectModelElement; import org.eclipse.linuxtools.tmf.ui.project.model.TmfExperimentElement; import org.eclipse.linuxtools.tmf.ui.project.model.TmfProjectElement; @@ -166,9 +167,9 @@ public class SelectTracesWizardPage extends WizardPage { IWorkspace workspace = ResourcesPlugin.getWorkspace(); try { Map properties = trace.getResource().getPersistentProperties(); - String bundleName = properties.get(TmfTraceElement.TRACEBUNDLE); - String traceType = properties.get(TmfTraceElement.TRACETYPE); - String iconUrl = properties.get(TmfTraceElement.TRACEICON); + String bundleName = properties.get(TmfCommonConstants.TRACEBUNDLE); + String traceType = properties.get(TmfCommonConstants.TRACETYPE); + String iconUrl = properties.get(TmfCommonConstants.TRACEICON); if (resource instanceof IFolder) { IFolder folder = experiment.getFolder(trace.getName()); @@ -194,9 +195,9 @@ public class SelectTracesWizardPage extends WizardPage { } private void setProperties(IResource resource, String bundleName, String traceType, String iconUrl) throws CoreException { - resource.setPersistentProperty(TmfTraceElement.TRACEBUNDLE, bundleName); - resource.setPersistentProperty(TmfTraceElement.TRACETYPE, traceType); - resource.setPersistentProperty(TmfTraceElement.TRACEICON, iconUrl); + resource.setPersistentProperty(TmfCommonConstants.TRACEBUNDLE, bundleName); + resource.setPersistentProperty(TmfCommonConstants.TRACETYPE, traceType); + resource.setPersistentProperty(TmfCommonConstants.TRACEICON, iconUrl); } /** diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/events/TmfEventsView.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/events/TmfEventsView.java index 230a8989ab..e208b1d4a9 100644 --- a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/events/TmfEventsView.java +++ b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/events/TmfEventsView.java @@ -31,13 +31,13 @@ import org.eclipse.linuxtools.internal.tmf.ui.TmfUiPlugin; import org.eclipse.linuxtools.internal.tmf.ui.parsers.custom.CustomEventsTable; import org.eclipse.linuxtools.internal.tmf.ui.parsers.custom.CustomTxtTrace; import org.eclipse.linuxtools.internal.tmf.ui.parsers.custom.CustomXmlTrace; +import org.eclipse.linuxtools.tmf.core.TmfCommonConstants; import org.eclipse.linuxtools.tmf.core.event.ITmfEvent; import org.eclipse.linuxtools.tmf.core.experiment.TmfExperiment; import org.eclipse.linuxtools.tmf.core.signal.TmfExperimentDisposedSignal; import org.eclipse.linuxtools.tmf.core.signal.TmfExperimentSelectedSignal; import org.eclipse.linuxtools.tmf.core.signal.TmfSignalHandler; import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace; -import org.eclipse.linuxtools.tmf.ui.project.model.TmfTraceElement; import org.eclipse.linuxtools.tmf.ui.project.model.TmfTraceType; import org.eclipse.linuxtools.tmf.ui.viewers.events.TmfEventsTable; import org.eclipse.linuxtools.tmf.ui.views.TmfView; @@ -123,7 +123,7 @@ public class TmfEventsView extends TmfView implements IResourceChangeListener { if (resource == null) { return new TmfEventsTable(parent, cacheSize); } - String traceType = resource.getPersistentProperty(TmfTraceElement.TRACETYPE); + String traceType = resource.getPersistentProperty(TmfCommonConstants.TRACETYPE); if (commonTraceType != null && !commonTraceType.equals(traceType)) { return new TmfEventsTable(parent, cacheSize); } -- 2.34.1