Only show "Change Type" when more than one type is available #5565
authorPatrick Plitzner <p.plitzner@bgbm.org>
Tue, 29 Mar 2016 13:03:26 +0000 (15:03 +0200)
committerPatrick Plitzner <p.plitzner@bgbm.org>
Tue, 29 Mar 2016 13:03:26 +0000 (15:03 +0200)
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/description/DescriptionElementDetailSection.java

index 48131bf00dcccf6103067e67d16490a530ac1696..c66e67a93d16bdbd1e485cfb80d823509ff83bbf 100644 (file)
@@ -18,6 +18,7 @@ import org.eclipse.swt.widgets.Control;
 
 import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
 import eu.etaxonomy.cdm.model.description.DescriptionElementBase;
 
 import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
 import eu.etaxonomy.cdm.model.description.DescriptionElementBase;
+import eu.etaxonomy.cdm.model.description.Feature;
 import eu.etaxonomy.cdm.model.description.TextData;
 import eu.etaxonomy.taxeditor.model.MessagingUtils;
 import eu.etaxonomy.taxeditor.store.CdmStore;
 import eu.etaxonomy.cdm.model.description.TextData;
 import eu.etaxonomy.taxeditor.model.MessagingUtils;
 import eu.etaxonomy.taxeditor.store.CdmStore;
@@ -55,13 +56,10 @@ public class DescriptionElementDetailSection extends
 
        @Override
     protected Control createToolbar() {
 
        @Override
     protected Control createToolbar() {
-               if(! hasSpecificElement()){
-                       return null;
-               }
 
                ToolBarManager toolBarManager = new ToolBarManager(SWT.FLAT);
 
 
                ToolBarManager toolBarManager = new ToolBarManager(SWT.FLAT);
 
-               final String destinationString = (getEntity() instanceof TextData) ? "the specific element" : "free text";
+               final String destinationString = (getEntity().isInstanceOf(TextData.class)) ? "the specific element" : "free text";
 
                final String label = "Change to " + destinationString;
 
 
                final String label = "Change to " + destinationString;
 
@@ -107,16 +105,23 @@ public class DescriptionElementDetailSection extends
        @Override
        protected void setSectionTitle() {
                this.setText(getHeading() + ": " + getEntity().getFeature().getLabel(CdmStore.getDefaultLanguage()));
        @Override
        protected void setSectionTitle() {
                this.setText(getHeading() + ": " + getEntity().getFeature().getLabel(CdmStore.getDefaultLanguage()));
-               setTextClient(createToolbar());
+
+        if(IsMoreThanOneTypeSupported()){
+            setTextClient(createToolbar());
+        }
        }
 
        }
 
-       private boolean hasSpecificElement(){
-               return  getEntity().getFeature().isSupportsCategoricalData()
-                               || getEntity().getFeature().isSupportsCommonTaxonName()
-                               || getEntity().getFeature().isSupportsDistribution()
-                               || getEntity().getFeature().isSupportsIndividualAssociation()
-                               || getEntity().getFeature().isSupportsQuantitativeData()
-                               || getEntity().getFeature().isSupportsTaxonInteraction();
+       private boolean IsMoreThanOneTypeSupported(){
+           int count = 0;
+           Feature feature = getEntity().getFeature();
+           if(feature.isSupportsCategoricalData()){count++;}
+           if(feature.isSupportsCommonTaxonName()){count++;}
+           if(feature.isSupportsDistribution()){count++;}
+           if(feature.isSupportsIndividualAssociation()){count++;}
+           if(feature.isSupportsQuantitativeData()){count++;}
+           if(feature.isSupportsTaxonInteraction()){count++;}
+           if(feature.isSupportsTextData()){count++;}
+           return count > 1;
        }
 
        /* (non-Javadoc)
        }
 
        /* (non-Javadoc)