add the possibility to add taxonnode agent relations to a taxonnode and to edit a...
authorKatja Luther <k.luther@bgbm.org>
Wed, 23 Mar 2016 12:51:20 +0000 (13:51 +0100)
committerKatja Luther <k.luther@bgbm.org>
Wed, 23 Mar 2016 12:52:12 +0000 (13:52 +0100)
eu.etaxonomy.taxeditor.store/OSGI-INF/l10n/bundle.properties
eu.etaxonomy.taxeditor.store/plugin.xml
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/handler/defaultHandler/DefaultOpenTaxonNodeWizardHandler.java [new file with mode: 0644]
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/element/CdmFormFactory.java
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/classification/EditTaxonNodeWizard.java [new file with mode: 0644]
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/classification/TaxonNodeAgentRelationCollectionElement.java [new file with mode: 0644]
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/classification/TaxonNodeAgentRelationCollectionSection.java [new file with mode: 0644]
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/classification/TaxonNodeDetailElement.java
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/classification/TaxonNodeDetailSection.java
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/classification/TaxonNodeWizardPage.java

index 242111fb2153704537ac1fe38e297b5239e5cd86..8b2e195f48b2f43d2dea560099073b2ae6f03f41 100644 (file)
@@ -164,4 +164,5 @@ command.label.CONNECT = Connect
 command.label.RE_CONNECT = Re-Connect\r
 command.name.CONNECT = Connect\r
 command.name.RE_CONNECT = Re-Connect\r
-command.name.OPEN_CLASSIFICATION_WIZARD = Open Classification Wizard
\ No newline at end of file
+command.name.OPEN_CLASSIFICATION_WIZARD = Open Classification Wizard\r
+command.name.OPEN_TAXONNODE_WIZARD = Open Taxon Node Wizard
\ No newline at end of file
index 4b8b2413b5fe2fe1c7357fa102e772ee776b3752..3e23d6cc7d54b7e7b1356315bc0543a76f913ac7 100644 (file)
                typeId="eu.etaxonomy.taxeditor.uuidParameterType">
          </commandParameter>
       </command>
+      <command
+            defaultHandler="eu.etaxonomy.taxeditor.handler.defaultHandler.DefaultOpenTaxonNodeWizardHandler"
+            id="eu.etaxonomy.taxeditor.command.openTaxonNodeWizard"
+            name="%command.name.OPEN_TAXONNODE_WIZARD">
+         <commandParameter
+               id="eu.etaxonomy.taxeditor.command.openTaxonNodeWizard.uuid"
+               name="TaxonNode Uuid"
+               optional="true"
+               typeId="eu.etaxonomy.taxeditor.uuidParameterType">
+         </commandParameter>
+      </command>
    </extension>
    <extension
          point="org.eclipse.ui.commands">
          selection="eu.etaxonomy.cdm.model.taxon.Classification"
          viewerName="Classification Wizard">
    </viewCommandMapping>
+   <viewCommandMapping
+         commandId="eu.etaxonomy.taxeditor.command.openTaxonNodeWizard"
+         selection="eu.etaxonomy.cdm.model.taxon.TaxonNode"
+         viewerName="TaxonNode Wizard">
+   </viewCommandMapping>
 </extension>
 </plugin>
