import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.linuxtools.internal.tmf.ui.Activator;
import org.eclipse.linuxtools.tmf.ui.project.model.TmfExperimentElement;
import org.eclipse.swt.SWT;
+import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.MessageBox;
import org.eclipse.swt.widgets.Shell;
+import org.eclipse.ui.IEditorReference;
+import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.part.FileEditorInput;
/**
* <b><u>DeleteExperimentHandler</u></b>
while (iterator.hasNext()) {
Object element = iterator.next();
if (element instanceof TmfExperimentElement) {
- TmfExperimentElement experiment = (TmfExperimentElement) element;
+ final TmfExperimentElement experiment = (TmfExperimentElement) element;
IResource resource = experiment.getResource();
+
try {
+ // Close the experiment if open
+ IFile file = experiment.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, delete the experiment
resource.delete(true, null);
+
+ // Refresh the project
experiment.getProject().refresh();
- } catch (CoreException e) {
+
+ } catch (final CoreException e) {
+ Display.getDefault().asyncExec(new Runnable() {
+ @Override
+ public void run() {
+ final MessageBox mb = new MessageBox(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell());
+ mb.setText(Messages.DeleteTraceHandler_Error + ' ' + experiment.getName());
+ mb.setMessage(e.getMessage());
+ mb.open();
+ }
+ });
Activator.getDefault().logError("Error deleting experiment: " + experiment.getName(), e); //$NON-NLS-1$
}
}
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
+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.TreeSelection;
import org.eclipse.linuxtools.internal.tmf.ui.Activator;
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;
import org.eclipse.swt.SWT;
+import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.MessageBox;
import org.eclipse.swt.widgets.Shell;
+import org.eclipse.ui.IEditorReference;
+import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.part.FileEditorInput;
/**
* <b><u>DeleteTraceHandler</u></b>
while (iterator.hasNext()) {
Object element = iterator.next();
if (element instanceof TmfTraceElement) {
- TmfTraceElement trace = (TmfTraceElement) element;
+ final TmfTraceElement trace = (TmfTraceElement) element;
IResource resource = trace.getResource();
try {
+ // Close the trace if open
+ IFile file = trace.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);
+ }
+ }
+ }
+ }
+
IPath path = resource.getLocation();
if (path != null && (trace.getParent() instanceof TmfTraceFolder)) {
String location = path.toString();
}
}
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);
}
// Refresh the project
trace.getProject().refresh();
- } catch (CoreException e) {
+ } catch (final CoreException e) {
+ Display.getDefault().asyncExec(new Runnable() {
+ @Override
+ public void run() {
+ final MessageBox mb = new MessageBox(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell());
+ mb.setText(Messages.DeleteTraceHandler_Error + ' ' + trace.getName());
+ mb.setMessage(e.getMessage());
+ mb.open();
+ }
+ });
Activator.getDefault().logError("Error deleting trace: " + trace.getName(), e); //$NON-NLS-1$
}
}
public static String DeleteDialog_Title;
public static String DeleteTraceHandler_Message;
+ public static String DeleteTraceHandler_Error;
public static String DeleteExperimentHandler_Message;
+ public static String DeleteExperimentHandler_Error;
public static String SelectTraceTypeHandler_Title;
public static String SelectTraceTypeHandler_InvalidTraceType;
package org.eclipse.linuxtools.internal.tmf.ui.project.handlers;
-import java.io.ByteArrayInputStream;
-import java.io.InputStream;
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.IFile;
-import org.eclipse.core.resources.IResource;
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.internal.tmf.ui.Activator;
-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.trace.ITmfTrace;
*/
public class OpenExperimentHandler extends AbstractHandler {
- private static final String BOOKMARKS_HIDDEN_FILE = ".bookmarks"; //$NON-NLS-1$
-
private TmfExperimentElement fExperiment = null;
// ------------------------------------------------------------------------
public void run() {
final IFile file;
-
try {
- final IFile bookmarksFile = experimentElement.getProject().getExperimentsFolder().getResource().getFile(BOOKMARKS_HIDDEN_FILE);
- if (!bookmarksFile.exists()) {
- final InputStream source = new ByteArrayInputStream(new byte[0]);
- bookmarksFile.create(source, true, null);
- }
- bookmarksFile.setHidden(true);
-
- file = experimentElement.getResource().getFile(experimentElement.getName() + '_');
- if (!file.exists()) {
- file.createLink(bookmarksFile.getLocation(), IResource.REPLACE, null);
- }
- file.setHidden(true);
- file.setPersistentProperty(TmfCommonConstants.TRACETYPE, TmfExperiment.class.getCanonicalName());
-
+ file = experimentElement.getBookmarksFile();
} catch (final CoreException e) {
Activator.getDefault().logError("Error opening experiment " + experimentElement.getName(), e); //$NON-NLS-1$
displayErrorMsg(Messages.OpenExperimentHandler_Error + "\n\n" + e.getMessage()); //$NON-NLS-1$
final TmfExperiment experiment = new TmfExperiment(ITmfEvent.class, experimentElement.getName(), traces, cacheSize);
experiment.setBookmarksFile(file);
- final String finalCommonEditorId = commonEditorId;
+ final String editorId = commonEditorId;
Display.getDefault().asyncExec(new Runnable() {
@Override
public void run() {
activePage.reuseEditor((IReusableEditor) editor, editorInput);
activePage.activate(editor);
} else {
- activePage.openEditor(editorInput, finalCommonEditorId);
+ activePage.openEditor(editorInput, editorId);
}
- IDE.setDefaultEditor(file, finalCommonEditorId);
+ IDE.setDefaultEditor(file, editorId);
// editor should dispose the experiment on close
} catch (final CoreException e) {
Activator.getDefault().logError("Error opening experiment " + experimentElement.getName(), e); //$NON-NLS-1$
package org.eclipse.linuxtools.internal.tmf.ui.project.handlers;
-import java.io.ByteArrayInputStream;
-import java.io.InputStream;
-
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.resources.IFile;
-import org.eclipse.core.resources.IFolder;
-import org.eclipse.core.resources.IResource;
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.internal.tmf.ui.Activator;
-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.trace.ITmfTrace;
-import org.eclipse.linuxtools.tmf.core.trace.TmfTrace;
import org.eclipse.linuxtools.tmf.ui.editors.TmfEditorInput;
import org.eclipse.linuxtools.tmf.ui.editors.TmfEventsEditor;
import org.eclipse.linuxtools.tmf.ui.project.model.TmfTraceElement;
*/
public class OpenTraceHandler extends AbstractHandler {
- private static final String BOOKMARKS_HIDDEN_FILE = ".bookmarks"; //$NON-NLS-1$
-
// ------------------------------------------------------------------------
// Attributes
// ------------------------------------------------------------------------
return;
}
- final IResource resource = traceElement.getResource();
- IFile file = null;
- if (resource instanceof IFile) {
- file = (IFile) resource;
- } else if (resource instanceof IFolder) {
- try {
- final IFile bookmarksFile = traceElement.getProject().getTracesFolder().getResource().getFile(BOOKMARKS_HIDDEN_FILE);
- if (!bookmarksFile.exists()) {
- final InputStream source = new ByteArrayInputStream(new byte[0]);
- bookmarksFile.create(source, true, null);
- }
- bookmarksFile.setHidden(true);
-
- final IFolder folder = (IFolder) resource;
- file = folder.getFile(traceElement.getName() + '_');
- if (!file.exists()) {
- file.createLink(bookmarksFile.getLocation(), IResource.REPLACE, null);
- }
- file.setHidden(true);
- file.setPersistentProperty(TmfCommonConstants.TRACETYPE, TmfTrace.class.getCanonicalName());
- IDE.setDefaultEditor(file, editorId);
- // editor should dispose the trace on close
- } catch (final CoreException e) {
- Activator.getDefault().logError("Error opening trace " + traceElement.getName(), e); //$NON-NLS-1$
- displayErrorMsg(Messages.OpenTraceHandler_Error + "\n\n" + e.getMessage()); //$NON-NLS-1$
- trace.dispose();
- return;
- }
+ final IFile file;
+ try {
+ file = traceElement.getBookmarksFile();
+ } catch (final CoreException e) {
+ Activator.getDefault().logError("Error opening trace " + traceElement.getName(), e); //$NON-NLS-1$
+ displayErrorMsg(Messages.OpenTraceHandler_Error + "\n\n" + e.getMessage()); //$NON-NLS-1$
+ trace.dispose();
+ return;
}
- final IFile editorFile = file;
Display.getDefault().asyncExec(new Runnable() {
@Override
public void run() {
try {
- final IEditorInput editorInput = new TmfEditorInput(editorFile, trace);
+ final IEditorInput editorInput = new TmfEditorInput(file, trace);
final IWorkbench wb = PlatformUI.getWorkbench();
final IWorkbenchPage activePage = wb.getActiveWorkbenchWindow().getActivePage();
- final IEditorPart editor = activePage.findEditor(new FileEditorInput(editorFile));
+ final IEditorPart editor = activePage.findEditor(new FileEditorInput(file));
if ((editor != null) && (editor instanceof IReusableEditor)) {
activePage.reuseEditor((IReusableEditor) editor, editorInput);
activePage.activate(editor);
} else {
activePage.openEditor(editorInput, editorId);
- if (resource instanceof IFile) {
- IDE.setDefaultEditor((IFile) resource, editorId);
- }
+ IDE.setDefaultEditor(file, editorId);
+ // editor should dispose the trace on close
}
} catch (final PartInitException e) {
displayErrorMsg(Messages.OpenTraceHandler_Error + "\n\n" + e.getMessage()); //$NON-NLS-1$
# Delete message
DeleteDialog_Title = Confirm Delete
DeleteTraceHandler_Message = Are you sure you want to delete this trace?
+DeleteTraceHandler_Error = Error deleting trace
DeleteExperimentHandler_Message = Are you sure you want to delete this experiment?
+DeleteExperimentHandler_Error = Error deleting experiment
# Set Trace Type
SelectTraceTypeHandler_Title = Validation Error
/*******************************************************************************
* Copyright (c) 2010, 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 - Initial API and implementation
*******************************************************************************/
package org.eclipse.linuxtools.tmf.ui.project.model;
+import java.io.ByteArrayInputStream;
+import java.io.InputStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
+import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IFolder;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.linuxtools.tmf.core.TmfCommonConstants;
+import org.eclipse.linuxtools.tmf.core.trace.TmfExperiment;
import org.eclipse.ui.views.properties.IPropertyDescriptor;
import org.eclipse.ui.views.properties.IPropertySource2;
import org.eclipse.ui.views.properties.TextPropertyDescriptor;
* <p>
* @version 1.0
* @author Francois Chouinard
- *
+ *
*/
public class TmfExperimentElement extends TmfProjectModelElement implements IPropertySource2 {
sfLocationDescriptor.setCategory(sfInfoCategory);
}
+ private static final String BOOKMARKS_HIDDEN_FILE = ".bookmarks"; //$NON-NLS-1$
+
// ------------------------------------------------------------------------
// Constructors
// ------------------------------------------------------------------------
/**
- * Constructor
+ * Constructor
* @param name The name of the experiment
* @param folder The folder reference
* @param parent The experiment folder reference.
return traces;
}
+ /**
+ * Returns the file resource used to store bookmarks.
+ * The linked file will be created if it doesn't exist.
+ * @return the bookmarks file
+ * @throws CoreException if the bookmarks file cannot be created
+ * @since 2.0
+ */
+ public IFile getBookmarksFile() throws CoreException {
+ IFile file = null;
+ final IFile bookmarksFile = getProject().getExperimentsFolder().getResource().getFile(BOOKMARKS_HIDDEN_FILE);
+ if (!bookmarksFile.exists()) {
+ final InputStream source = new ByteArrayInputStream(new byte[0]);
+ bookmarksFile.create(source, true, null);
+ }
+ bookmarksFile.setHidden(true);
+
+ final IFolder folder = (IFolder) fResource;
+ file = folder.getFile(getName() + '_');
+ if (!file.exists()) {
+ file.createLink(bookmarksFile.getLocation(), IResource.REPLACE, null);
+ }
+ file.setHidden(true);
+ file.setPersistentProperty(TmfCommonConstants.TRACETYPE, TmfExperiment.class.getCanonicalName());
+ return file;
+ }
+
// ------------------------------------------------------------------------
// IPropertySource2
// ------------------------------------------------------------------------
@Override
public Object getPropertyValue(Object id) {
- if (sfName.equals(id))
+ if (sfName.equals(id)) {
return getName();
+ }
- if (sfPath.equals(id))
+ if (sfPath.equals(id)) {
return getPath().toString();
+ }
- if (sfLocation.equals(id))
+ if (sfLocation.equals(id)) {
return getLocation().toString();
+ }
return null;
}
-
+
/*
* (non-Javadoc)
* @see org.eclipse.ui.views.properties.IPropertySource#resetPropertyValue(java.lang.Object)
ResourcesPlugin.getWorkspace().addResourceChangeListener(this);
}
+ private void dispose() {
+ ResourcesPlugin.getWorkspace().removeResourceChangeListener(this);
+ }
+
// ------------------------------------------------------------------------
// ITmfProjectModelElement
// ------------------------------------------------------------------------
@Override
public void removeChild(ITmfProjectModelElement child) {
fChildren.remove(child);
+ if (child instanceof TmfProjectModelElement) {
+ ((TmfProjectModelElement) child).dispose();
+ }
refresh();
}
/*
package org.eclipse.linuxtools.tmf.ui.project.model;
+import java.io.ByteArrayInputStream;
+import java.io.InputStream;
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;
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.core.trace.TmfTrace;
import org.eclipse.linuxtools.tmf.ui.editors.TmfEventsEditor;
import org.eclipse.ui.IActionFilter;
import org.eclipse.ui.views.properties.IPropertyDescriptor;
sfIsLinkedDescriptor.setCategory(sfInfoCategory);
}
+ private static final String BOOKMARKS_HIDDEN_FILE = ".bookmarks"; //$NON-NLS-1$
+
// ------------------------------------------------------------------------
// Attributes
// ------------------------------------------------------------------------
return null;
}
+ /**
+ * Returns the file resource used to store bookmarks.
+ * If the trace resource is a file, it is returned directly.
+ * If the trace resource is a folder, a linked file is returned.
+ * The linked file will be created if it doesn't exist.
+ * @return the bookmarks file
+ * @throws CoreException if the bookmarks file cannot be created
+ * @since 2.0
+ */
+ public IFile getBookmarksFile() throws CoreException {
+ IFile file = null;
+ if (fResource instanceof IFile) {
+ file = (IFile) fResource;
+ } else if (fResource instanceof IFolder) {
+ final IFile bookmarksFile = getProject().getTracesFolder().getResource().getFile(BOOKMARKS_HIDDEN_FILE);
+ if (!bookmarksFile.exists()) {
+ final InputStream source = new ByteArrayInputStream(new byte[0]);
+ bookmarksFile.create(source, true, null);
+ }
+ bookmarksFile.setHidden(true);
+
+ final IFolder folder = (IFolder) fResource;
+ file = folder.getFile(getName() + '_');
+ if (!file.exists()) {
+ file.createLink(bookmarksFile.getLocation(), IResource.REPLACE, null);
+ }
+ file.setHidden(true);
+ file.setPersistentProperty(TmfCommonConstants.TRACETYPE, TmfTrace.class.getCanonicalName());
+ }
+ return file;
+ }
+
/**
* Returns the <code>TmfTraceElement</code> located under the <code>TmfTracesFolder</code>.
*
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.osgi.util.NLS;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
+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.actions.WorkspaceModifyOperation;
import org.eclipse.ui.dialogs.SelectionStatusDialog;
+import org.eclipse.ui.part.FileEditorInput;
/**
* Implementation of a dialog box to rename an experiment.
if (monitor.isCanceled()) {
throw new OperationCanceledException();
}
+ // Close the experiment if open
+ IFile file = fExperiment.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);
+ }
+ }
+ }
+ }
+
IFolder folder = fExperiment.getResource();
- IFile bookmarksFile = folder.getFile(fExperiment.getName() + '_');
- IFile newBookmarksFile = folder.getFile(newName + '_');
+ IFile bookmarksFile = fExperiment.getBookmarksFile();
+ IFile newBookmarksFile = folder.getFile(bookmarksFile.getName().replace(fExperiment.getName(), newName));
if (bookmarksFile.exists()) {
if (!newBookmarksFile.exists()) {
IPath newBookmarksPath = newBookmarksFile.getFullPath();
} catch (InterruptedException exception) {
return null;
} catch (InvocationTargetException exception) {
- MessageDialog.openError(getShell(), "", NLS.bind("", exception.getTargetException().getMessage())); //$NON-NLS-1$ //$NON-NLS-2$
+ MessageDialog.openError(getShell(), "", exception.getTargetException().getMessage()); //$NON-NLS-1$
return null;
} catch (RuntimeException exception) {
return null;
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.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.TmfProjectElement;
import org.eclipse.linuxtools.tmf.ui.project.model.TmfTraceElement;
import org.eclipse.linuxtools.tmf.ui.project.model.TmfTraceFolder;
-import org.eclipse.osgi.util.NLS;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
+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.actions.WorkspaceModifyOperation;
import org.eclipse.ui.dialogs.SelectionStatusDialog;
+import org.eclipse.ui.part.FileEditorInput;
/**
* Implementation of a dialog box to rename a trace.
if (monitor.isCanceled()) {
throw new OperationCanceledException();
}
+ // Close the trace if open
+ IFile file = fTrace.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);
+ }
+ }
+ }
+ }
+ TmfExperimentFolder experimentFolder = fTrace.getProject().getExperimentsFolder();
+ for (final ITmfProjectModelElement experiment : experimentFolder.getChildren()) {
+ for (final ITmfProjectModelElement trace : experiment.getChildren()) {
+ if (trace.equals(fTrace)) {
+ // 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);
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+
if (fTrace.getResource() instanceof IFolder) {
IFolder folder = (IFolder) fTrace.getResource();
- IFile bookmarksFile = folder.getFile(fTrace.getName() + '_');
- IFile newBookmarksFile = folder.getFile(newName + '_');
+ IFile bookmarksFile = fTrace.getBookmarksFile();
+ IFile newBookmarksFile = folder.getFile(bookmarksFile.getName().replace(fTrace.getName(), newName));
if (bookmarksFile.exists()) {
if (!newBookmarksFile.exists()) {
IPath newBookmarksPath = newBookmarksFile.getFullPath();
} catch (InterruptedException exception) {
return null;
} catch (InvocationTargetException exception) {
- MessageDialog.openError(getShell(), "", NLS.bind("", exception.getTargetException().getMessage())); //$NON-NLS-1$ //$NON-NLS-2$
+ MessageDialog.openError(getShell(), "", exception.getTargetException().getMessage()); //$NON-NLS-1$
return null;
} catch (RuntimeException exception) {
return null;