Project

General

Profile

Download (8.35 KB) Statistics
| Branch: | Tag: | Revision:
1
// $Id$
2
/**
3
 * Copyright (C) 2007 EDIT
4
 * European Distributed Institute of Taxonomy 
5
 * http://www.e-taxonomy.eu
6
 * 
7
 * The contents of this file are subject to the Mozilla Public License Version 1.1
8
 * See LICENSE.TXT at the top of this package for the full license terms.
9
 */
10

    
11
package eu.etaxonomy.taxeditor.ui.section.classification;
12

    
13
import eu.etaxonomy.cdm.common.CdmUtils;
14
import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
15
import eu.etaxonomy.cdm.model.name.TaxonNameBase;
16
import eu.etaxonomy.cdm.model.reference.Reference;
17
import eu.etaxonomy.cdm.model.taxon.Classification;
18
import eu.etaxonomy.cdm.model.taxon.ITreeNode;
19
import eu.etaxonomy.cdm.model.taxon.Taxon;
20
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
21
import eu.etaxonomy.taxeditor.parser.ParseHandler;
22
import eu.etaxonomy.taxeditor.singlesource.ui.forms.CdmFormFactoryFacade;
23
import eu.etaxonomy.taxeditor.singlesource.ui.forms.TextWithLabelElementFacade;
24
import eu.etaxonomy.taxeditor.singlesource.ui.forms.CdmFormFactoryFacade.SelectionType;
25
import eu.etaxonomy.taxeditor.ui.forms.CheckboxElement;
26
import eu.etaxonomy.taxeditor.ui.forms.ICdmFormElement;
27
import eu.etaxonomy.taxeditor.ui.section.AbstractCdmDetailElement;
28
import eu.etaxonomy.taxeditor.ui.selection.ClassificationSelectionElement;
29
import eu.etaxonomy.taxeditor.ui.selection.NameSelectionElement;
30
import eu.etaxonomy.taxeditor.ui.selection.TaxonNodeSelectionElement;
31
import eu.etaxonomy.taxeditor.ui.selection.TaxonSelectionElement;
32

    
33
/**
34
 * <p>
35
 * TaxonNodeDetailElement class.
36
 * </p>
37
 * 
38
 * @author n.hoffmann
39
 * @created Sep 27, 2010
40
 * @version 1.0
41
 */