diff --git a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/handler/defaultHandler/DefaultOpenTaxonNodeWizardHandler.java b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/handler/defaultHandler/DefaultOpenTaxonNodeWizardHandler.java
new file mode 100644 (file)
index 0000000..0ac105f
--- /dev/null
@@ -0,0 +1,42 @@
+// $Id$
+/**
+* Copyright (C) 2016 EDIT
+* 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.handler.defaultHandler;
+
+import java.util.UUID;
+
+import org.eclipse.core.commands.ExecutionEvent;
+import org.eclipse.jface.wizard.WizardDialog;
+import org.eclipse.ui.PlatformUI;
+
+import eu.etaxonomy.cdm.api.service.ITaxonNodeService;
+import eu.etaxonomy.cdm.model.taxon.TaxonNode;
+import eu.etaxonomy.taxeditor.store.CdmStore;
+import eu.etaxonomy.taxeditor.ui.section.classification.EditTaxonNodeWizard;
+
+/**
+ * @author k.luther
+ * @date 22.03.2016
+ *
+ */
+public class DefaultOpenTaxonNodeWizardHandler extends DefaultOpenHandlerBase<TaxonNode> {
+    @Override
+    protected TaxonNode getEntity(UUID uuid) {
+        return CdmStore.getService(ITaxonNodeService.class).load(uuid);
+    }
+
+    @Override
+    protected void open(ExecutionEvent event, TaxonNode entity) {
+        EditTaxonNodeWizard taxonNodeWizard = new EditTaxonNodeWizard();
+        taxonNodeWizard.init(null, null);
+        taxonNodeWizard.setEntity(entity);
+        WizardDialog dialog = new WizardDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), taxonNodeWizard);
+        dialog.open();
+    }
+}
index 3efeb550a425ac28619ff3a4522cc54ec84712a9..8052c82f410c67ed1d40c7a2ca290f10e7e8f5bf 100644 (file)
@@ -102,6 +102,7 @@ import eu.etaxonomy.cdm.model.reference.Reference;
 import eu.etaxonomy.cdm.model.taxon.SynonymRelationship;
 import eu.etaxonomy.cdm.model.taxon.Taxon;
 import eu.etaxonomy.cdm.model.taxon.TaxonNode;
+import eu.etaxonomy.cdm.model.taxon.TaxonNodeAgentRelation;
 import eu.etaxonomy.cdm.strategy.parser.ParserProblem;
 import eu.etaxonomy.taxeditor.model.MessagingUtils;
 import eu.etaxonomy.taxeditor.ui.combo.EnumComboElement;
@@ -127,6 +128,8 @@ import eu.etaxonomy.taxeditor.ui.section.agent.TeamMemberSection;
 import eu.etaxonomy.taxeditor.ui.section.agent.TeamOrPersonBaseDetailSection;
 import eu.etaxonomy.taxeditor.ui.section.classification.ClassificationDetailElement;
 import eu.etaxonomy.taxeditor.ui.section.classification.ClassificationDetailSection;
+import eu.etaxonomy.taxeditor.ui.section.classification.TaxonNodeAgentRelationCollectionElement;
+import eu.etaxonomy.taxeditor.ui.section.classification.TaxonNodeAgentRelationCollectionSection;
 import eu.etaxonomy.taxeditor.ui.section.classification.TaxonNodeDetailElement;
 import eu.etaxonomy.taxeditor.ui.section.classification.TaxonNodeDetailSection;
 import eu.etaxonomy.taxeditor.ui.section.common.ReferenceEntityDetailElement;
@@ -1907,8 +1910,16 @@ public class CdmFormFactory extends FormToolkit {
         return element;
     }
 
