PropertyTester prevents handler execution [message #549988] |
Wed, 28 July 2010 16:23 |
Rainer 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 #550650 is a reply to message #549988] |
Wed, 04 August 2010 03:24 |
|
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 |
Rainer 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
|
|
|
|
Powered by
FUDForum. Page generated in 0.03339 seconds