tmf/lttng: Remove unneeded (non-Javadoc) comments
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.ui / src / org / eclipse / linuxtools / tmf / ui / project / wizards / RenameTraceDialog.java
index bafbb3daa63a11109223a300a21ee869865174eb..f1672270370c58167cfe37535994d0446f9eb10c 100644 (file)
@@ -1,11 +1,11 @@
 /*******************************************************************************
- * 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
  *******************************************************************************/
@@ -28,11 +28,13 @@ import org.eclipse.core.runtime.Path;
 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;
@@ -44,13 +46,20 @@ import org.eclipse.swt.widgets.Label;
 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 {
 
@@ -61,13 +70,17 @@ 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;
@@ -133,6 +146,10 @@ public class RenameTraceDialog extends SelectionStatusDialog {
         });
     }
 
+    /**
+     * Returns the new trace name
+     * @return the new trace name
+     */
     public String getNewTraceName() {
         return fNewTraceName;
     }
@@ -144,24 +161,24 @@ public class RenameTraceDialog extends SelectionStatusDialog {
         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$
     }
 
     // ------------------------------------------------------------------------
@@ -205,10 +222,43 @@ public class RenameTraceDialog extends SelectionStatusDialog {
                     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();
@@ -216,6 +266,8 @@ public class RenameTraceDialog extends SelectionStatusDialog {
                             }
                         }
                     }
+
+                    fTrace.renameSupplementaryFolder(newName);
                     fTrace.getResource().move(newPath, IResource.FORCE | IResource.SHALLOW, null);
                     if (monitor.isCanceled()) {
                         throw new OperationCanceledException();
@@ -231,7 +283,7 @@ public class RenameTraceDialog extends SelectionStatusDialog {
         } 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;
This page took 0.027738 seconds and 5 git commands to generate.