Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » Toggle Toolbar button
Toggle Toolbar button [message #452270] Wed, 16 March 2005 15:55 Go to next message
Mark Victory is currently offline Mark VictoryFriend
Messages: 133
Registered: July 2009
Senior Member
Hi all,

I have a View action that when run displays a modeless dialog. I want the
button to act as a toggle (it has the toggle style). I would like,
therefore, when the dialog is dismissed by the user to have the button
toggle. The code below is not working.

The unToggle method gets called but it appears to have no effect on the
Action's toolbar button.

Thanks,
Mark

public void unToggle()
{
this.setEnabled(false); //this.setChecked( ) has no effect either
}

public void run(IAction action)
{
//Show or hide the dialog based on the current state of the dialog.
if (m_theDialog != null && m_theDialog.getShell() != null &&
m_theDialog.getShell().isVisible())
m_theDialog.close();
else
{
m_theDialog = new CommentsDialog(MtPlugin.getShell());

m_theDialog.open();
m_theDialog.getShell().addDisposeListener(new DisposeListener()
{
public void widgetDisposed(DisposeEvent e)
{
unToggle();
}

});
}
}
Re: Toggle Toolbar button [message #452280 is a reply to message #452270] Wed, 16 March 2005 20:35 Go to previous message
Mark Victory is currently offline Mark VictoryFriend
Messages: 133
Registered: July 2009
Senior Member
I figured it out. I needed to get the toolbar manager, find the item and
call set checked.

HERE'S a larger question:

Why does the Action have methods such as setChecked, setEnabled, etc. if
calling them has no effect on the GUI widgets that run the action such as
the toolbar item or menu item.

Thanks,
Mark

"Mark Victory" <mvictory@us.ibm.com> wrote in message
news:d19ku8$17b$1@www.eclipse.org...
> Hi all,
>
> I have a View action that when run displays a modeless dialog. I want the
> button to act as a toggle (it has the toggle style). I would like,
> therefore, when the dialog is dismissed by the user to have the button
> toggle. The code below is not working.
>
> The unToggle method gets called but it appears to have no effect on the
> Action's toolbar button.
>
> Thanks,
> Mark
>
> public void unToggle()
> {
> this.setEnabled(false); //this.setChecked( ) has no effect either
> }
>
> public void run(IAction action)
> {
> //Show or hide the dialog based on the current state of the dialog.
> if (m_theDialog != null && m_theDialog.getShell() != null &&
> m_theDialog.getShell().isVisible())
> m_theDialog.close();
> else
> {
> m_theDialog = new CommentsDialog(MtPlugin.getShell());
>
> m_theDialog.open();
> m_theDialog.getShell().addDisposeListener(new DisposeListener()
> {
> public void widgetDisposed(DisposeEvent e)
> {
> unToggle();
> }
>
> });
> }
> }
>
>
Previous Topic:Why no widget Interfaces?
Next Topic:Intercepting
Goto Forum:
  


Current Time: Fri Apr 19 06:42:36 GMT 2024

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

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

Back to the top