/*******************************************************************************
- * Copyright (c) 2011 Ericsson
- *
+ * Copyright (c) 2011, 2014 Ericsson, École Polytechnique de Montréal
+ *
* 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
+ * Geneviève Bastien - Moved the actual copy code to model element's class
*******************************************************************************/
package org.eclipse.linuxtools.tmf.ui.project.wizards;
import java.lang.reflect.InvocationTargetException;
-import org.eclipse.core.resources.IContainer;
import org.eclipse.core.resources.IFolder;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IWorkspace;
import org.eclipse.core.runtime.Status;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.jface.dialogs.MessageDialog;
-import org.eclipse.linuxtools.tmf.ui.TmfUiPlugin;
+import org.eclipse.linuxtools.internal.tmf.ui.Activator;
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.ui.dialogs.SelectionStatusDialog;
/**
- * <b><u>CopyExperimentDialog</u></b>
+ * Implementation of the copy experiement dialog box.
* <p>
+ *
+ * @version 1.0
+ * @author Francois Chouinard
*/
public class CopyExperimentDialog extends SelectionStatusDialog {
// Members
// ------------------------------------------------------------------------
- private final TmfExperimentElement fExperiment;
- private Text fNewExperimentName;
- private IContainer fExperimentFolder;
- private TmfProjectElement fProject;
+ private final TmfExperimentElement fExperiment;
+ private Text fNewExperimentName;
+ private IFolder fExperimentFolder;
// ------------------------------------------------------------------------
// Constructor
// ------------------------------------------------------------------------
+ /**
+ * Constructor
+ *
+ * @param shell
+ * The parent shell
+ * @param experiment
+ * The TMF experiment model element
+ */
public CopyExperimentDialog(Shell shell, TmfExperimentElement experiment) {
super(shell);
fExperiment = experiment;
TmfExperimentFolder folder = (TmfExperimentFolder) experiment.getParent();
fExperimentFolder = folder.getResource();
- fProject = experiment.getProject();
setTitle(Messages.CopyExperimentDialog_DialogTitle);
setStatusLineAboveButtons(true);
}
fNewExperimentName.addListener(SWT.Modify, new Listener() {
@Override
public void handleEvent(Event event) {
- validateNewExperimentName();
+ validateNewExperimentName();
}
});
}
private void validateNewExperimentName() {
-
- String name = fNewExperimentName.getText();
+
+ String name = fNewExperimentName.getText();
IWorkspace workspace = fExperimentFolder.getWorkspace();
IStatus nameStatus = workspace.validateName(name, IResource.FOLDER);
if ("".equals(name)) { //$NON-NLS-1$
- updateStatus(new Status(IStatus.ERROR, TmfUiPlugin.PLUGIN_ID, IStatus.ERROR, Messages.Dialog_EmptyNameError, null));
- return;
+ updateStatus(new Status(IStatus.ERROR, Activator.PLUGIN_ID, IStatus.ERROR, Messages.Dialog_EmptyNameError, null));
+ return;
}
-
- if (nameStatus.isOK() == false) {
- updateStatus(nameStatus);
- return;
+
+ if (!nameStatus.isOK()) {
+ updateStatus(nameStatus);
+ return;
}
-
+
IPath path = new Path(name);
if (fExperimentFolder.getFolder(path).exists() || fExperimentFolder.getFile(path).exists()) {
- updateStatus(new Status(IStatus.ERROR, TmfUiPlugin.PLUGIN_ID, IStatus.ERROR, Messages.Dialog_ExistingNameError, null));
+ 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$
}
// ------------------------------------------------------------------------
}
setSelectionResult(new IFolder[] { folder });
super.okPressed();
-
- if (fProject != null) {
- fProject.refresh();
- }
}
- private IFolder copyExperiment(String newName) {
-
- IPath oldPath = fExperiment.getResource().getFullPath();
- final IPath newPath = oldPath.append("../" + newName); //$NON-NLS-1$
+ private IFolder copyExperiment(final String newName) {
- WorkspaceModifyOperation operation = new WorkspaceModifyOperation() {
+ WorkspaceModifyOperation operation = new WorkspaceModifyOperation() {
@Override
public void execute(IProgressMonitor monitor) throws CoreException {
try {
if (monitor.isCanceled()) {
throw new OperationCanceledException();
}
- fExperiment.getResource().copy(newPath, IResource.FORCE | IResource.SHALLOW, null);
+
+ fExperiment.copy(newName, true);
+
if (monitor.isCanceled()) {
throw new OperationCanceledException();
}