Coverage Report - org.openpermis.editor.policy.view.DecisionTool
 
Classes in this File Line Coverage Branch Coverage Complexity
DecisionTool
0%
0/59
0%
0/2
1.111
 
 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.view;
 11  
 
 12  
 import javax.swing.JComboBox;
 13  
 import javax.swing.JComponent;
 14  
 import javax.swing.JLabel;
 15  
 import javax.swing.JPanel;
 16  
 import javax.swing.JScrollPane;
 17  
 import javax.swing.JTable;
 18  
 import javax.swing.ListSelectionModel;
 19  
 import javax.swing.border.BevelBorder;
 20  
 
 21  
 import org.jdesktop.application.ApplicationContext;
 22  
 import org.jdesktop.beansbinding.BeanProperty;
 23  
 import org.jdesktop.beansbinding.BindingGroup;
 24  
 import org.jdesktop.beansbinding.Bindings;
 25  
 import org.jdesktop.beansbinding.AutoBinding.UpdateStrategy;
 26  
 import org.jdesktop.observablecollections.ObservableList;
 27  
 import org.jdesktop.swingbinding.SwingBindings;
 28  
 
 29  
 import bibliothek.gui.dock.common.CLocation;
 30  
 
 31  
 import com.jgoodies.forms.layout.CellConstraints;
 32  
 import com.jgoodies.forms.layout.FormLayout;
 33  
 
 34  
 import org.openpermis.editor.policy.adapter.AdapterTrader;
 35  
 import org.openpermis.editor.policy.adapter.overview.Overview;
 36  
 import org.openpermis.editor.policy.gui.checklist.CheckList;
 37  
 import org.openpermis.editor.policy.gui.component.TimeStampPicker;
 38  
 import org.openpermis.editor.policy.presenter.DecisionPresenter;
 39  
 import org.openpermis.editor.policy.presenter.PolicyContext;
 40  
 import org.openpermis.editor.policy.renderer.RendererFactory;
 41  
 import org.openpermis.policy.Role;
 42  
 import org.openpermis.policy.bean.PartBean;
 43  
 import org.openpermis.policy.bean.PolicyBean;
 44  
 
 45  
 
 46  
 /**
 47  
  * Displays the resulting access decision for selected roles and actions.
 48  
  * @since 0.3.0
 49  
  */
 50  0
 public class DecisionTool
 51  
         extends AbstractToolView<DecisionPresenter>
 52  
 {
 53  
 
 54  
         //---- Static
 55  
         
 56  
         /**
 57  
          * Place the tool by default in the right part of the window and give it enough space.
 58  
          * @since 0.3.0
 59  
          */
 60  0
         private static final CLocation DEFAULT_LOCATION = CLocation.base().normalEast(0.33);
 61  
         
 62  
         //---- State
 63  
         
 64  
         /**
 65  
          * @since 0.3.0
 66  
          */
 67  
         private JComboBox authorityList;
 68  
         
 69  
         /**
 70  
          * @since 0.3.0
 71  
          */
 72  
         private JComboBox resourceDomainList;
 73  
         
 74  
         /**
 75  
          * @since 0.3.0
 76  
          */
 77  
         private JComboBox actionList;
 78  
         
 79  
         /**
 80  
          * @since 0.3.0
 81  
          */
 82  
         private CheckList<Role> roleList;
 83  
         
 84  
         /**
 85  
          * @since 0.3.0
 86  
          */
 87  
         private TimeStampPicker timeStampPicker;
 88  
         
 89  
         /**
 90  
          * @since 0.3.0
 91  
          */
 92  
         private JLabel decisionLabel;
 93  
         
 94  
         /**
 95  
          * @since 0.3.0
 96  
          */
 97  
         private JPanel decisionPanel;
 98  
 
 99  
         /**
 100  
          * @since 0.3.0
 101  
          */
 102  
         private JTable parameterTable;
 103  
 
 104  
         //---- Constructors
 105  
         
 106  
         /**
 107  
          * Creates a decision tool view.
 108  
          * @param context application meta data for the tool.
 109  
          * @since 0.3.0
 110  
          */
 111  
         public DecisionTool (ApplicationContext context, AdapterTrader trader) {
 112  0
                 super(context, trader);
 113  0
         }
 114  
 
 115  
         //---- Methods
 116  
         
 117  
         /**
 118  
          * @since 0.3.0
 119  
          */
 120  
         private void bindPresenterProperties (DecisionPresenter presenter, BindingGroup bindings) {
 121  0
                 bindComboBox(
 122  
                         bindings,
 123  
                         this.authorityList,
 124  
                         presenter,
 125  
                         "authority",
 126  
                         presenter.getAuthorityPool().getPoolList()
 127  
                 );
 128  
                 
 129  0
                 bindComboBox(
 130  
                         bindings,
 131  
                         this.resourceDomainList,
 132  
                         presenter,
 133  
                         "resourceDomain",
 134  
                         presenter.getResourceDomainPool().getPoolList()
 135  
                 );
 136  
 
 137  0
                 bindComboBox(
 138  
                         bindings,
 139  
                         this.actionList,
 140  
                         presenter,
 141  
                         "action",
 142  
                         presenter.getActionPool().getPoolList()
 143  
                 );
 144  
                 
 145  0
                 this.roleList.bind(presenter.getRolePool().getPoolList(), presenter.getSelectedRoles());
 146  
                 
 147  0
                 bindings.addBinding(
 148  
                         Bindings.createAutoBinding(
 149  
                                 UpdateStrategy.READ_WRITE,
 150  
                                 presenter,
 151  
                                 BeanProperty.create("evaluationTimeStamp"),
 152  
                                 this.timeStampPicker,
 153  
                                 BeanProperty.create("timeStamp")
 154  
                         )
 155  
                 );
 156  
                 
 157  0
                 bindings.addBinding(
 158  
                         Bindings.createAutoBinding(
 159  
                                 UpdateStrategy.READ,
 160  
                                 presenter,
 161  
                                 BeanProperty.create("decisionText"),
 162  
                                 this.decisionLabel,
 163  
                                 BeanProperty.create("text")
 164  
                         )
 165  
                 );
 166  0
                 bindings.addBinding(
 167  
                         Bindings.createAutoBinding(
 168  
                                 UpdateStrategy.READ,
 169  
                                 presenter,
 170  
                                 BeanProperty.create("decisionColor"),
 171  
                                 this.decisionPanel,
 172  
                                 BeanProperty.create("background")
 173  
                         )
 174  
                 );
 175  0
                 this.parameterTable.setModel(presenter.getParameterTableModel());
 176  0
         }
 177  
         
 178  
         /**
 179  
          * @since 0.3.0
 180  
          */
 181  
         private void bindComboBox (
 182  
                 BindingGroup bindings,
 183  
                 JComboBox comboBox,
 184  
                 DecisionPresenter presenter,
 185  
                 String presenterProperty,
 186  
                 ObservableList<? extends PartBean> beanList
 187  
         ) {
 188  0
                 bindings.addBinding(
 189  
                         SwingBindings.createJComboBoxBinding(UpdateStrategy.READ, beanList, comboBox)
 190  
                 );
 191  0
                 bindings.addBinding(
 192  
                         Bindings.createAutoBinding(
 193  
                                 UpdateStrategy.READ_WRITE,
 194  
                                 presenter,
 195  
                                 BeanProperty.create(presenterProperty),
 196  
                                 comboBox,
 197  
                                 BeanProperty.create("selectedItem")
 198  
                         )
 199  
                 );
 200  0
         }
 201  
 
 202  
         /**
 203  
          * @since 0.3.0
 204  
          */
 205  
         private CheckList<Role> createRoleList () {
 206  0
                 final CheckList<Role> checkList = new CheckList<Role>();
 207  0
                 checkList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
 208  0
                 checkList.setVisibleRowCount(5);
 209  0
                 checkList.setItemRenderer(
 210  
                         RendererFactory.createTableCellRenderer(this.getAdapteeTrader(), Overview.class)
 211  
                 );
 212  0
                 return checkList;
 213  
         }
 214  
 
 215  
         /**
 216  
          * @since 0.3.0
 217  
          */
 218  
         private JPanel createDecisionPane (JLabel label) {
 219  0
                 final JPanel panel = new JPanel();
 220  0
                 panel.setBorder(new BevelBorder(BevelBorder.LOWERED));
 221  0
                 panel.add(label);
 222  0
                 return panel;
 223  
         }
 224  
         
 225  
         //---- Tool
 226  
         
 227  
         /**
 228  
          * @since 0.3.0
 229  
          */
 230  
         public void refresh (PolicyBean policy, PolicyContext context) {
 231  0
                 setPresenter(policy != null ? new DecisionPresenter(policy, context) : null);
 232  0
         }
 233  
         
 234  
         /**
 235  
          * @since 0.3.0
 236  
          */
 237  
         @Override
 238  
         protected void attachPresenter (DecisionPresenter presenter, BindingGroup bindings) {
 239  0
                 super.attachPresenter(presenter, bindings);
 240  0
                 bindPresenterProperties(presenter, bindings);
 241  0
         }
 242  
 
 243  
         //---- AbstractView
 244  
         
 245  
         /**
 246  
          * @since 0.3.0
 247  
          */
 248  
         @Override
 249  
         protected JComponent createContentPane () {
 250  0
                 final FormLayout layout = new FormLayout(
 251  
                         "pref, $lcgap, fill:min(100dlu;pref):grow",
 252  
                         "pref, $rgap, pref, $rgap, pref, pref, $rgap, pref, $rgap, pref, $ugap, pref"
 253  
                 );
 254  0
                 final JPanel panel = new JPanel(layout);
 255  0
                 final CellConstraints cc = new CellConstraints();
 256  
                 
 257  0
                 panel.add(label("authority"), cc.xy(1, 1));
 258  0
                 this.authorityList = new JComboBox();
 259  0
                 this.authorityList.setRenderer(
 260  
                         RendererFactory.createListCellRenderer(this.getAdapteeTrader(), Overview.class)
 261  
                 );
 262  0
                 panel.add(this.authorityList, cc.xy(3, 1));
 263  
                 
 264  0
                 panel.add(label("resource"), cc.xy(1, 3));
 265  0
                 this.resourceDomainList = new JComboBox();
 266  0
                 this.resourceDomainList.setRenderer(
 267  
                         RendererFactory.createListCellRenderer(this.getAdapteeTrader(), Overview.class)
 268  
                 );
 269  0
                 panel.add(this.resourceDomainList, cc.xy(3, 3));
 270  
                 
 271  0
                 panel.add(label("action"), cc.xy(1, 5));
 272  0
                 this.actionList = new JComboBox();
 273  0
                 this.actionList.setRenderer(
 274  
                         RendererFactory.createListCellRenderer(this.getAdapteeTrader(), Overview.class)
 275  
                 );
 276  0
                 panel.add(this.actionList, cc.xy(3, 5));
 277  0
                 this.parameterTable = new JTable();
 278  0
                 panel.add(this.parameterTable, cc.xy(3, 6));
 279  
                 
 280  0
                 panel.add(label("roles"), cc.xy(1, 8));
 281  0
                 this.roleList = createRoleList();
 282  0
                 panel.add(new JScrollPane(this.roleList), cc.xy(3, 8));
 283  
                 
 284  0
                 panel.add(label("evaluationTime"), cc.xy(1, 10));
 285  0
                 this.timeStampPicker = new TimeStampPicker();
 286  0
                 panel.add(this.timeStampPicker, cc.xy(3, 10));
 287  
                 
 288  0
                 panel.add(label("decision"), cc.xy(1, 12));
 289  0
                 this.decisionLabel = new JLabel(" ");
 290  0
                 this.decisionPanel = createDecisionPane(this.decisionLabel);
 291  0
                 panel.add(this.decisionPanel, cc.xy(3, 12));
 292  
                 
 293  0
                 return new JScrollPane(panel);
 294  
         }
 295  
 
 296  
         /**
 297  
          * @since 0.3.0
 298  
          */
 299  
         @Override
 300  
         public CLocation getDefaultLocation () {
 301  0
                 return DEFAULT_LOCATION;
 302  
         }
 303  
         
 304  
 }