1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-06-08 18:26: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;
import java.util.ArrayList;
import java.util.List;
import org.eclipse.core.filesystem.IFileStore;
import org.eclipse.jface.window.Window;
import org.eclipse.remote.core.IRemoteConnection;
import org.eclipse.remote.core.IRemoteServices;
import org.eclipse.remote.ui.IRemoteUIFileManager;
import org.eclipse.remote.ui.dialogs.RemoteResourceBrowser;
import org.eclipse.swt.widgets.Shell;
public class JSchUIFileManager implements IRemoteUIFileManager {
private IRemoteServices services = null;
private IRemoteConnection connection = null;
private boolean showConnections = false;
public JSchUIFileManager(IRemoteServices services) {
this.services = services;
}
/*
* (non-Javadoc)
*
@ -33,8 +31,9 @@ public class JSchUIFileManager implements IRemoteUIFileManager {
* org.eclipse.ptp.remote.core.IRemoteFileManager#browseDirectory(org.eclipse
* .swt.widgets.Shell, java.lang.String, java.lang.String)
*/
@Override
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.setInitialPath(filterPath);
browser.setTitle(message);
@ -43,11 +42,11 @@ public class JSchUIFileManager implements IRemoteUIFileManager {
return null;
}
connection = browser.getConnection();
String path = browser.getPath();
if (path == null) {
IFileStore resource = browser.getResource();
if (resource == 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
* .swt.widgets.Shell, java.lang.String, java.lang.String)
*/
@Override
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.setInitialPath(filterPath);
browser.setTitle(message);
@ -67,11 +67,11 @@ public class JSchUIFileManager implements IRemoteUIFileManager {
return null;
}
connection = browser.getConnection();
String path = browser.getPath();
if (path == null) {
IFileStore resource = browser.getResource();
if (resource == 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
* .swt.widgets.Shell, java.lang.String, java.lang.String)
*/
public String[] browseFiles(Shell shell, String message, String filterPath, int flags) {
RemoteResourceBrowser browser = new RemoteResourceBrowser(services, connection, shell, RemoteResourceBrowser.MULTI);
@Override
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.setInitialPath(filterPath);
browser.setTitle(message);
@ -91,11 +92,11 @@ public class JSchUIFileManager implements IRemoteUIFileManager {
return null;
}
connection = browser.getConnection();
String path[] = browser.getPaths();
if (path == null) {
return null;
List<String> paths = new ArrayList<String>();
for (IFileStore store : browser.getResources()) {
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()
*/
@Override
public IRemoteConnection getConnection() {
return connection;
}
@ -114,6 +116,7 @@ public class JSchUIFileManager implements IRemoteUIFileManager {
* org.eclipse.ptp.remote.ui.IRemoteUIFileManager#setConnection(org.eclipse
* .ptp.remote.core.IRemoteConnection)
*/
@Override
public void setConnection(IRemoteConnection connection) {
this.connection = connection;
}
@ -124,6 +127,7 @@ public class JSchUIFileManager implements IRemoteUIFileManager {
* @see
* org.eclipse.ptp.remote.ui.IRemoteUIFileManager#showConnections(boolean)
*/
@Override
public void showConnections(boolean enable) {
showConnections = enable;
}

View file

@ -41,6 +41,7 @@ public class JSchUIServices implements IRemoteUIServices {
*
* @see org.eclipse.ptp.remote.ui.IRemoteUIServicesDescriptor#getId()
*/
@Override
public String getId() {
return fServices.getId();
}
@ -50,6 +51,7 @@ public class JSchUIServices implements IRemoteUIServices {
*
* @see org.eclipse.ptp.remote.ui.IRemoteUIServicesDescriptor#getName()
*/
@Override
public String getName() {
return fServices.getName();
}
@ -59,6 +61,7 @@ public class JSchUIServices implements IRemoteUIServices {
*
* @see org.eclipse.ptp.remote.ui.IRemoteUIServicesDescriptor#getUIConnectionManager()
*/
@Override
public IRemoteUIConnectionManager getUIConnectionManager() {
return new JSchUIConnectionManager(fServices);
}
@ -68,7 +71,8 @@ public class JSchUIServices implements IRemoteUIServices {
*
* @see org.eclipse.ptp.remote.ui.IRemoteUIServicesDescriptor#getUIFileManager()
*/
@Override
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_fileTitle=Browse File
RemoteResourceBrowser_directoryTitle=Browse Directory
RemoteResourceBrowser_resourceLabel=Select resource:
RemoteResourceBrowser_resourceLabel=Selected resource:
RemoteResourceBrowser_fileLabel=Selected file:
RemoteResourceBrowser_directoryLabel=Selected directory:
RemoteResourceBrowser_connectonLabel=Connection:

View file

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

View file

@ -10,6 +10,8 @@
*******************************************************************************/
package org.eclipse.remote.ui;
import java.util.List;
import org.eclipse.remote.core.IRemoteConnection;
import org.eclipse.swt.widgets.Shell;
@ -60,7 +62,7 @@ public interface IRemoteUIFileManager {
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>.
*
* Equivalent to {@link org.eclipse.swt.widgets.FileDialog}.
@ -74,10 +76,10 @@ public interface IRemoteUIFileManager {
* @param flags
* options settings for dialog (@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
*/
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.

View file

@ -10,17 +10,25 @@
*******************************************************************************/
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.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.IRemoteServices;
import org.eclipse.remote.internal.ui.messages.Messages;
import org.eclipse.remote.ui.widgets.RemoteResourceBrowserWidget;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.FocusEvent;
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.GridLayout;
import org.eclipse.swt.widgets.Button;
@ -34,7 +42,7 @@ import org.eclipse.swt.widgets.Shell;
* @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 int FILE_BROWSER = 0x01;
public final static int DIRECTORY_BROWSER = 0x02;
@ -44,7 +52,8 @@ public class RemoteResourceBrowser extends Dialog {
private final static int widthHint = 400;
private Button okButton;
private RemoteResourceBrowserWidget fWidget;
private RemoteResourceBrowserWidget fResourceBrowserWidget;
private ProgressMonitorPart fProgressMonitor;
private int browserType;
private String dialogTitle;
@ -54,7 +63,7 @@ public class RemoteResourceBrowser extends Dialog {
private final IRemoteConnection fConnection;
private int optionFlags = SINGLE;
public RemoteResourceBrowser(IRemoteServices services, IRemoteConnection conn, Shell parent, int flags) {
public RemoteResourceBrowser(IRemoteConnection conn, Shell parent, int flags) {
super(parent);
setShellStyle(SWT.RESIZE | getShellStyle());
fConnection = conn;
@ -66,6 +75,10 @@ public class RemoteResourceBrowser extends Dialog {
setType(FILE_BROWSER);
}
public RemoteResourceBrowser(Shell parent, int flags) {
this(null, parent, flags);
}
/*
* (non-Javadoc)
*
@ -94,10 +107,10 @@ public class RemoteResourceBrowser extends Dialog {
Control contents = super.createContents(parent);
setTitle(dialogTitle);
if (!showConnections) {
fWidget.setConnection(fConnection);
fResourceBrowserWidget.setConnection(fConnection);
}
if (fInitialPath != null) {
fWidget.setInitialPath(fInitialPath);
fResourceBrowserWidget.setInitialPath(fInitialPath);
}
updateDialog();
return contents;
@ -113,7 +126,7 @@ public class RemoteResourceBrowser extends Dialog {
@Override
protected Control createDialogArea(Composite 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;
main.setLayoutData(gd);
main.setLayout(new GridLayout(1, true));
@ -130,14 +143,14 @@ public class RemoteResourceBrowser extends Dialog {
style = SWT.MULTI;
}
fWidget = new RemoteResourceBrowserWidget(main, style, options);
fWidget.addModifyListener(new ModifyListener() {
fResourceBrowserWidget = new RemoteResourceBrowserWidget(main, style, options);
fResourceBrowserWidget.addSelectionChangedListener(new ISelectionChangedListener() {
@Override
public void modifyText(ModifyEvent e) {
public void selectionChanged(SelectionChangedEvent event) {
updateDialog();
}
});
fWidget.addFocusListener(new FocusListener() {
fResourceBrowserWidget.addFocusListener(new FocusListener() {
@Override
public void focusGained(FocusEvent e) {
getShell().setDefaultButton(null); // allow text widget to receive SWT.DefaultSelection event
@ -148,7 +161,21 @@ public class RemoteResourceBrowser extends Dialog {
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;
}
@ -159,34 +186,52 @@ public class RemoteResourceBrowser extends Dialog {
* @return selected connection
*/
public IRemoteConnection getConnection() {
if (fWidget != null) {
return fWidget.getConnection();
if (fResourceBrowserWidget != null) {
return fResourceBrowserWidget.getConnection();
}
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() {
if (fWidget != null && fWidget.getPaths().size() > 0) {
return fWidget.getPaths().get(0);
public IFileStore getResource() {
if (fResourceBrowserWidget != null && fResourceBrowserWidget.getResources().size() > 0) {
return fResourceBrowserWidget.getResources().get(0);
}
return null;
}
/**
* Get the paths that were selected.
* Get the resources that were selected.
*
* @return selected paths
* @return selected resources
*/
public String[] getPaths() {
if (fWidget != null) {
return fWidget.getPaths().toArray(new String[0]);
public List<IFileStore> getResources() {
if (fResourceBrowserWidget != null) {
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() {
if (okButton != null) {
String path = getPath();
okButton.setEnabled(getConnection() != null && path != null && !path.equals(EMPTY_STRING));
okButton.setEnabled(getConnection() != null && getResource() != null);
}
}
}

View file

@ -92,12 +92,14 @@ public class RemoteConnectionWidget extends Composite {
listenerEnabled = enabled;
}
@Override
public void widgetDefaultSelected(SelectionEvent e) {
if (isEnabled()) {
widgetSelected(e);
}
}
@Override
public void widgetSelected(SelectionEvent e) {
if (isEnabled()) {
Object source = e.getSource();
@ -150,6 +152,22 @@ public class RemoteConnectionWidget extends Composite {
private final ListenerList fSelectionListeners = new ListenerList();
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
*
@ -163,7 +181,6 @@ public class RemoteConnectionWidget extends Composite {
* a combination of flags that modify the behavior of the widget.
* @param context
* runnable context, or null
* @since 7.0
*/
public RemoteConnectionWidget(Composite parent, int style, String title, int flags, IRunnableContext context) {
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.SubMonitor;
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.viewers.DoubleClickEvent;
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.RemoteUIServices;
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.SelectionEvent;
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.Shell;
import org.eclipse.swt.widgets.Text;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.model.WorkbenchLabelProvider;
/**
@ -90,8 +89,6 @@ public class RemoteResourceBrowserWidget extends Composite {
*/
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 heightHint = 300;
@ -105,16 +102,18 @@ public class RemoteResourceBrowserWidget extends Composite {
private String dialogLabel;
private boolean showHidden;
private final List<String> remotePaths = new ArrayList<String>();
private final List<IFileStore> fResources = new ArrayList<IFileStore>();
private String fInitialPath;
private IPath fRootPath;
private IRemoteFileManager fFileMgr;
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 IRunnableContext fRunnableContext;
public RemoteResourceBrowserWidget(Composite parent, int style, int flags) {
super(parent, style);
setTitle(Messages.RemoteResourceBrowser_resourceTitle);
@ -131,20 +130,26 @@ public class RemoteResourceBrowserWidget extends Composite {
setLayout(layout);
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.numColumns = 4;
mainComp.setLayout(layout);
if ((optionFlags & SHOW_CONNECTIONS) != 0) {
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.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent event) {
connectionSelected();
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));
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() {
@Override
public void widgetDefaultSelected(SelectionEvent e) {
remotePathText.setSelection(remotePathText.getText().length());
setRoot(remotePathText.getText());
}
});
GridData gd = new GridData(SWT.FILL, SWT.CENTER, true, false);
gd.minimumWidth = minimumWidth;
@ -261,7 +253,7 @@ public class RemoteResourceBrowserWidget extends Composite {
// see bug 158380
gd.heightHint = Math.max(parent.getSize().y, heightHint);
treeViewer.getTree().setLayoutData(gd);
// treeViewer.setUseHashlookup(true);
treeViewer.setUseHashlookup(true);
treeViewer.setComparer(new DeferredFileStoreComparer());
treeViewer.setComparator(new RemoteResourceComparator());
treeViewer.setContentProvider(new RemoteContentProvider());
@ -272,17 +264,18 @@ public class RemoteResourceBrowserWidget extends Composite {
ISelection selection = event.getSelection();
if (!selection.isEmpty() && selection instanceof IStructuredSelection) {
IStructuredSelection ss = (IStructuredSelection) selection;
remotePaths.clear();
fResources.clear();
for (Object currentSelection : ss.toArray()) {
if (currentSelection instanceof DeferredFileStore) {
String path = ((DeferredFileStore) currentSelection).getFileStore().toURI().getPath();
remotePaths.add(path);
IFileStore store = ((DeferredFileStore) currentSelection).getFileStore();
fResources.add(store);
}
}
if (remotePaths.size() > 0) {
remotePathText.setText(remotePaths.get(0));
if (fResources.size() > 0) {
remotePathText.setText(fResources.get(0).toURI().getPath());
}
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
* listener to add
*/
public void addModifyListener(ModifyListener listener) {
fModifyListeners.add(listener);
public void addSelectionChangedListener(ISelectionChangedListener listener) {
fSelectionListeners.add(listener);
}
/**
@ -348,7 +341,7 @@ public class RemoteResourceBrowserWidget extends Composite {
}
IRemoteUIConnectionManager uiMgr = RemoteUIServices.getRemoteUIServices(conn.getRemoteServices()).getUIConnectionManager();
if (uiMgr != null) {
uiMgr.openConnectionWithProgress(getShell(), null, conn);
uiMgr.openConnectionWithProgress(getShell(), getRunnableContext(), conn);
}
if (!conn.isOpen()) {
return false;
@ -374,11 +367,6 @@ public class RemoteResourceBrowserWidget extends Composite {
return false;
}
public void setConnection(IRemoteConnection connection) {
changeInput(connection);
updateEnablement();
}
/**
* 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];
name[0] = null;
try {
PlatformUI.getWorkbench().getProgressService().busyCursorWhile(new IRunnableWithProgress() {
IRunnableWithProgress runnable = new IRunnableWithProgress() {
@Override
public void run(IProgressMonitor monitor) {
SubMonitor progress = SubMonitor.convert(monitor, 10);
@ -425,13 +413,12 @@ public class RemoteResourceBrowserWidget extends Composite {
Messages.RemoteResourceBrowserWidget_Unable_to_create_new_folder, e.getStatus());
}
}
});
};
getRunnableContext().run(true, true, runnable);
} catch (InvocationTargetException e) {
// TODO Auto-generated catch block
e.printStackTrace();
// Ignore, return null
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
// Ignore, return null
}
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() {
return remotePaths;
public List<IFileStore> getResources() {
return fResources;
}
private void notifyListeners(ModifyEvent e) {
for (Object listener : fModifyListeners.getListeners()) {
((ModifyListener) listener).modifyText(e);
public IRunnableContext getRunnableContext() {
if (fRunnableContext == null) {
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
* modified.
* Remove a listener that will be notified when the selection is changed
*
* @param listener
* listener to remove
*/
public void removeModifyListener(ModifyListener listener) {
fModifyListeners.remove(listener);
public void removeSelectionChangedListener(ISelectionChangedListener 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));
remotePathText.setText(path);
remotePathText.setSelection(remotePathText.getText().length());
fResources.clear();
fResources.add(root);
fRootPath = new Path(path);
}
}
public void setRunnableContext(IRunnableContext context) {
fRunnableContext = context;
}
/**
* 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
* of files) or a directory browser (allows selection of directories), or
* both.
* of files only) or a directory browser (allows selection of directories only), or
* both files and directories.
*/
public void setType() {
if ((optionFlags & FILE_BROWSER) == FILE_BROWSER) {
if ((optionFlags & DIRECTORY_BROWSER) == 0) {
dialogLabel = Messages.RemoteResourceBrowser_fileLabel;
setTitle(Messages.RemoteResourceBrowser_fileTitle);
} else {
} else if ((optionFlags & FILE_BROWSER) == 0) {
dialogLabel = Messages.RemoteResourceBrowser_directoryLabel;
setTitle(Messages.RemoteResourceBrowser_directoryTitle);
} else {
dialogLabel = Messages.RemoteResourceBrowser_resourceLabel;
setTitle(Messages.RemoteResourceBrowser_resourceTitle);
}
}
@ -558,19 +566,20 @@ public class RemoteResourceBrowserWidget extends Composite {
boolean newFolderEnabled = false;
if (fConnection != null && fConnection.isOpen()) {
if (remotePaths.size() == 1) {
String pathText = remotePaths.get(0);
if (!pathText.equals(EMPTY_STRING)) {
if (fConnection.getFileManager().getResource(pathText).fetchInfo().isDirectory()) {
if (fResources.size() == 1) {
IFileStore store = fResources.get(0);
/*
* Assume that we have already called fetchInfo() on the file store, so this should
* effectively be a noop.
*/
if (store.fetchInfo().isDirectory()) {
newFolderEnabled = true;
}
IPath path = new Path(pathText);
if (!path.isRoot()) {
if (store.getParent() != null) {
upEnabled = true;
}
}
}
}
if (upButton != null) {
upButton.setEnabled(upEnabled);