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
|
}
|