Why is my property tester invoked when selecting text in editor? - eclipse-plugin

In my eclipse plugin that I'm writing I want to be able to make a popup menu contribution to be visible or not depending on the content on the current selected row in the editor.
To accomplice this I use a property tester. The test performed by the property tester can be a bit time consuming (~ 200 miliseconds) which is ok when it comes to waiting for the popup menu to show.
However I've noticed that the property tester is not only invoked when the popup is about to be shown, but it is also invoked as soon as I'm marking text in the editor making selection of text very slow and annoying.
So the questions are: Why is it invoked when I select/mark text and not just when the popup is about to be shown, and how can I avoid that ?
This is how I've set up the property tester and the menu:
<extension
point="org.eclipse.core.expressions.propertyTesters">
<propertyTester
class="popupmenucontribtest.PropertyTester"
id="PopupMenuContribTest.test1"
namespace="PopupMenuContribTest.propertyTester"
properties="propertyTester1"
type="java.lang.Object">
</propertyTester>
<extension
point="org.eclipse.ui.menus">
<menuContribution
allPopups="false"
locationURI="popup:org.eclipse.ui.popup.any?after=additions">
<command
commandId="PopupMenuContribTest.command"
label="My Popup Option"
style="push">
<visibleWhen
checkEnabled="false">
<and>
<test
forcePluginActivation="true"
property="PopupMenuContribTest.propertyTester.propertyTester1">
</test>
</and>
</visibleWhen>
</command>
</menuContribution>
Thanks!

You specified that property tester to be invoked for every instance of java.lang.Object, using the type attribute in your definition. Restrict this to a more concrete super class of your editor. See this example, where it is restricted to resources.
That said, to my mind a property test duration of 200 milli seconds is not acceptable, as users will notice such delays.

Related

grouping toolwindows in menu

I am creating several tool windows and i would like to group them all under the same designated menu or at least a submenu of view
I am able to make the tool windows using this sort of syntax in the plugin xml:
<extensions defaultExtensionNs="com.intellij">
<toolWindow id="My Sample Tool Window" secondary="true" icon="/myToolWindow/plus.png" anchor="right" factoryClass="myToolWindow.MyToolWindowFactory"/>
</extensions>
and I am able to make menus and menu items like this:
<actions>
<group id="SampleMenu" text="Sample Menu" description="Sample menu">
<action id="Textboxes" class="TextBoxes" text="Text _Boxes" description="A test menu item" />
<add-to-group group-id="MainMenu" relative-to-action="HelpMenu" anchor="before" />
</group>
</actions>
but I can't seem to figure out how to combine the two or find the relevant parts in the documentation
You can't control how toolwindows are presented under View | Tool Windows. You can define your own actions to show your toolwindows, and add those actions in any
other place of the menu, as a group or in any way that you prefer.
To activate a toolwindow programmatically, use:
ToolWindowManager.getInstance(project).getToolWindow(YOUR_ID).activate(null);

Right click doesn't work in plugin.xml

I am following this tutorial http://www.vogella.com/tutorials/EclipsePlugin/article.html#exercise-adding-e4view-based-parts-to-3-x-based-applications . When I'm trying to right click in extension tab to add a new e4View as shown in a tutorial, nothing happens, the popup menu doesn't appear. Is it possible to create this view in different way?
You can always edit the plugin.xml directly by clicking on the 'plugin.xml' tab.
A basic e4view would look something like:
<extension
point="org.eclipse.ui.views">
<e4view
class="testview.E4view1"
id="TestView.e4view1"
name="name"
restorable="true">
</e4view>
</extension>

how to add Wizards created in New->File->others into popup menus when right click in project explorer

