001    package org.springframework.richclient.command;
002    
003    import javax.swing.JComponent;
004    
005    /**
006     * CommandGroupComponentBuilder is a s-pecial case of the
007     * {@link org.springframework.richclient.command.CommandGroupModelBuilder}that
008     * is specifically designed to build swing GUI components based on the passed in
009     * command-group.
010     * 
011     * Basically it wraps the buildXXXModel method hierarchy of the
012     * {@link org.springframework.richclient.command.CommandGroupModelBuilder}into
013     * a buildXXXComponent structure that does the necessary typecasting allong the
014     * way.
015     * 
016     * @see org.springframework.richclient.command.CommandGroupModelBuilder
017     */
018    public abstract class CommandGroupJComponentBuilder extends CommandGroupModelBuilder
019    {
020    
021        /**
022         * JComponent-building variant of the
023         * {@link CommandGroupModelBuilder#buildModel(CommandGroup)}
024         */
025        public JComponent buildComponent(CommandGroup commandGroup)
026        {
027            return (JComponent) buildModel(commandGroup);
028        }
029    
030        /**
031         * JComponent-building variant of the
032         * {@link CommandGroupModelBuilder#buildRootModel(CommandGroup)}
033         */
034        protected abstract JComponent buildRootComponent(AbstractCommand command);
035    
036        /**
037         * JComponent-building variant of the
038         * {@link CommandGroupModelBuilder#buildChildModel(Object, AbstractCommand, int)}
039         */
040        protected abstract JComponent buildChildComponent(JComponent parentComponent, AbstractCommand command,
041                int level);
042    
043        /**
044         * JComponent-building variant of the
045         * {@link CommandGroupModelBuilder#buildGroupModel(Object, CommandGroup, int)}
046         */
047        protected abstract JComponent buildGroupComponent(JComponent parentComponent, CommandGroup command,
048                int level);
049    
050        /**
051         * Implementation wrapping around the
052         * {@link #buildRootComponent(AbstractCommand)}
053         */
054        protected final Object buildRootModel(CommandGroup commandGroup)
055        {
056            return buildRootComponent(commandGroup);
057        }
058    
059        /**
060         * Implementation wrapping around the
061         * {@link #buildGroupComponent(JComponent, CommandGroup, int)}
062         */
063        protected final Object buildGroupModel(Object parentModel, CommandGroup commandGroup, int level)
064        {
065            return buildGroupComponent((JComponent) parentModel, commandGroup, level);
066        }
067    
068        /**
069         * Implementation wrapping around the
070         * {@link #buildChildComponent(JComponent, AbstractCommand, int)dModel(AbstractCommand)}
071         */
072        protected final Object buildChildModel(Object parentModel, AbstractCommand command, int level)
073        {
074            return buildChildComponent((JComponent) parentModel, command, level);
075        }
076    }
077