Merge branch 'release/5.28.0'
[taxeditor.git] / eu.etaxonomy.taxeditor.store / src / main / java / eu / etaxonomy / taxeditor / store / StoreUtil.java
index dec333f61b7072bf2cf09dc1d45a364dc181c0cf..75ef8d37f5f7f92dff3199ff29aed32ba23c2a80 100644 (file)
@@ -9,8 +9,6 @@
 
 package eu.etaxonomy.taxeditor.store;
 
-import java.util.UUID;
-
 import org.eclipse.core.commands.operations.IOperationHistory;
 import org.eclipse.core.commands.operations.IUndoContext;
 import org.eclipse.core.runtime.NullProgressMonitor;
@@ -24,6 +22,7 @@ import org.eclipse.ui.forms.widgets.ExpandableComposite;
 import org.eclipse.ui.forms.widgets.ScrolledForm;
 
 import eu.etaxonomy.cdm.api.facade.DerivedUnitFacade;
+import eu.etaxonomy.cdm.api.service.UpdateResult;
 import eu.etaxonomy.cdm.common.CdmUtils;
 import eu.etaxonomy.cdm.model.common.CdmBase;
 import eu.etaxonomy.cdm.model.term.TermNode;
@@ -42,22 +41,9 @@ import eu.etaxonomy.taxeditor.workbench.part.IE4SavablePart;
  *
  * @author n.hoffmann
  * @created 11.05.2009
- * @version 1.0
  */
 public class StoreUtil extends AbstractUtility {
 
-       /**
-        * <p>checktaxonExists</p>
-        *
-        * @param fromString a {@link java.util.UUID} object.
-        */
-       public static void checktaxonExists(UUID fromString) {
-//        if (CdmStore.getTaxonService().getTaxonByUuid(UUID.fromString(uuid)) == null) {
-//             logger.warn("Couldn't find taxon with UUID " + uuid);
-//             return null;
-//        }
-       }
-
        /**
         * If the object given is already a {@link CdmBase} then it is returned.<br>
         * If it is a kind of "container" for CDM objects then it is asked for its "responsible" CdmBase entity.<br>
@@ -82,21 +68,11 @@ public class StoreUtil extends AbstractUtility {
         throw new IllegalArgumentException("Object " + object.toString() + " is neither a CdmBase nor a CDM \"container\"");
        }
 
-       /**
-        * <p>getOperationHistory</p>
-        *
-        * @return a {@link org.eclipse.core.commands.operations.IOperationHistory} object.
-        */
        public static IOperationHistory getOperationHistory() {
                return TaxeditorStorePlugin.getDefault().getWorkbench().
                                        getOperationSupport().getOperationHistory();
        }
 
-       /**
-        * <p>setStatusLineManager</p>
-        *
-        * @param manager a {@link org.eclipse.jface.action.IStatusLineManager} object.
-        */
        public static void setStatusLineManager(IStatusLineManager manager) {
                statusLineManager = manager;
        }
@@ -104,31 +80,27 @@ public class StoreUtil extends AbstractUtility {
        public static void reflowParentScrolledForm(Composite composite, boolean flushCashes){
         ScrolledForm scrolledForm = null;
         Composite parent = composite;
-        while(parent!=null && !(parent instanceof ScrolledForm)){
+        while(parent!=null && !(parent instanceof ScrolledForm) && !parent.isDisposed()){
             parent = parent.getParent();
         }
-        scrolledForm = (ScrolledForm)parent;
+        if (parent instanceof ScrolledForm){
+            scrolledForm = (ScrolledForm)parent;
+        }else if ( parent != null && !parent.isDisposed() && parent.getParent() != null && !parent.getParent().isDisposed() &&parent.getParent() instanceof ScrolledForm ){
+            scrolledForm = (ScrolledForm)parent.getParent();
+        }
+
         if(scrolledForm!=null){
-            scrolledForm.reflow(flushCashes);
-            scrolledForm.redraw();
+            if (!scrolledForm.isDisposed()){
+                scrolledForm.reflow(flushCashes);
+                scrolledForm.redraw();
+            }
         }
     }
 
-
-       /**
-        * <p>getUndoContext</p>
-        *
-        * @return a {@link org.eclipse.core.commands.operations.IUndoContext} object.
-        */
        public static IUndoContext getUndoContext(){
                return IOperationHistory.GLOBAL_UNDO_CONTEXT;
        }
 
-       /**
-        * <p>getPluginId</p>
-        *
-        * @return a {@link java.lang.String} object.
-        */
        public static String getPluginId(){
                return TaxeditorStorePlugin.PLUGIN_ID;
        }
@@ -226,7 +198,12 @@ public class StoreUtil extends AbstractUtility {
         int style = ExpandableComposite.TWISTIE;
         String prefKey = getPrefKey(clazz, input);
         if(PreferencesUtil.contains(prefKey)){
-            style = PreferencesUtil.getStringValue(prefKey).equals(CdmSectionPart.EXPANDED)?style |= ExpandableComposite.EXPANDED:style;
+            String string = PreferencesUtil.getStringValue(prefKey, true);
+            if (string != null){
+                style = string.equals(CdmSectionPart.EXPANDED)?style |= ExpandableComposite.EXPANDED:style;
+            }else{
+                style = initiallyExpanded?style |= ExpandableComposite.EXPANDED:style;
+            }
         }
         else{
             style = initiallyExpanded?style |= ExpandableComposite.EXPANDED:style;
@@ -234,9 +211,9 @@ public class StoreUtil extends AbstractUtility {
         return style;
     }
 
-    public static String getPath(TermNode node){
+    public static String getPath(TermNode<?> node){
         String path = node.getTerm().getLabel();
-        TermNode parent = node.getParent();
+        TermNode<?> parent = node.getParent();
         while(parent != null && parent.getTerm()!=null){
             path = parent.getTerm().getLabel() + "/" + path;
             parent = parent.getParent();
@@ -254,4 +231,16 @@ public class StoreUtil extends AbstractUtility {
             text.addListener(SWT.Modify, listener);
         }
     }
+
+    public static Exception mergeUpdateResultExceptions(UpdateResult result) {
+        Exception t = new Exception();
+        if (result.getExceptions().size() >1){
+               for (Exception e:result.getExceptions()){
+                       t.addSuppressed(e);
+               }
+        }else {
+               t = result.getExceptions().iterator().next();
+        }
+        return t;
+    }
 }