Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Rich Client Platform (RCP) » Change Text of Toolbar button
icon5.gif  Change Text of Toolbar button [message #509451] Fri, 22 January 2010 13:26 Go to next message
T. Wilhelm is currently offline T. WilhelmFriend
Messages: 129
Registered: July 2009
Senior Member
Hey all,

i have the following problem: I have a view and added some buttons to the toolbar of the view. Now i want that the text of the buttons changing when the button was pressed, i.e. the text of the button is "login" and after pressing the button, the text should be "logout". I tried to use the IElementupdater, but i have the problem that my button is disappearing when i press it. I also added the Command to my Filemenu, there it works properly. What can i do? Here is the simple Handler code:

public class TestHandler extends AbstractHandler implements IElementUpdater {
    @Override
    public Object execute( ExecutionEvent event) throws ExecutionException {
        System.out.println("TestHandler.execute()");
        return null;
    }
    @Override
    public void updateElement( UIElement element, Map parameters) {
        element.setText("Another text");
    }
}



Thanks a lot.
Thomas
Re: Change Text of Toolbar button [message #509917 is a reply to message #509451] Mon, 25 January 2010 18:47 Go to previous messageGo to next message
Paul Webster is currently offline Paul WebsterFriend
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

T. Wilhelm wrote:
> Hey all,
>
> i have the following problem: I have a view and added some buttons to
> the toolbar of the view. Now i want that the text of the buttons
> changing when the button was pressed, i.e. the text of the button is
> "login" and after pressing the button, the text should be "logout". I
> tried to use the IElementupdater, but i have the problem that my button
> is disappearing when i press it. I also added the Command to my
> Filemenu, there it works properly. What can i do? Here is the simple
> Handler code:
>
>
> public class TestHandler extends AbstractHandler implements
> IElementUpdater {
> @Override
> public Object execute( ExecutionEvent event) throws ExecutionException {
> System.out.println("TestHandler.execute()");
> return null;
> }
> @Override
> public void updateElement( UIElement element, Map parameters) {
> element.setText("Another text");
> }
> }

I think you're seeing a layout problem. What if you try starting with
"loginhexadecimal" and then switch to "logout"?

PW


--
Paul Webster
http://wiki.eclipse.org/Platform_Command_Framework
http://wiki.eclipse.org/Command_Core_Expressions
http://wiki.eclipse.org/Menu_Contributions
http://wiki.eclipse.org/Menus_Extension_Mapping
http://help.eclipse.org/galileo/index.jsp?topic=/org.eclipse .platform.doc.isv/guide/workbench.htm


Re: Change Text of Toolbar button [message #510023 is a reply to message #509917] Tue, 26 January 2010 09:31 Go to previous messageGo to next message
T. Wilhelm is currently offline T. WilhelmFriend
Messages: 129
Registered: July 2009
Senior Member
Hi Paul,

i also thought about a Layout problem, and so i tried it like you mentioned with "LoginHexadecimal" and "Logout". Well it worked, but thats no adequate solution or workaround.

Ok i got it, i got the toolbar of my view and called upate(). Now it works.

Thanks alot
Thomas

[Updated on: Tue, 26 January 2010 09:40]

Report message to a moderator

Re: Change Text of Toolbar button [message #510072 is a reply to message #510023] Tue, 26 January 2010 13:10 Go to previous messageGo to next message
Paul Webster is currently offline Paul WebsterFriend
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

T. Wilhelm wrote:
> Hi Paul,
>
> i also thought about a Layout problem, and so i tried it like you
> mentioned with "LoginHexadecimal" and "Logout". Well it worked, but
> thats no adequate solution or workaround. Is there a way to force the
> toolbar to layout() again ? Any other idea?

This is an existing bug, https://bugs.eclipse.org/bugs/show_bug.cgi?id=97522

One thing you could try is to update the actionbars:
IActionBars bars = viewPart.getViewSite().getActionBars();
bars.updateActionBars();

That does try to do a re-layout, but not always successfully.

--
Paul Webster
http://wiki.eclipse.org/Platform_Command_Framework
http://wiki.eclipse.org/Command_Core_Expressions
http://wiki.eclipse.org/Menu_Contributions
http://wiki.eclipse.org/Menus_Extension_Mapping
http://help.eclipse.org/galileo/index.jsp?topic=/org.eclipse .platform.doc.isv/guide/workbench.htm


Re: Change Text of Toolbar button [message #510305 is a reply to message #510072] Wed, 27 January 2010 08:03 Go to previous message
T. Wilhelm is currently offline T. WilhelmFriend
Messages: 129
Registered: July 2009
Senior Member
Hi Paul,

thanks again for your answer, i already used the code you´ve mentioned, and until now it works proper and bug-free Wink

It is a little bit unbeautiful, that the size of the button changes, but we can live with that fact.

Thanks + have a great day,

Thomas
Previous Topic:Is there a view that shows memory consumption per plugin?
Next Topic:Event or function called when user switches to other editor in same editor area.
Goto Forum:
  


Current Time: Thu Nov 27 21:13:35 GMT 2014

Powered by FUDForum. Page generated in 0.02120 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software