Announcement Announcement Module
Collapse
No announcement yet.
TargetableActionCommand Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • TargetableActionCommand

    Hi

    I want to use the ToggleCommand since I need toggable button in my toolbar. I also need to wrapp my command, which extends the ToggleCommand, in a TargetableActionCommand and then inject it into the toolbar I create. The button created will not be a JToggleButton since the TargetableActionCommand does:

    public AbstractButton createButton(String faceDescriptorId, ButtonFactory buttonFactory,
    CommandButtonConfigurer buttonConfigurer) {
    JButton button = buttonFactory.createButton();
    attach(button, faceDescriptorId, buttonConfigurer);
    return button;
    }

    My question is then. How can I get the ToggleCommand to render a JToggleButton instead of a JButton? (Can I some how controll how a command is being rendered?). I could offcause let my command be directly injected without having it being wrapped by the TargetableActionCommand but then I loss functionallity like security and such... or atleast so it seems?. My sub question then being what exactly is the TargetableActionCommand doing, which makes it neccessary.

    I first thought I could override the creatButton method in the AbstractCommand but since it is the TargetableActionCommand that is injected it want help.

    Cheers,Magnus

  • #2
    Clarification

    Ok I got how this to work now and as usually it was me not getting how the framework works...would'nt it be great with some documentation :-)

    If anybody wonders here it is.

    A TargetableActionCommand is used by the global command ids. All global command ids are defined in the command-context.xml file. So whats special about them then? We'll they are the command you see in the main windows toolbar and menus. These commands should have view specific behaivour so somehow we need to define this view specific behaivour. When a view gets in focus it need to replace the current functionallity for the global commands it has functionallity for. This can be done like this:

    public void componentFocusGained()
    {
    getContext().register(GlobalCommandIds.SELECT_ALL, new ActionCommandExecutor());
    }

    And then when it losses focus

    public void componentFocusLost()
    {
    getContext().register(GlobalCommandIds.SELECT_ALL, null);
    }

    When you set it to null the framework will disable the selection etc.

    So how should a user of the framework use this?

    We'll first of all spring rcp has a number of global command ids defined:
    public class GlobalCommandIds {
    public static final String CUT = "cutCommand";

    public static final String COPY = "copyCommand";

    public static final String PASTE = "pasteCommand";

    public static final String UNDO = "undoCommand";

    public static final String REDO = "redoCommand";

    public static final String SAVE = "saveCommand";

    public static final String SAVE_AS = "saveAsCommand";

    public static final String SELECT_ALL = "selectAllCommand";

    public static final String DELETE = "deleteCommand";

    public static final String PROPERTIES = "propertiesCommand";

    public static final String RUN = "runCommand";

    private GlobalCommandIds() {
    }
    }

    Most likely there will be more coming when the framework matures. If you wish to define your own global commands just create you command and wrap it in a TargetableActionCommand and add it to ApplicationWindowCommandManager, which is defined in the command-context.xml

    <bean id="windowCommandManager"
    class="org.springframework.richclient.application. support.ApplicationWindowCommandManager">
    <property name="sharedCommandIds">
    <list>
    <value>saveAsCommand</value>
    <value>propertiesCommand</value>
    <value>renameCommand</value>
    <value>undoCommand</value>
    <value>redoCommand</value>
    <value>cutCommand</value>
    <value>copyCommand</value>
    <value>pasteCommand</value>
    <value>selectAllCommand</value>
    <value>deleteCommand</value>
    <value>searchCommand</value>
    </list>
    </property>
    </bean>

    Now you can use that targetable command in any view/editor you have.

    Commands can also be local, which means it is not available in the main windows menu or/and toolbar. A command is a factory and can be used to create a component like JButton, JToogleButton etc. It can also be added to a command group and then the comand group can be used to rendere menus etc.

    The thing that I was looking for was a way to group commands so that only one command at the time could be active. This is easily achived by setting the propertyt "exclusive" when creating the command group:

    <bean id="thumbnailEditor.filterMenu"
    class="org.springframework.richclient.command.Comm andGroupFactoryBean">
    <property name="exclusive" value="true"/>
    <property name="securityControllerId" value="userController"/>
    <property name="members">
    <list>
    <ref bean="noFilterCommand"/>
    <ref bean="webFilterCommand"/>
    <ref bean="catalogFilterCommand"/>
    </list>
    </property>
    </bean>

    Cheers

    Magnus

    Comment

    Working...
    X