View | Details | Raw Unified | Return to bug 187678 | Differences between
and this patch

Collapse All | Expand All

(-)guide/dialogs_FilteredItemsSelectionDialog_example.htm (-2 / +36 lines)
Lines 13-25 Link Here
13
</head>
13
</head>
14
<body>
14
<body>
15
15
16
<h2>Creating a custom filtered item selection dialog</h2>
16
<h2>Creating a custom filtered items selection dialog</h2>
17
<p>In this example, we will contribute a basic search dialog to illustrate the steps 
17
<p>In this example, we will contribute a basic search dialog to illustrate the steps 
18
needed to create a custom subclass of  <a href="../reference/api/org/eclipse/ui/dialogs/FilteredItemsSelectionDialog.html">
18
needed to create a custom subclass of  <a href="../reference/api/org/eclipse/ui/dialogs/FilteredItemsSelectionDialog.html">
19
<b> FilteredItemsSelectionDialog</b></a>.</p>
19
<b> FilteredItemsSelectionDialog</b></a>.</p>
20
20
21
<ol>
21
<ol>
22
	<li>
22
	<li>
23
	Create a new Plug-in Project using Hello, world template. 
24
	</li>
25
	<li>
23
	Create a class extending <em>org.eclipse.ui.dialogs.FilteredItemsSelectionDialog</em>.
26
	Create a class extending <em>org.eclipse.ui.dialogs.FilteredItemsSelectionDialog</em>.
24
	Let's name it <em>FilteredResourcesSelectionDialogExample</em>.
27
	Let's name it <em>FilteredResourcesSelectionDialogExample</em>.
25
	</li>
28
	</li>
Lines 28-33 Link Here
28
	example we will generate our own set of random strings as follows:
31
	example we will generate our own set of random strings as follows:
29
	<pre>
32
	<pre>
30
   private static ArrayList resources = new ArrayList();
33
   private static ArrayList resources = new ArrayList();
34
   
