aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGeneviève Bastien2013-02-28 16:04:19 (EST)
committerPatrick Tasse2013-03-04 11:46:23 (EST)
commit431a96d21178f8d2dc31dacfb11d19f59dfcf6f6 (patch)
tree7d079f817e11464b094cf87f8f9d3f6d8605877d
parent7e74bb077af3e656e020ba5cb165cec8b372b955 (diff)
downloadorg.eclipse.linuxtools-431a96d21178f8d2dc31dacfb11d19f59dfcf6f6.zip
org.eclipse.linuxtools-431a96d21178f8d2dc31dacfb11d19f59dfcf6f6.tar.gz
org.eclipse.linuxtools-431a96d21178f8d2dc31dacfb11d19f59dfcf6f6.tar.bz2
tmf: Move some code to copy/add/remove traces in UIrefs/changes/51/10751/4
The "Copy trace", "Select traces..." and "Remove" functionnalities have some code that can be reused by each other and future features. This code has been moved to the model element's classes. Change-Id: Id61914521f41d9c2b2c25fe1268e61be62c1d504 Signed-off-by: Geneviève Bastien <gbastien+lttng@versatic.net> Reviewed-on: https://git.eclipse.org/r/10751 Tested-by: Hudson CI Reviewed-by: Patrick Tasse <patrick.tasse@gmail.com> IP-Clean: Patrick Tasse <patrick.tasse@gmail.com> Tested-by: Patrick Tasse <patrick.tasse@gmail.com>
-rw-r--r--lttng/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/handlers/DeleteTraceHandler.java17
-rw-r--r--lttng/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/project/model/TmfExperimentElement.java96
-rw-r--r--lttng/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/project/model/TmfTraceElement.java21
-rw-r--r--lttng/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/project/model/TmfWithFolderElement.java47
-rw-r--r--lttng/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/project/wizards/CopyExperimentDialog.java23
-rw-r--r--lttng/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/project/wizards/CopyTraceDialog.java23
-rw-r--r--lttng/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/project/wizards/SelectTracesWizardPage.java60
7 files changed, 175 insertions, 112 deletions
diff --git a/lttng/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/handlers/DeleteTraceHandler.java b/lttng/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/handlers/DeleteTraceHandler.java
index 5ef4814..9d46f91 100644
--- a/lttng/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/handlers/DeleteTraceHandler.java
+++ b/lttng/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/handlers/DeleteTraceHandler.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2009, 2013 Ericsson
+ * Copyright (c) 2009, 2013 Ericsson, École Polytechnique de Montréal
*
* 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
+ * Geneviève Bastien - Moved the delete code to element model's classes
*******************************************************************************/
package org.eclipse.linuxtools.internal.tmf.ui.project.handlers;
@@ -152,19 +153,7 @@ public class DeleteTraceHandler extends AbstractHandler {
}
for (ITmfProjectModelElement child : toRemove) {
// Close the experiment if open
- file = ((TmfExperimentElement) experiment).getBookmarksFile();
- input = new FileEditorInput(file);
- for (IWorkbenchWindow wbWindow : wb.getWorkbenchWindows()) {
- for (IWorkbenchPage wbPage : wbWindow.getPages()) {
- for (IEditorReference editorReference : wbPage.getEditorReferences()) {
- if (editorReference.getEditorInput().equals(input)) {
- wbPage.closeEditor(editorReference.getEditor(false), false);
- }
- }
- }
- }
- experiment.removeChild(child);
- child.getResource().delete(true, null);
+ ((TmfExperimentElement) experiment).removeTrace((TmfTraceElement)child);
}
}
diff --git a/lttng/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/project/model/TmfExperimentElement.java b/lttng/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/project/model/TmfExperimentElement.java
index 73e1a7b..41e72eb 100644
--- a/lttng/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/project/model/TmfExperimentElement.java
+++ b/lttng/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/project/model/TmfExperimentElement.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2010, 2013 Ericsson
+ * Copyright (c) 2010, 2013 Ericsson, École Polytechnique de Montréal
*
* 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
+ * Geneviève Bastien - Copied code to add/remove traces in this class
*******************************************************************************/
package org.eclipse.linuxtools.tmf.ui.project.model;
@@ -17,13 +18,25 @@ import java.io.InputStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
+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.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.QualifiedName;
+import org.eclipse.linuxtools.internal.tmf.ui.Activator;
import org.eclipse.linuxtools.tmf.core.TmfCommonConstants;
import org.eclipse.linuxtools.tmf.core.trace.TmfExperiment;
+import org.eclipse.ui.IEditorReference;
+import org.eclipse.ui.IWorkbench;
+import org.eclipse.ui.IWorkbenchPage;
+import org.eclipse.ui.IWorkbenchWindow;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.part.FileEditorInput;
import org.eclipse.ui.views.properties.IPropertyDescriptor;
import org.eclipse.ui.views.properties.IPropertySource2;
import org.eclipse.ui.views.properties.TextPropertyDescriptor;
@@ -118,6 +131,87 @@ public class TmfExperimentElement extends TmfWithFolderElement implements IPrope
return traces;
}
+
+ /**
+ * Adds a trace to the experiment
+ *
+ * @param trace The trace element to add
+ * @since 2.0
+ */
+ public void addTrace(TmfTraceElement trace) {
+ /**
+ * Create a link to the actual trace and set the trace type
+ */
+ IFolder experiment = getResource();
+ IResource resource = trace.getResource();
+ IPath location = resource.getLocation();
+ IWorkspace workspace = ResourcesPlugin.getWorkspace();
+ try {
+ Map<QualifiedName, String> properties = trace.getResource().getPersistentProperties();
+ 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());
+ if (workspace.validateLinkLocation(folder, location).isOK()) {
+ folder.createLink(location, IResource.REPLACE, null);
+ setProperties(folder, bundleName, traceType, iconUrl);
+
+ } else {
+ Activator.getDefault().logError("Error creating link. Invalid trace location " + location); //$NON-NLS-1$
+ }
+ } else {
+ IFile file = experiment.getFile(trace.getName());
+ if (workspace.validateLinkLocation(file, location).isOK()) {
+ file.createLink(location, IResource.REPLACE, null);
+ setProperties(file, bundleName, traceType, iconUrl);
+ } else {
+ Activator.getDefault().logError("Error creating link. Invalid trace location " + location); //$NON-NLS-1$
+ }
+ }
+ } catch (CoreException e) {
+ Activator.getDefault().logError("Error creating link to location " + location, e); //$NON-NLS-1$
+ }
+
+ }
+
+ /**
+ * Removes a trace from an experiment
+ *
+ * @param trace The trace to remove
+ * @throws CoreException exception
+ * @since 2.0
+ */
+ public void removeTrace(TmfTraceElement trace) throws CoreException {
+
+ // Close the experiment if open
+ IFile file = getBookmarksFile();
+ FileEditorInput input = new FileEditorInput(file);
+ IWorkbench wb = PlatformUI.getWorkbench();
+ for (IWorkbenchWindow wbWindow : wb.getWorkbenchWindows()) {
+ for (IWorkbenchPage wbPage : wbWindow.getPages()) {
+ for (IEditorReference editorReference : wbPage.getEditorReferences()) {
+ if (editorReference.getEditorInput().equals(input)) {
+ wbPage.closeEditor(editorReference.getEditor(false), false);
+ }
+ }
+ }
+ }
+
+ /* Finally, remove the trace from experiment*/
+ removeChild(trace);
+ trace.getResource().delete(true, null);
+
+ }
+
+ private static void setProperties(IResource resource, String bundleName,
+ String traceType, String iconUrl) throws CoreException {
+ resource.setPersistentProperty(TmfCommonConstants.TRACEBUNDLE, bundleName);
+ resource.setPersistentProperty(TmfCommonConstants.TRACETYPE, traceType);
+ resource.setPersistentProperty(TmfCommonConstants.TRACEICON, iconUrl);
+ }
+
/**
* Returns the file resource used to store bookmarks after creating it if necessary.
* The file will be created if it does not exist.
diff --git a/lttng/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/project/model/TmfTraceElement.java b/lttng/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/project/model/TmfTraceElement.java
index 4171d0b..e3b09d1 100644
--- a/lttng/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/project/model/TmfTraceElement.java
+++ b/lttng/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/project/model/TmfTraceElement.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2010, 2013 Ericsson
+ * Copyright (c) 2010, 2013 Ericsson, École Polytechnique de Montréal
*
* All rights reserved. This program and the accompanying materials are
* made available under the terms of the Eclipse Public License v1.0 which
@@ -9,7 +9,8 @@
* Contributors:
* Francois Chouinard - Initial API and implementation
* Bernd Hufmann - Added supplementary files handling
- * Geneviève Bastien - Moved supplementary files handling to parent class
+ * Geneviève Bastien - Moved supplementary files handling to parent class, added
+ * code to copy trace
*******************************************************************************/
package org.eclipse.linuxtools.tmf.ui.project.model;
@@ -468,4 +469,20 @@ public class TmfTraceElement extends TmfWithFolderElement implements IActionFilt
return false;
}
+ /**
+ * Copy this trace in the trace folder. No other parameters are mentioned so
+ * the trace is copied in this element's project trace folder
+ *
+ * @param string
+ * The new trace name
+ * @return the new Resource object
+ * @since 2.0
+ */
+ public TmfTraceElement copy(String string) {
+ TmfTraceFolder folder = this.getProject().getTracesFolder();
+ IResource res = super.copy(string, false);
+ return new TmfTraceElement(string, res, folder);
+ }
+
+
}
diff --git a/lttng/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/project/model/TmfWithFolderElement.java b/lttng/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/project/model/TmfWithFolderElement.java
index 02e5b33..b951b80 100644
--- a/lttng/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/project/model/TmfWithFolderElement.java
+++ b/lttng/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/project/model/TmfWithFolderElement.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2010-2013 Ericsson, École Polytechnique de Montréal
+ * Copyright (c) 2010, 2013 Ericsson, École Polytechnique de Montréal
*
* All rights reserved. This program and the accompanying materials are
* made available under the terms of the Eclipse Public License v1.0 which
@@ -9,17 +9,20 @@
* Contributors:
* Bernd Hufmann - Added supplementary files handling (in class TmfTraceElement)
* Geneviève Bastien - Copied supplementary files handling from TmfTracElement
+ * Moved to this class code to copy a model element
*******************************************************************************/
package org.eclipse.linuxtools.tmf.ui.project.model;
-
import org.eclipse.core.resources.IFolder;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.linuxtools.internal.tmf.ui.Activator;
import org.eclipse.linuxtools.tmf.core.TmfCommonConstants;
+import org.eclipse.linuxtools.tmf.core.trace.TmfExperiment;
+import org.eclipse.linuxtools.tmf.core.trace.TmfTrace;
/**
@@ -203,4 +206,44 @@ public abstract class TmfWithFolderElement extends TmfProjectModelElement {
}
+ /**
+ * Copy this model element
+ *
+ * @param newName The name of the new element
+ * @param copySuppFiles Whether to copy supplementary files or not
+ * @return the new Resource object
+ */
+ public IResource copy(final String newName, final boolean copySuppFiles) {
+
+ final IPath newPath = getParent().getResource().getFullPath().addTrailingSeparator().append(newName);
+
+ /* Copy supplementary files first, only if needed */
+ if (copySuppFiles) {
+ copySupplementaryFolder(newName);
+ }
+ /* Copy the trace */
+ try {
+ getResource().copy(newPath, IResource.FORCE | IResource.SHALLOW, null);
+
+ /* Delete any bookmarks file found in copied trace folder */
+ IFolder folder = ((IFolder)getParent().getResource()).getFolder(newName);
+ if (folder.exists()) {
+ for (IResource member : folder.members()) {
+ if (TmfTrace.class.getCanonicalName().equals(member.getPersistentProperty(TmfCommonConstants.TRACETYPE))) {
+ member.delete(true, null);
+ }
+ if (TmfExperiment.class.getCanonicalName().equals(member.getPersistentProperty(TmfCommonConstants.TRACETYPE))) {
+ member.delete(true, null);
+ }
+ }
+ }
+ return folder;
+ } catch (CoreException e) {
+
+ }
+
+ return null;
+
+ }
+
}
diff --git a/lttng/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/project/wizards/CopyExperimentDialog.java b/lttng/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/project/wizards/CopyExperimentDialog.java
index 53b558d..ed0edd5 100644
--- a/lttng/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/project/wizards/CopyExperimentDialog.java
+++ b/lttng/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/project/wizards/CopyExperimentDialog.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2011, 2013 Ericsson
+ * Copyright (c) 2011, 2013 Ericsson, École Polytechnique de Montréal
*
* 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 - Copied and adapted from NewFolderDialog
+ * Geneviève Bastien - Moved the actual copy code to model element's class
*******************************************************************************/
package org.eclipse.linuxtools.tmf.ui.project.wizards;
@@ -27,8 +28,6 @@ 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.Activator;
-import org.eclipse.linuxtools.tmf.core.TmfCommonConstants;
-import org.eclipse.linuxtools.tmf.core.trace.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;
@@ -209,9 +208,6 @@ public class CopyExperimentDialog extends SelectionStatusDialog {
private IFolder copyExperiment(final String newName) {
- IPath oldPath = fExperiment.getResource().getFullPath();
- final IPath newPath = oldPath.append("../" + newName); //$NON-NLS-1$
-
WorkspaceModifyOperation operation = new WorkspaceModifyOperation() {
@Override
public void execute(IProgressMonitor monitor) throws CoreException {
@@ -220,18 +216,9 @@ public class CopyExperimentDialog extends SelectionStatusDialog {
if (monitor.isCanceled()) {
throw new OperationCanceledException();
}
- // Copy supplementary files first
- fExperiment.copySupplementaryFolder(newName);
- fExperiment.getResource().copy(newPath, IResource.FORCE | IResource.SHALLOW, null);
- // Delete any bookmarks file found in copied experiment folder
- IFolder folder = fExperimentFolder.getFolder(newName);
- if (folder.exists()) {
- for (IResource member : folder.members()) {
- if (TmfExperiment.class.getCanonicalName().equals(member.getPersistentProperty(TmfCommonConstants.TRACETYPE))) {
- member.delete(true, null);
- }
- }
- }
+
+ fExperiment.copy(newName, true);
+
if (monitor.isCanceled()) {
throw new OperationCanceledException();
}
diff --git a/lttng/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/project/wizards/CopyTraceDialog.java b/lttng/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/project/wizards/CopyTraceDialog.java
index 046b526..ceca8af 100644
--- a/lttng/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/project/wizards/CopyTraceDialog.java
+++ b/lttng/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/project/wizards/CopyTraceDialog.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2011, 2012 Ericsson
+ * Copyright (c) 2011, 2013 Ericsson, École Polytechnique de Montréal
*
* 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 - Copied and adapted from NewFolderDialog
+ * Geneviève Bastien - Moved the actual copy code to model element's class
*******************************************************************************/
package org.eclipse.linuxtools.tmf.ui.project.wizards;
@@ -27,8 +28,6 @@ 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.Activator;
-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;
import org.eclipse.linuxtools.tmf.ui.project.model.TmfTraceFolder;
@@ -210,9 +209,6 @@ public class CopyTraceDialog extends SelectionStatusDialog {
private IResource copyTrace(final String newName) {
- IPath oldPath = fTrace.getResource().getFullPath();
- final IPath newPath = oldPath.append("../" + newName); //$NON-NLS-1$
-
WorkspaceModifyOperation operation = new WorkspaceModifyOperation() {
@Override
public void execute(IProgressMonitor monitor) throws CoreException {
@@ -221,19 +217,7 @@ public class CopyTraceDialog extends SelectionStatusDialog {
if (monitor.isCanceled()) {
throw new OperationCanceledException();
}
- // Copy supplementary files first
- 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(TmfCommonConstants.TRACETYPE))) {
- member.delete(true, null);
- }
- }
- }
+ fTrace.copy(newName, true);
if (monitor.isCanceled()) {
throw new OperationCanceledException();
}
@@ -255,6 +239,7 @@ public class CopyTraceDialog extends SelectionStatusDialog {
}
return fTrace.getResource();
+
}
}
diff --git a/lttng/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/project/wizards/SelectTracesWizardPage.java b/lttng/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/project/wizards/SelectTracesWizardPage.java
index f6e7b2d..8e4fb43 100644
--- a/lttng/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/project/wizards/SelectTracesWizardPage.java
+++ b/lttng/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/project/wizards/SelectTracesWizardPage.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2009, 2012 Ericsson
+ * Copyright (c) 2009, 2012, 2013 Ericsson, École Polytechnique de Montréal
*
* 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
+ * Geneviève Bastien - Moved the add and remove code to the experiment class
*******************************************************************************/
package org.eclipse.linuxtools.tmf.ui.project.wizards;
@@ -17,18 +18,11 @@ import java.util.Map;
import java.util.Set;
import java.util.Vector;
-import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IFolder;
-import org.eclipse.core.resources.IResource;
-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.QualifiedName;
import org.eclipse.jface.viewers.CheckboxTableViewer;
import org.eclipse.jface.wizard.WizardPage;
import org.eclipse.linuxtools.internal.tmf.ui.Activator;
-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;
@@ -153,19 +147,15 @@ public class SelectTracesWizardPage extends WizardPage {
if (keys.contains(name)) {
fPreviousTraces.remove(name);
} else {
- IResource resource = trace.getResource();
- IPath location = resource.getLocation();
- createLink(experiment, trace, resource, location);
+ fExperiment.addTrace(trace);
}
}
// Remove traces that were unchecked (thus left in fPreviousTraces)
keys = fPreviousTraces.keySet();
for (String key : keys) {
- fExperiment.removeChild(fPreviousTraces.get(key));
- IResource resource = experiment.findMember(key);
try {
- resource.delete(true, null);
+ fExperiment.removeTrace(fPreviousTraces.get(key));
} catch (CoreException e) {
Activator.getDefault().logError("Error selecting traces for experiment " + experiment.getName(), e); //$NON-NLS-1$
}
@@ -176,48 +166,6 @@ public class SelectTracesWizardPage extends WizardPage {
}
/**
- * Create a link to the actual trace and set the trace type
- */
- private static void createLink(IFolder experiment, TmfTraceElement trace,
- IResource resource, IPath location) {
- IWorkspace workspace = ResourcesPlugin.getWorkspace();
- try {
- Map<QualifiedName, String> properties = trace.getResource().getPersistentProperties();
- 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());
- if (workspace.validateLinkLocation(folder, location).isOK()) {
- folder.createLink(location, IResource.REPLACE, null);
- setProperties(folder, bundleName, traceType, iconUrl);
-
- } else {
- Activator.getDefault().logError("Error creating link. Invalid trace location " + location); //$NON-NLS-1$
- }
- } else {
- IFile file = experiment.getFile(trace.getName());
- if (workspace.validateLinkLocation(file, location).isOK()) {
- file.createLink(location, IResource.REPLACE, null);
- setProperties(file, bundleName, traceType, iconUrl);
- } else {
- Activator.getDefault().logError("Error creating link. Invalid trace location " + location); //$NON-NLS-1$
- }
- }
- } catch (CoreException e) {
- Activator.getDefault().logError("Error creating link to location " + location, e); //$NON-NLS-1$
- }
- }
-
- private static void setProperties(IResource resource, String bundleName,
- String traceType, String iconUrl) throws CoreException {
- resource.setPersistentProperty(TmfCommonConstants.TRACEBUNDLE, bundleName);
- resource.setPersistentProperty(TmfCommonConstants.TRACETYPE, traceType);
- resource.setPersistentProperty(TmfCommonConstants.TRACEICON, iconUrl);
- }
-
- /**
* Get the list of selected traces
*/
private TmfTraceElement[] getSelection() {