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