www.pietschy.com Forum Index www.pietschy.com

 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

List of commands in a group

 
Post new topic   Reply to topic    www.pietschy.com Forum Index -> Version 1.x
View previous topic :: View next topic  
Author Message
SheldonYoung



Joined: 12 Apr 2006
Posts: 6

PostPosted: Fri Apr 28, 2006 5:38 pm    Post subject: List of commands in a group Reply with quote

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
View user's profile Send private message
pietschy
Site Admin


Joined: 10 May 2005
Posts: 62

PostPosted: Fri Apr 28, 2006 7:14 pm    Post subject: Re: List of commands in a group Reply with quote

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
View user's profile Send private message
SheldonYoung



Joined: 12 Apr 2006
Posts: 6

PostPosted: Fri Apr 28, 2006 8:06 pm    Post subject: Reply with quote

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
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    www.pietschy.com Forum Index -> Version 1.x All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group