I have created a category in File->New->Others say "Enterprise".With some Wizards in it lets say "Instance","Component", etc.
Now what i want ,when i right click in Project Explorerand go in New those wizards should be seen their itself. Basically trying to make popup menu of those wizards.
So i created popup menus as:
<extension
point="org.eclipse.ui.menus">
<menuContribution
allPopups="true"
locationURI="popup:common.new.menu?before=additions">
<command
commandId="CommandComponent"
label="Component"
style="push">
</command>
</menuContribution>
</extension>
<extension
point="org.eclipse.ui.commands">
<command
id="CommandComponent"
name="Component">
</command>
</extension>
<extension
point="org.eclipse.ui.handlers">
<handler
commandId="CommandComponent">
</handler>
</extension>
Now how could I give the same class to the handler which I gave to Wizard Component?
Or do I have to write a new class with the same functionality but as per handler format (if it is possible)?
You use the org.eclipse.ui.perspectiveExtensions extension point to define the New Wizards which are show at the top level of the New menu using the newWizardShortcut element.
Something like:
<extension
point="org.eclipse.ui.perspectiveExtensions">
<perspectiveExtension
targetID="org.eclipse.jdt.ui.JavaPerspective">
<newWizardShortcut
id="org.eclipse.jdt.junit.wizards.NewTestCaseCreationWizard">
</newWizardShortcut>
</perspectiveExtension>
(which is the New JUnit Test Case shortcut).
You may need to Reset the Perspective or use Customize Perspective to make the item visible as the user has control over which of these shortcuts is shown.
More info in the help
This is what I did, in order to achieve what I was asking for.
A popup menu when I right click in project explorer it shows New -> Component Wizard. Which I have added in File -> New -> Others.
<extension point="org.eclipse.ui.menus">
<menuContribution allPopups="false" locationURI="popup:common.new.menu?after=new">
<command commandId=" org.eclipse.ui.newWizard" style="push">
<visibleWhen checkEnabled="false">
<with variable="activeWorkbenchWindow.activePerspective">
<equals value="org.eclipse.ui.resourcePerspective"></equals>
</with>
</visibleWhen>
<parameter name="newWizardId" value="Component"></parameter>
</command>
</menuContribution>
</extension>
Just like greg-449 mentioned, use the "org.eclipse.ui.perspectiveExtensions" extension point to contribute your elements to the perspective that you want.
When you right click on the project explorer or package explorer and click on New, the projects shown there are dependent on the perspective you are in. If you are in a Java perspective, you will find Java Project. If you are in the PDE perspective, you will find Plugin project. So it's good to contribute your Project type in the perspective you want it.

Location URI's for action sets

I want to add menu and toolbar item in the eclispe using the commands.
I want to add menu item after the Run -> External Tools menu item and toolbar action also after the External Tools action.
I have used below Location URI's but they are not helping.
for the Menu Item : menu:org.eclipse.debug.ui.launchActionSet?after=org.eclipse.ui.externaltools.ExternalToolMenuDelegateToolbar
for the toolbar action : toolbar:org.eclipse.debug.ui.launchActionSet?after=org.eclipse.ui.externaltools.ExternalToolMenuDelegateToolbar
My plug-in.xml snippet appears as shown below.
<extension
point="org.eclipse.ui.menus">
<menuContribution
locationURI="toolbar:org.eclipse.debug.ui.launchActionSet?after=org.eclipse.ui.externaltools.ExternalToolMenuDelegateToolbar">
<command
commandId="com.sample.uvextensions.commands.sampleCommand"
icon="icons/sample.gif"
id="com.sample.uvextensions.toolbars.sampleCommand"
label="Debug UV Project"
style="push"
tooltip="launches keil&apos;s debug session for selected project">
</command>
</menuContribution>
<menuContribution
locationURI="menu:org.eclipse.debug.ui.launchActionSet">
<command
commandId="com.sample.uvextensions.commands.sampleCommand"
icon="icons/sample.gif"
id="com.sample.uvextensions.menus.sampleCommand"
label="Debug UV Project"
style="push"
tooltip="launches keil&apos;s debug session for selected project">
</command>
</menuContribution>
Any pointers will be greatly helpfull for me.
Thanks in Advance.
Menu contributions can't refer to action sets because actions sets are processed after menu contributions and are not visible for the former.
You can declare your own action set and add actions with the same menubarPath ("org.eclipse.ui.run/ExternalToolsGroup") and toolbarPath ("org.eclipse.debug.ui.launchActionSet/debug") as those in the external tools plugin. To get your actions placed after those from the other plugin, make sure your action set ID is greater than "org.eclipse.ui.externaltools.ExternalToolsSet".

some of the toolbar menus are not seen in eclipse rcp application

When I launch rcp application some of the custom toolbar menus doesnot appear in my rcp application,if I change perspective then they appears.Any idea?
That's hard to say with no additional information. How do you create those toolbar items? Using some contributor class or in plugin.xml, using menu contributions? With the second option, check, that you have defined them in the proper plugin.xml (the one, which defines your perspective, in which you want to actually see them).
Ensure, that there are handlers for your commands/actions in your perspective.
If you are using associations, ensure, that those are correct:
<extension point="org.eclipse.ui.actionSetPartAssociations">
<actionSetPartAssociation targetID="YouractionSetId">
<part id="YourPartId"/>
</actionSetPartAssociation>