Project

General

Profile

Download (3.98 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.editor.view.descriptive.operation;
11

    
12
import org.eclipse.core.commands.ExecutionException;
13
import org.eclipse.core.commands.operations.IUndoContext;
14
import org.eclipse.core.runtime.IAdaptable;
15
import org.eclipse.core.runtime.IProgressMonitor;
16
import org.eclipse.core.runtime.IStatus;
17

    
18
import eu.etaxonomy.cdm.model.description.Feature;
19
import eu.etaxonomy.cdm.model.description.TaxonDescription;
20
import eu.etaxonomy.cdm.model.description.TextData;
21
import eu.etaxonomy.cdm.model.media.Media;
22
import eu.etaxonomy.cdm.model.taxon.Taxon;
23
import eu.etaxonomy.taxeditor.operation.AbstractPostDescribableOperation;
24
import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
25

    
26
/**
27
 * <p>CreateTaxonDescriptionOperation class.</p>
28
 *
29
 * @author p.ciardelli
30
 * @author n.hoffmann
31
 * @created 05.02.2009
32
 * @version 1.0
33
 */
34
public class CreateTaxonDescriptionOperation extends AbstractPostDescribableOperation{
35

    
36
	private TaxonDescription description;
37
	private boolean isImageGallery;
38

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

    
52
	/**
53
	 * <p>Constructor for CreateTaxonDescriptionOperation.</p>
54
	 *
55
	 * @param label a {@link java.lang.String} object.
56
	 * @param undoContext a {@link org.eclipse.core.commands.operations.IUndoContext} object.
57
	 * @param taxon a {@link eu.etaxonomy.cdm.model.taxon.Taxon} object.
58
	 * @param postOperationEnabled a {@link eu.etaxonomy.taxeditor.operation.IPostOperationEnabled} object.
59
	 * @param isImageGallery a boolean.
60
	 */
61
	public CreateTaxonDescriptionOperation(String label, IUndoContext undoContext,
62
			Taxon taxon, IPostOperationEnabled postOperationEnabled, boolean isImageGallery) {
63
		super(label, undoContext, taxon, postOperationEnabled);
64

    
65
		this.isImageGallery  = isImageGallery;
66
	}
67

    
68
	/* (non-Javadoc)
69
	 * @see org.eclipse.core.commands.operations.AbstractOperation#execute(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
70
	 */
71
	/** {@inheritDoc} */
72
	@Override
73
	public IStatus execute(IProgressMonitor monitor, IAdaptable info)
74
			throws ExecutionException {
75

    
76
		description = TaxonDescription.NewInstance(taxon);
77
		monitor.worked(20);
78

    
79
		if(isImageGallery){
80
			description.setImageGallery(isImageGallery);
81
			// add the description element to hold the media elements for this image gallery
82
			TextData element = TextData.NewInstance(Feature.IMAGE());
83
			element.addMedia(Media.NewInstance());
84
			description.addElement(element);
85
		}
86
		monitor.worked(40);
87

    
88
		return postExecute(description);
89
	}
90

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

    
99
		describable.addDescription(description);
100

    
101
		return postExecute(description);
102
	}
103

    
104
	/* (non-Javadoc)
105
	 * @see org.eclipse.core.commands.operations.AbstractOperation#undo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
106
	 */
107
	/** {@inheritDoc} */
108
	@Override
109
	public IStatus undo(IProgressMonitor monitor, IAdaptable info)
110
			throws ExecutionException {
111

    
112
		describable.removeDescription(description);
113

    
114
		return postExecute(null);
115
	}
116
}
(2-2/7)