| View previous topic :: View next topic |
| Author |
Message |
SheldonYoung
Joined: 12 Apr 2006 Posts: 6
|
Posted: Fri Apr 28, 2006 5:38 pm Post subject: List of commands in a group |
|
|
We have a component called a taskpane, which we want to keep in sync with a command group. Receiving events the contents of the group has changed is no problem. Unfortunately, the only way we have found to get the commands in a group is by iterating over the commands in the command manager and finding out if they are in the command group. This works, but it means the commands are listed out-of-order.
Is there a way to get the commands belong to a group, in order?
| Code: |
CommandManager cmdMgr = cmdGroup.getCommandManager();
Iterator iter = cmdMgr.commandIterator();
while (iter.hasNext()) {
Object next = iter.next();
if (next instanceof Command) {
Command cmd = (Command) next;
if (cmdGroup.contains(cmd)) {
ActionCommand actionCmd = cmdMgr.getCommand(cmd.getId());
System.out.println(cmd.getId());
}
}
}
| [/code] |
|
| Back to top |
|
 |
pietschy Site Admin
Joined: 10 May 2005 Posts: 62
|
Posted: Fri Apr 28, 2006 7:14 pm Post subject: Re: List of commands in a group |
|
|
The GroupVisitor interface was intended for this stort of thing, but unfortunately CommandGroup.visitChildren(visitor) method is currently protected (for no good reason).
I've added a bug for this in the bug tracker. https://gui-commands.dev.java.net/issues/show_bug.cgi?id=39
In the mean time I think?? you should be able to create a visitor in the package org.pietschy.command that's like the following..
| Code: |
package org.pietschy.command;
public class MyGroupVisitor implements GroupVisitor
{
public void collectChildren(CommandGroup group)
{
group.visitChildren(this);
}
public void visit(ActionCommand command)
{
// visiting a action command member so add
}
public void visit(CommandGroup command)
{
// visiting a command group member.
}
}
|
|
|
| Back to top |
|
 |
SheldonYoung
Joined: 12 Apr 2006 Posts: 6
|
Posted: Fri Apr 28, 2006 8:06 pm Post subject: |
|
|
| Thanks Andrew. It's easy to live with the out-of-order commands until this is fixed in the library itself. We'll implement your work around if needed when it gets close to the time we need to make a final release. |
|
| Back to top |
|
 |
|