ref #4302 Escape '&' in section titles
[taxeditor.git] / eu.etaxonomy.taxeditor.store / src / main / java / eu / etaxonomy / taxeditor / ui / section / AbstractCdmDetailSection.java
index 3d7efb919918129c259d8ffff6fd97bfecd453ec..ddb8f0d8006d1950a8d2e40f67ecb565a5458cda 100644 (file)
@@ -1,4 +1,3 @@
-// $Id$
 /**
  * Copyright (C) 2007 EDIT
  * European Distributed Institute of Taxonomy
@@ -10,6 +9,9 @@
 
 package eu.etaxonomy.taxeditor.ui.section;
 
+import java.util.ArrayList;
+import java.util.Collection;
+
 import org.eclipse.jface.action.ToolBarManager;
 import org.eclipse.jface.viewers.ISelectionProvider;
 import org.eclipse.swt.SWT;
@@ -21,10 +23,16 @@ 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.DefinedTermBase;
 import eu.etaxonomy.cdm.model.common.IdentifiableEntity;
-import eu.etaxonomy.taxeditor.ui.campanula.compatibility.ICdmFormElement;
+import eu.etaxonomy.cdm.model.common.Language;
+import eu.etaxonomy.cdm.model.description.TextData;
+import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase;
+import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
+import eu.etaxonomy.taxeditor.store.StoreUtil;
 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;
 
@@ -35,33 +43,13 @@ import eu.etaxonomy.taxeditor.ui.element.ISelectableElement;
  *
  * @author n.hoffmann
  * @created Feb 26, 2010
- * @version 1.0
  */
