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

double-click file download using background job

This commit is contained in:
David McKnight 2006-08-23 16:53:33 +00:00
parent 0698e1f803
commit 5c5121a9ed
2 changed files with 210 additions and 0 deletions

View file

@ -1129,6 +1129,156 @@ public class SystemEditableRemoteFile implements ISystemEditableRemoteObject, IP
}
}
/**
* Open in editor
*/
public void open(IProgressMonitor monitor)
{
open(monitor, false);
}
/**
* Open in editor
*/
public void open(IProgressMonitor monitor, boolean readOnly)
{
try
{
// ensure the file is stale
remoteFile.markStale(true, false);
{
remoteFile = remoteFile.getParentRemoteFileSubSystem().getRemoteFileObject(remoteFile.getAbsolutePath());
}
if (!remoteFile.exists())
{
SystemMessage message = RSEUIPlugin.getPluginMessage(ISystemMessages.MSG_ERROR_FILE_NOTFOUND);
message.makeSubstitution(remotePath, subsystem.getHost().getHostName());
DisplayMessageDialog dd = new DisplayMessageDialog(message);
Display.getDefault().syncExec(dd);
return;
}
// assumption is that editor is not open
if (readOnly)
{
if (download(monitor))
{
setLocalResourceProperties();
openEditor();
setEditorAsReadOnly();
}
}
else if (!isReadOnly())
{ // we have write access
if (download(monitor))
{
addAsListener();
setLocalResourceProperties();
openEditor();
}
}
else
{ // we do not have write access
IRemoteFile fakeRemoteFile = subsystem.getRemoteFileObject(remotePath);
if (!fakeRemoteFile.exists())
{ // this could be because file doesn't exist
download(monitor);
}
SystemMessage message = RSEUIPlugin.getPluginMessage(ISystemMessages.MSG_DOWNLOAD_NO_WRITE);
message.makeSubstitution(remotePath, subsystem.getHost().getHostName());
DisplayQuestionDialog dd = new DisplayQuestionDialog(message);
Display.getDefault().syncExec(dd);
boolean answer = dd.getResponse();
if (answer)
{
if (download(monitor))
{
setLocalResourceProperties();
setReadOnly(getLocalResource(), true);
openEditor();
setEditorAsReadOnly();
}
}
}
}
catch (Exception e)
{
if (e instanceof InterruptedException)
{
// do nothing since user pressed cancel
}
else if (e instanceof SystemMessageException)
{
DisplayMessageDialog dd = new DisplayMessageDialog(((SystemMessageException)e).getSystemMessage());
Display.getDefault().syncExec(dd);
}
else
{
RemoteFileIOException exc = new RemoteFileIOException(e);
DisplayMessageDialog dd = new DisplayMessageDialog(exc.getSystemMessage());
Display.getDefault().syncExec(dd);
}
}
}
public class DisplayMessageDialog implements Runnable
{
protected SystemMessage _msg;
public DisplayMessageDialog(SystemMessage msg)
{
_msg = msg;
}
public void run()
{
SystemMessageDialog dialog = new SystemMessageDialog(RSEUIPlugin.getActiveWorkbenchShell(), _msg);
dialog.open();
}
}
public class DisplayQuestionDialog implements Runnable
{
protected SystemMessage _msg;
public boolean _responce = false;
public DisplayQuestionDialog(SystemMessage msg)
{
_msg = msg;
}
public boolean getResponse()
{
return _responce;
}
public void run()
{
SystemMessageDialog dialog = new SystemMessageDialog(RSEUIPlugin.getActiveWorkbenchShell(), _msg);
try
{
_responce = dialog.openQuestion();
}
catch (Exception e)
{
}
}
}
/**
* Open in system editor
*/

View file

@ -0,0 +1,60 @@
/**
*
*/
package org.eclipse.rse.files.ui.view;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.rse.ui.view.ISystemEditableRemoteObject;
import org.eclipse.swt.widgets.Display;
public class DownloadJob extends Job
{
public class OpenEditorRunnable implements Runnable
{
private ISystemEditableRemoteObject _editable;
public OpenEditorRunnable(ISystemEditableRemoteObject editable)
{
_editable = editable;
}
public void run()
{
try
{
_editable.addAsListener();
_editable.setLocalResourceProperties();
_editable.openEditor();
}
catch (Exception e)
{
}
}
}
private ISystemEditableRemoteObject _editable;
public DownloadJob(ISystemEditableRemoteObject editable)
{
super("Download");
_editable = editable;
}
public IStatus run(IProgressMonitor monitor)
{
try
{
_editable.download(monitor);
}
catch (Exception e)
{
}
OpenEditorRunnable oe = new OpenEditorRunnable(_editable);
Display.getDefault().asyncExec(oe);
return Status.OK_STATUS;
}
}