Project

General

Profile

« Previous | Next » 

Revision 3be6ef3e

Added by Niels Hoffmann over 13 years ago

performed javacscript:fix and worked on documentation

View differences:

taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/operations/CreateDescriptionElementOperation.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.operations;
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.CategoricalData;
19
import eu.etaxonomy.cdm.model.description.CommonTaxonName;
20
import eu.etaxonomy.cdm.model.description.DescriptionElementBase;
21
import eu.etaxonomy.cdm.model.description.Distribution;
22
import eu.etaxonomy.cdm.model.description.Feature;
23
import eu.etaxonomy.cdm.model.description.IndividualsAssociation;
24
import eu.etaxonomy.cdm.model.description.QuantitativeData;
25
import eu.etaxonomy.cdm.model.description.TaxonDescription;
26
import eu.etaxonomy.cdm.model.description.TaxonInteraction;
27
import eu.etaxonomy.cdm.model.description.TextData;
28
import eu.etaxonomy.cdm.model.taxon.Taxon;
29

  
30
/**
31
 * @author p.ciardelli
32
 * @created 05.02.2009
33
 * @version 1.0
34
 * @author n.hoffmann
35
 */
36
public class CreateDescriptionElementOperation extends AbstractPostOperation {
37
	
38
	public static final String ID = "eu.etaxonomy.taxeditor.editor.description.createDescriptionElement";
39
	
40
	private TaxonDescription description;
41
	private Feature feature;
42
	private DescriptionElementBase element;
43

  
44
	public CreateDescriptionElementOperation(String label, IUndoContext undoContext,
45
			Taxon taxon, TaxonDescription description, Feature feature, IPostOperationEnabled postOperationEnabled) {
46
		super(label, undoContext, taxon, postOperationEnabled);
47
		
48
		this.description = description;
49
		this.feature = feature;
50
	}
51

  
52
	/**
53
	 * @param name
54
	 * @param undoContext
55
	 * @param taxon
56
	 * @param description
57
	 * @param feature
58
	 * @param element
59
	 * @param postOperationEnabled
60
	 */
61
	public CreateDescriptionElementOperation(String label,
62
			IUndoContext undoContext, Taxon taxon,
63
			TaxonDescription description, Feature feature,
64
			DescriptionElementBase element, IPostOperationEnabled postOperationEnabled) {
65
		this(label, undoContext, taxon, description, feature, postOperationEnabled);
66
		
67
		this.element = element;
68
	}
69

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

  
77
		monitor.worked(20);
78
		if (element == null) {
79
			if (feature.isSupportsCommonTaxonName()) {
80
				element = CommonTaxonName.NewInstance("", null);
81
			} 
82
			else if (feature.isSupportsDistribution()) {
83
				element = Distribution.NewInstance();
84
			} 
85
			else if(feature.isSupportsTaxonInteraction()){
86
				element = TaxonInteraction.NewInstance();
87
			}
88
			else if(feature.isSupportsIndividualAssociation()){
89
				element = IndividualsAssociation.NewInstance();
90
			}
91
			else if(feature.isSupportsCategoricalData()){
92
				element = CategoricalData.NewInstance();
93
			}
94
			else if(feature.isSupportsQuantitativeData()){
95
				element = QuantitativeData.NewInstance();
96
			}
97
			else {
98
				element = TextData.NewInstance();
99
			}
100
		}
101

  
102
		element.setFeature(feature);
103
		description.addElement(element);
104
		monitor.worked(40);
105

  
106
		return postExecute(element);
107
	}
108

  
109
	/* (non-Javadoc)
110
	 * @see org.eclipse.core.commands.operations.AbstractOperation#redo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
111
	 */
112
	@Override
113
	public IStatus redo(IProgressMonitor monitor, IAdaptable info)
114
			throws ExecutionException {
115
		
116
		description.addElement(element);
117
		
118
		return postExecute(element);
119
	}
120

  
121
	/* (non-Javadoc)
122
	 * @see org.eclipse.core.commands.operations.AbstractOperation#undo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
123
	 */
124
	@Override
125
	public IStatus undo(IProgressMonitor monitor, IAdaptable info)
126
			throws ExecutionException {
127
		
128
		description.removeElement(element);
129
		
130
		return postExecute(null);
131
	}
132
}
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.operations;
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.CategoricalData;
19
import eu.etaxonomy.cdm.model.description.CommonTaxonName;
20
import eu.etaxonomy.cdm.model.description.DescriptionElementBase;
21
import eu.etaxonomy.cdm.model.description.Distribution;
22
import eu.etaxonomy.cdm.model.description.Feature;
23
import eu.etaxonomy.cdm.model.description.IndividualsAssociation;
24
import eu.etaxonomy.cdm.model.description.QuantitativeData;
25
import eu.etaxonomy.cdm.model.description.TaxonDescription;
26
import eu.etaxonomy.cdm.model.description.TaxonInteraction;
27
import eu.etaxonomy.cdm.model.description.TextData;
28
import eu.etaxonomy.cdm.model.taxon.Taxon;
29

  
30
/**
31
 * <p>CreateDescriptionElementOperation class.</p>
32
 *
33
 * @author p.ciardelli
34
 * @author n.hoffmann
35
 * @created 05.02.2009
36
 * @version 1.0
37
 */
