Merge branch 'release/5.28.0'
[taxeditor.git] / eu.etaxonomy.taxeditor.store / src / main / java / eu / etaxonomy / taxeditor / ui / section / description / DescriptionElementDetailElement.java
index 5591416ff5177d31814e37bdaafd3efeaf4affc0..9a044ea82655010d0b39d73cd07cedaf991f4ebe 100644 (file)
@@ -1,18 +1,25 @@
-// $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.
 */
 
 package eu.etaxonomy.taxeditor.ui.section.description;
 
+import java.util.ArrayList;
+import java.util.Collection;
+
 import eu.etaxonomy.cdm.model.description.DescriptionElementBase;
+import eu.etaxonomy.cdm.model.description.Distribution;
+import eu.etaxonomy.taxeditor.editor.IDistributionEditorPart;
+import eu.etaxonomy.taxeditor.model.AbstractUtility;
+import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
 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.section.AbstractCdmDetailElement;
 
 /**
@@ -36,16 +43,34 @@ public class DescriptionElementDetailElement extends
                        ICdmFormElement formElement, int style) {
                super(cdmFormFactory, formElement);
        }
-       
+
        /** {@inheritDoc} */
        @Override
        protected void createControls(ICdmFormElement formElement, DescriptionElementBase entity, int style) {
-               formFactory.createDetailedDescriptionDetailElement(formElement, entity, style);
-       }
        
+               setEnabled(!((getEntity().getInDescription() != null && (getEntity().getInDescription().isComputed() || getEntity().getInDescription().isCloneForSource())&& PreferencesUtil.isComputedDesciptionHandlingDisabled()) || (getEntity() instanceof Distribution && AbstractUtility.getActivePart() instanceof IDistributionEditorPart)));
+               formFactory.createDetailedDescriptionDetailElement(formElement, entity, style, isEnabled());
+       }
+
        /** {@inheritDoc} */
        @Override
        public void handleEvent(Object eventSource) {
-               
+
        }
+
+       @Override
+    protected void updateControlStates(){
+        Collection<Object> except = new ArrayList<Object>();
+        for(ICdmFormElement formElement:getElements()){
+            if(formElement instanceof IEnableableFormElement && !((IEnableableFormElement) formElement).isEnabled()){
+                except.add(formElement);
+            }
+        }
+        if ((getEntity().getInDescription() != null && (getEntity().getInDescription().isComputed() || getEntity().getInDescription().isCloneForSource())&& PreferencesUtil.isComputedDesciptionHandlingDisabled()) || (getEntity() instanceof Distribution && AbstractUtility.getActivePart() instanceof IDistributionEditorPart)){
+            enabled = false;
+         }else{
+            enabled = true;
+        }
+        setEnabled(enabled, except);
+    }
 }