Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDarin Swanson2003-12-04 18:16:42 +0000
committerDarin Swanson2003-12-04 18:16:42 +0000
commit00ab42f6718aca299bacb1a954af48525a7818f8 (patch)
treec2a37b32e3d005b3a7927f17066256981f2c7aa4 /org.eclipse.ui.externaltools
parent5dd0a3c5eb98cf501d9da7684cb8a69889f0bb01 (diff)
downloadeclipse.platform.debug-00ab42f6718aca299bacb1a954af48525a7818f8.tar.gz
eclipse.platform.debug-00ab42f6718aca299bacb1a954af48525a7818f8.tar.xz
eclipse.platform.debug-00ab42f6718aca299bacb1a954af48525a7818f8.zip
Bug 47246 - Anvtiew add file dialog should allow multi select
Diffstat (limited to 'org.eclipse.ui.externaltools')
-rw-r--r--org.eclipse.ui.externaltools/External Tools Base/org/eclipse/ui/externaltools/internal/ui/FileSelectionDialog.java341
-rw-r--r--org.eclipse.ui.externaltools/External Tools Base/org/eclipse/ui/externaltools/internal/ui/TreeAndListGroup.java9
-rw-r--r--org.eclipse.ui.externaltools/Program Tools Support/org/eclipse/ui/externaltools/internal/program/launchConfigurations/ProgramMainTab.java18
3 files changed, 196 insertions, 172 deletions
diff --git a/org.eclipse.ui.externaltools/External Tools Base/org/eclipse/ui/externaltools/internal/ui/FileSelectionDialog.java b/org.eclipse.ui.externaltools/External Tools Base/org/eclipse/ui/externaltools/internal/ui/FileSelectionDialog.java
index cd0e5d1fb..707964fc1 100644
--- a/org.eclipse.ui.externaltools/External Tools Base/org/eclipse/ui/externaltools/internal/ui/FileSelectionDialog.java
+++ b/org.eclipse.ui.externaltools/External Tools Base/org/eclipse/ui/externaltools/internal/ui/FileSelectionDialog.java
@@ -10,12 +10,10 @@
*******************************************************************************/
package org.eclipse.ui.externaltools.internal.ui;
-
import java.util.ArrayList;
import java.util.List;
import org.eclipse.core.resources.IContainer;
-import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IAdaptable;
@@ -24,6 +22,7 @@ import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.viewers.DoubleClickEvent;
import org.eclipse.jface.viewers.IDoubleClickListener;
import org.eclipse.jface.viewers.ISelectionChangedListener;
+import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.ITreeContentProvider;
import org.eclipse.jface.viewers.SelectionChangedEvent;
import org.eclipse.swt.SWT;
@@ -41,190 +40,214 @@ import org.eclipse.ui.model.WorkbenchContentProvider;
import org.eclipse.ui.model.WorkbenchLabelProvider;
/**
- * Dialog for selecting a file in the workspace. Derived from
+ * Dialog for selecting a file in the workspace. Derived from
* org.eclipse.ui.dialogs.ResourceSelectionDialog
*/
public class FileSelectionDialog extends MessageDialog {
// the root element to populate the viewer with
- private IAdaptable root;
+ private IAdaptable root;
// the visual selection widget group
- private TreeAndListGroup selectionGroup;
+ private TreeAndListGroup selectionGroup;
// constants
- private final static int SIZING_SELECTION_WIDGET_WIDTH = 400;
- private final static int SIZING_SELECTION_WIDGET_HEIGHT = 300;
+ private final static int SIZING_SELECTION_WIDGET_WIDTH = 400;
+ private final static int SIZING_SELECTION_WIDGET_HEIGHT = 300;
/**
- * The file selected by the user.
+ * The file(s) selected by the user.
*/
- private IFile result= null;
+ private IStructuredSelection result = null;
/**
* String matcher used to filter content
*/
- private StringMatcher stringMatcher= null;
-/**
- * Creates a resource selection dialog rooted at the given element.
- *
- * @param parentShell the parent shell
- * @param rootElement the root element to populate this dialog with
- * @param message the message to be displayed at the top of this dialog, or
- * <code>null</code> to display a default message
- */
-public FileSelectionDialog(Shell parentShell, IAdaptable rootElement, String message) {
- super(parentShell, ExternalToolsUIMessages.getString("FileSelectionDialog.Choose_Location_1"), null, message, MessageDialog.NONE, new String[] {ExternalToolsUIMessages.getString("FileSelectionDialog.Ok_2"), ExternalToolsUIMessages.getString("FileSelectionDialog.Cancel_3")}, 0); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- root = rootElement;
- setShellStyle(getShellStyle() | SWT.RESIZE);
-}
-/**
- * Limits the files displayed in this dialog to files matching the given
- * pattern. The string can be a filename or a regular expression containing
- * '*' for any series of characters or '?' for any single character.
- *
- * @param pattern a pattern used to filter the displayed files or
- * <code>null</code> to display all files. If a pattern is supplied, only files
- * whose names match the given pattern will be available for selection.
- * @param ignoreCase if true, case is ignored. If the pattern argument is
- * <code>null</code>, this argument is ignored.
- */
-public void setFileFilter(String pattern, boolean ignoreCase) {
- if (pattern != null) {
- stringMatcher= new StringMatcher(pattern, ignoreCase, false);
- } else {
- stringMatcher= null;
- }
-}
-/* (non-Javadoc)
- * Method declared in Window.
- */
-protected void configureShell(Shell shell) {
- super.configureShell(shell);
- WorkbenchHelp.setHelp(shell, IExternalToolsHelpContextIds.FILE_SELECTION_DIALOG);
-}
-
-protected void createButtonsForButtonBar(Composite parent) {
- super.createButtonsForButtonBar(parent);
- initializeDialog();
-}
-/* (non-Javadoc)
- * Method declared on Dialog.
- */
-protected Control createDialogArea(Composite parent) {
- // page group
- Composite composite = (Composite) super.createDialogArea(parent);
+ private StringMatcher stringMatcher = null;
- //create the input element, which has the root resource
- //as its only child
+ private boolean allowMultiselection= false;
+ /**
+ * Creates a resource selection dialog rooted at the given element.
+ *
+ * @param parentShell
+ * the parent shell
+ * @param rootElement
+ * the root element to populate this dialog with
+ * @param message
+ * the message to be displayed at the top of this dialog, or
+ * <code>null</code> to display a default message
+ */
+ public FileSelectionDialog(Shell parentShell, IAdaptable rootElement, String message) {
+ super(parentShell, ExternalToolsUIMessages.getString("FileSelectionDialog.Choose_Location_1"), null, message, MessageDialog.NONE, new String[] { ExternalToolsUIMessages.getString("FileSelectionDialog.Ok_2"), ExternalToolsUIMessages.getString("FileSelectionDialog.Cancel_3")}, 0); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ root = rootElement;
+ setShellStyle(getShellStyle() | SWT.RESIZE);
+ }
+
+ /**
+ * Limits the files displayed in this dialog to files matching the given
+ * pattern. The string can be a filename or a regular expression containing
+ * '*' for any series of characters or '?' for any single character.
+ *
+ * @param pattern
+ * a pattern used to filter the displayed files or <code>null</code>
+ * to display all files. If a pattern is supplied, only files
+ * whose names match the given pattern will be available for
+ * selection.
+ * @param ignoreCase
+ * if true, case is ignored. If the pattern argument is <code>null</code>,
+ * this argument is ignored.
+ */
+ public void setFileFilter(String pattern, boolean ignoreCase) {
+ if (pattern != null) {
+ stringMatcher = new StringMatcher(pattern, ignoreCase, false);
+ } else {
+ stringMatcher = null;
+ }
+ }
+
+ /*
+ * (non-Javadoc) Method declared in Window.
+ */
+ protected void configureShell(Shell shell) {
+ super.configureShell(shell);
+ WorkbenchHelp.setHelp(
+ shell,
+ IExternalToolsHelpContextIds.FILE_SELECTION_DIALOG);
+ }
- selectionGroup =
- new TreeAndListGroup(
- composite,
- root,
- getResourceProvider(IResource.FOLDER | IResource.PROJECT | IResource.ROOT),
- new WorkbenchLabelProvider(),
- getResourceProvider(IResource.FILE),
- new WorkbenchLabelProvider(),
- SWT.NONE,
- // since this page has no other significantly-sized
- // widgets we need to hardcode the combined widget's
- // size, otherwise it will open too small
- SIZING_SELECTION_WIDGET_WIDTH,
- SIZING_SELECTION_WIDGET_HEIGHT);
+ protected void createButtonsForButtonBar(Composite parent) {
+ super.createButtonsForButtonBar(parent);
+ initializeDialog();
+ }
+
+ /*
+ * (non-Javadoc) Method declared on Dialog.
+ */
+ protected Control createDialogArea(Composite parent) {
+ // page group
+ Composite composite = (Composite) super.createDialogArea(parent);
- composite.addControlListener(new ControlListener() {
- public void controlMoved(ControlEvent e) {}
- public void controlResized(ControlEvent e) {
- //Also try and reset the size of the columns as appropriate
- TableColumn[] columns = selectionGroup.getListTable().getColumns();
- for (int i = 0; i < columns.length; i++) {
- columns[i].pack();
+ //create the input element, which has the root resource
+ //as its only child
+ selectionGroup =
+ new TreeAndListGroup(
+ composite,
+ root,
+ getResourceProvider(
+ IResource.FOLDER | IResource.PROJECT | IResource.ROOT),
+ new WorkbenchLabelProvider(),
+ getResourceProvider(IResource.FILE),
+ new WorkbenchLabelProvider(),
+ SWT.NONE,
+ // since this page has no other significantly-sized
+ // widgets we need to hardcode the combined widget's
+ // size, otherwise it will open too small
+ SIZING_SELECTION_WIDGET_WIDTH, SIZING_SELECTION_WIDGET_HEIGHT,
+ allowMultiselection);
+
+ composite.addControlListener(new ControlListener() {
+ public void controlMoved(ControlEvent e) {
}
- }
- });
+ public void controlResized(ControlEvent e) {
+ //Also try and reset the size of the columns as appropriate
+ TableColumn[] columns =
+ selectionGroup.getListTable().getColumns();
+ for (int i = 0; i < columns.length; i++) {
+ columns[i].pack();
+ }
+ }
+ });
- return composite;
-}
-/**
- * Returns a content provider for <code>IResource</code>s that returns
- * only children of the given resource type.
- */
-private ITreeContentProvider getResourceProvider(final int resourceType) {
- return new WorkbenchContentProvider() {
- public Object[] getChildren(Object o) {
- if (o instanceof IContainer) {
- IResource[] members = null;
- try {
- members = ((IContainer)o).members();
- List accessibleMembers= new ArrayList(members.length);
- for (int i = 0; i < members.length; i++) {
- IResource resource = members[i];
- if (resource.isAccessible()) {
- accessibleMembers.add(resource);
+ return composite;
+ }
+ /**
+ * Returns a content provider for <code>IResource</code> s that returns
+ * only children of the given resource type.
+ */
+ private ITreeContentProvider getResourceProvider(final int resourceType) {
+ return new WorkbenchContentProvider() {
+ public Object[] getChildren(Object o) {
+ if (o instanceof IContainer) {
+ IResource[] members = null;
+ try {
+ members = ((IContainer) o).members();
+ List accessibleMembers = new ArrayList(members.length);
+ for (int i = 0; i < members.length; i++) {
+ IResource resource = members[i];
+ if (resource.isAccessible()) {
+ accessibleMembers.add(resource);
+ }
}
+ members =
+ (IResource[]) accessibleMembers.toArray(
+ new IResource[accessibleMembers.size()]);
+ } catch (CoreException e) {
+ //just return an empty set of children
+ return new Object[0];
}
- members= (IResource[])accessibleMembers.toArray(new IResource[accessibleMembers.size()]);
- } catch (CoreException e) {
- //just return an empty set of children
- return new Object[0];
- }
- //filter out the desired resource types
- ArrayList results = new ArrayList();
- for (int i = 0; i < members.length; i++) {
- //And the test bits with the resource types to see if they are what we want
- if ((members[i].getType() & resourceType) > 0) {
- if (members[i].getType() == IResource.FILE &&
- stringMatcher != null &&
- !stringMatcher.match(members[i].getName())) {
- continue;
+ //filter out the desired resource types
+ ArrayList results = new ArrayList();
+ for (int i = 0; i < members.length; i++) {
+ //And the test bits with the resource types to see if
+ // they are what we want
+ if ((members[i].getType() & resourceType) > 0) {
+ if (members[i].getType() == IResource.FILE
+ && stringMatcher != null
+ && !stringMatcher.match(members[i].getName())) {
+ continue;
+ }
+ results.add(members[i]);
}
- results.add(members[i]);
}
+ return results.toArray();
+ } else {
+ return new Object[0];
}
- return results.toArray();
- } else {
- return new Object[0];
}
- }
- };
-}
-/**
- * Initializes this dialog's controls.
- */
-private void initializeDialog() {
- selectionGroup.addSelectionChangedListener(new ISelectionChangedListener() {
- public void selectionChanged(SelectionChangedEvent event) {
- getOkButton().setEnabled(!selectionGroup.getListTableSelection().isEmpty());
- }
- });
- selectionGroup.addDoubleClickListener(new IDoubleClickListener() {
- public void doubleClick(DoubleClickEvent event) {
- buttonPressed(IDialogConstants.OK_ID);
- }
- });
+ };
+ }
+ /**
+ * Initializes this dialog's controls.
+ */
+ private void initializeDialog() {
+ selectionGroup
+ .addSelectionChangedListener(new ISelectionChangedListener() {
+ public void selectionChanged(SelectionChangedEvent event) {
+ getOkButton().setEnabled(
+ !selectionGroup.getListTableSelection().isEmpty());
+ }
+ });
+ selectionGroup.addDoubleClickListener(new IDoubleClickListener() {
+ public void doubleClick(DoubleClickEvent event) {
+ buttonPressed(IDialogConstants.OK_ID);
+ }
+ });
- getOkButton().setEnabled(false);
-}
+ getOkButton().setEnabled(false);
+ }
-/**
- * Returns this dialog's OK button.
- */
-protected Button getOkButton() {
- return getButton(0);
-}
-/**
- * Returns the file the user chose or <code>null</code> if none.
- */
-public IFile getResult() {
- return result;
-}
+ /**
+ * Returns this dialog's OK button.
+ */
+ protected Button getOkButton() {
+ return getButton(0);
+ }
+ /**
+ * Returns the file the user chose or <code>null</code> if none.
+ */
+ public IStructuredSelection getResult() {
+ return result;
+ }
-protected void buttonPressed(int buttonId) {
- if (buttonId == IDialogConstants.OK_ID) {
- Object resource= selectionGroup.getListTableSelection().getFirstElement();
- if (resource instanceof IFile) {
- result = (IFile) resource;
+ protected void buttonPressed(int buttonId) {
+ if (buttonId == IDialogConstants.OK_ID) {
+ result= selectionGroup.getListTableSelection();
}
+ super.buttonPressed(buttonId);
+ }
+ /**
+ * Sets whether this dialog will allow multi-selection.
+ * Must be called before <code>open</code>
+ * @param allowMultiselection whether to allow multi-selection in the dialog
+ */
+ public void setAllowMultiselection(boolean allowMultiselection) {
+ this.allowMultiselection= allowMultiselection;
}
- super.buttonPressed(buttonId);
-}
-
}
diff --git a/org.eclipse.ui.externaltools/External Tools Base/org/eclipse/ui/externaltools/internal/ui/TreeAndListGroup.java b/org.eclipse.ui.externaltools/External Tools Base/org/eclipse/ui/externaltools/internal/ui/TreeAndListGroup.java
index b1ee2dac5..ca98fd6d3 100644
--- a/org.eclipse.ui.externaltools/External Tools Base/org/eclipse/ui/externaltools/internal/ui/TreeAndListGroup.java
+++ b/org.eclipse.ui.externaltools/External Tools Base/org/eclipse/ui/externaltools/internal/ui/TreeAndListGroup.java
@@ -69,14 +69,16 @@ public class TreeAndListGroup implements ISelectionChangedListener {
* @param listPropertyName java.lang.String
* @param width int
* @param height int
+ * @param allowMultiselection Whether to allow multi-selection in the list viewer.
*/
- public TreeAndListGroup(Composite parent, Object rootObject, ITreeContentProvider treeContentProvider, ILabelProvider treeLabelProvider, IStructuredContentProvider listContentProvider, ILabelProvider listLabelProvider, int style, int width, int height) {
+ public TreeAndListGroup(Composite parent, Object rootObject, ITreeContentProvider treeContentProvider, ILabelProvider treeLabelProvider, IStructuredContentProvider listContentProvider, ILabelProvider listLabelProvider, int style, int width, int height, boolean allowMultiselection) {
root = rootObject;
this.treeContentProvider = treeContentProvider;
this.listContentProvider = listContentProvider;
this.treeLabelProvider = treeLabelProvider;
this.listLabelProvider = listLabelProvider;
+ this.allowMultiselection= allowMultiselection;
createContents(parent, width, height, style);
}
/**
@@ -315,9 +317,4 @@ public class TreeAndListGroup implements ISelectionChangedListener {
this.treeViewer.getTree().setFocus();
}
-
- public void setAllowMultiselection(boolean allowMultiselection) {
- this.allowMultiselection= allowMultiselection;
-
- }
}
diff --git a/org.eclipse.ui.externaltools/Program Tools Support/org/eclipse/ui/externaltools/internal/program/launchConfigurations/ProgramMainTab.java b/org.eclipse.ui.externaltools/Program Tools Support/org/eclipse/ui/externaltools/internal/program/launchConfigurations/ProgramMainTab.java
index e6db7b0d3..14db303de 100644
--- a/org.eclipse.ui.externaltools/Program Tools Support/org/eclipse/ui/externaltools/internal/program/launchConfigurations/ProgramMainTab.java
+++ b/org.eclipse.ui.externaltools/Program Tools Support/org/eclipse/ui/externaltools/internal/program/launchConfigurations/ProgramMainTab.java
@@ -13,6 +13,7 @@ package org.eclipse.ui.externaltools.internal.program.launchConfigurations;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.ui.externaltools.internal.launchConfigurations.ExternalToolsMainTab;
import org.eclipse.ui.externaltools.internal.model.IExternalToolsHelpContextIds;
@@ -30,15 +31,18 @@ public class ProgramMainTab extends ExternalToolsMainTab {
FileSelectionDialog dialog;
dialog = new FileSelectionDialog(getShell(), ResourcesPlugin.getWorkspace().getRoot(), ExternalToolsProgramMessages.getString("ProgramMainTab.Select")); //$NON-NLS-1$
dialog.open();
- IFile file = dialog.getResult();
- if (file == null) {
+ IStructuredSelection result = dialog.getResult();
+ if (result == null) {
return;
}
- StringBuffer expression = new StringBuffer();
- expression.append("${workspace_loc:"); //$NON-NLS-1$
- expression.append(file.getFullPath().toString());
- expression.append("}"); //$NON-NLS-1$
- locationField.setText(expression.toString());
+ Object file= result.getFirstElement();
+ if (file instanceof IFile) {
+ StringBuffer expression = new StringBuffer();
+ expression.append("${workspace_loc:"); //$NON-NLS-1$
+ expression.append(((IFile)file).getFullPath().toString());
+ expression.append("}"); //$NON-NLS-1$
+ locationField.setText(expression.toString());
+ }
}

Back to the top