Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Platform » Help getting popup menu item to appear based on a System Property
Help getting popup menu item to appear based on a System Property [message #334031] Fri, 16 January 2009 05:06 Go to next message
Nadeem Aboobaker is currently offline Nadeem AboobakerFriend
Messages: 20
Registered: July 2009
Junior Member
Hello all,

I have a menu item on the right-click Popup Menu for a Project in the
Project Explorer. I want this menu item to only appear if a certain
System Property is set; I don't care what value it is set to, only that it
is set. Does anybody have any suggestions?

I've been searching the newsgroups, searching Google, experimenting with
my plugin.xml, and looking at the Eclipse source code trying to get it to
work.

I initially thought I'd use <visibility> and <systemProperty ...> on my
<objectContribution> to org.eclipse.ui.popupMenus. It doesn't seem like I
can specify in the plugin.xml that the value of the System Property is
anything or, in the negative case, that the value is not set or null. In
reading the source code of
org.eclipse.ui.internal.ActionExpression.SystemPropertyExpre ssion, I see
that isEnabledFor() always returns false when the System Property is not
set. So, I can set the visibility like so:

<visibility>
<not>
<systemProperty name="some.property" value=""/>
</not>
</and>

However, if the System Property is set to something, this doesn't work at
all.


My next thought was to use <filter> on my <objectContribution> and write
a custom org.eclipse.ui.IActionFilter. However, this doesn't seem like it
will work, because the menu item acts on a Project which already has an
IActionFilter.


The last thought was that I could set write code in my plugin activator
that would set the System Property to "" if it wasn't already set before.
Of course, this won't work, because the plugin with my action won't be
activated yet. This wouldn't work anyway, since in my case, the System
Property being set to a valid value is required for the plugin activator
to work correctly. So, I can't even make my plugin an EarlyStartup plugin
to set the System Property to "".



Thanks in advance!
Nadeem Aboobaker
Re: Help getting popup menu item to appear based on a System Property [message #334047 is a reply to message #334031] Fri, 16 January 2009 14:59 Go to previous messageGo to next message
Nadeem Aboobaker is currently offline Nadeem AboobakerFriend
Messages: 20
Registered: July 2009
Junior Member
I forgot to mention that I'm using Eclipse 3.3.2.

Also, I tried EarlyStartup as mentioned in my "last thought" after
re-organizing my code so the plugin activation does not depend on the
system property. I can now get the exact behavior I want, but it seems a
little hacky to use EarlyStartup for this (and plus, I'm not sure what
side effects are caused by EarlyStartup for my plugin).

So, I'm still searching for the "right" solution, if it exists. :)

Thanks!
Nadeem


Nadeem Aboobaker wrote:

> Hello all,

> I have a menu item on the right-click Popup Menu for a Project in the
> Project Explorer. I want this menu item to only appear if a certain
> System Property is set; I don't care what value it is set to, only that it
> is set. Does anybody have any suggestions?

> I've been searching the newsgroups, searching Google, experimenting with
> my plugin.xml, and looking at the Eclipse source code trying to get it to
> work.

> I initially thought I'd use <visibility> and <systemProperty ...> on my
> <objectContribution> to org.eclipse.ui.popupMenus. It doesn't seem like I
> can specify in the plugin.xml that the value of the System Property is
> anything or, in the negative case, that the value is not set or null. In
> reading the source code of
> org.eclipse.ui.internal.ActionExpression.SystemPropertyExpre ssion, I see
> that isEnabledFor() always returns false when the System Property is not
> set. So, I can set the visibility like so:

> <visibility>
> <not>
> <systemProperty name="some.property" value=""/>
> </not>
> </and>

> However, if the System Property is set to something, this doesn't work at
> all.


> My next thought was to use <filter> on my <objectContribution> and write
> a custom org.eclipse.ui.IActionFilter. However, this doesn't seem like it
> will work, because the menu item acts on a Project which already has an
> IActionFilter.


> The last thought was that I could set write code in my plugin activator
> that would set the System Property to "" if it wasn't already set before.
> Of course, this won't work, because the plugin with my action won't be
> activated yet. This wouldn't work anyway, since in my case, the System
> Property being set to a valid value is required for the plugin activator
> to work correctly. So, I can't even make my plugin an EarlyStartup plugin
> to set the System Property to "".



> Thanks in advance!
> Nadeem Aboobaker
Re: Help getting popup menu item to appear based on a System Property [message #334049 is a reply to message #334031] Fri, 16 January 2009 15:37 Go to previous messageGo to next message
Nadeem Aboobaker is currently offline Nadeem AboobakerFriend
Messages: 20
Registered: July 2009
Junior Member
I forgot to mention that I'm using Eclipse 3.3.2.

Also, I tried the EarlyStartup option mentioned in the "last thought" of
the original post. After, re-organizing my code so that the plugin
initialization does not require the system property, the visibility of the
popup menu item works as I want. However, it seems a little "hacky" to
use EarlyStartup (not to mention, I'm unsure of the side effects of
EarlyStartup on my plugin).

So, does anybody know the right solution, if it exists?

Thanks,
Nadeem Aboobaker


Nadeem Aboobaker wrote:

> Hello all,

> I have a menu item on the right-click Popup Menu for a Project in the
> Project Explorer. I want this menu item to only appear if a certain
> System Property is set; I don't care what value it is set to, only that it
> is set. Does anybody have any suggestions?

> I've been searching the newsgroups, searching Google, experimenting with
> my plugin.xml, and looking at the Eclipse source code trying to get it to
> work.

> I initially thought I'd use <visibility> and <systemProperty ...> on my
> <objectContribution> to org.eclipse.ui.popupMenus. It doesn't seem like I
> can specify in the plugin.xml that the value of the System Property is
> anything or, in the negative case, that the value is not set or null. In
> reading the source code of
> org.eclipse.ui.internal.ActionExpression.SystemPropertyExpre ssion, I see
> that isEnabledFor() always returns false when the System Property is not
> set. So, I can set the visibility like so:

> <visibility>
> <not>
> <systemProperty name="some.property" value=""/>
> </not>
> </and>

> However, if the System Property is set to something, this doesn't work at
> all.


> My next thought was to use <filter> on my <objectContribution> and write
> a custom org.eclipse.ui.IActionFilter. However, this doesn't seem like it
> will work, because the menu item acts on a Project which already has an
> IActionFilter.


> The last thought was that I could set write code in my plugin activator
> that would set the System Property to "" if it wasn't already set before.
> Of course, this won't work, because the plugin with my action won't be
> activated yet. This wouldn't work anyway, since in my case, the System
> Property being set to a valid value is required for the plugin activator
> to work correctly. So, I can't even make my plugin an EarlyStartup plugin
> to set the System Property to "".



> Thanks in advance!
> Nadeem Aboobaker
Re: Help getting popup menu item to appear based on a System Property [message #334058 is a reply to message #334031] Fri, 16 January 2009 19:59 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: coolsnoopy.gmx.net

Nadeem Aboobaker wrote:
> Hello all,
>
> I have a menu item on the right-click Popup Menu for a Project in the
> Project Explorer. I want this menu item to only appear if a certain
> System Property is set; I don't care what value it is set to, only that
> it is set. Does anybody have any suggestions?
>
Talking about "System Property", so:
what about simply using java.lang.System.getProperty("myproperty") or do
I miss something here?

Regards, Norbert
Re: Help getting popup menu item to appear based on a System Property [message #334061 is a reply to message #334058] Fri, 16 January 2009 22:20 Go to previous message
Nadeem Aboobaker is currently offline Nadeem AboobakerFriend
Messages: 20
Registered: July 2009
Junior Member
Norbert Ziegler wrote:

> Nadeem Aboobaker wrote:
>> Hello all,
>>
>> I have a menu item on the right-click Popup Menu for a Project in the
>> Project Explorer. I want this menu item to only appear if a certain
>> System Property is set; I don't care what value it is set to, only that
>> it is set. Does anybody have any suggestions?
>>
> Talking about "System Property", so:
> what about simply using java.lang.System.getProperty("myproperty") or do
> I miss something here?

> Regards, Norbert


I wasn't aware that you could specify Java code in a plugin.xml. Can you
please give an example of how I would use System.getProperty() in my
org.eclipse.ui.popupMenus extension in plugin.xml?

Thanks,
Nadeem
Previous Topic:Where to write initialization code before plug-in launches?
Next Topic:Re: pde headless build error
Goto Forum:
  


Current Time: Wed Jul 17 21:19:48 GMT 2024

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

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

Back to the top