*
* If the AlbumPresentationModel would provide a property
* bufferedComposerEnabled we could use that instead.
* I've not added the latter property to the AlbumPresentationModel
* so it remains close to the example used in Martin Fowler's
* description of the
* Presentation
* Model pattern.
*/
private void initEventHandling() {
ValueModel bufferedClassicalModel =
presentationModel.getBufferedModel(Album.PROPERTYNAME_CLASSICAL);
bufferedClassicalModel.addValueChangeListener(
new BufferedClassicalChangeHandler());
}
// Building ***************************************************************
/**
* Builds and returns a panel that consists of the editor and display.
*
* @return the built panel
*/
public JComponent build() {
initComponents();
initEventHandling();
FormLayout layout = new FormLayout(
"right:pref, 3dlu, 150dlu:grow",
"p, 3dlu, p, 3dlu, p, 3dlu, p, 3dlu, p, 17dlu, " +
"p, 3dlu, p, 3dlu, p, 3dlu, p, 3dlu, p, 17dlu, p");
PanelBuilder builder = new PanelBuilder(layout);
builder.setDefaultDialogBorder();
CellConstraints cc = new CellConstraints();
builder.addSeparator("Buffered", cc.xyw(1, 1, 3));
builder.addLabel("Title", cc.xy (1, 3));
builder.add(titleField, cc.xy (3, 3));
builder.addLabel("Artist", cc.xy (1, 5));
builder.add(artistField, cc.xy (3, 5));
builder.add(classicalBox, cc.xy (3, 7));
builder.addLabel("Composer", cc.xy (1, 9));
builder.add(composerField, cc.xy (3, 9));
builder.addSeparator("Unbuffered", cc.xyw(1, 11, 3));
builder.addLabel("Title", cc.xy (1, 13));
builder.add(unbufferedTitleField, cc.xy (3, 13));
builder.addLabel("Artist", cc.xy (1, 15));
builder.add(unbufferedArtistField, cc.xy (3, 15));
builder.add(unbufferedClassicalBox, cc.xy (3, 17));
builder.addLabel("Composer", cc.xy (1, 19));
builder.add(unbufferedComposerField, cc.xy (3, 19));
builder.add(buildButtonBar(), cc.xyw(1, 21, 3));
return builder.getPanel();
}
private JComponent buildButtonBar() {
return ButtonBarFactory.buildRightAlignedBar(
applyButton,
resetButton);
}
// Event Handling *********************************************************
/**
* Updates the composer field's enablement and contents.
* Sets the enablement according to the boolean state of
* the bufferd classical property. If the composer is not enabled,
* we copy the domain logic and set the composer to null
.
*/
private void updateComposerField() {
AbstractValueModel bufferedClassicalModel =
presentationModel.getBufferedModel(Album.PROPERTYNAME_CLASSICAL);
boolean composerEnabled = bufferedClassicalModel.booleanValue();
composerField.setEnabled(composerEnabled);
if (!composerEnabled) {
presentationModel.getBufferedModel(Album.PROPERTYNAME_COMPOSER).
setValue(null);
}
}
private class BufferedClassicalChangeHandler implements PropertyChangeListener {
/**
* The buffered (Boolean) classical property has changed.
* Updates the enablement and contents of the composer field.
*/
public void propertyChange(PropertyChangeEvent evt) {
updateComposerField();
}
}
// Actions ****************************************************************
/**
* Commits the Trigger used to buffer the editor contents.
*/
private final class ApplyAction extends AbstractAction {
private ApplyAction() {
super("Apply");
}
public void actionPerformed(ActionEvent e) {
presentationModel.triggerCommit();
}
}
/**
* Flushed the Trigger used to buffer the editor contents.
*/
private final class ResetAction extends AbstractAction {
private ResetAction() {
super("Reset");
}
public void actionPerformed(ActionEvent e) {
presentationModel.triggerFlush();
}
}
}
binding.zip( 506 k)