ss: Move plugins to Trace Compass namespace
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.ui / src / org / eclipse / linuxtools / tmf / ui / project / wizards / RenameTraceDialog.java
index 850e266b91eb60e8af3dae40ab4d231d2b9c4afe..ed2623ab9760cfac600653222f80b7b6325fed27 100644 (file)
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2011, 2012 Ericsson
+ * Copyright (c) 2011, 2014 Ericsson
  *
  * All rights reserved. This program and the accompanying materials are
  * made available under the terms of the Eclipse Public License v1.0 which
@@ -8,31 +8,19 @@
  *
  * Contributors:
  *   Francois Chouinard - Copied and adapted from NewFolderDialog
+ *   Patrick Tasse - Close editors to release resources
  *******************************************************************************/
 
 package org.eclipse.linuxtools.tmf.ui.project.wizards;
 
-import java.lang.reflect.InvocationTargetException;
-
 import org.eclipse.core.resources.IContainer;
-import org.eclipse.core.resources.IFile;
-import org.eclipse.core.resources.IFolder;
 import org.eclipse.core.resources.IResource;
 import org.eclipse.core.resources.IWorkspace;
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IPath;
-import org.eclipse.core.runtime.IProgressMonitor;
 import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.OperationCanceledException;
-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.Activator;
-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,8 +32,6 @@ 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.PlatformUI;
-import org.eclipse.ui.actions.WorkspaceModifyOperation;
 import org.eclipse.ui.dialogs.SelectionStatusDialog;
 
 /**
@@ -62,9 +48,6 @@ public class RenameTraceDialog extends SelectionStatusDialog {
 
     private final TmfTraceElement fTrace;
     private Text fNewTraceNameText;
-    private String fNewTraceName;
-    private final IContainer fTraceFolder;
-    private final TmfProjectElement fProject;
 
     // ------------------------------------------------------------------------
     // Constructor
@@ -77,9 +60,6 @@ public class RenameTraceDialog extends SelectionStatusDialog {
     public RenameTraceDialog(Shell shell, TmfTraceElement trace) {
         super(shell);
         fTrace = trace;
-        TmfTraceFolder folder = (TmfTraceFolder) trace.getParent();
-        fTraceFolder = folder.getResource();
-        fProject = trace.getProject();
         setTitle(Messages.RenameTraceDialog_DialogTitle);
         setStatusLineAboveButtons(true);
     }
@@ -87,10 +67,7 @@ public class RenameTraceDialog extends SelectionStatusDialog {
     // ------------------------------------------------------------------------
     // 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);
@@ -142,21 +119,13 @@ public class RenameTraceDialog extends SelectionStatusDialog {
         });
     }
 
-    /**
-     * Returns the new trace name
-     * @return the new trace name
-     */
-    public String getNewTraceName() {
-        return fNewTraceName;
-    }
-
     private void validateNewTraceName() {
 
-        fNewTraceName = fNewTraceNameText.getText();
-        IWorkspace workspace = fTraceFolder.getWorkspace();
-        IStatus nameStatus = workspace.validateName(fNewTraceName, IResource.FOLDER);
+        String newTraceName = fNewTraceNameText.getText();
+        IWorkspace workspace = fTrace.getResource().getWorkspace();
+        IStatus nameStatus = workspace.validateName(newTraceName, IResource.FOLDER);
 
-        if ("".equals(fNewTraceName)) { //$NON-NLS-1$
+        if ("".equals(newTraceName)) { //$NON-NLS-1$
             updateStatus(new Status(IStatus.ERROR, Activator.PLUGIN_ID, IStatus.ERROR,
                     Messages.Dialog_EmptyNameError, null));
             return;
@@ -167,8 +136,8 @@ public class RenameTraceDialog extends SelectionStatusDialog {
             return;
         }
 
-        IPath path = new Path(fNewTraceName);
-        if (fTraceFolder.getFolder(path).exists() || fTraceFolder.getFile(path).exists()) {
+        IContainer parentFolder = fTrace.getResource().getParent();
+        if (parentFolder.findMember(newTraceName) != null) {
             updateStatus(new Status(IStatus.ERROR, Activator.PLUGIN_ID, IStatus.ERROR,
                     Messages.Dialog_ExistingNameError, null));
             return;
@@ -180,88 +149,21 @@ public class RenameTraceDialog extends SelectionStatusDialog {
     // ------------------------------------------------------------------------
     // 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 (trace == null) {
-            return;
-        }
-        setSelectionResult(new IResource[] { trace });
+        setSelectionResult(new String[] { fNewTraceNameText.getText() });
         super.okPressed();
-
-        if (fProject != null) {
-            fProject.refresh();
-        }
-    }
-
-    private IResource renameTrace(final String newName) {
-
-        final IPath oldPath = fTrace.getResource().getFullPath();
-        final IPath newPath = oldPath.append("../" + newName); //$NON-NLS-1$
-
-        WorkspaceModifyOperation operation = new WorkspaceModifyOperation() {
-            @Override
-            public void execute(IProgressMonitor monitor) throws CoreException {
-                try {
-                    monitor.beginTask("", 1000); //$NON-NLS-1$
-                    if (monitor.isCanceled()) {
-                        throw new OperationCanceledException();
-                    }
-                    if (fTrace.getResource() instanceof IFolder) {
-                        IFolder folder = (IFolder) fTrace.getResource();
-                        IFile bookmarksFile = folder.getFile(fTrace.getName() + '_');
-                        IFile newBookmarksFile = folder.getFile(newName + '_');
-                        if (bookmarksFile.exists()) {
-                            if (!newBookmarksFile.exists()) {
-                                IPath newBookmarksPath = newBookmarksFile.getFullPath();
-                                bookmarksFile.move(newBookmarksPath, IResource.FORCE | IResource.SHALLOW, null);
-                            }
-                        }
-                    }
-
-                    fTrace.renameSupplementaryFolder(newName);
-                    fTrace.getResource().move(newPath, IResource.FORCE | IResource.SHALLOW, null);
-                    if (monitor.isCanceled()) {
-                        throw new OperationCanceledException();
-                    }
-                } finally {
-                    monitor.done();
-                }
-            }
-        };
-
-        try {
-            PlatformUI.getWorkbench().getProgressService().busyCursorWhile(operation);
-        } catch (InterruptedException exception) {
-            return null;
-        } catch (InvocationTargetException exception) {
-            MessageDialog.openError(getShell(), "", NLS.bind("", exception.getTargetException().getMessage())); //$NON-NLS-1$ //$NON-NLS-2$
-            return null;
-        } catch (RuntimeException exception) {
-            return null;
-        }
-
-        return fTrace.getResource();
     }
 
 }
This page took 0.030276 seconds and 5 git commands to generate.