Revision 3be6ef3e
Added by Niels Hoffmann over 13 years ago
taxeditor-bulkeditor/src/main/java/eu/etaxonomy/taxeditor/bulkeditor/handler/SetMarkerFlagFalseHandler.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.handler; |
|
12 |
|
|
13 |
import java.beans.PropertyChangeEvent; |
|
14 |
import java.util.Iterator; |
|
15 |
|
|
16 |
import org.apache.log4j.Logger; |
|
17 |
import org.eclipse.core.commands.AbstractHandler; |
|
18 |
import org.eclipse.core.commands.ExecutionEvent; |
|
19 |
import org.eclipse.core.commands.ExecutionException; |
|
20 |
import org.eclipse.jface.text.TextSelection; |
|
21 |
import org.eclipse.swt.widgets.Event; |
|
22 |
import org.eclipse.ui.handlers.HandlerUtil; |
|
23 |
|
|
24 |
import eu.etaxonomy.cdm.model.common.AnnotatableEntity; |
|
25 |
import eu.etaxonomy.cdm.model.common.CdmBase; |
|
26 |
import eu.etaxonomy.cdm.model.common.Marker; |
|
27 |
import eu.etaxonomy.cdm.model.common.MarkerType; |
|
28 |
import eu.etaxonomy.taxeditor.annotatedlineeditor.LineAnnotation; |
|
29 |
import eu.etaxonomy.taxeditor.annotatedlineeditor.LineAnnotationModel; |
|
30 |
import eu.etaxonomy.taxeditor.bulkeditor.BulkEditor; |
|
31 |
|
|
32 |
/** |
|
33 |
* @author p.ciardelli |
|
34 |
* @created 20.10.2009 |
|
35 |
* @version 1.0 |
|
36 |
*/ |
|
37 |
public class SetMarkerFlagFalseHandler extends AbstractHandler { |
|
38 |
private static final Logger logger = Logger |
|
39 |
.getLogger(SetMarkerFlagFalseHandler.class); |
|
40 |
|
|
41 |
/* (non-Javadoc) |
|
42 |
* @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent) |
|
43 |
*/ |
|
44 |
public Object execute(ExecutionEvent event) throws ExecutionException { |
|
45 |
|
|
46 |
// TODO merge this w SetMarkerFlagTrueHandler |
|
47 |
|
|
48 |
Object data = ((Event) event.getTrigger()).data; |
|
49 |
|
|
50 |
if (HandlerUtil.getCurrentSelection(event) instanceof TextSelection |
|
51 |
&& HandlerUtil.getActiveEditor(event) instanceof BulkEditor && data instanceof MarkerType) { |
|
52 |
TextSelection selection = (TextSelection) HandlerUtil.getCurrentSelection(event); |
|
53 |
BulkEditor editor = (BulkEditor) HandlerUtil.getActiveEditor(event); |
|
54 |
|
|
55 |
LineAnnotationModel model = (LineAnnotationModel) editor.getDocumentProvider().getAnnotationModel(editor.getEditorInput()); |
|
56 |
if (model != null) { |
|
57 |
Iterator iter = model.getAnnotationIterator(selection.getOffset(), selection.getLength(), true, true); |
|
58 |
while (iter.hasNext()) { |
|
59 |
Object next = iter.next(); |
|
60 |
if (next instanceof LineAnnotation) { |
|
61 |
Object entity = ((LineAnnotation) next).getEntity(); |
|
62 |
createOrUpdateMarker((AnnotatableEntity) entity, (MarkerType) data, false); |
|
63 |
((CdmBase) entity).firePropertyChange(new PropertyChangeEvent(entity, "", null, null)); |
|
64 |
} |
|
65 |
} |
|
66 |
} |
|
67 |
} |
|
68 |
return null; |
|
69 |
} |
|
70 |
|
|
71 |
/** |
|
72 |
* @param entity |
|
73 |
* @param publish |
|
74 |
* @param flag |
|
75 |
*/ |
|
76 |
private void createOrUpdateMarker(AnnotatableEntity entity, |
|
77 |
MarkerType markerType, boolean flag) { |
|
78 |
for (Marker marker : entity.getMarkers()) { |
|
79 |
if (markerType.equals(marker.getMarkerType())) { |
|
80 |
marker.setFlag(flag); |
|
81 |
return; |
|
82 |
} |
|
83 |
} |
|
84 |
entity.addMarker(Marker.NewInstance(markerType, flag)); |
|
85 |
} |
|
86 |
} |
|
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.handler; |
|
12 |
|
|
13 |
import java.beans.PropertyChangeEvent; |
|
14 |
import java.util.Iterator; |
|
15 |
|
|
16 |
import org.apache.log4j.Logger; |
|
17 |
import org.eclipse.core.commands.AbstractHandler; |
|
18 |
import org.eclipse.core.commands.ExecutionEvent; |
|
19 |
import org.eclipse.core.commands.ExecutionException; |
|
20 |
import org.eclipse.jface.text.TextSelection; |
|
21 |
import org.eclipse.swt.widgets.Event; |
|
22 |
import org.eclipse.ui.handlers.HandlerUtil; |
|
23 |
|
|
24 |
import eu.etaxonomy.cdm.model.common.AnnotatableEntity; |
|
25 |
import eu.etaxonomy.cdm.model.common.CdmBase; |
|
26 |
import eu.etaxonomy.cdm.model.common.Marker; |
|
27 |
import eu.etaxonomy.cdm.model.common.MarkerType; |
|
28 |
import eu.etaxonomy.taxeditor.annotatedlineeditor.LineAnnotation; |
|
29 |
import eu.etaxonomy.taxeditor.annotatedlineeditor.LineAnnotationModel; |
|
30 |
import eu.etaxonomy.taxeditor.bulkeditor.BulkEditor; |
|
31 |
|
|
32 |
/** |
|
33 |
* <p>SetMarkerFlagFalseHandler class.</p> |
|
34 |
* |
|
35 |
* @author p.ciardelli |
|
36 |
* @created 20.10.2009 |
|
37 |
* @version 1.0 |
|
38 |
*/ |
|
39 |
public class SetMarkerFlagFalseHandler extends AbstractHandler { |
|
40 |
private static final Logger logger = Logger |
|
41 |
.getLogger(SetMarkerFlagFalseHandler.class); |
|
42 |
|
|
43 |
/* (non-Javadoc) |
|
44 |
* @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent) |
|
45 |
*/ |
|
46 |
/** {@inheritDoc} */ |
|
47 |
public Object execute(ExecutionEvent event) throws ExecutionException { |
|
48 |
|
|
49 |
// TODO merge this w SetMarkerFlagTrueHandler |
|
50 |
|
|
51 |
Object data = ((Event) event.getTrigger()).data; |
|
52 |
|
|
53 |
if (HandlerUtil.getCurrentSelection(event) instanceof TextSelection |
|
54 |
&& HandlerUtil.getActiveEditor(event) instanceof BulkEditor && data instanceof MarkerType) { |
|
55 |
TextSelection selection = (TextSelection) HandlerUtil.getCurrentSelection(event); |
|
56 |
BulkEditor editor = (BulkEditor) HandlerUtil.getActiveEditor(event); |
|
57 |
|
|
58 |
LineAnnotationModel model = (LineAnnotationModel) editor.getDocumentProvider().getAnnotationModel(editor.getEditorInput()); |
|
59 |
if (model != null) { |
|
60 |
Iterator iter = model.getAnnotationIterator(selection.getOffset(), selection.getLength(), true, true); |
|
61 |
while (iter.hasNext()) { |
|
62 |
Object next = iter.next(); |
|
63 |
if (next instanceof LineAnnotation) { |
|
64 |
Object entity = ((LineAnnotation) next).getEntity(); |
|
65 |
createOrUpdateMarker((AnnotatableEntity) entity, (MarkerType) data, false); |
|
66 |
((CdmBase) entity).firePropertyChange(new PropertyChangeEvent(entity, "", null, null)); |
|
67 |
} |
|
68 |
} |
|
69 |
} |
|
70 |
} |
|
71 |
return null; |
|
72 |
} |
|
73 |
|
|
74 |
/** |
|
75 |
* @param entity |
|
76 |
* @param publish |
|
77 |
* @param flag |
|
78 |
*/ |
|
79 |
private void createOrUpdateMarker(AnnotatableEntity entity, |
|
80 |
MarkerType markerType, boolean flag) { |
|
81 |
for (Marker marker : entity.getMarkers()) { |
|
82 |
if (markerType.equals(marker.getMarkerType())) { |
|
83 |
marker.setFlag(flag); |
|
84 |
return; |
|
85 |
} |
|
86 |
} |
|
87 |
entity.addMarker(Marker.NewInstance(markerType, flag)); |
|
88 |
} |
|
89 |
} |
Also available in: Unified diff
performed javacscript:fix and worked on documentation