3 * Copyright (C) 2007 EDIT
4 * European Distributed Institute of Taxonomy
5 * http://www.e-taxonomy.eu
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.
11 package eu
.etaxonomy
.taxeditor
.bulkeditor
.handler
;
13 import java
.util
.HashSet
;
14 import java
.util
.Iterator
;
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
.jface
.viewers
.ISelection
;
22 import org
.eclipse
.swt
.widgets
.Event
;
23 import org
.eclipse
.ui
.IEditorPart
;
24 import org
.eclipse
.ui
.handlers
.HandlerUtil
;
26 import eu
.etaxonomy
.cdm
.model
.common
.IAnnotatableEntity
;
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 import eu
.etaxonomy
.taxeditor
.bulkeditor
.BulkEditorUtil
;
32 import eu
.etaxonomy
.taxeditor
.bulkeditor
.operation
.SetMarkerFlagOperation
;
33 import eu
.etaxonomy
.taxeditor
.operation
.AbstractPostOperation
;
36 * <p>SetMarkerFlagTrueHandler class.</p>
42 public class SetMarkerFlagHandler
extends AbstractHandler
{
45 * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
48 public Object
execute(ExecutionEvent event
) throws ExecutionException
{
50 ISelection selection
= HandlerUtil
.getCurrentSelection(event
);
52 IEditorPart editor
= HandlerUtil
.getActiveEditor(event
);
54 Object
[] data
= (Object
[]) ((Event
) event
.getTrigger()).data
;
56 if (selection
instanceof TextSelection
57 && editor
instanceof BulkEditor
) {
58 TextSelection textSelection
= (TextSelection
) selection
;
59 BulkEditor bulkEditor
= (BulkEditor
) editor
;
61 LineAnnotationModel model
= (LineAnnotationModel
) bulkEditor
.getDocumentProvider().getAnnotationModel(editor
.getEditorInput());
63 Iterator iter
= model
.getAnnotationIterator(textSelection
.getOffset(), textSelection
.getLength(), true, true);
65 Set
<IAnnotatableEntity
> annotatableEntities
= new HashSet
<IAnnotatableEntity
>();
66 while (iter
.hasNext()) {
67 Object next
= iter
.next();
68 if (next
instanceof LineAnnotation
) {
69 Object entity
= ((LineAnnotation
) next
).getEntity();
71 if(entity
instanceof IAnnotatableEntity
){
72 annotatableEntities
.add((IAnnotatableEntity
) entity
);
77 AbstractPostOperation operation
= new SetMarkerFlagOperation("Set Marker", BulkEditorUtil
.getUndoContext(), annotatableEntities
, (MarkerType
) data
[0], (Boolean
) data
[1], bulkEditor
);
78 BulkEditorUtil
.executeOperation(operation
);