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;
private ITaxonTreeNode parentTreeNode;
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;
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,
selection_parentTaxonNode = formFactory
.createTaxonNodeSelectionElement(getConversationHolder(), formElement, "Parent", null,
EntitySelectionElement.DELETABLE, style);
+
selection_reuseExistingTaxon = formFactory
.createSelectionElement(Taxon.class,
getConversationHolder(), formElement,
getConversationHolder(), formElement,
"Reuse existing name", null,
EntitySelectionElement.DELETABLE, style);
-
- text_newTaxonName = formFactory.createTextWithLabelElement(formElement,
+ selection_SecRef = formFactory
+ .createSelectionElement(Reference.class,getConversationHolder(), formElement, "Secundum Reference", null,
+ EntitySelectionElement.DELETABLE, style);
+ textNewTaxonName = formFactory.createTextWithLabelElement(formElement,
"New Taxon", "", style);
- text_newTaxonName.setFocus();
+ 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());
+ } else{
+ textNewTaxonName.setText(null);
+ }
+ complete = !textNewTaxonName.getText().isEmpty();
+
- setTaxon(selection_reuseExistingTaxon.getEntity());
} else if (eventSource == selection_reuseExistingName) {
- boolean enabled = selection_reuseExistingName.getEntity() == null;
+ boolean enabled = selection_reuseExistingName.getEntity() == null;
+ setTaxon(selection_reuseExistingName.getEntity());
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());
}
return classification;
}
- /**
- * <p>
- * isOpenInEditor
- * </p>
- *
- * @return the openInEditor
- */
public boolean isOpenInEditor() {
return openInEditor;
}
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(ITaxonTreeNode parentTreeNode) {
this.parentTreeNode = parentTreeNode;
selection_classification.setEntity(classification);
selection_parentTaxonNode.setEntity(null);
selection_parentTaxonNode.setClassification(classification);
+ selection_SecRef.setEntity(classification.getReference());
} else if (parentTreeNode instanceof TaxonNode) {
classification = (Classification) HibernateProxyHelper
.deproxy(((TaxonNode) parentTreeNode).getClassification());
selection_classification.setEntity(classification);
selection_parentTaxonNode.setEntity((TaxonNode) parentTreeNode);
selection_parentTaxonNode.setClassification(classification);
+ selection_SecRef.setEntity(((TaxonNode)parentTreeNode).getTaxon().getSec());
} else if(parentTreeNode == null){
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());
+ selection_SecRef.setEntity(taxon.getSec());
}
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) {
secundum = ((TaxonNode) getParentTreeNode()).getTaxon()
.getSec();
- }
+ }*/
+ }
+ if (taxonName != null){
+ taxon = Taxon.NewInstance(taxonName, secundum);
+ if (!taxonName.getTitleCache().trim().equals(textNewTaxonName.getText().trim())){
+ textNewTaxonName.setText(taxonName.getTitleCache());
+ }
+ } else {
+ textNewTaxonName.setText(null);
}
- 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;
}