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