- added possibility to also add a person as nomenclatural author (fixes #4301)
[taxeditor.git] / eu.etaxonomy.taxeditor.store / src / main / java / eu / etaxonomy / taxeditor / ui / section / AbstractCdmDetailSection.java
index 7a99479399ca7125a3550abd045af6c505779d81..c9ddfffb8af7fa38b4e267ce7099084339cf5bc2 100644 (file)
@@ -1,9 +1,9 @@
 // $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.
  */
@@ -17,46 +17,43 @@ import org.eclipse.swt.graphics.Color;
 import org.eclipse.swt.widgets.Control;
 import org.eclipse.ui.forms.events.ExpansionEvent;
 import org.eclipse.ui.forms.events.IExpansionListener;
-import org.eclipse.ui.forms.widgets.Section;
+import org.eclipse.ui.forms.widgets.ExpandableComposite;
 import org.eclipse.ui.forms.widgets.TableWrapLayout;
 
 import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
 import eu.etaxonomy.cdm.model.common.IdentifiableEntity;
-import eu.etaxonomy.taxeditor.ui.forms.AbstractFormSection;
-import eu.etaxonomy.taxeditor.ui.forms.CdmFormFactory;
-import eu.etaxonomy.taxeditor.ui.forms.CdmFormFactory.DetailType;
-import eu.etaxonomy.taxeditor.ui.forms.ICdmFormElement;
-import eu.etaxonomy.taxeditor.ui.forms.IEnableableFormElement;
-import eu.etaxonomy.taxeditor.ui.forms.ISelectableElement;
+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.IEnableableFormElement;
+import eu.etaxonomy.taxeditor.ui.element.ISelectableElement;
 
 /**
- * <p>
- * Abstract AbstractCdmDetailSection class.
- * </p>
- * 
+ * This class visualizes an CDM entity of type ENTITY.
+ *
+ * @param <ENTITY> A CDM entity which should be visualized by this section.
+ *
  * @author n.hoffmann
  * @created Feb 26, 2010
  * @version 1.0
  */
-public abstract class AbstractCdmDetailSection<ENTITY> extends
-               AbstractFormSection<ENTITY> implements IEnableableFormElement,
-               IExpansionListener {
+public abstract class AbstractCdmDetailSection<ENTITY> extends AbstractFormSection<ENTITY> implements IEnableableFormElement, IExpansionListener {
 
-       protected AbstractCdmDetailElement<ENTITY> detailElement;
+       protected ICdmDetailElement<ENTITY> detailElement;
 
        /**
         * <p>
         * Constructor for AbstractCdmDetailSection.
         * </p>
-        * 
+        *
         * @param formFactory
-        *            a {@link eu.etaxonomy.taxeditor.ui.forms.CdmFormFactory}
+        *            a {@link eu.etaxonomy.taxeditor.ui.element.CdmFormFactory}
         *            object.
         * @param conversation
         *            a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder}
         *            object.
         * @param parentElement
-        *            a {@link eu.etaxonomy.taxeditor.ui.forms.ICdmFormElement}
+        *            a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement}
         *            object.
         * @param selectionProvider
         *            a {@link org.eclipse.jface.viewers.ISelectionProvider} object.
@@ -68,27 +65,26 @@ public abstract class AbstractCdmDetailSection<ENTITY> extends
        public AbstractCdmDetailSection(CdmFormFactory formFactory,
                        ConversationHolder conversation, ICdmFormElement parentElement,
                        ISelectionProvider selectionProvider, int style) {
-               super(formFactory, parentElement, selectionProvider,
-                               Section.CLIENT_INDENT | style);
-
-               setText(getHeading());
+           this(formFactory, null, conversation, parentElement, selectionProvider, style);
+       }
 
-               addExpansionListener(this);
 
-               createControls(this, SWT.NULL);
-       }
-       
        public AbstractCdmDetailSection(CdmFormFactory formFactory, Class<ENTITY> clazz,
                        ConversationHolder conversation, ICdmFormElement parentElement,
                        ISelectionProvider selectionProvider, int style) {
                super(formFactory, parentElement, selectionProvider,
-                               Section.CLIENT_INDENT | style);
-               
-               setText(getHeading());
+                               ExpandableComposite.CLIENT_INDENT | style);
 
-               addExpansionListener(this);
+        setText(getHeading());
 
-               createControlsByType(this, clazz, SWT.NULL);
+        addExpansionListener(this);
+
+        if(clazz==null){
+            createControls(this, style);
+        }
+        else{
+            createControlsByType(this, clazz, SWT.NULL);
+        }
        }
 
        /**
@@ -96,9 +92,18 @@ public abstract class AbstractCdmDetailSection<ENTITY> extends
         * @param definedTermClass
         * @param null1
         */
-       protected void createControlsByType(
-                       AbstractCdmDetailSection<ENTITY> abstractCdmDetailSection,
-                       Class<ENTITY> entityClass, int style) {
+       protected void createControlsByType(AbstractCdmDetailSection<ENTITY> formElement, Class<ENTITY> entityClass, int style) {
+           TableWrapLayout layout = (TableWrapLayout) getLayoutComposite().getLayout();
+           layout.topMargin = 10;
+           layout.numColumns = 2;
+
+           getLayoutComposite().setLayout(layout);
+           if(entityClass==null){
+               detailElement = createCdmDetailElement(formElement, style);
+           }
+           else{
+               detailElement = createCdmDetailElementByType(formElement, entityClass, style);
+           }
        }
 
 
@@ -106,7 +111,7 @@ public abstract class AbstractCdmDetailSection<ENTITY> extends
         * <p>
         * createControls
         * </p>
-        * 
+        *
         * @param formElement
         *            a
         *            {@link eu.etaxonomy.taxeditor.ui.section.AbstractCdmDetailSection}
@@ -114,34 +119,21 @@ public abstract class AbstractCdmDetailSection<ENTITY> extends
         * @param style
         *            a int.
         */
-       protected void createControls(AbstractCdmDetailSection<ENTITY> formElement,
-                       int style) {
-               TableWrapLayout layout = (TableWrapLayout) getLayoutComposite()
-                               .getLayout();
-               layout.topMargin = 10;
-               layout.numColumns = 2;
-
-               getLayoutComposite().setLayout(layout);
-               detailElement = formFactory.createCdmDetailElement(getDetailType(),
-                               formElement, style);
+       protected void createControls(AbstractCdmDetailSection<ENTITY> formElement, int style) {
+           createControlsByType(formElement, null, style);
        }
 
-       /**
-        * <p>
-        * getDetailType
-        * </p>
-        * 
-        * @return a
-        *         {@link eu.etaxonomy.taxeditor.ui.forms.CdmFormFactory.DetailType}
-        *         object.
-        */
-       protected abstract DetailType getDetailType();
+       protected abstract ICdmDetailElement<ENTITY> createCdmDetailElement(AbstractCdmDetailSection<ENTITY> parentElement, int style);
+
+       protected ICdmDetailElement<ENTITY> createCdmDetailElementByType(AbstractCdmDetailSection<ENTITY> parentElement, Class<ENTITY> entityClass, int style){
+           return createCdmDetailElement(parentElement, style);
+       }
 
        /**
         * <p>
         * getHeading
         * </p>
-        * 
+        *
         * @return the heading for this section
         */
        public abstract String getHeading();
@@ -161,7 +153,7 @@ public abstract class AbstractCdmDetailSection<ENTITY> extends
 
        /*
         * (non-Javadoc)
-        * 
+        *
         * @see
         * eu.etaxonomy.taxeditor.forms.section.AbstractEditorFormSection#setBackground
         * (org.eclipse.swt.graphics.Color)
@@ -179,7 +171,7 @@ public abstract class AbstractCdmDetailSection<ENTITY> extends
         * <p>
         * setEntity
         * </p>
-        * 
+        *
         * @param entity
         *            a ENTITY object.
         */
@@ -228,19 +220,22 @@ public abstract class AbstractCdmDetailSection<ENTITY> extends
        }
 
        /** {@inheritDoc} */
-       public void setIrrelevant(boolean irrelevant) {
+       @Override
+    public void setIrrelevant(boolean irrelevant) {
                if (detailElement != null) {
                        detailElement.setIrrelevant(irrelevant);
                }
        }
 
        /** {@inheritDoc} */
-       public void expansionStateChanging(ExpansionEvent e) {
+       @Override
+    public void expansionStateChanging(ExpansionEvent e) {
                // logger.warn("Expansion State Changing");
        }
 
        /** {@inheritDoc} */
-       public void expansionStateChanged(ExpansionEvent e) {
+       @Override
+    public void expansionStateChanged(ExpansionEvent e) {
                // logger.warn("Expansion State Changed");
        }
 }