### Eclipse Workspace Patch 1.0 #P org.eclipse.platform.doc.isv Index: guide/dialogs_FilteredItemsSelectionDialog_example.htm =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.platform.doc.isv/guide/dialogs_FilteredItemsSelectionDialog_example.htm,v retrieving revision 1.5 diff -u -r1.5 dialogs_FilteredItemsSelectionDialog_example.htm --- guide/dialogs_FilteredItemsSelectionDialog_example.htm 8 Jun 2007 14:20:30 -0000 1.5 +++ guide/dialogs_FilteredItemsSelectionDialog_example.htm 11 Jun 2007 15:45:21 -0000 @@ -13,13 +13,16 @@ -

Creating a custom filtered item selection dialog

+

Creating a custom filtered items selection dialog

In this example, we will contribute a basic search dialog to illustrate the steps needed to create a custom subclass of FilteredItemsSelectionDialog.

  1. + Create a new Plug-in Project using Hello, world template. +
  2. +
  3. Create a class extending org.eclipse.ui.dialogs.FilteredItemsSelectionDialog. Let's name it FilteredResourcesSelectionDialogExample.
  4. @@ -28,6 +31,7 @@ example we will generate our own set of random strings as follows:
        private static ArrayList resources = new ArrayList();
    +   
        static {
           generateRescourcesTestCases('A', 'C', 8, ""); //$NON-NLS-1$
           generateRescourcesTestCases('a', 'c', 4, ""); //$NON-NLS-1$
    @@ -91,6 +95,8 @@
     		information about how the dialog information is persisted. This method can't
     		return null, so we'll just return a simple settings object: 
     		
    +   private static final String DIALOG_SETTINGS = "FilteredResourcesSelectionDialogExampleSettings";	
    +		
        protected IDialogSettings getDialogSettings() {
           	IDialogSettings settings = Activator.getDefault().getDialogSettings()
     				.getSection(DIALOG_SETTINGS);
    @@ -126,7 +132,34 @@
     
     	
     	
    -
    +	
  5. + Add title of dialog and set simple implementation of SelectionHistory on dialog:
    +	public FilteredResourcesSelectionDialogExample(Shell shell, boolean multi) {
    +	   super(shell, multi);
    +	   setTitle("Filtered Resources Selection Dialog Example");
    +	   setSelectionHistory(new ResourceSelectionHistory());
    +	}
    +	
    +	private class ResourceSelectionHistory extends SelectionHistory {
    +	   protected Object restoreItemFromMemento(IMemento element) {
    +		  return null; 
    +	   }
    +	   protected void storeItemToMemento(Object item, IMemento element) {
    +	   }
    +	}
  6. +
  7. + Change run(IAction) method from SimpleAction to:
    +	public void run(IAction action) {
    +	   Shell shell = new Shell();
    +	   Dialog dialog = new FilteredResourcesSelectionDialogExample(shell, true);
    +	   dialog.open();
    +	}
  8. +
  9. + Change tooltip of SimpleAction from "Hello, Eclipse world" to "Filtered Items Selection Dialog Example". +
  10. +
  11. + Run Eclipse with created plug-in. +
  12. The resulting dialog looks as follows:

    -

    Advanced use of the filtered item selection dialog

    +

    Advanced use of the filtered items selection dialog

    In the previous example, we saw how to create a simple subclass of FilteredItemsSelectionDialog. Now let's @@ -49,8 +49,7 @@
  13. On your subclass of FilteredItemsSelectionDialog, define the implementation of SelectionHistory to use.
    -   setSelectionHistory(new ResourceSelectionHistory());
    -  
  14. + setSelectionHistory(new ResourceSelectionHistory());
  15. Our example dialog now looks like this:

  16. Next, create a new action and add it to the menu by overriding fillViewMenu(IMenuManager). Eg.:
    +   private Action showOnlyLowerCaseStringsAction = new ShowOnlyLowerCaseStringsAction();
    +   
        private class ShowOnlyLowerCaseStringsAction extends Action {
           /**
            * Creates a new instance of the action.
    @@ -145,12 +146,20 @@
                 applyFilter();
              }
           }
    -   } 
    +   }
    +   
        protected void fillViewMenu(IMenuManager menuManager) {
           super.fillViewMenu(menuManager);
           menuManager.add(showOnlyLowerCaseStringsAction);
        }
       
  17. +
  18. At the end override applyFilter() as follows:
    +   protected void applyFilter() {
    +      super.applyFilter();
    +      checkButton.setSelection(onlyLowerCase);
    +      showOnlyLowerCaseStringsAction.setChecked(onlyLowerCase);
    +   }
    +
  19. Now open the dialog: