Project

General

Profile

Download (8.32 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.ui.forms.CdmFormFactory;
23
import eu.etaxonomy.taxeditor.ui.forms.CdmFormFactory.SelectionType;
24
import eu.etaxonomy.taxeditor.ui.forms.CdmPropertyChangeEvent;
25
import eu.etaxonomy.taxeditor.ui.forms.CheckboxElement;
26
import eu.etaxonomy.taxeditor.ui.forms.ICdmFormElement;
27
import eu.etaxonomy.taxeditor.ui.forms.TextWithLabelElement;
28
import eu.etaxonomy.taxeditor.ui.section.AbstractCdmDetailElement;
29
import eu.etaxonomy.taxeditor.ui.selection.ClassificationSelectionElement;
30
import eu.etaxonomy.taxeditor.ui.selection.NameSelectionElement;
31
import eu.etaxonomy.taxeditor.ui.selection.TaxonNodeSelectionElement;
32
import eu.etaxonomy.taxeditor.ui.selection.TaxonSelectionElement;
33

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

    
45
	private ClassificationSelectionElement selection_classification;
46

    
47
	private Classification classification;
48

    
49
	private TaxonNodeSelectionElement selection_parentTaxonNode;
50

    
51
	private ITreeNode parentTreeNode;
52

    
53
	private TaxonSelectionElement selection_reuseExistingTaxon;
54

    
55
	private Taxon taxon;
56

    
57
	private TextWithLabelElement text_newTaxonName;
58

    
59
	private CheckboxElement checkbox_openInEditor;
60

    
61
	private boolean openInEditor;
62

    
63
	private boolean complete;
64

    
65
	private NameSelectionElement selection_reuseExistingName;
66

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
285
}
(4-4/6)