Revision: 1760 http://svn.sourceforge.net/spring-rich-c/?rev=1760&view=rev Author: jhoskens Date: 2007-05-23 00:13:07 -0700 (Wed, 23 May 2007)
Log Message: ----------- some javadoc added & formatted code Modified Paths: -------------- trunk/spring-richclient/support/src/main/java/org/springframework/richclient/command/AbstractCommand.java trunk/spring-richclient/support/src/main/java/org/springframework/richclient/command/CommandServices.java trunk/spring-richclient/support/src/main/java/org/springframework/richclient/form/builder/support/AbstractFormComponentInterceptor.java Modified: trunk/spring-richclient/support/src/main/java/org/springframework/richclient/command/AbstractCommand.java =================================================================== --- trunk/spring-richclient/support/src/main/java/org/springframework/richclient/command/AbstractCommand.java 2007-05-23 06:28:59 UTC (rev 1759) +++ trunk/spring-richclient/support/src/main/java/org/springframework/richclient/command/AbstractCommand.java 2007-05-23 07:13:07 UTC (rev 1760) @@ -48,593 +48,698 @@ import org.springframework.util.CachingMapDecorator; import org.springframework.util.StringUtils; +/** + * <p> + * Base class for commands. Extend this class by implementing the + * [EMAIL PROTECTED] #execute()} method. + * </p> + * + * <p> + * Most (if not all) commands result in a UI component. Several methods are + * provided here to deliver abstractButtons or menuItems. Configuring this + * visual aspect of the command is done by a number of + * [EMAIL PROTECTED] CommandFaceDescriptor}s. One of these will be registered as the + * default while others can be used to create a different look by providing a + * faceDescriptorId. + * </p> + * + * @see CommandFaceDescriptor + * + * @author jh + * + */ public abstract class AbstractCommand extends AbstractPropertyChangePublisher implements InitializingBean, - BeanNameAware, GuardedActionCommandExecutor, SecurityControllable { + BeanNameAware, GuardedActionCommandExecutor, SecurityControllable { - public static final String ENABLED_PROPERTY_NAME = "enabled"; + /** Property used to notify changes in the <em>enabled</em> state. */ + public static final String ENABLED_PROPERTY_NAME = "enabled"; - public static final String VISIBLE_PROPERTY_NAME = "visible"; + /** Property used to notify changes in the <em>visible</em> state. */ + public static final String VISIBLE_PROPERTY_NAME = "visible"; - private static final String DEFAULT_FACE_DESCRIPTOR_ID = "default"; + private static final String DEFAULT_FACE_DESCRIPTOR_ID = "default"; - private String id; + private String id; - private String defaultFaceDescriptorId = DEFAULT_FACE_DESCRIPTOR_ID; + private String defaultFaceDescriptorId = DEFAULT_FACE_DESCRIPTOR_ID; - private boolean enabled = true; + private boolean enabled = true; - private boolean visible = true; - - private boolean authorized = true; - - private String securityControllerId = null; + private boolean visible = true; - private Map faceButtonManagers; + private boolean authorized = true; - private CommandServices commandServices; + private String securityControllerId = null; - private CommandFaceDescriptorRegistry faceDescriptorRegistry; + private Map faceButtonManagers; - private Boolean oldEnabledState; + private CommandServices commandServices; - private Boolean oldVisibleState; + private CommandFaceDescriptorRegistry faceDescriptorRegistry; - protected AbstractCommand() { - this(null); - } + private Boolean oldEnabledState; - protected AbstractCommand(String id) { - super(); - setId(id); - addEnabledListener(new ButtonEnablingListener()); // keep track of enable state for buttons - addPropertyChangeListener(VISIBLE_PROPERTY_NAME, new ButtonVisibleListener()); // keep track of visible state for buttons - } + private Boolean oldVisibleState; - protected AbstractCommand(String id, String encodedLabel) { - this(id, new CommandFaceDescriptor(encodedLabel)); - } + /** + * Default constructor. + */ + protected AbstractCommand() { + this(null); + } - protected AbstractCommand(String id, String encodedLabel, Icon icon, String caption) { - this(id, new CommandFaceDescriptor(encodedLabel, icon, caption)); - } + /** + * Constructor providing an Id for configuration. + * + * @param id + */ + protected AbstractCommand(String id) { + super(); + setId(id); + addEnabledListener(new ButtonEnablingListener()); // keep track of + // enable state for + // buttons + addPropertyChangeListener(VISIBLE_PROPERTY_NAME, new ButtonVisibleListener()); // keep + // track + // of + // visible + // state + // for + // buttons + } - protected AbstractCommand(String id, CommandFaceDescriptor faceDescriptor) { - this(id); - if (faceDescriptor != null) { - setFaceDescriptor(faceDescriptor); - } - } + /** + * Constructor providing id and encodedLabel. A default FaceDescriptor will + * be created by passing the encodedLabel. + * + * @param id + * @param encodedLabel label to use when creating the default + * [EMAIL PROTECTED] CommandFaceDescriptor}. + */ + protected AbstractCommand(String id, String encodedLabel) { + this(id, new CommandFaceDescriptor(encodedLabel)); + } - protected AbstractCommand(String id, Map faceDescriptors) { - this(id); - setFaceDescriptors(faceDescriptors); - } + /** + * Constructor providing id and a number of parameters to create a default + * [EMAIL PROTECTED] CommandFaceDescriptor}. + * + * @param id + * @param encodedLabel label for the default [EMAIL PROTECTED] CommandFaceDescriptor}. + * @param icon icon for the default [EMAIL PROTECTED] CommandFaceDescriptor}. + * @param caption caption for the default [EMAIL PROTECTED] CommandFaceDescriptor}. + */ + protected AbstractCommand(String id, String encodedLabel, Icon icon, String caption) { + this(id, new CommandFaceDescriptor(encodedLabel, icon, caption)); + } - public String getId() { - return this.id; - } + /** + * Constructor providing an id and the default FaceDescriptor. + * + * @param id + * @param faceDescriptor the default FaceDescriptor to use. + */ + protected AbstractCommand(String id, CommandFaceDescriptor faceDescriptor) { + this(id); + if (faceDescriptor != null) { + setFaceDescriptor(faceDescriptor); + } + } - protected void setId(String id) { - if (!StringUtils.hasText(id)) { - id = null; - } - this.id = id; - } + /** + * Constructor providing an id and a number of FaceDescriptors. No default + * faceDescriptor is set. + * + * @param id + * @param faceDescriptors a map which contains <faceDescriptorId, + * faceDescriptor> pairs. + */ + protected AbstractCommand(String id, Map faceDescriptors) { + this(id); + setFaceDescriptors(faceDescriptors); + } - /** - * - * [EMAIL PROTECTED] - */ - public void setBeanName(String name) { - if (getId() == null) { - setId(name); - } - } + /** + * @return id of this Command. + */ + public String getId() { + return this.id; + } - public void setFaceDescriptor(CommandFaceDescriptor faceDescriptor) { - setFaceDescriptor(getDefaultFaceDescriptorId(), faceDescriptor); - } + /** + * Set the id. In most cases, this is provided by the constructor or through + * the beanId provided in the applicationContext. + * + * @param id + */ + protected void setId(String id) { + if (!StringUtils.hasText(id)) { + id = null; + } + this.id = id; + } - public void setFaceDescriptor(String faceDescriptorId, CommandFaceDescriptor faceDescriptor) { - getButtonManager(faceDescriptorId).setFaceDescriptor(faceDescriptor); - } + /** + * [EMAIL PROTECTED] + */ + public void setBeanName(String name) { + if (getId() == null) { + setId(name); + } + } - public void setFaceDescriptors(Map faceDescriptors) { - Assert.notNull(faceDescriptors); - Iterator it = faceDescriptors.entrySet().iterator(); - while (it.hasNext()) { - Map.Entry entry = (Map.Entry)it.next(); - String faceDescriptorId = (String)entry.getKey(); - CommandFaceDescriptor faceDescriptor = (CommandFaceDescriptor)entry.getValue(); - setFaceDescriptor(faceDescriptorId, faceDescriptor); - } - } + /** + * Set the default faceDescriptor to use for this command. + * + * @param faceDescriptor the [EMAIL PROTECTED] CommandFaceDescriptor} to use as + * default. + */ + public void setFaceDescriptor(CommandFaceDescriptor faceDescriptor) { + setFaceDescriptor(getDefaultFaceDescriptorId(), faceDescriptor); + } - public void setDefaultFaceDescriptorId(String defaultFaceDescriptorId) { - this.defaultFaceDescriptorId = defaultFaceDescriptorId; - } + /** + * Add an additional [EMAIL PROTECTED] CommandFaceDescriptor}. + * + * @param faceDescriptorId key to identify and use this faceDescriptor. + * @param faceDescriptor additional [EMAIL PROTECTED] CommandFaceDescriptor}. + */ + public void setFaceDescriptor(String faceDescriptorId, CommandFaceDescriptor faceDescriptor) { + getButtonManager(faceDescriptorId).setFaceDescriptor(faceDescriptor); + } - public void setFaceDescriptorRegistry(CommandFaceDescriptorRegistry faceDescriptorRegistry) { - this.faceDescriptorRegistry = faceDescriptorRegistry; - } + /** + * Add a number of [EMAIL PROTECTED] CommandFaceDescriptor}s to this Command. + * + * @param faceDescriptors a [EMAIL PROTECTED] Map} which contains <faceDescriptorId, + * CommandFaceDescriptor> pairs. + */ + public void setFaceDescriptors(Map faceDescriptors) { + Assert.notNull(faceDescriptors); + Iterator it = faceDescriptors.entrySet().iterator(); + while (it.hasNext()) { + Map.Entry entry = (Map.Entry) it.next(); + String faceDescriptorId = (String) entry.getKey(); + CommandFaceDescriptor faceDescriptor = (CommandFaceDescriptor) entry.getValue(); + setFaceDescriptor(faceDescriptorId, faceDescriptor); + } + } - public void setCommandServices(CommandServices services) { - this.commandServices = services; - } + /** + * Change the default FaceDescriptor. + * + * @param defaultFaceDescriptorId the id of the faceDescriptor to be used as + * default. + */ + public void setDefaultFaceDescriptorId(String defaultFaceDescriptorId) { + this.defaultFaceDescriptorId = defaultFaceDescriptorId; + } - public void setLabel(String encodedLabel) { - getOrCreateFaceDescriptor().setButtonLabelInfo(encodedLabel); - } + public void setFaceDescriptorRegistry(CommandFaceDescriptorRegistry faceDescriptorRegistry) { + this.faceDescriptorRegistry = faceDescriptorRegistry; + } - public void setLabel(CommandButtonLabelInfo label) { - getOrCreateFaceDescriptor().setLabelInfo(label); - } + public void setCommandServices(CommandServices services) { + this.commandServices = services; + } - public void setCaption(String shortDescription) { - getOrCreateFaceDescriptor().setCaption(shortDescription); - } + public void setLabel(String encodedLabel) { + getOrCreateFaceDescriptor().setButtonLabelInfo(encodedLabel); + } - public void setIcon(Icon icon) { - getOrCreateFaceDescriptor().setIcon(icon); - } + public void setLabel(CommandButtonLabelInfo label) { + getOrCreateFaceDescriptor().setLabelInfo(label); + } - public void setIconInfo(CommandButtonIconInfo iconInfo) { - getOrCreateFaceDescriptor().setIconInfo(iconInfo); - } + public void setCaption(String shortDescription) { + getOrCreateFaceDescriptor().setCaption(shortDescription); + } - /** - * Performs initialization and validation of this instance after its dependencies have been set. - * If subclasses override this method, they should begin by calling [EMAIL PROTECTED] super.afterPropertiesSet()}. - */ - public void afterPropertiesSet() { - if (getId() == null) { - logger.info("Command " + this + " has no set id; note: anonymous commands cannot be used in registries."); - } - if (this instanceof ActionCommand && !isFaceConfigured()) { - logger.warn("The face descriptor property is not yet set for action command '" + getId() - + "'; command won't render correctly until this is configured"); - } - } + public void setIcon(Icon icon) { + getOrCreateFaceDescriptor().setIcon(icon); + } - private CommandFaceDescriptor getOrCreateFaceDescriptor() { - if (!isFaceConfigured()) { - if (logger.isInfoEnabled()) { - logger.info("Lazily instantiating default face descriptor on behalf of caller to prevent npe; " - + "command is being configured manually, right?"); - } - setFaceDescriptor(new CommandFaceDescriptor()); - } - return getFaceDescriptor(); - } + public void setIconInfo(CommandButtonIconInfo iconInfo) { + getOrCreateFaceDescriptor().setIconInfo(iconInfo); + } - public String getDefaultFaceDescriptorId() { - if (!StringUtils.hasText(defaultFaceDescriptorId)) { - return DEFAULT_FACE_DESCRIPTOR_ID; - } - return defaultFaceDescriptorId; - } + /** + * Performs initialization and validation of this instance after its + * dependencies have been set. If subclasses override this method, they + * should begin by calling [EMAIL PROTECTED] super.afterPropertiesSet()}. + */ + public void afterPropertiesSet() { + if (getId() == null) { + logger.info("Command " + this + " has no set id; note: anonymous commands cannot be used in registries."); + } + if (this instanceof ActionCommand && !isFaceConfigured()) { + logger.warn("The face descriptor property is not yet set for action command '" + getId() + + "'; command won't render correctly until this is configured"); + } + } - protected CommandFaceDescriptor getFaceDescriptor() { - return getDefaultButtonManager().getFaceDescriptor(); - } + /** + * @return defaultFaceDescriptor. Create one if needed. + */ + private CommandFaceDescriptor getOrCreateFaceDescriptor() { + if (!isFaceConfigured()) { + if (logger.isInfoEnabled()) { + logger.info("Lazily instantiating default face descriptor on behalf of caller to prevent npe; " + + "command is being configured manually, right?"); + } + setFaceDescriptor(new CommandFaceDescriptor()); + } + return getFaceDescriptor(); + } - public boolean isFaceConfigured() { - return getDefaultButtonManager().isFaceConfigured(); - } + /** + * @return default faceDescriptorId. + */ + public String getDefaultFaceDescriptorId() { + if (!StringUtils.hasText(defaultFaceDescriptorId)) { + return DEFAULT_FACE_DESCRIPTOR_ID; + } + return defaultFaceDescriptorId; + } - public String getText() { - if (isFaceConfigured()) { - return getFaceDescriptor().getText(); - } - return CommandButtonLabelInfo.BLANK_BUTTON_LABEL.getText(); - } + protected CommandFaceDescriptor getFaceDescriptor() { + return getDefaultButtonManager().getFaceDescriptor(); + } - public int getMnemonic() { - if (isFaceConfigured()) { - return getFaceDescriptor().getMnemonic(); - } - return CommandButtonLabelInfo.BLANK_BUTTON_LABEL.getMnemonic(); - } + public boolean isFaceConfigured() { + return getDefaultButtonManager().isFaceConfigured(); + } - public int getMnemonicIndex() { - if (isFaceConfigured()) { - return getFaceDescriptor().getMnemonicIndex(); - } - return CommandButtonLabelInfo.BLANK_BUTTON_LABEL.getMnemonicIndex(); - } + public String getText() { + if (isFaceConfigured()) { + return getFaceDescriptor().getText(); + } + return CommandButtonLabelInfo.BLANK_BUTTON_LABEL.getText(); + } - public KeyStroke getAccelerator() { - if (isFaceConfigured()) { - return getFaceDescriptor().getAccelerator(); - } - return CommandButtonLabelInfo.BLANK_BUTTON_LABEL.getAccelerator(); - } + public int getMnemonic() { + if (isFaceConfigured()) { + return getFaceDescriptor().getMnemonic(); + } + return CommandButtonLabelInfo.BLANK_BUTTON_LABEL.getMnemonic(); + } - public CommandFaceDescriptorRegistry getFaceDescriptorRegistry() { - return faceDescriptorRegistry; - } + public int getMnemonicIndex() { + if (isFaceConfigured()) { + return getFaceDescriptor().getMnemonicIndex(); + } + return CommandButtonLabelInfo.BLANK_BUTTON_LABEL.getMnemonicIndex(); + } - protected CommandServices getCommandServices() { - if (commandServices == null) { - commandServices = (CommandServices) ApplicationServicesLocator.services().getService(CommandServices.class); - } - return this.commandServices; - } + public KeyStroke getAccelerator() { + if (isFaceConfigured()) { + return getFaceDescriptor().getAccelerator(); + } + return CommandButtonLabelInfo.BLANK_BUTTON_LABEL.getAccelerator(); + } - /** - * Set the Id of the security controller that should manage this object. - * @param controllerId Id (bean name) of the security controller - */ - public void setSecurityControllerId(String controllerId) { - this.securityControllerId = controllerId; - } + public CommandFaceDescriptorRegistry getFaceDescriptorRegistry() { + return faceDescriptorRegistry; + } - /** - * Get the id (bean name) of the security controller that should manage this object. - * @return controller id - */ - public String getSecurityControllerId() { - return securityControllerId; - } + protected CommandServices getCommandServices() { + if (commandServices == null) { + commandServices = (CommandServices) ApplicationServicesLocator.services().getService(CommandServices.class); + } + return this.commandServices; + } - /** - * Set the authorized state. Setting authorized to false will override any call - * to [EMAIL PROTECTED] #setEnabled(boolean)}. As long as this object is unauthorized, - * it can not be enabled. - * @param authorized Pass <code>true</code> if the object is to be authorized - */ - public void setAuthorized(boolean authorized) { - boolean wasAuthorized = isAuthorized(); - if (hasChanged(wasAuthorized, authorized)) { - this.authorized = authorized; - firePropertyChange(AUTHORIZED_PROPERTY, wasAuthorized, authorized); - updatedEnabledState(); - } - } - - /** - * Get the authorized state. - * @return authorized - */ - public boolean isAuthorized() { - return authorized; - } + /** + * Set the Id of the security controller that should manage this object. + * @param controllerId Id (bean name) of the security controller + */ + public void setSecurityControllerId(String controllerId) { + this.securityControllerId = controllerId; + } - /** - * Get the enabled state - * @return if the command is enabled and [EMAIL PROTECTED] #isAuthorized()} returns true - * @see #isAuthorized() - */ - public boolean isEnabled() { - return enabled && isAuthorized(); - } - - /** - * This method is called when any predicate for enabled state has changed. This implemetation fires the enabled - * changed event if the return value of [EMAIL PROTECTED] #isEnabled()} has changed. - * <p> - * Sublcasses which have an additional predicate to enabled state must call this method if the state of the - * predicate changes. - */ - protected void updatedEnabledState() { - boolean isEnabled = isEnabled(); - if(oldEnabledState == null || hasChanged(oldEnabledState.booleanValue(), isEnabled)) { - firePropertyChange(ENABLED_PROPERTY_NAME, oldEnabledState == null ? !isEnabled : oldEnabledState - .booleanValue(), isEnabled); - } - oldEnabledState = Boolean.valueOf(isEnabled); - } + /** + * Get the id (bean name) of the security controller that should manage this + * object. + * @return controller id + */ + public String getSecurityControllerId() { + return securityControllerId; + } - /** - * Set the enabled state of this command. Note that if we are currently not - * authorized, then the new value will just be recorded and no change in the - * current enabled state will be made. - * @param enabled state - */ - public void setEnabled(boolean enabled) { - if( hasChanged(this.enabled, enabled)) { - this.enabled = enabled; - updatedEnabledState(); - } - } + /** + * Set the authorized state. Setting authorized to false will override any + * call to [EMAIL PROTECTED] #setEnabled(boolean)}. As long as this object is + * unauthorized, it can not be enabled. + * @param authorized Pass <code>true</code> if the object is to be + * authorized + */ + public void setAuthorized(boolean authorized) { + boolean wasAuthorized = isAuthorized(); + if (hasChanged(wasAuthorized, authorized)) { + this.authorized = authorized; + firePropertyChange(AUTHORIZED_PROPERTY, wasAuthorized, authorized); + updatedEnabledState(); + } + } - /** - * Listener to keep track of enabled state. When enable on command changes, - * each button has to be checked and set. - */ - private class ButtonEnablingListener implements PropertyChangeListener - { - public void propertyChange(PropertyChangeEvent evt) - { - // We need to keep the buttons in sync with the command, so go through the buttons and set Enabled state. - // alternative is to add a listener to the enabled value and change buttons in that listener - // NOT redundant - boolean enabled = evt.getNewValue() == Boolean.TRUE; - Iterator it = buttonIterator(); - while (it.hasNext()) - { - AbstractButton button = (AbstractButton)it.next(); - button.setEnabled(enabled); - } - } - } + /** + * Get the authorized state. + * @return authorized + */ + public boolean isAuthorized() { + return authorized; + } - /** - * Listener to keep track of visible state. When visible on command changes, - * each button has to be checked and set. - */ - private class ButtonVisibleListener implements PropertyChangeListener - { - public void propertyChange(PropertyChangeEvent evt) - { - // We need to keep the buttons in sync with the command, so go through the buttons and set visible state. - // alternative is to add a listener to the visible value and change buttons in that listener - // NOT redundant - boolean enabled = evt.getNewValue() == Boolean.TRUE; - Iterator it = buttonIterator(); - while (it.hasNext()) - { - AbstractButton button = (AbstractButton)it.next(); - button.setVisible(enabled); - } - } - } + /** + * Get the enabled state + * @return if the command is enabled and [EMAIL PROTECTED] #isAuthorized()} returns + * true + * @see #isAuthorized() + */ + public boolean isEnabled() { + return enabled && isAuthorized(); + } - public void addEnabledListener(PropertyChangeListener listener) { - addPropertyChangeListener(ENABLED_PROPERTY_NAME, listener); - } + /** + * This method is called when any predicate for enabled state has changed. + * This implemetation fires the enabled changed event if the return value of + * [EMAIL PROTECTED] #isEnabled()} has changed. + * <p> + * Sublcasses which have an additional predicate to enabled state must call + * this method if the state of the predicate changes. + */ + protected void updatedEnabledState() { + boolean isEnabled = isEnabled(); + if (oldEnabledState == null || hasChanged(oldEnabledState.booleanValue(), isEnabled)) { + firePropertyChange(ENABLED_PROPERTY_NAME, oldEnabledState == null ? !isEnabled : oldEnabledState + .booleanValue(), isEnabled); + } + oldEnabledState = Boolean.valueOf(isEnabled); + } - public void removeEnabledListener(PropertyChangeListener listener) { - removePropertyChangeListener(ENABLED_PROPERTY_NAME, listener); - } + /** + * Set the enabled state of this command. Note that if we are currently not + * authorized, then the new value will just be recorded and no change in the + * current enabled state will be made. + * @param enabled state + */ + public void setEnabled(boolean enabled) { + if (hasChanged(this.enabled, enabled)) { + this.enabled = enabled; + updatedEnabledState(); + } + } - protected final Iterator defaultButtonIterator() { - return getDefaultButtonManager().iterator(); - } - - protected final Iterator buttonIterator() { - - if (this.faceButtonManagers == null) - return Collections.EMPTY_SET.iterator(); - - return new NestedButtonIterator(this.faceButtonManagers.values().iterator()); - } - - private static final class NestedButtonIterator implements Iterator - { - private final Iterator managerIterator; - private Iterator currentButtonIterator; - private AbstractButton nextButton; - - NestedButtonIterator(Iterator it) - { - this.managerIterator = it; - preFetchNextButton(); - } - - public boolean hasNext() - { - return nextButton != null; - } + /** + * Listener to keep track of enabled state. When enable on command changes, + * each button has to be checked and set. + */ + private class ButtonEnablingListener implements PropertyChangeListener { + public void propertyChange(PropertyChangeEvent evt) { + // We need to keep the buttons in sync with the command, so go + // through the buttons and set Enabled state. + // alternative is to add a listener to the enabled value and change + // buttons in that listener + // NOT redundant + boolean enabled = evt.getNewValue() == Boolean.TRUE; + Iterator it = buttonIterator(); + while (it.hasNext()) { + AbstractButton button = (AbstractButton) it.next(); + button.setEnabled(enabled); + } + } + } - public Object next() - { - if (nextButton == null) { - throw new NoSuchElementException(); - } - AbstractButton lastButton = nextButton; - preFetchNextButton(); - return lastButton; - } + /** + * Listener to keep track of visible state. When visible on command changes, + * each button has to be checked and set. + */ + private class ButtonVisibleListener implements PropertyChangeListener { + public void propertyChange(PropertyChangeEvent evt) { + // We need to keep the buttons in sync with the command, so go + // through the buttons and set visible state. + // alternative is to add a listener to the visible value and change + // buttons in that listener + // NOT redundant + boolean enabled = evt.getNewValue() == Boolean.TRUE; + Iterator it = buttonIterator(); + while (it.hasNext()) { + AbstractButton button = (AbstractButton) it.next(); + button.setVisible(enabled); + } + } + } - public void remove() - { - throw new UnsupportedOperationException("Can't use a button-iterator on AbstractCommand to remove buttons."); - } - - private void preFetchNextButton() - { - while (this.currentButtonIterator == null || !this.currentButtonIterator.hasNext()) - { - if (this.managerIterator.hasNext()){ - CommandFaceButtonManager cfbm = (CommandFaceButtonManager)this.managerIterator.next(); - this.currentButtonIterator = cfbm.iterator(); - } - else - { - this.currentButtonIterator = null; - this.nextButton = null; - return; - } - } - - if (this.currentButtonIterator.hasNext()) - nextButton = (AbstractButton)this.currentButtonIterator.next(); - else - nextButton = null; - } - } - + public void addEnabledListener(PropertyChangeListener listener) { + addPropertyChangeListener(ENABLED_PROPERTY_NAME, listener); + } - public boolean isAnonymous() { - return id == null; - } + public void removeEnabledListener(PropertyChangeListener listener) { + removePropertyChangeListener(ENABLED_PROPERTY_NAME, listener); + } - public boolean isVisible() { - return this.visible; - } + protected final Iterator defaultButtonIterator() { + return getDefaultButtonManager().iterator(); + } - public void setVisible(boolean value) { - if (visible != value) { - this.visible = value; - updatedVisibleState(); - } - } - - /** - * This method is called when any predicate for visible state has changed. This implemetation fires the visible - * changed event if the return value of [EMAIL PROTECTED] #isVisible()} has changed. - * <p> - * Sublcasses which have an additional predicate to visible state must call this method if the state of the - * predicate changes. - */ - protected void updatedVisibleState() { - boolean isVisible = isVisible(); - if(oldVisibleState == null || hasChanged(oldVisibleState.booleanValue(), isVisible)) { - firePropertyChange(VISIBLE_PROPERTY_NAME, oldVisibleState == null ? !isVisible : oldVisibleState.booleanValue(), isVisible); - } - oldVisibleState = Boolean.valueOf(isVisible); - } + protected final Iterator buttonIterator() { - public final AbstractButton createButton() { - return createButton(getDefaultFaceDescriptorId(), getButtonFactory(), getDefaultButtonConfigurer()); - } + if (this.faceButtonManagers == null) + return Collections.EMPTY_SET.iterator(); - public final AbstractButton createButton(String faceDescriptorId) { - return createButton(faceDescriptorId, getButtonFactory(), getDefaultButtonConfigurer()); - } + return new NestedButtonIterator(this.faceButtonManagers.values().iterator()); + } - public final AbstractButton createButton(ButtonFactory buttonFactory) { - return createButton(getDefaultFaceDescriptorId(), buttonFactory, getDefaultButtonConfigurer()); - } + private static final class NestedButtonIterator implements Iterator { + private final Iterator managerIterator; - public final AbstractButton createButton(String faceDescriptorId, ButtonFactory buttonFactory) { - return createButton(faceDescriptorId, buttonFactory, getDefaultButtonConfigurer()); - } + private Iterator currentButtonIterator; - public final AbstractButton createButton(ButtonFactory buttonFactory, CommandButtonConfigurer buttonConfigurer) { - return createButton(getDefaultFaceDescriptorId(), buttonFactory, buttonConfigurer); - } + private AbstractButton nextButton; - public AbstractButton createButton(String faceDescriptorId, ButtonFactory buttonFactory, - CommandButtonConfigurer buttonConfigurer) { - JButton button = buttonFactory.createButton(); - attach(button, faceDescriptorId, buttonConfigurer); - return button; - } + NestedButtonIterator(Iterator it) { + this.managerIterator = it; + preFetchNextButton(); + } - public final JMenuItem createMenuItem() { - return createMenuItem(getDefaultFaceDescriptorId(), getMenuFactory(), getMenuItemButtonConfigurer()); - } + public boolean hasNext() { + return nextButton != null; + } - public final JMenuItem createMenuItem(String faceDescriptorId) { - return createMenuItem(faceDescriptorId, getMenuFactory(), getMenuItemButtonConfigurer()); - } + public Object next() { + if (nextButton == null) { + throw new NoSuchElementException(); + } + AbstractButton lastButton = nextButton; + preFetchNextButton(); + return lastButton; + } - public final JMenuItem createMenuItem(MenuFactory menuFactory) { - return createMenuItem(getDefaultFaceDescriptorId(), menuFactory, getMenuItemButtonConfigurer()); - } + public void remove() { + throw new UnsupportedOperationException("Can't use a button-iterator on AbstractCommand to remove buttons."); + } - public final JMenuItem createMenuItem(String faceDescriptorId, MenuFactory menuFactory) { - return createMenuItem(faceDescriptorId, menuFactory, getMenuItemButtonConfigurer()); - } + private void preFetchNextButton() { + while (this.currentButtonIterator == null || !this.currentButtonIterator.hasNext()) { + if (this.managerIterator.hasNext()) { + CommandFaceButtonManager cfbm = (CommandFaceButtonManager) this.managerIterator.next(); + this.currentButtonIterator = cfbm.iterator(); + } + else { + this.currentButtonIterator = null; + this.nextButton = null; + return; + } + } - public final JMenuItem createMenuItem(MenuFactory menuFactory, CommandButtonConfigurer buttonConfigurer) { - return createMenuItem(getDefaultFaceDescriptorId(), menuFactory, buttonConfigurer); - } + if (this.currentButtonIterator.hasNext()) + nextButton = (AbstractButton) this.currentButtonIterator.next(); + else + nextButton = null; + } + } - public JMenuItem createMenuItem(String faceDescriptorId, MenuFactory menuFactory, - CommandButtonConfigurer buttonConfigurer) { - JMenuItem menuItem = menuFactory.createMenuItem(); - attach(menuItem, faceDescriptorId, buttonConfigurer); - return menuItem; - } + public boolean isAnonymous() { + return id == null; + } - public void attach(AbstractButton button) { - attach(button, getDefaultFaceDescriptorId(), getCommandServices().getDefaultButtonConfigurer()); - } + public boolean isVisible() { + return this.visible; + } - public void attach(AbstractButton button, CommandButtonConfigurer configurer) { - attach(button, getDefaultFaceDescriptorId(), configurer); - } + public void setVisible(boolean value) { + if (visible != value) { + this.visible = value; + updatedVisibleState(); + } + } - public void attach(AbstractButton button, String faceDescriptorId, CommandButtonConfigurer configurer) { - getButtonManager(faceDescriptorId).attachAndConfigure(button, configurer); - onButtonAttached(button); - } + /** + * This method is called when any predicate for visible state has changed. + * This implemetation fires the visible changed event if the return value of + * [EMAIL PROTECTED] #isVisible()} has changed. + * <p> + * Sublcasses which have an additional predicate to visible state must call + * this method if the state of the predicate changes. + */ + protected void updatedVisibleState() { + boolean isVisible = isVisible(); + if (oldVisibleState == null || hasChanged(oldVisibleState.booleanValue(), isVisible)) { + firePropertyChange(VISIBLE_PROPERTY_NAME, oldVisibleState == null ? !isVisible : oldVisibleState + .booleanValue(), isVisible); + } + oldVisibleState = Boolean.valueOf(isVisible); + } - protected void onButtonAttached(AbstractButton button) { - if (logger.isDebugEnabled()) { - logger.debug("Configuring newly attached button for command '" + getId() + "' enabled=" + isEnabled() - + ", visible=" + isVisible()); - } - button.setEnabled(isEnabled()); - button.setVisible(isVisible()); - } + public final AbstractButton createButton() { + return createButton(getDefaultFaceDescriptorId(), getButtonFactory(), getDefaultButtonConfigurer()); + } - public void detach(AbstractButton button) { - if (getDefaultButtonManager().isAttachedTo(button)) { - getDefaultButtonManager().detach(button); - onButtonDetached(); - } - } + public final AbstractButton createButton(String faceDescriptorId) { + return createButton(faceDescriptorId, getButtonFactory(), getDefaultButtonConfigurer()); + } - public boolean isAttached(AbstractButton b) { - return getDefaultButtonManager().isAttachedTo(b); - } + public final AbstractButton createButton(ButtonFactory buttonFactory) { + return createButton(getDefaultFaceDescriptorId(), buttonFactory, getDefaultButtonConfigurer()); + } - protected void onButtonDetached() { - // default no op, subclasses may override - } + public final AbstractButton createButton(String faceDescriptorId, ButtonFactory buttonFactory) { + return createButton(faceDescriptorId, buttonFactory, getDefaultButtonConfigurer()); + } - private CommandFaceButtonManager getDefaultButtonManager() { - return getButtonManager(getDefaultFaceDescriptorId()); - } + public final AbstractButton createButton(ButtonFactory buttonFactory, CommandButtonConfigurer buttonConfigurer) { + return createButton(getDefaultFaceDescriptorId(), buttonFactory, buttonConfigurer); + } - private CommandFaceButtonManager getButtonManager(String faceDescriptorId) { - if (this.faceButtonManagers == null) { - this.faceButtonManagers = new CachingMapDecorator() { - protected Object create(Object key) { - return new CommandFaceButtonManager(AbstractCommand.this, (String)key); - } - }; - } - CommandFaceButtonManager m = (CommandFaceButtonManager)this.faceButtonManagers.get(faceDescriptorId); - return m; - } + public AbstractButton createButton(String faceDescriptorId, ButtonFactory buttonFactory, + CommandButtonConfigurer buttonConfigurer) { + JButton button = buttonFactory.createButton(); + attach(button, faceDescriptorId, buttonConfigurer); + return button; + } - protected CommandButtonConfigurer getDefaultButtonConfigurer() { - return getCommandServices().getDefaultButtonConfigurer(); - } + public final JMenuItem createMenuItem() { + return createMenuItem(getDefaultFaceDescriptorId(), getMenuFactory(), getMenuItemButtonConfigurer()); + } - protected CommandButtonConfigurer getToolBarButtonConfigurer() { - return getCommandServices().getToolBarButtonConfigurer(); - } + public final JMenuItem createMenuItem(String faceDescriptorId) { + return createMenuItem(faceDescriptorId, getMenuFactory(), getMenuItemButtonConfigurer()); + } - protected CommandButtonConfigurer getMenuItemButtonConfigurer() { - return getCommandServices().getMenuItemButtonConfigurer(); - } + public final JMenuItem createMenuItem(MenuFactory menuFactory) { + return createMenuItem(getDefaultFaceDescriptorId(), menuFactory, getMenuItemButtonConfigurer()); + } - protected ButtonFactory getButtonFactory() { - return getCommandServices().getButtonFactory(); - } + public final JMenuItem createMenuItem(String faceDescriptorId, MenuFactory menuFactory) { + return createMenuItem(faceDescriptorId, menuFactory, getMenuItemButtonConfigurer()); + } - protected MenuFactory getMenuFactory() { - return getCommandServices().getMenuFactory(); - } + public final JMenuItem createMenuItem(MenuFactory menuFactory, CommandButtonConfigurer buttonConfigurer) { + return createMenuItem(getDefaultFaceDescriptorId(), menuFactory, buttonConfigurer); + } - public boolean requestFocusIn(Container container) { - AbstractButton button = getButtonIn(container); - if (button != null) { - return button.requestFocusInWindow(); - } - return false; - } + public JMenuItem createMenuItem(String faceDescriptorId, MenuFactory menuFactory, + CommandButtonConfigurer buttonConfigurer) { + JMenuItem menuItem = menuFactory.createMenuItem(); + attach(menuItem, faceDescriptorId, buttonConfigurer); + return menuItem; + } - public AbstractButton getButtonIn(Container container) { - Iterator it = buttonIterator(); - while (it.hasNext()) { - AbstractButton button = (AbstractButton)it.next(); - if (SwingUtilities.isDescendingFrom(button, container)) { - return button; - } - } - return null; - } + public void attach(AbstractButton button) { + attach(button, getDefaultFaceDescriptorId(), getCommandServices().getDefaultButtonConfigurer()); + } - public String toString() { - return new ToStringCreator(this).append("id", getId()).append("enabled", enabled).append("visible", visible) - .append("defaultFaceDescriptorId", defaultFaceDescriptorId).toString(); - } + public void attach(AbstractButton button, CommandButtonConfigurer configurer) { + attach(button, getDefaultFaceDescriptorId(), configurer); + } + public void attach(AbstractButton button, String faceDescriptorId, CommandButtonConfigurer configurer) { + getButtonManager(faceDescriptorId).attachAndConfigure(button, configurer); + onButtonAttached(button); + } + + protected void onButtonAttached(AbstractButton button) { + if (logger.isDebugEnabled()) { + logger.debug("Configuring newly attached button for command '" + getId() + "' enabled=" + isEnabled() + + ", visible=" + isVisible()); + } + button.setEnabled(isEnabled()); + button.setVisible(isVisible()); + } + + public void detach(AbstractButton button) { + if (getDefaultButtonManager().isAttachedTo(button)) { + getDefaultButtonManager().detach(button); + onButtonDetached(); + } + } + + public boolean isAttached(AbstractButton b) { + return getDefaultButtonManager().isAttachedTo(b); + } + + protected void onButtonDetached() { + // default no op, subclasses may override + } + + private CommandFaceButtonManager getDefaultButtonManager() { + return getButtonManager(getDefaultFaceDescriptorId()); + } + + private CommandFaceButtonManager getButtonManager(String faceDescriptorId) { + if (this.faceButtonManagers == null) { + this.faceButtonManagers = new CachingMapDecorator() { + protected Object create(Object key) { + return new CommandFaceButtonManager(AbstractCommand.this, (String) key); + } + }; + } + CommandFaceButtonManager m = (CommandFaceButtonManager) this.faceButtonManagers.get(faceDescriptorId); + return m; + } + + protected CommandButtonConfigurer getDefaultButtonConfigurer() { + return getCommandServices().getDefaultButtonConfigurer(); + } + + protected CommandButtonConfigurer getToolBarButtonConfigurer() { + return getCommandServices().getToolBarButtonConfigurer(); + } + + protected CommandButtonConfigurer getMenuItemButtonConfigurer() { + return getCommandServices().getMenuItemButtonConfigurer(); + } + + protected ButtonFactory getButtonFactory() { + return getCommandServices().getButtonFactory(); + } + + protected MenuFactory getMenuFactory() { + return getCommandServices().getMenuFactory(); + } + + public boolean requestFocusIn(Container container) { + AbstractButton button = getButtonIn(container); + if (button != null) { + return button.requestFocusInWindow(); + } + return false; + } + + public AbstractButton getButtonIn(Container container) { + Iterator it = buttonIterator(); + while (it.hasNext()) { + AbstractButton button = (AbstractButton) it.next(); + if (SwingUtilities.isDescendingFrom(button, container)) { + return button; + } + } + return null; + } + + public String toString() { + return new ToStringCreator(this).append("id", getId()).append("enabled", enabled).append("visible", visible) + .append("defaultFaceDescriptorId", defaultFaceDescriptorId).toString(); + } + } \ No newline at end of file Modified: trunk/spring-richclient/support/src/main/java/org/springframework/richclient/command/CommandServices.java =================================================================== --- trunk/spring-richclient/support/src/main/java/org/springframework/richclient/command/CommandServices.java 2007-05-23 06:28:59 UTC (rev 1759) +++ trunk/spring-richclient/support/src/main/java/org/springframework/richclient/command/CommandServices.java 2007-05-23 07:13:07 UTC (rev 1760) @@ -20,6 +20,9 @@ import org.springframework.richclient.factory.MenuFactory; /** + * This service delivers the necessary factories and configurers to use with + * commands. + * * @author Keith Donald */ public interface CommandServices { Modified: trunk/spring-richclient/support/src/main/java/org/springframework/richclient/form/builder/support/AbstractFormComponentInterceptor.java =================================================================== --- trunk/spring-richclient/support/src/main/java/org/springframework/richclient/form/builder/support/AbstractFormComponentInterceptor.java 2007-05-23 06:28:59 UTC (rev 1759) +++ trunk/spring-richclient/support/src/main/java/org/springframework/richclient/form/builder/support/AbstractFormComponentInterceptor.java 2007-05-23 07:13:07 UTC (rev 1760) @@ -14,35 +14,46 @@ import org.springframework.util.Assert; /** + * Abstract base for + * [EMAIL PROTECTED] org.springframework.richclient.form.builder.FormComponentInterceptorFactory} + * with formModel handling. + * * @author oliverh */ public abstract class AbstractFormComponentInterceptor implements FormComponentInterceptor { - private final FormModel formModel; + private final FormModel formModel; - protected AbstractFormComponentInterceptor() { - formModel = null; - } + protected AbstractFormComponentInterceptor() { + formModel = null; + } - protected AbstractFormComponentInterceptor(FormModel formModel) { - Assert.notNull(formModel); - this.formModel = formModel; - } + protected AbstractFormComponentInterceptor(FormModel formModel) { + Assert.notNull(formModel); + this.formModel = formModel; + } - protected FormModel getFormModel() { - return formModel; - } + protected FormModel getFormModel() { + return formModel; + } - public void processLabel(String propertyName, JComponent label) { - } + public void processLabel(String propertyName, JComponent label) { + } - public void processComponent(String propertyName, JComponent component) { - } + public void processComponent(String propertyName, JComponent component) { + } - protected JComponent getInnerComponent(JComponent component) { - if (component instanceof JScrollPane) { - return (JComponent)((JScrollPane)component).getViewport().getView(); - } - return component; - } + /** + * Check for JScrollPane. + * + * @param component + * @return the component itself, or the inner component if it was a + * JScrollPane. + */ + protected JComponent getInnerComponent(JComponent component) { + if (component instanceof JScrollPane) { + return (JComponent) ((JScrollPane) component).getViewport().getView(); + } + return component; + } } \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. ------------------------------------------------------------------------- This SF.net email is sponsored by DB2 Express Download DB2 Express C - the FREE version of DB2 express and take control of your XML. No limits. Just data. Click to get it now. http://sourceforge.net/powerbar/db2/ _______________________________________________ spring-rich-c-cvs mailing list spring-rich-c-cvs@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/spring-rich-c-cvs