Revision 3be6ef3e
Added by Niels Hoffmann over 13 years ago
taxeditor-bulkeditor/src/main/java/eu/etaxonomy/taxeditor/bulkeditor/BulkEditorSearchComposite.java | ||
---|---|---|
1 |
// $Id$ |
|
2 |
/** |
|
3 |
* Copyright (C) 2007 EDIT |
|
4 |
* European Distributed Institute of Taxonomy |
|
5 |
* http://www.e-taxonomy.eu |
|
6 |
* |
|
7 |
* The contents of this file are subject to the Mozilla Public License Version 1.1 |
|
8 |
* See LICENSE.TXT at the top of this package for the full license terms. |
|
9 |
*/ |
|
10 |
|
|
11 |
package eu.etaxonomy.taxeditor.bulkeditor; |
|
12 |
|
|
13 |
import java.util.Comparator; |
|
14 |
|
|
15 |
import org.apache.log4j.Logger; |
|
16 |
import org.eclipse.swt.SWT; |
|
17 |
import org.eclipse.swt.events.FocusEvent; |
|
18 |
import org.eclipse.swt.events.FocusListener; |
|
19 |
import org.eclipse.swt.events.KeyAdapter; |
|
20 |
import org.eclipse.swt.events.KeyEvent; |
|
21 |
import org.eclipse.swt.events.SelectionAdapter; |
|
22 |
import org.eclipse.swt.events.SelectionEvent; |
|
23 |
import org.eclipse.swt.events.SelectionListener; |
|
24 |
import org.eclipse.swt.graphics.Point; |
|
25 |
import org.eclipse.swt.graphics.Rectangle; |
|
26 |
import org.eclipse.swt.layout.GridData; |
|
27 |
import org.eclipse.swt.layout.GridLayout; |
|
28 |
import org.eclipse.swt.widgets.Composite; |
|
29 |
import org.eclipse.swt.widgets.Menu; |
|
30 |
import org.eclipse.swt.widgets.MenuItem; |
|
31 |
import org.eclipse.swt.widgets.Text; |
|
32 |
import org.eclipse.swt.widgets.ToolBar; |
|
33 |
import org.eclipse.swt.widgets.ToolItem; |
|
34 |
import org.eclipse.ui.IEditorInput; |
|
35 |
import org.eclipse.ui.IEditorPart; |
|
36 |
import org.eclipse.ui.PlatformUI; |
|
37 |
import org.eclipse.ui.swt.IFocusService; |
|
38 |
|
|
39 |
import eu.etaxonomy.cdm.api.service.config.IIdentifiableEntityServiceConfigurator; |
|
40 |
import eu.etaxonomy.cdm.api.service.config.impl.IdentifiableServiceConfiguratorImpl; |
|
41 |
import eu.etaxonomy.taxeditor.bulkeditor.input.AbstractBulkEditorInput; |
|
42 |
import eu.etaxonomy.taxeditor.preference.Resources; |
|
43 |
|
|
44 |
/** |
|
45 |
* @author p.ciardelli |
|
46 |
* @author e.-m.lee |
|
47 |
* @created 17.08.2009 |
|
48 |
* @version 1.0 |
|
49 |
*/ |
|
50 |
public class BulkEditorSearchComposite extends Composite { |
|
51 |
private static final Logger logger = Logger.getLogger(BulkEditorSearchComposite.class); |
|
52 |
|
|
53 |
private IEditorPart editor; |
|
54 |
private IBulkEditorSortMenuProvider menuProvider; |
|
55 |
private Menu sortMenu; |
|
56 |
private Text text; |
|
57 |
private static final String DEFAULT_TEXT = "Use \"*\" for wildcard searching"; |
|
58 |
public Object ORDER_BY = new Object(); |
|
59 |
private ToolItem toolItem; |
|
60 |
|
|
61 |
/** |
|
62 |
* @param parent |
|
63 |
* @param style |
|
64 |
*/ |
|
65 |
public BulkEditorSearchComposite(IEditorPart editor, Composite parent, int style) { |
|
66 |
super(parent, style); |
|
67 |
this.editor = editor; |
|
68 |
this.menuProvider = new BulkEditorSortMenuProvider(); |
|
69 |
|
|
70 |
createControl(); |
|
71 |
} |
|
72 |
|
|
73 |
/* |
|
74 |
* Creates the search control. |
|
75 |
*/ |
|
76 |
protected void createControl() { |
|
77 |
createLayout(); |
|
78 |
createSearchTextField(); |
|
79 |
createToolBar(); |
|
80 |
registerAtFocusService(); |
|
81 |
setSearchEnabled(false); |
|
82 |
} |
|
83 |
|
|
84 |
|
|
85 |
/** |
|
86 |
* Handles focus changes for the textfield. |
|
87 |
*/ |
|
88 |
private void registerAtFocusService() { |
|
89 |
IFocusService focusService = |
|
90 |
(IFocusService) PlatformUI.getWorkbench().getService(IFocusService.class); |
|
91 |
if (focusService != null) { |
|
92 |
focusService.addFocusTracker(text, "bulkeditor.textControlId"); |
|
93 |
} |
|
94 |
} |
|
95 |
|
|
96 |
|
|
97 |
/** |
|
98 |
* Creates the search toolbar. |
|
99 |
*/ |
|
100 |
private void createToolBar() { |
|
101 |
final ToolBar toolBar = new ToolBar(this, SWT.NULL); |
|
102 |
|
|
103 |
toolItem = new ToolItem(toolBar, SWT.DROP_DOWN | SWT.BORDER); |
|
104 |
toolItem.setText("Search"); |
|
105 |
|
|
106 |
DropdownMenu dropdownMenu = new DropdownMenu(toolItem); |
|
107 |
toolItem.addSelectionListener(dropdownMenu); |
|
108 |
} |
|
109 |
|
|
110 |
|
|
111 |
/** |
|
112 |
* Creates the search textfield. |
|
113 |
*/ |
|
114 |
private void createSearchTextField() { |
|
115 |
text = new Text(this, SWT.BORDER | SWT.SINGLE | SWT.FULL_SELECTION); |
|
116 |
text.setText(DEFAULT_TEXT); |
|
117 |
text.setForeground(BulkEditorUtil.getColor(Resources.SEARCH_VIEW_FOREGROUND)); |
|
118 |
|
|
119 |
text.addFocusListener(new FocusListener() { |
|
120 |
|
|
121 |
public void focusGained(FocusEvent e) { |
|
122 |
text.setForeground(BulkEditorUtil.getColor(Resources.SEARCH_VIEW_FOCUS)); |
|
123 |
if (DEFAULT_TEXT.equals(text.getText())) { |
|
124 |
text.setText(""); |
|
125 |
} |
|
126 |
} |
|
127 |
|
|
128 |
public void focusLost(FocusEvent e) { |
|
129 |
if (text.getText() == "") { |
|
130 |
text.setForeground(BulkEditorUtil.getColor(Resources.SEARCH_VIEW_FOREGROUND)); |
|
131 |
text.setText(DEFAULT_TEXT); |
|
132 |
setSearchEnabled(false); |
|
133 |
} else { |
|
134 |
setSearchEnabled(true); |
|
135 |
} |
|
136 |
} |
|
137 |
}); |
|
138 |
|
|
139 |
text.addKeyListener(new KeyAdapter() { |
|
140 |
/* (non-Javadoc) |
|
141 |
* @see org.eclipse.swt.events.KeyAdapter#keyReleased(org.eclipse.swt.events.KeyEvent) |
|
142 |
*/ |
|
143 |
@Override |
|
144 |
public void keyReleased(KeyEvent e) { |
|
145 |
if (e.keyCode == SWT.CR) { |
|
146 |
updateEditorInput(); |
|
147 |
} |
|
148 |
} |
|
149 |
}); |
|
150 |
|
|
151 |
GridData gridData = new GridData(SWT.FILL, SWT.TOP, true, false); |
|
152 |
text.setLayoutData(gridData); |
|
153 |
} |
|
154 |
|
|
155 |
|
|
156 |
/** |
|
157 |
* Creates the search layout. |
|
158 |
*/ |
|
159 |
private void createLayout() { |
|
160 |
GridLayout gridLayout = new GridLayout(); |
|
161 |
gridLayout.numColumns = 3; |
|
162 |
gridLayout.marginHeight = 0; |
|
163 |
gridLayout.marginWidth = 12; |
|
164 |
setLayout(gridLayout); |
|
165 |
} |
|
166 |
|
|
167 |
/* |
|
168 |
* Toggles the availability of the search toolItem. |
|
169 |
*/ |
|
170 |
private void setSearchEnabled(boolean enabled) { |
|
171 |
// toolItem.setEnabled(enabled); |
|
172 |
} |
|
173 |
|
|
174 |
/* |
|
175 |
* Shows the results of the search. |
|
176 |
*/ |
|
177 |
private void updateEditorInput() { |
|
178 |
|
|
179 |
String searchString = getSearchString(); |
|
180 |
|
|
181 |
if(!DEFAULT_TEXT.equals(searchString.trim()) && searchString.length() > 0){ |
|
182 |
// update query in IEditorInput |
|
183 |
IEditorInput input = editor.getEditorInput(); |
|
184 |
if (input instanceof AbstractBulkEditorInput) { |
|
185 |
((AbstractBulkEditorInput) input).setQuery(new BulkEditorQuery(getSearchString(), getComparator())); |
|
186 |
} |
|
187 |
} |
|
188 |
} |
|
189 |
|
|
190 |
/* |
|
191 |
* Handles drop down menu selection. |
|
192 |
*/ |
|
193 |
class DropdownMenu extends SelectionAdapter { |
|
194 |
|
|
195 |
/** |
|
196 |
* @param dropdown |
|
197 |
*/ |
|
198 |
public DropdownMenu(ToolItem dropdown) { |
|
199 |
sortMenu = new Menu(dropdown.getParent().getShell()); |
|
200 |
|
|
201 |
MenuItem menuItem = new MenuItem(sortMenu, SWT.PUSH); |
|
202 |
menuItem.setText("Order by:"); |
|
203 |
menuItem.setData(ORDER_BY); |
|
204 |
new MenuItem(sortMenu, SWT.SEPARATOR); |
|
205 |
|
|
206 |
menuProvider.fillMenu(editor.getEditorInput(), sortMenu); |
|
207 |
|
|
208 |
SelectionListener listener = new SortListSelectionListener(); |
|
209 |
|
|
210 |
for (MenuItem item : sortMenu.getItems()) { |
|
211 |
if (item.getData() instanceof Comparator) { |
|
212 |
item.addSelectionListener(listener); |
|
213 |
} |
|
214 |
} |
|
215 |
} |
|
216 |
|
|
217 |
/* (non-Javadoc) |
|
218 |
* @see org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse.swt.events.SelectionEvent) |
|
219 |
*/ |
|
220 |
public void widgetSelected(SelectionEvent event) { |
|
221 |
if (event.detail == SWT.ARROW) { |
|
222 |
ToolItem item = (ToolItem) event.widget; |
|
223 |
Rectangle rect = item.getBounds(); |
|
224 |
Point pt = item.getParent().toDisplay(new Point(rect.x, rect.y)); |
|
225 |
sortMenu.setLocation(pt.x, pt.y + rect.height); |
|
226 |
sortMenu.setVisible(true); |
|
227 |
} else { |
|
228 |
updateEditorInput(); |
|
229 |
} |
|
230 |
} |
|
231 |
} |
|
232 |
|
|
233 |
/* |
|
234 |
* Handles search configuration selection. |
|
235 |
*/ |
|
236 |
class SortListSelectionListener extends SelectionAdapter { |
|
237 |
|
|
238 |
public void widgetSelected(SelectionEvent e) { |
|
239 |
for (MenuItem item : sortMenu.getItems()) { |
|
240 |
if (item.getData() instanceof Comparator) { |
|
241 |
if (item.equals(e.getSource())) { |
|
242 |
item.setSelection(true); |
|
243 |
} else { |
|
244 |
item.setSelection(false); |
|
245 |
} |
|
246 |
} |
|
247 |
} |
|
248 |
} |
|
249 |
} |
|
250 |
|
|
251 |
/* |
|
252 |
* Returns the current string in the search textfield. |
|
253 |
* @return the content of the textfield |
|
254 |
*/ |
|
255 |
public String getSearchString() { |
|
256 |
return text.getText().trim(); |
|
257 |
} |
|
258 |
|
|
259 |
/* |
|
260 |
* |
|
261 |
*/ |
|
262 |
public Comparator getComparator() { |
|
263 |
Comparator comparator; |
|
264 |
for (MenuItem item : sortMenu.getItems()) { |
|
265 |
if (item.getSelection() == true && item.getData() instanceof Comparator) { |
|
266 |
return (Comparator) item.getData(); |
|
267 |
} |
|
268 |
} |
|
269 |
return null; |
|
270 |
}; |
|
271 |
|
|
272 |
/* |
|
273 |
* |
|
274 |
*/ |
|
275 |
class BulkEditorQuery implements IBulkEditorQuery { |
|
276 |
|
|
277 |
private String searchString; |
|
278 |
private Comparator comparator; |
|
279 |
private IIdentifiableEntityServiceConfigurator searchConfigurator; |
|
280 |
|
|
281 |
BulkEditorQuery (String searchString, Comparator comparator) { |
|
282 |
this.searchString = searchString; |
|
283 |
this.comparator = comparator; |
|
284 |
|
|
285 |
searchConfigurator = IdentifiableServiceConfiguratorImpl.NewInstance(); |
|
286 |
searchConfigurator.setTitleSearchString(searchString); |
|
287 |
} |
|
288 |
|
|
289 |
/* (non-Javadoc) |
|
290 |
* @see eu.etaxonomy.taxeditor.bulkeditor.IBulkEditorQuery#getComparator() |
|
291 |
*/ |
|
292 |
public Comparator getComparator() { |
|
293 |
return comparator; |
|
294 |
} |
|
295 |
|
|
296 |
/* (non-Javadoc) |
|
297 |
* @see eu.etaxonomy.taxeditor.bulkeditor.IBulkEditorQuery#getSearchString() |
|
298 |
*/ |
|
299 |
public String getSearchString() { |
|
300 |
return searchString; |
|
301 |
} |
|
302 |
|
|
303 |
/* (non-Javadoc) |
|
304 |
* @see eu.etaxonomy.taxeditor.bulkeditor.IBulkEditorQuery#getSearchConfigurator() |
|
305 |
*/ |
|
306 |
public IIdentifiableEntityServiceConfigurator getSearchConfigurator() { |
|
307 |
return searchConfigurator; |
|
308 |
} |
|
309 |
} |
|
310 |
} |
|
1 |
// $Id$ |
|
2 |
/** |
|
3 |
* Copyright (C) 2007 EDIT |
|
4 |
* European Distributed Institute of Taxonomy |
|
5 |
* http://www.e-taxonomy.eu |
|
6 |
* |
|
7 |
* The contents of this file are subject to the Mozilla Public License Version 1.1 |
|
8 |
* See LICENSE.TXT at the top of this package for the full license terms. |
|
9 |
*/ |
|
10 |
|
|
11 |
package eu.etaxonomy.taxeditor.bulkeditor; |
|
12 |
|
|
13 |
import java.util.Comparator; |
|
14 |
|
|
15 |
import org.apache.log4j.Logger; |
|
16 |
import org.eclipse.swt.SWT; |
|
17 |
import org.eclipse.swt.events.FocusEvent; |
|
18 |
import org.eclipse.swt.events.FocusListener; |
|
19 |
import org.eclipse.swt.events.KeyAdapter; |
|
20 |
import org.eclipse.swt.events.KeyEvent; |
|
21 |
import org.eclipse.swt.events.SelectionAdapter; |
|
22 |
import org.eclipse.swt.events.SelectionEvent; |
|
23 |
import org.eclipse.swt.events.SelectionListener; |
|
24 |
import org.eclipse.swt.graphics.Point; |
|
25 |
import org.eclipse.swt.graphics.Rectangle; |
|
26 |
import org.eclipse.swt.layout.GridData; |
|
27 |
import org.eclipse.swt.layout.GridLayout; |
|
28 |
import org.eclipse.swt.widgets.Composite; |
|
29 |
import org.eclipse.swt.widgets.Menu; |
|
30 |
import org.eclipse.swt.widgets.MenuItem; |
|
31 |
import org.eclipse.swt.widgets.Text; |
|
32 |
import org.eclipse.swt.widgets.ToolBar; |
|
33 |
import org.eclipse.swt.widgets.ToolItem; |
|
34 |
import org.eclipse.ui.IEditorInput; |
|
35 |
import org.eclipse.ui.IEditorPart; |
|
36 |
import org.eclipse.ui.PlatformUI; |
|
37 |
import org.eclipse.ui.swt.IFocusService; |
|
38 |
|
|
39 |
import eu.etaxonomy.cdm.api.service.config.IIdentifiableEntityServiceConfigurator; |
|
40 |
import eu.etaxonomy.cdm.api.service.config.impl.IdentifiableServiceConfiguratorImpl; |
|
41 |
import eu.etaxonomy.taxeditor.bulkeditor.input.AbstractBulkEditorInput; |
|
42 |
import eu.etaxonomy.taxeditor.preference.Resources; |
|
43 |
|
|
44 |
/** |
|
45 |
* <p>BulkEditorSearchComposite class.</p> |
|
46 |
* |
|
47 |
* @author p.ciardelli |
|
48 |
* @author e.-m.lee |
|
49 |
* @created 17.08.2009 |
|
50 |
* @version 1.0 |
|
51 |
*/ |
|
52 |
public class BulkEditorSearchComposite extends Composite { |
|
53 |
private static final Logger logger = Logger.getLogger(BulkEditorSearchComposite.class); |
|
54 |
|
|
55 |
private IEditorPart editor; |
|
56 |
private IBulkEditorSortMenuProvider menuProvider; |
|
57 |
private Menu sortMenu; |
|
58 |
private Text text; |
|
59 |
private static final String DEFAULT_TEXT = "Use \"*\" for wildcard searching"; |
|
60 |
public Object ORDER_BY = new Object(); |
|
61 |
private ToolItem toolItem; |
|
62 |
|
|
63 |
/** |
|
64 |
* <p>Constructor for BulkEditorSearchComposite.</p> |
|
65 |
* |
|
66 |
* @param parent a {@link org.eclipse.swt.widgets.Composite} object. |
|
67 |
* @param style a int. |
|
68 |
* @param editor a {@link org.eclipse.ui.IEditorPart} object. |
|
69 |
*/ |
|
70 |
public BulkEditorSearchComposite(IEditorPart editor, Composite parent, int style) { |
|
71 |
super(parent, style); |
|
72 |
this.editor = editor; |
|
73 |
this.menuProvider = new BulkEditorSortMenuProvider(); |
|
74 |
|
|
75 |
createControl(); |
|
76 |
} |
|
77 |
|
|
78 |
/* |
|
79 |
* Creates the search control. |
|
80 |
*/ |
|
81 |
/** |
|
82 |
* <p>createControl</p> |
|
83 |
*/ |
|
84 |
protected void createControl() { |
|
85 |
createLayout(); |
|
86 |
createSearchTextField(); |
|
87 |
createToolBar(); |
|
88 |
registerAtFocusService(); |
|
89 |
setSearchEnabled(false); |
|
90 |
} |
|
91 |
|
|
92 |
|
|
93 |
/** |
|
94 |
* Handles focus changes for the textfield. |
|
95 |
*/ |
|
96 |
private void registerAtFocusService() { |
|
97 |
IFocusService focusService = |
|
98 |
(IFocusService) PlatformUI.getWorkbench().getService(IFocusService.class); |
|
99 |
if (focusService != null) { |
|
100 |
focusService.addFocusTracker(text, "bulkeditor.textControlId"); |
|
101 |
} |
|
102 |
} |
|
103 |
|
|
104 |
|
|
105 |
/** |
|
106 |
* Creates the search toolbar. |
|
107 |
*/ |
|
108 |
private void createToolBar() { |
|
109 |
final ToolBar toolBar = new ToolBar(this, SWT.NULL); |
|
110 |
|
|
111 |
toolItem = new ToolItem(toolBar, SWT.DROP_DOWN | SWT.BORDER); |
|
112 |
toolItem.setText("Search"); |
|
113 |
|
|
114 |
DropdownMenu dropdownMenu = new DropdownMenu(toolItem); |
|
115 |
toolItem.addSelectionListener(dropdownMenu); |
|
116 |
} |
|
117 |
|
|
118 |
|
|
119 |
/** |
|
120 |
* Creates the search textfield. |
|
121 |
*/ |
|
122 |
private void createSearchTextField() { |
|
123 |
text = new Text(this, SWT.BORDER | SWT.SINGLE | SWT.FULL_SELECTION); |
|
124 |
text.setText(DEFAULT_TEXT); |
|
125 |
text.setForeground(BulkEditorUtil.getColor(Resources.SEARCH_VIEW_FOREGROUND)); |
|
126 |
|
|
127 |
text.addFocusListener(new FocusListener() { |
|
128 |
|
|
129 |
public void focusGained(FocusEvent e) { |
|
130 |
text.setForeground(BulkEditorUtil.getColor(Resources.SEARCH_VIEW_FOCUS)); |
|
131 |
if (DEFAULT_TEXT.equals(text.getText())) { |
|
132 |
text.setText(""); |
|
133 |
} |
|
134 |
} |
|
135 |
|
|
136 |
public void focusLost(FocusEvent e) { |
|
137 |
if (text.getText() == "") { |
|
138 |
text.setForeground(BulkEditorUtil.getColor(Resources.SEARCH_VIEW_FOREGROUND)); |
|
139 |
text.setText(DEFAULT_TEXT); |
|
140 |
setSearchEnabled(false); |
|
141 |
} else { |
|
142 |
setSearchEnabled(true); |
|
143 |
} |
|
144 |
} |
|
145 |
}); |
|
146 |
|
|
147 |
text.addKeyListener(new KeyAdapter() { |
|
148 |
/* (non-Javadoc) |
|
149 |
* @see org.eclipse.swt.events.KeyAdapter#keyReleased(org.eclipse.swt.events.KeyEvent) |
|
150 |
*/ |
|
151 |
@Override |
|
152 |
public void keyReleased(KeyEvent e) { |
|
153 |
if (e.keyCode == SWT.CR) { |
|
154 |
updateEditorInput(); |
|
155 |
} |
|
156 |
} |
|
157 |
}); |
|
158 |
|
|
159 |
GridData gridData = new GridData(SWT.FILL, SWT.TOP, true, false); |
|
160 |
text.setLayoutData(gridData); |
|
161 |
} |
|
162 |
|
|
163 |
|
|
164 |
/** |
|
165 |
* Creates the search layout. |
|
166 |
*/ |
|
167 |
private void createLayout() { |
|
168 |
GridLayout gridLayout = new GridLayout(); |
|
169 |
gridLayout.numColumns = 3; |
|
170 |
gridLayout.marginHeight = 0; |
|
171 |
gridLayout.marginWidth = 12; |
|
172 |
setLayout(gridLayout); |
|
173 |
} |
|
174 |
|
|
175 |
/* |
|
176 |
* Toggles the availability of the search toolItem. |
|
177 |
*/ |
|
178 |
private void setSearchEnabled(boolean enabled) { |
|
179 |
// toolItem.setEnabled(enabled); |
|
180 |
} |
|
181 |
|
|
182 |
/* |
|
183 |
* Shows the results of the search. |
|
184 |
*/ |
|
185 |
private void updateEditorInput() { |
|
186 |
|
|
187 |
String searchString = getSearchString(); |
|
188 |
|
|
189 |
if(!DEFAULT_TEXT.equals(searchString.trim()) && searchString.length() > 0){ |
|
190 |
// update query in IEditorInput |
|
191 |
IEditorInput input = editor.getEditorInput(); |
|
192 |
if (input instanceof AbstractBulkEditorInput) { |
|
193 |
((AbstractBulkEditorInput) input).setQuery(new BulkEditorQuery(getSearchString(), getComparator())); |
|
194 |
} |
|
195 |
} |
|
196 |
} |
|
197 |
|
|
198 |
/* |
|
199 |
* Handles drop down menu selection. |
|
200 |
*/ |
|
201 |
class DropdownMenu extends SelectionAdapter { |
|
202 |
|
|
203 |
/** |
|
204 |
* @param dropdown |
|
205 |
*/ |
|
206 |
public DropdownMenu(ToolItem dropdown) { |
|
207 |
sortMenu = new Menu(dropdown.getParent().getShell()); |
|
208 |
|
|
209 |
MenuItem menuItem = new MenuItem(sortMenu, SWT.PUSH); |
|
210 |
menuItem.setText("Order by:"); |
|
211 |
menuItem.setData(ORDER_BY); |
|
212 |
new MenuItem(sortMenu, SWT.SEPARATOR); |
|
213 |
|
|
214 |
menuProvider.fillMenu(editor.getEditorInput(), sortMenu); |
|
215 |
|
|
216 |
SelectionListener listener = new SortListSelectionListener(); |
|
217 |
|
|
218 |
for (MenuItem item : sortMenu.getItems()) { |
|
219 |
if (item.getData() instanceof Comparator) { |
|
220 |
item.addSelectionListener(listener); |
|
221 |
} |
|
222 |
} |
|
223 |
} |
|
224 |
|
|
225 |
/* (non-Javadoc) |
|
226 |
* @see org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse.swt.events.SelectionEvent) |
|
227 |
*/ |
|
228 |
public void widgetSelected(SelectionEvent event) { |
|
229 |
if (event.detail == SWT.ARROW) { |
|
230 |
ToolItem item = (ToolItem) event.widget; |
|
231 |
Rectangle rect = item.getBounds(); |
|
232 |
Point pt = item.getParent().toDisplay(new Point(rect.x, rect.y)); |
|
233 |
sortMenu.setLocation(pt.x, pt.y + rect.height); |
|
234 |
sortMenu.setVisible(true); |
|
235 |
} else { |
|
236 |
updateEditorInput(); |
|
237 |
} |
|
238 |
} |
|
239 |
} |
|
240 |
|
|
241 |
/* |
|
242 |
* Handles search configuration selection. |
|
243 |
*/ |
|
244 |
class SortListSelectionListener extends SelectionAdapter { |
|
245 |
|
|
246 |
public void widgetSelected(SelectionEvent e) { |
|
247 |
for (MenuItem item : sortMenu.getItems()) { |
|
248 |
if (item.getData() instanceof Comparator) { |
|
249 |
if (item.equals(e.getSource())) { |
|
250 |
item.setSelection(true); |
|
251 |
} else { |
|
252 |
item.setSelection(false); |
|
253 |
} |
|
254 |
} |
|
255 |
} |
|
256 |
} |
|
257 |
} |
|
258 |
|
|
259 |
/* |
|
260 |
* Returns the current string in the search textfield. |
|
261 |
* @return the content of the textfield |
|
262 |
*/ |
|
263 |
/** |
|
264 |
* <p>getSearchString</p> |
|
265 |
* |
|
266 |
* @return a {@link java.lang.String} object. |
|
267 |
*/ |
|
268 |
public String getSearchString() { |
|
269 |
return text.getText().trim(); |
|
270 |
} |
|
271 |
|
|
272 |
/* |
|
273 |
* |
|
274 |
*/ |
|
275 |
/** |
|
276 |
* <p>getComparator</p> |
|
277 |
* |
|
278 |
* @return a {@link java.util.Comparator} object. |
|
279 |
*/ |
|
280 |
public Comparator getComparator() { |
|
281 |
Comparator comparator; |
|
282 |
for (MenuItem item : sortMenu.getItems()) { |
|
283 |
if (item.getSelection() == true && item.getData() instanceof Comparator) { |
|
284 |
return (Comparator) item.getData(); |
|
285 |
} |
|
286 |
} |
|
287 |
return null; |
|
288 |
}; |
|
289 |
|
|
290 |
/* |
|
291 |
* |
|
292 |
*/ |
|
293 |
class BulkEditorQuery implements IBulkEditorQuery { |
|
294 |
|
|
295 |
private String searchString; |
|
296 |
private Comparator comparator; |
|
297 |
private IIdentifiableEntityServiceConfigurator searchConfigurator; |
|
298 |
|
|
299 |
BulkEditorQuery (String searchString, Comparator comparator) { |
|
300 |
this.searchString = searchString; |
|
301 |
this.comparator = comparator; |
|
302 |
|
|
303 |
searchConfigurator = IdentifiableServiceConfiguratorImpl.NewInstance(); |
|
304 |
searchConfigurator.setTitleSearchString(searchString); |
|
305 |
} |
|
306 |
|
|
307 |
/* (non-Javadoc) |
|
308 |
* @see eu.etaxonomy.taxeditor.bulkeditor.IBulkEditorQuery#getComparator() |
|
309 |
*/ |
|
310 |
public Comparator getComparator() { |
|
311 |
return comparator; |
|
312 |
} |
|
313 |
|
|
314 |
/* (non-Javadoc) |
|
315 |
* @see eu.etaxonomy.taxeditor.bulkeditor.IBulkEditorQuery#getSearchString() |
|
316 |
*/ |
|
317 |
public String getSearchString() { |
|
318 |
return searchString; |
|
319 |
} |
|
320 |
|
|
321 |
/* (non-Javadoc) |
|
322 |
* @see eu.etaxonomy.taxeditor.bulkeditor.IBulkEditorQuery#getSearchConfigurator() |
|
323 |
*/ |
|
324 |
public IIdentifiableEntityServiceConfigurator getSearchConfigurator() { |
|
325 |
return searchConfigurator; |
|
326 |
} |
|
327 |
} |
|
328 |
} |
Also available in: Unified diff
performed javacscript:fix and worked on documentation