Merge branch 'release/5.8.0'
[taxeditor.git] / eu.etaxonomy.taxeditor.store / src / main / java / eu / etaxonomy / taxeditor / store / StoreUtil.java
index 1f8c7d385b974693a2107feebb936351e3dfe7ba..08a86aa30d1bec14f04626f55ad181ce4b9d0890 100644 (file)
@@ -17,6 +17,7 @@ import org.eclipse.core.runtime.NullProgressMonitor;
 import org.eclipse.jface.action.IStatusLineManager;
 import org.eclipse.jface.dialogs.MessageDialog;
 import org.eclipse.swt.widgets.Composite;
+import org.eclipse.ui.forms.widgets.ExpandableComposite;
 import org.eclipse.ui.forms.widgets.ScrolledForm;
 
 import eu.etaxonomy.cdm.api.facade.DerivedUnitFacade;
@@ -25,8 +26,10 @@ import eu.etaxonomy.taxeditor.l10n.Messages;
 import eu.etaxonomy.taxeditor.model.AbstractUtility;
 import eu.etaxonomy.taxeditor.model.FeatureNodeContainer;
 import eu.etaxonomy.taxeditor.model.MessagingUtils;
+import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
 import eu.etaxonomy.taxeditor.store.internal.TaxeditorStorePlugin;
 import eu.etaxonomy.taxeditor.ui.element.AbstractFormSection;
+import eu.etaxonomy.taxeditor.view.detail.CdmSectionPart;
 import eu.etaxonomy.taxeditor.workbench.part.IE4SavablePart;
 
 /**
@@ -139,8 +142,8 @@ public class StoreUtil extends AbstractUtility {
            return title.replace("&", "&&");
        }
 
-    public static String getPrefKey(Class<? extends AbstractFormSection> sectionClass, Object entity) {
-        return sectionClass.getCanonicalName()+";"+entity.getClass().getCanonicalName();
+    public static String getPrefKey(Class<? extends AbstractFormSection> sectionClass, String entity) {
+        return sectionClass.getCanonicalName()+";"+entity;
     }
 
     /**
@@ -209,4 +212,20 @@ public class StoreUtil extends AbstractUtility {
         }
         return string1.compareTo(string2);
     }
+
+    public static int getSectionStyle(Class<? extends AbstractFormSection> clazz, String input){
+        return StoreUtil.getSectionStyle(clazz, input, false);
+    }
+
+    public static int getSectionStyle(Class<? extends AbstractFormSection> clazz, String input, boolean initiallyExpanded){
+        int style = ExpandableComposite.TWISTIE;
+        String prefKey = getPrefKey(clazz, input);
+        if(PreferencesUtil.contains(prefKey)){
+            style = PreferencesUtil.getStringValue(prefKey).equals(CdmSectionPart.EXPANDED)?style |= ExpandableComposite.EXPANDED:style;
+        }
+        else{
+            style = initiallyExpanded?style |= ExpandableComposite.EXPANDED:style;
+        }
+        return style;
+    }
 }