Coverage Report - org.openpermis.editor.policy.presenter.RoleHierarchyListPresenter
 
Classes in this File Line Coverage Branch Coverage Complexity
RoleHierarchyListPresenter
0%
0/24
0%
0/2
1.25
 
 1  
 /*
 2  
  * Copyright (c) 2009, Swiss Federal Department of Defence Civil Protection and Sport
 3  
  *                     (http://www.vbs.admin.ch)
 4  
  * Copyright (c) 2009, Ergon Informatik AG (http://www.ergon.ch)
 5  
  * All rights reserved.
 6  
  *
 7  
  * Licensed under the Open Permis License which accompanies this distribution,
 8  
  * and is available at http://www.openpermis.org/BSDlicenceKent.txt
 9  
  */
 10  
 package org.openpermis.editor.policy.presenter;
 11  
 
 12  
 import java.net.URI;
 13  
 
 14  
 import org.jdesktop.observablecollections.ObservableCollections;
 15  
 import org.jdesktop.observablecollections.ObservableList;
 16  
 import org.slf4j.Logger;
 17  
 import org.slf4j.LoggerFactory;
 18  
 
 19  
 import org.openpermis.editor.policy.beans.PropertyChange;
 20  
 import org.openpermis.editor.policy.command.CollectionAddCommand;
 21  
 import org.openpermis.editor.policy.command.CollectionRemoveCommand;
 22  
 import org.openpermis.policy.bean.PolicyBean;
 23  
 import org.openpermis.policy.bean.RoleHierarchyBean;
 24  
 
 25  
 /**
 26  
  * Presenter for a list of {@link RoleHierarchyBean}s found in a {@link PolicyBean}.
 27  
  * @since 0.3.0
 28  
  */
 29  
 public class RoleHierarchyListPresenter
 30  
         extends PartPresenter<PolicyBean>
 31  
 {
 32  
 
 33  
         //---- Static
 34  
 
 35  
         /**
 36  
          * The logger object of this class.
 37  
          * @since 0.3.0
 38  
          */
 39  0
         private static final Logger LOGGER =
 40  
                 LoggerFactory.getLogger(RoleHierarchyListPresenter.class);
 41  
 
 42  
         //---- State
 43  
 
 44  
         /**
 45  
          * An observable list of all role hierarchies in the policy.
 46  
          * @since 0.3.0
 47  
          */
 48  
         private final ObservableList<RoleHierarchyBean> roleHierarchies;
 49  
 
 50  
         /**
 51  
          * The currently active role hierarchy.
 52  
          * @since 0.3.0
 53  
          */
 54  
         private RoleHierarchyBean active;
 55  
 
 56  
         //---- Constructors
 57  
 
 58  
         /**
 59  
          * Creates a new role hierarchy list presenter.
 60  
          * @param model the policy for which to provide the role hierarchies.
 61  
          * @since 0.3.0
 62  
          */
 63  
         public RoleHierarchyListPresenter (PolicyBean model, PolicyContext context) {
 64  0
                 super(model, context);
 65  0
                 this.roleHierarchies = ObservableCollections.observableList(
 66  
                         getModel().getRoleHierarchies().toList()
 67  
                 );
 68  0
         }
 69  
 
 70  
         //---- Methods
 71  
 
 72  
         /**
 73  
          * @since 0.3.0
 74  
          */
 75  
         public void addRoleHierarchy (URI uri) {
 76  0
                 if (getRoleHierarchies() == null) {
 77  0
                         return;
 78  
                 }
 79  0
                 final RoleHierarchyBean rule =
 80  
                         getPartBeanFactory().createRoleHierarchy(uri);
 81  0
                 execute(new CollectionAddCommand<RoleHierarchyBean>(
 82  
                         getModel(), rule, "roleHierarchies"));
 83  0
         }
 84  
 
 85  
 
 86  
         /**
 87  
          * @since 0.3.0
 88  
          */
 89  
         public void removeRoleHierarchy (RoleHierarchyBean rule) {
 90  0
                 execute(new CollectionRemoveCommand<RoleHierarchyBean>(
 91  
                         getModel(), rule, "roleHierarchies"));
 92  0
         }
 93  
 
 94  
         /**
 95  
          * Returns an observable list of role hierarchies.
 96  
          * @return an observable list of role hierarchies.
 97  
          * @since 0.3.0
 98  
          */
 99  
         public ObservableList<RoleHierarchyBean> getRoleHierarchies () {
 100  0
                 return this.roleHierarchies;
 101  
         }
 102  
 
 103  
         /**
 104  
          * Returns the currently active role hierarchy.
 105  
          * @return the currently active role hierarchy, may be <code>null</code>.
 106  
          * @since 0.3.0
 107  
          */
 108  
         public RoleHierarchyBean getActive () {
 109  0
                 return this.active;
 110  
         }
 111  
 
 112  
         /**
 113  
          * Sets the currently active role hierarchy.
 114  
          * @param active the role hierarchy to set active.
 115  
          * @see #setActive(RoleHierarchyBean)
 116  
          * @since 0.3.0
 117  
          */
 118  
         public void setActive (RoleHierarchyBean active) {
 119  0
                 final RoleHierarchyBean oldValue = this.active;
 120  0
                 this.active = active;
 121  0
                 firePropertyChange("active", oldValue, this.active);
 122  0
         }
 123  
 
 124  
         //---- PropertyChanges
 125  
 
 126  
         /**
 127  
          * Handles property changes of roleHierarchies.
 128  
          * @since 0.3.0
 129  
          */
 130  
         @PropertyChange(bean = PolicyBean.class, property = "roleHierarchies")
 131  
         public void roleHierarchiesChanged () {
 132  0
                 LOGGER.debug("roleHierarchiesChanged");
 133  0
                 this.roleHierarchies.clear();
 134  0
                 this.roleHierarchies.addAll(getModel().getRoleHierarchies().toList());
 135  0
         }
 136  
 
 137  
         /**
 138  
          * Handles property changes of roleHierarchies.
 139  
          * @since 0.3.0
 140  
          */
 141  
         @PropertyChange(bean = PolicyBean.class, property = "roleAssignmentRules")
 142  
         public void roleAssignmentRulesChanged () {
 143  0
                 LOGGER.debug("roleAssignmentRulesChanged");
 144  0
                 this.roleHierarchiesChanged();
 145  0
         }
 146  
 
 147  
 
 148  
 
 149  
 }