Coverage Report - org.openpermis.editor.policy.view.RoleAssignmentRuleEditor
 
Classes in this File Line Coverage Branch Coverage Complexity
RoleAssignmentRuleEditor
0%
0/240
0%
0/48
1.931
RoleAssignmentRuleEditor$1
0%
0/3
N/A
1.931
RoleAssignmentRuleEditor$2
0%
0/5
N/A
1.931
RoleAssignmentRuleEditor$3
0%
0/3
N/A
1.931
RoleAssignmentRuleEditor$4
0%
0/3
N/A
1.931
RoleAssignmentRuleEditor$5
0%
0/3
N/A
1.931
RoleAssignmentRuleEditor$6
0%
0/3
N/A
1.931
RoleAssignmentRuleEditor$7
0%
0/4
0%
0/2
1.931
 
 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 java.awt.event.ActionEvent;
 13  
 import java.awt.event.ActionListener;
 14  
 import java.util.Calendar;
 15  
 import java.util.Date;
 16  
 import java.util.List;
 17  
 import java.util.TimeZone;
 18  
 
 19  
 import javax.swing.JButton;
 20  
 import javax.swing.JCheckBox;
 21  
 import javax.swing.JComboBox;
 22  
 import javax.swing.JComponent;
 23  
 import javax.swing.JLabel;
 24  
 import javax.swing.JOptionPane;
 25  
 import javax.swing.JPanel;
 26  
 import javax.swing.JScrollPane;
 27  
 
 28  
 import org.jdesktop.application.Action;
 29  
 import org.jdesktop.application.ApplicationContext;
 30  
 import org.jdesktop.beansbinding.BeanProperty;
 31  
 import org.jdesktop.beansbinding.BindingGroup;
 32  
 import org.jdesktop.beansbinding.Bindings;
 33  
 import org.jdesktop.beansbinding.AutoBinding.UpdateStrategy;
 34  
 import org.jdesktop.swingbinding.SwingBindings;
 35  
 import org.jdesktop.swingx.JXDatePicker;
 36  
 import org.joda.time.Period;
 37  
 import org.joda.time.PeriodType;
 38  
 import org.slf4j.Logger;
 39  
 import org.slf4j.LoggerFactory;
 40  
 
 41  
 import com.jgoodies.forms.layout.CellConstraints;
 42  
 import com.jgoodies.forms.layout.FormLayout;
 43  
 
 44  
 import org.openpermis.basic.AbsoluteTimePeriod;
 45  
 import org.openpermis.basic.TimePeriod;
 46  
 import org.openpermis.basic.TimePeriodConstraint;
 47  
 import org.openpermis.editor.policy.adapter.AdapterTrader;
 48  
 import org.openpermis.editor.policy.gui.checklist.CheckList;
 49  
 import org.openpermis.editor.policy.presenter.RoleAssignmentRulePresenter;
 50  
 import org.openpermis.policy.Role;
 51  
 import org.openpermis.policy.TimeStamp;
 52  
 import org.openpermis.policy.bean.AuthorityBean;
 53  
 import org.openpermis.policy.bean.DomainBean;
 54  
 import org.openpermis.policy.bean.PolicyBean;
 55  
 import org.openpermis.policy.bean.RoleAssignmentRuleBean;
 56  
 import org.openpermis.policy.bean.RoleAssignmentRuleBeanCollection;
 57  
 
 58  
 /**
 59  
  * Tool view that displays a role assignment rule.
 60  
  * @since 0.3.0
 61  
  */
 62  0
 public class RoleAssignmentRuleEditor
 63  
         extends AbstractEditor<RoleAssignmentRulePresenter>
 64  
 {
 65  
 
 66  
         //---- Static
 67  
 
 68  
         /**
 69  
          * The logger object of this class.
 70  
          * @since 0.3.0
 71  
          */
 72  0
         private static final Logger LOGGER =
 73  
                 LoggerFactory.getLogger(RoleAssignmentRuleEditor.class);
 74  
 
 75  
         /**
 76  
          * @since 0.3.0
 77  
          */
 78  
         private static final int MILLIS_IN_A_DAY = 24 * 3600 * 1000;
 79  
 
 80  
         //---- State
 81  
         
 82  
         /**
 83  
          * Chooser for the authority.
 84  
          * @since 0.3.0
 85  
          */
 86  0
         private JComboBox authority = new JComboBox();
 87  
 
 88  
         /**
 89  
          * Chooser for the subject domain of the rule.
 90  
          * @since 0.3.0
 91  
          */
 92  0
         private JComboBox subjectDomain = new JComboBox();
 93  
 
 94  
         /**
 95  
          * The list of roles in the role assignment rule.
 96  
          * @since 0.3.0
 97  
          */
 98  
         private CheckList<Role> roleList;
 99  
 
 100  
         /**
 101  
          * @since 0.3.0
 102  
          */
 103  0
         private JLabel delegationDepthLabel = new JLabel();
 104  
         
 105  
         /**
 106  
          * @since 0.3.0
 107  
          */
 108  0
         private JCheckBox absolutePeriodCheckBox = new JCheckBox();
 109  
 
 110  
         /**
 111  
          * @since 0.3.0
 112  
          */
 113  0
         private JXDatePicker startDatePicker = new JXDatePicker();
 114  
 
 115  
         /**
 116  
          * @since 0.3.0
 117  
          */
 118  0
         private JXDatePicker endDatePicker = new JXDatePicker();
 119  
 
 120  
         /**
 121  
          * @since 0.3.0
 122  
          */
 123  0
         private JXDatePicker referenceDatePicker = new JXDatePicker();
 124  
 
 125  
         /**
 126  
          * @since 0.3.0
 127  
          */
 128  0
         private JCheckBox minimumFromCheckBox = new JCheckBox();
 129  
         
 130  
         /**
 131  
          * @since 0.3.0
 132  
          */
 133  0
         private JXDatePicker minimumFromDatePicker = new JXDatePicker();
 134  
 
 135  
         /**
 136  
          * @since 0.3.0
 137  
          */
 138  0
         private int minimumFromDays = 0;
 139  
 
 140  
         /**
 141  
          * @since 0.3.0
 142  
          */
 143  0
         private JCheckBox minimumUpToCheckBox = new JCheckBox();
 144  
 
 145  
         /**
 146  
          * @since 0.3.0
 147  
          */
 148  0
         private JXDatePicker minimumUpToDatePicker = new JXDatePicker();
 149  
 
 150  
         /**
 151  
          * @since 0.3.0
 152  
          */
 153  0
         private int minimumUpToDays = 0;
 154  
         
 155  
         /**
 156  
          * @since 0.3.0
 157  
          */
 158  0
         private JCheckBox maximumUpToCheckBox = new JCheckBox();
 159  
 
 160  
         /**
 161  
          * @since 0.3.0
 162  
          */
 163  0
         private JXDatePicker maximumUpToDatePicker = new JXDatePicker();
 164  
 
 165  
         /**
 166  
          * @since 0.3.0
 167  
          */
 168  0
         private int maximumUpToDays = 0;
 169  
 
 170  
         /**
 171  
          * @since 0.3.0
 172  
          */
 173  0
         private TimeStamp defaultZoneTimeStamp = new TimeStamp(new Date(), TimeZone.getDefault());
 174  
 
 175  
         
 176  
         //---- Constructors
 177  
 
 178  
         /**
 179  
          * Creates role assignment rule editor.
 180  
          * @param context the application context used to lookup the action and resource map.
 181  
          * @param presenter the presenter of this view.
 182  
          * @since 0.3.0
 183  
          */
 184  
         public RoleAssignmentRuleEditor (
 185  
                 ApplicationContext context, AdapterTrader trader, RoleAssignmentRulePresenter presenter
 186  
         ) {
 187  0
                 super(context, trader, presenter);
 188  0
                 this.delegationDepthLabel.setText(String.valueOf(presenter.getDelegationDepth()));
 189  0
                 LOGGER.debug("create RoleAssigmentRuleEditor");
 190  
 
 191  0
                 ActionListener listener4CheckBoxes = new ActionListener() {
 192  0
                         public void actionPerformed (ActionEvent e) {
 193  0
                                 updateConstraintAtModel();
 194  0
                         }        
 195  
                 };
 196  
                 
 197  0
                 Calendar calender = Calendar.getInstance();
 198  0
                 calender.set(Calendar.MILLISECOND, 0);
 199  0
                 calender.set(Calendar.SECOND, 0);
 200  0
                 calender.set(Calendar.MINUTE, 0);
 201  0
                 calender.set(Calendar.HOUR_OF_DAY, 0);
 202  0
                 Date today = calender.getTime();
 203  
 
 204  0
                 this.absolutePeriodCheckBox.addActionListener(listener4CheckBoxes);
 205  0
                 this.startDatePicker.setDate(today);
 206  0
                 this.endDatePicker.setDate(today);
 207  0
                 this.startDatePicker.addActionListener(listener4CheckBoxes);
 208  0
                 this.endDatePicker.addActionListener(listener4CheckBoxes);
 209  
                 
 210  0
                 this.referenceDatePicker.setDate(today);
 211  0
                 this.referenceDatePicker.addActionListener(new ActionListener() {
 212  0
                         public void actionPerformed (ActionEvent e) {
 213  0
                                 setMinimumValidFromDayNumber(RoleAssignmentRuleEditor.this.minimumFromDays);
 214  0
                                 setMinimumValidUpToDayNumber(RoleAssignmentRuleEditor.this.minimumUpToDays);
 215  0
                                 setMaximumValidUpToDayNumber(RoleAssignmentRuleEditor.this.maximumUpToDays);
 216  0
                         }        
 217  
                 });
 218  
 
 219  0
                 this.minimumFromCheckBox.addActionListener(listener4CheckBoxes);
 220  0
                 this.minimumFromDatePicker.setDate(today);
 221  0
                 this.minimumFromDatePicker.addActionListener(new ActionListener() {
 222  0
                         public void actionPerformed (ActionEvent e) {
 223  0
                                 RoleAssignmentRuleEditor.this.minimumFromDays = extractMinimumFromDays();
 224  0
                         }        
 225  
                 });
 226  0
                 this.minimumFromDatePicker.addActionListener(listener4CheckBoxes);
 227  
 
 228  0
                 this.minimumUpToCheckBox.addActionListener(listener4CheckBoxes);
 229  0
                 this.minimumUpToDatePicker.setDate(today);
 230  0
                 this.minimumUpToDatePicker.addActionListener(new ActionListener() {
 231  0
                         public void actionPerformed (ActionEvent e) {
 232  0
                                 RoleAssignmentRuleEditor.this.minimumUpToDays = extractMinimumUpToDays();
 233  0
                         }        
 234  
                 });
 235  0
                 this.minimumUpToDatePicker.addActionListener(listener4CheckBoxes);
 236  
 
 237  0
                 this.maximumUpToCheckBox.addActionListener(listener4CheckBoxes);
 238  0
                 this.maximumUpToDatePicker.setDate(today);
 239  0
                 this.maximumUpToDatePicker.addActionListener(new ActionListener() {
 240  0
                         public void actionPerformed (ActionEvent e) {
 241  0
                                 RoleAssignmentRuleEditor.this.maximumUpToDays = extractMaximumUpToDays();
 242  0
                         }        
 243  
                 });
 244  0
                 this.maximumUpToDatePicker.addActionListener(listener4CheckBoxes);
 245  0
         }
 246  
 
 247  
         //---- Methods
 248  
 
 249  
         /**
 250  
          * Updates the the constraints in the model.
 251  
          * @since 0.3.0
 252  
          */
 253  
         public void updateConstraintAtModel () {
 254  
                 
 255  
                 // Even if the validators constantly check that only valid values are entered, if a policy
 256  
                 // with disabled constraints is loaded, the constraints values are 0.To avoid a lock this
 257  
                 // method modifies those values to make them become valid.
 258  
                 
 259  0
                 TimePeriod absoluteTimePeriod = null;
 260  0
                 Period minimumValidFrom = null;
 261  0
                 Period minimumValidUpTo = null;
 262  0
                 Period maximumValidUpTo = null;
 263  
 
 264  0
                 if (this.absolutePeriodCheckBox.isSelected()) {
 265  0
                         Date startDate = this.startDatePicker.getDate();
 266  0
                         Date endDate = this.endDatePicker.getDate();
 267  0
                         if (!startDate.before(endDate)) {
 268  0
                                 endDate = new Date(startDate.getTime() + MILLIS_IN_A_DAY);
 269  
                                 // Necessary for the cases in which no event is fired due to the lack of change.
 270  0
                                 this.endDatePicker.setDate(endDate);
 271  
                         }
 272  0
                         absoluteTimePeriod =
 273  
                                 new AbsoluteTimePeriod(
 274  
                                         startDate,
 275  
                                         endDate
 276  
                                 );
 277  
                 }
 278  
 
 279  0
                 int localMinimumFromDays = extractMinimumFromDays();
 280  0
                 int localMinimumUpToDays = extractMinimumUpToDays();
 281  0
                 int localMaximumUpToDays = extractMaximumUpToDays();
 282  
                                 
 283  0
                 if (this.minimumFromCheckBox.isSelected()) {
 284  0
                         if (localMinimumFromDays > 0) {
 285  0
                                 localMinimumFromDays = 0;
 286  0
                                 this.minimumFromDays = localMinimumFromDays;
 287  
                                 // Necessary for the cases in which no event is fired due to the lack of change.
 288  0
                                 setMinimumValidFromDayNumber(this.minimumFromDays);
 289  
                         }
 290  0
                         minimumValidFrom = new Period(
 291  
                                 0,
 292  
                                 0,
 293  
                                 0,
 294  
                                 -localMinimumFromDays,
 295  
                                 0,
 296  
                                 0,
 297  
                                 0,
 298  
                                 0
 299  
                         );
 300  
                 }
 301  
 
 302  0
                 if (this.minimumUpToCheckBox.isSelected()) {
 303  0
                         if (
 304  
                                 localMinimumUpToDays < 0
 305  
                         ) {
 306  0
                                 localMinimumUpToDays = 0;
 307  0
                                 this.minimumUpToDays = 0;
 308  
                                 // Necessary for the cases in which no event is fired due to the lack of change.
 309  0
                                 setMinimumValidUpToDayNumber(this.minimumUpToDays);
 310  
                         }
 311  0
                         minimumValidUpTo = new Period(
 312  
                                 0,
 313  
                                 0,
 314  
                                 0,
 315  
                                 localMinimumUpToDays,
 316  
                                 0,
 317  
                                 0,
 318  
                                 0,
 319  
                                 0
 320  
                         );
 321  
                 }
 322  
                 
 323  
                 
 324  0
                 if (this.maximumUpToCheckBox.isSelected()) {
 325  0
                         if (
 326  
                                 localMaximumUpToDays < 0
 327  
                         ) {
 328  0
                                 localMaximumUpToDays = 0;
 329  0
                                 this.maximumUpToDays = 0;
 330  
                                 // Necessary for the cases in which no event is fired due to the lack of change.
 331  0
                                 setMaximumValidUpToDayNumber(this.maximumUpToDays);
 332  
                         }
 333  0
                         if (
 334  
                                 this.minimumUpToCheckBox.isSelected() &&
 335  
                                 localMinimumUpToDays > localMaximumUpToDays
 336  
                         ) {
 337  0
                                 localMaximumUpToDays = localMinimumUpToDays;
 338  0
                                 this.maximumUpToDays = localMaximumUpToDays;
 339  
                                 // Necessary for the cases in which no event is fired due to the lack of change.
 340  0
                                 setMaximumValidUpToDayNumber(this.maximumUpToDays);
 341  
                         }
 342  0
                         maximumValidUpTo = new Period(
 343  
                                 0,
 344  
                                 0,
 345  
                                 0,
 346  
                                 localMaximumUpToDays,
 347  
                                 0,
 348  
                                 0,
 349  
                                 0,
 350  
                                 0
 351  
                         );
 352  
                 }
 353  
                 
 354  0
                 getPresenter().updateConstraintAtModel(new TimePeriodConstraint(
 355  
                         absoluteTimePeriod,
 356  
                         minimumValidFrom,
 357  
                         minimumValidUpTo,
 358  
                         maximumValidUpTo
 359  
                 ));
 360  0
         }
 361  
 
 362  
         /**
 363  
          * Sets the constraint.
 364  
          * @param newConstraint the constraint.
 365  
          * @since 0.3.0
 366  
          */
 367  
         public void setConstraint (TimePeriodConstraint newConstraint) {
 368  
 
 369  0
                 TimePeriod timePeriod = newConstraint.getAbsolutePeriod();
 370  
 
 371  
                 // Absolute constraint.
 372  0
                 if (timePeriod.equals(TimePeriod.INFINITE) || timePeriod.equals(TimePeriod.EMPTY)) {
 373  0
                         this.absolutePeriodCheckBox.setSelected(false);                
 374  
                 } else {
 375  0
                         AbsoluteTimePeriod absolutePeriod = (AbsoluteTimePeriod) timePeriod;
 376  0
                         this.startDatePicker.setDate(
 377  
                                 absolutePeriod.getStart().toDateTime(this.defaultZoneTimeStamp).toDate()
 378  
                         );
 379  0
                         this.endDatePicker.setDate(
 380  
                                 absolutePeriod.getEnd().toDateTime(this.defaultZoneTimeStamp).toDate()
 381  
                         );
 382  0
                         this.absolutePeriodCheckBox.setSelected(true);                
 383  
 
 384  
                 }
 385  
                 
 386  
                 
 387  
 
 388  
                 // Minimum valid from constraint.
 389  0
                 Period minimumValidFromPeriod = newConstraint.getMinimumValidFrom();
 390  
 
 391  0
                 if (minimumValidFromPeriod == null) {
 392  0
                         this.minimumFromCheckBox.setSelected(false);
 393  
                 } else {
 394  0
                         int daysNumber =
 395  
                                 minimumValidFromPeriod.
 396  
                                 normalizedStandard(PeriodType.time()).
 397  
                                 toStandardDays().getDays();
 398  0
                         setMinimumValidFromDayNumber(-daysNumber);
 399  0
                         this.minimumFromCheckBox.setSelected(true);
 400  
                 }
 401  
 
 402  
                 // Minimum valid up to constraint.
 403  0
                 Period minimumValidUpToPeriod = newConstraint.getMinimumValidUpTo();
 404  
 
 405  0
                 if (minimumValidUpToPeriod == null) {
 406  0
                         this.minimumUpToCheckBox.setSelected(false);
 407  
                 } else {
 408  0
                         int daysNumber =
 409  
                                 minimumValidUpToPeriod.
 410  
                                 normalizedStandard(PeriodType.time()).
 411  
                                 toStandardDays().getDays();
 412  0
                         setMinimumValidUpToDayNumber(daysNumber);
 413  0
                         this.minimumUpToCheckBox.setSelected(true);
 414  
                 }
 415  
 
 416  
                 // Maximum valid up to constraint.
 417  0
                 Period maximumValidUpToPeriod = newConstraint.getMaximumValidUpTo();
 418  
 
 419  0
                 if (maximumValidUpToPeriod == null) {
 420  0
                         this.maximumUpToCheckBox.setSelected(false);
 421  
                 } else {
 422  0
                         int daysNumber =
 423  
                                 maximumValidUpToPeriod.
 424  
                                 normalizedStandard(PeriodType.time()).
 425  
                                 toStandardDays().getDays();
 426  0
                         setMaximumValidUpToDayNumber(daysNumber);
 427  0
                         this.maximumUpToCheckBox.setSelected(true);
 428  
                 }
 429  0
         }
 430  
         
 431  
         /**
 432  
          * @since 0.3.0
 433  
          */
 434  
         private int extractMaximumUpToDays () {
 435  0
                 return Math.round((this.maximumUpToDatePicker.getDate().getTime() -
 436  
                         this.referenceDatePicker.getDate().getTime()) / (float) MILLIS_IN_A_DAY);
 437  
         }
 438  
 
 439  
         /**
 440  
          * @since 0.3.0
 441  
          */
 442  
         private int extractMinimumUpToDays () {
 443  0
                 return Math.round((this.minimumUpToDatePicker.getDate().getTime() -
 444  
                         this.referenceDatePicker.getDate().getTime()) / (float) MILLIS_IN_A_DAY);
 445  
         }
 446  
 
 447  
         /**
 448  
          * @since 0.3.0
 449  
          */
 450  
         private int extractMinimumFromDays () {
 451  0
                 return Math.round((this.minimumFromDatePicker.getDate().getTime() -
 452  
                         this.referenceDatePicker.getDate().getTime()) / (float) MILLIS_IN_A_DAY);
 453  
         }
 454  
 
 455  
         /**
 456  
          * @since 0.3.0
 457  
          */
 458  
         private void setMaximumValidUpToDayNumber (int daysNumber) {
 459  0
                 this.maximumUpToDatePicker.setDate(addToReference(daysNumber));
 460  0
         }
 461  
 
 462  
         /**
 463  
          * @since 0.3.0
 464  
          */
 465  
         private void setMinimumValidUpToDayNumber (int daysNumber) {
 466  0
                 this.minimumUpToDatePicker.setDate(addToReference(daysNumber));
 467  0
         }
 468  
 
 469  
         /**
 470  
          * @since 0.3.0
 471  
          */
 472  
         private void setMinimumValidFromDayNumber (int daysNumber) {
 473  0
                 this.minimumFromDatePicker.setDate(addToReference(daysNumber));
 474  0
         }
 475  
 
 476  
         /**
 477  
          * @since 0.3.0
 478  
          */
 479  
         private Date addToReference (int daysNumber) {
 480  0
                 Calendar calendar = Calendar.getInstance();
 481  0
                 calendar.setTime(this.referenceDatePicker.getDate());
 482  0
                 calendar.add(Calendar.DAY_OF_WEEK, daysNumber);
 483  0
                 return calendar.getTime();
 484  
         }
 485  
 
 486  
         //---- Actions
 487  
         
 488  
         /**
 489  
          * @since 0.3.0
 490  
          */
 491  
         @Action
 492  
         public void addAuthority () {
 493  0
                 LOGGER.debug("addAuthority");
 494  0
                 getPresenter().addAuthority(new EditPartCommand<AuthorityBean>(getViewContext()));
 495  0
         }
 496  
         
 497  
         /**
 498  
          * @since 0.3.0
 499  
          */
 500  
         @Action
 501  
         public void removeAuthority () {
 502  0
                 LOGGER.debug("removeAuthority");
 503  0
                 AuthorityBean activeAuthority = this.getPresenter().getActiveAuthority();
 504  0
                 if (activeAuthority != null) {
 505  
                         
 506  0
                         PolicyBean policyBean = this.getPresenter().getContext().getPolicyBean();
 507  0
                         RoleAssignmentRuleBeanCollection roleAssignmentRules =
 508  
                                 policyBean.getRoleAssignmentRules();
 509  0
                         for (final RoleAssignmentRuleBean currRule : roleAssignmentRules) {
 510  0
                                 if (currRule.getAuthority().equals(activeAuthority)) {
 511  0
                                         if (showYesNoDialog("nRefsTitle", "nRefs", JOptionPane.NO_OPTION)) {
 512  0
                                                 return;
 513  
                                         }
 514  
                                         break;
 515  
                                 }
 516  
                         }
 517  0
                         getPresenter().removeActiveAuthority(activeAuthority);
 518  0
                 } else {
 519  0
                         LOGGER.debug("no part selected");
 520  
                 }
 521  0
         }
 522  
         
 523  
         /**
 524  
          * @since 0.3.0
 525  
          */
 526  
         @Action
 527  
         public void editAuthority () {
 528  0
                 LOGGER.debug("editAuthority");
 529  0
                 final AuthorityBean active = getPresenter().getActiveAuthority();
 530  0
                 if (active != null) {
 531  0
                         editPart(active);
 532  
                 }
 533  0
         }
 534  
                 
 535  
         /**
 536  
          * @since 0.3.0
 537  
          */
 538  
         @Action
 539  
         public void addSubjectDomain () {
 540  0
                 LOGGER.debug("addSubjectDomain");
 541  0
                 getPresenter().addSubjectDomain(new EditPartCommand<DomainBean>(getViewContext()));
 542  0
         }
 543  
 
 544  
         /**
 545  
          * @since 0.3.0
 546  
          */
 547  
         @Action
 548  
         public void removeSubjectDomain () {
 549  0
                 LOGGER.debug("removeSubjectDomain");
 550  0
                 DomainBean activeSubjectDomain = this.getPresenter().getActiveSubjectDomain();
 551  0
                 if (activeSubjectDomain != null) {
 552  0
                         final PolicyBean policy = this.getPresenter().getContext().getPolicyBean();
 553  0
                         final List<RoleAssignmentRuleBean> parents = 
 554  
                                 policy.getParentRoleAssignmentRules(activeSubjectDomain);
 555  0
                         if ((parents.size() > 1)
 556  
                                 && showYesNoDialog("nRefsTitle", "nRefs", JOptionPane.NO_OPTION)) {
 557  0
                                 return;
 558  
                         }
 559  0
                         getPresenter().removeActiveSubjectDomain(activeSubjectDomain);
 560  0
                 } else {
 561  0
                         LOGGER.debug("no part selected");
 562  
                 }
 563  0
         }
 564  
 
 565  
         /**
 566  
          * @since 0.3.0
 567  
          */
 568  
         @Action
 569  
         public void editSubjectDomain () {
 570  0
                 LOGGER.debug("editSubjectDomain");
 571  0
                 final DomainBean active = getPresenter().getActiveSubjectDomain();
 572  0
                 if (active != null) {
 573  0
                         editPart(active);
 574  
                 }
 575  0
         }
 576  
 
 577  
         //---- AbstractEditor
 578  
 
 579  
         /**
 580  
          * @since 0.3.0
 581  
          */
 582  
         @Override
 583  
         protected void bind (BindingGroup bindings) {
 584  0
                 bindings.addBinding(
 585  
                         SwingBindings.createJComboBoxBinding(
 586  
                                 UpdateStrategy.READ,
 587  
                                 getPresenter().getAuthorityPool().getPoolList(),
 588  
                                 this.authority
 589  
                         )
 590  
                 );
 591  0
                 bindings.addBinding(
 592  
                         Bindings.createAutoBinding(
 593  
                                 UpdateStrategy.READ_WRITE,
 594  
                                 getPresenter(),
 595  
                                 BeanProperty.create("activeAuthority"),
 596  
                                 this.authority,
 597  
                                 BeanProperty.create("selectedItem")
 598  
                         )
 599  
                 );
 600  0
                 bindings.addBinding(
 601  
                         SwingBindings.createJComboBoxBinding(
 602  
                                 UpdateStrategy.READ,
 603  
                                 getPresenter().getSubjectDomainPool().getPoolList(),
 604  
                                 this.subjectDomain
 605  
                         )
 606  
                 );
 607  0
                 bindings.addBinding(
 608  
                         Bindings.createAutoBinding(
 609  
                                 UpdateStrategy.READ_WRITE,
 610  
                                 getPresenter(),
 611  
                                 BeanProperty.create("activeSubjectDomain"),
 612  
                                 this.subjectDomain,
 613  
                                 BeanProperty.create("selectedItem")
 614  
                         )
 615  
                 );
 616  0
                 this.roleList.bind(
 617  
                         getPresenter().getRolePool().getPoolList(),
 618  
                         getPresenter().getRoles()
 619  
                 );
 620  0
                 bindings.addBinding(
 621  
                         Bindings.createAutoBinding(
 622  
                                 UpdateStrategy.READ,
 623  
                                 getPresenter(),
 624  
                                 BeanProperty.create("delegationDepth"),
 625  
                                 this.delegationDepthLabel,
 626  
                                 BeanProperty.create("text")
 627  
                         )
 628  
                 );
 629  0
                 bindings.addBinding(
 630  
                         Bindings.createAutoBinding(
 631  
                                 UpdateStrategy.READ,
 632  
                                 getPresenter(),
 633  
                                 BeanProperty.create("constraint"),
 634  
                                 this,
 635  
                                 BeanProperty.create("constraint")
 636  
                         )
 637  
                 );
 638  0
         }
 639  
 
 640  
         //---- View
 641  
         
 642  
         /**
 643  
          * @since 0.3.0
 644  
          */
 645  
         private JComponent attributeAuthority () {
 646  0
                 final FormLayout layout = new FormLayout(
 647  
                         "pref, 2dlu, fill:50dlu:grow, 2dlu, pref",
 648  
                         "pref"
 649  
                 );
 650  0
                 final JPanel panel = new JPanel();
 651  0
                 panel.setLayout(layout);
 652  0
                 final CellConstraints cc = new CellConstraints();
 653  0
                 panel.add(label("authority"), cc.xy(1, 1));
 654  0
                 panel.add(this.authority, cc.xy(3, 1));
 655  0
                 panel.add(toolBar("authorityToolBar"), cc.xy(5, 1));
 656  0
                 return panel;
 657  
         }
 658  
         
 659  
         /**
 660  
          * @since 0.3.0
 661  
          */
 662  
         private JComponent subjectDomainChooser () {
 663  0
                 final FormLayout layout = new FormLayout(
 664  
                         "pref, 2dlu, fill:50dlu:grow, 2dlu, pref",
 665  
                         "pref"
 666  
                 );
 667  0
                 final JPanel panel = new JPanel();
 668  0
                 panel.setLayout(layout);
 669  0
                 final CellConstraints cc = new CellConstraints();
 670  0
                 panel.add(label("subjectDomain"), cc.xy(1, 1));
 671  0
                 panel.add(this.subjectDomain, cc.xy(3, 1));
 672  0
                 panel.add(toolBar("subjectDomainToolBar"), cc.xy(5, 1));
 673  0
                 return panel;
 674  
         }
 675  
 
 676  
         /**
 677  
          * @since 0.3.0
 678  
          */
 679  
         private JComponent roleList () {
 680  0
                 final FormLayout layout = new FormLayout(
 681  
                         "pref, fill:pref:grow",
 682  
                         "pref, fill:pref:grow"
 683  
                 );
 684  0
                 final JPanel panel = new JPanel();
 685  0
                 panel.setLayout(layout);
 686  0
                 final CellConstraints cc = new CellConstraints();
 687  0
                 panel.add(label("roles"), cc.xy(1, 1));
 688  0
                 panel.add(toolBar("roleToolBar"), cc.xy(2, 1));
 689  0
                 this.roleList.setVisibleRowCount(5);
 690  0
                 panel.add(new JScrollPane(this.roleList), cc.xyw(1, 2, 2));
 691  0
                 return panel;
 692  
         }
 693  
 
 694  
         /**
 695  
          * @since 0.3.0
 696  
          */
 697  
         private JComponent depthAndConstraints () {
 698  0
                 final JPanel panel = new JPanel();
 699  0
                 final FormLayout layout = new FormLayout(
 700  
                         "pref, pref, 10dlu, pref, pref, 10dlu, pref, pref, 17dlu, fill:pref:grow",
 701  
                         "pref, 50dlu, pref, pref, pref, pref, pref"
 702  
                 );
 703  0
                 final CellConstraints cc = new CellConstraints();
 704  0
                 panel.setLayout(layout);
 705  
                 
 706  0
                 panel.add(label("delegationDepth"), cc.xyw(1, 1, 2));
 707  0
                 panel.add(this.delegationDepthLabel, cc.xy(4, 1));
 708  0
                 final JButton plusButton = new JButton("+");
 709  0
                 plusButton.addActionListener(new ActionListener() {
 710  0
                         public void actionPerformed (ActionEvent e) {
 711  0
                                 getPresenter().updateDelegationDepthAtModel(
 712  
                                         getPresenter().getDelegationDepth() + 1
 713  
                                 );
 714  0
                         }
 715  
                 });
 716  0
                 panel.add(plusButton, cc.xy(5, 1));
 717  0
                 final JButton minusButton = new JButton("-");
 718  0
                 minusButton.addActionListener(new ActionListener() {
 719  0
                         public void actionPerformed (ActionEvent e) {
 720  0
                                 if (getPresenter().getDelegationDepth() > 0) {
 721  0
                                         getPresenter().updateDelegationDepthAtModel(
 722  
                                                 getPresenter().getDelegationDepth() - 1
 723  
                                         );
 724  
                                 }
 725  0
                         }
 726  
                 });
 727  0
                 panel.add(minusButton, cc.xy(8, 1));
 728  
 
 729  0
                 panel.add(this.absolutePeriodCheckBox, cc.xy(1, 2));
 730  0
                 panel.add(label("absolutePeriod"), cc.xy(2, 2));
 731  0
                 panel.add(label("absolutePeriod.start"), cc.xy(4, 2));
 732  
                 
 733  0
                 panel.add(this.startDatePicker, cc.xy(5, 2));
 734  0
                 panel.add(label("absolutePeriod.end"), cc.xy(7, 2));
 735  0
                 panel.add(this.endDatePicker, cc.xy(8, 2));
 736  
                 
 737  0
                 panel.add(this.minimumFromCheckBox, cc.xy(1, 4));
 738  0
                 panel.add(label("minimumValidFrom"), cc.xy(2, 4));
 739  0
                 panel.add(this.minimumFromDatePicker, cc.xy(5, 4));
 740  
 
 741  0
                 panel.add(this.minimumUpToCheckBox, cc.xy(1, 5));
 742  0
                 panel.add(label("minimumValidUpTo"), cc.xy(2, 5));
 743  0
                 panel.add(this.minimumUpToDatePicker, cc.xy(5, 5));
 744  
 
 745  0
                 panel.add(this.maximumUpToCheckBox, cc.xy(1, 6));
 746  0
                 panel.add(label("maximumValidUpTo"), cc.xy(2, 6));
 747  0
                 panel.add(this.maximumUpToDatePicker, cc.xy(5, 6));
 748  
 
 749  0
                 panel.add(label("referenceDate"), cc.xy(2, 7));
 750  0
                 panel.add(this.referenceDatePicker, cc.xy(5, 7));
 751  
 
 752  0
                 return panel;
 753  
         }
 754  
         
 755  
         /**
 756  
          * @since 0.3.0
 757  
          */
 758  
         public void fillContentPane (JPanel panel) {
 759  0
                 final FormLayout layout = new FormLayout(
 760  
                         "8dlu, fill:min:grow, 8dlu",
 761  
                         "8dlu, pref, 8dlu, pref, 8dlu, pref, 8dlu, pref, 8dlu, fill:pref:grow, 8dlu"
 762  
                 );
 763  0
                 panel.setLayout(layout);
 764  0
                 final CellConstraints cc = new CellConstraints();
 765  0
                 this.roleList = new CheckList<Role>();
 766  0
                 this.roleList.setDoubleClickAction(getActionMap().get("editRole"));
 767  0
                 this.roleList.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
 768  0
                 panel.add(attributeAuthority(), cc.xy(2, 2));
 769  0
                 panel.add(subjectDomainChooser(), cc.xy(2, 4));
 770  0
                 panel.add(roleList(), cc.xy(2, 6));
 771  0
                 panel.add(depthAndConstraints(), cc.xy(2, 10));
 772  0
         }
 773  
 
 774  
 }