// $Id$
/**
* Copyright (C) 2007 EDIT
- * European Distributed Institute of Taxonomy
+ * European Distributed Institute of Taxonomy
* http://www.e-taxonomy.eu
- *
+ *
* The contents of this file are subject to the Mozilla Public License Version 1.1
* See LICENSE.TXT at the top of this package for the full license terms.
*/
package eu.etaxonomy.taxeditor.ui.section.classification;
+import org.apache.commons.lang.StringUtils;
+import org.eclipse.swt.widgets.Text;
+
import eu.etaxonomy.cdm.common.CdmUtils;
import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
+import eu.etaxonomy.cdm.model.name.NonViralName;
import eu.etaxonomy.cdm.model.name.TaxonNameBase;
import eu.etaxonomy.cdm.model.reference.Reference;
import eu.etaxonomy.cdm.model.taxon.Classification;
-import eu.etaxonomy.cdm.model.taxon.ITreeNode;
+import eu.etaxonomy.cdm.model.taxon.ITaxonTreeNode;
import eu.etaxonomy.cdm.model.taxon.Taxon;
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
import eu.etaxonomy.taxeditor.parser.ParseHandler;
import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
-import eu.etaxonomy.taxeditor.ui.element.CdmPropertyChangeEvent;
import eu.etaxonomy.taxeditor.ui.element.CheckboxElement;
import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;
import eu.etaxonomy.taxeditor.ui.element.TextWithLabelElement;
-import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory.SelectionType;
import eu.etaxonomy.taxeditor.ui.section.AbstractCdmDetailElement;
-import eu.etaxonomy.taxeditor.ui.selection.ClassificationSelectionElement;
-import eu.etaxonomy.taxeditor.ui.selection.NameSelectionElement;
+import eu.etaxonomy.taxeditor.ui.selection.EntitySelectionElement;
import eu.etaxonomy.taxeditor.ui.selection.TaxonNodeSelectionElement;
-import eu.etaxonomy.taxeditor.ui.selection.TaxonSelectionElement;
/**
* <p>
* TaxonNodeDetailElement class.
* </p>
- *
+ *
* @author n.hoffmann
* @created Sep 27, 2010
* @version 1.0
*/
-public class TaxonNodeDetailElement extends AbstractCdmDetailElement<ITreeNode> {
+public class TaxonNodeDetailElement extends AbstractCdmDetailElement<ITaxonTreeNode> {
- private ClassificationSelectionElement selection_classification;
+ private EntitySelectionElement<Classification> selection_classification;
private Classification classification;
private TaxonNodeSelectionElement selection_parentTaxonNode;
- private ITreeNode parentTreeNode;
+ private ITaxonTreeNode parentTreeNode;
- private TaxonSelectionElement selection_reuseExistingTaxon;
+ private EntitySelectionElement<Taxon> selection_reuseExistingTaxon;
+ private EntitySelectionElement<Reference> selection_SecRef;
private Taxon taxon;
- private TextWithLabelElement text_newTaxonName;
+ private Reference secReference;
+
+ private TextWithLabelElement textNewTaxonName;
private CheckboxElement checkbox_openInEditor;
private boolean complete;
- private NameSelectionElement selection_reuseExistingName;
+ private EntitySelectionElement<TaxonNameBase> selection_reuseExistingName;
/**
* <p>
* Constructor for TaxonNodeDetailElement.
* </p>
- *
+ *
* @param formFactory
* a {@link eu.etaxonomy.taxeditor.ui.element.CdmFormFactory}
* object.
super(formFactory, formElement);
}
- /*
- * (non-Javadoc)
- *
- * @see
- * eu.etaxonomy.taxeditor.section.AbstractCdmDetailElement#createControls
- * (eu.etaxonomy.taxeditor.forms.ICdmFormElement,
- * eu.etaxonomy.cdm.model.common.IAnnotatableEntity, int)
- */
/** {@inheritDoc} */
@Override
protected void createControls(ICdmFormElement formElement,
- ITreeNode entity, int style) {
- selection_classification = (ClassificationSelectionElement) formFactory
- .createSelectionElement(SelectionType.CLASSIFICATION,
+ ITaxonTreeNode entity, int style) {
+ selection_classification = formFactory
+ .createSelectionElement(Classification.class,
getConversationHolder(), formElement, "Classification",
- null, ClassificationSelectionElement.DEFAULT, style);
- selection_parentTaxonNode = (TaxonNodeSelectionElement) formFactory
- .createSelectionElement(SelectionType.TAXON_NODE,
- getConversationHolder(), formElement, "Parent", null,
- TaxonNodeSelectionElement.DEFAULT, style);
- selection_reuseExistingTaxon = (TaxonSelectionElement) formFactory
- .createSelectionElement(SelectionType.TAXON,
+ null, EntitySelectionElement.DELETABLE, style);
+ selection_parentTaxonNode = formFactory
+ .createTaxonNodeSelectionElement(getConversationHolder(), formElement, "Parent", null,
+ EntitySelectionElement.DELETABLE, style);
+ selection_SecRef = formFactory
+ .createSelectionElement(Reference.class,getConversationHolder(), formElement, "Secundum Reference", null,
+ EntitySelectionElement.DELETABLE, style);
+ selection_reuseExistingTaxon = formFactory
+ .createSelectionElement(Taxon.class,
getConversationHolder(), formElement,
- "Reuse existing Taxon", null,
- TaxonSelectionElement.DELETABLE, style);
+ "Reuse existing taxon", null,
+ EntitySelectionElement.DELETABLE, style);
- selection_reuseExistingName = (NameSelectionElement) formFactory
- .createSelectionElement(SelectionType.NAME,
+ selection_reuseExistingName = formFactory
+ .createSelectionElement(TaxonNameBase.class,
getConversationHolder(), formElement,
"Reuse existing name", null,
- NameSelectionElement.DEFAULT, style);
+ EntitySelectionElement.DELETABLE, style);
- text_newTaxonName = formFactory.createTextWithLabelElement(formElement,
+ textNewTaxonName = formFactory.createTextWithLabelElement(formElement,
"New Taxon", "", style);
+ textNewTaxonName.setFocus();
+ preFillParentTaxonName();
checkbox_openInEditor = formFactory.createCheckbox(formElement,
"Open in Editor", true, style);
setParentTreeNode(entity);
}
- /*
- * (non-Javadoc)
- *
- * @see
- * eu.etaxonomy.taxeditor.section.AbstractCdmDetailElement#handleEvent(java
- * .lang.Object)
- */
+ private void preFillParentTaxonName() {
+ if(getEntity() instanceof TaxonNode){
+ TaxonNode node = (TaxonNode)getEntity();
+ if(node.getTaxon()!=null){
+ Taxon taxon = HibernateProxyHelper.deproxy(node.getTaxon(), Taxon.class);
+ if(taxon.getName()!=null && taxon.getName().isInstanceOf(NonViralName.class)){
+ NonViralName<?> name = HibernateProxyHelper.deproxy(node.getTaxon().getName(), NonViralName.class);
+ if( ! name.isSupraGeneric() && name.getRank() != null){
+ String taxonName = "";
+ if(name.isGenus() || name.isInfraGeneric()|| name.isSpeciesAggregate() ){
+ taxonName = name.getGenusOrUninomial();
+ }
+ else if(name.isSpecies() || name.isInfraSpecific() ){
+ taxonName = CdmUtils.concat(" ", name.getGenusOrUninomial(),name.getSpecificEpithet());
+ }
+ if (StringUtils.isNotBlank(taxonName)){
+ textNewTaxonName.setText(taxonName + " ");
+ if(textNewTaxonName.getMainControl() instanceof Text){
+ Text text = (Text)textNewTaxonName.getMainControl();
+ text.setSelection(textNewTaxonName.getText().length());
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+
/** {@inheritDoc} */
@Override
public void handleEvent(Object eventSource) {
setClassification(selection_classification.getEntity());
} else if (eventSource == selection_parentTaxonNode) {
setParentTreeNode(selection_parentTaxonNode.getEntity());
+ } else if (eventSource == selection_SecRef) {
+ setSecReference(selection_SecRef.getEntity());
} else if (eventSource == selection_reuseExistingTaxon) {
- boolean enabled = selection_reuseExistingTaxon.getEntity() == null;
- selection_reuseExistingName.setEnabled(enabled);
- text_newTaxonName.setEnabled(enabled);
+ boolean enabled = selection_reuseExistingTaxon.getEntity() == null;
+ selection_reuseExistingName.setEnabled(enabled);
+ textNewTaxonName.setEnabled(enabled);
+ if (!enabled){
+ setTaxon(selection_reuseExistingTaxon.getEntity());
+ }
+ complete = !textNewTaxonName.getText().isEmpty();
+
- setTaxon(selection_reuseExistingTaxon.getEntity());
} else if (eventSource == selection_reuseExistingName) {
boolean enabled = selection_reuseExistingName.getEntity() == null;
selection_reuseExistingTaxon.setEnabled(enabled);
- text_newTaxonName.setEnabled(enabled);
+ textNewTaxonName.setEnabled(enabled);
setTaxon(selection_reuseExistingName.getEntity());
- } else if (eventSource == text_newTaxonName) {
- boolean enabled = CdmUtils.isEmpty(text_newTaxonName.getText());
+ complete = !textNewTaxonName.getText().isEmpty();
+ } else if (eventSource == textNewTaxonName) {
+ boolean enabled = CdmUtils.isBlank(textNewTaxonName.getText());
selection_reuseExistingTaxon.setEnabled(enabled);
selection_reuseExistingName.setEnabled(enabled);
- setTaxon(text_newTaxonName.getText());
+ setTaxon(textNewTaxonName.getText());
+ complete = !textNewTaxonName.getText().isEmpty();
} else if (eventSource == checkbox_openInEditor) {
setOpenInEditor(checkbox_openInEditor.getSelection());
}
* <p>
* Getter for the field <code>classification</code>.
* </p>
- *
+ *
* @return the classification
*/
public Classification getClassification() {
return classification;
}
- /**
- * <p>
- * isOpenInEditor
- * </p>
- *
- * @return the openInEditor
- */
public boolean isOpenInEditor() {
return openInEditor;
}
* <p>
* Getter for the field <code>parentTreeNode</code>.
* </p>
- *
- * @return a {@link eu.etaxonomy.cdm.model.taxon.ITreeNode} object.
+ *
+ * @return a {@link eu.etaxonomy.cdm.model.taxon.ITaxonTreeNode} object.
*/
- public ITreeNode getParentTreeNode() {
+ public ITaxonTreeNode getParentTreeNode() {
return parentTreeNode;
}
* <p>
* Getter for the field <code>taxon</code>.
* </p>
- *
+ *
* @return the taxon
*/
public Taxon getTaxon() {
return taxon;
}
- /**
- * @param classification
- * the classification to set
- */
private void setClassification(Classification classification) {
this.classification = classification;
setParentTreeNode(classification);
}
- /**
- * @param parentTreeNode
- * the parentTreeNode to set
- */
- private void setParentTreeNode(ITreeNode parentTreeNode) {
+ private void setParentTreeNode(ITaxonTreeNode parentTreeNode) {
this.parentTreeNode = parentTreeNode;
if (parentTreeNode instanceof Classification) {
selection_parentTaxonNode.setEntity((TaxonNode) parentTreeNode);
selection_parentTaxonNode.setClassification(classification);
} else if(parentTreeNode == null){
- this.parentTreeNode = selection_classification.getEntity();
+ this.parentTreeNode = selection_classification.getEntity();
}
}
- /**
- * @param reuseExistingTaxon
- * the reuseExistingTaxon to set
- */
+ private void setSecReference(Reference secRef){
+ this.secReference = secRef;
+ setTaxon(textNewTaxonName.getText());
+ }
+
private void setTaxon(Taxon taxon) {
this.taxon = taxon;
+ textNewTaxonName.setText(taxon.getName().getTitleCache());
+
}
private void setTaxon(String taxonNameString) {
private void setTaxon(TaxonNameBase taxonName) {
Reference secundum = null;
if (getParentTreeNode() != null) {
- if (getParentTreeNode() instanceof Classification) {
+ if (this.secReference != null){
+ secundum = this.secReference;
+ } else if (getParentTreeNode() instanceof Classification) {
secundum = ((Classification) getParentTreeNode())
.getReference();
} else if (getParentTreeNode() instanceof TaxonNode) {
taxon = Taxon.NewInstance(taxonName, secundum);
}
- /**
- * @param openInEditor
- * the openInEditor to set
- */
private void setOpenInEditor(boolean openInEditor) {
this.openInEditor = openInEditor;
}
- /**
- * <p>
- * isComplete
- * </p>
- *
- * @return the complete
- */
+ public TextWithLabelElement getTextNewTaxonName() {
+ return textNewTaxonName;
+ }
+
public boolean isComplete() {
return complete;
}