-    public TaxonNodeDetailElement createTaxonNodeDetailElement(ICdmFormElement parentElement){
-        TaxonNodeDetailElement element = new TaxonNodeDetailElement(this, parentElement);
+    public TaxonNodeAgentRelationCollectionSection createTaxonNodeAgentRelationCollectionElement(ICdmFormElement parentElement, ConversationHolder conversation, int style){
+        TaxonNodeAgentRelationCollectionSection element = new TaxonNodeAgentRelationCollectionSection(this, conversation, parentElement, style);
+        adapt(element);
+        parentElement.addElement(element);
+
+        return element;
+    }
+
+    public TaxonNodeDetailElement createTaxonNodeDetailElement(ICdmFormElement parentElement, boolean createNew){
+        TaxonNodeDetailElement element = new TaxonNodeDetailElement(this, parentElement, createNew);
         addAndAdaptElement(parentElement, element);
         return element;
     }
@@ -2416,6 +2427,7 @@ public class CdmFormFactory extends FormToolkit {
         return section;
     }
 
+
     public AbstractEntityCollectionElement createEntityCollectionElement(AbstractFormSection parentElement,
             Object versionableEntity, SelectionListener removeListener, Color backgroundColor, int style) {
         AbstractEntityCollectionElement element = null;
@@ -2424,7 +2436,7 @@ public class CdmFormFactory extends FormToolkit {
 
         if (entity instanceof Annotation) {
             element = new AnnotationElement(this, parentElement, (Annotation) entity, removeListener, style);
-        } else if (entity instanceof Person) {
+        }else if (entity instanceof Person) {
             element = new TeamMemberElement(this, parentElement, (Person) entity, removeListener, style);
         } else if (entity instanceof Credit) {
             element = new CreditElement(this, parentElement, (Credit) entity, removeListener, style);
@@ -2432,7 +2444,9 @@ public class CdmFormFactory extends FormToolkit {
             element = new ExtensionElement(this, parentElement, (Extension) entity, removeListener, style);
         } else if (entity instanceof Marker) {
             element = new MarkerElement(this, parentElement, (Marker) entity, removeListener, style);
-        } else if (entity instanceof Media) {
+        } else if (entity instanceof TaxonNodeAgentRelation) {
+            element = new TaxonNodeAgentRelationCollectionElement(this, parentElement, (TaxonNodeAgentRelation) entity, removeListener, backgroundColor, style);
+        }else if (entity instanceof Media) {
             element = new MediaMetaElement(this, parentElement, (Media) entity, removeListener, true, style);
         } else if (entity instanceof MediaRepresentation) {
             element = new MediaRepresentationElement(this, parentElement, (MediaRepresentation) entity, removeListener,
@@ -2450,7 +2464,11 @@ public class CdmFormFactory extends FormToolkit {
         } else if (entity instanceof DescriptionElementSource) {
             element = new DescriptionElementSourceElement(this, parentElement, (DescriptionElementSource) entity,
                     removeListener, style);
-        } else if (entity instanceof IdentifiableSource) {
+        } else if (entity instanceof TaxonNodeAgentRelation) {
+            element = new TaxonNodeAgentRelationCollectionElement(this, parentElement, (TaxonNodeAgentRelation) entity,
+                    removeListener,backgroundColor, style);
+        }
+        else if (entity instanceof IdentifiableSource) {
             element = new IdentifiableSourceElement(this, parentElement, (IdentifiableSource) entity, removeListener,
                     style);
         } else if (entity instanceof DefinedTerm) {
@@ -2567,6 +2585,7 @@ public class CdmFormFactory extends FormToolkit {
             element = new StatisticalMeasureCollectionElement(this, parentElement, (StatisticalMeasure) entity, removeListener, backgroundColor, style);
         }
 
+
         if (element == null) {
             MessagingUtils.messageDialog("No element for entity", this,
                     "Could not generate element for entity. Looks like the case is not handled already. Check implementation. Entity: "
@@ -2793,4 +2812,17 @@ public class CdmFormFactory extends FormToolkit {
         return section;
     }
 
+    /**
+     * @param formElement
+     * @param conversationHolder
+     * @param style
+     * @return
+     */
+    public TaxonNodeAgentRelationCollectionSection createTaxonNodeAgentRelationCollectionSection(
+            ICdmFormElement formElement, ConversationHolder conversationHolder, int style) {
+        TaxonNodeAgentRelationCollectionSection section = new TaxonNodeAgentRelationCollectionSection(this, conversationHolder, formElement, style);
+        addAndAdaptSection(formElement, section);
+        return section;
+    }
+
 }
diff --git a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/classification/EditTaxonNodeWizard.java b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/classification/EditTaxonNodeWizard.java
new file mode 100644 (file)
index 0000000..68bd471
--- /dev/null
@@ -0,0 +1,67 @@
+// $Id$
+/**
+* Copyright (C) 2016 EDIT
+* 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 eu.etaxonomy.cdm.api.service.ITaxonNodeService;
+import eu.etaxonomy.cdm.model.taxon.ITaxonTreeNode;
+import eu.etaxonomy.cdm.model.taxon.TaxonNode;
+import eu.etaxonomy.taxeditor.newWizard.IWizardPageListener;
+import eu.etaxonomy.taxeditor.store.CdmStore;
+
+/**
+ * @author k.luther
+ * @date 23.03.2016
+ *
+ */
+public class EditTaxonNodeWizard extends AbstractEditWizard<ITaxonTreeNode> {
+
+    private TaxonNodeWizardPage taxonNodePage;
+    private IWizardPageListener wizardPageListener;
+
+    /* (non-Javadoc)
+     * @see eu.etaxonomy.taxeditor.ui.section.classification.AbstractEditWizard#getEntityName()
+     */
+    @Override
+    protected String getEntityName() {
+        return "TaxonNode";
+    }
+
+    /* (non-Javadoc)
+     * @see eu.etaxonomy.taxeditor.ui.section.classification.AbstractEditWizard#saveEntity()
+     */
+    @Override
+    protected void saveEntity() {
+        getConversationHolder().bind();
+        TaxonNode node = (TaxonNode)getEntity();
+
+        CdmStore.getService(ITaxonNodeService.class).merge(node, true);
+    }
+    @Override
+    public void addPages() {
+        taxonNodePage = new TaxonNodeWizardPage(formFactory, getConversationHolder(), getEntity(), wizardPageListener, false);
+
+        addPage(taxonNodePage);
+    }
+
+    public void addWizardPageListener(IWizardPageListener wizardPageListener){
+        this.wizardPageListener = wizardPageListener;
+    }
+
+    /* (non-Javadoc)
+     * @see eu.etaxonomy.taxeditor.newWizard.AbstractNewEntityWizard#setEntity(java.lang.Object)
+     */
+    @Override
+    public void setEntity(ITaxonTreeNode entity) {
+        setWindowTitle(String.format("Edit %s", getEntityName()));
+        entity = CdmStore.getService(ITaxonNodeService.class).load(entity.getUuid());
+        super.setEntity(entity);
+    }
+
+}
diff --git a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/classification/TaxonNodeAgentRelationCollectionElement.java b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/classification/TaxonNodeAgentRelationCollectionElement.java
new file mode 100644 (file)
index 0000000..a2443df
--- /dev/null
@@ -0,0 +1,116 @@
+// $Id$
+/**
+* Copyright (C) 2016 EDIT
+* 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.eclipse.swt.events.SelectionListener;
+import org.eclipse.swt.graphics.Color;
+
+import eu.etaxonomy.cdm.model.agent.TeamOrPersonBase;
+import eu.etaxonomy.cdm.model.common.DefinedTerm;
+import eu.etaxonomy.cdm.model.common.TermType;
+import eu.etaxonomy.cdm.model.taxon.TaxonNodeAgentRelation;
+import eu.etaxonomy.taxeditor.ui.combo.TermComboElement;
+import eu.etaxonomy.taxeditor.ui.element.AbstractFormSection;
+import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
+import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;
+import eu.etaxonomy.taxeditor.ui.element.LabelElement;
+import eu.etaxonomy.taxeditor.ui.section.AbstractEntityCollectionElement;
+import eu.etaxonomy.taxeditor.ui.selection.EntitySelectionElement;
+
+/**
+ * @author k.luther
+ * @date 22.03.2016
+ *
+ */
+public class TaxonNodeAgentRelationCollectionElement extends AbstractEntityCollectionElement<TaxonNodeAgentRelation> {
+
+
+
+
+    /**
+     * @param formFactory
+     * @param section
+     * @param entity
+     * @param removeListener
+     * @param backgroundColor
+     * @param style
+     */
+    public TaxonNodeAgentRelationCollectionElement(CdmFormFactory formFactory, AbstractFormSection section,
+            TaxonNodeAgentRelation entity, SelectionListener removeListener, Color backgroundColor, int style) {
+        super(formFactory, section, entity, removeListener, backgroundColor, style);
+
+        // TODO Auto-generated constructor stub
+    }
+
+
+
+
+    private EntitySelectionElement<TeamOrPersonBase> selection_toPerson;
+    private TermComboElement<DefinedTerm> combo_relationshipType;
+    private LabelElement label;
+
+
+
+
+
+
+
+    @Override
+    public void setEntity(TaxonNodeAgentRelation entity) {
+
+        if(entity.getId()!=0){
+            combo_relationshipType.setSelection(entity.getType());
+            selection_toPerson.setEntity(entity.getAgent());
+        }
+        this.entity = entity;
+    }
+
+    @Override
+    public void handleEvent(Object eventSource) {
+        if(eventSource==combo_relationshipType){
+
+            entity.setType(combo_relationshipType.getSelection());
+
+        }else if (eventSource == selection_toPerson){
+            entity.setAgent(selection_toPerson.getEntity());
+        }
+    }
+
+    /* (non-Javadoc)
+     * @see eu.etaxonomy.taxeditor.ui.section.AbstractEntityCollectionElement#createControls(eu.etaxonomy.taxeditor.ui.element.ICdmFormElement, int)
+     */
+    @Override
+    public void createControls(ICdmFormElement element, int style) {
+        combo_relationshipType = formFactory.createDefinedTermComboElement(TermType.TaxonNodeAgentRelationType, element, "Taxonnode Agent Relationtype", null, style);
+        if (entity != null){
+            selection_toPerson = formFactory
+                    .createSelectionElement(TeamOrPersonBase.class,
+                            getConversationHolder(), element, "Agent", entity.getAgent(),
+                            EntitySelectionElement.ALL, style);
+        } else{
+            selection_toPerson = formFactory
+                    .createSelectionElement(TeamOrPersonBase.class,
+                            getConversationHolder(), element, "Agent", null,
+                            EntitySelectionElement.ALL, style);
+        }
+        label = formFactory.createLabel(element, null);
+
+    }
+
+    public boolean isComplete(){
+        if (selection_toPerson.getSelection()!= null && combo_relationshipType.getSelection() != null){
+            return true;
+        }
+        return false;
+
+    }
+
+
+}
diff --git a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/classification/TaxonNodeAgentRelationCollectionSection.java b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/classification/TaxonNodeAgentRelationCollectionSection.java
new file mode 100644 (file)
index 0000000..c161aec
--- /dev/null
@@ -0,0 +1,103 @@
+// $Id$
+/**
+* Copyright (C) 2016 EDIT
+* 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 java.util.Collection;
+
+import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
+import eu.etaxonomy.cdm.model.taxon.TaxonNode;
+import eu.etaxonomy.cdm.model.taxon.TaxonNodeAgentRelation;
+import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
+import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;
+import eu.etaxonomy.taxeditor.ui.section.AbstractEntityCollectionSection;
+
+/**
+ * @author k.luther
+ * @date 22.03.2016
+ *
+ */
+public class TaxonNodeAgentRelationCollectionSection extends AbstractEntityCollectionSection<TaxonNode, TaxonNodeAgentRelation> {
+
+
+
+    /**
+     * @param formFactory
+     * @param conversation
+     * @param parentElement
+
+     * @param style
+     */
+    public TaxonNodeAgentRelationCollectionSection (CdmFormFactory formFactory, ConversationHolder conversation,
+            ICdmFormElement parentElement, int style) {
+        super(formFactory, conversation, parentElement,  "TaxonNode Agent Relation", style);
+
+    }
+
+
+    /* (non-Javadoc)
+     * @see eu.etaxonomy.taxeditor.ui.section.AbstractEntityCollectionSection#getEmptyString()
+     */
+    @Override
+    public String getEmptyString() {
+        return "No taxon node agent relations yet.";
+    }
+
+    /* (non-Javadoc)
+     * @see eu.etaxonomy.taxeditor.ui.section.AbstractEntityCollectionSection#getTooltipString()
+     */
+    @Override
+    protected String getTooltipString() {
+        return "Add a new agent relation to this taxon node.";
+    }
+
+    /* (non-Javadoc)
+     * @see eu.etaxonomy.taxeditor.ui.section.AbstractEntityCollectionSection#getCollection(java.lang.Object)
+     */
+    @Override
+    public Collection<TaxonNodeAgentRelation> getCollection(TaxonNode entity) {
+        //why Do I have to give the method an entity???
+       Collection<TaxonNodeAgentRelation> allAgentRelationships = getEntity().getAgentRelations();
+       return allAgentRelationships;
+    }
+
+    /* (non-Javadoc)
+     * @see eu.etaxonomy.taxeditor.ui.section.AbstractEntityCollectionSection#addElement(java.lang.Object)
+     */
+    @Override
+    public void addElement(TaxonNodeAgentRelation element) {
+
+
+    }
+
+    /* (non-Javadoc)
+     * @see eu.etaxonomy.taxeditor.ui.section.AbstractEntityCollectionSection#removeElement(java.lang.Object)
+     */
+    @Override
+    public void removeElement(TaxonNodeAgentRelation element) {
+        getEntity().removeNodeAgent(element);
+      //  CdmStore.getService(ITaxonNodeService.class).deleteAgentrelation(element);
+    }
+
+
+    /* (non-Javadoc)
+     * @see eu.etaxonomy.taxeditor.ui.section.AbstractEntityCollectionSection#createNewElement()
+     */
+    @Override
+    public TaxonNodeAgentRelation createNewElement() {
+        TaxonNodeAgentRelation rel = getEntity().addAgentRelation(null, null);
+        return rel;
+    }
+
+    public boolean isComplete(){
+
+        return false;
+    }
+
+}
index 90706eb8b265d80d239665053ae1fabafcef4739..5ac40f536071de654a8df5356bf562f4269081a4 100644 (file)
@@ -26,6 +26,7 @@ import eu.etaxonomy.taxeditor.parser.ParseHandler;
 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;
@@ -39,6 +40,8 @@ import eu.etaxonomy.taxeditor.ui.selection.TaxonNodeSelectionElement;
  */
 public class TaxonNodeDetailElement extends AbstractCdmDetailElement<ITaxonTreeNode> {
 
+    private boolean createNew = false;
+
        private EntitySelectionElement<Classification> selection_classification;
 
        private Classification classification;
@@ -56,6 +59,9 @@ public class TaxonNodeDetailElement extends AbstractCdmDetailElement<ITaxonTreeN
 
        private TextWithLabelElement textNewTaxonName;
 
+       private TaxonNodeAgentRelationCollectionSection selectionNodeAgentRelation;
+
+
        private CheckboxElement checkbox_openInEditor;
 
        private boolean openInEditor;
@@ -65,8 +71,9 @@ public class TaxonNodeDetailElement extends AbstractCdmDetailElement<ITaxonTreeN
        private EntitySelectionElement<TaxonNameBase> selection_reuseExistingName;
 
        public TaxonNodeDetailElement(CdmFormFactory formFactory,
-                       ICdmFormElement formElement) {
+                       ICdmFormElement formElement, boolean isCreateNew) {
                super(formFactory, formElement);
+               createNew = isCreateNew;
        }
 
        /** {@inheritDoc} */
@@ -95,25 +102,44 @@ public class TaxonNodeDetailElement extends AbstractCdmDetailElement<ITaxonTreeN
                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();
@@ -129,9 +155,11 @@ public class TaxonNodeDetailElement extends AbstractCdmDetailElement<ITaxonTreeN
                                }
                         }
                     }
+
                 }
-               
+
             }
+
         }
     }
 
@@ -147,14 +175,19 @@ public class TaxonNodeDetailElement extends AbstractCdmDetailElement<ITaxonTreeN
                } 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;
@@ -174,6 +207,13 @@ public class TaxonNodeDetailElement extends AbstractCdmDetailElement<ITaxonTreeN
                        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;
                }
        }
 
