1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-06-09 02:36:01 +02:00

Add progress monitor to RemoteResourceBrowser.

Change RemoteResourceBrowserWidget to return IFileStore instead of
String.

Signed-off-by: Greg Watson <g.watson@computer.org>
This commit is contained in:
Greg Watson 2013-12-19 11:36:45 -05:00
parent 290378c74a
commit 80792af690
8 changed files with 213 additions and 125 deletions

View file

@ -10,22 +10,20 @@
*******************************************************************************/ *******************************************************************************/
package org.eclipse.remote.internal.jsch.ui; package org.eclipse.remote.internal.jsch.ui;
import java.util.ArrayList;
import java.util.List;
import org.eclipse.core.filesystem.IFileStore;
import org.eclipse.jface.window.Window; import org.eclipse.jface.window.Window;
import org.eclipse.remote.core.IRemoteConnection; import org.eclipse.remote.core.IRemoteConnection;
import org.eclipse.remote.core.IRemoteServices;
import org.eclipse.remote.ui.IRemoteUIFileManager; import org.eclipse.remote.ui.IRemoteUIFileManager;
import org.eclipse.remote.ui.dialogs.RemoteResourceBrowser; import org.eclipse.remote.ui.dialogs.RemoteResourceBrowser;
import org.eclipse.swt.widgets.Shell; import org.eclipse.swt.widgets.Shell;
public class JSchUIFileManager implements IRemoteUIFileManager { public class JSchUIFileManager implements IRemoteUIFileManager {
private IRemoteServices services = null;
private IRemoteConnection connection = null; private IRemoteConnection connection = null;
private boolean showConnections = false; private boolean showConnections = false;
public JSchUIFileManager(IRemoteServices services) {
this.services = services;
}
/* /*
* (non-Javadoc) * (non-Javadoc)
* *
@ -33,8 +31,9 @@ public class JSchUIFileManager implements IRemoteUIFileManager {
* org.eclipse.ptp.remote.core.IRemoteFileManager#browseDirectory(org.eclipse * org.eclipse.ptp.remote.core.IRemoteFileManager#browseDirectory(org.eclipse
* .swt.widgets.Shell, java.lang.String, java.lang.String) * .swt.widgets.Shell, java.lang.String, java.lang.String)
*/ */
@Override
public String browseDirectory(Shell shell, String message, String filterPath, int flags) { public String browseDirectory(Shell shell, String message, String filterPath, int flags) {
RemoteResourceBrowser browser = new RemoteResourceBrowser(services, connection, shell, RemoteResourceBrowser.SINGLE); RemoteResourceBrowser browser = new RemoteResourceBrowser(connection, shell, RemoteResourceBrowser.SINGLE);
browser.setType(RemoteResourceBrowser.DIRECTORY_BROWSER); browser.setType(RemoteResourceBrowser.DIRECTORY_BROWSER);
browser.setInitialPath(filterPath); browser.setInitialPath(filterPath);
browser.setTitle(message); browser.setTitle(message);
@ -43,11 +42,11 @@ public class JSchUIFileManager implements IRemoteUIFileManager {
return null; return null;
} }
connection = browser.getConnection(); connection = browser.getConnection();
String path = browser.getPath(); IFileStore resource = browser.getResource();
if (path == null) { if (resource == null) {
return null; return null;
} }
return path; return resource.toURI().getPath();
} }
/* /*
@ -57,8 +56,9 @@ public class JSchUIFileManager implements IRemoteUIFileManager {
* org.eclipse.ptp.remote.core.IRemoteFileManager#browseFile(org.eclipse * org.eclipse.ptp.remote.core.IRemoteFileManager#browseFile(org.eclipse
* .swt.widgets.Shell, java.lang.String, java.lang.String) * .swt.widgets.Shell, java.lang.String, java.lang.String)
*/ */
@Override
public String browseFile(Shell shell, String message, String filterPath, int flags) { public String browseFile(Shell shell, String message, String filterPath, int flags) {
RemoteResourceBrowser browser = new RemoteResourceBrowser(services, connection, shell, RemoteResourceBrowser.SINGLE); RemoteResourceBrowser browser = new RemoteResourceBrowser(connection, shell, RemoteResourceBrowser.SINGLE);
browser.setType(RemoteResourceBrowser.FILE_BROWSER); browser.setType(RemoteResourceBrowser.FILE_BROWSER);
browser.setInitialPath(filterPath); browser.setInitialPath(filterPath);
browser.setTitle(message); browser.setTitle(message);
@ -67,11 +67,11 @@ public class JSchUIFileManager implements IRemoteUIFileManager {
return null; return null;
} }
connection = browser.getConnection(); connection = browser.getConnection();
String path = browser.getPath(); IFileStore resource = browser.getResource();
if (path == null) { if (resource == null) {
return null; return null;
} }
return path; return resource.toURI().getPath();
} }
/* /*
@ -81,8 +81,9 @@ public class JSchUIFileManager implements IRemoteUIFileManager {
* org.eclipse.ptp.remote.core.IRemoteFileManager#browseFile(org.eclipse * org.eclipse.ptp.remote.core.IRemoteFileManager#browseFile(org.eclipse
* .swt.widgets.Shell, java.lang.String, java.lang.String) * .swt.widgets.Shell, java.lang.String, java.lang.String)
*/ */
public String[] browseFiles(Shell shell, String message, String filterPath, int flags) { @Override
RemoteResourceBrowser browser = new RemoteResourceBrowser(services, connection, shell, RemoteResourceBrowser.MULTI); public List<String> browseFiles(Shell shell, String message, String filterPath, int flags) {
RemoteResourceBrowser browser = new RemoteResourceBrowser(connection, shell, RemoteResourceBrowser.MULTI);
browser.setType(RemoteResourceBrowser.FILE_BROWSER); browser.setType(RemoteResourceBrowser.FILE_BROWSER);
browser.setInitialPath(filterPath); browser.setInitialPath(filterPath);
browser.setTitle(message); browser.setTitle(message);
@ -91,11 +92,11 @@ public class JSchUIFileManager implements IRemoteUIFileManager {
return null; return null;
} }
connection = browser.getConnection(); connection = browser.getConnection();
String path[] = browser.getPaths(); List<String> paths = new ArrayList<String>();
if (path == null) { for (IFileStore store : browser.getResources()) {
return null; paths.add(store.toURI().getPath());
} }
return path; return paths;
} }
/* /*
@ -103,6 +104,7 @@ public class JSchUIFileManager implements IRemoteUIFileManager {
* *
* @see org.eclipse.ptp.remote.ui.IRemoteUIFileManager#getConnection() * @see org.eclipse.ptp.remote.ui.IRemoteUIFileManager#getConnection()
*/ */
@Override
public IRemoteConnection getConnection() { public IRemoteConnection getConnection() {
return connection; return connection;
} }
@ -114,6 +116,7 @@ public class JSchUIFileManager implements IRemoteUIFileManager {
* org.eclipse.ptp.remote.ui.IRemoteUIFileManager#setConnection(org.eclipse * org.eclipse.ptp.remote.ui.IRemoteUIFileManager#setConnection(org.eclipse
* .ptp.remote.core.IRemoteConnection) * .ptp.remote.core.IRemoteConnection)
*/ */
@Override
public void setConnection(IRemoteConnection connection) { public void setConnection(IRemoteConnection connection) {
this.connection = connection; this.connection = connection;
} }
@ -124,6 +127,7 @@ public class JSchUIFileManager implements IRemoteUIFileManager {
* @see * @see
* org.eclipse.ptp.remote.ui.IRemoteUIFileManager#showConnections(boolean) * org.eclipse.ptp.remote.ui.IRemoteUIFileManager#showConnections(boolean)
*/ */
@Override
public void showConnections(boolean enable) { public void showConnections(boolean enable) {
showConnections = enable; showConnections = enable;
} }

View file

@ -41,6 +41,7 @@ public class JSchUIServices implements IRemoteUIServices {
* *
* @see org.eclipse.ptp.remote.ui.IRemoteUIServicesDescriptor#getId() * @see org.eclipse.ptp.remote.ui.IRemoteUIServicesDescriptor#getId()
*/ */
@Override
public String getId() { public String getId() {
return fServices.getId(); return fServices.getId();
} }
@ -50,6 +51,7 @@ public class JSchUIServices implements IRemoteUIServices {
* *
* @see org.eclipse.ptp.remote.ui.IRemoteUIServicesDescriptor#getName() * @see org.eclipse.ptp.remote.ui.IRemoteUIServicesDescriptor#getName()
*/ */
@Override
public String getName() { public String getName() {
return fServices.getName(); return fServices.getName();
} }
@ -59,6 +61,7 @@ public class JSchUIServices implements IRemoteUIServices {
* *
* @see org.eclipse.ptp.remote.ui.IRemoteUIServicesDescriptor#getUIConnectionManager() * @see org.eclipse.ptp.remote.ui.IRemoteUIServicesDescriptor#getUIConnectionManager()
*/ */
@Override
public IRemoteUIConnectionManager getUIConnectionManager() { public IRemoteUIConnectionManager getUIConnectionManager() {
return new JSchUIConnectionManager(fServices); return new JSchUIConnectionManager(fServices);
} }
@ -68,7 +71,8 @@ public class JSchUIServices implements IRemoteUIServices {
* *
* @see org.eclipse.ptp.remote.ui.IRemoteUIServicesDescriptor#getUIFileManager() * @see org.eclipse.ptp.remote.ui.IRemoteUIServicesDescriptor#getUIFileManager()
*/ */
@Override
public IRemoteUIFileManager getUIFileManager() { public IRemoteUIFileManager getUIFileManager() {
return new JSchUIFileManager(fServices); return new JSchUIFileManager();
} }
} }

View file

@ -48,7 +48,7 @@ RemoteFileWidget_Select_File=Select File
RemoteResourceBrowser_resourceTitle=Browse Resource RemoteResourceBrowser_resourceTitle=Browse Resource
RemoteResourceBrowser_fileTitle=Browse File RemoteResourceBrowser_fileTitle=Browse File
RemoteResourceBrowser_directoryTitle=Browse Directory RemoteResourceBrowser_directoryTitle=Browse Directory
RemoteResourceBrowser_resourceLabel=Select resource: RemoteResourceBrowser_resourceLabel=Selected resource:
RemoteResourceBrowser_fileLabel=Selected file: RemoteResourceBrowser_fileLabel=Selected file:
RemoteResourceBrowser_directoryLabel=Selected directory: RemoteResourceBrowser_directoryLabel=Selected directory:
RemoteResourceBrowser_connectonLabel=Connection: RemoteResourceBrowser_connectonLabel=Connection:

View file

@ -11,6 +11,8 @@
package org.eclipse.remote.internal.ui.services.local; package org.eclipse.remote.internal.ui.services.local;
import java.io.File; import java.io.File;
import java.util.Arrays;
import java.util.List;
import org.eclipse.remote.core.IRemoteConnection; import org.eclipse.remote.core.IRemoteConnection;
import org.eclipse.remote.ui.IRemoteUIFileManager; import org.eclipse.remote.ui.IRemoteUIFileManager;
@ -29,6 +31,7 @@ public class LocalUIFileManager implements IRemoteUIFileManager {
* org.eclipse.remote.core.IRemoteFileManager#browseDirectory(org.eclipse * org.eclipse.remote.core.IRemoteFileManager#browseDirectory(org.eclipse
* .swt.widgets.Shell, java.lang.String, java.lang.String) * .swt.widgets.Shell, java.lang.String, java.lang.String)
*/ */
@Override
public String browseDirectory(Shell shell, String message, String filterPath, int flags) { public String browseDirectory(Shell shell, String message, String filterPath, int flags) {
DirectoryDialog dialog = new DirectoryDialog(shell); DirectoryDialog dialog = new DirectoryDialog(shell);
dialog.setText(message); dialog.setText(message);
@ -54,6 +57,7 @@ public class LocalUIFileManager implements IRemoteUIFileManager {
* org.eclipse.remote.core.IRemoteFileManager#browseFile(org.eclipse * org.eclipse.remote.core.IRemoteFileManager#browseFile(org.eclipse
* .swt.widgets.Shell, java.lang.String, java.lang.String) * .swt.widgets.Shell, java.lang.String, java.lang.String)
*/ */
@Override
public String browseFile(Shell shell, String message, String filterPath, int flags) { public String browseFile(Shell shell, String message, String filterPath, int flags) {
FileDialog dialog = new FileDialog(shell, SWT.SINGLE); FileDialog dialog = new FileDialog(shell, SWT.SINGLE);
dialog.setText(message); dialog.setText(message);
@ -79,7 +83,8 @@ public class LocalUIFileManager implements IRemoteUIFileManager {
* org.eclipse.remote.core.IRemoteFileManager#browseFile(org.eclipse * org.eclipse.remote.core.IRemoteFileManager#browseFile(org.eclipse
* .swt.widgets.Shell, java.lang.String, java.lang.String) * .swt.widgets.Shell, java.lang.String, java.lang.String)
*/ */
public String[] browseFiles(Shell shell, String message, String filterPath, int flags) { @Override
public List<String> browseFiles(Shell shell, String message, String filterPath, int flags) {
FileDialog dialog = new FileDialog(shell, SWT.MULTI); FileDialog dialog = new FileDialog(shell, SWT.MULTI);
dialog.setText(message); dialog.setText(message);
if (filterPath != null) { if (filterPath != null) {
@ -94,7 +99,7 @@ public class LocalUIFileManager implements IRemoteUIFileManager {
return null; return null;
} }
return dialog.getFileNames(); return Arrays.asList(dialog.getFileNames());
} }
/* /*
@ -102,6 +107,7 @@ public class LocalUIFileManager implements IRemoteUIFileManager {
* *
* @see org.eclipse.remote.ui.IRemoteUIFileManager#getConnection() * @see org.eclipse.remote.ui.IRemoteUIFileManager#getConnection()
*/ */
@Override
public IRemoteConnection getConnection() { public IRemoteConnection getConnection() {
return connection; return connection;
} }
@ -113,6 +119,7 @@ public class LocalUIFileManager implements IRemoteUIFileManager {
* org.eclipse.remote.ui.IRemoteUIFileManager#setConnection(org.eclipse * org.eclipse.remote.ui.IRemoteUIFileManager#setConnection(org.eclipse
* .remote.core.IRemoteConnection) * .remote.core.IRemoteConnection)
*/ */
@Override
public void setConnection(IRemoteConnection connection) { public void setConnection(IRemoteConnection connection) {
this.connection = connection; this.connection = connection;
} }
@ -123,6 +130,7 @@ public class LocalUIFileManager implements IRemoteUIFileManager {
* @see * @see
* org.eclipse.remote.ui.IRemoteUIFileManager#showConnections(boolean) * org.eclipse.remote.ui.IRemoteUIFileManager#showConnections(boolean)
*/ */
@Override
public void showConnections(boolean enable) { public void showConnections(boolean enable) {
// Not implemented // Not implemented
} }

View file

@ -10,6 +10,8 @@
*******************************************************************************/ *******************************************************************************/
package org.eclipse.remote.ui; package org.eclipse.remote.ui;
import java.util.List;
import org.eclipse.remote.core.IRemoteConnection; import org.eclipse.remote.core.IRemoteConnection;
import org.eclipse.swt.widgets.Shell; import org.eclipse.swt.widgets.Shell;
@ -60,7 +62,7 @@ public interface IRemoteUIFileManager {
public String browseFile(Shell shell, String message, String initialPath, int flags); public String browseFile(Shell shell, String message, String initialPath, int flags);
/** /**
* Browse for a set of remote files. The return value is an array of paths * Browse for a set of remote files. The return value is a list of paths
* of the files <i>on the remote system</i>. * of the files <i>on the remote system</i>.
* *
* Equivalent to {@link org.eclipse.swt.widgets.FileDialog}. * Equivalent to {@link org.eclipse.swt.widgets.FileDialog}.
@ -74,10 +76,10 @@ public interface IRemoteUIFileManager {
* @param flags * @param flags
* options settings for dialog (@see IRemoteUIConstants) * options settings for dialog (@see IRemoteUIConstants)
* valid values are NONE, SAVE, or OPEN (@see IRemoteUIConstants) * valid values are NONE, SAVE, or OPEN (@see IRemoteUIConstants)
* @return the path to the file relative to the remote system or null if the * @return list of paths to the files relative to the remote system or null if the
* browser was cancelled * browser was cancelled
*/ */
public String[] browseFiles(Shell shell, String message, String initialPath, int flags); public List<String> browseFiles(Shell shell, String message, String initialPath, int flags);
/** /**
* Get the last connection that was selected in the browser. * Get the last connection that was selected in the browser.

View file

@ -10,17 +10,25 @@
*******************************************************************************/ *******************************************************************************/
package org.eclipse.remote.ui.dialogs; package org.eclipse.remote.ui.dialogs;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.List;
import org.eclipse.core.filesystem.IFileStore;
import org.eclipse.jface.dialogs.Dialog; import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.dialogs.IDialogConstants; import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.jface.operation.IRunnableContext;
import org.eclipse.jface.operation.IRunnableWithProgress;
import org.eclipse.jface.operation.ModalContext;
import org.eclipse.jface.viewers.ISelectionChangedListener;
import org.eclipse.jface.viewers.SelectionChangedEvent;
import org.eclipse.jface.wizard.ProgressMonitorPart;
import org.eclipse.remote.core.IRemoteConnection; import org.eclipse.remote.core.IRemoteConnection;
import org.eclipse.remote.core.IRemoteServices;
import org.eclipse.remote.internal.ui.messages.Messages; import org.eclipse.remote.internal.ui.messages.Messages;
import org.eclipse.remote.ui.widgets.RemoteResourceBrowserWidget; import org.eclipse.remote.ui.widgets.RemoteResourceBrowserWidget;
import org.eclipse.swt.SWT; import org.eclipse.swt.SWT;
import org.eclipse.swt.events.FocusEvent; import org.eclipse.swt.events.FocusEvent;
import org.eclipse.swt.events.FocusListener; import org.eclipse.swt.events.FocusListener;
import org.eclipse.swt.events.ModifyEvent;
import org.eclipse.swt.events.ModifyListener;
import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Button;
@ -34,7 +42,7 @@ import org.eclipse.swt.widgets.Shell;
* @author greg * @author greg
* *
*/ */
public class RemoteResourceBrowser extends Dialog { public class RemoteResourceBrowser extends Dialog implements IRunnableContext {
public final static String EMPTY_STRING = ""; //$NON-NLS-1$ public final static String EMPTY_STRING = ""; //$NON-NLS-1$
public final static int FILE_BROWSER = 0x01; public final static int FILE_BROWSER = 0x01;
public final static int DIRECTORY_BROWSER = 0x02; public final static int DIRECTORY_BROWSER = 0x02;
@ -44,7 +52,8 @@ public class RemoteResourceBrowser extends Dialog {
private final static int widthHint = 400; private final static int widthHint = 400;
private Button okButton; private Button okButton;
private RemoteResourceBrowserWidget fWidget; private RemoteResourceBrowserWidget fResourceBrowserWidget;
private ProgressMonitorPart fProgressMonitor;
private int browserType; private int browserType;
private String dialogTitle; private String dialogTitle;
@ -54,7 +63,7 @@ public class RemoteResourceBrowser extends Dialog {
private final IRemoteConnection fConnection; private final IRemoteConnection fConnection;
private int optionFlags = SINGLE; private int optionFlags = SINGLE;
public RemoteResourceBrowser(IRemoteServices services, IRemoteConnection conn, Shell parent, int flags) { public RemoteResourceBrowser(IRemoteConnection conn, Shell parent, int flags) {
super(parent); super(parent);
setShellStyle(SWT.RESIZE | getShellStyle()); setShellStyle(SWT.RESIZE | getShellStyle());
fConnection = conn; fConnection = conn;
@ -66,6 +75,10 @@ public class RemoteResourceBrowser extends Dialog {
setType(FILE_BROWSER); setType(FILE_BROWSER);
} }
public RemoteResourceBrowser(Shell parent, int flags) {
this(null, parent, flags);
}
/* /*
* (non-Javadoc) * (non-Javadoc)
* *
@ -94,10 +107,10 @@ public class RemoteResourceBrowser extends Dialog {
Control contents = super.createContents(parent); Control contents = super.createContents(parent);
setTitle(dialogTitle); setTitle(dialogTitle);
if (!showConnections) { if (!showConnections) {
fWidget.setConnection(fConnection); fResourceBrowserWidget.setConnection(fConnection);
} }
if (fInitialPath != null) { if (fInitialPath != null) {
fWidget.setInitialPath(fInitialPath); fResourceBrowserWidget.setInitialPath(fInitialPath);
} }
updateDialog(); updateDialog();
return contents; return contents;
@ -113,7 +126,7 @@ public class RemoteResourceBrowser extends Dialog {
@Override @Override
protected Control createDialogArea(Composite parent) { protected Control createDialogArea(Composite parent) {
Composite main = (Composite) super.createDialogArea(parent); Composite main = (Composite) super.createDialogArea(parent);
GridData gd = new GridData(SWT.FILL, SWT.TOP, true, true); GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true);
gd.widthHint = widthHint; gd.widthHint = widthHint;
main.setLayoutData(gd); main.setLayoutData(gd);
main.setLayout(new GridLayout(1, true)); main.setLayout(new GridLayout(1, true));
@ -130,14 +143,14 @@ public class RemoteResourceBrowser extends Dialog {
style = SWT.MULTI; style = SWT.MULTI;
} }
fWidget = new RemoteResourceBrowserWidget(main, style, options); fResourceBrowserWidget = new RemoteResourceBrowserWidget(main, style, options);
fWidget.addModifyListener(new ModifyListener() { fResourceBrowserWidget.addSelectionChangedListener(new ISelectionChangedListener() {
@Override @Override
public void modifyText(ModifyEvent e) { public void selectionChanged(SelectionChangedEvent event) {
updateDialog(); updateDialog();
} }
}); });
fWidget.addFocusListener(new FocusListener() { fResourceBrowserWidget.addFocusListener(new FocusListener() {
@Override @Override
public void focusGained(FocusEvent e) { public void focusGained(FocusEvent e) {
getShell().setDefaultButton(null); // allow text widget to receive SWT.DefaultSelection event getShell().setDefaultButton(null); // allow text widget to receive SWT.DefaultSelection event
@ -148,7 +161,21 @@ public class RemoteResourceBrowser extends Dialog {
getShell().setDefaultButton(okButton); getShell().setDefaultButton(okButton);
} }
}); });
fWidget.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, true)); fResourceBrowserWidget.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
Composite monitorComposite = new Composite(main, SWT.NULL);
GridLayout layout = new GridLayout();
layout.marginHeight = 0;
layout.marginWidth = 0;
layout.numColumns = 2;
monitorComposite.setLayout(layout);
monitorComposite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
fProgressMonitor = new ProgressMonitorPart(monitorComposite, new GridLayout(), true);
GridData gridData = new GridData(SWT.FILL, SWT.TOP, true, true);
fProgressMonitor.setLayoutData(gridData);
monitorComposite.setVisible(false);
fResourceBrowserWidget.setRunnableContext(this);
return main; return main;
} }
@ -159,34 +186,52 @@ public class RemoteResourceBrowser extends Dialog {
* @return selected connection * @return selected connection
*/ */
public IRemoteConnection getConnection() { public IRemoteConnection getConnection() {
if (fWidget != null) { if (fResourceBrowserWidget != null) {
return fWidget.getConnection(); return fResourceBrowserWidget.getConnection();
} }
return null; return null;
} }
/** /**
* Get the path that was selected. * Get the resources that was selected.
* *
* @return selected path * @return selected resource or null if no resource is selected
*/ */
public String getPath() { public IFileStore getResource() {
if (fWidget != null && fWidget.getPaths().size() > 0) { if (fResourceBrowserWidget != null && fResourceBrowserWidget.getResources().size() > 0) {
return fWidget.getPaths().get(0); return fResourceBrowserWidget.getResources().get(0);
} }
return null; return null;
} }
/** /**
* Get the paths that were selected. * Get the resources that were selected.
* *
* @return selected paths * @return selected resources
*/ */
public String[] getPaths() { public List<IFileStore> getResources() {
if (fWidget != null) { if (fResourceBrowserWidget != null) {
return fWidget.getPaths().toArray(new String[0]); return fResourceBrowserWidget.getResources();
}
return new ArrayList<IFileStore>();
}
/*
* (non-Javadoc)
*
* @see org.eclipse.jface.operation.IRunnableContext#run(boolean, boolean, org.eclipse.jface.operation.IRunnableWithProgress)
*/
@Override
public void run(boolean fork, boolean cancelable, IRunnableWithProgress runnable) throws InvocationTargetException,
InterruptedException {
fProgressMonitor.attachToCancelComponent(null);
fProgressMonitor.getParent().setVisible(true);
try {
ModalContext.run(runnable, fork, fProgressMonitor, getShell().getDisplay());
} finally {
fProgressMonitor.getParent().setVisible(false);
fProgressMonitor.removeFromCancelComponent(null);
} }
return null;
} }
/** /**
@ -241,8 +286,7 @@ public class RemoteResourceBrowser extends Dialog {
private void updateDialog() { private void updateDialog() {
if (okButton != null) { if (okButton != null) {
String path = getPath(); okButton.setEnabled(getConnection() != null && getResource() != null);
okButton.setEnabled(getConnection() != null && path != null && !path.equals(EMPTY_STRING));
} }
} }
} }

View file

@ -92,12 +92,14 @@ public class RemoteConnectionWidget extends Composite {
listenerEnabled = enabled; listenerEnabled = enabled;
} }
@Override
public void widgetDefaultSelected(SelectionEvent e) { public void widgetDefaultSelected(SelectionEvent e) {
if (isEnabled()) { if (isEnabled()) {
widgetSelected(e); widgetSelected(e);
} }
} }
@Override
public void widgetSelected(SelectionEvent e) { public void widgetSelected(SelectionEvent e) {
if (isEnabled()) { if (isEnabled()) {
Object source = e.getSource(); Object source = e.getSource();
@ -150,6 +152,22 @@ public class RemoteConnectionWidget extends Composite {
private final ListenerList fSelectionListeners = new ListenerList(); private final ListenerList fSelectionListeners = new ListenerList();
private final WidgetListener fWidgetListener = new WidgetListener(); private final WidgetListener fWidgetListener = new WidgetListener();
/**
* Constructor
*
* @param parent
* parent composite
* @param style
* style or SWT.NONE
* @param title
* if a title is supplied then the widget will be placed in a group. Can be null.
* @param flags
* a combination of flags that modify the behavior of the widget.
*/
public RemoteConnectionWidget(Composite parent, int style, String title, int flags) {
this(parent, style, title, flags, null);
}
/** /**
* Constructor * Constructor
* *
@ -163,7 +181,6 @@ public class RemoteConnectionWidget extends Composite {
* a combination of flags that modify the behavior of the widget. * a combination of flags that modify the behavior of the widget.
* @param context * @param context
* runnable context, or null * runnable context, or null
* @since 7.0
*/ */
public RemoteConnectionWidget(Composite parent, int style, String title, int flags, IRunnableContext context) { public RemoteConnectionWidget(Composite parent, int style, String title, int flags, IRunnableContext context) {
super(parent, style); super(parent, style);

View file

@ -23,6 +23,8 @@ import org.eclipse.core.runtime.ListenerList;
import org.eclipse.core.runtime.Path; import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.SubMonitor; import org.eclipse.core.runtime.SubMonitor;
import org.eclipse.jface.dialogs.ErrorDialog; import org.eclipse.jface.dialogs.ErrorDialog;
import org.eclipse.jface.dialogs.ProgressMonitorDialog;
import org.eclipse.jface.operation.IRunnableContext;
import org.eclipse.jface.operation.IRunnableWithProgress; import org.eclipse.jface.operation.IRunnableWithProgress;
import org.eclipse.jface.viewers.DoubleClickEvent; import org.eclipse.jface.viewers.DoubleClickEvent;
import org.eclipse.jface.viewers.IDoubleClickListener; import org.eclipse.jface.viewers.IDoubleClickListener;
@ -48,8 +50,6 @@ import org.eclipse.remote.internal.ui.messages.Messages;
import org.eclipse.remote.ui.IRemoteUIConnectionManager; import org.eclipse.remote.ui.IRemoteUIConnectionManager;
import org.eclipse.remote.ui.RemoteUIServices; import org.eclipse.remote.ui.RemoteUIServices;
import org.eclipse.swt.SWT; import org.eclipse.swt.SWT;
import org.eclipse.swt.events.ModifyEvent;
import org.eclipse.swt.events.ModifyListener;
import org.eclipse.swt.events.SelectionAdapter; import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent; import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridData;
@ -59,7 +59,6 @@ import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label; import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell; import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text; import org.eclipse.swt.widgets.Text;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.model.WorkbenchLabelProvider; import org.eclipse.ui.model.WorkbenchLabelProvider;
/** /**
@ -90,8 +89,6 @@ public class RemoteResourceBrowserWidget extends Composite {
*/ */
public static final int SHOW_CONNECTIONS = 0x40; public static final int SHOW_CONNECTIONS = 0x40;
private static final String EMPTY_STRING = ""; //$NON-NLS-1$
private static final int minimumWidth = 200; private static final int minimumWidth = 200;
private static final int heightHint = 300; private static final int heightHint = 300;
@ -105,16 +102,18 @@ public class RemoteResourceBrowserWidget extends Composite {
private String dialogLabel; private String dialogLabel;
private boolean showHidden; private boolean showHidden;
private final List<String> remotePaths = new ArrayList<String>(); private final List<IFileStore> fResources = new ArrayList<IFileStore>();
private String fInitialPath; private String fInitialPath;
private IPath fRootPath; private IPath fRootPath;
private IRemoteFileManager fFileMgr; private IRemoteFileManager fFileMgr;
private IRemoteConnection fConnection; private IRemoteConnection fConnection;
private final ListenerList fModifyListeners = new ListenerList(); private final ListenerList fSelectionListeners = new ListenerList();
private int optionFlags = FILE_BROWSER | SHOW_HIDDEN_CHECKBOX | SHOW_NEW_FOLDER_BUTTON; private int optionFlags = FILE_BROWSER | SHOW_HIDDEN_CHECKBOX | SHOW_NEW_FOLDER_BUTTON;
private IRunnableContext fRunnableContext;
public RemoteResourceBrowserWidget(Composite parent, int style, int flags) { public RemoteResourceBrowserWidget(Composite parent, int style, int flags) {
super(parent, style); super(parent, style);
setTitle(Messages.RemoteResourceBrowser_resourceTitle); setTitle(Messages.RemoteResourceBrowser_resourceTitle);
@ -131,20 +130,26 @@ public class RemoteResourceBrowserWidget extends Composite {
setLayout(layout); setLayout(layout);
final Composite mainComp = new Composite(this, SWT.NONE); final Composite mainComp = new Composite(this, SWT.NONE);
mainComp.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, true)); mainComp.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
layout = new GridLayout(); layout = new GridLayout();
layout.numColumns = 4; layout.numColumns = 4;
mainComp.setLayout(layout); mainComp.setLayout(layout);
if ((optionFlags & SHOW_CONNECTIONS) != 0) { if ((optionFlags & SHOW_CONNECTIONS) != 0) {
fRemoteConnectionWidget = new RemoteConnectionWidget(mainComp, SWT.NONE, null, fRemoteConnectionWidget = new RemoteConnectionWidget(mainComp, SWT.NONE, null,
RemoteConnectionWidget.FLAG_NO_LOCAL_SELECTION, null); RemoteConnectionWidget.FLAG_NO_LOCAL_SELECTION);
fRemoteConnectionWidget.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 4, 1)); fRemoteConnectionWidget.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 4, 1));
fRemoteConnectionWidget.addSelectionListener(new SelectionAdapter() { fRemoteConnectionWidget.addSelectionListener(new SelectionAdapter() {
@Override @Override
public void widgetSelected(SelectionEvent event) { public void widgetSelected(SelectionEvent event) {
connectionSelected(); connectionSelected();
updateEnablement(); updateEnablement();
notifySelectionChangedListeners(new SelectionChangedEvent(treeViewer, new ISelection() {
@Override
public boolean isEmpty() {
return true;
}
}));
} }
}); });
} }
@ -154,25 +159,12 @@ public class RemoteResourceBrowserWidget extends Composite {
label.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false)); label.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false));
remotePathText = new Text(mainComp, SWT.BORDER | SWT.SINGLE); remotePathText = new Text(mainComp, SWT.BORDER | SWT.SINGLE);
remotePathText.addModifyListener(new ModifyListener() {
@Override
public void modifyText(ModifyEvent e) {
if (remotePaths.size() == 0) {
remotePaths.add(remotePathText.getText());
} else {
remotePaths.set(0, remotePathText.getText());
}
notifyListeners(e);
updateEnablement();
}
});
remotePathText.addSelectionListener(new SelectionAdapter() { remotePathText.addSelectionListener(new SelectionAdapter() {
@Override @Override
public void widgetDefaultSelected(SelectionEvent e) { public void widgetDefaultSelected(SelectionEvent e) {
remotePathText.setSelection(remotePathText.getText().length()); remotePathText.setSelection(remotePathText.getText().length());
setRoot(remotePathText.getText()); setRoot(remotePathText.getText());
} }
}); });
GridData gd = new GridData(SWT.FILL, SWT.CENTER, true, false); GridData gd = new GridData(SWT.FILL, SWT.CENTER, true, false);
gd.minimumWidth = minimumWidth; gd.minimumWidth = minimumWidth;
@ -261,7 +253,7 @@ public class RemoteResourceBrowserWidget extends Composite {
// see bug 158380 // see bug 158380
gd.heightHint = Math.max(parent.getSize().y, heightHint); gd.heightHint = Math.max(parent.getSize().y, heightHint);
treeViewer.getTree().setLayoutData(gd); treeViewer.getTree().setLayoutData(gd);
// treeViewer.setUseHashlookup(true); treeViewer.setUseHashlookup(true);
treeViewer.setComparer(new DeferredFileStoreComparer()); treeViewer.setComparer(new DeferredFileStoreComparer());
treeViewer.setComparator(new RemoteResourceComparator()); treeViewer.setComparator(new RemoteResourceComparator());
treeViewer.setContentProvider(new RemoteContentProvider()); treeViewer.setContentProvider(new RemoteContentProvider());
@ -272,17 +264,18 @@ public class RemoteResourceBrowserWidget extends Composite {
ISelection selection = event.getSelection(); ISelection selection = event.getSelection();
if (!selection.isEmpty() && selection instanceof IStructuredSelection) { if (!selection.isEmpty() && selection instanceof IStructuredSelection) {
IStructuredSelection ss = (IStructuredSelection) selection; IStructuredSelection ss = (IStructuredSelection) selection;
remotePaths.clear(); fResources.clear();
for (Object currentSelection : ss.toArray()) { for (Object currentSelection : ss.toArray()) {
if (currentSelection instanceof DeferredFileStore) { if (currentSelection instanceof DeferredFileStore) {
String path = ((DeferredFileStore) currentSelection).getFileStore().toURI().getPath(); IFileStore store = ((DeferredFileStore) currentSelection).getFileStore();
remotePaths.add(path); fResources.add(store);
} }
} }
if (remotePaths.size() > 0) { if (fResources.size() > 0) {
remotePathText.setText(remotePaths.get(0)); remotePathText.setText(fResources.get(0).toURI().getPath());
} }
updateEnablement(); updateEnablement();
notifySelectionChangedListeners(event);
} }
} }
}); });
@ -326,13 +319,13 @@ public class RemoteResourceBrowserWidget extends Composite {
} }
/** /**
* Add a listener that will be notified when the directory path is modified. * Add a listener that will be notified when the selection is changed.
* *
* @param listener * @param listener
* listener to add * listener to add
*/ */
public void addModifyListener(ModifyListener listener) { public void addSelectionChangedListener(ISelectionChangedListener listener) {
fModifyListeners.add(listener); fSelectionListeners.add(listener);
} }
/** /**
@ -348,7 +341,7 @@ public class RemoteResourceBrowserWidget extends Composite {
} }
IRemoteUIConnectionManager uiMgr = RemoteUIServices.getRemoteUIServices(conn.getRemoteServices()).getUIConnectionManager(); IRemoteUIConnectionManager uiMgr = RemoteUIServices.getRemoteUIServices(conn.getRemoteServices()).getUIConnectionManager();
if (uiMgr != null) { if (uiMgr != null) {
uiMgr.openConnectionWithProgress(getShell(), null, conn); uiMgr.openConnectionWithProgress(getShell(), getRunnableContext(), conn);
} }
if (!conn.isOpen()) { if (!conn.isOpen()) {
return false; return false;
@ -374,11 +367,6 @@ public class RemoteResourceBrowserWidget extends Composite {
return false; return false;
} }
public void setConnection(IRemoteConnection connection) {
changeInput(connection);
updateEnablement();
}
/** /**
* When a new connection is selected, make sure it is open before using it. * When a new connection is selected, make sure it is open before using it.
*/ */
@ -403,7 +391,7 @@ public class RemoteResourceBrowserWidget extends Composite {
final String[] name = new String[1]; final String[] name = new String[1];
name[0] = null; name[0] = null;
try { try {
PlatformUI.getWorkbench().getProgressService().busyCursorWhile(new IRunnableWithProgress() { IRunnableWithProgress runnable = new IRunnableWithProgress() {
@Override @Override
public void run(IProgressMonitor monitor) { public void run(IProgressMonitor monitor) {
SubMonitor progress = SubMonitor.convert(monitor, 10); SubMonitor progress = SubMonitor.convert(monitor, 10);
@ -425,13 +413,12 @@ public class RemoteResourceBrowserWidget extends Composite {
Messages.RemoteResourceBrowserWidget_Unable_to_create_new_folder, e.getStatus()); Messages.RemoteResourceBrowserWidget_Unable_to_create_new_folder, e.getStatus());
} }
} }
}); };
getRunnableContext().run(true, true, runnable);
} catch (InvocationTargetException e) { } catch (InvocationTargetException e) {
// TODO Auto-generated catch block // Ignore, return null
e.printStackTrace();
} catch (InterruptedException e) { } catch (InterruptedException e) {
// TODO Auto-generated catch block // Ignore, return null
e.printStackTrace();
} }
return name[0]; return name[0];
} }
@ -468,29 +455,40 @@ public class RemoteResourceBrowserWidget extends Composite {
} }
/** /**
* Get the paths that were selected. * Get the resources that were selected.
* *
* @return selected paths * @return selected resources
*/ */
public List<String> getPaths() { public List<IFileStore> getResources() {
return remotePaths; return fResources;
} }
private void notifyListeners(ModifyEvent e) { public IRunnableContext getRunnableContext() {
for (Object listener : fModifyListeners.getListeners()) { if (fRunnableContext == null) {
((ModifyListener) listener).modifyText(e); return new ProgressMonitorDialog(getShell());
}
return fRunnableContext;
}
private void notifySelectionChangedListeners(SelectionChangedEvent e) {
for (Object listener : fSelectionListeners.getListeners()) {
((ISelectionChangedListener) listener).selectionChanged(e);
} }
} }
/** /**
* Remove a listener that will be notified when the directory path is * Remove a listener that will be notified when the selection is changed
* modified.
* *
* @param listener * @param listener
* listener to remove * listener to remove
*/ */
public void removeModifyListener(ModifyListener listener) { public void removeSelectionChangedListener(ISelectionChangedListener listener) {
fModifyListeners.remove(listener); fSelectionListeners.remove(listener);
}
public void setConnection(IRemoteConnection connection) {
changeInput(connection);
updateEnablement();
} }
/** /**
@ -518,10 +516,16 @@ public class RemoteResourceBrowserWidget extends Composite {
treeViewer.setInput(new DeferredFileStore(root, !showHidden)); treeViewer.setInput(new DeferredFileStore(root, !showHidden));
remotePathText.setText(path); remotePathText.setText(path);
remotePathText.setSelection(remotePathText.getText().length()); remotePathText.setSelection(remotePathText.getText().length());
fResources.clear();
fResources.add(root);
fRootPath = new Path(path); fRootPath = new Path(path);
} }
} }
public void setRunnableContext(IRunnableContext context) {
fRunnableContext = context;
}
/** /**
* Set the dialogTitle of the dialog. * Set the dialogTitle of the dialog.
* *
@ -540,16 +544,20 @@ public class RemoteResourceBrowserWidget extends Composite {
/** /**
* Set the type of browser. Can be either a file browser (allows selection * Set the type of browser. Can be either a file browser (allows selection
* of files) or a directory browser (allows selection of directories), or * of files only) or a directory browser (allows selection of directories only), or
* both. * both files and directories.
*/ */
public void setType() { public void setType() {
if ((optionFlags & FILE_BROWSER) == FILE_BROWSER) { if ((optionFlags & DIRECTORY_BROWSER) == 0) {
dialogLabel = Messages.RemoteResourceBrowser_fileLabel; dialogLabel = Messages.RemoteResourceBrowser_fileLabel;
setTitle(Messages.RemoteResourceBrowser_fileTitle); setTitle(Messages.RemoteResourceBrowser_fileTitle);
} else { } else if ((optionFlags & FILE_BROWSER) == 0) {
dialogLabel = Messages.RemoteResourceBrowser_directoryLabel; dialogLabel = Messages.RemoteResourceBrowser_directoryLabel;
setTitle(Messages.RemoteResourceBrowser_directoryTitle); setTitle(Messages.RemoteResourceBrowser_directoryTitle);
} else {
dialogLabel = Messages.RemoteResourceBrowser_resourceLabel;
setTitle(Messages.RemoteResourceBrowser_resourceTitle);
} }
} }
@ -558,16 +566,17 @@ public class RemoteResourceBrowserWidget extends Composite {
boolean newFolderEnabled = false; boolean newFolderEnabled = false;
if (fConnection != null && fConnection.isOpen()) { if (fConnection != null && fConnection.isOpen()) {
if (remotePaths.size() == 1) { if (fResources.size() == 1) {
String pathText = remotePaths.get(0); IFileStore store = fResources.get(0);
if (!pathText.equals(EMPTY_STRING)) { /*
if (fConnection.getFileManager().getResource(pathText).fetchInfo().isDirectory()) { * Assume that we have already called fetchInfo() on the file store, so this should
newFolderEnabled = true; * effectively be a noop.
} */
IPath path = new Path(pathText); if (store.fetchInfo().isDirectory()) {
if (!path.isRoot()) { newFolderEnabled = true;
upEnabled = true; }
} if (store.getParent() != null) {
upEnabled = true;
} }
} }
} }