1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-03 07:05:24 +02:00

[180874] progress dialog when creating remote project

This commit is contained in:
Martin Oberhuber 2007-04-06 11:31:58 +00:00
parent 8022c9712d
commit d4881b58d7

View file

@ -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;
/**
//----------------------------------------------------------------------------
// <Adapted from org.eclipse.ui.actions.CopyProjectAction as of Eclipse 3.3M6>
// (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 <code>CoreException</code>
*/
final void recordError(CoreException error) {
this.errorStatus = error.getStatus();
}
/**
* Opens an error dialog to display the given message.
* <p>
* Note that this method must be called from UI thread.
* </p>
*
* @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 <code>true</code> if the copy operation completed, and
* <code>false</code> 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;
}
//----------------------------------------------------------------------------
// </Adapted from org.eclipse.ui.actions.CopyProjectAction as of Eclipse 3.3M6>
// (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;
}