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