001    /*
002     * Copyright 2002-2004 the original author or authors.
003     * 
004     * Licensed under the Apache License, Version 2.0 (the "License"); you may not
005     * use this file except in compliance with the License. You may obtain a copy of
006     * the License at
007     * 
008     * http://www.apache.org/licenses/LICENSE-2.0
009     * 
010     * Unless required by applicable law or agreed to in writing, software
011     * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
012     * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
013     * License for the specific language governing permissions and limitations under
014     * the License.
015     */
016    package org.springframework.richclient.command;
017    
018    import java.util.List;
019    
020    import org.apache.commons.logging.Log;
021    import org.apache.commons.logging.LogFactory;
022    import org.springframework.richclient.command.config.CommandButtonConfigurer;
023    
024    /**
025     * A member of a {@link CommandGroup}. 
026     * 
027     * <p>
028     * A command group will generally consist of command objects but may also contain other objects 
029     * such as separators or glue components used for spacing. This class is a simple wrapper around 
030     * these various types of command group members. 
031     * </p>
032     *
033     */
034    public abstract class GroupMember {
035    
036        /** Class logger, available to subclasses. */
037        protected final Log logger = LogFactory.getLog(getClass());
038    
039        /**
040         * Subclasses must implement this method to use the given container populator to add a 
041         * GUI control component to a GUI container. The actual type of the GUI control will be 
042         * determined by the type of the {@code controlFactory} provided, but it will generally be
043         * a control that a command can be associated with, such as a button or menu item.
044         *
045         * @param containerPopulator The object responsible for populating a GUI container with 
046         * an appropriate control component based on this instance. Must not be null.
047         * 
048         * @param controlFactory The factory for creating an appropriate GUI control that the underlying
049         * command will be associated with.
050         * 
051         * @param buttonConfigurer The object that is to configure the newly created control component. 
052         * 
053         * @param previousButtons A list of {@link AbstractButton} instances that have already been
054         * added to the container. May be null or empty.
055         * 
056         * @throws IllegalArgumentException if {@code containerPopulator}, {@code controlFactory}
057         * or {@code buttonConfigurer} are null.
058         */
059        protected abstract void fill(GroupContainerPopulator containerPopulator,
060                                     Object controlFactory,
061                                     CommandButtonConfigurer buttonConfigurer, 
062                                     List previousButtons);
063    
064        /**
065         * Subclasses may override this method to allow their underlying command to be enabled or disabled.
066         * @param enabled The enabled flag.
067         */
068        public abstract void setEnabled(boolean enabled);
069    
070        /**
071         * Subclasses must implement this method to indicate whether or not they manage a command
072         * with the given id. This method should also traverse nested commands if the command managed 
073         * by this member is a {@link CommandGroup}.
074         * 
075         * @param commandId The id of the command to be checked for. May be null.
076         * @return true if the command, or any of its nested commands, managed by this group member
077         * has the given command id.
078         */
079        public abstract boolean managesCommand(String commandId);
080    
081        /**
082         * Subclasses may override to return the command that they wrap.
083         *
084         * @return The wrapped command, possibly null.
085         */
086        public AbstractCommand getCommand() {
087            return null;
088        }
089    
090        /**
091         * Subclasses may override to be notified when they are added to a command group.
092         */
093        protected void onAdded() {
094            //do nothing
095        }
096    
097        /**
098         * Subclasses may override to be notified when they are removed from the group they belong to.
099         */
100        protected void onRemoved() {
101            //do nothing
102        }
103        
104    }