Eclipse PropertyPage enabling - eclipse

I want to add a property page in eclipse via my plugin. This property page must be enabled only for projects of my nature. I have written the below code in plugin.xml
<extension
point="org.eclipse.ui.propertyPages">
<page
class="com.test.me.ME"
id="com.test.me.ME"
name="ME">
<and>
<instanceof
value="org.eclipse.core.resources.IProject">
</instanceof>
<adapt
type="org.eclipse.core.resources.IResource">
<test
property="org.eclipse.core.resources.projectNature"
value="com.test.me.meprojectnature">
</test>
</adapt>
</and>
</page>
The above code works fine for the projects in project explorer and navigator view. But the same doesn't work in package Explorer view.
So, how to achieve the same functionality specific for package explorer view?

You should move your instanceof check inside adapt.

I have not tried it but my opinion is that in your package explorer there aren't org.eclipse.core.resources.IProject elements, you should try whatever input you have (for example org.eclipse.jdt.core.IJavaProject)

#nitind is right, you're specifying too many constraints. You want to say "Enabled when the selection is adaptable to an IProject and it's "projectNaure" property includes "my nature."
This should do it:
<extension point="org.eclipse.ui.propertyPages">
<page
name="My Property Page"
class="some.package.MyPropertyPage"
id="some.package.MyPropertyPage">
<enabledWhen>
<adapt type="org.eclipse.core.resources.IProject">
<test
property="org.eclipse.core.resources.projectNature"
value="some.package.MyNatureID"/>
</adapt>
</enabledWhen>
</page>

Related

Eclipse RCP: How to properly create a toolbar with global actions using the Command framework?

I my RCP application there is a view with a TreeViewer inside. Using the Command framework, I’m trying to populate its toolbar with items that would perform common actions on the tree elements, such as “delete", “properties" etc.
I would like the icons to be enabled/disabled according to the TreeViewer’s selection state, but they should always be visible.
Here is what I came up with so far (I’m showing only the delete command, the others are very similar):
<extension point="org.eclipse.ui.handlers">
<handler commandId="org.eclipse.ui.edit.delete" class="my.custom.DeleteHandler">
<activeWhen>
<with variable="activePartId">
<equals value="my.custom.ViewPart" />
</with>
</activeWhen>
<enabledWhen>
<count value="(0-" />
</enabledWhen>
</handler>
</extension>
<extension point="org.eclipse.ui.menus">
<menuContribution locationURI="toolbar:my.custom.ViewPart">
<command commandId="org.eclipse.ui.edit.delete" label="Delete" />
</menuContribution>
</extension>
Everything works fine as long as the active part is my tree view. But when the focus goes, say, to an editor, the buttons get activated. I suppose this happens because my custom handlers are deactivated in favor of the default workbench handlers.
How can I keep the "delete", "properties" items visible but disabled, when the active part is not my view part?
Don't use <activeWhen> instead put all your conditions in the <enabledWhen>:
<enabledWhen>
<and>
<count value="(0-" />
<with variable="activePartId">
<equals value="my.custom.ViewPart" />
</with>
</and>
</enabledWhen>

enabledwhen without using property tester class

I have a tree created using TreeViewer. I want to disable a menu item say "Expand All" when user right clicks on the last tree item (i.e., tree item does not have a child). Using PropertyTester i am able to achieve this.
plugin.xml code:
<enabledWhen>
<with
variable="selection">
<iterate
ifEmpty="false">
<instanceof
value="com.xxx.automation.touchstone.model.GUIObject">
</instanceof>
</iterate>
<test
forcePluginActivation="true"
property="com.xxx.automation.touchstone.testers.GUIObjects.canExpandAll"
value="true">
</test>
</with>
</enabledWhen>
I want to know if we can achieve the same without using property tester class. I mean using ContentProvider's hasChildren method within the plugin xml .
Thoughts

How create popup menu item in PackageExplorer only for directories

