Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Platform » creating dynamic visibleWhen expression
creating dynamic visibleWhen expression [message #329813] Sun, 06 July 2008 21:02 Go to next message
Eclipse UserFriend
Originally posted by: novs.gmx.net

Hi,

I declared created a definition using the
"org.eclipse.core.expressions.definitions" definition point which is
attached to some menu and toolbar entries as visibleWhen expression, so
that they are only shown when an editor is open. However, some of the
toolbar items are not created via plugin.xml but during runtime as
CommandContributionItems. My problem is, that I'd like to attach the same
expression to these dynamically created items but the registerVisibleWhen
method from the MenuService seems to be no longer available. Is there an
alternative?

Thanks very much for your help,
Chris
Re: creating dynamic visibleWhen expression [message #329923 is a reply to message #329813] Thu, 10 July 2008 16:39 Go to previous messageGo to next message
Paul Webster is currently offline Paul WebsterFriend
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

AbstractContributionFactory is a programmatic API that provides access
to menu contribution population and is added using IMenuService. It
still has access to register the visibleWhen clause for any
IContributionItems that it provides.

The other alternative would be to use the IEvaluationService ... your
IPropertyChangeListener would have to perform the work of the
IMenuService equivalent, like marking the parent dirty and requesting an
update after all the CommandContributionItems were updated (for
toolbars, not needed for MenuManagers). This is harder to get correct.

PW


--
Paul Webster
http://wiki.eclipse.org/Platform_Command_Framework
http://wiki.eclipse.org/Command_Core_Expressions
http://wiki.eclipse.org/Menu_Contributions
http://wiki.eclipse.org/Menus_Extension_Mapping
http://help.eclipse.org/help33/index.jsp?topic=/org.eclipse. platform.doc.isv/guide/workbench.htm


Re: creating dynamic visibleWhen expression [message #330026 is a reply to message #329923] Sun, 13 July 2008 18:08 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: novs.gmx.net

Hi Paul,

Thank you very much for your answer. Using AbstractContributionFactory
seems to be a convenient way to achieve exactly what I have in mind.
However, the information in the comment of this class seems to be
outdated. The createContributionItems method is called with a
ServiceLocator and an IContributionRoot instead of an IMenuService and a
List (as mentioned in the comment). This means that I would have to
include ContributionRoot and WorkbenchMenuService, both of which are
internal, as imports. Is there a way to avoid this (to avoid problems if
the API changes in the next Eclipse version).

Regards,
Chris
Re: creating dynamic visibleWhen expression [message #330085 is a reply to message #330026] Mon, 14 July 2008 14:47 Go to previous messageGo to next message
Paul Webster is currently offline Paul WebsterFriend
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

It should be called with IServiceLocator and IContributionRoot, which
are both API ... no?

PW

--
Paul Webster
http://wiki.eclipse.org/Platform_Command_Framework
http://wiki.eclipse.org/Command_Core_Expressions
http://wiki.eclipse.org/Menu_Contributions
http://wiki.eclipse.org/Menus_Extension_Mapping
http://help.eclipse.org/help33/index.jsp?topic=/org.eclipse. platform.doc.isv/guide/workbench.htm


Re: creating dynamic visibleWhen expression [message #330089 is a reply to message #330085] Mon, 14 July 2008 15:37 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: novs.gmx.net

You are right, it's called with IContributionRoot which contains
addContributionItem as well as registerVisibilityForChild. My current
problem is, that both methods require the visibleWhen-Expression as an
argument, and I have no idea on how to create an Expression object for an
existing plugin.xml definition using the public API. It seems to work if I
use "new ReferenceExpression(expressionDefinitionID)" but this is internal.

Regards,
Chris
Re: creating dynamic visibleWhen expression [message #330093 is a reply to message #330089] Mon, 14 July 2008 17:20 Go to previous messageGo to next message
Paul Webster is currently offline Paul WebsterFriend
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

Most programmatic expressions are simply subclasses of Expression ...
the idea being that programmatic code will always be simpler/faster than
building an AST out of objects. But if you want to re-use a reference,
I can see it's hard to do :-)

As goofy as it looks, the API way to do what you want is:

String xml
= "<reference definitionId=\"org.eclipse.example.checkId\"/>";
DocumentBuilder builder
= DocumentBuilderFactory.newInstance().newDocumentBuilder();
Document doc = builder.parse(new ByteArrayInputStream(xml.getBytes()));
Expression x
= ExpressionConverter.getDefault().perform(doc.getDocumentElem ent());


PW


--
Paul Webster
http://wiki.eclipse.org/Platform_Command_Framework
http://wiki.eclipse.org/Command_Core_Expressions
http://wiki.eclipse.org/Menu_Contributions
http://wiki.eclipse.org/Menus_Extension_Mapping
http://help.eclipse.org/help33/index.jsp?topic=/org.eclipse. platform.doc.isv/guide/workbench.htm


Re: creating dynamic visibleWhen expression [message #330105 is a reply to message #330093] Tue, 15 July 2008 10:48 Go to previous message
Eclipse UserFriend
Originally posted by: novs.gmx.net

Hi Paul,

thank you very much for this solution, it certainly seems unconventional :)

Regards,
Chris
Previous Topic:Getting File path of the Bundle's location
Next Topic:How to diagnose when Eclipse dies silently
Goto Forum:
  


Current Time: Wed Jul 17 12:18:07 GMT 2024

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

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

Back to the top