/*******************************************************************************
- * Copyright (c) 2011, 2012 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.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.
- * <p>
+ * <p>
* @version 1.0
* @author Francois Chouinard
*/
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
// ------------------------------------------------------------------------
// Dialog
// ------------------------------------------------------------------------
- /*
- * (non-Javadoc)
- * @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite)
- */
+
@Override
protected Control createDialogArea(Composite parent) {
Composite composite = (Composite) super.createDialogArea(parent);
// ------------------------------------------------------------------------
// SelectionStatusDialog
// ------------------------------------------------------------------------
- /*
- * (non-Javadoc)
- * @see org.eclipse.ui.dialogs.SelectionStatusDialog#computeResult()
- */
+
@Override
protected void computeResult() {
}
- /*
- * (non-Javadoc)
- * @see org.eclipse.ui.dialogs.SelectionStatusDialog#create()
- */
+
@Override
public void create() {
super.create();
getButton(IDialogConstants.OK_ID).setEnabled(false);
}
- /*
- * (non-Javadoc)
- * @see org.eclipse.ui.dialogs.SelectionStatusDialog#okPressed()
- */
+
@Override
protected void okPressed() {
IResource trace = renameTrace(fNewTraceNameText.getText());
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;