Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse 4 » Can't get visible-when to work
Can't get visible-when to work [message #836467] Wed, 04 April 2012 14:12 Go to next message
Phill Perryman is currently offline Phill PerrymanFriend
Messages: 214
Registered: July 2009
Senior Member
I have an edit menu with a single handledMenuItem (Invoice Address). Run the app and it appears. I have then added a visible when core expression and set it to the definition id of the core expression from the extension point.

In the tree on the part I have a selection listener which does a setSelection using the injected ESelectionService. I can debug this and see it make the call.

I have tried setting the selection to to the IStructuredSelection and to its first element (an InvoiceAddress) and I have tried setting the core expression to both an instanceof(InvoiceAddress) and an iterate/instanceof(InvoiceAddress).

None of these cause the menu item to appear. Also if I then set the visible when back to None the menu still does not appear. If I delete and re-add without setting the visible when it comes back again.

I am obviously missing something here.
Re: Can't get visible-when to work [message #856130 is a reply to message #836467] Wed, 25 April 2012 11:51 Go to previous messageGo to next message
Paul Webster is currently offline Paul WebsterFriend
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

It looks like the ESelectionService uses org.eclipse.e4.ui.services.IServiceConstants.ACTIVE_SELECTION, org.eclipse.ui.selection, instead of selection that's used in the 4.2 Workbench.

You could try that in your visibleWhen expression. You can also open a bug against Platform/UI (if you include a small example view, that would help).

PW


Re: Can't get visible-when to work [message #856248 is a reply to message #856130] Wed, 25 April 2012 13:55 Go to previous messageGo to next message
Phill Perryman is currently offline Phill PerrymanFriend
Messages: 214
Registered: July 2009
Senior Member
Not sure I understand you. I set the active selection using selectionService.setSelection(selection); this works fine as I also have an
@Inject
void updateFolder(@Optional @javax.inject.Named(IServiceConstants.ACTIVE_SELECTION) Object object) {
if (object != null)
System.out.println(object.toString());
}
And that all works fine and I get a printout every time a make a selection in the viewer.

In my definitions I have
<extension point="org.eclipse.core.expressions.definitions">
<definition id="instance.InvoiceAddress">
<iterate operator="or">
<instanceof value="swb3.quotes.providers.InvoiceAddress"></instanceof>
</iterate>
</definition>

I know the class is correct as I have a println in the set selection method "Setting selection to swb3.quotes.providers.InvoiceAddress"

I added a menu in the model

<children xsi:type="menu:Menu" xmi:id="_y4_NkH5TEeGwE_NvT3bHXA" elementId="menu.edit" label="Edit">
<children xsi:type="menu:HandledMenuItem" xmi:id="_lSY_kH5UEeGwE_NvT3bHXA" elementId="handled.InvoiceAddress" label="Invoice Address" command="_uvx2IH5LEeG8BsWZBE4Y6g">
<visibleWhen xsi:type="ui:CoreExpression" xmi:id="_z8SYEIL9EeGHd819fxj36w" coreExpressionId="instance.InvoiceAddress"/>
</children>
</children>

However the menu item never appears. Not sure how I can incorporate the org.eclipse.ui.selection in a visible when as I just want the menu to appear when a certain selection is made.

Happy to raise a bug if you think the above should work.
Re: Can't get visible-when to work [message #857172 is a reply to message #856248] Thu, 26 April 2012 09:54 Go to previous messageGo to next message
Christoph Keimel is currently offline Christoph KeimelFriend
Messages: 482
Registered: December 2010
Location: Germany
Senior Member
Hi Phil,

I haven't tried it, but shouldn't your definition include a <with> element, i.e. like this:

<extension point="org.eclipse.core.expressions.definitions">
	<definition id="instance.InvoiceAddress">
		<with variable="selection">
			<iterate operator="or">
				<instanceof value="swb3.quotes.providers.InvoiceAddress"></instanceof>
			</iterate>
		</with>
	</definition>
</extension>


If I understand PW correctly, then in e4 it should be:
<with variable="org.eclipse.ui.selection">

Let me know if this works. I will have to do something similar in a couple of weeks.

Greetings
Christoph
Re: Can't get visible-when to work [message #857206 is a reply to message #857172] Thu, 26 April 2012 10:43 Go to previous messageGo to next message
Phill Perryman is currently offline Phill PerrymanFriend
Messages: 214
Registered: July 2009
Senior Member
Yipeeee, that explains Paul's comments perfectly.

You do however have to be careful about the setSelection. Following an example I had (Lars' Eclipse 4 Platform Services - Tutorial).

StructuredSelection selection = (StructuredSelection) event.getSelection();
Object object = selection.getFirstElement();
if (object != null)
selectionService.setSelection(object);

in which case you have to omit the iterate from the definition.

<definition id="instance.InvoiceAddress">
<with variable="org.eclipse.ui.selection">
<instanceof value="swb3.quotes.providers.InvoiceAddress"></instanceof>
</with>
</definition>

if you do a
StructuredSelection selection = (StructuredSelection) event.getSelection();
selectionService.setSelection(selection);

then the definition needs to iterate

<definition id="instance.InvoiceAddress">
<with variable="org.eclipse.ui.selection">
<iterate ifEmpty="false" operator="or">
<instanceof value="swb3.quotes.providers.InvoiceAddress"></instanceof>
</iterate>
</with>
</definition>

Because the same selection is injected into my update handlers I need to decide on a standard approach. Because some of my viewers allow multiple selection I will have to use the StructuredSelection in all my selection setting/getting.

Now my menus appears/disappears as expected. Now I just need to find out how to define a popup menu in a model fragment so I can add it to a viewer and my menu handling seems ok.

Massive thanks
Re: Can't get visible-when to work [message #857214 is a reply to message #857206] Thu, 26 April 2012 10:51 Go to previous messageGo to next message
Christoph Keimel is currently offline Christoph KeimelFriend
Messages: 482
Registered: December 2010
Location: Germany
Senior Member
Great to know! That saves me a lot of research, so thank you.

I define Popup Menus like this:
<elements xsi:type="basic:Part" ...>
	<menus xsi:type="menu:PopupMenu" elementId="YOUR_ID" ...>
		<children xsi:type="menu:HandledMenuItem" .../>
	...


Hook it up to your component (i.e. tree) like this:
MPopupMenu menu = menuService.registerContextMenu(tree, YOUR_ID);


Greetings
Christoph
Re: Can't get visible-when to work [message #857356 is a reply to message #857214] Thu, 26 April 2012 13:28 Go to previous messageGo to next message
Eclipse UserFriend
I believe you guys need to be aware of bug 375393 regarding the context menus.
Re: Can't get visible-when to work [message #870394 is a reply to message #857356] Mon, 07 May 2012 23:20 Go to previous message
Lars Vogel is currently offline Lars VogelFriend
Messages: 1098
Registered: July 2009
Senior Member

@Phil: I also added the definition of a Popup Menu to my tutorial Eclipse 4 Tutorial - Popup Menu
Previous Topic:Multiple Perspectives in an RCP e4 Application
Next Topic:Eclipse 4 Training in the Netherlands (English)
Goto Forum:
  


Current Time: Fri Mar 29 12:03:11 GMT 2024

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

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

Back to the top