Home » Eclipse Projects » Eclipse Platform » Property Tester works only on selected objects?
Property Tester works only on selected objects? [message #330145] |
Wed, 16 July 2008 22:24 |
Eclipse User |
|
|
|
Originally posted by: x_raajes.ugs.com
Does a property tester always test based on the current selection? Can I
have a tester that checks, say, for the logged-in user's privileges? What
would be my input object (receiver) in this case?
I have worked with property testers before, and checked for properties on
the currently selected object, where I put the "test" condition under a
visibleWhen, but I am wondering about the following if I just want to
enable/disable a menu item based on the logged-in user's privileges.
How would the structure of the XML declaration be? When I work with the
selected object, I have previously used a condition like this for the active
handler:
<visibleWhen>
<iterate ifEmpty="false">
<adapt type="XYZ">
<test property="abc.def" value="false"></test>
</adapt>
</iterate>
</visibleWhen>
In this case, it is iterating over the set of selected objects (possibly a
multi-selection), so the input object that comes to the tester is the
selection, adapted to XYZ. If I want to simply have the menu item (or
command) be visible when the logged-in user has certain privileges... what
set of objects would I iterate over?
If I simply try to say:
<visibleWhen>
<test property="abc.def" value="false"></test>
</visibleWhen>
and just check for the logged-in user's privileges in the tester and return
true/false, I find that this tester does not get fired at all.
I guess my fundamental question is about what makes the test condition fire,
and what would be the input object that the tester receives, and whether we
have control over what must be checked by the visibleWhen. I could not find
any documentation that explains this.
Thanks for any insight anyone may have.
|
|
| |
Re: Property Tester works only on selected objects? [message #330225 is a reply to message #330221] |
Mon, 21 July 2008 19:11 |
Eclipse User |
|
|
|
Originally posted by: x_raajes.ugs.com
Thanks Paul.
I understand that the property tester tests something on an object. However,
it is not clear to me what makes the property tester fire. (For example, I
know that in the visibleWhen example in my original post, it gets fired when
iterating over a set of selected objects. What tells it that it must look
only at the selected objects? Can it look at something else? Is that
"something else" the "variable" in the "with" clause?).
Also, I think the second option looks good. However, when looking through
the example, I noticed that the variable was created using an extension
point org.eclipse.ui.services. Is this a new extension point in 3.4? We use
Eclipse 3.3 for our product. How would we normally create such a variable in
3.3? Can I find the steps to do this somewhere? After I create this
variable, I would be able to check for it anywhere, not necessarily when a
selection happens, correct (which is related to my question above)?
"Paul Webster" <pwebster@ca.ibm.com> wrote in message
news:g62enm$r6j$2@build.eclipse.org...
> Property testers are tied to an object type. You have 2 options.
>
> 1) add your property tester to java.lang.Object ... then it will be called
> no matter what, but the receiver becomes irrelevant.
>
> 2) add a variable source that provides your user. Then your property
> tester is tied to your user type. A primitive example of this is
> available in org.eclipse.ui.examples.contributions
> :pserver:anonymous@dev.eclipse.org:/cvsroot/eclipse
>
> Later,
> 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/help33/index.jsp?topic=/org.eclipse. platform.doc.isv/guide/workbench.htm
|
|
|
Re: Property Tester works only on selected objects? [message #330238 is a reply to message #330225] |
Tue, 22 July 2008 15:53 |
|
Raajesh B.Kashyap wrote:
> Thanks Paul.
>
> I understand that the property tester tests something on an object. However,
> it is not clear to me what makes the property tester fire. (For example, I
> know that in the visibleWhen example in my original post, it gets fired when
> iterating over a set of selected objects. What tells it that it must look
> only at the selected objects? Can it look at something else? Is that
> "something else" the "variable" in the "with" clause?).
The property tester will view when the "variable in context" changes.
The default variable for enabledWhen/activeWhen/visibleWhen is the
current selection, stored in a Collection. Using something like with
variable="activePartId" changes the variable in context, and (in this
example) the property tester will be re-evaluated when the activePartId
changes.
In 3.3 there's no way to re-evaluate when a property changes, that is
API added in 3.4 to IEvaluationService.
>
> Also, I think the second option looks good. However, when looking through
> the example, I noticed that the variable was created using an extension
> point org.eclipse.ui.services. Is this a new extension point in 3.4? We use
> Eclipse 3.3 for our product. How would we normally create such a variable in
> 3.3? Can I find the steps to do this somewhere? After I create this
> variable, I would be able to check for it anywhere, not necessarily when a
> selection happens, correct (which is related to my question above)?
In 3.3 it is more difficult, especially depending one what you need to
support. visibleWhen and enabledWhen are the easiest to do.
Try out the project from
http://dev.eclipse.org/newslists/news.eclipse.platform/msg75 543.html
To add a variable your AbstractSourceProvider implementation needs to
fire events when the variable changes. Check out how the subclasses do it.
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/help33/index.jsp?topic=/org.eclipse. platform.doc.isv/guide/workbench.htm
Paul Webster
http://wiki.eclipse.org/Platform_Command_Framework
http://wiki.eclipse.org/Command_Core_Expressions
http://wiki.eclipse.org/Menu_Contributions
|
|
|
Goto Forum:
Current Time: Sat Nov 02 18:48:31 GMT 2024
Powered by FUDForum. Page generated in 0.03128 seconds
|