- added label to EmptyElement
authorPatric Plitzner <p.plitzner@bgbm.org>
Mon, 8 Sep 2014 13:34:14 +0000 (13:34 +0000)
committerPatric Plitzner <p.plitzner@bgbm.org>
Mon, 8 Sep 2014 13:34:14 +0000 (13:34 +0000)
 - added EmptyElement to NonViralNameDetailSection if taxon.getName() is null (fixes #4221)

eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/element/CdmFormFactory.java
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/EmptyElement.java
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/name/NonViralNameDetailElement.java
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/occurrence/EmptySection.java

index d4c2870cd2d4d671cdf7de58da120f308a43d2dd..6cb8a02a346cafc51eeeb32c35052c4351d7e754 100644 (file)
@@ -1442,8 +1442,8 @@ public class CdmFormFactory extends FormToolkit {
      *            object.
      * @return a {@link eu.etaxonomy.taxeditor.ui.section.EmptyElement} object.
      */
-    public EmptyElement createEmptyElement(ICdmFormElement parentElement) {
-        EmptyElement element = new EmptyElement(this, parentElement, null, SWT.NULL);
+    public EmptyElement createEmptyElement(ICdmFormElement parentElement, String emptyText) {
+        EmptyElement element = new EmptyElement(this, parentElement, emptyText, SWT.NULL);
         adapt(element);
         parentElement.addElement(element);
         return element;
index c36aa92a3cb5dff80f0a964d778ead9c268e0527..f2a1fcee5be7d7dc8b28f118928917919e85ee42 100644 (file)
 
 package eu.etaxonomy.taxeditor.ui.section;
 
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.widgets.Label;
-
-import eu.etaxonomy.cdm.model.common.VersionableEntity;
 import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
 import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;
 
@@ -34,9 +30,11 @@ public class EmptyElement extends AbstractCdmDetailElement{
         * @param parentElement a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement} object.
         * @param entity a {@link eu.etaxonomy.cdm.model.common.VersionableEntity} object.
         */
-       public EmptyElement(CdmFormFactory toolkit, ICdmFormElement parentElement, VersionableEntity entity, int style) {
+       public EmptyElement(CdmFormFactory toolkit, ICdmFormElement parentElement, String emptyText, int style) {
                super(toolkit, parentElement);
-               addControl(new Label(getLayoutComposite(), SWT.HORIZONTAL));
+               if(emptyText!=null){
+                   formFactory.createLabel(parentElement, emptyText);
+               }
        }
 
        /* (non-Javadoc)
@@ -44,8 +42,7 @@ public class EmptyElement extends AbstractCdmDetailElement{
         */
        @Override
        protected void createControls(ICdmFormElement formElement, Object entity, int style) {
-           // TODO Auto-generated method stub
-
+           //empty
        }
 
     /* (non-Javadoc)
index d75b3698af4acd72f44598fd999bfee39b63471b..d913442dbe169b9969b31c31ad15e9a16dbd782f 100644 (file)
@@ -70,34 +70,40 @@ public class NonViralNameDetailElement extends
        /** {@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());
-               
-        //TODO RL
-               if(PreferencesUtil.getPreferenceStore().getBoolean(IPreferenceKeys.IS_RL)){
-               toggleable_cache.setVisible(false);
-               combo_nomenclaturalCode.setVisible(false);
-        }
-        
-        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);
-        }       
+           //name can be null in rare cases. Temporary solution for #4221. May be obsolete when
+           //#4393 (Make changing name of a taxon possible in details view) is implemented.
+           if(entity==null){
+               formFactory.createEmptyElement(formElement, "No name associated with this taxon.");
+           }
+           else {
+               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);
+               }
+
+               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} */
@@ -107,19 +113,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);
-               if (section_name!=null) section_name.setEntity(entity);
-               if (section_author!=null) section_author.setEntity(entity);
-               if (section_hybrid!=null) 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} */
index 1bc4f703f4bdf766644d530d4eb6450378d054aa..df4d63b904891f0a85e5a6723b6415fb60e25aa4 100644 (file)
@@ -45,6 +45,6 @@ public class EmptySection extends AbstractCdmDetailSection<Object> {
      */
     @Override
     protected AbstractCdmDetailElement<Object> createCdmDetailElement(AbstractCdmDetailSection<Object> parentElement, int style) {
-        return formFactory.createEmptyElement(parentElement);
+        return formFactory.createEmptyElement(parentElement, null);
     }
 }