Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse 4 » Enable/Disable ToolItem
Enable/Disable ToolItem [message #548900] Fri, 23 July 2010 12:14 Go to next message
Walter Mising name is currently offline Walter Mising nameFriend
Messages: 128
Registered: July 2009
Senior Member
Is it possible to enable/disable toolitem programatically ?

- Walter.
Re: Enable/Disable ToolItem [message #548901 is a reply to message #548900] Fri, 23 July 2010 12:28 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6651
Registered: July 2009
Senior Member
Sure get access to the model and call setEnabled() but often this is
controlled by the Command-Attached to it.

Tom

Am 23.07.10 14:14, schrieb Walter Prabhakar:
> Is it possible to enable/disable toolitem programatically ?
>
> - Walter.
Re: Enable/Disable ToolItem [message #549019 is a reply to message #548900] Fri, 23 July 2010 17:17 Go to previous messageGo to next message
Paul Webster is currently offline Paul WebsterFriend
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

Walter Prabhakar wrote:
> Is it possible to enable/disable toolitem programatically ?

As Tom mentioned, both a Handled tool item and direct tool item work by
querying the handler's @CanExecute method (where the direct tool item
handler is simply a contribution object).

If you are the handler, you can return true/false from your @CanExecute
method.

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: Enable/Disable ToolItem [message #549076 is a reply to message #548901] Sat, 24 July 2010 03:10 Go to previous messageGo to next message
Walter Mising name is currently offline Walter Mising nameFriend
Messages: 128
Registered: July 2009
Senior Member
My xwt contains the following
..
<ToolBar x:style="SWT.NONE">
<ToolItem x:Data="test" x:style="SWT.PUSH" SelectionEvent="onTI1Clicked"
image="/icons/sample.gif" Loaded="performToolItemLoaded"></ToolItem>
<ToolItem x:Data="test1" x:style="SWT.PUSH"
SelectionEvent="onTI2Clicked"
image="/icons/sample.gif" Loaded="performToolItemLoaded"></ToolItem>
</ToolBar>

The ToolItem getControl is null as demonstrated with this snippet.

Map oM = new HashMap ( ) ;
public void performToolItemLoaded(Object object, Event event) {
ToolItem oTI = (ToolItem) event.widget;
System.out.println ( oTI.getData() ) ;
oM.put(oTI.getData(), oTI) ;
}
public void onTI1Clicked(Object object, Event event) {
ToolItem oTI = (ToolItem) event.widget;
System.out.println ( oTI.getData() ) ;
oTI = ( ToolItem ) oM.get ( "test1" ) ;
if ( oTI.getControl ( ) == null )
System.err.println ( "test1 control: " + oTI.getControl ( ) ) ;
else
oTI.getControl().setEnabled(false) ;
}
public void onTI2Clicked(Object object, Event event) {
ToolItem oTI = (ToolItem) event.widget;
System.out.println ( oTI.getData() ) ;
}

How do I disable a tool item when another tool item is clicked ?

Thanks
- Walter




"Tom Schindl" <tom.schindl@bestsolution.at> wrote in message
news:i2c1sm$13s$1@build.eclipse.org...
> Sure get access to the model and call setEnabled() but often this is
> controlled by the Command-Attached to it.
>
> Tom
>
> Am 23.07.10 14:14, schrieb Walter Prabhakar:
>> Is it possible to enable/disable toolitem programatically ?
>>
>> - Walter.
>
Re: Enable/Disable ToolItem [message #549086 is a reply to message #549076] Sat, 24 July 2010 08:11 Go to previous message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6651
Registered: July 2009
Senior Member
Hi,

Ok you should have been more specific in your question. The answer from
me and Paul was about the e4-Workbench-ToolItems while you are talking
about XWT.

I'd suggest for the future that people use [xwt] in the subject if their
question is on this topic.

Tom

Am 24.07.10 05:10, schrieb Walter Prabhakar:
> My xwt contains the following
> .
> <ToolBar x:style="SWT.NONE">
> <ToolItem x:Data="test" x:style="SWT.PUSH" SelectionEvent="onTI1Clicked"
> image="/icons/sample.gif" Loaded="performToolItemLoaded"></ToolItem>
> <ToolItem x:Data="test1" x:style="SWT.PUSH"
> SelectionEvent="onTI2Clicked"
> image="/icons/sample.gif" Loaded="performToolItemLoaded"></ToolItem>
> </ToolBar>
>
> The ToolItem getControl is null as demonstrated with this snippet.
>
> Map oM = new HashMap ( ) ;
> public void performToolItemLoaded(Object object, Event event) {
> ToolItem oTI = (ToolItem) event.widget;
> System.out.println ( oTI.getData() ) ;
> oM.put(oTI.getData(), oTI) ;
> }
> public void onTI1Clicked(Object object, Event event) {
> ToolItem oTI = (ToolItem) event.widget;
> System.out.println ( oTI.getData() ) ;
> oTI = ( ToolItem ) oM.get ( "test1" ) ;
> if ( oTI.getControl ( ) == null )
> System.err.println ( "test1 control: " + oTI.getControl ( ) ) ;
> else
> oTI.getControl().setEnabled(false) ;
> }
> public void onTI2Clicked(Object object, Event event) {
> ToolItem oTI = (ToolItem) event.widget;
> System.out.println ( oTI.getData() ) ;
> }
>
> How do I disable a tool item when another tool item is clicked ?
>
> Thanks
> - Walter
>
>
>
>
> "Tom Schindl" <tom.schindl@bestsolution.at> wrote in message
> news:i2c1sm$13s$1@build.eclipse.org...
>> Sure get access to the model and call setEnabled() but often this is
>> controlled by the Command-Attached to it.
>>
>> Tom
>>
>> Am 23.07.10 14:14, schrieb Walter Prabhakar:
>>> Is it possible to enable/disable toolitem programatically ?
>>>
>>> - Walter.
>>
>
Re: Enable/Disable ToolItem [message #579264 is a reply to message #548900] Fri, 23 July 2010 12:28 Go to previous message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6651
Registered: July 2009
Senior Member
Sure get access to the model and call setEnabled() but often this is
controlled by the Command-Attached to it.

Tom

Am 23.07.10 14:14, schrieb Walter Prabhakar:
> Is it possible to enable/disable toolitem programatically ?
>
> - Walter.
Re: Enable/Disable ToolItem [message #579372 is a reply to message #548900] Fri, 23 July 2010 17:17 Go to previous message
Paul Webster is currently offline Paul WebsterFriend
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

Walter Prabhakar wrote:
> Is it possible to enable/disable toolitem programatically ?

As Tom mentioned, both a Handled tool item and direct tool item work by
querying the handler's @CanExecute method (where the direct tool item
handler is simply a contribution object).

If you are the handler, you can return true/false from your @CanExecute
method.

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: Enable/Disable ToolItem [message #579396 is a reply to message #548901] Sat, 24 July 2010 03:10 Go to previous message
Walter Mising name is currently offline Walter Mising nameFriend
Messages: 128
Registered: July 2009
Senior Member
My xwt contains the following
..
<ToolBar x:style="SWT.NONE">
<ToolItem x:Data="test" x:style="SWT.PUSH" SelectionEvent="onTI1Clicked"
image="/icons/sample.gif" Loaded="performToolItemLoaded"></ToolItem>
<ToolItem x:Data="test1" x:style="SWT.PUSH"
SelectionEvent="onTI2Clicked"
image="/icons/sample.gif" Loaded="performToolItemLoaded"></ToolItem>
</ToolBar>

The ToolItem getControl is null as demonstrated with this snippet.

Map oM = new HashMap ( ) ;
public void performToolItemLoaded(Object object, Event event) {
ToolItem oTI = (ToolItem) event.widget;
System.out.println ( oTI.getData() ) ;
oM.put(oTI.getData(), oTI) ;
}
public void onTI1Clicked(Object object, Event event) {
ToolItem oTI = (ToolItem) event.widget;
System.out.println ( oTI.getData() ) ;
oTI = ( ToolItem ) oM.get ( "test1" ) ;
if ( oTI.getControl ( ) == null )
System.err.println ( "test1 control: " + oTI.getControl ( ) ) ;
else
oTI.getControl().setEnabled(false) ;
}
public void onTI2Clicked(Object object, Event event) {
ToolItem oTI = (ToolItem) event.widget;
System.out.println ( oTI.getData() ) ;
}

How do I disable a tool item when another tool item is clicked ?

Thanks
- Walter




"Tom Schindl" <tom.schindl@bestsolution.at> wrote in message
news:i2c1sm$13s$1@build.eclipse.org...
> Sure get access to the model and call setEnabled() but often this is
> controlled by the Command-Attached to it.
>
> Tom
>
> Am 23.07.10 14:14, schrieb Walter Prabhakar:
>> Is it possible to enable/disable toolitem programatically ?
>>
>> - Walter.
>
Re: Enable/Disable ToolItem [message #579408 is a reply to message #549076] Sat, 24 July 2010 08:11 Go to previous message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6651
Registered: July 2009
Senior Member
Hi,

Ok you should have been more specific in your question. The answer from
me and Paul was about the e4-Workbench-ToolItems while you are talking
about XWT.

I'd suggest for the future that people use [xwt] in the subject if their
question is on this topic.

Tom

Am 24.07.10 05:10, schrieb Walter Prabhakar:
> My xwt contains the following
> .
> <ToolBar x:style="SWT.NONE">
> <ToolItem x:Data="test" x:style="SWT.PUSH" SelectionEvent="onTI1Clicked"
> image="/icons/sample.gif" Loaded="performToolItemLoaded"></ToolItem>
> <ToolItem x:Data="test1" x:style="SWT.PUSH"
> SelectionEvent="onTI2Clicked"
> image="/icons/sample.gif" Loaded="performToolItemLoaded"></ToolItem>
> </ToolBar>
>
> The ToolItem getControl is null as demonstrated with this snippet.
>
> Map oM = new HashMap ( ) ;
> public void performToolItemLoaded(Object object, Event event) {
> ToolItem oTI = (ToolItem) event.widget;
> System.out.println ( oTI.getData() ) ;
> oM.put(oTI.getData(), oTI) ;
> }
> public void onTI1Clicked(Object object, Event event) {
> ToolItem oTI = (ToolItem) event.widget;
> System.out.println ( oTI.getData() ) ;
> oTI = ( ToolItem ) oM.get ( "test1" ) ;
> if ( oTI.getControl ( ) == null )
> System.err.println ( "test1 control: " + oTI.getControl ( ) ) ;
> else
> oTI.getControl().setEnabled(false) ;
> }
> public void onTI2Clicked(Object object, Event event) {
> ToolItem oTI = (ToolItem) event.widget;
> System.out.println ( oTI.getData() ) ;
> }
>
> How do I disable a tool item when another tool item is clicked ?
>
> Thanks
> - Walter
>
>
>
>
> "Tom Schindl" <tom.schindl@bestsolution.at> wrote in message
> news:i2c1sm$13s$1@build.eclipse.org...
>> Sure get access to the model and call setEnabled() but often this is
>> controlled by the Command-Attached to it.
>>
>> Tom
>>
>> Am 23.07.10 14:14, schrieb Walter Prabhakar:
>>> Is it possible to enable/disable toolitem programatically ?
>>>
>>> - Walter.
>>
>
Previous Topic:How to get a View dynamically
Next Topic:Retrieving a child datacontext
Goto Forum:
  


Current Time: Tue Apr 16 09:51:24 GMT 2024

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

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

Back to the top