Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Rich Client Platform (RCP) » PropertyTester prevents handler execution
icon5.gif  PropertyTester prevents handler execution [message #549988] Wed, 28 July 2010 16:23 Go to next message
Rainer is currently offline RainerFriend
Messages: 6
Registered: July 2010
Junior Member
Hello,

I'm developing a Plugin for Eclipse.

Certain commands in my view's toolbar shall be enabled/disabled depending on the type of file that was selected in the Package Explorer (so each click in the Package Explorer can possibly change the enabled state).

I was able to achieve that behavior with property testers and an enabledWhen statement in the plugin.xml for the handler.

The problem is that the handler's Java code is never called. When clicking on the command, nothing happens and the command becomes disabled.

I first thought that the problem might be that my property tester is called on the click on the command and evaluates to false, but it is not even called then, and letting it always return true does not solve the problem either.

When I remove the enabledWhen from the handler, everything works fine, but then I lose that enabling/disabling behaviour that I wanted to achieve by using the property testers.
Changing the enabledWhen to activeWhen does not change anything (which was to be expected), and setting the handler's Java class as the default handler for the command seems to disable the property tester.

I'm using Eclipse 3.6 (same behaviour under 3.5 though) and really need help on this as I'm running out of ideas.


My handler looks like this:

<handler
commandId="project.setDDL"
class="handlers.SetDDLHandler">
<enabledWhen>
<with
variable="selection">
<test
forcePluginActivation="true"
property="testers.ddlSelected">
</test>
</with>
</enabledWhen>
</handler>

The corresponding property tester:

<propertyTester
class="view.handlers.testers.DDLSelectedTester"
id="project.ddlSelectedTester"
namespace="testers"
properties="ddlSelected"
type="org.eclipse.jface.viewers.ISelection">
</propertyTester>

The command:

<command
id="project.setDDL"
name="Set DDL file">
</command>

And, for completeness, the menu contribution:

<command
commandId="project.setDDL"
icon="res/setDDL.png"
label="DDL-Datei setzen, in die geschrieben wird"
style="push">
</command>


Thanks in advance!
Rainer
Re: PropertyTester prevents handler execution [message #550254 is a reply to message #549988] Thu, 29 July 2010 15:26 Go to previous messageGo to next message
Paul Webster is currently offline Paul WebsterFriend
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

You need to start with one scenario and debug it. Your XML seems
reasonable.


Command with no default handler:
<command
id="project.setDDL"
name="Set DDL file">
</command>

Default handler definition with enabledWhen:

<handler
commandId="project.setDDL"
class="handlers.SetDDLHandler">
<enabledWhen>
<with
variable="selection">
<test
forcePluginActivation="true"
property="testers.ddlSelected">
</test>
</with>
</enabledWhen>
</handler>

menuContribution ... what's the locationURI?

<command
commandId="project.setDDL"
icon="res/setDDL.png"
label="DDL-Datei setzen, in die geschrieben wird"
style="push">
</command>


Because your handler definition doesn't include an activeWhen, it's the
equivalent of a defaultHandler. If you provide a default handler (or
another handler with no activeWhen) anywhere else in the system they'll
cancel each other out.

Your property tester should get called on every selection change (select
different files in the package explorer, you should see changes).

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: PropertyTester prevents handler execution [message #550650 is a reply to message #549988] Wed, 04 August 2010 03:24 Go to previous messageGo to next message
Craig Foote is currently offline Craig FooteFriend
Messages: 217
Registered: July 2009
Senior Member
Shouldn't the child of <with variable="selection"> be an <iterate>? I.e.:

<handler
commandId="project.setDDL"
class="handlers.SetDDLHandler">
<enabledWhen>
<with
variable="selection">
<iterate
operator="or"
ifEmpty="false">
<test
forcePluginActivation="true"
property="testers.ddlSelected">
</test>
</iterate>
</with>
</enabledWhen>
</handler>

Craig

On Wed, 28 Jul 2010 12:23:27 -0400, rainerbass wrote:

> Hello,
>
> I'm developing a Plugin for Eclipse.
>
> Certain commands in my view's toolbar shall be enabled/disabled
> depending on the type of file that was selected in the Package Explorer
> (so each click in the Package Explorer can possibly change the enabled
> state).
>
> I was able to achieve that behavior with property testers and an
> enabledWhen statement in the plugin.xml for the handler.
>
> The problem is that the handler's Java code is never called. When
> clicking on the command, nothing happens and the command becomes
> disabled.
>
> I first thought that the problem might be that my property tester is
> called on the click on the command and evaluates to false, but it is not
> even called then, and letting it always return true does not solve the
> problem either.
>
> When I remove the enabledWhen from the handler, everything works fine,
> but then I lose that enabling/disabling behaviour that I wanted to
> achieve by using the property testers. Changing the enabledWhen to
> activeWhen does not change anything (which was to be expected), and
> setting the handler's Java class as the default handler for the command
> seems to disable the property tester.
>
> I'm using Eclipse 3.6 (same behaviour under 3.5 though) and really need
> help on this as I'm running out of ideas.
>
>
> My handler looks like this:
>
> <handler
> commandId="project.setDDL"
> class="handlers.SetDDLHandler">
> <enabledWhen>
> <with
> variable="selection">
> <test
> forcePluginActivation="true"
> property="testers.ddlSelected">
> </test>
> </with>
> </enabledWhen>
> </handler>
>
> The corresponding property tester:
>
> <propertyTester
> class="view.handlers.testers.DDLSelectedTester"
> id="project.ddlSelectedTester"
> namespace="testers"
> properties="ddlSelected"
> type="org.eclipse.jface.viewers.ISelection">
> </propertyTester>
>
> The command:
>
> <command
> id="project.setDDL"
> name="Set DDL file">
> </command>
>
> And, for completeness, the menu contribution:
>
> <command
> commandId="project.setDDL"
> icon="res/setDDL.png"
> label="DDL-Datei setzen, in die geschrieben wird"
> style="push">
> </command>
>
>
> Thanks in advance!
> Rainer
Re: PropertyTester prevents handler execution [message #552508 is a reply to message #549988] Thu, 12 August 2010 12:32 Go to previous messageGo to next message
Rainer is currently offline RainerFriend
Messages: 6
Registered: July 2010
Junior Member
Thanks for your replies, and sorry for my late answer, I was on vacation.

Quote:
Shouldn't the child of <with variable="selection"> be an <iterate>?

I tried it with <iterate>, even with ifEmpty="true", but it makes things even stranger - the property tester is not called by clicking on something in the Package Explorer, but only by clicking into an editor - selection events from views seem to be completely ignored. Removing the <iterate> restores the old behaviour of correctly enabling/disabling the command visually but removing the handler's functionality. The handler can only be called if I manually set a defaultHandler for the command, but then I lose the enabling/disabling. Sadly the handlers reference the commands and not the other way round, so I cannot combine my handler (that includes the enabling/disabling conditions) with the defaultHandler attribute of the command.

Quote:
You need to start with one scenario and debug it

I started with the handler calling (using defaultHandlers), which worked instantly. I then continued with enabling/disabling, which also worked using propertyTesters. It's only the combination of both that doesn't.

Quote:

menuContribution ... what's the locationURI?

It's "toolbar:project.view".

Quote:

Because your handler definition doesn't include an activeWhen, it's the
equivalent of a defaultHandler. If you provide a default handler (or
another handler with no activeWhen) anywhere else in the system they'll
cancel each other out.


I changed the enabledWhen to activeWhen but the effects are identical.

Quote:
Your property tester should get called on every selection change (select
different files in the package explorer, you should see changes).

The property testers are indeed called, the problem is that the handlers are not. The handlers I provide in the "handlers" extension point seem to be correctly linked to the commands, but not to the Java handlers, although there are no warnings and the same paths I use in the handlers' "class" attribute work well when used in a command's defaultHandler attribute.

Any other advice? I really need to get this fixed - and I want to understand what I do wrong.

[Updated on: Thu, 12 August 2010 12:33]

Report message to a moderator

Re: PropertyTester prevents handler execution [message #552841 is a reply to message #549988] Fri, 13 August 2010 17:32 Go to previous message
Rainer is currently offline RainerFriend
Messages: 6
Registered: July 2010
Junior Member
I finally got most of what I wanted working.

My solution is omiting Property Testers totally and using SourceProviders. The enabling/disabling logic is now in the SourceProvider that produces a String which is evaluated via <equals> in the plugin.xml. Reevaluation is now triggered in the Source Providers as well via fireSourceChanged().

The only thing I miss now is related to selection events in editors and views that are not hooked to my listeners and therefore don't change the enabling/disabling state of my commands, but maybe I can work around that somehow too.
Previous Topic:Where are the branding infos taken from: .product or plugin.xml?
Next Topic:Multiple Applications in one rcp installation
Goto Forum:
  


Current Time: Thu Apr 25 00:09:50 GMT 2024

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

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

Back to the top