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, an instance
10   * 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 extends AbstractValidationModel {
17  
18     private static final String[] VALIDATION_PROPERTIES = { Disc.PROPERTYNAME_NAME, Disc.PROPERTYNAME_NOTES,
19              Disc.PROPERTYNAME_COVER_URL, Disc.PROPERTYNAME_GENRE, Disc.PROPERTYNAME_YEAR };
20  
21     /**
22      * Constructor that takes an Disc object.
23      * <p>
24      * @param aDisc the domain object
25      */
26     public DiscValidationModel(Disc aDisc) {
27        super(aDisc);
28     }
29  
30     /**
31      * Turns the buttons on this editor on or off based on state of the
32      * underlying ORM object. If it is modified turn these on.
33      * <p>
34      * @param enabled true to enable false to disable
35      */
36     @Override
37     public void updateButtonState(boolean enabled) {
38        this.dirty = enabled;
39  
40        ActionManager.get(Actions.COMMIT_ID).setEnabled(enabled);
41        ActionManager.get(Actions.ROLLBACK_ID).setEnabled(enabled);
42        ActionManager.get(Actions.DELETE_ID).setEnabled(enabled);
43  
44        final Disc disc = (Disc) getBean();
45        final boolean isValid = ((disc == null) ? false : disc.isValid());
46        ActionManager.get(Actions.FILE_RENAME_ID).setEnabled(isValid && enabled);
47        ActionManager.get(Actions.DISC_COVER_ID).setEnabled(isValid && enabled);
48        ActionManager.get(Actions.DISC_WEB_ID).setEnabled(isValid && enabled);
49        ActionManager.get(Actions.FREE_DB_ID).setEnabled(isValid && enabled);
50     }
51  
52     /*
53      * (non-Javadoc)
54      * @seecom.melloware.jukes.gui.view.validation.AbstractValidationModel#
55      * getPropertiesToCheck()
56      */
57     @Override
58     protected String[] getPropertiesToCheck() {
59        return VALIDATION_PROPERTIES;
60     }
61  
62     @Override
63     protected void updateValidationResult() {
64        Disc disc = (Disc) getBean();
65        ValidationResult result = new DiscValidator(disc).validate(null);
66        validationResultModel.setResult(result);
67     }
68  
69  }