Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse 4 » show up dynamic (part) menu
show up dynamic (part) menu [message #635367] Tue, 26 October 2010 15:05 Go to next message
Jens Piegsa is currently offline Jens PiegsaFriend
Messages: 16
Registered: July 2009
Location: Germany
Junior Member

Hello,

I want to implement a popup menu for a JFace TreeViewer that is
contained in a view part represented in the model.

The popup menu should (as usual) be different depending on the
selection. I found a snippet where that is implementetdoing in this way:

MenuManager manager = new MenuManager();
manager.setRemoveAllWhenShown(true);

manager.addMenuListener(new IMenuListener() {

@Override
public void menuAboutToShow(final IMenuManager currentManager) {
IStructuredSelection selection =
(IStructuredSelection) treeViewer.getSelection();
if (!selection.isEmpty())
currentManager.add(someAction);
...
}
}
});

treeViewer.getControl().setMenu(manager.createContextMenu(tr eeViewer.getControl()));

---

Now I thought about introducing the menu to the workbench model.
It is possible to add menus to parts or create menu contributions via
the model editor.
So what is the proper way to (combine and) show them up in this case?

Thanks,

Jens
Re: show up dynamic (part) menu [message #635540 is a reply to message #635367] Wed, 27 October 2010 09:32 Go to previous messageGo to next message
Jens Piegsa is currently offline Jens PiegsaFriend
Messages: 16
Registered: July 2009
Location: Germany
Junior Member

Hi all,

I figured out that I can use the EMenuService to add a menu to any control.

MPopupMenu contextMenu =
menuService.registerContextMenu(viewer.getControl(), "contextMenu");

That only succeeds, when the menu is defined in the "Menus" section of
the part and is of type MPopupMenu.
I had to add the type as an attribute in the e4xmi manually (the e4
Workbenchmodel editor doesn't seem to support popup menus there yet):

<menus xsi:type="menu:PopupMenu" .. > .. </menus>

Now the context menu is showing up, but the set of menu items is still
static.

My question now is whether I could use visibleWhen-Expressions to show /
hide single items depending on the current selection in the tree.
I don't know how and where to define those expressions, so
I would appreciate if anyone could give me a simple example.

Thanks,
Jens
Re: show up dynamic (part) menu [message #635598 is a reply to message #635540] Wed, 27 October 2010 13:28 Go to previous messageGo to next message
Paul Webster is currently offline Paul WebsterFriend
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

Check out the org.eclipse.e4.demo.simpleide.navigator project.
/cvsroot/eclipse
e4/org.eclipse.e4.ui/examples/org.eclipse.e4.demo.simpleide. navigator

This is the context menu view with a visibleWhen example:
/org.eclipse.e4.demo.simpleide.navigator/xmi/contextViewMenu Fragment.e4xmi
/org.eclipse.e4.demo.simpleide.navigator/src/org/eclipse/e4/ demo/simpleide/menu/ContextMenuView.java

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: show up dynamic (part) menu [message #635662 is a reply to message #635598] Wed, 27 October 2010 16:25 Go to previous messageGo to next message
Jens Piegsa is currently offline Jens PiegsaFriend
Messages: 16
Registered: July 2009
Location: Germany
Junior Member

Hi Paul,

Thank you very much! Now, my context menu lives up to its name.

Primary insights:
* I have to define the core expression via the extension point
org.eclipse.core.expressions.definitions
* they must refer to variables that I modify by the part's
IEclipseContext in an ISelectionChangedListener of the TreeViewer
* I should use Menu Contributions, since "normal" menu items won't
disappear again (when the visibleWhen expression is no longer true)

Secondary insights:
* DirectMenuItems don't call the @CanExecute-Method, therefore I have to
use Commands
* An entire Menu Contribution can be addressed by a visibleWhen
expression (rather than every single item)

Proposals for the e4 Workbenchmodel Editor:
* visibleWhen expressions should be assignable to Menu Contributions
* Popup Menus should be insertable into Parts
* Ctrl+X in a text field (on the right) should not cut the entire item
(on the left) ^^

So long,

Jens
Re: show up dynamic (part) menu [message #635668 is a reply to message #635662] Wed, 27 October 2010 17:02 Go to previous messageGo to next message
Paul Webster is currently offline Paul WebsterFriend
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

Hi Jens,

Thanx for writing this up. Comments I can think of are in line:

Jens Piegsa wrote:
> * they must refer to variables that I modify by the part's
> IEclipseContext in an ISelectionChangedListener of the TreeViewer

Yes, the important part is that the IEclipseContext is the link between
the information you need to post and what is available to the <with/>
element.

> * I should use Menu Contributions, since "normal" menu items won't
> disappear again (when the visibleWhen expression is no longer true)

This will be fixed post-M3.

>
> Secondary insights:
> * DirectMenuItems don't call the @CanExecute-Method, therefore I have to
> use Commands

This will also be fixed post-M3.

In general, our advice on direct menu items is they are literally a
modeled representation of an SWT.Selection listener. Not cached, not
available to the rest of the system, etc.


Thanx again,
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: show up dynamic (part) menu [message #635725 is a reply to message #635662] Wed, 27 October 2010 20:27 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6651
Registered: July 2009
Senior Member
[...]

> Proposals for the e4 Workbenchmodel Editor:
> * visibleWhen expressions should be assignable to Menu Contributions

Could you file a bug an CC me

> * Popup Menus should be insertable into Parts

Could you file a bug and CC me

> * Ctrl+X in a text field (on the right) should not cut the entire item
> (on the left) ^^
>

There is already a bug for the incorrect C&P which is a subject to
improve like the rest of the Model Editor but my day job didn't give me
any time to work on this which is at least *in my personal opinion a
real problem* because without tooling our fantastic new concept of the
modeled workbench will not be understood/manageable by software
developers :-(

It would be the same fun as you'd have to write bundles without PDE but
I currently don't see how we (at least) I can fix this because no other
party has really invested into this area (I'm talking about time which
is equal to money) or stepped up to support my work on it.

Tom
Re: show up dynamic (part) menu [message #640137 is a reply to message #635367] Fri, 19 November 2010 10:08 Go to previous messageGo to next message
Missing name Missing name is currently offline Missing name Missing nameFriend
Messages: 57
Registered: September 2009
Member
Hello,

I fill this topic to ask a question about popupmenu on a TreeViewer.

I define a TreeViewer and add a context menu on right click like in org.eclipse.e4.demo.simpleide.navigator project example.

My aim is to display the popupmenu on right click on a Document node only.

I define a fragment.xmi file containing command, handler and HandledMenuItem for a menu Open on right clic.
The popupMenu is defined on a Part

<fragments xsi:type="fragment:StringModelFragment" xmi:id="_Y-YtMPJXEd-zYovACAqcKg" featurename="children" parentElementId="west.southStack">
    <elements xsi:type="basic:Part" xmi:id="_ccS-gPJXEd-zYovACAqcKg" elementId="ui.context" contributionURI="platform:/plugin/ui.contextview/ui.contextview.ui.ContextView" label="Context">
      <menus xsi:type="menu:PopupMenu" xmi:id="_3ABIMPMwEd-ASfDNQGFGZQ" elementId="ContextView.popupmenu">
        <children xsi:type="menu:HandledMenuItem" xmi:id="_KwfCAPMxEd-ASfDNQGFGZQ" elementId="ContextView.popupmenu.open" label="Open" enabled="true" command="_JQv4IPMyEd-ASfDNQGFGZQ">
          <visibleWhen xsi:type="ui:CoreExpression" xmi:id="_wPOsQPOxEd-oqu9Gg20ngw" coreExpressionId="ui.contextview.selection.document"/>
        </children>
        <children xsi:type="menu:MenuSeparator" xmi:id="_Roqv4PMzEd-ASfDNQGFGZQ"/>
      </menus>
    </elements>
  </fragments>



The plugin.xml file contains the extension:

<extension
         point="org.eclipse.core.expressions.definitions">
      <definition
            id="ui.contextview.selection.document">
         <with
               variable="output.selection">
            <count
                  value="1">
            </count>
            <iterate
                  ifEmpty="false"
                  operator="and">
               <instanceof
                     value="ui.data.context.api.Document">
               </instanceof>
            </iterate>
         </with>
      </definition>
   </extension>


My pb is the Open Menu is always disabled. Have you got an idea ?

Thank you.

[Updated on: Fri, 19 November 2010 10:09]

Report message to a moderator

Re: show up dynamic (part) menu [message #640184 is a reply to message #640137] Fri, 19 November 2010 13:40 Go to previous message
Paul Webster is currently offline Paul WebsterFriend
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

open a bug at
https://bugs.eclipse.org/bugs/enter_bug.cgi?product=E4&c omponent=UI

If you can provide your testcase as a patch on
org.eclipse.e4.demo.simpleide.navigator that would aid in debugging the
problem.

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:Job API for Eclipse e4
Next Topic:e4: Programmatically resizing a sash container
Goto Forum:
  


Current Time: Fri Apr 19 19:58:52 GMT 2024

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

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

Back to the top