/*******************************************************************************
- * Copyright (c) 2011 Ericsson
- *
+ * Copyright (c) 2011, 2013 Ericsson
+ *
* All rights reserved. This program and the accompanying materials are
* made available under the terms of the Eclipse Public License v1.0 which
* accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
- *
+ *
* Contributors:
* Francois Chouinard - Copied and adapted from NewFolderDialog
*******************************************************************************/
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.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;
/**
- * <b><u>RenameTraceDialog</u></b>
+ * Implementation of a dialog box to rename a trace.
* <p>
+ * @version 1.0
+ * @author Francois Chouinard
*/
public class RenameTraceDialog extends SelectionStatusDialog {
private final TmfTraceElement fTrace;
private Text fNewTraceNameText;
private String fNewTraceName;
- private IContainer fTraceFolder;
- private TmfProjectElement fProject;
+ private final IContainer fTraceFolder;
+ private final TmfProjectElement fProject;
// ------------------------------------------------------------------------
// Constructor
// ------------------------------------------------------------------------
-
+ /**
+ * Constructor
+ * @param shell The parent shell
+ * @param trace The trace element to rename
+ */
public RenameTraceDialog(Shell shell, TmfTraceElement trace) {
super(shell);
fTrace = trace;
});
}
+ /**
+ * Returns the new trace name
+ * @return the new trace name
+ */
public String getNewTraceName() {
return fNewTraceName;
}
IStatus nameStatus = workspace.validateName(fNewTraceName, IResource.FOLDER);
if ("".equals(fNewTraceName)) { //$NON-NLS-1$
- updateStatus(new Status(IStatus.ERROR, TmfUiPlugin.PLUGIN_ID, IStatus.ERROR,
+ updateStatus(new Status(IStatus.ERROR, Activator.PLUGIN_ID, IStatus.ERROR,
Messages.Dialog_EmptyNameError, null));
return;
}
- if (nameStatus.isOK() == false) {
+ if (!nameStatus.isOK()) {
updateStatus(nameStatus);
return;
}
IPath path = new Path(fNewTraceName);
if (fTraceFolder.getFolder(path).exists() || fTraceFolder.getFile(path).exists()) {
- updateStatus(new Status(IStatus.ERROR, TmfUiPlugin.PLUGIN_ID, IStatus.ERROR,
+ updateStatus(new Status(IStatus.ERROR, Activator.PLUGIN_ID, IStatus.ERROR,
Messages.Dialog_ExistingNameError, null));
return;
}
- updateStatus(new Status(IStatus.OK, TmfUiPlugin.PLUGIN_ID, "")); //$NON-NLS-1$
+ updateStatus(new Status(IStatus.OK, Activator.PLUGIN_ID, "")); //$NON-NLS-1$
}
// ------------------------------------------------------------------------
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;