Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Rich Client Platform (RCP) » <iterate> using multiple results
<iterate> using multiple results [message #885042] Tue, 12 June 2012 10:36 Go to next message
Seán Dunne is currently offline Seán DunneFriend
Messages: 2
Registered: June 2012
Junior Member
Hi,

So I am working on an application where we can select multiple different Objects.
I am trying to contribute a menu item based on the selection. So far I have the item appearing in the Context menu as I need I am having an issue getting the <enabledWhen> working correctly.

What I am trying to do is,
When one ObjectA and one ObjectB is selected enable the menu item.
The item should only be enabled when there is at least one of each of the objects in the selection and should not be enabled if there is another object type in the selection.
I hope I made my criteria understandable.

So far this is what I have atm, I have tried so many different approaches.
         <enabledWhen>
            <with
                  variable="selection">
               <iterate>
                  <or>
                     <instanceof value="org.xyz.Alpha" />
                     <instanceof value="org.xyz.Beta" />
                  </or>
               </iterate>
            </with>
         </enabledWhen>


This partially works, it does enable when I have a least one of each of ObjectA and ObjectB
but the problem is, it will also be enabled if I have only ObjectA in the selection and no ObjectB. Or if I have another object selected, say ObjectC and one of A or B selected.

Any help with this would be greatly appreciated.
And I would just like to say a big word of thanks to everyone on this forum that has contributed. This is my first post but I have used this forum for a long time when trying to figure out other stuff and the fact I haven't needed to post until now just shows how much info is already on here. So a big thanks to anyone that has asked and especially answered questions!!

Seán.
Re: <iterate> using multiple results [message #885112 is a reply to message #885042] Tue, 12 June 2012 13:39 Go to previous messageGo to next message
Paul Webster is currently offline Paul WebsterFriend
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

Core expressions are more declarative and not imperative or procedural. So it's not really easy to create an expression to do what you want.

<with variable="activeMenuSelection">
  <count value="2"/>
  <iterate operator="and">
    <or>
      <instanceof value="org.xyz.Alpha" />
      <instanceof value="org.xyz.Beta" />
    </or>
  </iterate>
  <iterate operator="or">
    <instanceof value="org.xyz.Alpha" />
  </iterate>
  <iterate operator="or">
    <instanceof value="org.xyz.Beta" />
  </iterate>
</with>


Painful. And I'm not even 100% sure it's correct.

If you are contributing to a context menu, you should use activeMenuSelection as the variable. Although for most views, activeMenuSelection will equal selection.

PW


Re: <iterate> using multiple results [message #885132 is a reply to message #885112] Tue, 12 June 2012 14:11 Go to previous messageGo to next message
Seán Dunne is currently offline Seán DunneFriend
Messages: 2
Registered: June 2012
Junior Member
Certainly seems to be working, just had a quick test of it and all seems to be good, thanks so much for the help.

It's a pretty painful expression alright and my actual problem involves three objects so it's going to be a bit more painful but with your help it should at least work Smile Thanks!!


Just something I would like to clarify after looking at your solution.
I thought the operator attribute of <iterate> changes how the iterate tag treats it's children.
But it looks like the operator attribute changes how iterates parent interprets the result of the iterate tag.
Is this correct or am I gone mad altogether?

Again thanks alot Paul!!
Re: <iterate> using multiple results [message #885668 is a reply to message #885132] Wed, 13 June 2012 12:17 Go to previous message
Paul Webster is currently offline Paul WebsterFriend
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

Yes, you've noticed the difference.

The iterate element will always AND its children together (same as the with element). The operator attribute changes how iterate processes the multiple elements in the variable it's working on.

PW


Previous Topic:Delete(org.eclipse.ui.edit.delete) Cool Bar Icon disabled for View
Next Topic:Reusing workspace selection dialog in RCP application
Goto Forum:
  


Current Time: Tue Dec 23 04:41:39 GMT 2014

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

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