adapt master to develop
[taxeditor.git] / eu.etaxonomy.taxeditor.bulkeditor / src / main / java / eu / etaxonomy / taxeditor / bulkeditor / operation / SetMarkerFlagOperation.java
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 package eu.etaxonomy.taxeditor.bulkeditor.operation;
10
11 import java.util.Set;
12
13 import org.eclipse.core.commands.ExecutionException;
14 import org.eclipse.core.commands.operations.IUndoContext;
15 import org.eclipse.core.runtime.IAdaptable;
16 import org.eclipse.core.runtime.IProgressMonitor;
17 import org.eclipse.core.runtime.IStatus;
18
19 import eu.etaxonomy.cdm.model.common.IAnnotatableEntity;
20 import eu.etaxonomy.cdm.model.common.Marker;
21 import eu.etaxonomy.cdm.model.common.MarkerType;
22 import eu.etaxonomy.taxeditor.operation.AbstractPostTaxonOperation;
23 import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
24
25 /**
26 * @author n.hoffmann
27 * @created Dec 13, 2010
28 */
29 public class SetMarkerFlagOperation extends AbstractPostTaxonOperation {
30
31 private Set<IAnnotatableEntity> annotatableEntities;
32 private MarkerType markerType;
33 private boolean value;
34
35 public SetMarkerFlagOperation(String label, IUndoContext undoContext,
36 Set<IAnnotatableEntity> annotatableEntities, MarkerType markerType, boolean value,
37 IPostOperationEnabled postOperationEnabled) {
38 super(label, undoContext, postOperationEnabled);
39 this.annotatableEntities = annotatableEntities;
40 this.markerType = markerType;
41 this.value = value;
42 }
43
44 @Override
45 public IStatus execute(IProgressMonitor monitor, IAdaptable info)
46 throws ExecutionException {
47
48 for(IAnnotatableEntity annotatableEntity : annotatableEntities){
49 Marker marker = Marker.NewInstance(markerType, value);
50
51 annotatableEntity.addMarker(marker);
52 }
53
54 return postExecute(null);
55 }
56
57 @Override
58 public IStatus redo(IProgressMonitor monitor, IAdaptable info)
59 throws ExecutionException {
60 return execute(monitor, info);
61 }
62
63 @Override
64 public IStatus undo(IProgressMonitor monitor, IAdaptable info)
65 throws ExecutionException {
66 for(IAnnotatableEntity annotatableEntity : annotatableEntities){
67 Marker marker = Marker.NewInstance(markerType, ! value);
68
69 annotatableEntity.addMarker(marker);
70 }
71
72 return postExecute(null);
73 }
74 }