Revision 95ee1b51
Added by U-BGBM\k.luther over 8 years ago
eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/bulkeditor/input/AgentEditorInput.java | ||
---|---|---|
82 | 82 |
public boolean merge(TeamOrPersonBase entity, TeamOrPersonBase mergeTarget) { |
83 | 83 |
if (entity instanceof IMergable) { |
84 | 84 |
try { |
85 |
if(entity instanceof Person) { |
|
85 |
if(entity instanceof Person && mergeTarget instanceof Person) {
|
|
86 | 86 |
IMergeStrategy strategy = DefaultMergeStrategy.NewInstance(Person.class); |
87 | 87 |
strategy.setMergeMode("institutionalMemberships", MergeMode.FIRST); |
88 | 88 |
CdmStore.getCommonService().merge(mergeTarget.getId(), entity.getId(), Person.class); |
eu.etaxonomy.taxeditor.editor.src/main/java/eu/etaxonomy/taxeditor/editor/name/container/RulerWithIcon.java | ||
---|---|---|
1 |
/** |
|
2 |
* Copyright (C) 2007 EDIT |
|
3 |
* European Distributed Institute of Taxonomy |
|
4 |
* http://www.e-taxonomy.eu |
|
5 |
* |
|
6 |
* The contents of this file are subject to the Mozilla Public License Version 1.1 |
|
7 |
* See LICENSE.TXT at the top of this package for the full license terms. |
|
8 |
*/ |
|
9 |
|
|
10 |
package eu.etaxonomy.taxeditor.editor.name.container; |
|
11 |
|
|
12 |
import java.util.Iterator; |
|
13 |
|
|
14 |
import org.apache.log4j.Logger; |
|
15 |
import org.eclipse.jface.text.BadLocationException; |
|
16 |
import org.eclipse.jface.text.IDocument; |
|
17 |
import org.eclipse.jface.text.IRegion; |
|
18 |
import org.eclipse.jface.text.ITextListener; |
|
19 |
import org.eclipse.jface.text.ITextViewer; |
|
20 |
import org.eclipse.jface.text.ITextViewerExtension5; |
|
21 |
import org.eclipse.jface.text.IViewportListener; |
|
22 |
import org.eclipse.jface.text.JFaceTextUtil; |
|
23 |
import org.eclipse.jface.text.Position; |
|
24 |
import org.eclipse.jface.text.Region; |
|
25 |
import org.eclipse.jface.text.TextEvent; |
|
26 |
import org.eclipse.jface.text.source.Annotation; |
|
27 |
import org.eclipse.jface.text.source.IAnnotationAccess; |
|
28 |
import org.eclipse.jface.text.source.IAnnotationAccessExtension; |
|
29 |
import org.eclipse.jface.text.source.IAnnotationModel; |
|
30 |
import org.eclipse.jface.text.source.IAnnotationModelListener; |
|
31 |
import org.eclipse.jface.text.source.IAnnotationPresentation; |
|
32 |
import org.eclipse.jface.text.source.IVerticalRuler; |
|
33 |
import org.eclipse.jface.text.source.IVerticalRulerExtension; |
|
34 |
import org.eclipse.swt.SWT; |
|
35 |
import org.eclipse.swt.custom.StyledText; |
|
36 |
import org.eclipse.swt.events.DisposeEvent; |
|
37 |
import org.eclipse.swt.events.DisposeListener; |
|
38 |
import org.eclipse.swt.events.MouseEvent; |
|
39 |
import org.eclipse.swt.events.MouseListener; |
|
40 |
import org.eclipse.swt.events.PaintEvent; |
|
41 |
import org.eclipse.swt.events.PaintListener; |
|
42 |
import org.eclipse.swt.graphics.Font; |
|
43 |
import org.eclipse.swt.graphics.GC; |
|
44 |
import org.eclipse.swt.graphics.Image; |
|
45 |
import org.eclipse.swt.graphics.Point; |
|
46 |
import org.eclipse.swt.graphics.Rectangle; |
|
47 |
import org.eclipse.swt.widgets.Canvas; |
|
48 |
import org.eclipse.swt.widgets.Composite; |
|
49 |
import org.eclipse.swt.widgets.Control; |
|
50 |
import org.eclipse.swt.widgets.Display; |
|
51 |
import org.eclipse.ui.forms.widgets.TableWrapData; |
|
52 |
|
|
53 |
/** |
|
54 |
* 99% of the code in this class was copied from org.eclipse.jface.text.source.VerticalRuler, |
|
55 |
* which allows neither access to its paint methods nor subclassing to do same. |
|
56 |
* <p> |
|
57 |
* Changes made in method doubleBufferPaint(doubleBufferPaint(GC dest)). |
|
58 |
* |
|
59 |
* @see org.eclipse.jface.text.source.VerticalRuler |
|
60 |
* @author p.ciardelli |
|
61 |
* @created 27.01.2009 |
|
62 |
* @version 1.0 |
|
63 |
*/ |
|
64 |
public class RulerWithIcon implements IVerticalRuler, IVerticalRulerExtension { |
|
65 |
private static final Logger logger = Logger.getLogger(RulerWithIcon.class); |
|
66 |
|
|
67 |
/** |
|
68 |
* Internal listener class. |
|
69 |
*/ |
|
70 |
class InternalListener implements IViewportListener, IAnnotationModelListener, ITextListener { |
|
71 |
|
|
72 |
/* |
|
73 |
* @see IViewportListener#viewportChanged(int) |
|
74 |
*/ |
|
75 |
public void viewportChanged(int verticalPosition) { |
|
76 |
if (verticalPosition != fScrollPos) |
|
77 |
redraw(); |
|
78 |
} |
|
79 |
|
|
80 |
/* |
|
81 |
* @see IAnnotationModelListener#modelChanged(IAnnotationModel) |
|
82 |
*/ |
|
83 |
public void modelChanged(IAnnotationModel model) { |
|
84 |
update(); |
|
85 |
} |
|
86 |
|
|
87 |
/* |
|
88 |
* @see ITextListener#textChanged(TextEvent) |
|
89 |
*/ |
|
90 |
public void textChanged(TextEvent e) { |
|
91 |
if (fTextViewer != null && e.getViewerRedrawState()) |
|
92 |
redraw(); |
|
93 |
} |
|
94 |
} |
|
95 |
|
|
96 |
/** The vertical ruler's text viewer */ |
|
97 |
private ITextViewer fTextViewer; |
|
98 |
/** The ruler's canvas */ |
|
99 |
private Canvas fCanvas; |
|
100 |
/** The vertical ruler's model */ |
|
101 |
private IAnnotationModel fModel; |
|
102 |
/** Cache for the actual scroll position in pixels */ |
|
103 |
private int fScrollPos; |
|
104 |
/** The buffer for double buffering */ |
|
105 |
private Image fBuffer; |
|
106 |
/** The line of the last mouse button activity */ |
|
107 |
private int fLastMouseButtonActivityLine= -1; |
|
108 |
/** The internal listener */ |
|
109 |
private InternalListener fInternalListener= new InternalListener(); |
|
110 |
/** The width of this vertical ruler */ |
|
111 |
private int fWidth; |
|
112 |
/** |
|
113 |
* The annotation access of this vertical ruler |
|
114 |
* @since 3.0 |
|
115 |
*/ |
|
116 |
private IAnnotationAccess fAnnotationAccess; |
|
117 |
private Image icon; |
|
118 |
|
|
119 |
/** |
|
120 |
* Constructs a vertical ruler with the given width. |
|
121 |
* |
|
122 |
* @param width the width of the vertical ruler |
|
123 |
*/ |
|
124 |
public RulerWithIcon(int width) { |
|
125 |
this(width, null); |
|
126 |
} |
|
127 |
|
|
128 |
/** |
|
129 |
* Constructs a vertical ruler with the given width and the given annotation |
|
130 |
* access. |
|
131 |
* |
|
132 |
* @param width the width of the vertical ruler |
|
133 |
* @param annotationAcccess the annotation access |
|
134 |
* @since 3.0 |
|
135 |
*/ |
|
136 |
public RulerWithIcon(int width, IAnnotationAccess annotationAcccess) { |
|
137 |
fWidth= width; |
|
138 |
fAnnotationAccess= annotationAcccess; |
|
139 |
} |
|
140 |
|
|
141 |
/* |
|
142 |
* @see IVerticalRuler#getControl() |
|
143 |
*/ |
|
144 |
/** |
|
145 |
* <p>getControl</p> |
|
146 |
* |
|
147 |
* @return a {@link org.eclipse.swt.widgets.Control} object. |
|
148 |
*/ |
|
149 |
public Control getControl() { |
|
150 |
return fCanvas; |
|
151 |
} |
|
152 |
|
|
153 |
/* |
|
154 |
* @see IVerticalRuler#createControl(Composite, ITextViewer) |
|
155 |
*/ |
|
156 |
/** {@inheritDoc} */ |
|
157 |
public Control createControl(Composite parent, ITextViewer textViewer) { |
|
158 |
|
|
159 |
fTextViewer= textViewer; |
|
160 |
|
|
161 |
fCanvas= new Canvas(parent, SWT.NO_BACKGROUND); |
|
162 |
|
|
163 |
TableWrapData layout = new TableWrapData(TableWrapData.LEFT); |
|
164 |
layout.heightHint = 20; |
|
165 |
layout.maxWidth = fWidth; |
|
166 |
fCanvas.setLayoutData(layout); |
|
167 |
|
|
168 |
fCanvas.addPaintListener(new PaintListener() { |
|
169 |
public void paintControl(PaintEvent event) { |
|
170 |
if (fTextViewer != null) |
|
171 |
doubleBufferPaint(event.gc); |
|
172 |
} |
|
173 |
}); |
|
174 |
|
|
175 |
fCanvas.addDisposeListener(new DisposeListener() { |
|
176 |
public void widgetDisposed(DisposeEvent e) { |
|
177 |
handleDispose(); |
|
178 |
fTextViewer= null; |
|
179 |
} |
|
180 |
}); |
|
181 |
|
|
182 |
fCanvas.addMouseListener(new MouseListener() { |
|
183 |
public void mouseUp(MouseEvent event) { |
|
184 |
} |
|
185 |
|
|
186 |
public void mouseDown(MouseEvent event) { |
|
187 |
fLastMouseButtonActivityLine= toDocumentLineNumber(event.y); |
|
188 |
} |
|
189 |
|
|
190 |
public void mouseDoubleClick(MouseEvent event) { |
|
191 |
fLastMouseButtonActivityLine= toDocumentLineNumber(event.y); |
|
192 |
} |
|
193 |
}); |
|
194 |
|
|
195 |
if (fTextViewer != null) { |
|
196 |
fTextViewer.addViewportListener(fInternalListener); |
|
197 |
fTextViewer.addTextListener(fInternalListener); |
|
198 |
} |
|
199 |
|
|
200 |
return fCanvas; |
|
201 |
} |
|
202 |
|
|
203 |
/** |
|
204 |
* Disposes the ruler's resources. |
|
205 |
*/ |
|
206 |
private void handleDispose() { |
|
207 |
|
|
208 |
if (fTextViewer != null) { |
|
209 |
fTextViewer.removeViewportListener(fInternalListener); |
|
210 |
fTextViewer.removeTextListener(fInternalListener); |
|
211 |
fTextViewer= null; |
|
212 |
} |
|
213 |
|
|
214 |
if (fModel != null) |
|
215 |
fModel.removeAnnotationModelListener(fInternalListener); |
|
216 |
|
|
217 |
if (fBuffer != null) { |
|
218 |
fBuffer.dispose(); |
|
219 |
fBuffer= null; |
|
220 |
} |
|
221 |
} |
|
222 |
|
|
223 |
|
|
224 |
/** |
|
225 |
* Double buffer drawing. |
|
226 |
* |
|
227 |
* @param dest the GC to draw into |
|
228 |
*/ |
|
229 |
private void doubleBufferPaint(GC dest) { |
|
230 |
|
|
231 |
Point size= fCanvas.getSize(); |
|
232 |
|
|
233 |
if (size.x <= 0 || size.y <= 0) |
|
234 |
return; |
|
235 |
|
|
236 |
if (fBuffer != null) { |
|
237 |
Rectangle r= fBuffer.getBounds(); |
|
238 |
if (r.width != size.x || r.height != size.y) { |
|
239 |
fBuffer.dispose(); |
|
240 |
fBuffer= null; |
|
241 |
} |
|
242 |
} |
|
243 |
if (fBuffer == null) |
|
244 |
fBuffer= new Image(fCanvas.getDisplay(), size.x, size.y); |
|
245 |
|
|
246 |
GC gc= new GC(fBuffer); |
|
247 |
gc.setFont(fTextViewer.getTextWidget().getFont()); |
|
248 |
try { |
|
249 |
gc.setBackground(fCanvas.getBackground()); |
|
250 |
gc.fillRectangle(0, 0, size.x, size.y); |
|
251 |
|
|
252 |
// Code added to VerticalRuler starts here |
|
253 |
if (icon != null) { |
|
254 |
|
|
255 |
Rectangle r = icon.getBounds(); |
|
256 |
|
|
257 |
if (r.width > size.x || r.height > size.y) { |
|
258 |
logger.warn(r.width + "x" + r.height + " icon too big for " + size.x + "x" + size.y + " Canvas."); |
|
259 |
} else { |
|
260 |
|
|
261 |
// Set destination coordinates to center icon |
|
262 |
int x = (size.x - r.width) / 2; |
|
263 |
int y = (size.y - r.height) / 2; |
|
264 |
|
|
265 |
gc.drawImage(icon, 0, 0, r.width, r.height, x, y, r.width, r.height); |
|
266 |
} |
|
267 |
} |
|
268 |
// Code added to VerticalRuler ends here |
|
269 |
|
|
270 |
if (fTextViewer instanceof ITextViewerExtension5) |
|
271 |
doPaint1(gc); |
|
272 |
else |
|
273 |
doPaint(gc); |
|
274 |
|
|
275 |
} finally { |
|
276 |
gc.dispose(); |
|
277 |
} |
|
278 |
|
|
279 |
dest.drawImage(fBuffer, 0, 0); |
|
280 |
} |
|
281 |
|
|
282 |
/** |
|
283 |
* Returns the document offset of the upper left corner of the |
|
284 |
* widgets view port, possibly including partially visible lines. |
|
285 |
* |
|
286 |
* @return the document offset of the upper left corner including partially visible lines |
|
287 |
* @since 2.0 |
|
288 |
*/ |
|
289 |
private int getInclusiveTopIndexStartOffset() { |
|
290 |
|
|
291 |
StyledText textWidget= fTextViewer.getTextWidget(); |
|
292 |
if (textWidget != null && !textWidget.isDisposed()) { |
|
293 |
int top= JFaceTextUtil.getPartialTopIndex(fTextViewer); |
|
294 |
try { |
|
295 |
IDocument document= fTextViewer.getDocument(); |
|
296 |
return document.getLineOffset(top); |
|
297 |
} catch (BadLocationException x) { |
|
298 |
} |
|
299 |
} |
|
300 |
|
|
301 |
return -1; |
|
302 |
} |
|
303 |
|
|
304 |
|
|
305 |
|
|
306 |
/** |
|
307 |
* Draws the vertical ruler w/o drawing the Canvas background. |
|
308 |
* |
|
309 |
* @param gc the GC to draw into |
|
310 |
*/ |
|
311 |
protected void doPaint(GC gc) { |
|
312 |
|
|
313 |
if (fModel == null || fTextViewer == null) |
|
314 |
return; |
|
315 |
|
|
316 |
IAnnotationAccessExtension annotationAccessExtension= null; |
|
317 |
if (fAnnotationAccess instanceof IAnnotationAccessExtension) |
|
318 |
annotationAccessExtension= (IAnnotationAccessExtension) fAnnotationAccess; |
|
319 |
|
|
320 |
StyledText styledText= fTextViewer.getTextWidget(); |
|
321 |
IDocument doc= fTextViewer.getDocument(); |
|
322 |
|
|
323 |
int topLeft= getInclusiveTopIndexStartOffset(); |
|
324 |
int bottomRight= fTextViewer.getBottomIndexEndOffset(); |
|
325 |
int viewPort= bottomRight - topLeft; |
|
326 |
|
|
327 |
Point d= fCanvas.getSize(); |
|
328 |
fScrollPos= styledText.getTopPixel(); |
|
329 |
|
|
330 |
int topLine= -1, bottomLine= -1; |
|
331 |
try { |
|
332 |
IRegion region= fTextViewer.getVisibleRegion(); |
|
333 |
topLine= doc.getLineOfOffset(region.getOffset()); |
|
334 |
bottomLine= doc.getLineOfOffset(region.getOffset() + region.getLength()); |
|
335 |
} catch (BadLocationException x) { |
|
336 |
return; |
|
337 |
} |
|
338 |
|
|
339 |
// draw Annotations |
|
340 |
Rectangle r= new Rectangle(0, 0, 0, 0); |
|
341 |
int maxLayer= 1; // loop at least once though layers. |
|
342 |
|
|
343 |
for (int layer= 0; layer < maxLayer; layer++) { |
|
344 |
Iterator<?> iter= fModel.getAnnotationIterator(); |
|
345 |
while (iter.hasNext()) { |
|
346 |
IAnnotationPresentation annotationPresentation= null; |
|
347 |
Annotation annotation= (Annotation) iter.next(); |
|
348 |
|
|
349 |
int lay= IAnnotationAccessExtension.DEFAULT_LAYER; |
|
350 |
if (annotationAccessExtension != null) |
|
351 |
lay= annotationAccessExtension.getLayer(annotation); |
|
352 |
else if (annotation instanceof IAnnotationPresentation) { |
|
353 |
annotationPresentation= (IAnnotationPresentation)annotation; |
|
354 |
lay= annotationPresentation.getLayer(); |
|
355 |
} |
|
356 |
maxLayer= Math.max(maxLayer, lay+1); // dynamically update layer maximum |
|
357 |
if (lay != layer) // wrong layer: skip annotation |
|
358 |
continue; |
|
359 |
|
|
360 |
Position position= fModel.getPosition(annotation); |
|
361 |
if (position == null) |
|
362 |
continue; |
|
363 |
|
|
364 |
if (!position.overlapsWith(topLeft, viewPort)) |
|
365 |
continue; |
|
366 |
|
|
367 |
try { |
|
368 |
|
|
369 |
int offset= position.getOffset(); |
|
370 |
int length= position.getLength(); |
|
371 |
|
|
372 |
int startLine= doc.getLineOfOffset(offset); |
|
373 |
if (startLine < topLine) |
|
374 |
startLine= topLine; |
|
375 |
|
|
376 |
int endLine= startLine; |
|
377 |
if (length > 0) |
|
378 |
endLine= doc.getLineOfOffset(offset + length - 1); |
|
379 |
if (endLine > bottomLine) |
|
380 |
endLine= bottomLine; |
|
381 |
|
|
382 |
startLine -= topLine; |
|
383 |
endLine -= topLine; |
|
384 |
|
|
385 |
r.x= 0; |
|
386 |
r.y= JFaceTextUtil.computeLineHeight(styledText, 0, startLine, startLine) - fScrollPos; |
|
387 |
|
|
388 |
r.width= d.x; |
|
389 |
int lines= endLine - startLine; |
|
390 |
|
|
391 |
r.height= JFaceTextUtil.computeLineHeight(styledText, startLine, endLine + 1, (lines+1)); |
|
392 |
|
|
393 |
if (r.y < d.y && annotationAccessExtension != null) // annotation within visible area |
|
394 |
annotationAccessExtension.paint(annotation, gc, fCanvas, r); |
|
395 |
else if (annotationPresentation != null) |
|
396 |
annotationPresentation.paint(gc, fCanvas, r); |
|
397 |
|
|
398 |
} catch (BadLocationException e) { |
|
399 |
} |
|
400 |
} |
|
401 |
} |
|
402 |
} |
|
403 |
|
|
404 |
/** |
|
405 |
* Draws the vertical ruler w/o drawing the Canvas background. Uses |
|
406 |
* <code>ITextViewerExtension5</code> for its implementation. Will replace |
|
407 |
* <code>doPaint(GC)</code>. |
|
408 |
* |
|
409 |
* @param gc the GC to draw into |
|
410 |
*/ |
|
411 |
protected void doPaint1(GC gc) { |
|
412 |
|
|
413 |
if (fModel == null || fTextViewer == null) |
|
414 |
return; |
|
415 |
|
|
416 |
IAnnotationAccessExtension annotationAccessExtension= null; |
|
417 |
if (fAnnotationAccess instanceof IAnnotationAccessExtension) |
|
418 |
annotationAccessExtension= (IAnnotationAccessExtension) fAnnotationAccess; |
|
419 |
|
|
420 |
ITextViewerExtension5 extension= (ITextViewerExtension5) fTextViewer; |
|
421 |
StyledText textWidget= fTextViewer.getTextWidget(); |
|
422 |
|
|
423 |
fScrollPos= textWidget.getTopPixel(); |
|
424 |
Point dimension= fCanvas.getSize(); |
|
425 |
|
|
426 |
// draw Annotations |
|
427 |
Rectangle r= new Rectangle(0, 0, 0, 0); |
|
428 |
int maxLayer= 1; // loop at least once through layers. |
|
429 |
|
|
430 |
for (int layer= 0; layer < maxLayer; layer++) { |
|
431 |
Iterator<?> iter= fModel.getAnnotationIterator(); |
|
432 |
while (iter.hasNext()) { |
|
433 |
IAnnotationPresentation annotationPresentation= null; |
|
434 |
Annotation annotation= (Annotation) iter.next(); |
|
435 |
|
|
436 |
int lay= IAnnotationAccessExtension.DEFAULT_LAYER; |
|
437 |
if (annotationAccessExtension != null) |
|
438 |
lay= annotationAccessExtension.getLayer(annotation); |
|
439 |
else if (annotation instanceof IAnnotationPresentation) { |
|
440 |
annotationPresentation= (IAnnotationPresentation)annotation; |
|
441 |
lay= annotationPresentation.getLayer(); |
|
442 |
} |
|
443 |
maxLayer= Math.max(maxLayer, lay+1); // dynamically update layer maximum |
|
444 |
if (lay != layer) // wrong layer: skip annotation |
|
445 |
continue; |
|
446 |
|
|
447 |
Position position= fModel.getPosition(annotation); |
|
448 |
if (position == null) |
|
449 |
continue; |
|
450 |
|
|
451 |
IRegion widgetRegion= extension.modelRange2WidgetRange(new Region(position.getOffset(), position.getLength())); |
|
452 |
if (widgetRegion == null) |
|
453 |
continue; |
|
454 |
|
|
455 |
int startLine= extension.widgetLineOfWidgetOffset(widgetRegion.getOffset()); |
|
456 |
if (startLine == -1) |
|
457 |
continue; |
|
458 |
|
|
459 |
int endLine= extension.widgetLineOfWidgetOffset(widgetRegion.getOffset() + Math.max(widgetRegion.getLength() -1, 0)); |
|
460 |
if (endLine == -1) |
|
461 |
continue; |
|
462 |
|
|
463 |
r.x= 0; |
|
464 |
r.y= JFaceTextUtil.computeLineHeight(textWidget, 0, startLine, startLine) - fScrollPos; |
|
465 |
|
|
466 |
r.width= dimension.x; |
|
467 |
int lines= endLine - startLine; |
|
468 |
|
|
469 |
r.height= JFaceTextUtil.computeLineHeight(textWidget, startLine, endLine + 1, lines+1); |
|
470 |
|
|
471 |
if (r.y < dimension.y && annotationAccessExtension != null) // annotation within visible area |
|
472 |
annotationAccessExtension.paint(annotation, gc, fCanvas, r); |
|
473 |
else if (annotationPresentation != null) |
|
474 |
annotationPresentation.paint(gc, fCanvas, r); |
|
475 |
} |
|
476 |
} |
|
477 |
} |
|
478 |
|
|
479 |
/** |
|
480 |
* Thread-safe implementation. |
|
481 |
* Can be called from any thread. |
|
482 |
*/ |
|
483 |
/* |
|
484 |
* @see IVerticalRuler#update() |
|
485 |
*/ |
|
486 |
public void update() { |
|
487 |
if (fCanvas != null && !fCanvas.isDisposed()) { |
|
488 |
Display d= fCanvas.getDisplay(); |
|
489 |
if (d != null) { |
|
490 |
d.asyncExec(new Runnable() { |
|
491 |
public void run() { |
|
492 |
redraw(); |
|
493 |
} |
|
494 |
}); |
|
495 |
} |
|
496 |
} |
|
497 |
} |
|
498 |
|
|
499 |
/** |
|
500 |
* Redraws the vertical ruler. |
|
501 |
*/ |
|
502 |
private void redraw() { |
|
503 |
if (fCanvas != null && !fCanvas.isDisposed()) { |
|
504 |
GC gc= new GC(fCanvas); |
|
505 |
doubleBufferPaint(gc); |
|
506 |
gc.dispose(); |
|
507 |
} |
|
508 |
} |
|
509 |
|
|
510 |
/* |
|
511 |
* @see IVerticalRuler#setModel(IAnnotationModel) |
|
512 |
*/ |
|
513 |
/** {@inheritDoc} */ |
|
514 |
public void setModel(IAnnotationModel model) { |
|
515 |
if (model != fModel) { |
|
516 |
|
|
517 |
if (fModel != null) |
|
518 |
fModel.removeAnnotationModelListener(fInternalListener); |
|
519 |
|
|
520 |
fModel= model; |
|
521 |
|
|
522 |
if (fModel != null) |
|
523 |
fModel.addAnnotationModelListener(fInternalListener); |
|
524 |
|
|
525 |
update(); |
|
526 |
} |
|
527 |
} |
|
528 |
|
|
529 |
/* |
|
530 |
* @see IVerticalRuler#getModel() |
|
531 |
*/ |
|
532 |
/** |
|
533 |
* <p>getModel</p> |
|
534 |
* |
|
535 |
* @return a {@link org.eclipse.jface.text.source.IAnnotationModel} object. |
|
536 |
*/ |
|
537 |
public IAnnotationModel getModel() { |
|
538 |
return fModel; |
|
539 |
} |
|
540 |
|
|
541 |
/* |
|
542 |
* @see IVerticalRulerInfo#getWidth() |
|
543 |
*/ |
|
544 |
/** |
|
545 |
* <p>getWidth</p> |
|
546 |
* |
|
547 |
* @return a int. |
|
548 |
*/ |
|
549 |
public int getWidth() { |
|
550 |
return fWidth; |
|
551 |
} |
|
552 |
|
|
553 |
/* |
|
554 |
* @see IVerticalRulerInfo#getLineOfLastMouseButtonActivity() |
|
555 |
*/ |
|
556 |
/** |
|
557 |
* <p>getLineOfLastMouseButtonActivity</p> |
|
558 |
* |
|
559 |
* @return a int. |
|
560 |
*/ |
|
561 |
public int getLineOfLastMouseButtonActivity() { |
|
562 |
return fLastMouseButtonActivityLine; |
|
563 |
} |
|
564 |
|
|
565 |
/* |
|
566 |
* @see IVerticalRulerInfo#toDocumentLineNumber(int) |
|
567 |
*/ |
|
568 |
/** {@inheritDoc} */ |
|
569 |
public int toDocumentLineNumber(int y_coordinate) { |
|
570 |
if (fTextViewer == null || y_coordinate == -1) |
|
571 |
return -1; |
|
572 |
|
|
573 |
StyledText text= fTextViewer.getTextWidget(); |
|
574 |
int line= text.getLineIndex(y_coordinate); |
|
575 |
|
|
576 |
if (line == text.getLineCount() - 1) { |
|
577 |
// check whether y_coordinate exceeds last line |
|
578 |
if (y_coordinate > text.getLinePixel(line + 1)) |
|
579 |
return -1; |
|
580 |
} |
|
581 |
|
|
582 |
return widgetLine2ModelLine(fTextViewer, line); |
|
583 |
} |
|
584 |
|
|
585 |
/** |
|
586 |
* Returns the line of the viewer's document that corresponds to the given widget line. |
|
587 |
* |
|
588 |
* @param viewer the viewer |
|
589 |
* @param widgetLine the widget line |
|
590 |
* @return the corresponding line of the viewer's document |
|
591 |
* @since 2.1 |
|
592 |
*/ |
|
593 |
protected final static int widgetLine2ModelLine(ITextViewer viewer, int widgetLine) { |
|
594 |
|
|
595 |
if (viewer instanceof ITextViewerExtension5) { |
|
596 |
ITextViewerExtension5 extension= (ITextViewerExtension5) viewer; |
|
597 |
return extension.widgetLine2ModelLine(widgetLine); |
|
598 |
} |
|
599 |
|
|
600 |
try { |
|
601 |
IRegion r= viewer.getVisibleRegion(); |
|
602 |
IDocument d= viewer.getDocument(); |
|
603 |
return widgetLine += d.getLineOfOffset(r.getOffset()); |
|
604 |
} catch (BadLocationException x) { |
|
605 |
} |
|
606 |
return widgetLine; |
|
607 |
} |
|
608 |
|
|
609 |
/* |
|
610 |
* @see IVerticalRulerExtension#setFont(Font) |
|
611 |
* @since 2.0 |
|
612 |
*/ |
|
613 |
/** {@inheritDoc} */ |
|
614 |
public void setFont(Font font) { |
|
615 |
} |
|
616 |
|
|
617 |
/* |
|
618 |
* @see IVerticalRulerExtension#setLocationOfLastMouseButtonActivity(int, int) |
|
619 |
* @since 2.0 |
|
620 |
*/ |
|
621 |
/** {@inheritDoc} */ |
|
622 |
public void setLocationOfLastMouseButtonActivity(int x, int y) { |
|
623 |
fLastMouseButtonActivityLine= toDocumentLineNumber(y); |
|
624 |
} |
|
625 |
|
|
626 |
/** |
|
627 |
* Adds the given mouse listener. |
|
628 |
* |
|
629 |
* @param listener the listener to be added |
|
630 |
* @deprecated will be removed |
|
631 |
* @since 2.0 |
|
632 |
*/ |
|
633 |
public void addMouseListener(MouseListener listener) { |
|
634 |
if (fCanvas != null && !fCanvas.isDisposed()) |
|
635 |
fCanvas.addMouseListener(listener); |
|
636 |
} |
|
637 |
|
|
638 |
/** |
|
639 |
* Removes the given mouse listener. |
|
640 |
* |
|
641 |
* @param listener the listener to be removed |
|
642 |
* @deprecated will be removed |
|
643 |
* @since 2.0 |
|
644 |
*/ |
|
645 |
public void removeMouseListener(MouseListener listener) { |
|
646 |
if (fCanvas != null && !fCanvas.isDisposed()) |
|
647 |
fCanvas.removeMouseListener(listener); |
|
648 |
} |
|
649 |
|
|
650 |
/** |
|
651 |
* <p>Setter for the field <code>icon</code>.</p> |
|
652 |
* |
|
653 |
* @param icon a {@link org.eclipse.swt.graphics.Image} object. |
|
654 |
*/ |
|
655 |
public void setIcon(Image icon) { |
|
656 |
this.icon = icon; |
|
657 |
redraw(); |
|
658 |
} |
|
659 |
} |
|
660 |
|
eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/TreeNodeDropAdapter.java | ||
---|---|---|
14 | 14 |
import java.util.HashSet; |
15 | 15 |
import java.util.Iterator; |
16 | 16 |
import java.util.Set; |
17 |
import java.util.UUID; |
|
17 | 18 |
|
18 | 19 |
import org.apache.log4j.Logger; |
19 | 20 |
import org.eclipse.core.commands.operations.IUndoContext; |
20 |
import org.eclipse.core.runtime.IStatus; |
|
21 |
import org.eclipse.core.runtime.Status; |
|
22 |
import org.eclipse.jface.dialogs.IconAndMessageDialog; |
|
23 | 21 |
import org.eclipse.jface.dialogs.MessageDialog; |
24 | 22 |
import org.eclipse.jface.util.LocalSelectionTransfer; |
25 | 23 |
import org.eclipse.jface.viewers.ISelection; |
26 | 24 |
import org.eclipse.jface.viewers.TreeSelection; |
27 |
import org.eclipse.jface.viewers.Viewer; |
|
28 | 25 |
import org.eclipse.jface.viewers.ViewerDropAdapter; |
29 | 26 |
import org.eclipse.swt.dnd.DND; |
30 | 27 |
import org.eclipse.swt.dnd.DropTargetEvent; |
31 | 28 |
import org.eclipse.swt.dnd.TransferData; |
32 |
import org.eclipse.swt.graphics.Image; |
|
33 |
import org.eclipse.swt.widgets.Shell; |
|
34 |
import org.eclipse.ui.handlers.HandlerUtil; |
|
35 |
import org.eclipse.ui.navigator.CommonDropAdapter; |
|
36 |
import org.eclipse.ui.navigator.CommonDropAdapterAssistant; |
|
37 |
import org.eclipse.ui.navigator.CommonViewer; |
|
38 | 29 |
|
39 | 30 |
import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper; |
40 | 31 |
import eu.etaxonomy.cdm.model.common.CdmBase; |
41 |
import eu.etaxonomy.cdm.model.common.OrderedTermBase; |
|
42 |
import eu.etaxonomy.cdm.model.common.TermBase; |
|
43 | 32 |
import eu.etaxonomy.cdm.model.taxon.Classification; |
44 | 33 |
import eu.etaxonomy.cdm.model.taxon.ITaxonTreeNode; |
45 | 34 |
import eu.etaxonomy.cdm.model.taxon.TaxonNode; |
46 | 35 |
import eu.etaxonomy.cdm.persistence.hibernate.permission.CRUD; |
47 |
import eu.etaxonomy.taxeditor.editor.definedterm.DefinedTermEditor; |
|
48 | 36 |
import eu.etaxonomy.taxeditor.navigation.NavigationUtil; |
49 | 37 |
import eu.etaxonomy.taxeditor.navigation.navigator.operation.MoveTaxonOperation; |
50 | 38 |
import eu.etaxonomy.taxeditor.operation.AbstractPostOperation; |
... | ... | |
67 | 55 |
protected TreeNodeDropAdapter(TaxonNavigatorViewer navigatorViewer) { |
68 | 56 |
super(navigatorViewer); |
69 | 57 |
this.navigatorViewer = navigatorViewer; |
70 |
|
|
58 |
|
|
71 | 59 |
} |
72 |
|
|
60 |
|
|
73 | 61 |
private final TaxonNavigatorViewer navigatorViewer; |
74 | 62 |
private static final Logger logger = Logger.getLogger(TreeNodeDropAdapter.class); |
75 | 63 |
|
... | ... | |
77 | 65 |
public static final String ID = "eu.etaxonomy.taxeditor.navigation.navigator.dropassistant"; //$NON-NLS-1$ |
78 | 66 |
|
79 | 67 |
private static final EnumSet<CRUD> UPDATE = EnumSet.of(CRUD.UPDATE); |
80 |
|
|
81 |
|
|
82 |
|
|
68 |
|
|
69 |
|
|
70 |
|
|
83 | 71 |
/* (non-Javadoc) |
84 | 72 |
* @see org.eclipse.ui.navigator.CommonDropAdapterAssistant#handleDrop(org.eclipse.ui.navigator.CommonDropAdapter, org.eclipse.swt.dnd.DropTargetEvent, java.lang.Object) |
85 | 73 |
*/ |
... | ... | |
87 | 75 |
@Override |
88 | 76 |
public boolean performDrop(Object target) { |
89 | 77 |
|
90 |
|
|
78 |
|
|
91 | 79 |
if (target instanceof ITaxonTreeNode) { |
92 | 80 |
Set<TaxonNode> taxonNodes = getSelectedTaxa(); |
93 | 81 |
ITaxonTreeNode targetTreeNode = (ITaxonTreeNode) target; |
... | ... | |
97 | 85 |
} |
98 | 86 |
if(taxonNodes != null) { |
99 | 87 |
if (taxonNodes.size() == 1){ |
100 |
return moveTaxon(taxonNodes.iterator().next(), targetTreeNode);
|
|
88 |
return moveTaxon(taxonNodes, targetTreeNode); |
|
101 | 89 |
} else{ |
102 | 90 |
if( MessageDialog.openConfirm(null, "Moving taxon", "The operation move accepted taxon to other parent is available only for a single taxon.")){ |
103 | 91 |
return true; |
... | ... | |
105 | 93 |
} |
106 | 94 |
} |
107 | 95 |
} |
108 |
|
|
96 |
|
|
109 | 97 |
return false; |
110 | 98 |
} |
111 | 99 |
|
... | ... | |
135 | 123 |
@Override |
136 | 124 |
public boolean validateDrop(Object target, int operation, |
137 | 125 |
TransferData transferType) { |
138 |
|
|
126 |
|
|
139 | 127 |
if (target instanceof ITaxonTreeNode) { |
140 |
|
|
128 |
|
|
141 | 129 |
// check users permissions with target taxonnode and taxon |
142 | 130 |
if (target instanceof TaxonNode) { |
143 | 131 |
TaxonNode targetNode = (TaxonNode)target; |
... | ... | |
187 | 175 |
* @param parentTaxon |
188 | 176 |
* @return |
189 | 177 |
*/ |
190 |
private boolean moveTaxon(TaxonNode taxonNode, ITaxonTreeNode targetITaxonTreeNode) {
|
|
178 |
private boolean moveTaxon(Set<TaxonNode> taxonNodes, ITaxonTreeNode targetITaxonTreeNode) {
|
|
191 | 179 |
|
192 | 180 |
TaxonNavigator taxonNavigator; |
193 | 181 |
taxonNavigator = (TaxonNavigator) NavigationUtil.showView(TaxonNavigator.ID); |
... | ... | |
203 | 191 |
} |
204 | 192 |
|
205 | 193 |
} |
194 |
Iterator<TaxonNode> taxIterator = taxonNodes.iterator(); |
|
195 |
Set<UUID> uuids = new HashSet<UUID>(); |
|
196 |
TaxonNode node = null; |
|
197 |
while(taxIterator.hasNext()){ |
|
198 |
node = taxIterator.next(); |
|
199 |
uuids.add(node.getUuid()); |
|
200 |
} |
|
206 | 201 |
if (!PreferencesUtil.getSortNodesNaturally()){ |
207 | 202 |
IUndoContext workspaceUndoContext = NavigationUtil.getWorkbenchUndoContext(); |
208 | 203 |
if (workspaceUndoContext == null) { |
209 | 204 |
logger.error("Workspace undo context is null. DND operation cancelled"); |
210 | 205 |
return false; |
211 | 206 |
} |
212 |
|
|
207 |
|
|
213 | 208 |
AbstractPostOperation operation = new MoveTaxonOperation |
214 |
("Move Taxon", workspaceUndoContext, taxonNode, targetITaxonTreeNode, this, taxonNavigator, true);
|
|
209 |
("Move Taxon", workspaceUndoContext, uuids, targetITaxonTreeNode, this, taxonNavigator, true);
|
|
215 | 210 |
NavigationUtil.executeOperation(operation); |
216 |
|
|
211 |
|
|
217 | 212 |
logger.info("Moved taxa to new parent " + targetITaxonTreeNode); |
218 | 213 |
return true; |
219 | 214 |
}else{ |
... | ... | |
227 | 222 |
logger.error("Workspace undo context is null. DND operation cancelled"); |
228 | 223 |
return false; |
229 | 224 |
} |
230 |
|
|
225 |
|
|
231 | 226 |
AbstractPostOperation operation = new MoveTaxonOperation |
232 |
("Move Taxon", workspaceUndoContext, taxonNode, targetITaxonTreeNode, this, taxonNavigator, true);
|
|
227 |
("Move Taxon", workspaceUndoContext, uuids, targetITaxonTreeNode, this, taxonNavigator, true);
|
|
233 | 228 |
NavigationUtil.executeOperation(operation); |
234 |
|
|
229 |
|
|
235 | 230 |
logger.info("Moved taxa to new parent " + targetITaxonTreeNode); |
236 | 231 |
return true; |
237 | 232 |
}else if (returnCode == 1){ |
... | ... | |
240 | 235 |
logger.error("Workspace undo context is null. DND operation cancelled"); |
241 | 236 |
return false; |
242 | 237 |
} |
243 |
|
|
238 |
|
|
244 | 239 |
AbstractPostOperation operation = new MoveTaxonOperation |
245 |
("Move Taxon", workspaceUndoContext, taxonNode, targetITaxonTreeNode, this, taxonNavigator, false);
|
|
240 |
("Move Taxon", workspaceUndoContext, uuids, targetITaxonTreeNode, this, taxonNavigator, false);
|
|
246 | 241 |
NavigationUtil.executeOperation(operation); |
247 |
|
|
242 |
|
|
248 | 243 |
logger.info("Moved taxa to new parent " + targetITaxonTreeNode); |
249 | 244 |
return true; |
250 | 245 |
} else{ |
251 | 246 |
return false; |
252 | 247 |
} |
253 |
|
|
254 |
|
|
248 |
|
|
249 |
|
|
255 | 250 |
} |
256 | 251 |
} |
257 | 252 |
|
... | ... | |
278 | 273 |
public void dragOver(DropTargetEvent event) { |
279 | 274 |
super.dragOver(event); |
280 | 275 |
event.feedback = DND.FEEDBACK_SELECT | DND.FEEDBACK_INSERT_AFTER; |
281 |
|
|
276 |
|
|
282 | 277 |
} |
283 |
|
|
278 |
|
|
284 | 279 |
} |
eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/TreeNodeDropAdapterAssistant.java | ||
---|---|---|
14 | 14 |
import java.util.HashSet; |
15 | 15 |
import java.util.Iterator; |
16 | 16 |
import java.util.Set; |
17 |
import java.util.UUID; |
|
17 | 18 |
|
18 | 19 |
import org.apache.log4j.Logger; |
19 | 20 |
import org.eclipse.core.commands.operations.IUndoContext; |
20 | 21 |
import org.eclipse.core.runtime.IStatus; |
21 | 22 |
import org.eclipse.core.runtime.Status; |
22 |
import org.eclipse.jface.dialogs.IconAndMessageDialog; |
|
23 | 23 |
import org.eclipse.jface.dialogs.MessageDialog; |
24 | 24 |
import org.eclipse.jface.util.LocalSelectionTransfer; |
25 | 25 |
import org.eclipse.jface.viewers.ISelection; |
26 | 26 |
import org.eclipse.jface.viewers.TreeSelection; |
27 | 27 |
import org.eclipse.swt.dnd.DropTargetEvent; |
28 | 28 |
import org.eclipse.swt.dnd.TransferData; |
29 |
import org.eclipse.swt.graphics.Image; |
|
30 |
import org.eclipse.swt.widgets.Shell; |
|
31 |
import org.eclipse.ui.handlers.HandlerUtil; |
|
32 | 29 |
import org.eclipse.ui.navigator.CommonDropAdapter; |
33 | 30 |
import org.eclipse.ui.navigator.CommonDropAdapterAssistant; |
34 | 31 |
|
... | ... | |
69 | 66 |
public IStatus handleDrop(CommonDropAdapter dropAdapter, |
70 | 67 |
DropTargetEvent dropTargetEvent, Object target) { |
71 | 68 |
|
72 |
|
|
69 |
|
|
73 | 70 |
if (target instanceof ITaxonTreeNode) { |
74 | 71 |
Set<TaxonNode> taxonNodes = getSelectedTaxa(); |
75 | 72 |
ITaxonTreeNode targetTreeNode = (ITaxonTreeNode) target; |
... | ... | |
77 | 74 |
targetTreeNode = ((Classification)targetTreeNode).getRootNode(); |
78 | 75 |
targetTreeNode = HibernateProxyHelper.deproxy(targetTreeNode, TaxonNode.class); |
79 | 76 |
} |
80 |
if(taxonNodes != null) { |
|
81 |
if (taxonNodes.size() == 1){
|
|
82 |
return moveTaxon(taxonNodes.iterator().next(), targetTreeNode);
|
|
83 |
} else{ |
|
77 |
//if(taxonNodes != null) {
|
|
78 |
if (taxonNodes.size() >= 1){
|
|
79 |
return moveTaxon(taxonNodes, targetTreeNode); |
|
80 |
/*} else{
|
|
84 | 81 |
if( MessageDialog.openConfirm(null, "Moving taxon", "The operation move accepted taxon to other parent is available only for a single taxon.")){ |
85 | 82 |
return null; |
86 | 83 |
} |
87 |
} |
|
84 |
}*/
|
|
88 | 85 |
} |
89 | 86 |
} |
90 |
|
|
87 |
|
|
91 | 88 |
return Status.CANCEL_STATUS; |
92 | 89 |
} |
93 | 90 |
|
... | ... | |
168 | 165 |
* @param parentTaxon |
169 | 166 |
* @return |
170 | 167 |
*/ |
171 |
private IStatus moveTaxon(TaxonNode taxonNode, ITaxonTreeNode targetITaxonTreeNode) {
|
|
168 |
private IStatus moveTaxon(Set<TaxonNode> taxonNodes, ITaxonTreeNode targetITaxonTreeNode) {
|
|
172 | 169 |
|
173 | 170 |
TaxonNavigator taxonNavigator; |
174 | 171 |
taxonNavigator = (TaxonNavigator) NavigationUtil.showView(TaxonNavigator.ID); |
... | ... | |
184 | 181 |
} |
185 | 182 |
|
186 | 183 |
} |
184 |
Iterator<TaxonNode> taxIterator = taxonNodes.iterator(); |
|
185 |
Set<UUID> uuids = new HashSet<UUID>(); |
|
186 |
TaxonNode node = null; |
|
187 |
while(taxIterator.hasNext()){ |
|
188 |
node = taxIterator.next(); |
|
189 |
uuids.add(node.getUuid()); |
|
190 |
} |
|
187 | 191 |
if (!PreferencesUtil.getSortNodesNaturally()){ |
188 | 192 |
IUndoContext workspaceUndoContext = NavigationUtil.getWorkbenchUndoContext(); |
189 | 193 |
if (workspaceUndoContext == null) { |
190 | 194 |
logger.error("Workspace undo context is null. DND operation cancelled"); |
191 | 195 |
return Status.CANCEL_STATUS; |
192 | 196 |
} |
193 |
|
|
197 |
|
|
194 | 198 |
AbstractPostOperation operation = new MoveTaxonOperation |
195 |
("Move Taxon", workspaceUndoContext, taxonNode, targetITaxonTreeNode, this, taxonNavigator, true);
|
|
199 |
("Move Taxon", workspaceUndoContext, uuids, targetITaxonTreeNode, this, taxonNavigator, true);
|
|
196 | 200 |
NavigationUtil.executeOperation(operation); |
197 |
|
|
201 |
|
|
198 | 202 |
logger.info("Moved taxa to new parent " + targetITaxonTreeNode); |
199 | 203 |
return Status.OK_STATUS; |
200 | 204 |
}else{ |
... | ... | |
208 | 212 |
logger.error("Workspace undo context is null. DND operation cancelled"); |
209 | 213 |
return Status.CANCEL_STATUS; |
210 | 214 |
} |
211 |
|
|
215 |
|
|
212 | 216 |
AbstractPostOperation operation = new MoveTaxonOperation |
213 |
("Move Taxon", workspaceUndoContext, taxonNode, targetITaxonTreeNode, this, taxonNavigator, true);
|
|
217 |
("Move Taxon", workspaceUndoContext, uuids, targetITaxonTreeNode, this, taxonNavigator, true);
|
|
214 | 218 |
NavigationUtil.executeOperation(operation); |
215 |
|
|
219 |
|
|
216 | 220 |
logger.info("Moved taxa to new parent " + targetITaxonTreeNode); |
217 | 221 |
return Status.OK_STATUS; |
218 | 222 |
}else if (returnCode == 1){ |
... | ... | |
221 | 225 |
logger.error("Workspace undo context is null. DND operation cancelled"); |
222 | 226 |
return Status.CANCEL_STATUS; |
223 | 227 |
} |
224 |
|
|
228 |
|
|
225 | 229 |
AbstractPostOperation operation = new MoveTaxonOperation |
226 |
("Move Taxon", workspaceUndoContext, taxonNode, targetITaxonTreeNode, this, taxonNavigator, false);
|
|
230 |
("Move Taxon", workspaceUndoContext, uuids, targetITaxonTreeNode, this, taxonNavigator, false);
|
|
227 | 231 |
NavigationUtil.executeOperation(operation); |
228 |
|
|
232 |
|
|
229 | 233 |
logger.info("Moved taxa to new parent " + targetITaxonTreeNode); |
230 | 234 |
return Status.OK_STATUS; |
231 | 235 |
} else{ |
232 | 236 |
return Status.CANCEL_STATUS; |
233 | 237 |
} |
234 |
|
|
235 |
|
|
238 |
|
|
239 |
|
|
236 | 240 |
} |
237 | 241 |
} |
238 | 242 |
|
eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/handler/MoveTaxonHandler.java | ||
---|---|---|
1 | 1 |
/** |
2 | 2 |
* Copyright (C) 2007 EDIT |
3 |
* European Distributed Institute of Taxonomy
|
|
3 |
* European Distributed Institute of Taxonomy |
|
4 | 4 |
* http://www.e-taxonomy.eu |
5 |
*
|
|
5 |
* |
|
6 | 6 |
* The contents of this file are subject to the Mozilla Public License Version 1.1 |
7 | 7 |
* See LICENSE.TXT at the top of this package for the full license terms. |
8 | 8 |
*/ |
... | ... | |
19 | 19 |
import org.eclipse.core.commands.AbstractHandler; |
20 | 20 |
import org.eclipse.core.commands.ExecutionEvent; |
21 | 21 |
import org.eclipse.core.commands.ExecutionException; |
22 |
import org.eclipse.core.expressions.EvaluationContext; |
|
23 | 22 |
import org.eclipse.jface.dialogs.MessageDialog; |
24 | 23 |
import org.eclipse.jface.viewers.TreeSelection; |
25 |
import org.eclipse.ui.IEditorInput; |
|
26 |
import org.eclipse.ui.IEditorReference; |
|
27 | 24 |
import org.eclipse.ui.IWorkbenchPage; |
28 |
import org.eclipse.ui.PartInitException; |
|
29 | 25 |
import org.eclipse.ui.handlers.HandlerUtil; |
30 | 26 |
|
31 |
import eu.etaxonomy.cdm.api.application.ICdmApplicationConfiguration; |
|
32 |
import eu.etaxonomy.cdm.api.service.ITaxonNodeService; |
|
33 | 27 |
import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper; |
34 | 28 |
import eu.etaxonomy.cdm.model.common.CdmBase; |
35 |
import eu.etaxonomy.cdm.model.common.ITreeNode; |
|
36 |
import eu.etaxonomy.cdm.model.taxon.ITaxonTreeNode; |
|
37 | 29 |
import eu.etaxonomy.cdm.model.taxon.TaxonNode; |
38 |
import eu.etaxonomy.taxeditor.editor.TaxonEditorInput; |
|
39 | 30 |
import eu.etaxonomy.taxeditor.navigation.NavigationUtil; |
40 | 31 |
import eu.etaxonomy.taxeditor.navigation.navigator.TaxonNavigator; |
41 | 32 |
import eu.etaxonomy.taxeditor.navigation.navigator.operation.MoveTaxonOperation; |
42 | 33 |
import eu.etaxonomy.taxeditor.operation.AbstractPostOperation; |
43 | 34 |
import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled; |
44 | 35 |
import eu.etaxonomy.taxeditor.preference.PreferencesUtil; |
45 |
import eu.etaxonomy.taxeditor.store.CdmStore; |
|
46 | 36 |
import eu.etaxonomy.taxeditor.ui.dialog.selection.TaxonNodeSelectionDialog; |
47 |
import eu.etaxonomy.taxeditor.ui.dialog.selection.TaxonNodeSelectionNaturalOrderDialog; |
|
48 | 37 |
|
49 | 38 |
/** |
50 | 39 |
* <p>MoveTaxonHandler class.</p> |
... | ... | |
61 | 50 |
* @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent) |
62 | 51 |
*/ |
63 | 52 |
/** {@inheritDoc} */ |
64 |
public Object execute(ExecutionEvent event) throws ExecutionException { |
|
53 |
@Override |
|
54 |
public Object execute(ExecutionEvent event) throws ExecutionException { |
|
65 | 55 |
activePage = HandlerUtil.getActiveWorkbenchWindow(event).getActivePage(); |
66 | 56 |
TaxonNavigator taxonNavigator = (TaxonNavigator)NavigationUtil.showView(TaxonNavigator.ID); |
67 |
|
|
57 |
|
|
68 | 58 |
TreeSelection selection = (TreeSelection) HandlerUtil.getCurrentSelection(event); |
69 |
|
|
59 |
|
|
70 | 60 |
Iterator selectionIterator = selection.iterator(); |
71 |
TaxonNode taxonNode = null; |
|
72 |
UUID taxonNodeUUID = null; |
|
61 |
Set<TaxonNode> taxonNodes = new HashSet<TaxonNode>(); |
|
62 |
TaxonNode taxonNode= null; |
|
63 |
Set<UUID> taxonNodeUUIDs = new HashSet<UUID>(); |
|
73 | 64 |
// do not show the current selection |
74 | 65 |
List<UUID> excludeTaxa = new ArrayList<UUID>(); |
75 |
|
|
76 |
if (selection.size() == 1){ |
|
66 |
|
|
67 |
//if (selection.size() == 1){ |
|
68 |
|
|
69 |
while (selectionIterator.hasNext()){ |
|
77 | 70 |
Object object = selectionIterator.next(); |
78 | 71 |
if(object instanceof TaxonNode){ |
79 |
taxonNode = HibernateProxyHelper.deproxy(object,TaxonNode.class); |
|
80 |
taxonNodeUUID = taxonNode.getUuid(); |
|
72 |
taxonNode = HibernateProxyHelper.deproxy(object,TaxonNode.class); |
|
73 |
taxonNodes.add(taxonNode); |
|
74 |
taxonNodeUUIDs.add(taxonNode.getUuid()); |
|
81 | 75 |
excludeTaxa.add(taxonNode.getTaxon().getUuid()); |
82 | 76 |
} |
83 |
} else{ |
|
77 |
} |
|
78 |
/*} else{ |
|
84 | 79 |
if( MessageDialog.openConfirm(HandlerUtil.getActiveShell(event), "Moving taxon", "The operation move accepted taxon to other parent is available only for a single taxon.")){ |
85 | 80 |
return null; |
86 | 81 |
} |
87 |
} |
|
88 |
|
|
89 |
|
|
82 |
}*/
|
|
83 |
|
|
84 |
|
|
90 | 85 |
// TaxonNode taxonNode = (TaxonNode) selection.getFirstElement(); |
91 |
if (taxonNode != null){
|
|
92 |
boolean moveToNewParent = true;
|
|
86 |
if (taxonNodes.size() >= 1){
|
|
87 |
boolean moveToNewParent = true; |
|
93 | 88 |
if (PreferencesUtil.getSortNodesNaturally()){ |
94 | 89 |
if(!MessageDialog.openQuestion(null, "Target node", "The choosen target node should be the parent?")){ |
95 | 90 |
moveToNewParent = false; |
... | ... | |
104 | 99 |
"changes in the parent taxon. Please save first."); |
105 | 100 |
return null; |
106 | 101 |
} |
107 |
|
|
102 |
|
|
108 | 103 |
AbstractPostOperation operation = new MoveTaxonOperation |
109 | 104 |
("Move taxon to new parent", NavigationUtil.getUndoContext(), |
110 |
taxonNode, parentTaxonNode, taxonNavigator, taxonNavigator, moveToNewParent); //$NON-NLS-1$ |
|
105 |
taxonNodeUUIDs, parentTaxonNode, taxonNavigator, taxonNavigator, moveToNewParent); //$NON-NLS-1$
|
|
111 | 106 |
NavigationUtil.executeOperation(operation); |
112 | 107 |
taxonNavigator.refresh(); |
113 |
|
|
108 |
|
|
114 | 109 |
} |
115 | 110 |
} |
116 | 111 |
return null; |
... | ... | |
120 | 115 |
* @see eu.etaxonomy.taxeditor.operations.IPostOperationEnabled#postOperation(eu.etaxonomy.cdm.model.common.CdmBase) |
121 | 116 |
*/ |
122 | 117 |
/** {@inheritDoc} */ |
123 |
public boolean postOperation(CdmBase objectAffectedByOperation) { |
|
118 |
@Override |
|
119 |
public boolean postOperation(CdmBase objectAffectedByOperation) { |
|
124 | 120 |
return true; |
125 | 121 |
} |
126 | 122 |
|
... | ... | |
129 | 125 |
* |
130 | 126 |
* @return a boolean. |
131 | 127 |
*/ |
132 |
public boolean onComplete() { |
|
128 |
@Override |
|
129 |
public boolean onComplete() { |
|
133 | 130 |
return false; |
134 | 131 |
} |
135 |
|
|
136 |
|
|
137 |
|
|
132 |
|
|
133 |
|
|
134 |
|
|
138 | 135 |
} |
eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/operation/MoveTaxonOperation.java | ||
---|---|---|
9 | 9 |
|
10 | 10 |
package eu.etaxonomy.taxeditor.navigation.navigator.operation; |
11 | 11 |
|
12 |
import java.util.HashMap; |
|
13 |
import java.util.HashSet; |
|
14 |
import java.util.Map; |
|
15 | 12 |
import java.util.Set; |
16 | 13 |
import java.util.UUID; |
17 | 14 |
|
... | ... | |
22 | 19 |
import org.eclipse.core.runtime.IStatus; |
23 | 20 |
import org.eclipse.core.runtime.Status; |
24 | 21 |
|
25 |
import eu.etaxonomy.cdm.api.application.ICdmApplicationConfiguration; |
|
26 | 22 |
import eu.etaxonomy.cdm.api.conversation.IConversationEnabled; |
27 | 23 |
import eu.etaxonomy.cdm.api.service.ITaxonNodeService; |
28 | 24 |
import eu.etaxonomy.cdm.api.service.UpdateResult; |
29 | 25 |
import eu.etaxonomy.cdm.model.taxon.ITaxonTreeNode; |
30 |
import eu.etaxonomy.cdm.model.taxon.IllegalAncestryException; |
|
31 |
import eu.etaxonomy.cdm.model.taxon.TaxonNode; |
|
32 | 26 |
import eu.etaxonomy.taxeditor.model.MessagingUtils; |
33 | 27 |
import eu.etaxonomy.taxeditor.operation.AbstractPersistentPostOperation; |
34 | 28 |
import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled; |
... | ... | |
46 | 40 |
/** |
47 | 41 |
* A reference to the new taxonomical parent. |
48 | 42 |
*/ |
49 |
private ITaxonTreeNode newParentTreeNode; |
|
43 |
private final ITaxonTreeNode newParentTreeNode;
|
|
50 | 44 |
/** |
51 | 45 |
* A reference to the former taxonomical parents |
52 | 46 |
*/ |
53 | 47 |
//private Map<TaxonNode, ITaxonTreeNode> oldParentTreeNodes; |
54 | 48 |
|
55 |
private TaxonNode taxonNode;
|
|
56 |
private boolean moveToParentNode; |
|
49 |
private final Set<UUID> taxonNodesUuid;
|
|
50 |
private final boolean moveToParentNode;
|
|
57 | 51 |
/** |
58 | 52 |
* <p>Constructor for MoveTaxonOperation.</p> |
59 | 53 |
* |
... | ... | |
65 | 59 |
* @param conversationEnabled a {@link eu.etaxonomy.cdm.api.conversation.IConversationEnabled} object. |
66 | 60 |
*/ |
67 | 61 |
public MoveTaxonOperation(String label, IUndoContext undoContext, |
68 |
TaxonNode taxonNodeToMove, ITaxonTreeNode newParentTreeNode, IPostOperationEnabled postOperationEnabled, IConversationEnabled conversationEnabled, boolean moveToParentNode) {
|
|
62 |
Set<UUID> taxonNodesUUIDToMove, ITaxonTreeNode newParentTreeNode, IPostOperationEnabled postOperationEnabled, IConversationEnabled conversationEnabled, boolean moveToParentNode) {
|
|
69 | 63 |
super(label, undoContext, postOperationEnabled, conversationEnabled); |
70 |
|
|
71 |
this.taxonNode = taxonNodeToMove;
|
|
64 |
|
|
65 |
this.taxonNodesUuid = taxonNodesUUIDToMove;
|
|
72 | 66 |
/*for (TaxonNode node:taxonNodes){ |
73 | 67 |
this.taxonNodes.add(service.load(node.getUuid())); |
74 | 68 |
}*/ |
75 |
|
|
69 |
|
|
76 | 70 |
this.newParentTreeNode = newParentTreeNode; |
77 | 71 |
this.moveToParentNode = moveToParentNode; |
78 | 72 |
// Save old parent ITaxonTreeNodes for undo |
79 |
|
|
73 |
|
|
80 | 74 |
//this.parentNode = taxonNode.getParent(); |
81 | 75 |
} |
82 | 76 |
|
... | ... | |
90 | 84 |
bind(); |
91 | 85 |
monitor.worked(20); |
92 | 86 |
|
93 |
UpdateResult result = CdmStore.getService(ITaxonNodeService.class).moveTaxonNode(this.taxonNode.getUuid(),newParentTreeNode.getUuid(), moveToParentNode);
|
|
87 |
UpdateResult result = CdmStore.getService(ITaxonNodeService.class).moveTaxonNodes(this.taxonNodesUuid,newParentTreeNode.getUuid());
|
|
94 | 88 |
// try { |
95 | 89 |
// for (TaxonNode taxonNode : taxonNodes){ |
96 | 90 |
// TaxonNode newTaxonNode = newParentTreeNode.addChildNode(taxonNode, |
97 | 91 |
// newParentTreeNode.getReference(), newParentTreeNode.getMicroReference()); |
98 | 92 |
// //taxonNodes.add(newTaxonNode); |
99 |
//
|
|
93 |
// |
|
100 | 94 |
// monitor.worked(2); |
101 | 95 |
// } |
102 | 96 |
// } catch(IllegalAncestryException e) { |
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/classification/TaxonNodeDetailElement.java | ||
---|---|---|
174 | 174 |
textNewTaxonName.setEnabled(enabled); |
175 | 175 |
|
176 | 176 |
setTaxon(selection_reuseExistingName.getEntity()); |
177 |
complete = !textNewTaxonName.getText().isEmpty(); |
|
177 | 178 |
} else if (eventSource == textNewTaxonName) { |
178 | 179 |
boolean enabled = CdmUtils.isBlank(textNewTaxonName.getText()); |
179 | 180 |
selection_reuseExistingTaxon.setEnabled(enabled); |
Also available in: Unified diff
moving more than one taxon node, merge of team and person, reusing name for new taxon