Merge branch 'release/5.32.0'
[taxeditor.git] / eu.etaxonomy.taxeditor.store / src / main / java / eu / etaxonomy / taxeditor / ui / section / AbstractEntityCollectionElement.java
index b8f0c20f6c616a65bdba1cded738caf40f343800..6dcee17c97fa8f65ff79c200dd79c16ed99c39da 100644 (file)
@@ -6,7 +6,6 @@
  * 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;
 
 import org.eclipse.jface.util.PropertyChangeEvent;
@@ -30,6 +29,7 @@ import eu.etaxonomy.taxeditor.ui.element.AbstractCdmFormElement;
 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.IEntityElement;
 import eu.etaxonomy.taxeditor.ui.element.ISelectable;
 import eu.etaxonomy.taxeditor.ui.element.LabelElement;
@@ -37,16 +37,17 @@ import eu.etaxonomy.taxeditor.ui.element.LayoutConstants;
 
 /**
  * Visualizes an element of type ENTITY in an {@link AbstractEntityCollectionSection}
- *  and links listener functionalities to it.
+ * and links listener functionalities to it.
  *
- *  @param ENTITY the type of the element which is visualized by this class
+ * @param ENTITY the type of the element which is visualized by this class
  *
  * @author n.hoffmann
  * @created Nov 16, 2009
  */
-public abstract class AbstractEntityCollectionElement<ENTITY> extends
-               AbstractCdmFormElement implements IEntityElement<ENTITY>,
-               SelectionListener, IConversationEnabled {
+public abstract class AbstractEntityCollectionElement<ENTITY>
+        extends AbstractCdmFormElement
+        implements IEntityElement<ENTITY>, SelectionListener,
+              IConversationEnabled, IEnableableFormElement {
 
        protected ENTITY entity;
 
@@ -57,8 +58,11 @@ public abstract class AbstractEntityCollectionElement<ENTITY> extends
         */
        private final Composite box;
 
+       private boolean isEnabled;
+
        private Button btnRemove;
-    protected Button btnChooseEntity;
+
+       private Button btnChooseEntity;
 
        private Color backgroundColor;
 
@@ -106,11 +110,13 @@ public abstract class AbstractEntityCollectionElement<ENTITY> extends
                        btnRemove.setToolTipText("Remove");
 
                        btnRemove.addSelectionListener(removeListener);
+                       btnRemove.setEnabled(isEnabled);
                }
 
-               createControls(this, style);
+
 
                setEntity(entity);
+               createControls(this, style);
        }
 
        /**
@@ -156,7 +162,6 @@ public abstract class AbstractEntityCollectionElement<ENTITY> extends
                setBackground(selected ? SELECTED : getPersistentBackground());
        }
 
-       /** {@inheritDoc} */
        @Override
        public void propertyChange(PropertyChangeEvent event) {
                if (event == null) {
@@ -170,7 +175,6 @@ public abstract class AbstractEntityCollectionElement<ENTITY> extends
 
        public abstract void handleEvent(Object eventSource);
 
-       /** {@inheritDoc} */
        @Override
     public void setBackground(Color color) {
            if(box.isDisposed() || container.isDisposed()){
@@ -192,12 +196,10 @@ public abstract class AbstractEntityCollectionElement<ENTITY> extends
 
        }
 
-       /** {@inheritDoc} */
        @Override
     public void widgetDefaultSelected(SelectionEvent e) {
        }
 
-       /** {@inheritDoc} */
        @Override
        public Composite getLayoutComposite() {
                return container;
@@ -221,7 +223,6 @@ public abstract class AbstractEntityCollectionElement<ENTITY> extends
                                "Parent element should be IConversationEnabled");
        }
 
-       /** {@inheritDoc} */
        @Override
     public void update(CdmDataChangeMap changeEvents) {
        }
@@ -255,4 +256,26 @@ public abstract class AbstractEntityCollectionElement<ENTITY> extends
             warnForReferencedObjects.setVisible(isVisible);
         }
     }
+
+    @Override
+       public void setEnabled(boolean enabled) {
+               this.isEnabled = enabled;
+               if (btnRemove != null){
+                       btnRemove.setEnabled(enabled);
+               }
+               if (btnChooseEntity != null){
+                       btnChooseEntity.setEnabled(enabled);
+               }
+
+               for (ICdmFormElement element:this.getElements()){
+                       if (element instanceof IEnableableFormElement){
+                               ((IEnableableFormElement)element).setEnabled(enabled);
+                       }
+               }
+       }
+
+       @Override
+       public boolean isEnabled() {
+               return isEnabled;
+       }
 }