- added util method to get for getting a CDM entity (used in authenication/permissio...
authorPatric Plitzner <p.plitzner@bgbm.org>
Wed, 5 Mar 2014 07:43:08 +0000 (07:43 +0000)
committerPatric Plitzner <p.plitzner@bgbm.org>
Wed, 5 Mar 2014 07:43:08 +0000 (07:43 +0000)
 - made use of this method where the type of the parameter was too general (like object)
 - made getBaseUnit() of DerivedUnitFacade public

eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/TaxonNodeLabelProvider.java
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/security/PermissionPropertyTester.java
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/store/StoreUtil.java
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/AbstractCdmDetailElement.java
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/AbstractEntityCollectionSection.java
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/AbstractIdentifiableEntityDetailElement.java
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/selection/EntitySelectionElement.java

index d4b243b01ccd37d1e83ac032d969e248ebc95704..6a6189dfb13b655fc671e7ae1ab2cc40a9f244cd 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.
 */
@@ -21,7 +21,6 @@ import org.eclipse.ui.navigator.IDescriptionProvider;
 import org.hibernate.LazyInitializationException;
 
 import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
-import eu.etaxonomy.cdm.model.common.CdmBase;
 import eu.etaxonomy.cdm.model.common.IIdentifiableEntity;
 import eu.etaxonomy.cdm.model.taxon.Taxon;
 import eu.etaxonomy.cdm.model.taxon.TaxonNode;
@@ -38,12 +37,12 @@ import eu.etaxonomy.taxeditor.store.StoreUtil;
  * @created 04.06.2009
  * @version 1.0
  */
-public class TaxonNodeLabelProvider extends ColumnLabelProvider 
+public class TaxonNodeLabelProvider extends ColumnLabelProvider
                implements ILabelProvider, IDescriptionProvider, IStyledLabelProvider {
-       
+
 
        private Styler notGrantedStyler = null;
-       
+
        /** {@inheritDoc} */
        @Override
        public Image getImage(Object element) {
@@ -55,14 +54,14 @@ public class TaxonNodeLabelProvider extends ColumnLabelProvider
        public String getText(Object element) {
                if (element instanceof TaxonNode){
                        TaxonNode taxonNode = (TaxonNode) HibernateProxyHelper.deproxy(element);
-                       
+
                        try{
                                Taxon taxon = (Taxon) HibernateProxyHelper.deproxy(taxonNode.getTaxon());
                                if(taxon == null){
                                        NavigationUtil.error(getClass(), "The taxon node does not have a taxon attached to it. Please check your import. TaxonNode: " + element, null);
 //                                     throw new RuntimeException("The data your are trying to view is corrupt. Please check your import.");
                                }else{
-                                       try{                                    
+                                       try{
                                                return taxon.getName() != null ? ((IIdentifiableEntity) HibernateProxyHelper.deproxy(taxon.getName())).getTitleCache() : new String();
                                        }catch(Exception e){
                                                NavigationUtil.error(getClass(), e);
@@ -71,16 +70,17 @@ public class TaxonNodeLabelProvider extends ColumnLabelProvider
                        }catch (LazyInitializationException e){
                                NavigationUtil.error(getClass(), e);
                        }
-                       
+
                }
                return new String();
        }
-       
+
        /* (non-Javadoc)
         * @see org.eclipse.ui.navigator.IDescriptionProvider#getDescription(java.lang.Object)
         */
        /** {@inheritDoc} */
-       public String getDescription(Object anElement) {
+       @Override
+    public String getDescription(Object anElement) {
                if (anElement instanceof TaxonNode) {
                        Taxon data = ((TaxonNode) anElement).getTaxon();
                        return "Taxon: " + data.getTitleCache(); //$NON-NLS-1$
@@ -92,16 +92,17 @@ public class TaxonNodeLabelProvider extends ColumnLabelProvider
         * @see org.eclipse.jface.viewers.DelegatingStyledCellLabelProvider.IStyledLabelProvider#getStyledText(java.lang.Object)
         */
        /** {@inheritDoc} */
-       public StyledString getStyledText(Object element) {
+       @Override
+    public StyledString getStyledText(Object element) {
                // determine style base on  user grants
                Styler styler = null;
-               if(!CdmStore.currentAuthentiationHasPermission((CdmBase)element, RequiredPermissions.TAXONNODE_EDIT)){
+               if(!CdmStore.currentAuthentiationHasPermission(StoreUtil.getCdmEntity(element), RequiredPermissions.TAXONNODE_EDIT)){
                        styler = getNotGrantedStyler();
                }
                return new StyledString(getText(element), styler);
-               
+
        }
-       
+
        /**
         * @return
         */
index ca9a014dcfc46fde753c814077675ddbefa4ff53..7be4c8720211a93f60e3711563723231a8234d52 100644 (file)
@@ -10,17 +10,18 @@ import eu.etaxonomy.cdm.model.common.CdmBase;
 import eu.etaxonomy.cdm.persistence.hibernate.permission.CRUD;
 import eu.etaxonomy.cdm.persistence.hibernate.permission.CdmAuthority;
 import eu.etaxonomy.taxeditor.store.CdmStore;
+import eu.etaxonomy.taxeditor.store.StoreUtil;
 
 /**
  * Checks if the currently authenticated user for {@link CdmAuthority} assignments.
- * 
+ *
  * @author andreas
  *
  */
 public class PermissionPropertyTester extends PropertyTester {
-       
+
        private static final String HAS_PERMISSIONS = "hasPermissions";
-       
+
        private static final String CREATE = CRUD.CREATE.toString();
        private static final String READ = CRUD.READ.toString();
        private static final String UPDATE = CRUD.UPDATE.toString();
@@ -29,21 +30,21 @@ public class PermissionPropertyTester extends PropertyTester {
        @Override
        public boolean test(Object receiver, String property, Object[] args,
                        Object expectedValue) {
-               
+
                if(property.equals(HAS_PERMISSIONS)){
                        return checkHasPermission(receiver, args);
                }
-                       
+
                return false;
        }
 
        private boolean checkHasPermission(Object receiver, Object[] args) {
                EnumSet<CRUD> crudSet = crudSetFromArgs(args);
 
-               
+
                List<Object> selectedElements = ((IStructuredSelection) receiver).toList();
                for(Object selectedElement : selectedElements){
-                       if(selectedElement instanceof CdmBase && ! CdmStore.currentAuthentiationHasPermission((CdmBase) selectedElement, crudSet)){
+                       if(selectedElement instanceof CdmBase && ! CdmStore.currentAuthentiationHasPermission(StoreUtil.getCdmEntity(selectedElement), crudSet)){
                                return false;
                        }
                }
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() {
index 96631a3e2688fa09151c611efbe4bf6a331efa6e..e75872c9b67a959fe94efc5ee85c122597f05cae 100644 (file)
@@ -19,13 +19,13 @@ import org.eclipse.swt.widgets.Composite;
 
 import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
 import eu.etaxonomy.cdm.api.conversation.IConversationEnabled;
-import eu.etaxonomy.cdm.model.common.CdmBase;
 import eu.etaxonomy.cdm.model.name.TaxonNameBase;
 import eu.etaxonomy.cdm.model.taxon.TaxonBase;
 import eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap;
 import eu.etaxonomy.cdm.persistence.hibernate.permission.CRUD;
 import eu.etaxonomy.taxeditor.model.AbstractUtility;
 import eu.etaxonomy.taxeditor.store.CdmStore;
+import eu.etaxonomy.taxeditor.store.StoreUtil;
 import eu.etaxonomy.taxeditor.ui.element.AbstractCdmFormElement;
 import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
 import eu.etaxonomy.taxeditor.ui.element.CdmPropertyChangeEvent;
@@ -106,8 +106,8 @@ public abstract class AbstractCdmDetailElement<T> extends AbstractCdmFormElement
                removeElements();
                createControls(this, entity, SWT.WRAP);
                getLayoutComposite().layout();
-               
-               setEnabled(CdmStore.currentAuthentiationHasPermission((CdmBase) getEntity(), UPDATE));
+
+               setEnabled(getEntity() != null && CdmStore.currentAuthentiationHasPermission(StoreUtil.getCdmEntity(getEntity()), UPDATE));
        }
 
        /*
index c3a11387a24af8a85d8e47c60b7fa311fb95a3f7..92cd0bf2d94cfe0eaa54e1bc53b206775edf8266 100644 (file)
@@ -29,7 +29,6 @@ import org.eclipse.ui.forms.widgets.ExpandableComposite;
 
 import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
 import eu.etaxonomy.cdm.common.CdmUtils;
-import eu.etaxonomy.cdm.model.common.CdmBase;
 import eu.etaxonomy.cdm.persistence.hibernate.permission.CRUD;
 import eu.etaxonomy.taxeditor.model.AbstractUtility;
 import eu.etaxonomy.taxeditor.model.ImageResources;
@@ -38,6 +37,7 @@ import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
 import eu.etaxonomy.taxeditor.preference.Resources;
 import eu.etaxonomy.taxeditor.store.CdmStore;
 import eu.etaxonomy.taxeditor.store.LoginManager;
+import eu.etaxonomy.taxeditor.store.StoreUtil;
 import eu.etaxonomy.taxeditor.ui.element.AbstractFormSection;
 import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
 import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;
@@ -329,7 +329,7 @@ public abstract class AbstractEntityCollectionSection<ENTITY, ELEMENT> extends A
        }
 
     private void updateToolbar() {
-        if(getEntity() != null && CdmStore.currentAuthentiationHasPermission((CdmBase) getEntity(), UPDATE)){
+        if(getEntity() != null && CdmStore.currentAuthentiationHasPermission(StoreUtil.getCdmEntity(getEntity()), UPDATE)){
             showToolbar();
         } else {
             removeToolbar();
index 1f6abee77612b4c17b154ecd1e5e91f3261bfbc8..6df772713e148b9d2acbb1e0b8a13fa74c18a932 100644 (file)
@@ -8,11 +8,11 @@ import java.util.EnumSet;
 import java.util.Observable;
 import java.util.Observer;
 
-import eu.etaxonomy.cdm.model.common.CdmBase;
 import eu.etaxonomy.cdm.model.common.IIdentifiableEntity;
 import eu.etaxonomy.cdm.persistence.hibernate.permission.CRUD;
 import eu.etaxonomy.taxeditor.store.CdmStore;
 import eu.etaxonomy.taxeditor.store.LoginManager;
+import eu.etaxonomy.taxeditor.store.StoreUtil;
 import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
 import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;
 import eu.etaxonomy.taxeditor.ui.element.ToggleableTextElement;
@@ -63,7 +63,7 @@ public abstract class AbstractIdentifiableEntityDetailElement<T extends IIdentif
 
     private void updateToggleableCacheState() {
         if(toggleable_cache != null){
-            toggleable_cache.setEnabled(getEntity() != null && CdmStore.currentAuthentiationHasPermission((CdmBase) getEntity(), UPDATE));
+            toggleable_cache.setEnabled(getEntity() != null && CdmStore.currentAuthentiationHasPermission(StoreUtil.getCdmEntity(getEntity()), UPDATE));
         }
     }
 
index 3ee7c331651fbc3734e820ef19ffb081bb7d1943..86387f9e945b3577da60523cd2866f5d40c46f86 100644 (file)
@@ -24,7 +24,6 @@ import org.springframework.security.core.GrantedAuthority;
 import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
 import eu.etaxonomy.cdm.api.conversation.IConversationEnabled;
 import eu.etaxonomy.cdm.common.CdmUtils;
-import eu.etaxonomy.cdm.model.common.CdmBase;
 import eu.etaxonomy.cdm.model.common.Group;
 import eu.etaxonomy.cdm.model.common.ICdmBase;
 import eu.etaxonomy.cdm.model.common.IIdentifiableEntity;
@@ -482,6 +481,6 @@ public class EntitySelectionElement<T extends ICdmBase> extends
        }
 
        private void updateButtonStates() {
-               button_edit.setEnabled(isEditable && button_selection.isEnabled() && getEntity() != null && CdmStore.currentAuthentiationHasPermission((CdmBase) getEntity(), UPDATE));
+               button_edit.setEnabled(isEditable && button_selection.isEnabled() && getEntity() != null  && CdmStore.currentAuthentiationHasPermission(StoreUtil.getCdmEntity(getEntity()), UPDATE));
        }
 }