- added util method to get for getting a CDM entity (used in authenication/permissio...
[taxeditor.git] / eu.etaxonomy.taxeditor.store / src / main / java / eu / etaxonomy / taxeditor / store / StoreUtil.java
index 0f30b2a098f466eebec6653911021176f83eaf68..afe513e95d8157e63d372d3325e94034eed59144 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.
 */
@@ -18,6 +18,8 @@ import org.eclipse.jface.action.IStatusLineManager;
 import org.eclipse.ui.IEditorInput;
 import org.eclipse.ui.IEditorPart;
 
+import eu.etaxonomy.cdm.api.facade.DerivedUnitFacade;
+import eu.etaxonomy.cdm.model.common.CdmBase;
 import eu.etaxonomy.taxeditor.model.AbstractUtility;
 import eu.etaxonomy.taxeditor.store.internal.TaxeditorStorePlugin;
 
@@ -41,7 +43,26 @@ public class StoreUtil extends AbstractUtility {
 //             return null;
 //        }
        }
-       
+
+       /**
+        * If the object given is already a {@link CdmBase} then it is returned.<br>
+        * If it is a facade then it is asked for its "responsible" CdmBase entity.<br>
+        * Otherwise an exception is thrown.
+        * @param object the object to test for CdmBase
+        * @return a CdmBase object
+        * @throws IllegalArgumentException if the tested object is neither a CdmBase nor a facade
+        */
+       public static CdmBase getCdmEntity(Object object){
+        // TODO temporary solution for ticket #????
+        if(object instanceof DerivedUnitFacade){
+            return ((DerivedUnitFacade)object).getBaseUnit();
+        }
+        else if(object instanceof CdmBase){
+            return (CdmBase) object;
+        }
+        throw new IllegalArgumentException("Object is neither a CdmBase nor an EntityFacade");
+       }
+
        /**
         * <p>getOperationHistory</p>
         *
@@ -51,7 +72,7 @@ public class StoreUtil extends AbstractUtility {
                return TaxeditorStorePlugin.getDefault().getWorkbench().
                                        getOperationSupport().getOperationHistory();
        }
-       
+
        /**
         * <p>setStatusLineManager</p>
         *
@@ -60,7 +81,7 @@ public class StoreUtil extends AbstractUtility {
        public static void setStatusLineManager(IStatusLineManager manager) {
                statusLineManager = manager;
        }
-       
+
 
        /**
         * <p>getUndoContext</p>
@@ -70,7 +91,7 @@ public class StoreUtil extends AbstractUtility {
        public static IUndoContext getUndoContext(){
                return IOperationHistory.GLOBAL_UNDO_CONTEXT;
        }
-       
+
        /**
         * <p>getPluginId</p>
         *
@@ -81,7 +102,7 @@ public class StoreUtil extends AbstractUtility {
        }
 
        /**
-        * 
+        *
         * @return
         */
        public static IEditorInput getActiveEditorInput() {