View Javadoc

1   package com.melloware.jukes.gui.view.validation;
2   
3   import com.jgoodies.uif.action.ActionManager;
4   import com.jgoodies.validation.ValidationResult;
5   import com.melloware.jukes.db.orm.Disc;
6   import com.melloware.jukes.gui.tool.Actions;
7   
8   /**
9    * Provides all models to bind an artist editor to its domain model,
10   * an instance of {@link Disc}.
11   * <p>
12   * Copyright (c) 1999-2007 Melloware, Inc. <http://www.melloware.com>
13   * @author Emil A. Lefkof III <info@melloware.com>
14   * @version 4.0
15   */
16  public final class DiscValidationModel
17      extends AbstractValidationModel {
18  
19      private static final String[] VALIDATION_PROPERTIES = {
20          Disc.PROPERTYNAME_NAME, Disc.PROPERTYNAME_NOTES, Disc.PROPERTYNAME_COVER_URL, Disc.PROPERTYNAME_GENRE,
21          Disc.PROPERTYNAME_YEAR
22      };
23  
24      /**
25       * Constuctor that takes an Disc object.
26       * <p>
27       * @param aDisc the domain object
28       */
29      public DiscValidationModel(Disc aDisc) {
30          super(aDisc);
31      }
32  
33      /**
34       * Turns the buttons on this editor on or off based on state of the
35       * underlying ORM object.  If it is modified turn these on.
36       * <p>
37       * @param enabled true to enable false to disable
38       */
39      public void updateButtonState(boolean enabled) {
40          this.dirty = enabled;
41  
42          ActionManager.get(Actions.COMMIT_ID).setEnabled(enabled);
43          ActionManager.get(Actions.ROLLBACK_ID).setEnabled(enabled);
44          ActionManager.get(Actions.DELETE_ID).setEnabled(enabled);
45  
46          final Disc disc = (Disc)getBean();
47          final boolean isValid = ((disc == null) ? false : disc.isValid());
48          ActionManager.get(Actions.FILE_RENAME_ID).setEnabled(isValid && enabled);
49          ActionManager.get(Actions.DISC_COVER_ID).setEnabled(isValid && enabled);
50          ActionManager.get(Actions.DISC_WEB_ID).setEnabled(isValid && enabled);
51      }
52  
53      /* (non-Javadoc)
54       * @see com.melloware.jukes.gui.view.validation.AbstractValidationModel#getPropertiesToCheck()
55       */
56      protected String[] getPropertiesToCheck() {
57          return VALIDATION_PROPERTIES;
58      }
59  
60      protected void updateValidationResult() {
61          Disc disc = (Disc)getBean();
62          ValidationResult result = new DiscValidator(disc).validate();
63          validationResultModel.setResult(result);
64      }
65  
66  }