42
public class TaxonNodeDetailElement extends AbstractCdmDetailElement<ITreeNode> {
43

    
44
	private ClassificationSelectionElement selection_classification;
45

    
46
	private Classification classification;
47

    
48
	private TaxonNodeSelectionElement selection_parentTaxonNode;
49

    
50
	private ITreeNode parentTreeNode;
51

    
52
	private TaxonSelectionElement selection_reuseExistingTaxon;
53

    
54
	private Taxon taxon;
55

    
56
	private TextWithLabelElementFacade text_newTaxonName;
57

    
58
	private CheckboxElement checkbox_openInEditor;
59

    
60
	private boolean openInEditor;
61

    
62
	private boolean complete;
63

    
64
	private NameSelectionElement selection_reuseExistingName;
65

    
66
	/**
67
	 * <p>
68
	 * Constructor for TaxonNodeDetailElement.
69
	 * </p>
70
	 * 
71
	 * @param formFactory
72
	 *            a {@link eu.etaxonomy.taxeditor.singlesource.ui.forms.CdmFormFactoryFacade}
73
	 *            object.
74
	 * @param formElement
75
	 *            a {@link eu.etaxonomy.taxeditor.ui.forms.ICdmFormElement}
76
	 *            object.
77
	 */
78
	public TaxonNodeDetailElement(CdmFormFactoryFacade formFactory,
79
			ICdmFormElement formElement) {
80
		super(formFactory, formElement);
81
	}
82

    
83
	/*
84
	 * (non-Javadoc)
85
	 * 
86
	 * @see
87
	 * eu.etaxonomy.taxeditor.section.AbstractCdmDetailElement#createControls
88
	 * (eu.etaxonomy.taxeditor.forms.ICdmFormElement,
89
	 * eu.etaxonomy.cdm.model.common.IAnnotatableEntity, int)
90
	 */
91
	/** {@inheritDoc} */
92
	@Override
93
	protected void createControls(ICdmFormElement formElement,
94
			ITreeNode entity, int style) {
95
		selection_classification = (ClassificationSelectionElement) formFactory
96
				.createSelectionElement(SelectionType.CLASSIFICATION,
97
						getConversationHolder(), formElement, "Classification",
98
						null, ClassificationSelectionElement.DEFAULT, style);
99
		selection_parentTaxonNode = (TaxonNodeSelectionElement) formFactory
100
				.createSelectionElement(SelectionType.TAXON_NODE,
101
						getConversationHolder(), formElement, "Parent", null,
102
						TaxonNodeSelectionElement.DEFAULT, style);
103
		selection_reuseExistingTaxon = (TaxonSelectionElement) formFactory
104
				.createSelectionElement(SelectionType.TAXON,
105
						getConversationHolder(), formElement,
106
						"Reuse existing Taxon", null,
107
						TaxonSelectionElement.DELETABLE, style);
108

    
109
		selection_reuseExistingName = (NameSelectionElement) formFactory
110
				.createSelectionElement(SelectionType.NAME,
111
						getConversationHolder(), formElement,
112
						"Reuse existing name", null,
113
						NameSelectionElement.DEFAULT, style);
114

    
115
		text_newTaxonName = formFactory.createTextWithLabelElement(formElement,
116
				"New Taxon", "", style);
117

    
118
		checkbox_openInEditor = formFactory.createCheckbox(formElement,
119
				"Open in Editor", true, style);
120
		setOpenInEditor(true);
121
		setParentTreeNode(entity);
122
	}
123

    
124
	/*
125
	 * (non-Javadoc)
126
	 * 
127
	 * @see
128
	 * eu.etaxonomy.taxeditor.section.AbstractCdmDetailElement#handleEvent(java
129
	 * .lang.Object)
130
	 */
131
	/** {@inheritDoc} */
132
	@Override
133
	public void handleEvent(Object eventSource) {
134
		if (eventSource == selection_classification) {
135
			setClassification(selection_classification.getEntity());
136
		} else if (eventSource == selection_parentTaxonNode) {
137
			setParentTreeNode(selection_parentTaxonNode.getEntity());
138
		} else if (eventSource == selection_reuseExistingTaxon) {
139
			boolean enabled = selection_reuseExistingTaxon.getEntity() == null;
140
			selection_reuseExistingName.setEnabled(enabled);
141
			text_newTaxonName.setEnabled(enabled);
142

    
143
			setTaxon(selection_reuseExistingTaxon.getEntity());
144
		} else if (eventSource == selection_reuseExistingName) {
145
			boolean enabled = selection_reuseExistingName.getEntity() == null;
146
			selection_reuseExistingTaxon.setEnabled(enabled);
147
			text_newTaxonName.setEnabled(enabled);
148

    
149
			setTaxon(selection_reuseExistingName.getEntity());
150
		} else if (eventSource == text_newTaxonName) {
151
			boolean enabled = CdmUtils.isEmpty(text_newTaxonName.getText());
152
			selection_reuseExistingTaxon.setEnabled(enabled);
153
			selection_reuseExistingName.setEnabled(enabled);
154

    
155
			setTaxon(text_newTaxonName.getText());
156
		} else if (eventSource == checkbox_openInEditor) {
157
			setOpenInEditor(checkbox_openInEditor.getSelection());
158
		}
159
	}
160

    
161
	/**
162
	 * <p>
163
	 * Getter for the field <code>classification</code>.
164
	 * </p>
165
	 * 
166
	 * @return the classification
167
	 */
168
	public Classification getClassification() {
169
		return classification;
170
	}
171

    
172
	/**
173
	 * <p>
174
	 * isOpenInEditor
175
	 * </p>
176
	 * 
177
	 * @return the openInEditor
178
	 */
179
	public boolean isOpenInEditor() {
180
		return openInEditor;
181
	}
182

    
183
	/**
184
	 * <p>
185
	 * Getter for the field <code>parentTreeNode</code>.
186
	 * </p>
187
	 * 
188
	 * @return a {@link eu.etaxonomy.cdm.model.taxon.ITreeNode} object.
189
	 */
190
	public ITreeNode getParentTreeNode() {
191
		return parentTreeNode;
192
	}
193

    
194
	/**
195
	 * <p>
196
	 * Getter for the field <code>taxon</code>.
197
	 * </p>
198
	 * 
199
	 * @return the taxon
200
	 */
201
	public Taxon getTaxon() {
202
		return taxon;
203
	}
204

    
205
	/**
206
	 * @param classification
207
	 *            the classification to set
208
	 */
209
	private void setClassification(Classification classification) {
210
		this.classification = classification;
211
		setParentTreeNode(classification);
212
	}
213

    
214
	/**
215
	 * @param parentTreeNode
216
	 *            the parentTreeNode to set
217
	 */
218
	private void setParentTreeNode(ITreeNode parentTreeNode) {
219
		this.parentTreeNode = parentTreeNode;
220

    
221
		if (parentTreeNode instanceof Classification) {
222
			classification = (Classification) parentTreeNode;
223
			selection_classification.setEntity(classification);
224
			selection_parentTaxonNode.setEntity(null);
225
			selection_parentTaxonNode.setClassification(classification);
226
		} else if (parentTreeNode instanceof TaxonNode) {
227
			classification = (Classification) HibernateProxyHelper
228
					.deproxy(((TaxonNode) parentTreeNode).getClassification());
229
			selection_classification.setEntity(classification);
230
			selection_parentTaxonNode.setEntity((TaxonNode) parentTreeNode);
231
			selection_parentTaxonNode.setClassification(classification);
232
		} else if(parentTreeNode == null){
233
			this.parentTreeNode = selection_classification.getEntity();			
234
		}
235
	}
236

    
237
	/**
238
	 * @param reuseExistingTaxon
239
	 *            the reuseExistingTaxon to set
240
	 */
241
	private void setTaxon(Taxon taxon) {
242
		this.taxon = taxon;
243
	}
244

    
245
	private void setTaxon(String taxonNameString) {
246
		TaxonNameBase taxonName = ParseHandler.parseReferencedName(
247
				taxonNameString, null);
248
		setTaxon(taxonName);
249
	}
250

    
251
	private void setTaxon(TaxonNameBase taxonName) {
252
		Reference secundum = null;
253
		if (getParentTreeNode() != null) {
254
			if (getParentTreeNode() instanceof Classification) {
255
				secundum = ((Classification) getParentTreeNode())
256
						.getReference();
257
			} else if (getParentTreeNode() instanceof TaxonNode) {
258
				secundum = ((TaxonNode) getParentTreeNode()).getTaxon()
259
						.getSec();
260
			}
261
		}
262
		taxon = Taxon.NewInstance(taxonName, secundum);
263
	}
264

    
265
	/**
266
	 * @param openInEditor
267
	 *            the openInEditor to set
268
	 */
269
	private void setOpenInEditor(boolean openInEditor) {
270
		this.openInEditor = openInEditor;
271
	}
272

    
273
	/**
274
	 * <p>
275
	 * isComplete
276
	 * </p>
277
	 * 
278
	 * @return the complete
279
	 */
280
	public boolean isComplete() {
281
		return complete;
282
	}
283

    
284
}
(4-4/6)