Project

General

Profile

Download (2.89 KB) Statistics
| Branch: | Tag: | Revision:
1
/**
2
* Copyright (C) 2007 EDIT
3
* European Distributed Institute of Taxonomy 
4
* http://www.e-taxonomy.eu
5
* 
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.
8
*/
9

    
10
package eu.etaxonomy.taxeditor.bulkeditor.handler;
11

    
12
import java.util.HashSet;
13
import java.util.Iterator;
14
import java.util.Set;
15

    
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;
24

    
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;
33

    
34
/**
35
 * <p>SetMarkerFlagTrueHandler class.</p>
36
 *
37
 * @author p.ciardelli
38
 * @created 20.10.2009
39
 * @version 1.0
40
 */
41
public class SetMarkerFlagHandler extends AbstractHandler {
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
		ISelection selection = HandlerUtil.getCurrentSelection(event);
50
		
51
		IEditorPart editor = HandlerUtil.getActiveEditor(event);
52
		
53
		Object[] data = (Object[]) ((Event) event.getTrigger()).data;
54
		
55
		if (selection instanceof TextSelection 
56
					&& editor instanceof BulkEditor) {
57
			TextSelection textSelection = (TextSelection) selection;
58
			BulkEditor bulkEditor = (BulkEditor) editor;
59
			
60
			LineAnnotationModel model = (LineAnnotationModel) bulkEditor.getDocumentProvider().getAnnotationModel(editor.getEditorInput());
61
			if (model != null) {
62
				Iterator iter = model.getAnnotationIterator(textSelection.getOffset(), textSelection.getLength(), true, true);
63
				
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();
69
						
70
						if(entity instanceof IAnnotatableEntity){
71
							annotatableEntities.add((IAnnotatableEntity) entity);
72
						}
73
					}
74
				}
75
								
76
				AbstractPostOperation operation = new SetMarkerFlagOperation("Set Marker", BulkEditorUtil.getUndoContext(), annotatableEntities, (MarkerType) data[0], (Boolean) data[1], bulkEditor);
77
				BulkEditorUtil.executeOperation(operation);
78
			}
79
		}
80
		return null;
81
	}
82
}
(7-7/9)