import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
import eu.etaxonomy.taxeditor.ui.element.CheckboxElement;
import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;
+import eu.etaxonomy.taxeditor.ui.element.LayoutConstants;
import eu.etaxonomy.taxeditor.ui.element.TextWithLabelElement;
import eu.etaxonomy.taxeditor.ui.section.AbstractCdmDetailElement;
import eu.etaxonomy.taxeditor.ui.selection.EntitySelectionElement;
*/
public class TaxonNodeDetailElement extends AbstractCdmDetailElement<ITaxonTreeNode> {
+ private boolean createNew = false;
+
private EntitySelectionElement<Classification> selection_classification;
private Classification classification;
private TextWithLabelElement textNewTaxonName;
+ private TaxonNodeAgentRelationCollectionSection selectionNodeAgentRelation;
+
+
private CheckboxElement checkbox_openInEditor;
private boolean openInEditor;
private EntitySelectionElement<TaxonNameBase> selection_reuseExistingName;
public TaxonNodeDetailElement(CdmFormFactory formFactory,
- ICdmFormElement formElement) {
+ ICdmFormElement formElement, boolean isCreateNew) {
super(formFactory, formElement);
+ createNew = isCreateNew;
}
/** {@inheritDoc} */
selection_SecRef = formFactory
.createSelectionElement(Reference.class,getConversationHolder(), formElement, "Secundum Reference", null,
EntitySelectionElement.DELETABLE, style);
- textNewTaxonName = formFactory.createTextWithLabelElement(formElement,
- "New Taxon", "", style);
- textNewTaxonName.setFocus();
- preFillParentTaxonName();
+ if (isCreateNew()){
+ textNewTaxonName = formFactory.createTextWithLabelElement(formElement,"New Taxon", "", style);
+ textNewTaxonName.setFocus();
+ } else{
+ textNewTaxonName = formFactory.createTextWithLabelElement(formElement,"Taxon", "", style);
+
+ }
+
+ if (isCreateNew()){
+ setParentTreeNode(entity);
+
+ } else{
+ setTreeNode(entity);
+ complete = true;
+ }
+ if (!isCreateNew()){
+ selectionNodeAgentRelation = formFactory.createTaxonNodeAgentRelationCollectionSection(formElement, getConversationHolder(), style);
+ selectionNodeAgentRelation.setEntity((TaxonNode)entity);
+ selectionNodeAgentRelation.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
+ }
+ preFillTaxonName();
checkbox_openInEditor = formFactory.createCheckbox(formElement,
"Open in Editor", true, style);
setOpenInEditor(true);
- setParentTreeNode(entity);
+
}
- private void preFillParentTaxonName() {
- if(getEntity() instanceof TaxonNode){
+ private void preFillTaxonName() {
+ 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){
+ if (!isCreateNew()){
+ textNewTaxonName.setText(name.getNameCache());
+ } else if( ! name.isSupraGeneric() && name.getRank() != null){
String taxonName = "";
if(name.isGenus() || name.isInfraGeneric()|| name.isSpeciesAggregate() ){
taxonName = name.getGenusOrUninomial();
}
}
}
+
}
-
+
}
+
}
}
} else if (eventSource == selection_reuseExistingTaxon) {
boolean enabled = selection_reuseExistingTaxon.getEntity() == null;
selection_reuseExistingName.setEnabled(enabled);
- textNewTaxonName.setEnabled(enabled);
if (!enabled){
- setTaxon(selection_reuseExistingTaxon.getEntity());
- } else{
- textNewTaxonName.setText(null);
+ setTaxon(selection_reuseExistingTaxon.getEntity());
+ }
+ if (isCreateNew()){
+ textNewTaxonName.setEnabled(enabled);
+ if (!enabled){
+ setTaxon(selection_reuseExistingTaxon.getEntity());
+ } else{
+ textNewTaxonName.setText(null);
+ }
+
+ complete = !textNewTaxonName.getText().isEmpty();
}
- complete = !textNewTaxonName.getText().isEmpty();
-
} else if (eventSource == selection_reuseExistingName) {
boolean enabled = selection_reuseExistingName.getEntity() == null;
complete = !textNewTaxonName.getText().isEmpty();
} else if (eventSource == checkbox_openInEditor) {
setOpenInEditor(checkbox_openInEditor.getSelection());
+ } else if (eventSource == selectionNodeAgentRelation){
+ boolean allComplete = true;
+ for (ICdmFormElement element : selectionNodeAgentRelation.getElements()){
+ allComplete &=((TaxonNodeAgentRelationCollectionElement)element).isComplete();
+ }
+
+ complete = !isCreateNew() && allComplete;
}
}
selection_parentTaxonNode.setClassification(classification);
selection_SecRef.setEntity(classification.getReference());
} else if (parentTreeNode instanceof TaxonNode) {
- classification = (Classification) HibernateProxyHelper
+ classification = HibernateProxyHelper
.deproxy(((TaxonNode) parentTreeNode).getClassification());
selection_classification.setEntity(classification);
selection_parentTaxonNode.setEntity((TaxonNode) parentTreeNode);
}
}
+ private void setTreeNode(ITaxonTreeNode treeNode) {
+ classification = HibernateProxyHelper
+ .deproxy(((TaxonNode) treeNode).getClassification());
+ selection_classification.setEntity(classification);
+ selection_parentTaxonNode.setEntity(((TaxonNode) treeNode).getParent());
+ selection_parentTaxonNode.setClassification(((TaxonNode) treeNode).getParent().getClassification());
+ selection_SecRef.setEntity(((TaxonNode)treeNode).getTaxon().getSec());
+ }
+
private void setSecReference(Reference secRef){
this.secReference = secRef;
setTaxon(textNewTaxonName.getText());
private void setTaxon(Taxon taxon) {
this.taxon = taxon;
- textNewTaxonName.setText(taxon.getName().getTitleCache());
+ if (isCreateNew()){
+ textNewTaxonName.setText(taxon.getName().getTitleCache());
+ }
selection_SecRef.setEntity(taxon.getSec());
}
}
public boolean isComplete() {
+ boolean allComplete = true;
+ if (!isCreateNew()){
+ for (ICdmFormElement element : selectionNodeAgentRelation.getElements()){
+ allComplete &=((TaxonNodeAgentRelationCollectionElement)element).isComplete();
+ }
+ complete = allComplete;
+ }
+
+
return complete;
}
+ /**
+ * @return the createNew
+ */
+ public boolean isCreateNew() {
+ return createNew;
+ }
+
}