PDA

View Full Version : Global commands and TextComponentPopupInterceptorFactory


Patrick Vanhuyse
Oct 5th, 2004, 03:06 AM
In my application, I doesn't need global commands. So I removed all the defined global commands
from the command manager definition :

<bean id="commandManager" class="org.springframework.richclient.command.support.Def aultCommandManager">
<property name="globalCommandIds">
<list>
<value>startCommand</value>
<value>stopCommand</value>
<value>executeCommand</value>
</list>
</property>
</bean>

When I use the TextComponentPopupInterceptorFactory like in the Petclinic sample,
my dialog doesn't show because of a NullPointerException in org.springframework.richclient.text.TextComponentP opup :

public void registerAccelerators() {
CommandManager commandManager = getCommandManager();
Keymap keymap = textComponent.getKeymap();
ActionCommand command = commandManager.getActionCommand(
GlobalCommandIds.UNDO);
keymap.addActionForKeyStroke(command.getAccelerato r(), command.getSwingActionAdapter());
command = commandManager.getActionCommand(
GlobalCommandIds.REDO);
keymap.addActionForKeyStroke(command.getAccelerato r(), command.getSwingActionAdapter());
command = commandManager.getActionCommand(
GlobalCommandIds.COPY);
keymap.addActionForKeyStroke(command.getAccelerato r(), command.getSwingActionAdapter());
command = commandManager.getActionCommand(
GlobalCommandIds.CUT);
keymap.addActionForKeyStroke(command.getAccelerato r(), command.getSwingActionAdapter());
command = commandManager.getActionCommand(
GlobalCommandIds.PASTE);
keymap.addActionForKeyStroke(command.getAccelerato r(), command.getSwingActionAdapter());
command = commandManager.getActionCommand(
GlobalCommandIds.SELECT_ALL);
keymap.addActionForKeyStroke(command.getAccelerato r(), command.getSwingActionAdapter());
}

I put "if (command != null)" before each keymap.addActionForKeyStroke(...). My dialog shows and works but
I get a series of complaints about commands not found.

I think it would be a good idea not considering that the predifined global commands must exists. Or define
them automatically.

oliverhutchison
Oct 5th, 2004, 04:22 AM
Patrick,

I've fixed it. I think... can you test this out. You may have to wait for CVS to update.

Ollie

Patrick Vanhuyse
Oct 8th, 2004, 05:29 AM
Ollie,

It works. Great job.

Patrick