* @param traces the experiment set of traces
*/
public TmfExperiment(final Class<? extends ITmfEvent> type, final String id, final ITmfTrace[] traces) {
- this(type, id, traces, DEFAULT_INDEX_PAGE_SIZE);
+ this(type, id, traces, DEFAULT_INDEX_PAGE_SIZE, null);
}
+ /**
+ * Constructor of experiment taking type, path, traces and resource
+ *
+ * @param type
+ * the event type
+ * @param id
+ * the experiment id
+ * @param traces
+ * the experiment set of traces
+ * @param resource
+ * the resource associated to the experiment
+ */
+ public TmfExperiment(final Class<? extends ITmfEvent> type, final String id, final ITmfTrace[] traces, IResource resource) {
+ this(type, id, traces, DEFAULT_INDEX_PAGE_SIZE, resource);
+ }
+
+
/**
* @param type the event type
* @param path the experiment path
* @param indexPageSize the experiment index page size
*/
public TmfExperiment(final Class<? extends ITmfEvent> type, final String path, final ITmfTrace[] traces, final int indexPageSize) {
+ this(type, path, traces, indexPageSize, null);
+ }
+
+ /**
+ * Full constructor of an experiment, taking the type, path, traces,
+ * indexPageSize and resource
+ *
+ * @param type
+ * the event type
+ * @param path
+ * the experiment path
+ * @param traces
+ * the experiment set of traces
+ * @param indexPageSize
+ * the experiment index page size
+ * @param resource
+ * the resource associated to the experiment
+ */
+ public TmfExperiment(final Class<? extends ITmfEvent> type, final String path, final ITmfTrace[] traces, final int indexPageSize, IResource resource) {
setCacheSize(indexPageSize);
setStreamingInterval(0);
setIndexer(new TmfCheckpointIndexer(this, indexPageSize));
setParser(this);
try {
- super.initialize(null, path, type);
+ super.initialize(resource, path, type);
} catch (TmfTraceException e) {
e.printStackTrace();
}
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IPath;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.TreeSelection;
import org.eclipse.linuxtools.internal.tmf.ui.Activator;
}
}
+ IPath path = resource.getLocation();
+ if (path != null) {
+ // Delete supplementary files
+ experiment.deleteSupplementaryFolder();
+ }
+
// Finally, delete the experiment
resource.delete(true, null);
TmfExperimentElement trace = (TmfExperimentElement) element;
+ IResource[] resources = trace.getSupplementaryResources();
+ resourcesList.addAll(Arrays.asList(resources));
+
for (TmfTraceElement aTrace : trace.getTraces()) {
// If trace is under an experiment, use the original trace from the traces folder
aTrace = aTrace.getElementUnderTraceFolder();
// Delete the selected resources
- IResource[] resources = aTrace.getSupplementaryResources();
+ resources = aTrace.getSupplementaryResources();
resourcesList.addAll(Arrays.asList(resources));
}
return;
}
+ /* Unlike traces, there is no instanceExperiment, so we call this function
+ * here alone. Maybe it would be better to do this on experiment's element
+ * constructor?
+ */
+ experimentElement.refreshSupplementaryFolder();
+
// Instantiate the experiment's traces
final List<TmfTraceElement> traceEntries = experimentElement.getTraces();
final int nbTraces = traceEntries.size();
}
// Create the experiment
- final TmfExperiment experiment = new TmfExperiment(ITmfEvent.class, experimentElement.getName(), traces, cacheSize);
+ final TmfExperiment experiment = new TmfExperiment(ITmfEvent.class, experimentElement.getName(), traces, cacheSize, experimentElement.getResource());
experiment.setBookmarksFile(file);
final String editorId = commonEditorId;
cacheSize = Math.min(cacheSize, trace.getCacheSize());
traces[i] = trace;
}
- final TmfExperiment experiment = new TmfExperiment(ITmfEvent.class, experimentElement.getName(), traces, cacheSize);
+ final TmfExperiment experiment = new TmfExperiment(ITmfEvent.class, experimentElement.getName(), traces, cacheSize, experimentElement.getResource());
experiment.setBookmarksFile(fFile);
fTrace = experiment;
break;
* @author Francois Chouinard
*
*/
-public class TmfExperimentElement extends TmfProjectModelElement implements IPropertySource2 {
+public class TmfExperimentElement extends TmfWithFolderElement implements IPropertySource2 {
// ------------------------------------------------------------------------
// Constants
private static final String sfName = "name"; //$NON-NLS-1$
private static final String sfPath = "path"; //$NON-NLS-1$
private static final String sfLocation = "location"; //$NON-NLS-1$
+ private static final String sfFolderSuffix = "_exp"; //$NON-NLS-1$
private static final TextPropertyDescriptor sfNameDescriptor = new TextPropertyDescriptor(sfName, sfName);
private static final TextPropertyDescriptor sfPathDescriptor = new TextPropertyDescriptor(sfPath, sfPath);
return false;
}
+ /**
+ * Return the suffix for resource names
+ * @return The folder suffix
+ */
+ @Override
+ public String getSuffix() {
+ return sfFolderSuffix;
+ }
+
}
* Contributors:
* Francois Chouinard - Initial API and implementation
* Bernd Hufmann - Added supplementary files handling
+ * Geneviève Bastien - Moved supplementary files handling to parent class
*******************************************************************************/
package org.eclipse.linuxtools.tmf.ui.project.model;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IConfigurationElement;
-import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.Platform;
import org.eclipse.linuxtools.internal.tmf.ui.Activator;
import org.eclipse.linuxtools.internal.tmf.ui.parsers.custom.CustomTxtEvent;
* @version 1.0
* @author Francois Chouinard
*/
-public class TmfTraceElement extends TmfProjectModelElement implements IActionFilter, IPropertySource2 {
+public class TmfTraceElement extends TmfWithFolderElement implements IActionFilter, IPropertySource2 {
// ------------------------------------------------------------------------
// Constants
return this;
}
- /**
- * 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) {
- Activator.getDefault().logError("Error deleting supplementary folder " + supplFolder, 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) {
- Activator.getDefault().logError("Error renaming supplementary folder " + oldSupplFolder, 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) {
- Activator.getDefault().logError("Error renaming supplementary folder " + oldSupplFolder, 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) {
- Activator.getDefault().logError("Error copying supplementary folder " + oldSupplFolder, e); //$NON-NLS-1$
- }
- }
- }
-
-
- /**
- * 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 <code>true</code> 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) {
- Activator.getDefault().logError("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) {
- Activator.getDefault().logError("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) {
- Activator.getDefault().logError("Error creating resource supplementary file " + supplFolder, e); //$NON-NLS-1$
- }
- }
-
- try {
- fResource.setPersistentProperty(TmfCommonConstants.TRACE_SUPPLEMENTARY_FOLDER, supplFolder.getLocationURI().getPath());
- } catch (CoreException e) {
- Activator.getDefault().logError("Error setting persistant property " + TmfCommonConstants.TRACE_SUPPLEMENTARY_FOLDER, e); //$NON-NLS-1$
- }
-
- }
-
// ------------------------------------------------------------------------
// IActionFilter
// ------------------------------------------------------------------------
--- /dev/null
+/*******************************************************************************
+ * 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
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Bernd Hufmann - Added supplementary files handling (in class TmfTraceElement)
+ * Geneviève Bastien - Copied supplementary files handling from TmfTracElement
+ *******************************************************************************/
+
+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.NullProgressMonitor;
+import org.eclipse.linuxtools.internal.tmf.ui.Activator;
+import org.eclipse.linuxtools.tmf.core.TmfCommonConstants;
+
+
+/**
+ * Base class for project elements who will have folder elements
+ * under them to store supplementary files.
+ *
+ * @author gbastien
+ * @since 2.0
+ */
+public abstract class TmfWithFolderElement extends TmfProjectModelElement {
+
+ // ------------------------------------------------------------------------
+ // Constructors
+ // ------------------------------------------------------------------------
+
+
+ /**
+ * Constructor.
+ * Creates model element.
+ * @param name The name of the element
+ * @param resource The resource.
+ * @param parent The parent element
+ */
+ public TmfWithFolderElement(String name, IResource resource, TmfProjectModelElement parent) {
+ super(name, resource, parent);
+ }
+
+ /**
+ * Return the resource name for this element
+ *
+ * @return The name of the resource for this element
+ */
+ protected String getResourceName() {
+ return fResource.getName() + getSuffix();
+ }
+
+ /**
+ * @return The suffix for resource names
+ */
+ protected String getSuffix() {
+ return ""; //$NON-NLS-1$
+ }
+
+ /**
+ * Deletes this element specific supplementary folder.
+ */
+ public void deleteSupplementaryFolder() {
+ IFolder supplFolder = getTraceSupplementaryFolder(getResourceName());
+ if (supplFolder.exists()) {
+ try {
+ supplFolder.delete(true, new NullProgressMonitor());
+ } catch (CoreException e) {
+ Activator.getDefault().logError("Error deleting supplementary folder " + supplFolder, e); //$NON-NLS-1$
+ }
+ }
+ }
+
+ /**
+ * Renames the element specific supplementary folder according to the new element name.
+ *
+ * @param newName The new element name
+ */
+ public void renameSupplementaryFolder(String newName) {
+ IFolder oldSupplFolder = getTraceSupplementaryFolder(getResourceName());
+ IFolder newSupplFolder = getTraceSupplementaryFolder(newName + getSuffix());
+
+ // Rename supplementary folder
+ if (oldSupplFolder.exists()) {
+ try {
+ oldSupplFolder.move(newSupplFolder.getFullPath(), true, new NullProgressMonitor());
+ } catch (CoreException e) {
+ Activator.getDefault().logError("Error renaming supplementary folder " + oldSupplFolder, e); //$NON-NLS-1$
+ }
+ }
+ }
+
+ /**
+ * Copies the element specific supplementary folder to the new element name.
+ *
+ * @param newName The new element name
+ */
+ public void copySupplementaryFolder(String newName) {
+ IFolder oldSupplFolder = getTraceSupplementaryFolder(getResourceName());
+ IFolder newSupplFolder = getTraceSupplementaryFolder(newName + getSuffix());
+
+ // copy supplementary folder
+ if (oldSupplFolder.exists()) {
+ try {
+ oldSupplFolder.copy(newSupplFolder.getFullPath(), true, new NullProgressMonitor());
+ } catch (CoreException e) {
+ Activator.getDefault().logError("Error renaming supplementary folder " + oldSupplFolder, e); //$NON-NLS-1$
+ }
+ }
+ }
+
+ /**
+ * Copies the element specific supplementary folder a new folder.
+ *
+ * @param destination The destination folder to copy to.
+ */
+ public void copySupplementaryFolder(IFolder destination) {
+ IFolder oldSupplFolder = getTraceSupplementaryFolder(getResourceName());
+
+ // copy supplementary folder
+ if (oldSupplFolder.exists()) {
+ try {
+ oldSupplFolder.copy(destination.getFullPath(), true, new NullProgressMonitor());
+ } catch (CoreException e) {
+ Activator.getDefault().logError("Error copying supplementary folder " + oldSupplFolder, e); //$NON-NLS-1$
+ }
+ }
+ }
+
+
+ /**
+ * Refreshes the element 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 <code>true</code> if one or more files are under the element 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(getResourceName());
+ if (supplFolder.exists()) {
+ try {
+ return supplFolder.members();
+ } catch (CoreException e) {
+ Activator.getDefault().logError("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) {
+ Activator.getDefault().logError("Error deleting supplementary resource " + resources[i], e); //$NON-NLS-1$
+ }
+ }
+ }
+
+ private void createSupplementaryDirectory() {
+ IFolder supplFolder = getTraceSupplementaryFolder(getResourceName());
+ if (!supplFolder.exists()) {
+ try {
+ supplFolder.create(true, true, new NullProgressMonitor());
+ } catch (CoreException e) {
+ Activator.getDefault().logError("Error creating resource supplementary file " + supplFolder, e); //$NON-NLS-1$
+ }
+ }
+
+ try {
+ fResource.setPersistentProperty(TmfCommonConstants.TRACE_SUPPLEMENTARY_FOLDER, supplFolder.getLocationURI().getPath());
+ } catch (CoreException e) {
+ Activator.getDefault().logError("Error setting persistant property " + TmfCommonConstants.TRACE_SUPPLEMENTARY_FOLDER, e); //$NON-NLS-1$
+ }
+
+ }
+
+}
/*******************************************************************************
* Copyright (c) 2011, 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:
* Francois Chouinard - Copied and adapted from NewFolderDialog
*******************************************************************************/
// ------------------------------------------------------------------------
// Dialog
// ------------------------------------------------------------------------
-
+
/*
* (non-Javadoc)
* @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite)
}
private void validateNewExperimentName() {
-
+
String name = fNewExperimentName.getText();
IWorkspace workspace = fExperimentFolder.getWorkspace();
IStatus nameStatus = workspace.validateName(name, IResource.FOLDER);
updateStatus(new Status(IStatus.ERROR, Activator.PLUGIN_ID, IStatus.ERROR, Messages.Dialog_EmptyNameError, null));
return;
}
-
+
if (!nameStatus.isOK()) {
updateStatus(nameStatus);
return;
}
-
+
IPath path = new Path(name);
if (fExperimentFolder.getFolder(path).exists() || fExperimentFolder.getFile(path).exists()) {
updateStatus(new Status(IStatus.ERROR, Activator.PLUGIN_ID, IStatus.ERROR, Messages.Dialog_ExistingNameError, null));
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);
bookmarksFile.move(newBookmarksPath, IResource.FORCE | IResource.SHALLOW, null);
}
}
+
+ fExperiment.renameSupplementaryFolder(newName);
fExperiment.getResource().move(newPath, IResource.FORCE | IResource.SHALLOW, null);
if (monitor.isCanceled()) {
throw new OperationCanceledException();