Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Rich Client Platform (RCP) » Expression definition test(What can I put in the "args" attribute?)
Expression definition test [message #639395] Tue, 16 November 2010 11:55 Go to next message
Alexandra Niculai is currently offline Alexandra NiculaiFriend
Messages: 84
Registered: July 2009
Member
Hello everyone! Smile

I am a little confused Confused about the test in expression definitions.
I read this in the documentation:

Quote:
args - additional arguments passed to the property tester. Multiple arguments are separated by commas. Each individual argument is converted into a Java base type using the same rules as defined for the value attribute of the test expression.


Since this is a hard-coded thing, I don't really know what would be useful to pass there. I wanted to pass for example, "activePart", but it sent the String "activePart" on the other side(in the actual tester code).
Could someone please help me understand this better, maybe through an example? Thank you!

Alexandra.
Re: Expression definition test [message #639399 is a reply to message #639395] Tue, 16 November 2010 12:27 Go to previous messageGo to next message
T. Wilhelm is currently offline T. WilhelmFriend
Messages: 129
Registered: July 2009
Senior Member
Hi Alexandra,

maybe you mixed up "value" and "variable" ?

"activePart" can be used as variable, its not a value.

In the args you can give a value to the tester, so it´s possible that the tester can test vs different values. For example, you have two handlers, the first should be activated if 1 person in a table is selected the second one if 2 or more persons are selected. For both you can use the same tester but with different arguments.

i hope it get a little bit more clear.

Greetz
Thomas
Re: Expression definition test [message #639409 is a reply to message #639399] Tue, 16 November 2010 13:02 Go to previous messageGo to next message
Alexandra Niculai is currently offline Alexandra NiculaiFriend
Messages: 84
Registered: July 2009
Member
Hi Thomas,

Thank you for answering. I'm not sure I get it. So, what you're saying is that(for example), if the handler should "Do Thing" only if 2 persons are selected, we can test if it's allowed to do the thing with something like this:

               <test
                     args="2"
                     forcePluginActivation="true"
                     property="myProject.tester.mayDoThing"
                     value="true">
               </test>

?
So in the tester code, there should be some checking on the number of selected persons?

Alexandra.
Re: Expression definition test [message #639411 is a reply to message #639409] Tue, 16 November 2010 13:13 Go to previous messageGo to next message
T. Wilhelm is currently offline T. WilhelmFriend
Messages: 129
Registered: July 2009
Senior Member
Yes, in the tester you do a check like

if(numberOfSelcetedPersons == args)
{ 
return true;
}


So you can use this tester for different handlers, i.e. for handlers which can only be executed if ONE person is selected AND for handlers which can only be executed if TWO persons are selected. You simply have to pass a different args.

Greetz
Re: Expression definition test [message #639413 is a reply to message #639395] Tue, 16 November 2010 13:14 Go to previous messageGo to next message
Paul Webster is currently offline Paul WebsterFriend
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

A property tester is applied to an object in the expression. In your
case to act on the activePart:

<with variable="activePart">
<test property="org.eclipse.testPart"
args="arg1,arg2"
value="yesOrNo"/>
</with>

value and args are just Strings, although value can be converted based
on rules specified in the docs.

PW


--
Paul Webster
http://wiki.eclipse.org/Platform_Command_Framework
http://wiki.eclipse.org/Command_Core_Expressions
http://wiki.eclipse.org/Platform_Expression_Framework
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: Expression definition test [message #639415 is a reply to message #639413] Tue, 16 November 2010 13:23 Go to previous messageGo to next message
Alexandra Niculai is currently offline Alexandra NiculaiFriend
Messages: 84
Registered: July 2009
Member
In fact, my attempt has been something like this(which of course, didn't send the actual active part to the tester, because it can't, it sent the String "activePart", which wasn't relevant for the test, since the test needed both the currently selected element and the active part):

         <with
               variable="selection">
            <iterate
                  ifEmpty="true"
                  operator="or">
               <test
                     args="activePart"
                     forcePluginActivation="true"
                     property="myProject.tester.mayDoThing"
                     value="true">
               </test>
            </iterate>
         </with>


Alexandra.

[Updated on: Tue, 16 November 2010 13:26]

Report message to a moderator

Re: Expression definition test [message #639416 is a reply to message #639409] Tue, 16 November 2010 13:22 Go to previous messageGo to next message
Paul Webster is currently offline Paul WebsterFriend
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

You have to use "with" to pick the variable under test. All contained
core expression elements apply to a default variable, picked by the
"with" statement:

<with variable="selection">
<count value="2"/>
<test property="org.example.testPeople" value="2"/>
</with>

where org.example.testPeople is a property tester on an ISelection.

PW

--
Paul Webster
http://wiki.eclipse.org/Platform_Command_Framework
http://wiki.eclipse.org/Command_Core_Expressions
http://wiki.eclipse.org/Platform_Expression_Framework
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: Expression definition test [message #639496 is a reply to message #639415] Tue, 16 November 2010 18:25 Go to previous messageGo to next message
Paul Webster is currently offline Paul WebsterFriend
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

Does it do what you want now?

PW


--
Paul Webster
http://wiki.eclipse.org/Platform_Command_Framework
http://wiki.eclipse.org/Command_Core_Expressions
http://wiki.eclipse.org/Platform_Expression_Framework
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: Expression definition test [message #639528 is a reply to message #639496] Tue, 16 November 2010 19:58 Go to previous messageGo to next message
Alexandra Niculai is currently offline Alexandra NiculaiFriend
Messages: 84
Registered: July 2009
Member
Yes, I was just wondering how I could make good use of this attribute, too. In the end, I did something like this:

            <with
                  variable="selection">
               <iterate
                     ifEmpty="false"
                     operator="or">
                  <with
                        variable="activePart">
                        <test
                              forcePluginActivation="true"
                              property="myProject.tester.mayDoThing"
                              value="true">
                        </test>
                  </with>
               </iterate>
            </with>


Which works, but I think it looks ... strange.
Thank you for your answers!

Greetings
Alexandra.
Re: Expression definition test [message #639719 is a reply to message #639528] Wed, 17 November 2010 15:18 Go to previous message
Paul Webster is currently offline Paul WebsterFriend
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

Alexandra Niculai wrote:
> Yes, I was just wondering how I could make good use of this attribute,
> too. In the end, I did something like this:
>
>
> <with
> variable="selection">
> <iterate
> ifEmpty="false"
> operator="or">
> <with
> variable="activePart">
> <test
> forcePluginActivation="true"
> property="myProject.tester.mayDoThing"
> value="true">
> </test>
> </with>
> </iterate>
> </with>

your first iterate means that for every item in the current selection
.... go off and check the activePart (they're unrelated variables :-)


<with
variable="activePart">
<test
forcePluginActivation="true"
property="myProject.tester.mayDoThing"
value="true">
</test>
</with>


If you did need to test 2 things, you would go:
<and>
<with variable="activePart">
<test
forcePluginActivation="true"
property="myProject.tester.mayDoThing"
value="true"/>
</with>
<with variable="selection>
<iterate ifEmpty="false">
... selection test ...
</iterate>
</with>
</and>

Good luck.
PW

--
Paul Webster
http://wiki.eclipse.org/Platform_Command_Framework
http://wiki.eclipse.org/Command_Core_Expressions
http://wiki.eclipse.org/Platform_Expression_Framework
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


Previous Topic:beginner mistake
Next Topic:How to remove the unwanted "Run as/Debug as" from context menu
Goto Forum:
  


Current Time: Fri Apr 26 10:49:21 GMT 2024

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

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

Back to the top