Coverage Report - org.openpermis.editor.policy.presenter.RoleAssignmentRuleListPresenter
 
Classes in this File Line Coverage Branch Coverage Complexity
RoleAssignmentRuleListPresenter
0%
0/21
0%
0/2
1.286
 
 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 org.jdesktop.observablecollections.ObservableCollections;
 13  
 import org.jdesktop.observablecollections.ObservableList;
 14  
 import org.slf4j.Logger;
 15  
 import org.slf4j.LoggerFactory;
 16  
 
 17  
 import org.openpermis.editor.policy.beans.PropertyChange;
 18  
 import org.openpermis.editor.policy.command.CollectionAddCommand;
 19  
 import org.openpermis.editor.policy.command.CollectionRemoveCommand;
 20  
 import org.openpermis.policy.bean.PolicyBean;
 21  
 import org.openpermis.policy.bean.RoleAssignmentRuleBean;
 22  
 
 23  
 /**
 24  
  * Presenter for a list of {@link RoleAssignmentRuleBean}s found in a {@link PolicyBean}.
 25  
  * @since 0.3.0
 26  
  */
 27  
 public class RoleAssignmentRuleListPresenter
 28  
         extends PartPresenter<PolicyBean>
 29  
 {
 30  
 
 31  
         //---- Static
 32  
 
 33  
         /**
 34  
          * The logger object of this class.
 35  
          * @since 0.3.0
 36  
          */
 37  0
         private static final Logger LOGGER =
 38  
                 LoggerFactory.getLogger(RoleAssignmentRuleListPresenter.class);
 39  
 
 40  
         //---- State
 41  
 
 42  
         /**
 43  
          * An observable list of all role assignment rules in the policy.
 44  
          * @since 0.3.0
 45  
          */
 46  
         private final ObservableList<RoleAssignmentRuleBean> roleAssignmentRules;
 47  
 
 48  
         /**
 49  
          * The currently active role assignment rule.
 50  
          * @since 0.3.0
 51  
          */
 52  
         private RoleAssignmentRuleBean active;
 53  
 
 54  
         //---- Constructors
 55  
 
 56  
         /**
 57  
          * Creates a new role assignment rule list presenter.
 58  
          * @param model the policy for which to provide the role assignment rules.
 59  
          * @since 0.3.0
 60  
          */
 61  
         public RoleAssignmentRuleListPresenter (PolicyBean model, PolicyContext context) {
 62  0
                 super(model, context);
 63  0
                 this.roleAssignmentRules = ObservableCollections.observableList(
 64  
                         getModel().getRoleAssignmentRules().toList()
 65  
                 );
 66  0
         }
 67  
 
 68  
         //---- Methods
 69  
 
 70  
         /**
 71  
          * @since 0.3.0
 72  
          */
 73  
         public void addRoleAssignmentRule () {
 74  0
                 if (getRoleAssignmentRules() == null) {
 75  0
                         return;
 76  
                 }
 77  0
                 final RoleAssignmentRuleBean rule =
 78  
                         getPartBeanFactory().createRoleAssignmentRule(null, null, null, null, 0);
 79  0
                 execute(new CollectionAddCommand<RoleAssignmentRuleBean>(
 80  
                         getModel(), rule, "roleAssignmentRules"));
 81  0
         }
 82  
 
 83  
 
 84  
         /**
 85  
          * @since 0.3.0
 86  
          */
 87  
         public void removeRoleAssignmentRule (RoleAssignmentRuleBean rule) {
 88  0
                 execute(new CollectionRemoveCommand<RoleAssignmentRuleBean>(
 89  
                         getModel(), rule, "roleAssignmentRules"));
 90  0
         }
 91  
 
 92  
         /**
 93  
          * Returns an observable list of role assignment rules.
 94  
          * @return an observable list of role assignment rules.
 95  
          * @since 0.3.0
 96  
          */
 97  
         public ObservableList<RoleAssignmentRuleBean> getRoleAssignmentRules () {
 98  0
                 return this.roleAssignmentRules;
 99  
         }
 100  
 
 101  
         /**
 102  
          * Returns the currently active role assignment rule.
 103  
          * @return the currently active role assignment rule, may be <code>null</code>.
 104  
          * @since 0.3.0
 105  
          */
 106  
         public RoleAssignmentRuleBean getActive () {
 107  0
                 return this.active;
 108  
         }
 109  
 
 110  
         /**
 111  
          * Sets the currently active role assignment rule.
 112  
          * @param active the role assignment rule to set active.
 113  
          * @see #setActive(RoleAssignmentRuleBean)
 114  
          * @since 0.3.0
 115  
          */
 116  
         public void setActive (RoleAssignmentRuleBean active) {
 117  0
                 final RoleAssignmentRuleBean oldValue = this.active;
 118  0
                 this.active = active;
 119  0
                 firePropertyChange("active", oldValue, this.active);
 120  0
         }
 121  
 
 122  
         //---- PropertyChanges
 123  
 
 124  
         /**
 125  
          * Handles property changes of roleAssignmentRules.
 126  
          * @since 0.3.0
 127  
          */
 128  
         @PropertyChange(bean = PolicyBean.class, property = "roleAssignmentRules")
 129  
         public void roleAssignmentRulesChanged () {
 130  0
                 LOGGER.debug("roleAssignmentRulesChanged");
 131  0
                 this.roleAssignmentRules.clear();
 132  0
                 this.roleAssignmentRules.addAll(getModel().getRoleAssignmentRules().toList());
 133  0
         }
 134  
 
 135  
 }