38
public class CreateDescriptionElementOperation extends AbstractPostOperation {
39
	
40
	/** Constant <code>ID="eu.etaxonomy.taxeditor.editor.descripti"{trunked}</code> */
41
	public static final String ID = "eu.etaxonomy.taxeditor.editor.description.createDescriptionElement";
42
	
43
	private TaxonDescription description;
44
	private Feature feature;
45
	private DescriptionElementBase element;
46

  
47
	/**
48
	 * <p>Constructor for CreateDescriptionElementOperation.</p>
49
	 *
50
	 * @param label a {@link java.lang.String} object.
51
	 * @param undoContext a {@link org.eclipse.core.commands.operations.IUndoContext} object.
52
	 * @param taxon a {@link eu.etaxonomy.cdm.model.taxon.Taxon} object.
53
	 * @param description a {@link eu.etaxonomy.cdm.model.description.TaxonDescription} object.
54
	 * @param feature a {@link eu.etaxonomy.cdm.model.description.Feature} object.
55
	 * @param postOperationEnabled a {@link eu.etaxonomy.taxeditor.operations.IPostOperationEnabled} object.
56
	 */
57
	public CreateDescriptionElementOperation(String label, IUndoContext undoContext,
58
			Taxon taxon, TaxonDescription description, Feature feature, IPostOperationEnabled postOperationEnabled) {
59
		super(label, undoContext, taxon, postOperationEnabled);
60
		
61
		this.description = description;
62
		this.feature = feature;
63
	}
64

  
65
	/**
66
	 * <p>Constructor for CreateDescriptionElementOperation.</p>
67
	 *
68
	 * @param undoContext a {@link org.eclipse.core.commands.operations.IUndoContext} object.
69
	 * @param taxon a {@link eu.etaxonomy.cdm.model.taxon.Taxon} object.
70
	 * @param description a {@link eu.etaxonomy.cdm.model.description.TaxonDescription} object.
71
	 * @param feature a {@link eu.etaxonomy.cdm.model.description.Feature} object.
72
	 * @param element a {@link eu.etaxonomy.cdm.model.description.DescriptionElementBase} object.
73
	 * @param postOperationEnabled a {@link eu.etaxonomy.taxeditor.operations.IPostOperationEnabled} object.
74
	 * @param label a {@link java.lang.String} object.
75
	 */
76
	public CreateDescriptionElementOperation(String label,
77
			IUndoContext undoContext, Taxon taxon,
78
			TaxonDescription description, Feature feature,
79
			DescriptionElementBase element, IPostOperationEnabled postOperationEnabled) {
80
		this(label, undoContext, taxon, description, feature, postOperationEnabled);
81
		
82
		this.element = element;
83
	}
84

  
85
	/* (non-Javadoc)
86
	 * @see org.eclipse.core.commands.operations.AbstractOperation#execute(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
87
	 */
88
	/** {@inheritDoc} */
89
	@Override
90
	public IStatus execute(IProgressMonitor monitor, IAdaptable info)
91
			throws ExecutionException {
92

  
93
		monitor.worked(20);
94
		if (element == null) {
95
			if (feature.isSupportsCommonTaxonName()) {
96
				element = CommonTaxonName.NewInstance("", null);
97
			} 
98
			else if (feature.isSupportsDistribution()) {
99
				element = Distribution.NewInstance();
100
			} 
101
			else if(feature.isSupportsTaxonInteraction()){
102
				element = TaxonInteraction.NewInstance();
103
			}
104
			else if(feature.isSupportsIndividualAssociation()){
105
				element = IndividualsAssociation.NewInstance();
106
			}
107
			else if(feature.isSupportsCategoricalData()){
108
				element = CategoricalData.NewInstance();
109
			}
110
			else if(feature.isSupportsQuantitativeData()){
111
				element = QuantitativeData.NewInstance();
112
			}
113
			else {
114
				element = TextData.NewInstance();
115
			}
116
		}
117

  
118
		element.setFeature(feature);
119
		description.addElement(element);
120
		monitor.worked(40);
121

  
122
		return postExecute(element);
123
	}
124

  
125
	/* (non-Javadoc)
126
	 * @see org.eclipse.core.commands.operations.AbstractOperation#redo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
127
	 */
128
	/** {@inheritDoc} */
129
	@Override
130
	public IStatus redo(IProgressMonitor monitor, IAdaptable info)
131
			throws ExecutionException {
132
		
133
		description.addElement(element);
134
		
135
		return postExecute(element);
136
	}
137

  
138
	/* (non-Javadoc)
139
	 * @see org.eclipse.core.commands.operations.AbstractOperation#undo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
140
	 */
141
	/** {@inheritDoc} */
142
	@Override
143
	public IStatus undo(IProgressMonitor monitor, IAdaptable info)
144
			throws ExecutionException {
145
		
146
		description.removeElement(element);
147
		
148
		return postExecute(null);
149
	}
150
}

Also available in: Unified diff