I am writing Eclispe (Kepler) plugin. Main goal of this plugin is to add in PackageExplorer popup menu "Open In Explorer" item. This item should be visible for directories,packages etc. but no for files. I've tried this:
<menuContribution
locationURI="popup:org.eclipse.jdt.ui.PackageExplorer">
<command
commandId="pl.com.tt.wide.lms.core.commands.sampleCommand"
id="pl.com.tt.wide.lms.core.menus.sampleCommand"
mnemonic="S">
<visibleWhen>
<with variable="activeMenuSelection">
<iterate
ifEmpty="false">
<adapt type="org.eclipse.core.resources.IResource">
<test property="org.eclipse.core.resources.type" value="org.eclipse.core.resources.FOLDER"/>
</adapt>
</iterate>
</with>
</visibleWhen>
</command>
</menuContribution>
This is not working. Do you have any suggestions how to accomplish this?
Thanks for any help.
I think, first of all the idea is not to hide elements of a Menu, rather disable them. This gives users at least the hint, that there will be a command available, but not just now. So I'd use "enableWhen" instead of "visibleWhen".
Otherwise you have weirdly changing menus and orders of items depending on selection, which might increase the confusion. Especially within Eclipse, where you are surrounded by confusion. :-)
Maybe take a look at the this already existing plug-in: http://marketplace.eclipse.org/content/easyshell#.Ul6fNfnIZsg
The Package Explorer does not only use types of org.eclipse.core.resources but uses the types of org.ecliplse.jdt.core, too.
Have a look at IPackageFragment, IPackageFragmentRoot and IJavaProject. Using these in an or statement will probably produce, what you want.
This is what worked for me:
<visibleWhen>
<with variable="activeMenuSelection">
<iterate ifEmpty="false">
<or>
<adapt type="org.eclipse.jdt.core.IJavaProject">
</adapt>
<adapt type="org.eclipse.jdt.core.IPackageFragmentRoot">
</adapt>
<adapt type="org.eclipse.jdt.core.IPackageFragment">
</adapt>
</or>
</iterate>
</with>
</visibleWhen>

How to hide default menus in RCP?

I am new in Eclipse RCP plug in development.
I had written one plug-in with my own perspective and added perspective specific menus within it.
My question is how to hide the default menus provided within Eclipse, like Edit, Navigated, Search, Project ?
I tried with using '< extension point="org.eclipse.core.expressions.definitions" >'
and putting my view specific condition, withing menu contribution's.
Any help is appreciated.
Best regards,
Mandar Phatak.
You need activities. Example from my current project:
<extension
point="org.eclipse.ui.activities">
<activity
id="arm.activity.disabled"
name="%arm.activity.disabled.name">
<enabledWhen>
<with
variable="selection">
<count
value="-1">
</count>
</with>
</enabledWhen>
</activity>
<activityPatternBinding
activityId="arm.activity.disabled"
pattern="org\.eclipse\.m2e\..*">
</activityPatternBinding>
<activityPatternBinding
activityId="arm.activity.disabled"
pattern="org\.eclipse\.search\..*">
</activityPatternBinding>
<activityPatternBinding
activityId="arm.activity.disabled"
pattern="org\.eclipse\.team\..*">
</activityPatternBinding>
<activityPatternBinding
activityId="arm.activity.disabled"
pattern="org\.eclipse\.compare.*">
</activityPatternBinding>
<activityPatternBinding
activityId="arm.activity.disabled"
pattern="org\.eclipse\.help\.ui\.PrefPageHelp.*">
</activityPatternBinding>
<activityPatternBinding
activityId="arm.activity.disabled"
isEqualityPattern="true"
pattern="org.eclipse.ui.ide/org.eclipse.ui.preferencePages.Workspace">
</activityPatternBinding>
<activityPatternBinding
activityId="arm.activity.disabled"
isEqualityPattern="true"
pattern="org.eclipse.ui.ide/org.eclipse.ui.preferencePages.Perspectives">
</activityPatternBinding>
</extension>
One approach is in your rcp application you have a class that extends ActionBarAdvisor and in the constructor of the class you can do something like this for example to remove the edit menu
configurer.getMenuManager().remove(IWorkbenchActionConstants.M_EDIT);
All common eclipse menus like edit will have a constant defined in the class above, do that for the menu's you want to remove from your application.
This is only one approach I'm sure there might be others but hope this gets what you need.

adding and removing popup menu items for java file

I wanted to add one item in the popup when I right click all java file which is in the package explorer. I gave the object class as org.eclipse.core.resources.IFile and nameFilter is *.java. But it does not work for me.But If I give some other extensions as namefilter like *.abc, then it works for me. How do I add popupmenu items into java files?Wont eclipse support the popumenu item for adding into java files? And also I need to remove some of the existing popumenu items for the java files.How can I do that?
Please help me in this.
Thanks
Bhanu
Use commands, not actions. The code below should work.
<extension
point="org.eclipse.ui.menus">
<menuContribution
locationURI="popup:org.eclipse.jdt.ui.PackageExplorer">
<command
commandId="my id"
label="my command label"
style="push">
<visibleWhen>
<with variable="activeMenuSelection">
<iterate
ifEmpty="false">
<adapt type="org.eclipse.core.resources.IResource">
<test property="org.eclipse.core.resources.name" value="*.java" />
</adapt>
</iterate>
</with>
</visibleWhen>
</command>
</menuContribution>
</extension>
However, if you must contribute an action, here's how to do it.
As for removing items from a menu, this question has been posted and answered several times on SO already, for example here.