AnsweredAssumed Answered

Plugin - Adding Chat Toolbar Buttons - Example is wrong?

Question asked by Pulsar on Feb 3, 2009
Latest reply on Feb 17, 2009 by Pulsar

I've been trying to get my plugin to properly add buttons to ToolBar in chat windows.  I followed the example code shown in the dev guide:

 

/**
     * Adds a button to each Chat Room that is opened.
     */
    private void addChatRoomButton(){
        // Retrieve ChatManager from the SparkManager
        ChatManager chatManager = SparkManager.getChatManager();

        // Create a new ChatRoomButton.
        final ChatRoomButton button = new ChatRoomButton("Push Me");


        // Add to a new ChatRoom when the ChatRoom opens.
        chatManager.addChatRoomListener(new ChatRoomListenerAdapter() {
            public void chatRoomOpened(ChatRoom room) {
                room.getToolBar().addChatRoomButton(button);
            }

            public void chatRoomLeft(ChatRoom room) {
                room.getToolBar().removeChatRoomButton(button);
            }
        });
    }


And yes, if you run that, it does add the example button to the first chat room that you open... so it looks like the code works.

 

But then if you open another chat room, it will add the button to the new chat room, but it will no longer show up on the first chat room's toolbar.  Adding further chat rooms does the same thing.  The button will always appear on the most recently added chat room, but none of the others.

 

What's going on here?  If this method isn't the correct way to add buttons to the toolbar (and keep them there), then what is?

 

I'm using Spark 2.5.8 and Java 1.5.

Outcomes