I created a simple Eclipse plugin, to launch a wizard and create some files, everything is working, I also added an option lo launch the wizard from the New > Mi Wizard menu, but now I want to display this option only when I right click an specific folder in a project, this is what I have so far:
This is my wizard:
<extension point="org.eclipse.ui.newWizards">
<category
name="My Category"
id="com.test.myCategory">
</category>
<wizard
name="My Wizard"
icon="icons/wizard1.gif"
category="com.test.myCategory"
class="com.test.myWizard"
id="com.test.myWizard">
</wizard>
</extension>
And this is how I'm adding the wizard to the New menu:
<extension point="org.eclipse.ui.navigator.navigatorContent">
<commonWizard
type="new"
wizardId="com.test.myWizard"
menuGroupId="testGroup">
<enablement>
<adapt type="org.eclipse.core.resources.IFolder">
<test property="org.eclipse.wst.common.project.facet.core.projectFacet" value="myFacet:1.3" forcePluginActivation="true"/>
</adapt>
</enablement>
</commonWizard>
</extension>
The option in the New menu is displayed correctly, but it is displayed when I right click all folders, is there a way to display the option only when I right click a certain folder, specifically the WebContent folder?
You can use the org.eclipse.core.resources.name property tester to test the resource name:
<adapt type="org.eclipse.core.resources.IFolder">
<and>
<test property="org.eclipse.core.resources.name" value="WebContent"/>
<test property="org.eclipse.wst.common.project.facet.core.projectFacet" value="myFacet:1.3" forcePluginActivation="true"/>
</and>
</adapt>
Related
I use Eclipse SDK Mars.1(4.5.1). I create a propertyPages plug-in.
In plugin.xml:
If I change value of “nameFilter” to “.txt”, then only when I select .txt file, the propertyPage item can appear in left of the properties dialog;
If I change value of “nameFilter” to “.java” or “.xml” or even “.*”, then still only when I select .txt file, the propertyPage item can appear.
Here is my plugin.xml:
<?xml version="1.0" encoding="UTF-8"?>
<?eclipse version="3.4"?>
<plugin>
<extension
point="org.eclipse.ui.propertyPages">
<page
id="com.def.btp_property_3.properties.BTPPropertyPage"
name="BTP Page"
class="com.def.btp_property_3.properties.BTPPropertyPage"
nameFilter="*.java">
<enabledWhen>
<instanceof
value="org.eclipse.core.resources.IFile">
</instanceof>
</enabledWhen>
</page>
</extension>
</plugin>
Can anyone tell me the reason and give me a solution.
For the enableWhen use:
<enabledWhen>
<or>
<instanceof
value="org.eclipse.core.resources.IFile">
</instanceof>
<adapt
type="org.eclipse.core.resources.IFile">
</adapt>
</or>
</enabledWhen>
User interface elements in views are often not instances of IFile, instead they are some other object which can be 'adapted' to IFile. This enabledWhen deals with this case.
I have an eclipse RCP application (already built). I need to integrate it with eclipse UI itself. What I mean is -- I want to add a menu option in eclipse User Interface and a command in the menu which when clicked runs the application.
It is similar to find and replace option in the eclipse menu
Any idea how this can be done?
I also want the application to be bundled with eclipse
Write a plugin that you install in to Eclipse (rather than your RCP).
The plugin can use the org.eclipse.ui.menus extension point to add to the File menu. For example:
<extension
point="org.eclipse.ui.menus">
<menuContribution
locationURI="menu:file?after=open.ext">
<command
commandId="my.command.id"
id="my.menu.id"
style="push">
</command>
</menuContribution>
Use the org.eclipse.ui.commands extension point to define the command
<extension
point="org.eclipse.ui.commands">
<command
id="my.commnd.id"
description="Description text"
name="Name">
</command>
Use the org.eclipse.ui.handlers extension point to define a handler for the command
<extension
point="org.eclipse.ui.handlers">
<handler
class="package.CommandHandler"
commandId="my.command.id">
</handler>
The handler contains the code to run your RCP:
public class CommandHandler extends AbstractHandler
{
public Object execute(ExecutionEvent event) throws ExecutionException
{
// TODO launch your RCP
return null;
}
}
On developing an eclipse plugin i created a command in the Manifest extensions with id crtc_v4.session with a default handler crtc_v4.handlers.StartSession , I added a handler in the manifest for this command this handler enables the command according to the variable crtc_v4.sessionvar.
The problem which appears on the console is :
!MESSAGE Conflicting handlers for crtc_v4.session: {crtc_v4.handlers.StartSession#98bc5c} vs {crtc_v4.handlers.StartSession#1265d09}
But it doesn't block running the plugin. I'm asking about the solution for this problem, and whether it affects the performance of my plugin in general ?
Edit :
The snippet that define the command :
<extension
point="org.eclipse.ui.menus">
<menuContribution
allPopups="false"
locationURI="toolbar:org.eclipse.ui.main.toolbar">
<toolbar
id="crtc_v5.crtctoolbar">
<command
commandId="crtc_v5.session"
icon="icons/neutral.png"
label="Start Session"
style="push">
</command>
</toolbar>
</menuContribution>
The snippet that define the handler :
</extension>
<command
defaultHandler="crtc_v5.handlers.StartSession"
id="crtc_v5.session"
name="session">
</command>
</extension>
And here is the enablement against sessionvar :
<extension
point="org.eclipse.ui.handlers">
<handler
class="crtc_v5.handlers.StartSession"
commandId="crtc_v5.session">
<enabledWhen>
<with
variable="crtc_v5.sessionvar">
<equals
value="LOGGEDIN">
</equals>
</with>
</enabledWhen>
</handler>
You've defined a default handler in the command and another one in the org.eclipse.ui.handlers extension. If you want to use enabledWhen, simply remove the defaultHandler attribute (since both instances provide the same handler, crtc_v5.handlers.StartSession).
When you want to have different handlers provide the behaviour for your command depending on the application state, you would use activeWhen in the org.eclipse.ui.handlers definition, but that doesn't seem to be the case here.
I have a command to launch views configured in plugin.xml of an RCP application module as follows:
<extension
point="org.eclipse.ui.commands">
<command
defaultHandler="myapp.commandhandler.LaunchView"
id="myapp.command.launchview"
name="Map">
</command>
</extension>
I have configured this command to be shared across a couple of menu extensions like this:
<menuContribution
allPopups="false"
locationURI="menu:org.eclipse.ui.main.menu">
<menu
id="myapp.application.menu.showview"
label="Show View">
<command
commandId="myapp.command.launchview"
label="Map"
style="push">
</command>
<command
commandId="myapp.command.launchview"
label="Legend"
style="push">
</command>
</menu>
</menuContribution>
Now I want to pass a command parameter representing each view's ID, similar to what is being done here Eclipse RCP commands.
But when I add these parameter configurations, these menu items disappear from the main menu. Any ideas?
Menu item will disappear from menu if the commandId or commandParameter it is bound to does not exist.
I have written a custom launcher in Eclipse which I can access via the "Run As" and "Debug As" menu options on the toolbar. I also want to be able to launch via the package explorer and via right clicking on the editor of a file to be launched. I followed the tutorial here to add the shortcut but nothing happens, it does not enter my handling code, nor does it complain regarding the configuration of the extension point.
Here is a snippet from my plugin.xml
<extension point="org.eclipse.debug.ui.launchShortcuts">
<shortcut
id = "org.mylauncher.launchCalcShortcut"
class = "org.mylauncher.LaunchCalcShortcut"
description="Execute calculations"
icon="icons/launch_16_16.png"
label="Calculate"
modes="run, debug" >
<configurationType id="org.mylauncher.launchCalc"/>
</shortcut>
I have also played with removing the (optional) icon attribute, and have separately validated the path of the icon.
I've been modifying this configuration for hours now with no good result and it is impossible to debug as it is not running in my own code at all.
Thanks.
It seems that the correct answer to this problem is to specify a contextual launch shortcut. Here is my working configuration:
<extension
point="org.eclipse.debug.ui.launchShortcuts">
<shortcut
class="com.xxxx.CalcLaunchShortcut"
icon="calc.png"
id="com.xxxx.CalcLaunchShortcut"
label="Calc"
modes="run, debug">
<contextualLaunch>
<contextLabel mode="run" label="Run Calculator" />
<contextLabel mode="debug" label="Debug Calculator" />
<enablement >
<with variable="selection">
<count value="1"/>
<iterate>
<adapt type="org.eclipse.core.resources.IResource">
<and>
<test property="org.eclipse.core.resources.name" value="*.calc"/>
</and>
</adapt>
</iterate>
</with>
</enablement>
</contextualLaunch>
</shortcut>