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.
Related
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;
}
}
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>
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>
I am using menuContributions+popup to show a context menu in my plugin.xml. I need to limit it's visibility only to
certain type of Project(e.g. Dynamic Web Project) (Menu should appear on right click of only parent project folder) and
a particular folder(e.g Web Content) and it's sub folders inside the Project Folder structure.
I was able to achieve the 1) condition to some extent by using
<menuContribution locationURI="popup:common.new.menu?after=additions">
<command
label="Web Wiz"
commandId="commandId"
icon="icons/sample.gif">
<visibleWhen>
<with variable="selection">
<iterate ifEmpty="false"
operator="or">
<instanceof
value="org.eclipse.core.resources.IProject"/>
</iterate>
</with>
</visibleWhen>
</command>
</menuContribution>
but it appears for all kinds of projects...I need to limit it to only a Dynamic Web Project, so what should I add to meet this requirement in plugin.xml?
Add a propertyTester that will test your project type.
Use that tester in the visibleWhen
You can read about property-tester at the eclipse help, or at the extension help itself :)
EDIT - Check this one out as well - http://wiki.eclipse.org/Command_Core_Expressions#Property_Testers (especially the ResourcePropertyTester, which can provide you a built-in implementation that you can use)
For the second condition:
<test forcePluginActivation="true"
property="testWizard.propertyTester.checkFolder"
value="org.eclipse.wst.jsdt.core.jsNature"
</test>
is the reference to the property tester , which can be defined as
<extension
point="org.eclipse.core.expressions.propertyTesters">
<propertyTester
class="testwizard.wizards.MyPropTester"
id="MyPropTesterFolder"
namespace="testWizard.propertyTester"
properties="checkFolder"
type="org.eclipse.core.resources.IFolder">
</propertyTester>
then the kind of folder and it's subfolders can be tested as below in
package testwizard.wizards;
import org.eclipse.core.expressions.PropertyTester;
import org.eclipse.core.resources.IFolder;
import org.eclipse.core.runtime.CoreException;
public class MyPropTester extends PropertyTester{
#Override
public boolean test(Object receiver, String property, Object[] args,
Object expectedValue) {
IFolder folder=(IFolder)receiver;
String folderPath=folder.getProjectRelativePath().toString();
String arr[]=folderPath.split("/");
try {
if(folder.getProject().hasNature(expectedValue.toString()))
{
if(arr[0].equals("XYZ"))
{
return true;
}
}
} catch (CoreException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return false;
}
}
<menuContribution locationURI="popup:common.new.menu?after=additions">
<command
label="Web Wiz"
commandId="commandId"
icon="icons/sample.gif">
<visibleWhen>
<with variable="selection">
<iterate operator="and" ifEmpty="false">
<test
property="org.eclipse.core.resources.projectNature"
value="your-project-nature" />
</iterate>
</with>
</visibleWhen>
</command>
<menuContribution>