- added specific methods for creating detail sections
[taxeditor.git] / eu.etaxonomy.taxeditor.store / src / main / java / eu / etaxonomy / taxeditor / ui / element / AbstractFormSection.java
index 0ebb936413cbe0c0b9ab0a2926da834ef3e8de86..cece9928bba24c05f590518a3603b11d2651c766 100644 (file)
@@ -33,20 +33,24 @@ import org.eclipse.ui.forms.widgets.ToggleHyperlink;
 import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
 import eu.etaxonomy.cdm.api.conversation.IConversationEnabled;
 import eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap;
-import eu.etaxonomy.taxeditor.store.StoreUtil;
+import eu.etaxonomy.taxeditor.model.AbstractUtility;
 
 /**
  * <p>
- * Abstract AbstractFormSection class.
+ * Abstract super class for a {@link Section} GUI element that visualizes a CDM
+ * entity, manages a conversation and listens to selections
  * </p>
  *
+ * @param <ENTITY> A CDM entity which should be visualized by this section.
+ *
  * @author n.hoffmann
  * @created Feb 22, 2010
  * @version 1.0
  * @param <T>
  */
+//TODO shouldn't ENTITY be bound with super class ICdmBase for example (AbstractFormSection<ENTITY extends ICdmBase>)?
 public abstract class AbstractFormSection<ENTITY> extends Section implements
-               ISelectionChangedListener, ICdmFormElement, IEntityElement<ENTITY>,
+               ISelectionChangedListener, IEntityElement<ENTITY>,
                IConversationEnabled {
 
        private ISelectionProvider selectionProvider;
@@ -81,8 +85,7 @@ public abstract class AbstractFormSection<ENTITY> extends Section implements
         * @param <ENTITY>
         *            a ENTITY object.
         */
-       protected AbstractFormSection(CdmFormFactory formFactory, ICdmFormElement parentElement,
-                       int style) {
+    protected AbstractFormSection(CdmFormFactory formFactory, ICdmFormElement parentElement, int style) {
                super(parentElement.getLayoutComposite(), style);
 
                this.parentElement = parentElement;
@@ -103,31 +106,29 @@ public abstract class AbstractFormSection<ENTITY> extends Section implements
                this.setClient(client);
        }
 
-       /**
-        * <p>
-        * Constructor for AbstractFormSection.
-        * </p>
-        *
-        * @param formFactory
-        *            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.element.ICdmFormElement}
-        *            object.
-        * @param selectionProvider
-        *            a {@link org.eclipse.jface.viewers.ISelectionProvider} object.
-        * @param style
-        *            a int.
-        */
-       protected AbstractFormSection(CdmFormFactory formFactory,
-                       ICdmFormElement parentElement,
-                       ISelectionProvider selectionProvider, int style) {
-               this(formFactory, parentElement, style);
-               this.selectionProvider = selectionProvider;
-       }
+           /**
+     * <p>
+     * Constructor for AbstractFormSection.
+     * </p>
+     *
+     * @param formFactory
+     *            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.element.ICdmFormElement}
+     *            object.
+     * @param selectionProvider
+     *            a {@link org.eclipse.jface.viewers.ISelectionProvider} object.
+     * @param style
+     *            a int.
+     */
+    protected AbstractFormSection(CdmFormFactory formFactory, ICdmFormElement parentElement, ISelectionProvider selectionProvider, int style) {
+        this(formFactory, parentElement, style);
+        this.selectionProvider = selectionProvider;
+    }
 
        /**
         * <p>
@@ -210,17 +211,15 @@ public abstract class AbstractFormSection<ENTITY> extends Section implements
        /** {@inheritDoc} */
        @Override
     public void firePropertyChangeEvent(CdmPropertyChangeEvent event) {
-               Assert.isNotNull(propertyChangeListeners,
-                               "No property change listeners.");
-               try {
-                       for (Object listener : propertyChangeListeners) {
-                               ((IPropertyChangeListener) listener).propertyChange(event);
-                       }
-               } catch (ConcurrentModificationException e) {
-                       StoreUtil.warn(getClass(),
-                                       "ConcurrentModificationException while handling PropertyChangeEvents."
-                                                       + " It seems like this is not critical");
-               }
+        Assert.isNotNull(propertyChangeListeners, "No property change listeners.");
+        try {
+            for (Object listener : propertyChangeListeners) {
+                ((IPropertyChangeListener) listener).propertyChange(event);
+            }
+        } catch (ConcurrentModificationException e) {
+            AbstractUtility.warn(getClass(), "ConcurrentModificationException while handling PropertyChangeEvents."
+                    + " It seems like this is not critical");
+        }
        }
 
        /**
@@ -310,20 +309,19 @@ public abstract class AbstractFormSection<ENTITY> extends Section implements
         *            a {@link org.eclipse.swt.events.SelectionEvent} object.
         */
        public void widgetSelected(SelectionEvent e) {
-               Widget widget = e.widget;
-
-               if (widget instanceof Control) {
-                       Control control = (Control) widget;
-                       if (checkControlAncestryForWidget(control)) {
-                               if (getEntity() != null) {
-                                       IStructuredSelection selection = new StructuredSelection(
-                                                       getEntity());
-                                       if (selectionProvider != null) {
-                                               selectionProvider.setSelection(selection);
-                                       }
-                               }
-                       }
-               }
+        Widget widget = e.widget;
+
+        if (widget instanceof Control) {
+            Control control = (Control) widget;
+            if (checkControlAncestryForWidget(control)) {
+                if (getEntity() != null) {
+                    IStructuredSelection selection = new StructuredSelection(getEntity());
+                    if (selectionProvider != null) {
+                        selectionProvider.setSelection(selection);
+                    }
+                }
+            }
+        }
        }
 
        private boolean checkControlAncestryForWidget(Control control) {
@@ -425,8 +423,7 @@ public abstract class AbstractFormSection<ENTITY> extends Section implements
                        // unregister selection arbitrator
                        if (childElement instanceof ISelectableElement) {
                                ISelectableElement selectableElement = (ISelectableElement) childElement;
-                               if (selectableElement != null
-                                               && selectableElement.getSelectionArbitrator() != null) {
+                               if (selectableElement.getSelectionArbitrator() != null) {
                                        formFactory.destroySelectionArbitrator(selectableElement
                                                        .getSelectionArbitrator());
                                }
@@ -568,15 +565,15 @@ public abstract class AbstractFormSection<ENTITY> extends Section implements
     public ConversationHolder getConversationHolder() {
                if(getParentElement() instanceof RootElement || getParentElement() == null){
 
-                       IEditorPart activeEditor = StoreUtil.getActiveEditor();
+                       IEditorPart activeEditor = AbstractUtility.getActiveEditor();
                        if(activeEditor instanceof IConversationEnabled){
-                               ConversationHolder conversation = ((IConversationEnabled) StoreUtil.getActiveEditor()).getConversationHolder();
+                               ConversationHolder conversation = ((IConversationEnabled) AbstractUtility.getActiveEditor()).getConversationHolder();
                                return conversation;
                        }
                }else if(getParentElement() instanceof IConversationEnabled){
                        return ((IConversationEnabled) getParentElement()).getConversationHolder();
                }
-               StoreUtil.errorDialog("Could not get conversation for AbstractFormSection",
+               AbstractUtility.errorDialog("Could not get conversation for AbstractFormSection",
                                getClass(), "There is an error in the implementation. There should have been an active editor but it wasn't",
                                new IllegalArgumentException());
                return null;