1 |
db5e366d
|
n.hoffmann
|
// $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.util.HashSet;
|
14 |
|
|
import java.util.Iterator;
|
15 |
|
|
import java.util.Set;
|
16 |
|
|
|
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;
|
25 |
|
|
|
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;
|
34 |
|
|
|
35 |
|
|
/**
|
36 |
|
|
* <p>SetMarkerFlagTrueHandler class.</p>
|
37 |
|
|
*
|
38 |
|
|
* @author p.ciardelli
|
39 |
|
|
* @created 20.10.2009
|
40 |
|
|
* @version 1.0
|
41 |
|
|
*/
|
42 |
|
|
public class SetMarkerFlagHandler extends AbstractHandler {
|
43 |
|
|
|
44 |
|
|
/* (non-Javadoc)
|
45 |
|
|
* @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
|
46 |
|
|
*/
|
47 |
|
|
/** {@inheritDoc} */
|
48 |
|
|
public Object execute(ExecutionEvent event) throws ExecutionException {
|
49 |
|
|
|
50 |
|
|
ISelection selection = HandlerUtil.getCurrentSelection(event);
|
51 |
|
|
|
52 |
|
|
IEditorPart editor = HandlerUtil.getActiveEditor(event);
|
53 |
|
|
|
54 |
|
|
Object[] data = (Object[]) ((Event) event.getTrigger()).data;
|
55 |
|
|
|
56 |
|
|
if (selection instanceof TextSelection
|
57 |
|
|
&& editor instanceof BulkEditor) {
|
58 |
|
|
TextSelection textSelection = (TextSelection) selection;
|
59 |
|
|
BulkEditor bulkEditor = (BulkEditor) editor;
|
60 |
|
|
|
61 |
|
|
LineAnnotationModel model = (LineAnnotationModel) bulkEditor.getDocumentProvider().getAnnotationModel(editor.getEditorInput());
|
62 |
|
|
if (model != null) {
|
63 |
|
|
Iterator iter = model.getAnnotationIterator(textSelection.getOffset(), textSelection.getLength(), true, true);
|
64 |
|
|
|
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();
|
70 |
|
|
|
71 |
|
|
if(entity instanceof IAnnotatableEntity){
|
72 |
|
|
annotatableEntities.add((IAnnotatableEntity) entity);
|
73 |
|
|
}
|
74 |
|
|
}
|
75 |
|
|
}
|
76 |
|
|
|
77 |
|
|
AbstractPostOperation operation = new SetMarkerFlagOperation("Set Marker", BulkEditorUtil.getUndoContext(), annotatableEntities, (MarkerType) data[0], (Boolean) data[1], bulkEditor);
|
78 |
|
|
BulkEditorUtil.executeOperation(operation);
|
79 |
|
|
}
|
80 |
|
|
}
|
81 |
|
|
return null;
|
82 |
|
|
}
|
83 |
|
|
}
|