fixing #5341 and colouring for cache relevant fields #4915 and #4944
[taxeditor.git] / eu.etaxonomy.taxeditor.store / src / main / java / eu / etaxonomy / taxeditor / ui / section / name / NonViralNameDetailElement.java
index 3979e7021f99c4a7e6b15107d53481e4d5074f5a..6b82772415c8f007691f004b3215731a67af233d 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.
  */
@@ -12,22 +12,21 @@ package eu.etaxonomy.taxeditor.ui.section.name;
 
 import java.util.Arrays;
 
-import org.eclipse.ui.forms.widgets.Section;
+import org.eclipse.ui.forms.widgets.ExpandableComposite;
 
 import eu.etaxonomy.cdm.model.name.NomenclaturalCode;
 import eu.etaxonomy.cdm.model.name.NonViralName;
+import eu.etaxonomy.taxeditor.preference.IPreferenceKeys;
+import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
 import eu.etaxonomy.taxeditor.ui.combo.EnumComboElement;
-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.element.CdmFormFactory;
+import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;
+import eu.etaxonomy.taxeditor.ui.element.LayoutConstants;
+import eu.etaxonomy.taxeditor.ui.element.LsidWithExceptionLabelElement;
 import eu.etaxonomy.taxeditor.ui.section.AbstractCdmDetailSection;
 import eu.etaxonomy.taxeditor.ui.section.AbstractIdentifiableEntityDetailElement;
 
 /**
- * <p>
- * NonViralNameDetailElement class.
- * </p>
- * 
  * @author n.hoffmann
  * @created May 20, 2010
  * @version 1.0
@@ -39,67 +38,46 @@ public class NonViralNameDetailElement extends
        private AuthorshipDetailSection section_author;
        private EnumComboElement<NomenclaturalCode> combo_nomenclaturalCode;
        private HybridDetailSection section_hybrid;
+       private LsidWithExceptionLabelElement textLsid;
 
-       /**
-        * <p>
-        * Constructor for NonViralNameDetailElement.
-        * </p>
-        * 
-        * @param formFactory
-        *            a {@link eu.etaxonomy.taxeditor.ui.forms.CdmFormFactory}
-        *            object.
-        * @param formElement
-        *            a {@link eu.etaxonomy.taxeditor.ui.forms.ICdmFormElement}
-        *            object.
-        */
        public NonViralNameDetailElement(CdmFormFactory formFactory,
                        ICdmFormElement formElement) {
                super(formFactory, formElement);
        }
 
-       /*
-        * (non-Javadoc)
-        * 
-        * @see
-        * eu.etaxonomy.taxeditor.section.AbstractCdmDetailElement#createControls
-        * (eu.etaxonomy.taxeditor.section.AbstractCdmDetailElement,
-        * eu.etaxonomy.cdm.model.common.AnnotatableEntity, int)
-        */
        /** {@inheritDoc} */
        @Override
-       protected void createControls(ICdmFormElement formElement,
-                       final NonViralName entity, int style) {
-
-               toggleable_cache = formFactory.createToggleableTextField(formElement,
-                               "Cache", entity.getTitleCache(), entity.isProtectedTitleCache()
-                                               || entity.isProtectedFullTitleCache(), style);
-
-               combo_nomenclaturalCode = formFactory
-                               .createEnumComboElement(NomenclaturalCode.class,
-                                               formElement, style);
-               combo_nomenclaturalCode.setSelection(entity.getNomenclaturalCode());
-
-               section_name = (NameDetailSection) formFactory.createCdmDetailSection(
-                               DetailType.SCIENTIFICNAME, getConversationHolder(),
-                               formElement, null, Section.TWISTIE | Section.EXPANDED);
-               section_name.setLayoutData(CdmFormFactory.FILL_HORIZONTALLY(2, 1));
-               addControl(section_name);
-               addElement(section_name);
-               section_author = (AuthorshipDetailSection) formFactory
-                               .createCdmDetailSection(DetailType.AUTHORSHIP,
-                                               getConversationHolder(), formElement, null,
-                                               Section.TWISTIE | Section.EXPANDED);
-               section_author.setLayoutData(CdmFormFactory.FILL_HORIZONTALLY(2, 1));
-               addControl(section_author);
-               addElement(section_author);
-               
-               section_hybrid = (HybridDetailSection) formFactory.createCdmDetailSection(DetailType.HYBRID, 
-                                               getConversationHolder(), formElement, null, 
-                                               Section.TWISTIE);
-               section_hybrid.setLayoutData(CdmFormFactory.FILL_HORIZONTALLY(2, 1));
-               addControl(section_hybrid);
-               addElement(section_hybrid);
-       }
+    protected void createControls(ICdmFormElement formElement, final NonViralName entity, int style) {
+           toggleable_cache = formFactory.createToggleableTextField(formElement, "Cache", entity.getTitleCache(), entity.isProtectedTitleCache() || entity.isProtectedFullTitleCache(), style);
+
+           combo_nomenclaturalCode = formFactory.createEnumComboElement(NomenclaturalCode.class, formElement, style);
+           combo_nomenclaturalCode.setSelection(entity.getNomenclaturalCode());
+
+           //TODO RL
+           if(PreferencesUtil.getPreferenceStore().getBoolean(IPreferenceKeys.IS_RL)){
+               toggleable_cache.setVisible(false);
+               combo_nomenclaturalCode.setVisible(false);
+           }
+           textLsid = formFactory.createLsidWithExceptionLabelElement(formElement, "Lsid", entity.getLsid(), style);
+           section_name = formFactory.createNameDetailSection(getConversationHolder(), formElement, null, ExpandableComposite.TWISTIE | ExpandableComposite.EXPANDED);
+           section_name.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
+           addControl(section_name);
+           addElement(section_name);
+           section_author = formFactory.createAuthorshipDetailSection(getConversationHolder(), formElement, null, ExpandableComposite.TWISTIE | ExpandableComposite.EXPANDED);
+           section_author.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
+           addControl(section_author);
+           addElement(section_author);
+
+           //TODO RL
+           if(!PreferencesUtil.getPreferenceStore().getBoolean(IPreferenceKeys.IS_RL)){
+               section_hybrid = formFactory.createHybridDetailSection(getConversationHolder(), formElement, null, ExpandableComposite.TWISTIE);
+               section_hybrid.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
+               addControl(section_hybrid);
+               addElement(section_hybrid);
+           }
+
+
+    }
 
        /** {@inheritDoc} */
        @Override
