From d4881b58d7eda87a7fb32f109ab1e470674cda29 Mon Sep 17 00:00:00 2001 From: Martin Oberhuber < martin.oberhuber@windriver.com> Date: Fri, 6 Apr 2007 11:31:58 +0000 Subject: [PATCH] [180874] progress dialog when creating remote project --- .../CreateRemoteProjectActionDelegate.java | 133 ++++++++++++++++-- 1 file changed, 121 insertions(+), 12 deletions(-) diff --git a/rse/plugins/org.eclipse.rse.eclipse.filesystem/src/org/eclipse/rse/internal/eclipse/filesystem/ui/actions/CreateRemoteProjectActionDelegate.java b/rse/plugins/org.eclipse.rse.eclipse.filesystem/src/org/eclipse/rse/internal/eclipse/filesystem/ui/actions/CreateRemoteProjectActionDelegate.java index f176356adca..309304791b6 100644 --- a/rse/plugins/org.eclipse.rse.eclipse.filesystem/src/org/eclipse/rse/internal/eclipse/filesystem/ui/actions/CreateRemoteProjectActionDelegate.java +++ b/rse/plugins/org.eclipse.rse.eclipse.filesystem/src/org/eclipse/rse/internal/eclipse/filesystem/ui/actions/CreateRemoteProjectActionDelegate.java @@ -1,5 +1,5 @@ /******************************************************************************** - * Copyright (c) 2006 IBM Corporation. All rights reserved. + * Copyright (c) 2000, 2006 IBM Corporation and others. 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 @@ -13,10 +13,13 @@ * Contributors: * IBM Corporation - initial API and implementation * Kushal Munir (IBM) - moved to internal package + * Martin Oberhuber (Wind River) - added progress dialog + * - (adapted from org.eclipse.ui.actions.CopyProjectAction, copyright IBM) ********************************************************************************/ package org.eclipse.rse.internal.eclipse.filesystem.ui.actions; +import java.lang.reflect.InvocationTargetException; import java.net.URI; import java.util.Iterator; @@ -27,12 +30,18 @@ import org.eclipse.core.resources.IResource; import org.eclipse.core.resources.IWorkspaceRoot; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.NullProgressMonitor; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Status; import org.eclipse.jface.action.IAction; +import org.eclipse.jface.dialogs.ErrorDialog; +import org.eclipse.jface.dialogs.MessageDialog; +import org.eclipse.jface.dialogs.ProgressMonitorDialog; +import org.eclipse.jface.operation.IRunnableWithProgress; import org.eclipse.jface.viewers.ISelection; import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.jface.viewers.StructuredSelection; import org.eclipse.rse.core.SystemBasePlugin; +import org.eclipse.rse.internal.eclipse.filesystem.Activator; import org.eclipse.rse.internal.eclipse.filesystem.RSEFileSystem; import org.eclipse.rse.subsystems.files.core.subsystems.IRemoteFile; import org.eclipse.swt.widgets.Display; @@ -42,23 +51,122 @@ import org.eclipse.ui.IWorkbench; import org.eclipse.ui.PlatformUI; - public class CreateRemoteProjectActionDelegate implements IActionDelegate { protected IStructuredSelection fSelection; + private IStatus errorStatus; - - /** + //---------------------------------------------------------------------------- + // + // (Copyright 2000, 2006 IBM Corporation and others) + //---------------------------------------------------------------------------- + + /* (non-Javadoc) * @see org.eclipse.ui.IActionDelegate#run(org.eclipse.jface.action.IAction) */ public void run(IAction action) { - IRemoteFile directory = (IRemoteFile)fSelection.getFirstElement(); - createRemoteProject(directory, new NullProgressMonitor()); - - } - + errorStatus = null; + IRemoteFile directory = (IRemoteFile)fSelection.getFirstElement(); + + boolean completed = performCreateRemoteProject(directory); + + if (!completed) { + return; // not appropriate to show errors + } + + // If errors occurred, open an Error dialog + if (errorStatus != null) { + ErrorDialog.openError(getShell(), getErrorsTitle(), null, errorStatus); + errorStatus = null; + } + } + + /** + * Records the core exception to be displayed to the user once the action is + * finished. + * + * @param error + * a CoreException + */ + final void recordError(CoreException error) { + this.errorStatus = error.getStatus(); + } + + /** + * Opens an error dialog to display the given message. + *

+ * Note that this method must be called from UI thread. + *

+ * + * @param message + * the message + */ + void displayError(String message) { + MessageDialog.openError(getShell(), getErrorsTitle(), message); + } + + /** + * Return the title of the errors dialog. + * + * @return java.lang.String + */ + protected String getErrorsTitle() { + return "Error creating remote project"; + } + + /** + * Creates a remote project. + * + * @param directory + * the remote folder on which the EFS project should be locaed + * @return true if the copy operation completed, and + * false if it was abandoned part way + */ + boolean performCreateRemoteProject(final IRemoteFile directory) { + IRunnableWithProgress op = new IRunnableWithProgress() { + public void run(IProgressMonitor monitor) { + try { + createRemoteProject(directory, monitor); + } catch (Exception e) { + if (e.getCause() instanceof CoreException) { + recordError((CoreException)e.getCause()); + } else { + Activator.getDefault().getLog().log(new Status(IStatus.ERROR, + Activator.getDefault().getBundle().getSymbolicName(), + -1, e.getMessage(), e)); + displayError(e.getMessage()); + } + } + } + }; + + try { + //TODO make this a Job an run in foreground with option to send to background + ProgressMonitorDialog mon = new ProgressMonitorDialog(getShell()) { + protected void configureShell(Shell shell) { + super.configureShell(shell); + shell.setText("Creating remote Project"); + } + }; + mon.run(true, true, op); + } catch (InterruptedException e) { + return false; + } catch (InvocationTargetException e) { + displayError("Internal Error: "+e.getTargetException().getMessage()); + return false; + } + + return true; + } + + //---------------------------------------------------------------------------- + //
+ // (Copyright 2000, 2006 IBM Corporation and others) + //---------------------------------------------------------------------------- + + private IProject createRemoteProject(IRemoteFile directory, IProgressMonitor monitor) { IWorkspaceRoot root = SystemBasePlugin.getWorkspaceRoot(); @@ -84,14 +192,15 @@ public class CreateRemoteProjectActionDelegate implements IActionDelegate { editProject.open(monitor); - editProject.refreshLocal(IResource.DEPTH_INFINITE, monitor); + editProject.refreshLocal(IResource.DEPTH_ONE, monitor); } catch (CoreException e) { - SystemBasePlugin.logError("Error creating temp project", e); //$NON-NLS-1$ + SystemBasePlugin.logError("Error creating temp project", e); } catch (Exception e) { + SystemBasePlugin.logError("Error creating temp project", e); } return editProject; }