Project

General

Profile

Download (3.95 KB) Statistics
| Branch: | Tag: | Revision:
1
package eu.etaxonomy.taxeditor.editor.view.uses.operation;
2

    
3
import java.util.HashSet;
4
import java.util.Set;
5
import java.util.UUID;
6

    
7
import org.eclipse.core.commands.ExecutionException;
8
import org.eclipse.core.commands.operations.IUndoContext;
9
import org.eclipse.core.runtime.IAdaptable;
10
import org.eclipse.core.runtime.IProgressMonitor;
11
import org.eclipse.core.runtime.IStatus;
12

    
13
import eu.etaxonomy.cdm.api.service.ITermService;
14
import eu.etaxonomy.cdm.model.common.Marker;
15
import eu.etaxonomy.cdm.model.common.MarkerType;
16
import eu.etaxonomy.cdm.model.description.Feature;
17
import eu.etaxonomy.cdm.model.description.TaxonDescription;
18
import eu.etaxonomy.cdm.model.description.TextData;
19
import eu.etaxonomy.cdm.model.media.Media;
20
import eu.etaxonomy.cdm.model.taxon.Taxon;
21
import eu.etaxonomy.taxeditor.operation.AbstractPostOperation;
22
import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
23
import eu.etaxonomy.taxeditor.store.CdmStore;
24

    
25
/**
26
 * The context manager mediates context start/stop and workbench shutdowns to all registered listeners.
27
 *
28
 * @author a.theys	
29
 * @created mar 13, 2012
30
 * @version 1.0
31
 */
32
public class CreateTaxonUseOperation extends AbstractPostOperation {
33
	private TaxonDescription description;
34
	private Marker marker;
35

    
36
	/**
37
	 * <p>Constructor for CreateTaxonDescriptionOperation.</p>
38
	 *
39
	 * @param label a {@link java.lang.String} object.
40
	 * @param undoContext a {@link org.eclipse.core.commands.operations.IUndoContext} object.
41
	 * @param taxon a {@link eu.etaxonomy.cdm.model.taxon.Taxon} object.
42
	 * @param postOperationEnabled a {@link eu.etaxonomy.taxeditor.operation.IPostOperationEnabled} object.
43
	 */
44
	public CreateTaxonUseOperation(String label, IUndoContext undoContext,
45
			Taxon taxon, IPostOperationEnabled postOperationEnabled) {
46
		this(label, undoContext, taxon, postOperationEnabled, false);
47
	}
48

    
49
	/**
50
	 * <p>Constructor for CreateTaxonDescriptionOperation.</p>
51
	 *
52
	 * @param label a {@link java.lang.String} object.
53
	 * @param undoContext a {@link org.eclipse.core.commands.operations.IUndoContext} object.
54
	 * @param taxon a {@link eu.etaxonomy.cdm.model.taxon.Taxon} object.
55
	 * @param postOperationEnabled a {@link eu.etaxonomy.taxeditor.operation.IPostOperationEnabled} object.
56
	 * @param isImageGallery a boolean.
57
	 */
58
	public CreateTaxonUseOperation(String label, IUndoContext undoContext,
59
			Taxon taxon, IPostOperationEnabled postOperationEnabled, boolean isImageGallery) {
60
		super(label, undoContext, taxon, postOperationEnabled);
61
	}
62
	
63
	/* (non-Javadoc)
64
	 * @see org.eclipse.core.commands.operations.AbstractOperation#execute(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
65
	 */
66
	/** {@inheritDoc} */
67
	@Override
68
	public IStatus execute(IProgressMonitor monitor, IAdaptable info)
69
			throws ExecutionException {
70
		
71
		description = TaxonDescription.NewInstance(taxon);
72
		monitor.worked(20);
73
		MarkerType useMarkerType = (MarkerType) CdmStore.getService(ITermService.class).find(UUID.fromString("2e6e42d9-e92a-41f4-899b-03c0ac64f039"));
74
		marker = Marker.NewInstance(useMarkerType, true);
75
		description.addMarker(marker);
76
		monitor.worked(40);
77

    
78
		return postExecute(description);
79
	}
80

    
81
	/* (non-Javadoc)
82
	 * @see org.eclipse.core.commands.operations.AbstractOperation#redo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
83
	 */
84
	/** {@inheritDoc} */
85
	@Override
86
	public IStatus redo(IProgressMonitor monitor, IAdaptable info)
87
			throws ExecutionException {
88
		
89
		taxon.addDescription(description);
90
		
91
		return postExecute(description);
92
	}
93

    
94
	/* (non-Javadoc)
95
	 * @see org.eclipse.core.commands.operations.AbstractOperation#undo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
96
	 */
97
	/** {@inheritDoc} */
98
	@Override
99
	public IStatus undo(IProgressMonitor monitor, IAdaptable info)
100
			throws ExecutionException {
101

    
102
		taxon.removeDescription(description);
103
		
104
		return postExecute(null);
105
	}
106
}
107

    
(1-1/4)