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.Track;
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 Track}.
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 TrackValidationModel extends AbstractValidationModel {
17  
18     private static final String[] VALIDATION_PROPERTIES = { Track.PROPERTYNAME_NAME, Track.PROPERTYNAME_TRACK_NUMBER,
19              Track.PROPERTYNAME_COMMENT };
20  
21     /**
22      * Constuctor that takes an Track object.
23      * <p>
24      * @param aTrack the domain object
25      */
26     public TrackValidationModel(Track aTrack) {
27        super(aTrack);
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        ActionManager.get(Actions.COMMIT_ID).setEnabled(enabled);
40        ActionManager.get(Actions.ROLLBACK_ID).setEnabled(enabled);
41        ActionManager.get(Actions.DELETE_ID).setEnabled(enabled);
42  
43        final Track track = (Track) getBean();
44        final boolean isValid = ((track == null) ? false : track.isValid());
45        ActionManager.get(Actions.FILE_RENAME_ID).setEnabled(isValid && enabled);
46     }
47  
48     /*
49      * (non-Javadoc)
50      * @seecom.melloware.jukes.gui.view.validation.AbstractValidationModel#
51      * getPropertiesToCheck()
52      */
53     @Override
54     protected String[] getPropertiesToCheck() {
55        return VALIDATION_PROPERTIES;
56     }
57  
58     @Override
59     protected void updateValidationResult() {
60        Track track = (Track) getBean();
61        ValidationResult result = new TrackValidator(track).validate(null);
62        validationResultModel.setResult(result);
63     }
64  
65  }