mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-06-08 10:16:03 +02:00
Allow browser to select files, directories or resources.
Signed-off-by: Greg Watson <g.watson@computer.org>
This commit is contained in:
parent
a4895a48d7
commit
93ecdc6948
3 changed files with 38 additions and 24 deletions
|
@ -18,6 +18,7 @@ import org.eclipse.jface.window.Window;
|
|||
import org.eclipse.remote.core.IRemoteConnection;
|
||||
import org.eclipse.remote.ui.IRemoteUIFileManager;
|
||||
import org.eclipse.remote.ui.dialogs.RemoteResourceBrowser;
|
||||
import org.eclipse.swt.SWT;
|
||||
import org.eclipse.swt.widgets.Shell;
|
||||
|
||||
public class JSchUIFileManager implements IRemoteUIFileManager {
|
||||
|
@ -33,7 +34,7 @@ public class JSchUIFileManager implements IRemoteUIFileManager {
|
|||
*/
|
||||
@Override
|
||||
public String browseDirectory(Shell shell, String message, String filterPath, int flags) {
|
||||
RemoteResourceBrowser browser = new RemoteResourceBrowser(shell, RemoteResourceBrowser.SINGLE);
|
||||
RemoteResourceBrowser browser = new RemoteResourceBrowser(shell, SWT.SINGLE);
|
||||
browser.setType(RemoteResourceBrowser.DIRECTORY_BROWSER);
|
||||
browser.setInitialPath(filterPath);
|
||||
browser.setTitle(message);
|
||||
|
@ -59,7 +60,7 @@ public class JSchUIFileManager implements IRemoteUIFileManager {
|
|||
*/
|
||||
@Override
|
||||
public String browseFile(Shell shell, String message, String filterPath, int flags) {
|
||||
RemoteResourceBrowser browser = new RemoteResourceBrowser(shell, RemoteResourceBrowser.SINGLE);
|
||||
RemoteResourceBrowser browser = new RemoteResourceBrowser(shell, SWT.SINGLE);
|
||||
browser.setType(RemoteResourceBrowser.FILE_BROWSER);
|
||||
browser.setInitialPath(filterPath);
|
||||
browser.setTitle(message);
|
||||
|
@ -85,7 +86,7 @@ public class JSchUIFileManager implements IRemoteUIFileManager {
|
|||
*/
|
||||
@Override
|
||||
public List<String> browseFiles(Shell shell, String message, String filterPath, int flags) {
|
||||
RemoteResourceBrowser browser = new RemoteResourceBrowser(shell, RemoteResourceBrowser.MULTI);
|
||||
RemoteResourceBrowser browser = new RemoteResourceBrowser(shell, SWT.MULTI);
|
||||
browser.setType(RemoteResourceBrowser.FILE_BROWSER);
|
||||
browser.setInitialPath(filterPath);
|
||||
browser.setTitle(message);
|
||||
|
|
|
@ -39,15 +39,20 @@ import org.eclipse.swt.widgets.Shell;
|
|||
/**
|
||||
* Generic file/directory browser for remote resources.
|
||||
*
|
||||
* A directory browser (DIRECTORY_BROWSER) only allows selection of directories.
|
||||
* A file browser (FILE_BROWSER) allows selection of files and directories, but the ok button is only enabled when a file is
|
||||
* selected.
|
||||
* A resource browser (FILE_BROWSER|DIRECTORY_BROWSER) allows selection of files and directories. This is the default.
|
||||
*
|
||||
* To select multiple resources, set the style to SWT.MULTI.
|
||||
*
|
||||
* @author greg
|
||||
*
|
||||
*/
|
||||
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;
|
||||
public static final int SINGLE = 0x01;
|
||||
public static final int MULTI = 0x02;
|
||||
public static final String EMPTY_STRING = ""; //$NON-NLS-1$
|
||||
public static final int FILE_BROWSER = 0x01;
|
||||
public static final int DIRECTORY_BROWSER = 0x02;
|
||||
|
||||
private final static int widthHint = 400;
|
||||
|
||||
|
@ -61,14 +66,16 @@ public class RemoteResourceBrowser extends Dialog implements IRunnableContext {
|
|||
private boolean showConnections = false;
|
||||
private String fInitialPath;
|
||||
private IRemoteConnection fConnection;
|
||||
private int optionFlags = SINGLE;
|
||||
private int fBrowserStyle = SWT.SINGLE;
|
||||
|
||||
public RemoteResourceBrowser(Shell parent, int flags) {
|
||||
public RemoteResourceBrowser(Shell parent, int style) {
|
||||
super(parent);
|
||||
setShellStyle(SWT.RESIZE | getShellStyle());
|
||||
this.optionFlags = flags;
|
||||
if (style != SWT.NONE) {
|
||||
fBrowserStyle = style;
|
||||
}
|
||||
setTitle(Messages.RemoteResourceBrowser_resourceTitle);
|
||||
setType(FILE_BROWSER);
|
||||
setType(FILE_BROWSER | DIRECTORY_BROWSER);
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -124,18 +131,17 @@ public class RemoteResourceBrowser extends Dialog implements IRunnableContext {
|
|||
main.setLayout(new GridLayout(1, true));
|
||||
|
||||
int options = RemoteResourceBrowserWidget.SHOW_HIDDEN_CHECKBOX | RemoteResourceBrowserWidget.SHOW_NEW_FOLDER_BUTTON;
|
||||
int style = SWT.NONE;
|
||||
if (fConnection == null || showConnections) {
|
||||
options |= RemoteResourceBrowserWidget.SHOW_CONNECTIONS;
|
||||
}
|
||||
if (browserType == DIRECTORY_BROWSER) {
|
||||
options |= RemoteResourceBrowserWidget.DIRECTORY_BROWSER;
|
||||
} else if (browserType == FILE_BROWSER) {
|
||||
options |= RemoteResourceBrowserWidget.FILE_BROWSER;
|
||||
} else {
|
||||
options |= RemoteResourceBrowserWidget.FILE_BROWSER | RemoteResourceBrowserWidget.DIRECTORY_BROWSER;
|
||||
}
|
||||
if ((optionFlags & MULTI) == MULTI) {
|
||||
style = SWT.MULTI;
|
||||
}
|
||||
|
||||
fResourceBrowserWidget = new RemoteResourceBrowserWidget(main, style, options);
|
||||
fResourceBrowserWidget = new RemoteResourceBrowserWidget(main, fBrowserStyle, options);
|
||||
fResourceBrowserWidget.addSelectionChangedListener(new ISelectionChangedListener() {
|
||||
@Override
|
||||
public void selectionChanged(SelectionChangedEvent event) {
|
||||
|
@ -267,14 +273,14 @@ public class RemoteResourceBrowser extends Dialog implements IRunnableContext {
|
|||
|
||||
/**
|
||||
* 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), a directory browser (allows selection of directories), or
|
||||
* a resource browser (allows selection of files and directories).
|
||||
*/
|
||||
public void setType(int type) {
|
||||
browserType = type;
|
||||
if (type == DIRECTORY_BROWSER) {
|
||||
setTitle(Messages.RemoteResourceBrowser_directoryTitle);
|
||||
} else {
|
||||
} else if (type == FILE_BROWSER) {
|
||||
setTitle(Messages.RemoteResourceBrowser_fileTitle);
|
||||
}
|
||||
}
|
||||
|
@ -290,7 +296,12 @@ public class RemoteResourceBrowser extends Dialog implements IRunnableContext {
|
|||
|
||||
private void updateDialog() {
|
||||
if (okButton != null) {
|
||||
okButton.setEnabled(getConnection() != null && getResource() != null);
|
||||
IFileStore resource = getResource();
|
||||
boolean enabled = getConnection() != null && resource != null;
|
||||
if (enabled && browserType == FILE_BROWSER) {
|
||||
enabled &= !resource.fetchInfo().isDirectory();
|
||||
}
|
||||
okButton.setEnabled(enabled);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -292,7 +292,10 @@ public class RemoteResourceBrowserWidget extends Composite {
|
|||
}
|
||||
|
||||
});
|
||||
if ((fOptionFlags & DIRECTORY_BROWSER) != 0) {
|
||||
/*
|
||||
* Only add filter if we are a directory browser. File and resource browsers show everything.
|
||||
*/
|
||||
if (fOptionFlags == DIRECTORY_BROWSER) {
|
||||
fTreeViewer.addFilter(new ViewerFilter() {
|
||||
@Override
|
||||
public boolean select(Viewer viewer, Object parentElement, Object element) {
|
||||
|
@ -567,7 +570,6 @@ public class RemoteResourceBrowserWidget extends Composite {
|
|||
} else {
|
||||
fDialogLabel = Messages.RemoteResourceBrowser_resourceLabel;
|
||||
setTitle(Messages.RemoteResourceBrowser_resourceTitle);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue