Command Expression for active debug session? - eclipse

I added the extension point org.eclipse.ui.menus to create a new button in the debug view.
That works perfectly, but this particular button is now always visible. How can I add a visibleWhen condition that checks if a debug session is currently running?
I checked the Command Core Expressions, but did not find any expressions that may work in that case.

The menus in the org.eclipse.jdt.debug.ui plugin use expressions like this:
<visibleWhen
checkEnabled="false">
<and>
<systemTest
property="org.eclipse.jdt.debug.ui.debuggerActive"
value="true">
</systemTest>
... other tests ...
</and>
</visibleWhen>

There is a good example project in CDT on how to get started customizing DSF. Please have a look at it's plugin.xml and follow the uses of the command id defined there: org.eclipse.cdt.examples.dsf.gdb.command.showVersion
Here is one of the visibleWhen's from that code.
<visibleWhen
checkEnabled="false">
<and>
<reference
definitionId="org.eclipse.cdt.debug.ui.testIsDebugActionSetActive">
</reference>
<with variable="org.eclipse.core.runtime.Platform">
<test property="org.eclipse.core.runtime.bundleState"
args="org.eclipse.cdt.examples.dsf.gdb"
value="ACTIVE">
</test>
</with>
</and>
</visibleWhen>

Related

Eclipse Plugin: what property attribut for testing name of subversion resources

I'm writing a plugin. To start it, the menu entry is displayed when doing a rightclick on a project in SVN-Plugin-View. By using "org.tigris.subversion.subclipse.ui.repository.RepositoriesView" as locationURI inside the plugin.xml my menu entry is visible, as I wanted.
But now I want to make it visible under special conditions. I don't find out, what property I can use to test the name of the Project.
I already did something similar inside Eclipse with
<command...
<visible when>
<with variable="activeMenuSelection">
<iterate ifEmpty="false">
<adapt type="org.eclipse.core.resources.IProject">
<test property="org.eclipse.core.resources.name" value="Test_*"/>
</adapt>
</iterate>
</with>
</visibleWhen>
</command>
Now I use
but I don't find out what to use as test property
Like in my working (without SVN) example I tried
<test property="org.tigris.subversion.subclipse.core.resources.name" value="Test_*/>"
But it did not work. The menu entry was not visible for SVN-Projects with names starting with "Test_"

Submenu on method level for custom launcher in RCP client

I have written a custom launcher in Eclipse which I can access via the "Run As" and "Debug As" on class level. I have a similar configuration as described in How do I use "org.eclipse.debug.ui.launchShortcuts"?. Unfortunately I can't see the submenu in the package explorer at the method level (for example submenu to launch the customer launcher in order to execute a single JUnit test). How can I do this?
JUnit uses a contextualLaunch based on the selected element being a org.eclipse.jdt.core.IJavaElement rather than just a resource. You will need to do the same.
This is what JUnit uses:
<contextualLaunch>
<enablement>
<with variable="selection">
<count value="1"/>
<iterate>
<adapt type="org.eclipse.jdt.core.IJavaElement">
<and>
<test property="org.eclipse.jdt.core.isInJavaProject"/>
<or>
<test property="org.eclipse.jdt.core.hasTypeOnClasspath" value="junit.framework.Test"/>
<test property="org.eclipse.jdt.core.hasTypeOnClasspath" value="org.junit.platform.commons.annotation.Testable"/>
</or>
<test property="org.eclipse.jdt.junit.canLaunchAsJUnit" forcePluginActivation="true"/>
</and>
</adapt>
</iterate>
</with>
</enablement>
</contextualLaunch>
Some of the <test elements are specific to JUnit so you will need to use something different.

Use of ILaunchConfigurationMigrationDelegate

I do not understand how migration of Eclipse Launch Configrations (ILaunchConfiguration) works. In my dreams, I'd love to have the following:
My plugin, version 1.0, is used to create a Launch Configuration referencing file something_1.0/foo
The plugin is upgraded to version 2.0, which also deletes the file still referenced in all old launch configurations of the plugin
The old launch configurations are automatically upgraded so that something_2.0/foo is referenced instead of the non-existing something_1.0/foo
Step 3 sadly is the one that does not work, although I wrote and connected a corresponding implementation of ILaunchConfigurationMigrationDelegate. It seems the code is never executed.
When exactly are configurations migrated? According to the code, there is a Migrate button, which I cannot find. According to the documentation configurations might be migrated automatically. How is this triggered?
Thanks,
Carsten
This implementation of this interface should be declared in extension point.
You can refer to JDT itself implementation org.eclipse.jdt.internal.launching.JavaMigrationDelegate.
Please note the launch shortcut specify the configuration type as the one defined via extension.
<extension
point="org.eclipse.debug.ui.launchShortcuts">
<shortcut
class="org.eclipse.jdt.debug.ui.launchConfigurations.JavaApplicationLaunchShortcut"
description="%JavaLaunchShortcut.description"
helpContextId="org.eclipse.jdt.debug.ui.shortcut_local_java_application"
icon="$nl$/icons/full/etool16/java_app.gif"
id="org.eclipse.jdt.debug.ui.localJavaShortcut"
label="%JavaApplicationShortcut.label"
modes="run, debug">
<contextualLaunch>
<enablement>
<with variable="selection">
<count value="1"/>
<iterate>
<and>
<adapt type="org.eclipse.jdt.core.IJavaElement">
<test property="org.eclipse.jdt.core.isInJavaProject"/>
</adapt>
<or>
<test property="org.eclipse.jdt.launching.hasMain"/>
<test property="org.eclipse.jdt.launching.isContainer"/>
<test property="org.eclipse.jdt.launching.isPackageFragment"/>
<test property="org.eclipse.jdt.launching.isPackageFragmentRoot"/>
</or>
</and>
</iterate>
</with>
</enablement>
</contextualLaunch>
<configurationType
id="org.eclipse.jdt.launching.localJavaApplication">
</configurationType>
<description
description="%RunJavaLaunchShortcut.description"
mode="run">
</description>
<description
description="%DebugJavaLaunchShortcut.description"
mode="debug">
</description>
</shortcut>

visibleWhen menuContribution showing up wrongly

I have created an eclipse menucontribution in my plugin which should show up ONLY when rightclicking a project that has a specific nature:
<menuContribution
allPopups="false"
locationURI="popup:org.eclipse.ui.popup.any?after=additions">
<menu
icon="ico/full/obj16/icon-logo-composer.png"
id="com.dubture.composer.lib.ui.menu"
label="Composer">
<visibleWhen
checkEnabled="false">
<iterate>
<adapt
type="org.eclipse.core.resources.IProject">
<and>
<test
property="org.eclipse.core.resources.projectNature"
value="com.dubture.composer.core.composerNature">
</test>
</and>
</adapt>
</iterate>
</visibleWhen>
</menu>
</menuContribution>
The visibleWhen condition seems to work only when right-clicking a project. The menu is only shown when the project has the specified nature.
However, when i right-click somewhere else (for example in some empty area in the project explorer or inside the problems view), the menu entry will show up despite the adapt condition.
Anyone knows how to restrict it to right clicking on projects only?
the test property is used by PropertyTester
if you add your menucontribution to popup:org.eclipse.ui.popup.any?after=additions, I believe it could show everywhere, you should restrict to popup:org.eclipse.ui.navigator.ProjectExplorer#PopupMenu unless required otherwise
this snippet uses commands but I think you can try to mix with your requirements to see if it works
<menuContribution locationURI="popup:org.eclipse.ui.navigator.ProjectExplorer#PopupMenu">
<command
commandId="COMMANDID"
icon="icons/icon.png"
label="LABEL"
style="push">
<visibleWhen
checkEnabled="false">
<iterate
ifEmpty="false"
operator="and">
<instanceof
value="org.eclipse.core.resources.IProject">
</instanceof>
</iterate>
</visibleWhen>
</command>
</menuContribution>

How do you create an retargetable action for a specific object type in Eclipse using the commands framework?

The Eclipse command framework allows you to create a generic command and handler. However, when you create an extension point that targets 'copy' the runtime complains:
<extension point="org.eclipse.ui.handlers">
<handler class="example.Handler" commandId="org.eclipse.ui.edit.copy"/>
</extension>
!MESSAGE Conflicting handlers for org.eclipse.ui.edit.copy: {org.eclipse.ui.internal.handlers.WidgetMethodHandler:copy} vs {example.Handler}
If you add an activeWhen clause, so that the special handler is only invoked when an object of a particular type is selected in a viewer, then you get an exception when you try and copy:
<extension point="org.eclipse.ui.handlers">
<handler class="example.Handler" commandId="org.eclipse.ui.edit.copy">
<activeWhen>
<with
variable="selection">
<iterate
ifEmpty="false"
operator="or">
<instanceof
value="sample.Class">
</instanceof>
</iterate>
</with>
</activeWhen>
</handler>
</extension>
Caused by: org.eclipse.core.commands.NotHandledException: There is no handler to execute for command org.eclipse.ui.edit.copy
What's the right way of using the commands framework to provide a specific copy operation for objects of a particular type?
Your activeWhen clause looks acceptable. What will matter is what selection you are going for. ex:
<handler class="z.ex.cmd.handlers.LongCopyHandler"
commandId="org.eclipse.ui.edit.copy">
<activeWhen>
<with variable="selection">
<iterate ifEmpty="false"
operator="and">
<adapt type="org.eclipse.core.resources.IMarker"/>
</iterate>
</with>
</activeWhen>
</handler>
I originally tried instanceof in my activeWhen expression to get access to the IMarkers in the markers view, but that didn't work (the objects don't implement IMarker). I had to adapt them to get my handler to work correctly. This would apply to .java files in the Package Explorer as well, they adapt to an IResource but they're actually IJavaElements or something.