Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDani Megert2001-10-10 06:22:56 -0400
committerDani Megert2001-10-10 06:22:56 -0400
commit08069f07e2621c8b485b2c6575e3594f801ea769 (patch)
tree27bae191d8a6fc60e91f4a435baafb2ca81269dd
parent8bf8e2a4b885bd10227906cd0ea808e8aead3abb (diff)
downloadeclipse.platform.text-08069f07e2621c8b485b2c6575e3594f801ea769.tar.gz
eclipse.platform.text-08069f07e2621c8b485b2c6575e3594f801ea769.tar.xz
eclipse.platform.text-08069f07e2621c8b485b2c6575e3594f801ea769.zip
First cut: 1GDU9JE: ITPJUI:ALL - DCR: Add "Search Scope" capability
-rw-r--r--org.eclipse.search/search/org/eclipse/search/internal/ui/ScopePart.java72
-rw-r--r--org.eclipse.search/search/org/eclipse/search/internal/ui/SearchPlugin.java26
-rw-r--r--org.eclipse.search/search/org/eclipse/search/internal/ui/util/ListContentProvider.java41
-rw-r--r--org.eclipse.search/search/org/eclipse/search/internal/workingsets/WorkingSet.java95
-rw-r--r--org.eclipse.search/search/org/eclipse/search/internal/workingsets/WorkingSetDialog.java115
-rw-r--r--org.eclipse.search/search/org/eclipse/search/internal/workingsets/WorkingSetSelectionDialog.java255
-rw-r--r--org.eclipse.search/search/org/eclipse/search/ui/SearchUI.java3
7 files changed, 545 insertions, 62 deletions
diff --git a/org.eclipse.search/search/org/eclipse/search/internal/ui/ScopePart.java b/org.eclipse.search/search/org/eclipse/search/internal/ui/ScopePart.java
index 8909367b2..a563171b9 100644
--- a/org.eclipse.search/search/org/eclipse/search/internal/ui/ScopePart.java
+++ b/org.eclipse.search/search/org/eclipse/search/internal/ui/ScopePart.java
@@ -15,10 +15,12 @@ import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Text;
import org.eclipse.ui.dialogs.SelectionDialog;
+import java.util.Arrays;
import org.eclipse.core.resources.IResource;
import org.eclipse.jface.util.Assert;
import org.eclipse.search.internal.ui.util.SWTUtil;
+import org.eclipse.search.internal.workingsets.WorkingSet;
import org.eclipse.search.ui.IWorkingSet;
import org.eclipse.search.ui.SearchUI;
@@ -36,8 +38,8 @@ public class ScopePart {
private int fScope;
- private Text fWorkingSet;
- private IWorkingSet fWorkingSetValue;
+ private Text fWorkingSetText;
+ private IWorkingSet fWorkingSet;
/**
* Returns a new scope part with workspace as initial scope.
@@ -69,7 +71,7 @@ public class ScopePart {
public ScopePart(IWorkingSet workingSet) {
Assert.isNotNull(workingSet);
fScope= WORKING_SET_SCOPE;
- fWorkingSetValue= workingSet;
+ fWorkingSet= workingSet;
}
/**
@@ -108,27 +110,21 @@ public class ScopePart {
fUseWorkspace.setSelection(false);
fUseSelection.setSelection(false);
fUseWorkingSet.setSelection(true);
+ fUseWorkingSet.setEnabled(true);
break;
}
}
/**
- * Returns the selected working of this part.
+ * Returns the selected working set of this part.
*
- * @return the selected working set or null if the scope is not WORKING_SET_SCOPE
+ * @return the selected working set or null
+ * - if the scope is not WORKING_SET_SCOPE
+ * - if there is no working set selected
*/
public IWorkingSet getSelectedWorkingSet() {
- if (getSelectedScope() == WORKING_SET_SCOPE) {
- return new IWorkingSet() {
- public String getName() {
- return "This is a Test Scope"; //$NON-NLS-1$
- }
-
- public IResource[] getResources() {
- return new IResource[0];
- }
- };
- }
+ if (getSelectedScope() == WORKING_SET_SCOPE)
+ return fWorkingSet;
else
return null;
}
@@ -140,10 +136,11 @@ public class ScopePart {
* @param workingSet the working set to be selected
*/
public void setSelectedWorkingSet(IWorkingSet workingSet) {
- Assert.isNotNull(fWorkingSet);
+ Assert.isNotNull(workingSet);
setSelectedScope(WORKING_SET_SCOPE);
-// fWorkingSet= workingSet;
- fWorkingSetValue= workingSet;
+ fWorkingSet= workingSet;
+ if (fWorkingSetText != null)
+ fWorkingSetText.setText(workingSet.getName());
}
/**
@@ -175,7 +172,8 @@ public class ScopePart {
fUseWorkingSet= new Button(group, SWT.RADIO);
fUseWorkingSet.setData(new Integer(WORKING_SET_SCOPE));
fUseWorkingSet.setText(SearchMessages.getString("ScopePart.workingSetScope.text")); //$NON-NLS-1$
- fWorkingSet= new Text(group, SWT.SINGLE | SWT.BORDER | SWT.READ_ONLY);
+ fUseWorkingSet.setEnabled(getSelectedWorkingSet() != null);
+ fWorkingSetText= new Text(group, SWT.SINGLE | SWT.BORDER | SWT.READ_ONLY);
Button chooseWorkingSet= new Button(group, SWT.PUSH);
chooseWorkingSet.setLayoutData(new GridData());
chooseWorkingSet.setText(SearchMessages.getString("ScopePart.workingSetChooseButton.text")); //$NON-NLS-1$
@@ -183,17 +181,14 @@ public class ScopePart {
chooseWorkingSet.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
if (handleChooseWorkingSet()) {
- fUseWorkspace.setSelection(false);
- fUseSelection.setSelection(false);
- fUseWorkingSet.setSelection(true);
- fScope= WORKING_SET_SCOPE;
+ setSelectedScope(WORKING_SET_SCOPE);
}
}
});
gd= new GridData(GridData.FILL_HORIZONTAL);
gd.horizontalIndent= 8;
- gd.widthHint= SWTUtil.convertWidthInCharsToPixels(30, fWorkingSet);
- fWorkingSet.setLayoutData(gd);
+ gd.widthHint= SWTUtil.convertWidthInCharsToPixels(30, fWorkingSetText);
+ fWorkingSetText.setLayoutData(gd);
// Add scope change listeners
SelectionAdapter scopeChangedLister= new SelectionAdapter() {
@@ -209,15 +204,9 @@ public class ScopePart {
setSelectedScope(fScope);
// Set initial working set
- if (fWorkingSetValue != null)
- fWorkingSet.setText(fWorkingSetValue.getName());
+ if (fWorkingSet != null)
+ fWorkingSetText.setText(fWorkingSet.getName());
-
- // disable working sets - not available yet
- fUseWorkingSet.setVisible(false);
- fWorkingSet.setVisible(false);
- chooseWorkingSet.setVisible(false);
-
return group;
}
@@ -232,7 +221,18 @@ public class ScopePart {
private boolean handleChooseWorkingSet() {
SelectionDialog dialog= SearchUI.createWorkingSetDialog(fUseSelection.getShell());
- System.out.println("Choose working set. Scope is: " + fScope); //$NON-NLS-1$
- return true;
+ if (fWorkingSet != null)
+ dialog.setInitialSelections(new IWorkingSet[] {fWorkingSet});
+ if (dialog.open() == dialog.OK) {
+ setSelectedWorkingSet((IWorkingSet)dialog.getResult()[0]);
+ return true;
+ } else {
+ // test if selected working set has been removed
+ if (!Arrays.asList(WorkingSet.getWorkingSets()).contains(fWorkingSet)) {
+ fWorkingSetText.setText("");
+ fWorkingSet= null;
+ }
+ }
+ return false;
}
}
diff --git a/org.eclipse.search/search/org/eclipse/search/internal/ui/SearchPlugin.java b/org.eclipse.search/search/org/eclipse/search/internal/ui/SearchPlugin.java
index eefe2a623..41c632fc9 100644
--- a/org.eclipse.search/search/org/eclipse/search/internal/ui/SearchPlugin.java
+++ b/org.eclipse.search/search/org/eclipse/search/internal/ui/SearchPlugin.java
@@ -25,14 +25,12 @@ import org.eclipse.swt.widgets.Shell;
import org.eclipse.jface.action.GroupMarker;
import org.eclipse.jface.action.IMenuManager;
import org.eclipse.jface.action.Separator;
-import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.util.Assert;
import org.eclipse.ui.IViewPart;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.PartInitException;
-import org.eclipse.ui.dialogs.SelectionDialog;
import org.eclipse.ui.plugin.AbstractUIPlugin;
import org.eclipse.search.internal.ui.util.ExceptionHandler;
@@ -49,7 +47,7 @@ public class SearchPlugin extends AbstractUIPlugin {
public static final String SORTER_EXTENSION_POINT= "searchResultSorters"; //$NON-NLS-1$
private static SearchPlugin fgSearchPlugin;
-
+
private List fPageDescriptors;
private List fSorterDescriptors;
@@ -270,26 +268,4 @@ public class SearchPlugin extends AbstractUIPlugin {
menu.add(new Separator(IContextMenuConstants.GROUP_VIEWER_SETUP));
menu.add(new Separator(IContextMenuConstants.GROUP_PROPERTIES));
}
-
- /**
- * Creates a selection dialog that lists all working sets and allows to
- * add and edit working sets.
- * The caller is responsible for opening the dialog with <code>Window.open</code>,
- * and subsequently extracting the selected working sets (of type
- * <code>IWorkingSet</code>) via <code>SelectionDialog.getResult</code>.
- * <p>
- * This method is for internal use only due to issue below. Once
- * the issues is solved there will be an official API.
- * </p>
- * <p>
- * [Issue: Working set must be provided by platform.]
- * </p>
- *
- * @param parent the parent shell of the dialog to be created
- * @return a new selection dialog or <code>null</code> if none available
- */
- public static SelectionDialog createWorkingSetDialog(Shell parent) {
- MessageDialog.openInformation(getActiveWorkbenchShell(), "Working Set Dialog", "The working set dialog will come soon!"); //$NON-NLS-1$ //$NON-NLS-2$
- return null;
- }
}
diff --git a/org.eclipse.search/search/org/eclipse/search/internal/ui/util/ListContentProvider.java b/org.eclipse.search/search/org/eclipse/search/internal/ui/util/ListContentProvider.java
new file mode 100644
index 000000000..c1e5f6a72
--- /dev/null
+++ b/org.eclipse.search/search/org/eclipse/search/internal/ui/util/ListContentProvider.java
@@ -0,0 +1,41 @@
+/*
+ * (c) Copyright IBM Corp. 2000, 2001.
+ * All Rights Reserved.
+ */
+package org.eclipse.search.internal.ui.util;
+
+import java.util.List;
+
+import org.eclipse.jface.viewers.IStructuredContentProvider;
+import org.eclipse.jface.viewers.Viewer;
+
+/**
+ * A specialized content provider to show a list of editor parts.
+ */
+public class ListContentProvider implements IStructuredContentProvider {
+ List fContents;
+
+ public ListContentProvider() {
+ }
+
+ public Object[] getElements(Object input) {
+ if (fContents != null && fContents == input)
+ return fContents.toArray();
+ return new Object[0];
+ }
+
+ public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
+ if (newInput instanceof List)
+ fContents= (List)newInput;
+ else
+ fContents= null;
+ // we use a fixed set.
+ }
+
+ public void dispose() {
+ }
+
+ public boolean isDeleted(Object o) {
+ return fContents != null && !fContents.contains(o);
+ }
+} \ No newline at end of file
diff --git a/org.eclipse.search/search/org/eclipse/search/internal/workingsets/WorkingSet.java b/org.eclipse.search/search/org/eclipse/search/internal/workingsets/WorkingSet.java
new file mode 100644
index 000000000..c7505fff5
--- /dev/null
+++ b/org.eclipse.search/search/org/eclipse/search/internal/workingsets/WorkingSet.java
@@ -0,0 +1,95 @@
+package org.eclipse.search.internal.workingsets;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.runtime.IPath;
+
+import org.eclipse.jface.util.Assert;
+
+import org.eclipse.search.ui.IWorkingSet;
+
+
+public class WorkingSet implements IWorkingSet {
+
+ private static Set fgWorkingSets= new HashSet(5);
+
+ String fName;
+ Set fElements; // of IResources
+
+ WorkingSet(String name, Object[] elements) {
+ setName(name);
+ setResources(elements);
+ }
+
+ void setResources(Object[] elements) {
+ Assert.isNotNull(elements, "IPath array must not be null");
+ fElements= new HashSet(elements.length);
+ for (int i= 0; i < elements.length; i++) {
+ Assert.isTrue(elements[i] instanceof IResource);
+ Assert.isTrue(!fElements.contains(elements[i]), "elements must only contain each element once");
+ fElements.add(elements[i]);
+ }
+ }
+
+ void setPaths(IPath[] elements) {
+ Assert.isNotNull(elements, "IPath array must not be null");
+ fElements= new HashSet(elements.length);
+ for (int i= 0; i < elements.length; i++) {
+ Assert.isTrue(!fElements.contains(elements[i]), "elements must only contain each element once");
+ fElements.add(elements[i]);
+ }
+ }
+
+ /*
+ * @see IWorkingSet#getName()
+ */
+ public String getName() {
+ return fName;
+ }
+
+ void setName(String name) {
+ Assert.isNotNull(name, "name must not be null");
+ fName= name;
+ }
+
+ /*
+ * @see IWorkingSet#getResources()
+ */
+ public IResource[] getResources() {
+ return (IResource[])fElements.toArray(new IResource[fElements.size()]);
+ }
+
+ public boolean equals (Object o) {
+ return (o instanceof IWorkingSet) && ((IWorkingSet)o).getName().equals(getName());
+ }
+
+ public int hashCode() {
+ return fName.hashCode();
+ }
+
+ /**
+ * Returns the workbench from which this plugin has been loaded.
+ */
+ public static IWorkingSet[] getWorkingSets() {
+ return (IWorkingSet[])fgWorkingSets.toArray(new IWorkingSet[fgWorkingSets.size()]);
+ }
+
+ /**
+ * Removes the working set from the workspace.
+ * This is a NOP if the working set does not exist in the workspace.
+ */
+ static void remove(IWorkingSet workingSet) {
+ fgWorkingSets.remove(workingSet);
+ }
+
+ /**
+ * Adds the working set to the workspace.
+ * The working set must not exist yet.
+ */
+ static void add(IWorkingSet workingSet) {
+ Assert.isTrue(!fgWorkingSets.contains(workingSet), "working set already registered");
+ fgWorkingSets.add(workingSet);
+ }
+} \ No newline at end of file
diff --git a/org.eclipse.search/search/org/eclipse/search/internal/workingsets/WorkingSetDialog.java b/org.eclipse.search/search/org/eclipse/search/internal/workingsets/WorkingSetDialog.java
new file mode 100644
index 000000000..c74852e53
--- /dev/null
+++ b/org.eclipse.search/search/org/eclipse/search/internal/workingsets/WorkingSetDialog.java
@@ -0,0 +1,115 @@
+package org.eclipse.search.internal.workingsets;
+
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.MouseAdapter;
+import org.eclipse.swt.events.MouseEvent;
+import org.eclipse.swt.events.MouseListener;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Shell;
+
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.jface.dialogs.IInputValidator;
+import org.eclipse.jface.dialogs.InputDialog;
+
+import org.eclipse.jface.util.Assert;
+import org.eclipse.jface.viewers.CheckboxTreeViewer;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.ui.model.WorkbenchContentProvider;
+import org.eclipse.ui.model.WorkbenchLabelProvider;
+
+import org.eclipse.search.internal.ui.SearchPlugin;
+import org.eclipse.search.ui.IWorkingSet;
+import org.eclipse.search.internal.ui.util.*;
+
+
+public class WorkingSetDialog extends InputDialog {
+
+ private static class WorkingSetNameInputValidator implements IInputValidator {
+
+ String fInitalName;
+
+ public WorkingSetNameInputValidator(String initialName) {
+ Assert.isNotNull(initialName, "initial name must not be null");
+ fInitalName= initialName;
+ }
+
+ public String isValid(String newText) {
+ if (newText == null ||newText.equals(""))
+ return "The name must not be empty.";
+ IWorkingSet[] workingSets= WorkingSet.getWorkingSets();
+ if (newText.equals(fInitalName))
+ return null;
+ for (int i= 0; i < workingSets.length; i++) {
+ if (newText.equals(workingSets[i].getName()))
+ return "A workspace with that name already exists.";
+ }
+ return null;
+ }
+ }
+
+ // Widgets constants
+ private final static int SIZING_SELECTION_WIDGET_WIDTH= 300;
+ private final static int SIZING_SELECTION_WIDGET_HEIGHT= 300;
+
+ private IWorkingSet fWorkingSet;
+ private CheckboxTreeViewer fTree;
+
+ public WorkingSetDialog(Shell parentShell) {
+ this(parentShell, "");
+ }
+
+ public WorkingSetDialog(Shell parentShell, IWorkingSet workingSet) {
+ this(parentShell, workingSet.getName());
+ fWorkingSet= workingSet;
+ }
+
+ private WorkingSetDialog(Shell parentShell, String initialSelection) {
+ super(parentShell, "Working Set", "Define the working set name:", initialSelection, new WorkingSetNameInputValidator(initialSelection));
+ }
+
+ /*
+ * Overrides method from Dialog.
+ */
+ protected Control createDialogArea(Composite parent) {
+ // page group
+ Composite composite= (Composite)super.createDialogArea(parent);
+
+ fTree= new CheckboxTreeViewer(composite);
+ fTree.setContentProvider(new WorkbenchContentProvider());
+ fTree.setLabelProvider(new WorkbenchLabelProvider());
+ fTree.setInput(SearchPlugin.getWorkspace().getRoot());
+
+ GridData gd= new GridData(GridData.FILL_BOTH | GridData.GRAB_VERTICAL);
+ gd.heightHint= SIZING_SELECTION_WIDGET_HEIGHT;
+ fTree.getControl().setLayoutData(gd);
+
+ if (fWorkingSet != null)
+ fTree.setCheckedElements(fWorkingSet.getResources());
+
+ return composite;
+ }
+
+ /*
+ * Overrides method from Dialog
+ */
+ protected void okPressed() {
+ if (fWorkingSet == null)
+ fWorkingSet= new WorkingSet(getText().getText(), fTree.getCheckedElements());
+ else {
+ if (fWorkingSet instanceof WorkingSet) {
+ ((WorkingSet)fWorkingSet).setName(getText().getText());
+ ((WorkingSet)fWorkingSet).setResources(fTree.getCheckedElements());
+ }
+ }
+
+ super.okPressed();
+ }
+
+ public IWorkingSet getWorkingSet() {
+ return fWorkingSet;
+ }
+}
diff --git a/org.eclipse.search/search/org/eclipse/search/internal/workingsets/WorkingSetSelectionDialog.java b/org.eclipse.search/search/org/eclipse/search/internal/workingsets/WorkingSetSelectionDialog.java
new file mode 100644
index 000000000..c43689f0c
--- /dev/null
+++ b/org.eclipse.search/search/org/eclipse/search/internal/workingsets/WorkingSetSelectionDialog.java
@@ -0,0 +1,255 @@
+/*
+ * (c) Copyright IBM Corp. 2000, 2001.
+ * All Rights Reserved.
+ */
+package org.eclipse.search.internal.workingsets;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Iterator;
+import java.util.List;
+
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Shell;
+
+import org.eclipse.jface.dialogs.IDialogConstants;
+import org.eclipse.jface.util.Assert;
+import org.eclipse.jface.viewers.DoubleClickEvent;
+import org.eclipse.jface.viewers.IDoubleClickListener;
+import org.eclipse.jface.viewers.ILabelProvider;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.ISelectionChangedListener;
+import org.eclipse.jface.viewers.IStructuredContentProvider;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.viewers.LabelProvider;
+import org.eclipse.jface.viewers.SelectionChangedEvent;
+import org.eclipse.jface.viewers.StructuredSelection;
+import org.eclipse.jface.viewers.TableViewer;
+
+import org.eclipse.ui.dialogs.SelectionDialog;
+
+import org.eclipse.search.internal.ui.util.ListContentProvider;
+import org.eclipse.search.ui.IWorkingSet;
+
+public class WorkingSetSelectionDialog extends SelectionDialog {
+
+ private static class WorkingSetLabelProvider extends LabelProvider {
+ public String getText(Object workingSet) {
+ Assert.isTrue(workingSet instanceof IWorkingSet);
+ return ((IWorkingSet)workingSet).getName();
+ }
+
+// public Image getImage(Object workingSet) {
+// return null;
+// }
+ }
+
+ // sizing constants
+ private final static int SIZING_SELECTION_WIDGET_HEIGHT= 250;
+ private final static int SIZING_SELECTION_WIDGET_WIDTH= 300;
+
+ // Providers for populating this dialog
+ private ILabelProvider fLabelProvider;
+ private IStructuredContentProvider fContentProvider;
+
+ // The visual selection widget group
+ private TableViewer fListViewer;
+
+ // Modify buttons
+ private Button fNewButton;
+ private Button fDetailsButton;
+ private Button fRemoveButton;
+
+ private IWorkingSet fResult;
+
+ /**
+ * Creates a working set selection dialog.
+ *
+ * @param parentShell the parent shell
+ */
+ public WorkingSetSelectionDialog(Shell parentShell) {
+ super(parentShell);
+ setTitle("Working Sets"); //$NON-NLS-1$
+ fContentProvider= new ListContentProvider();
+ fLabelProvider= new WorkingSetLabelProvider();
+ setMessage("Select a working set."); //$NON-NLS-1$
+
+ }
+
+ /**
+ * Add the modify buttons to the dialog.
+ */
+ private void addModifyButtons(Composite composite) {
+
+ Composite buttonComposite= new Composite(composite, SWT.RIGHT);
+ GridLayout layout= new GridLayout();
+ layout.numColumns= 2;
+ buttonComposite.setLayout(layout);
+ GridData data =
+ new GridData(GridData.HORIZONTAL_ALIGN_END | GridData.GRAB_HORIZONTAL);
+ data.grabExcessHorizontalSpace= true;
+ composite.setData(data);
+
+ int id= IDialogConstants.CLIENT_ID + 1;
+ fNewButton= createButton(buttonComposite, id++, "New...", false);
+ fNewButton.addSelectionListener(new SelectionAdapter() {
+ public void widgetSelected(SelectionEvent e) {
+ WorkingSetDialog dlg= new WorkingSetDialog(getShell());
+ if (dlg.open() == dlg.OK) {
+ fListViewer.add(dlg.getWorkingSet());
+ fListViewer.setSelection(new StructuredSelection(dlg.getWorkingSet()), true);
+ WorkingSet.add(dlg.getWorkingSet());
+ }
+ }
+ });
+
+ fDetailsButton= createButton(buttonComposite, id++, "Details...", false);
+ fDetailsButton.addSelectionListener(new SelectionAdapter() {
+ public void widgetSelected(SelectionEvent e) {
+ WorkingSetDialog dlg= new WorkingSetDialog(getShell(), getWorkingSet());
+ if (dlg.open() == dlg.OK)
+ fListViewer.update(dlg.getWorkingSet(), null);
+ }
+ });
+
+ fRemoveButton= createButton(buttonComposite, id++, "Remove", false);
+ fRemoveButton.addSelectionListener(new SelectionAdapter() {
+ public void widgetSelected(SelectionEvent e) {
+ removeSelectedWorkingSets();
+ }
+ });
+ }
+
+ /**
+ * Visually checks the previously-specified elements in this dialog's list
+ * viewer.
+ */
+ private void checkInitialSelections() {
+ fListViewer.setSelection(new StructuredSelection(getInitialSelections()), true);
+ }
+
+ /*
+ * Overrides method from Window.
+ */
+ protected void configureShell(Shell shell) {
+ super.configureShell(shell);
+ // XXX: Needs help
+// WorkbenchHelp.setHelp(shell, new Object[] {IHelpContextIds.LIST_SELECTION_DIALOG});
+ }
+
+ /*
+ * Overrides method from Dialog.
+ */
+ protected Control createDialogArea(Composite parent) {
+ // page group
+ Composite composite= (Composite)super.createDialogArea(parent);
+
+ createMessageArea(composite);
+
+ fListViewer= new TableViewer(composite, SWT.BORDER | SWT.MULTI);
+ GridData data= new GridData(GridData.FILL_BOTH);
+ data.heightHint= SIZING_SELECTION_WIDGET_HEIGHT;
+ data.widthHint= SIZING_SELECTION_WIDGET_WIDTH;
+ fListViewer.getTable().setLayoutData(data);
+
+ fListViewer.setLabelProvider(fLabelProvider);
+ fListViewer.setContentProvider(fContentProvider);
+
+ fListViewer.addSelectionChangedListener(new ISelectionChangedListener() {
+ public void selectionChanged(SelectionChangedEvent event) {
+ handleSelectionChanged();
+ }
+ });
+
+ fListViewer.addDoubleClickListener(new IDoubleClickListener() {
+ public void doubleClick(DoubleClickEvent event) {
+ okPressed();
+ }
+ });
+
+ addModifyButtons(composite);
+ initializeViewer();
+
+ return composite;
+ }
+
+ protected Control createContents(Composite parent) {
+ Control control= super.createContents(parent);
+ if (getInitialSelections() != null && !getInitialSelections().isEmpty())
+ checkInitialSelections();
+ updateButtonAvailability();
+
+ return control;
+ }
+
+ /**
+ * Initializes this dialog's viewer after it has been laid out.
+ */
+ private void initializeViewer() {
+ fListViewer.setInput(Arrays.asList(WorkingSet.getWorkingSets()));
+ }
+
+ /*
+ * Overrides method from Dialog
+ */
+ protected void okPressed() {
+ List result= new ArrayList(1);
+ fResult= getSelectedWorkingSet();
+ if (fResult != null)
+ result.add(fResult);
+ setResult(result);
+ super.okPressed();
+ }
+
+ private void handleSelectionChanged() {
+ updateButtonAvailability();
+ fResult= getSelectedWorkingSet();
+ }
+
+ private void updateButtonAvailability() {
+ ISelection selection= fListViewer.getSelection();
+ boolean hasSelection= selection != null && !selection.isEmpty();
+ fRemoveButton.setEnabled(hasSelection);
+ boolean hasSingleSelection= hasSelection;
+ if (hasSelection && selection instanceof IStructuredSelection)
+ hasSingleSelection= ((IStructuredSelection)selection).size() == 1;
+ fDetailsButton.setEnabled(hasSingleSelection);
+ getOkButton().setEnabled(hasSingleSelection);
+ }
+
+ private void removeSelectedWorkingSets() {
+ List result= new ArrayList(1);
+ ISelection selection= fListViewer.getSelection();
+ if (selection instanceof IStructuredSelection) {
+ Iterator iter= ((IStructuredSelection)selection).iterator();
+ while (iter.hasNext())
+ WorkingSet.remove(((IWorkingSet)iter.next()));
+ fListViewer.remove(((IStructuredSelection)selection).toArray());
+ }
+ }
+
+ /**
+ * Returns the selected working set, or <code>null</code> if
+ * the selection was canceled.
+ *
+ * @return the selected <code>IWorkingSet</code> or <code>null</code> if Cancel was pressed
+ */
+ public IWorkingSet getWorkingSet() {
+ return fResult;
+ }
+
+
+ private IWorkingSet getSelectedWorkingSet() {
+ ISelection selection= fListViewer.getSelection();
+ if (selection instanceof IStructuredSelection)
+ return (IWorkingSet)((IStructuredSelection)selection).getFirstElement();
+ return null;
+ }
+}
diff --git a/org.eclipse.search/search/org/eclipse/search/ui/SearchUI.java b/org.eclipse.search/search/org/eclipse/search/ui/SearchUI.java
index b093d1642..aef466a97 100644
--- a/org.eclipse.search/search/org/eclipse/search/ui/SearchUI.java
+++ b/org.eclipse.search/search/org/eclipse/search/ui/SearchUI.java
@@ -13,6 +13,7 @@ import org.eclipse.ui.dialogs.SelectionDialog;
import org.eclipse.search.internal.ui.SearchPlugin;
import org.eclipse.search.internal.ui.SearchPluginImages;
+import org.eclipse.search.internal.workingsets.WorkingSetSelectionDialog;
/**
* The central class for access to the Search Plug-in's User Interface.
@@ -114,7 +115,7 @@ public final class SearchUI {
* @return a new selection dialog or <code>null</code> if none available
*/
public static SelectionDialog createWorkingSetDialog(Shell parent) {
- return SearchPlugin.createWorkingSetDialog(parent);
+ return new WorkingSetSelectionDialog(parent);
}
/**

Back to the top