@@ -208,7 +248,7 @@ public class TaxonNodeDetailElement extends AbstractCdmDetailElement<ITaxonTreeN
                        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);
@@ -219,6 +259,15 @@ public class TaxonNodeDetailElement extends AbstractCdmDetailElement<ITaxonTreeN
                }
        }
 
+       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());
@@ -226,7 +275,9 @@ public class TaxonNodeDetailElement extends AbstractCdmDetailElement<ITaxonTreeN
 
        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());
        }
 
@@ -268,7 +319,23 @@ public class TaxonNodeDetailElement extends AbstractCdmDetailElement<ITaxonTreeN
     }
 
        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;
+    }
+
 }
index 0508372da8f9116d5969f55247edc163ecfced5b..e108c85dc9e973c34106fe713ece923a10551f2b 100644 (file)
@@ -58,6 +58,6 @@ public class TaxonNodeDetailSection extends AbstractCdmDetailSection<TaxonNode>
        @Override
        protected AbstractCdmDetailElement createCdmDetailElement(AbstractCdmDetailSection<TaxonNode> parentElement, int style) {
            //FIXME generic
-           return formFactory.createTaxonNodeDetailElement(parentElement);
+           return formFactory.createTaxonNodeDetailElement(parentElement, false);
        }
 }
index df24d7c6c3fb97633b1c61a574f927b3f9709100..62d95788b0a643f6d1e38aca7021ce9a95b52bd1 100644 (file)
@@ -35,6 +35,7 @@ import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;
 public class TaxonNodeWizardPage extends AbstractCdmEntityWizardPage<ITaxonTreeNode> implements Listener{
 
     private final IWizardPageListener wizardPageListener;
+    private final boolean isCreateNew;
 
     /**
         * <p>
@@ -52,10 +53,12 @@ public class TaxonNodeWizardPage extends AbstractCdmEntityWizardPage<ITaxonTreeN
      * @param closeOnEnterListener
         */
        public TaxonNodeWizardPage(CdmFormFactory formFactory,
-                       ConversationHolder conversation, ITaxonTreeNode entity, IWizardPageListener closeOnEnterListener) {
+                       ConversationHolder conversation, ITaxonTreeNode entity, IWizardPageListener closeOnEnterListener, boolean isCreateNew) {
                super(formFactory, conversation, entity);
                this.wizardPageListener = closeOnEnterListener;
-               setTitle("Create a new Taxon");
+               setTitle("TaxonNode");
+               this.isCreateNew = isCreateNew;
+
        }
 
        /*
@@ -68,10 +71,12 @@ public class TaxonNodeWizardPage extends AbstractCdmEntityWizardPage<ITaxonTreeN
        /** {@inheritDoc} */
        @Override
        public TaxonNodeDetailElement createElement(ICdmFormElement rootElement) {
-           TaxonNodeDetailElement detailElement = formFactory.createTaxonNodeDetailElement(rootElement);
+           TaxonNodeDetailElement detailElement = formFactory.createTaxonNodeDetailElement(rootElement, this.isCreateNew);
                detailElement.setEntity(entity);
                formFactory.addPropertyChangeListener(this);
-               detailElement.getTextNewTaxonName().getMainControl().addListener(SWT.KeyDown, this);
+               if (isCreateNew){
+                   detailElement.getTextNewTaxonName().getMainControl().addListener(SWT.KeyDown, this);
+               }
                return detailElement;
        }
 
@@ -96,9 +101,7 @@ public class TaxonNodeWizardPage extends AbstractCdmEntityWizardPage<ITaxonTreeN
        /** {@inheritDoc} */
        @Override
        public void propertyChange(PropertyChangeEvent event) {
-               if (event.getSource() == getDetailElement()) {
-                       checkComplete();
-               }
+               checkComplete();
        }
 
        @Override
@@ -108,8 +111,14 @@ public class TaxonNodeWizardPage extends AbstractCdmEntityWizardPage<ITaxonTreeN
                if (detailElement.getClassification() == null) {
                        setMessage("No classification set.", WARNING);
                }
-               else if(detailElement.getTextNewTaxonName().getText().isEmpty()){
-                   setMessage("No taxon name set.", ERROR);
+               else if(isCreateNew ){
+                   if(detailElement.getTextNewTaxonName().getText().isEmpty()){
+                       setMessage("No taxon name set.", ERROR);
+                   } else{
+                       setMessage(null);
+                   setPageComplete(true);
+                   return;
+                   }
                }
                else if(!detailElement.isComplete()){
                    setMessage("Not all required fields are filled.", ERROR);