Revision 5aeccadc
Added by Katja Luther over 6 years ago
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/dialog/selection/SearchDialog.java | ||
---|---|---|
17 | 17 |
import java.util.Comparator; |
18 | 18 |
import java.util.List; |
19 | 19 |
|
20 |
import org.eclipse.core.commands.AbstractHandler; |
|
21 |
import org.eclipse.core.commands.ExecutionEvent; |
|
22 |
import org.eclipse.core.commands.IHandler; |
|
23 | 20 |
import org.eclipse.core.runtime.Assert; |
24 | 21 |
import org.eclipse.core.runtime.CoreException; |
25 | 22 |
import org.eclipse.core.runtime.IProgressMonitor; |
... | ... | |
27 | 24 |
import org.eclipse.core.runtime.ListenerList; |
28 | 25 |
import org.eclipse.core.runtime.Status; |
29 | 26 |
import org.eclipse.core.runtime.jobs.Job; |
30 |
import org.eclipse.jface.action.IMenuManager; |
|
31 | 27 |
import org.eclipse.jface.action.LegacyActionTools; |
32 | 28 |
import org.eclipse.jface.action.MenuManager; |
33 | 29 |
import org.eclipse.jface.dialogs.Dialog; |
... | ... | |
54 | 50 |
import org.eclipse.swt.accessibility.AccessibleEvent; |
55 | 51 |
import org.eclipse.swt.events.ModifyEvent; |
56 | 52 |
import org.eclipse.swt.events.ModifyListener; |
57 |
import org.eclipse.swt.events.SelectionAdapter; |
|
58 |
import org.eclipse.swt.events.SelectionEvent; |
|
59 | 53 |
import org.eclipse.swt.events.TraverseEvent; |
60 | 54 |
import org.eclipse.swt.events.TraverseListener; |
61 | 55 |
import org.eclipse.swt.graphics.Color; |
... | ... | |
65 | 59 |
import org.eclipse.swt.graphics.Rectangle; |
66 | 60 |
import org.eclipse.swt.layout.GridData; |
67 | 61 |
import org.eclipse.swt.layout.GridLayout; |
62 |
import org.eclipse.swt.widgets.Button; |
|
68 | 63 |
import org.eclipse.swt.widgets.Composite; |
69 | 64 |
import org.eclipse.swt.widgets.Control; |
70 | 65 |
import org.eclipse.swt.widgets.Display; |
71 | 66 |
import org.eclipse.swt.widgets.Event; |
72 | 67 |
import org.eclipse.swt.widgets.Label; |
73 |
import org.eclipse.swt.widgets.Menu; |
|
74 | 68 |
import org.eclipse.swt.widgets.Shell; |
75 | 69 |
import org.eclipse.swt.widgets.Table; |
76 | 70 |
import org.eclipse.swt.widgets.Text; |
77 | 71 |
import org.eclipse.swt.widgets.ToolBar; |
78 |
import org.eclipse.swt.widgets.ToolItem; |
|
79 | 72 |
import org.eclipse.ui.IWorkbenchPreferenceConstants; |
80 | 73 |
import org.eclipse.ui.PlatformUI; |
81 | 74 |
import org.eclipse.ui.dialogs.FilteredItemsSelectionDialog; |
82 |
import org.eclipse.ui.handlers.IHandlerService; |
|
83 | 75 |
import org.eclipse.ui.internal.IWorkbenchGraphicConstants; |
84 | 76 |
import org.eclipse.ui.internal.WorkbenchImages; |
85 | 77 |
import org.eclipse.ui.internal.WorkbenchMessages; |
... | ... | |
101 | 93 |
private TableViewer list; |
102 | 94 |
private Text searchField; |
103 | 95 |
private String title; |
96 |
protected Button newButton1; |
|
97 |
|
|
98 |
|
|
99 |
protected Button newButton2; |
|
100 |
protected Button filterButton; |
|
104 | 101 |
private StructuredSelection currentSelection; |
105 | 102 |
|
106 | 103 |
// message to show user |
... | ... | |
112 | 109 |
private final RefreshCacheJob refreshCacheJob; |
113 | 110 |
|
114 | 111 |
private ToolBar toolBar; |
115 |
private ToolItem toolItem; |
|
116 | 112 |
private MenuManager menuManager; |
113 |
|
|
114 |
protected Object preferenceID; |
|
115 |
|
|
116 |
protected final int new_id = 4; |
|
117 |
protected final int new_id2 = 5; |
|
117 | 118 |
// Need to keep our own list of listeners |
118 | 119 |
private final ListenerList listeners = new ListenerList(); |
119 | 120 |
|
... | ... | |
126 | 127 |
contentProvider = new ContentProvider(); |
127 | 128 |
refreshCacheJob = new RefreshCacheJob(); |
128 | 129 |
|
130 |
|
|
129 | 131 |
} |
130 | 132 |
|
131 | 133 |
|
... | ... | |
144 | 146 |
|
145 | 147 |
final Label headerLabel = createHeader(container); |
146 | 148 |
|
147 |
searchField = new Text(container, SWT.SINGLE | SWT.BORDER | SWT.SEARCH | SWT.ICON_CANCEL); |
|
149 |
Composite searchAndFilter = new Composite(container, container.getStyle()); |
|
150 |
// GridData gd_searchAndFilter = new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1); |
|
151 |
GridData gd_searchAndFilter =new GridData(GridData.GRAB_HORIZONTAL | GridData.HORIZONTAL_ALIGN_FILL); |
|
152 |
// gd_searchAndFilter.widthHint = 576; |
|
153 |
searchAndFilter.setLayoutData(gd_searchAndFilter); |
|
154 |
GridLayout searchAndFilterLayout = new GridLayout(); |
|
155 |
searchAndFilterLayout.numColumns = 2; |
|
156 |
searchAndFilter.setLayout(searchAndFilterLayout); |
|
157 |
searchField = new Text(searchAndFilter, SWT.SINGLE | SWT.BORDER | SWT.SEARCH | SWT.ICON_CANCEL); |
|
148 | 158 |
searchField.getAccessible().addAccessibleListener(new AccessibleAdapter() { |
149 | 159 |
@Override |
150 | 160 |
public void getName(AccessibleEvent e) { |
... | ... | |
164 | 174 |
} |
165 | 175 |
} |
166 | 176 |
}); |
167 |
gd_1 = new GridData(GridData.FILL_HORIZONTAL); |
|
168 |
gd_1.horizontalIndent = 2; |
|
169 |
gd_1.horizontalAlignment = SWT.CENTER; |
|
170 |
gd_1.widthHint = 575; |
|
177 |
gd_1 = new GridData(GridData.GRAB_HORIZONTAL | GridData.HORIZONTAL_ALIGN_FILL); |
|
178 |
|
|
179 |
// gd_1.horizontalIndent = 2; |
|
180 |
// gd_1.horizontalAlignment = SWT.CENTER; |
|
181 |
// gd_1.grabExcessHorizontalSpace = true; |
|
182 |
// gd_1.widthHint = 500; |
|
171 | 183 |
searchField.setLayoutData(gd_1); |
172 | 184 |
|
185 |
createFilterButton(searchAndFilter); |
|
173 | 186 |
setList(new TableViewer(container, SWT.SINGLE |
174 | 187 |
| SWT.BORDER | SWT.V_SCROLL | SWT.VIRTUAL)); |
175 | 188 |
|
... | ... | |
191 | 204 |
okPressed(); |
192 | 205 |
} |
193 | 206 |
}); |
194 |
createExtendedContentArea(container); |
|
207 |
// createExtendedContentArea(container); |
|
208 |
new Label(container, SWT.NONE); |
|
195 | 209 |
|
196 | 210 |
return container; |
197 | 211 |
} |
198 | 212 |
|
213 |
|
|
214 |
abstract void createFilterButton(Composite searchAndFilter) ; |
|
215 |
|
|
199 | 216 |
protected abstract void search(); |
200 | 217 |
|
201 | 218 |
/** |
... | ... | |
205 | 222 |
* parent to create the dialog widgets in |
206 | 223 |
* @return an extra content area |
207 | 224 |
*/ |
208 |
protected abstract Control createExtendedContentArea(Composite parent); |
|
225 |
// protected abstract Control createExtendedContentArea(Composite parent);
|
|
209 | 226 |
|
210 | 227 |
/** |
211 | 228 |
* Sets the title for this dialog. |
... | ... | |
225 | 242 |
*/ |
226 | 243 |
private Label createHeader(Composite parent) { |
227 | 244 |
Composite header = new Composite(parent, SWT.NONE); |
228 |
GridData gd_header = new GridData(SWT.CENTER, SWT.CENTER, false, false, 1, 1);
|
|
245 |
GridData gd_header = new GridData(SWT.CENTER, SWT.CENTER, false, false, 2, 1);
|
|
229 | 246 |
gd_header.widthHint = 575; |
230 | 247 |
header.setLayoutData(gd_header); |
231 | 248 |
|
... | ... | |
234 | 251 |
layout.marginWidth = 0; |
235 | 252 |
layout.marginHeight = 0; |
236 | 253 |
header.setLayout(layout); |
237 |
|
|
238 |
createViewMenu(header); |
|
239 |
|
|
254 |
new Label(header, SWT.NONE); |
|
240 | 255 |
Label headerLabel = new Label(header, SWT.NONE); |
241 | 256 |
headerLabel.setText((getMessage() != null && getMessage().trim() |
242 | 257 |
.length() > 0) ? getMessage() |
... | ... | |
256 | 271 |
gd_headerLabel.verticalAlignment = SWT.BOTTOM; |
257 | 272 |
gd_headerLabel.minimumHeight = 10; |
258 | 273 |
headerLabel.setLayoutData(gd_headerLabel); |
259 |
new Label(header, SWT.NONE); |
|
260 |
|
|
261 | 274 |
return headerLabel; |
262 | 275 |
} |
263 | 276 |
|
... | ... | |
285 | 298 |
} |
286 | 299 |
return itemsListLabelProvider; |
287 | 300 |
} |
288 |
private void createViewMenu(Composite parent) { |
|
289 |
toolBar = new ToolBar(parent, SWT.FLAT); |
|
290 |
toolItem = new ToolItem(toolBar, SWT.PUSH, 0); |
|
291 |
|
|
292 |
GridData data = new GridData(); |
|
293 |
data.horizontalAlignment = GridData.END; |
|
294 |
data.grabExcessHorizontalSpace = true; |
|
295 |
toolBar.setLayoutData(data); |
|
296 |
|
|
297 |
// toolBar.addMouseListener(new MouseAdapter() { |
|
301 |
// private void createViewMenu(Composite parent) { |
|
302 |
// toolBar = new ToolBar(parent, SWT.FLAT); |
|
303 |
// |
|
304 |
// GridData data = new GridData(); |
|
305 |
// data.horizontalAlignment = GridData.END; |
|
306 |
// data.grabExcessHorizontalSpace = true; |
|
307 |
// toolBar.setLayoutData(data); |
|
308 |
// |
|
309 |
// menuManager = new MenuManager(); |
|
310 |
// |
|
311 |
// fillViewMenu(menuManager); |
|
312 |
// |
|
313 |
// IHandlerService service = PlatformUI.getWorkbench() |
|
314 |
// .getService(IHandlerService.class); |
|
315 |
// IHandler handler = new AbstractHandler() { |
|
298 | 316 |
// @Override |
299 |
// public void mouseDown(MouseEvent e) {
|
|
317 |
// public Object execute(ExecutionEvent event) {
|
|
300 | 318 |
// showViewMenu(); |
319 |
// return null; |
|
301 | 320 |
// } |
302 |
// }); |
|
321 |
// }; |
|
322 |
// } |
|
323 |
|
|
324 |
// /** |
|
325 |
// * Fills the menu of the dialog. |
|
326 |
// * |
|
327 |
// * @param menuManager |
|
328 |
// * the menu manager |
|
329 |
// */ |
|
330 |
// protected void fillViewMenu(IMenuManager menuManager) { |
|
331 |
// |
|
332 |
// } |
|
333 |
|
|
334 |
// private void showViewMenu() { |
|
335 |
// Menu menu = menuManager.createContextMenu(getShell()); |
|
336 |
// Rectangle bounds = toolItem.getBounds(); |
|
337 |
// Point topLeft = new Point(bounds.x, bounds.y + bounds.height); |
|
338 |
// topLeft = toolBar.toDisplay(topLeft); |
|
339 |
// menu.setLocation(topLeft.x, topLeft.y); |
|
340 |
// menu.setVisible(true); |
|
341 |
// } |
|
303 | 342 |
|
304 |
toolItem.setImage(WorkbenchImages |
|
305 |
.getImage(IWorkbenchGraphicConstants.IMG_LCL_VIEW_MENU)); |
|
306 |
toolItem |
|
307 |
.setToolTipText(WorkbenchMessages.FilteredItemsSelectionDialog_menu); |
|
308 |
toolItem.addSelectionListener(new SelectionAdapter() { |
|
309 |
@Override |
|
310 |
public void widgetSelected(SelectionEvent e) { |
|
311 |
showViewMenu(); |
|
312 |
} |
|
313 |
}); |
|
343 |
public TableViewer getList() { |
|
344 |
return list; |
|
345 |
} |
|
314 | 346 |
|
315 |
menuManager = new MenuManager(); |
|
347 |
public void setList(TableViewer list) { |
|
348 |
this.list = list; |
|
349 |
Table table = list.getTable(); |
|
350 |
GridData gd_table = new GridData(SWT.CENTER, SWT.CENTER, true, true, 2, 1); |
|
351 |
gd_table.heightHint = 231; |
|
352 |
gd_table.widthHint = 543; |
|
353 |
table.setLayoutData(gd_table); |
|
354 |
} |
|
316 | 355 |
|
317 |
fillViewMenu(menuManager); |
|
356 |
public Button getNewButton1() { |
|
357 |
return newButton1; |
|
358 |
} |
|
318 | 359 |
|
319 |
IHandlerService service = PlatformUI.getWorkbench() |
|
320 |
.getService(IHandlerService.class); |
|
321 |
IHandler handler = new AbstractHandler() { |
|
322 |
@Override |
|
323 |
public Object execute(ExecutionEvent event) { |
|
324 |
showViewMenu(); |
|
325 |
return null; |
|
326 |
} |
|
327 |
}; |
|
360 |
|
|
361 |
public void setNewButton1(Button newButton1) { |
|
362 |
this.newButton1 = newButton1; |
|
328 | 363 |
} |
329 | 364 |
|
330 |
/** |
|
331 |
* Fills the menu of the dialog. |
|
332 |
* |
|
333 |
* @param menuManager |
|
334 |
* the menu manager |
|
335 |
*/ |
|
336 |
protected void fillViewMenu(IMenuManager menuManager) { |
|
337 | 365 |
|
366 |
public Button getNewButton2() { |
|
367 |
return newButton2; |
|
338 | 368 |
} |
339 | 369 |
|
340 |
private void showViewMenu() { |
|
341 |
Menu menu = menuManager.createContextMenu(getShell()); |
|
342 |
Rectangle bounds = toolItem.getBounds(); |
|
343 |
Point topLeft = new Point(bounds.x, bounds.y + bounds.height); |
|
344 |
topLeft = toolBar.toDisplay(topLeft); |
|
345 |
menu.setLocation(topLeft.x, topLeft.y); |
|
346 |
menu.setVisible(true); |
|
370 |
|
|
371 |
public void setNewButton2(Button newButton2) { |
|
372 |
this.newButton2 = newButton2; |
|
347 | 373 |
} |
348 | 374 |
|
349 |
public TableViewer getList() { |
|
350 |
return list; |
|
375 |
|
|
376 |
public Button getFilterButton() { |
|
377 |
return filterButton; |
|
351 | 378 |
} |
352 | 379 |
|
353 |
public void setList(TableViewer list) { |
|
354 |
this.list = list; |
|
355 |
Table table = list.getTable(); |
|
356 |
GridData gd_table = new GridData(SWT.CENTER, SWT.CENTER, true, true, 1, 1); |
|
357 |
gd_table.heightHint = 231; |
|
358 |
gd_table.widthHint = 543; |
|
359 |
table.setLayoutData(gd_table); |
|
380 |
|
|
381 |
public void setFilterButton(Button filterButton) { |
|
382 |
this.filterButton = filterButton; |
|
360 | 383 |
} |
361 | 384 |
|
362 | 385 |
/** |
... | ... | |
796 | 819 |
return new Point(593, 399); |
797 | 820 |
} |
798 | 821 |
|
822 |
|
|
823 |
|
|
799 | 824 |
} |
800 | 825 |
|
801 | 826 |
|
Also available in: Unified diff
e4 migration of selection dialogs