@@ -108,19 +86,29 @@ public class NonViralNameDetailElement extends
 
                // disable nomenclatural code, because changing of nom.code is not
                // implemented on library side
-               combo_nomenclaturalCode.setEnabled(false);
+               if(combo_nomenclaturalCode!=null){
+                   combo_nomenclaturalCode.setEnabled(false);
+               }
 
-               setIrrelevant(toggleable_cache.getState(),
-                               Arrays.asList(new Object[] { toggleable_cache }));
+               if(toggleable_cache!=null){
+                   setIrrelevant(toggleable_cache.getState(),
+                           Arrays.asList(new Object[] { toggleable_cache }));
+               }
        }
 
        /** {@inheritDoc} */
        @Override
        public void setEntity(NonViralName entity) {
                super.setEntity(entity);
-               section_name.setEntity(entity);
-               section_author.setEntity(entity);
-               section_hybrid.setEntity(entity);
+               if (section_name!=null) {
+            section_name.setEntity(entity);
+        }
+               if (section_author!=null) {
+            section_author.setEntity(entity);
+        }
+               if (section_hybrid!=null) {
+            section_hybrid.setEntity(entity);
+        }
        }
 
        /** {@inheritDoc} */
@@ -141,13 +129,6 @@ public class NonViralNameDetailElement extends
                }
        }
 
-       /*
-        * (non-Javadoc)
-        * 
-        * @see
-        * eu.etaxonomy.taxeditor.section.AbstractCdmDetailElement#handleEvent(java
-        * .lang.Object)
-        */
        /** {@inheritDoc} */
        @Override
        public void handleEvent(Object eventSource) {
@@ -158,8 +139,9 @@ public class NonViralNameDetailElement extends
                        // initiating the free text name editor
                        getEntity().setProtectedFullTitleCache(false);
                } else if (eventSource == section_name || eventSource == section_author) {
-                       if (getParentElement() instanceof AbstractCdmDetailSection)
-                               ((AbstractCdmDetailSection) getParentElement()).updateTitle();
+                       if (getParentElement() instanceof AbstractCdmDetailSection) {
+                ((AbstractCdmDetailSection) getParentElement()).updateTitle();
+            }
                        if (!toggleable_cache.getState()) {
                                toggleable_cache.setText(getEntity().getTitleCache());
                        }
@@ -168,5 +150,16 @@ public class NonViralNameDetailElement extends
                        section_name.setEntity(getEntity());
                        getLayoutComposite().layout();
                }
+               else if(eventSource==textLsid){
+                   getEntity().setLsid(textLsid.parseText());
+               }
        }
+       @Override
+       protected void handleToggleableCacheField() {
+        boolean pushedState = toggleable_cache.getState();
+
+        getEntity().setTitleCache(toggleable_cache.getText(), pushedState);
+        setIrrelevant(pushedState, Arrays.asList(new Object[] { toggleable_cache, textLsid }));
+        updateToggleableCacheField();
+    }
 }