Skip to main content



      Home
Home » Eclipse Projects » Eclipse 4 » Handled tool item - visible when(Handled tool item visible when)
Handled tool item - visible when [message #1007153] Mon, 04 February 2013 10:59 Go to next message
Eclipse UserFriend
I want a "Handled tool item" to be visible only when the active part is an instance of a specific class.

What is the right way to obtain that.

Best regards,
Alain
Re: Handled tool item - visible when [message #1007487 is a reply to message #1007153] Wed, 06 February 2013 02:18 Go to previous messageGo to next message
Eclipse UserFriend
Use a core expression as explained here http://www.eclipse.org/forums/index.php/t/452233/
Re: Handled tool item - visible when [message #1007681 is a reply to message #1007153] Thu, 07 February 2013 00:14 Go to previous messageGo to next message
Eclipse UserFriend
Thanks for answer.
Core expression works with menu:HandledMenuItem but not with menu:HandledToolItem.

In plugin.xml file, following extension is added:
   <extension point="org.eclipse.core.expressions.definitions">
      <definition id="debugenabled">
         <with variable="debugEnabled">
            <equals value="true"/>
         </with>
      </definition>
   </extension>

In Application.e4xmi file, following code is added:
...
<children xsi:type="basic:TrimmedWindow" xmi:id="xxx" elementId="adichatz.application.trimmedwindow" label="Adichatz RCP" width="500" height="400">
  <mainMenu xmi:id="xxx" elementId="menu:org.eclipse.ui.main.menu">
    <children xsi:type="menu:Menu" xmi:id="xxx" label="File">
      <children xsi:type="menu:HandledMenuItem" xmi:id="xxx" label="Open" iconURI="platform:/plugin/E4Project/icons/open.gif" command="xxx"/>
      <children xsi:type="menu:HandledMenuItem" xmi:id="saveMenuItem" label="Save" iconURI="platform:/plugin/E4Project/icons/save.gif" command="xxx">
            <visibleWhen xsi:type="ui:CoreExpression" xmi:id="xxx" coreExpressionId="debugenabled"/>
      </children>
    </children>
  </mainMenu>
  <trimBars xmi:id="xxx" elementId="adichatz.application.window.trim">
    <children xsi:type="menu:ToolBar" xmi:id="xxx" elementId="toolbar:org.eclipse.ui.main.toolbar">
      <children xsi:type="menu:HandledToolItem" xmi:id="xxx" iconURI="platform:/plugin/E4Project/icons/open.gif" command="xxx"/>
      <children xsi:type="menu:HandledToolItem" xmi:id="xxx" iconURI="platform:/plugin/E4Project/icons/save.gif" command="xxx">
            <visibleWhen xsi:type="ui:CoreExpression" xmi:id="xxx" coreExpressionId="debugenabled"/>
      </children>
    </children>
  </trimBars>
</children>
...


Menu handle can be hidden or shown. But there is no effect on menu item.

Any suggestion?
Re: Handled tool item - visible when [message #1007693 is a reply to message #1007681] Thu, 07 February 2013 02:42 Go to previous messageGo to next message
Eclipse UserFriend
Hi,

I tested this in my little example and IMHO this is a bug. It seems that only the visible flag it checked for HandledMenuItems, not the core expression.

To the Eclipse 4 developers: Is this a already known bug?

Greez,
Dirk

P.S. If you need a running example just let me know, my toolbar example I provided in other bugs already can be easily adjusted to show that behaviour.
Re: Handled tool item - visible when [message #1007714 is a reply to message #1007693] Thu, 07 February 2013 04:18 Go to previous messageGo to next message
Eclipse UserFriend
What's the build id?
Re: Handled tool item - visible when [message #1007716 is a reply to message #1007714] Thu, 07 February 2013 04:33 Go to previous messageGo to next message
Eclipse UserFriend
I20121214-0730 ... haven't updated to M5 yet
Re: Handled tool item - visible when [message #1007764 is a reply to message #1007716] Thu, 07 February 2013 07:55 Go to previous messageGo to next message
Eclipse UserFriend
Please file a bug on platform/ui then.
Re: Handled tool item - visible when [message #1007791 is a reply to message #1007764] Thu, 07 February 2013 09:04 Go to previous messageGo to next message
Eclipse UserFriend
Created a bug for this https://bugs.eclipse.org/bugs/show_bug.cgi?id=400217

Also found out the the visibility could not be changed at runtime for tool items and menu items that are directly added to the main menu.
Re: Handled tool item - visible when [message #1007831 is a reply to message #1007153] Thu, 07 February 2013 11:51 Go to previous messageGo to next message
Eclipse UserFriend
Thanks for all.
I think, i have found a workaround.
in the handler class add this code:
HandledToolItemImpl refreshToolItem;

@CanExecute
boolean isVisible(@Named(IServiceConstants.ACTIVE_PART) MPart part) {
	boolean visible = null != part && part.getObject() instanceof MyPart;
	refreshToolItem.setVisible(visible);
	return true;
}

@PostConstruct
public void postConstruct(MApplication application, EModelService modelService) {
	refreshToolItem = (HandledToolItemImpl) modelService.find("refresh.toolItem", application);
}

@Execute
...


Any comment?
Re: Handled tool item - visible when [message #1007912 is a reply to message #1007831] Fri, 08 February 2013 02:21 Go to previous message
Eclipse UserFriend
I don't think this solves the issue well. In the example I attached to the bug you will see that even setting the visible flag to true doesn't rerender correctly if there is another tool item in the toolbar. But if this is working for you in your case, then you should use it until the bug is fixed. Smile
Previous Topic:How to implement the 'New window' command (org.eclipse.ui.window.newWindow)
Next Topic:Eclipse 4 menu icon size
Goto Forum:
  


Current Time: Wed Apr 30 23:20:06 EDT 2025

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

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

Back to the top