From ec0d118e2332e77f319bc12300981151051602b1 Mon Sep 17 00:00:00 2001 From: Greg Watson Date: Mon, 27 Jan 2014 16:48:38 -0500 Subject: [PATCH] Allow local file/directory selection to be enabled on the resource browser. Signed-off-by: Greg Watson --- .../ui/dialogs/RemoteResourceBrowser.java | 13 ++++++++++++ .../widgets/RemoteResourceBrowserWidget.java | 20 +++++++++++++------ 2 files changed, 27 insertions(+), 6 deletions(-) diff --git a/bundles/org.eclipse.remote.ui/src/org/eclipse/remote/ui/dialogs/RemoteResourceBrowser.java b/bundles/org.eclipse.remote.ui/src/org/eclipse/remote/ui/dialogs/RemoteResourceBrowser.java index 9d665366629..118632e87f8 100644 --- a/bundles/org.eclipse.remote.ui/src/org/eclipse/remote/ui/dialogs/RemoteResourceBrowser.java +++ b/bundles/org.eclipse.remote.ui/src/org/eclipse/remote/ui/dialogs/RemoteResourceBrowser.java @@ -66,6 +66,7 @@ public class RemoteResourceBrowser extends Dialog implements IRunnableContext { private boolean fShowHiddenCheckbox = true; private boolean fShowNewFolderButton = true; private boolean fShowConnections = false; + private boolean fShowLocalSelection = false; private String fInitialPath; private IRemoteConnection fConnection; private int fBrowserStyle = SWT.SINGLE; @@ -157,6 +158,9 @@ public class RemoteResourceBrowser extends Dialog implements IRunnableContext { if (fShowNewFolderButton) { options |= RemoteResourceBrowserWidget.SHOW_NEW_FOLDER_BUTTON; } + if (fShowLocalSelection) { + options |= RemoteResourceBrowserWidget.SHOW_LOCAL_SELECTION; + } fResourceBrowserWidget = new RemoteResourceBrowserWidget(main, fBrowserStyle, options); fResourceBrowserWidget.addSelectionChangedListener(new ISelectionChangedListener() { @Override @@ -314,6 +318,15 @@ public class RemoteResourceBrowser extends Dialog implements IRunnableContext { fShowHiddenCheckbox = showHidden; } + /** + * Enable selection of local files + * + * @param showNewFolderButton + */ + public void showLocalSelection(boolean showLocalSelection) { + fShowLocalSelection = showLocalSelection; + } + /** * Enable a button to create new folders (default enabled) * diff --git a/bundles/org.eclipse.remote.ui/src/org/eclipse/remote/ui/widgets/RemoteResourceBrowserWidget.java b/bundles/org.eclipse.remote.ui/src/org/eclipse/remote/ui/widgets/RemoteResourceBrowserWidget.java index efa383ca630..76ced9fce6f 100644 --- a/bundles/org.eclipse.remote.ui/src/org/eclipse/remote/ui/widgets/RemoteResourceBrowserWidget.java +++ b/bundles/org.eclipse.remote.ui/src/org/eclipse/remote/ui/widgets/RemoteResourceBrowserWidget.java @@ -76,6 +76,10 @@ public class RemoteResourceBrowserWidget extends Composite { * Browse for directories (files are not shown) */ public static final int DIRECTORY_BROWSER = 0x02; + /** + * Show local selection button + */ + public static final int SHOW_LOCAL_SELECTION = 0x04; /** * Display checkbox to show/hide hidden files */ @@ -136,7 +140,7 @@ public class RemoteResourceBrowserWidget extends Composite { if ((fOptionFlags & SHOW_CONNECTIONS) != 0) { fRemoteConnectionWidget = new RemoteConnectionWidget(mainComp, SWT.NONE, "", //$NON-NLS-1$ - RemoteConnectionWidget.FLAG_NO_LOCAL_SELECTION); + (fOptionFlags & SHOW_LOCAL_SELECTION) == 0 ? RemoteConnectionWidget.FLAG_NO_LOCAL_SELECTION : 0); fRemoteConnectionWidget.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false)); fRemoteConnectionWidget.addSelectionListener(new SelectionAdapter() { @Override @@ -345,7 +349,8 @@ public class RemoteResourceBrowserWidget extends Composite { */ private boolean changeInput(final IRemoteConnection conn) { if (conn == null) { - return false; + setRoot(null); + return true; } IRemoteUIConnectionManager uiMgr = RemoteUIServices.getRemoteUIServices(conn.getRemoteServices()).getUIConnectionManager(); if (uiMgr != null) { @@ -521,18 +526,21 @@ public class RemoteResourceBrowserWidget extends Composite { /** * Set the root directory for the browser. This will also update the text - * field with the path. + * field with the path. If the path is null, the browser will be set to the initial state. * * @param path - * path of root directory + * path of root directory or null */ private void setRoot(String path) { - if (fFileMgr != null) { + fResources.clear(); + fRootPath = null; + if (path == null) { + fTreeViewer.setInput(null); + } else if (fFileMgr != null) { IFileStore root = fFileMgr.getResource(path); fTreeViewer.setInput(new DeferredFileStore(root, !fShowHidden)); fRemotePathText.setText(path); fRemotePathText.setSelection(fRemotePathText.getText().length()); - fResources.clear(); fResources.add(root); fRootPath = new Path(path); }