31
   static {
35
   static {
32
      generateRescourcesTestCases('A', 'C', 8, ""); //$NON-NLS-1$
36
      generateRescourcesTestCases('A', 'C', 8, ""); //$NON-NLS-1$
33
      generateRescourcesTestCases('a', 'c', 4, ""); //$NON-NLS-1$
37
      generateRescourcesTestCases('a', 'c', 4, ""); //$NON-NLS-1$
Lines 91-96 Link Here
91
		information about how the dialog information is persisted. This method can't
95
		information about how the dialog information is persisted. This method can't
92
		return null, so we'll just return a simple settings object: 
96
		return null, so we'll just return a simple settings object: 
93
		<pre>
97
		<pre>
98
   private static final String DIALOG_SETTINGS = "FilteredResourcesSelectionDialogExampleSettings";	
99
		
94
   protected IDialogSettings getDialogSettings() {
100
   protected IDialogSettings getDialogSettings() {
95
      	IDialogSettings settings = Activator.getDefault().getDialogSettings()
101
      	IDialogSettings settings = Activator.getDefault().getDialogSettings()
96
				.getSection(DIALOG_SETTINGS);
102
				.getSection(DIALOG_SETTINGS);
Lines 126-132 Link Here
126
132
127
	</ul>
133
	</ul>
128
	</li>
134
	</li>
129
135
	<li>
136
	Add title of dialog and set simple implementation of <em>SelectionHistory</em> on dialog:<pre>
137
	public FilteredResourcesSelectionDialogExample(Shell shell, boolean multi) {
138
	   super(shell, multi);
139
	   setTitle("Filtered Resources Selection Dialog Example");
140
	   setSelectionHistory(new ResourceSelectionHistory());
141
	}
142
	
143
	private class ResourceSelectionHistory extends SelectionHistory {
144
	   protected Object restoreItemFromMemento(IMemento element) {
145
		  return null; 
146
	   }
147
	   protected void storeItemToMemento(Object item, IMemento element) {
148
	   }
149
	}</pre></li>
150
	<li>
151
	Change <em>run(IAction)</em> method from <em>SimpleAction</em> to:<pre>
152
	public void run(IAction action) {
153
	   Shell shell = new Shell();
154
	   FilteredItemsSelectionDialog dialog = new FilteredResourcesSelectionDialogExample(shell, true);
155
	   dialog.setInitialPattern("a");
156
	   dialog.open();
157
	}</pre></li>	
158
	<li>
159
	Change tooltip of SimpleAction from <em>"Hello, Eclipse world"</em> to <em>"Filtered Items Selection Dialog Example"</em>.
160
	</li>
161
	<li>
162
	Run Eclipse with created plug-in.
163
	</li>
130
	<li>
164
	<li>
131
	The resulting dialog looks as follows:
165
	The resulting dialog looks as follows:
132
	<p><img
166
	<p><img
(-)guide/dialogs_FilteredItemsSelectionDialog_example_advanced.htm (-8 / +53 lines)
Lines 13-19 Link Here
13
</head>
13
</head>
14
<body>
14
<body>
15
15
16
<h2>Advanced use of the filtered item selection dialog</h2>
16
<h2>Advanced use of the filtered items selection dialog</h2>
17
17
18
In the <a href="dialogs_FilteredItemsSelectionDialog_example.htm">previous example</a>, 
18
In the <a href="dialogs_FilteredItemsSelectionDialog_example.htm">previous example</a>, 
19
we saw how to create a simple subclass of FilteredItemsSelectionDialog. Now let's 
19
we saw how to create a simple subclass of FilteredItemsSelectionDialog. Now let's 
Lines 28-35 Link Here
28
The dialog can be configured to save and restore the history of items that have
28
The dialog can be configured to save and restore the history of items that have
29
been selected.
29
been selected.
30
<ol>
30
<ol>
31
	<li>Create a subclass of <em>FilteredItemsSelectionDialog.SelectionHistory</em>
31
	<li>In the <a href="dialogs_FilteredItemsSelectionDialog_example.htm">previous part</a> we created a subclass of <em>FilteredItemsSelectionDialog.SelectionHistory</em> but it do nothing.
32
	and implement the abstract methods for saving and loading objects:</li>
32
	Now, we should fill out methods responsible for saving and loading objects:</li>
33
	<pre>
33
	<pre>
34
   private class ResourceSelectionHistory extends SelectionHistory {
34
   private class ResourceSelectionHistory extends SelectionHistory {
35
      /*
35
      /*
Lines 47-56 Link Here
47
      }
47
      }
48
   }</pre>
48
   }</pre>
49
49
50
	<li>On your subclass of FilteredItemsSelectionDialog, define the implementation of SelectionHistory to use. 
50
    <li>Open the dialog.
51
	<pre>
51
    </li>
52
   setSelectionHistory(new ResourceSelectionHistory());
52
    <li>Select listed elements and click OK:
53
  </pre></li>
53
    	<ul>
54
    		<li>
55
    			<em>AbCdEfGh</em>
56
    		</li>
57
    		<li>
58
    			<em>AbCdEfGi</em>
59
    		</li>
60
    		<li>
61
    			<em>AbCdEfGj</em>
62
    		</li>
63
    		<li>
64
    			<em>AbCdEfHh</em>
65
    		</li>
66
    		<li>
67
    			<em>AbCdEfHi</em>
68
    		</li>
69
    		<li>
70
    			<em>AbCdEfHj</em>
71
    		</li>
72
    		<li>
73
    			<em>abCd</em>
74
    		</li>
75
    		<li>
76
    			<em>abCe</em>
77
    		</li>
78
    		<li>
79
    			<em>abCf</em>
80
    		</li>
81
    		<li>
82
    			<em>abDd</em>
83
    		</li>
84
    		<li>
85
    			<em>abDe</em>
86
    		</li>
87
    	</ul>
88
    </li>
54
	<li>Our example dialog now looks like this:
89
	<li>Our example dialog now looks like this:
55
	<p><img
90
	<p><img
56
		src="images/filteredResourcesSelectionDialogExampleAdvance1.png"
91
		src="images/filteredResourcesSelectionDialogExampleAdvance1.png"
Lines 131-136 Link Here
131
   }</pre></li>
166
   }</pre></li>
132
	<li>Next, create a new action and add it to the menu by overriding <em>fillViewMenu(IMenuManager)</em>.
167
	<li>Next, create a new action and add it to the menu by overriding <em>fillViewMenu(IMenuManager)</em>.
133
	Eg.: <pre>
168
	Eg.: <pre>
169
   private Action showOnlyLowerCaseStringsAction = new ShowOnlyLowerCaseStringsAction();
170
   
134
   private class ShowOnlyLowerCaseStringsAction extends Action {
171
   private class ShowOnlyLowerCaseStringsAction extends Action {
135
      /**
172
      /**
136
       * Creates a new instance of the action.
173
       * Creates a new instance of the action.
Lines 145-156 Link Here
145
            applyFilter();
182
            applyFilter();
146
         }
183
         }
147
      }
184
      }
148
   } 
185
   }
186
   
149
   protected void fillViewMenu(IMenuManager menuManager) {
187
   protected void fillViewMenu(IMenuManager menuManager) {
150
      super.fillViewMenu(menuManager);
188
      super.fillViewMenu(menuManager);
151
      menuManager.add(showOnlyLowerCaseStringsAction);
189
      menuManager.add(showOnlyLowerCaseStringsAction);
152
   }
190
   }
153
  </pre></li>
191
  </pre></li>
192
  <li>At the end override <em>applyFilter()</em> as follows:<pre>
193
   protected void applyFilter() {
194
      super.applyFilter();
195
      checkButton.setSelection(onlyLowerCase);
196
      showOnlyLowerCaseStringsAction.setChecked(onlyLowerCase);
197
   }</pre>
198
  </li>
154
199
155
	<li>Now open the dialog: 
200
	<li>Now open the dialog: 
156
	<p><img src="images/filteredResourcesSelectionDialogExampleAdvance3.png"
201
	<p><img src="images/filteredResourcesSelectionDialogExampleAdvance3.png"

Return to bug 187678