2 * Copyright (C) 2007 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
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.
10 package eu
.etaxonomy
.taxeditor
.bulkeditor
.handler
;
12 import java
.util
.HashSet
;
13 import java
.util
.Iterator
;
16 import org
.eclipse
.core
.commands
.AbstractHandler
;
17 import org
.eclipse
.core
.commands
.ExecutionEvent
;
18 import org
.eclipse
.core
.commands
.ExecutionException
;
19 import org
.eclipse
.jface
.text
.TextSelection
;
20 import org
.eclipse
.jface
.viewers
.ISelection
;
21 import org
.eclipse
.swt
.widgets
.Event
;
22 import org
.eclipse
.ui
.IEditorPart
;
23 import org
.eclipse
.ui
.handlers
.HandlerUtil
;
25 import eu
.etaxonomy
.cdm
.model
.common
.IAnnotatableEntity
;
26 import eu
.etaxonomy
.cdm
.model
.common
.MarkerType
;
27 import eu
.etaxonomy
.taxeditor
.annotatedlineeditor
.LineAnnotation
;
28 import eu
.etaxonomy
.taxeditor
.annotatedlineeditor
.LineAnnotationModel
;
29 import eu
.etaxonomy
.taxeditor
.bulkeditor
.BulkEditor
;
30 import eu
.etaxonomy
.taxeditor
.bulkeditor
.BulkEditorUtil
;
31 import eu
.etaxonomy
.taxeditor
.bulkeditor
.operation
.SetMarkerFlagOperation
;
32 import eu
.etaxonomy
.taxeditor
.operation
.AbstractPostOperation
;
35 * <p>SetMarkerFlagTrueHandler class.</p>
41 public class SetMarkerFlagHandler
extends AbstractHandler
{
44 * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
47 public Object
execute(ExecutionEvent event
) throws ExecutionException
{
49 ISelection selection
= HandlerUtil
.getCurrentSelection(event
);
51 IEditorPart editor
= HandlerUtil
.getActiveEditor(event
);
53 Object
[] data
= (Object
[]) ((Event
) event
.getTrigger()).data
;
55 if (selection
instanceof TextSelection
56 && editor
instanceof BulkEditor
) {
57 TextSelection textSelection
= (TextSelection
) selection
;
58 BulkEditor bulkEditor
= (BulkEditor
) editor
;
60 LineAnnotationModel model
= (LineAnnotationModel
) bulkEditor
.getDocumentProvider().getAnnotationModel(editor
.getEditorInput());
62 Iterator iter
= model
.getAnnotationIterator(textSelection
.getOffset(), textSelection
.getLength(), true, true);
64 Set
<IAnnotatableEntity
> annotatableEntities
= new HashSet
<IAnnotatableEntity
>();
65 while (iter
.hasNext()) {
66 Object next
= iter
.next();
67 if (next
instanceof LineAnnotation
) {
68 Object entity
= ((LineAnnotation
) next
).getEntity();
70 if(entity
instanceof IAnnotatableEntity
){
71 annotatableEntities
.add((IAnnotatableEntity
) entity
);
76 AbstractPostOperation operation
= new SetMarkerFlagOperation("Set Marker", BulkEditorUtil
.getUndoContext(), annotatableEntities
, (MarkerType
) data
[0], (Boolean
) data
[1], bulkEditor
);
77 BulkEditorUtil
.executeOperation(operation
);