-public abstract class AbstractCdmDetailSection<ENTITY> extends AbstractFormSection<ENTITY> implements IEnableableFormElement, IExpansionListener {
-
-       protected ICdmDetailElement<ENTITY> detailElement;
-
-       /**
-        * <p>
-        * Constructor for AbstractCdmDetailSection.
-        * </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.
-        * @param <ENTITY>
-        *            a ENTITY object.
-        */
+public abstract class AbstractCdmDetailSection<ENTITY>
+                       extends AbstractFormSection<ENTITY>
+                       implements IEnableableFormElement, IExpansionListener {
+
+       protected AbstractCdmDetailElement<ENTITY> detailElement;
+
        public AbstractCdmDetailSection(CdmFormFactory formFactory,
                        ConversationHolder conversation, ICdmFormElement parentElement,
                        ISelectionProvider selectionProvider, int style) {
@@ -87,15 +75,15 @@ public abstract class AbstractCdmDetailSection<ENTITY> extends AbstractFormSecti
         }
        }
 
-       /**
-        * @param abstractCdmDetailSection
-        * @param definedTermClass
-        * @param null1
-        */
+       @Override
+       public void setText(String title) {
+           super.setText(StoreUtil.cleanTitleString(title));
+       }
+
        protected void createControlsByType(AbstractCdmDetailSection<ENTITY> formElement, Class<ENTITY> entityClass, int style) {
            TableWrapLayout layout = (TableWrapLayout) getLayoutComposite().getLayout();
            layout.topMargin = 10;
-           layout.numColumns = 2;
+           layout.numColumns = DEFAULT_NUM_COLUMNS;
 
            getLayoutComposite().setLayout(layout);
            if(entityClass==null){
@@ -106,36 +94,16 @@ public abstract class AbstractCdmDetailSection<ENTITY> extends AbstractFormSecti
            }
        }
 
-
-       /**
-        * <p>
-        * createControls
-        * </p>
-        *
-        * @param formElement
-        *            a
-        *            {@link eu.etaxonomy.taxeditor.ui.section.AbstractCdmDetailSection}
-        *            object.
-        * @param style
-        *            a int.
-        */
        protected void createControls(AbstractCdmDetailSection<ENTITY> formElement, int style) {
            createControlsByType(formElement, null, style);
        }
 
-       protected abstract ICdmDetailElement<ENTITY> createCdmDetailElement(AbstractCdmDetailSection<ENTITY> parentElement, int style);
+       protected abstract AbstractCdmDetailElement<ENTITY> createCdmDetailElement(AbstractCdmDetailSection<ENTITY> parentElement, int style);
 
-       protected ICdmDetailElement<ENTITY> createCdmDetailElementByType(AbstractCdmDetailSection<ENTITY> parentElement, Class<ENTITY> entityClass, int style){
+       protected AbstractCdmDetailElement<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();
 
        /** {@inheritDoc} */
@@ -151,13 +119,6 @@ public abstract class AbstractCdmDetailSection<ENTITY> extends AbstractFormSecti
                super.dispose();
        }
 
-       /*
-        * (non-Javadoc)
-        *
-        * @see
-        * eu.etaxonomy.taxeditor.forms.section.AbstractEditorFormSection#setBackground
-        * (org.eclipse.swt.graphics.Color)
-        */
        /** {@inheritDoc} */
        @Override
        public void setBackground(Color color) {
@@ -167,51 +128,53 @@ public abstract class AbstractCdmDetailSection<ENTITY> extends AbstractFormSecti
                super.setBackground(color);
        }
 
-       /**
-        * <p>
-        * setEntity
-        * </p>
-        *
-        * @param entity
-        *            a ENTITY object.
-        */
        @Override
        public void setEntity(ENTITY entity) {
                if (detailElement != null) {
                        detailElement.setEntity(entity);
+               Collection<Object> except = new ArrayList<Object>();
+               for(ICdmFormElement formElement:detailElement.getElements()){
+                   if(formElement instanceof IEnableableFormElement && !((IEnableableFormElement) formElement).isEnabled()){
+                       except.add(formElement);
+                   }
+               }
+                       detailElement.setEnabled(isEnabled(), except);
                }
                super.setEntity(entity);
                setSectionTitle();
                layout();
+
        }
 
-       /**
-        * <p>
-        * setSectionTitle
-        * </p>
-        */
        protected void setSectionTitle() {
                String title = "";
-               if (getEntity() != null && (getEntity() instanceof IdentifiableEntity)) {
-                       title = ": " + ((IdentifiableEntity) getEntity()).getTitleCache();
+               String label = "";
+               if (getEntity() != null && (getEntity() instanceof IdentifiableEntity) && !(getEntity() instanceof SpecimenOrObservationBase)) {
+                       if (getEntity() instanceof DefinedTermBase<?> ){
+                               label = ((DefinedTermBase<?>)getEntity()).getLabel(PreferencesUtil.getGlobalLanguage());
+                               if (label == null){
+                                       label = ((DefinedTermBase<?>)getEntity()).getLabel();
+                               }
+
+                       } else if (getEntity() instanceof TextData){
+                               label = ((TextData)getEntity()).getLanguageText(PreferencesUtil.getGlobalLanguage()).getText();
+                               if (label == null){
+                                       label = ((TextData)getEntity()).getLanguageText(Language.DEFAULT()).getText();
+                               }
+                       } else{
+                               label =((IdentifiableEntity) getEntity()).getTitleCache();
+                       }
+                       title = ": " + label;
                }
                this.setText(String.format("%s%s", getHeading(), title));
                setTextClient(createToolbar());
        }
 
-       /**
-        * @return
-        */
        protected Control createToolbar() {
                ToolBarManager toolBarManager = new ToolBarManager(SWT.FLAT);
                return toolBarManager.createControl(this);
        }
 
-       /**
-        * <p>
-        * updateTitle
-        * </p>
-        */
        public void updateTitle() {
                if (!isDisposed()) {
                        setSectionTitle();
@@ -223,6 +186,7 @@ public abstract class AbstractCdmDetailSection<ENTITY> extends AbstractFormSecti
        @Override
     public void setIrrelevant(boolean irrelevant) {
                if (detailElement != null) {
+
                        detailElement.setIrrelevant(irrelevant);
                }
        }