I want have a context menu (right-click) that allows to toggle different states of the clicked object.
In the plugin.xml, I already have a popup menu with commands entries such as:
<command
commandId="...switchDistanceCommand"
label="30s"
style="toggle">
<parameter
name="...switchDistanceMillis"
value="30000">
</parameter>
</command>
and a command:
<extension
point="org.eclipse.ui.commands">
<command
id="....switchDistanceCommand"
name="Switch Distance">
<commandParameter
id="....switchDistanceMillis"
name="Seconds"
optional="false">
</commandParameter>
</command>
</extension>
The handler:
<handler
class="....SwitchDistanceHandler"
commandId="....switchDistanceCommand">
</handler>
The handler class SwitchDistanceHandler checks which objects are selected an calls a method on them to switch their state (adding or removing the parametrized value to a List).
So far so good...
However, I want to have my menu entries work as checkboxes (as style="toggle") indicates. Every tutorial on this issue (such as this one) explains how to add a state to command by adding the following code to the plugin.xml:
<state
class="org.eclipse.ui.handlers.RegistryToggleState:true"
id="org.eclipse.ui.commands.toggleState">
</state>
But this will only give me only one global state for this command, I want to read the state(s) from the clicked objects? How can I do this?
Edit 1: Copied the wrong code snipped from the tutorial. Also I tried to implement an own class that extends the State class (as RegistryToggleState does). But I could not figure out how to return a state from this class.
Edit 2: I found a workaround. It does not solve the proposed problem but it works for me.
Workaround
This is not exactly a solution to the problem because it does not use any state objects. But it works fine for me:
Following the advice from this question I implemented IElementUpdater in my Handler.
In the updateElement method, I fetched the selected element(s) from the element object and called element.setChecked()accordingly.
Related
I have a command into the plugin.xml which will add a new menu button. This button should not be visible all the time, hence I would like to check a complex condition from Java code to decide when it have to be visible.
I know that there is a visiblewhen and a hidewhen possibility, but I don't know how can let a Java class/method to make the decision.
For this check the enabled state of the command is used, which is determined by the return value of IHandler.isEnabled().
In the plugin.xml the contribution of the command to the menu has to have the visibleWhen element and checkEnabled="true". In Eclipse you can right click the command contribution and add visible when, in the plugin.xml it looks like this:
<command
commandId="...">
<visibleWhen
checkEnabled="true">
</visibleWhen>
</command>
To enable/disable the command you have to implement the isEnabled() method from org.eclipse.core.commands.IHandler (or override from AbstractHandler) in your command handler and return false, if the menu entry should be hidden.
I'm creating an RCP 3.7 editor by using org.eclipse.ui.editors extension point. What I need is to dynamically define icon path based on some conditions during editor startup.
(EDIT: The editor is actually just restored after startup, but it's not selected as active yet, so you can see only tab with title and icon)
I tried to work with getImageDescriptor() method in class implementing IEditorInput, which doesn't seem to be used. The only way that has some effect on the icon is changing the icon path in definition of editor extension.
Therefore I started to play with org.eclipse.core.variables.valueVariables and org.eclipse.core.variables.dynamicVariables for use in icon attribute (showing valueVariables just for easy example):
<extension point="org.eclipse.ui.editors">
<editor name="%Editor_TITLE"
extensions="xml"
icon="${FOO}"
class="org.example.ExampleEditor"
id="org.example.ExampleEditor">
</editor>
</extension>
<extension point="org.eclipse.core.variables.valueVariables">
<variable name="FOO"
initialValue="images/obj16/editor.png">
</variable>
</extension>
However, that doesn't work either. Is there some way to use dynamically defined variable values (based on current condition) that could change the path of icon? ...or I'll be greatfull even for a workaround suggestion, that will lead to successful changing of the icon during startup (like making the ImageDescriptor work no startup).
Variables only work in places where they are explicitly support in the code. If the documentation for an extension point does not say they are supported then they won't work.
You get use the image descriptor from the editor input to set the editor title image by doing something like the following in your editor's init method:
public void init(IEditorSite site, IEditorInput input)
throws PartInitException
{
... other code
ImageDescriptor desc = input.getImageDescriptor();
Image image = desc.createImage();
setTitleImage(image);
... other code
}
I just started working on a project using RCP. And in its "about" section, it uses
the built in WorkbenchAction:
IWorkbenchAction actionAbout = ActionFactory.ABOUT.create(window);
actionAbout.setText(Messages.ABOUT);
itemAbout = new ActionContributionItem(actionAbout);
However, I need to add a tab in that popup and I'm not finding any way to customize
it. Is this something possible or should look for another way to do things?
Use the org.eclipse.ui.installationPages extension point to add a tab to the Installation Details tabs.
<extension point="org.eclipse.ui.installationPages">
<page
name="XYZ Info"
class="package.XYZInstallInfoPage"
id="plugin.xyz>
</page>
</extension>
Your class must extends org.eclipse.ui.about.InstallationPage
For more details see the help
I have made a eclipse RCP application, everything is working fine but i recently noticed the Refractor option in menu. I would like to get rid of it. I have the following in ActionBarAdvisor.java:
#Override
protected void fillMenuBar(IMenuManager menu) {
menu.add(createFile());
menu.add(createEdit());
menu.add(createNavigate());
menu.add(createProject());
menu.add(new GroupMarker(IWorkbenchActionConstants.MB_ADDITIONS));
menu.add(createWindow());
menu.add(createHelp());
}
The above functions add actions to menu as:
edit.add(undoAct);
and also undoAct is defined as:
private IWorkbenchAction undoAction
makeActions function has contents as:
#Override
protected void makeActions(IWorkbenchWindow window) {
undoAction = ActionFactory.UNDO.create(window);
undoAction.setText("Undo Menu");
register(undoAction);
}
I found a suggestion which said to use hideActionSets to hide the menu. But I could not hide the entire menu but just its actions!
Remove "File, edit,...etc" menus from Eclipse RCP application
How to remove Refractor option now?
Thank you.
You can use activities, as described here.
First, you will need to find the ID of the menu:
Use the Plug-In Spy
The first way is to use the Plug-In Spy. Press alt-shift-F2 and click on a
menu item or toolbar button that you want to be hidden. If there is an ID
string under the heading "active action definition identifier" then you are
in luck. This item has been added using the Command Extension and you can
use this ID as the pattern argument for the Activities Extension. But not
all items that have been added using the Command Extension present their ID
string to the plug-in spy.
As a side note, the ID strings are period separated. For instance the ID for
a button might be "org.eclipse.ui.navigate.backwardHistory". Regular
expressions use the period to stand for any character. Luckily the period
used as a wild card matches with actual period characters so you don't need
to escape them if you don't want to. I find it makes it a bit easier to read
if they are not escaped and it is highly unlikely it will cause any
ambiguous matches.
Use the Plug-In Registry and plugin.xml files
The second way is to use the Plug-In Registry. You can open this view by
going to:
Window/Show View.../Other/Plug-in Development/Plug-In Registry
What you would like to do is to try to get a couple pieces of information:
a) the plugin that is contributing the UI element
b) information about what kind of extension the plugin is using to create
the UI element
If there is a very unique word associated with the UI element or its tool
tip then you can use this in the Plug-In Registry's filter field to try to
nail down which plug-in is contributing the UI element. The filter field is
not a very powerful tool so it can be a bit frustrating to use. It does not
allow wildcards and does not match space characters.
When you track down which plug-in is contributing the UI element then you
open the the plug-in in question from the Plug-Ins view which is found
grouped with the Package Explorer in the Plug-in Development perspective.
Then go to the Extensions tab and search for the ID string which can usually
be found in either a usage of the Command or ActionSet extension. If the UI
element is added using an ActionSet then you prefix the plug-in ID to UI ID
in the pattern argument given to the Activities Extension. For example
org.eclipse.ui.actionsets.foo becomes the pattern
org.eclipse.ui/org.eclipse.ui.actionsets.foo.
Then create a new Activity which will never be activated and a corresponding activityPatternBinding with the id you found in the last step. It will look like this in your plugin.xml:
<extension point="org.eclipse.ui.activities">
<activity id="myActivity" name="MenuHidingActivity">
<enabledWhen>
<with variable="activePartId">
<equals value="nonExistentPartId"></equals>
</with>
</enabledWhen>
</activity>
<activityPatternBinding activityId="myActivity" pattern="menuItemID">
</activityPatternBinding>
</extension>
I want to specify a custom icon for a marker. Sadly, the icon that I chose is not displayed.
Here's the relevant parts of the plugin.xml file (the project id "x"):
<extension
id="xmlProblem"
name="XML Problem"
point="org.eclipse.core.resources.markers">
<super type="org.eclipse.core.resources.problemmarker"/>
<persistent
value="true">
</persistent>
</extension>
<extension
point="org.eclipse.ui.ide.markerImageProviders">
<imageprovider
markertype="x.xmlProblem"
icon="icons/marker.png"
id="xmlProblemImageProvider">
</imageprovider>
</extension>
I also tried specifying a class (implementing IMarkerImageProvider) instead of an icon, but that getImagePath() method of the class does not get called.
Any thoughts on how to make custom marker icons work?
Desperately, yours.
-Itay
Update
VonC's solution is pretty much correct, except that you must not specify org.eclipse.core.resources.problemmarker as a supertype of your marker. It worked only when I used org.eclipse.core.resources.textmarker as the only supertype.
See bug 260909 "markerImageProviders extension point does not work" (found after reading this thread)
Tod Creasey 2009-01-21 07:32:38 EST
We have never had the push to make this API because it has some inflexibility that made it generally not consumable - it was written early on to enable the first marker views for the 3 severities we use and as a result was not used by the markerSupport as it was not API.
It is confusing that we have an internal extension point (we don't generally do
that) but removing it would likely break someone without warning.
[EDIT by Itay]
Following on Vonc's pointers, I eventually managed to make this thing work.
Here are the relevant fragments from my plugin.xml (assuming the plugin name is a.b.c)
<extension point="org.eclipse.core.resources.markers"
id="myMarker">
<super type="org.eclipse.core.resources.textmarker"/>
<persistent value="true"/>
</extension>
<extension point="org.eclipse.ui.editors.annotationTypes">
<type
super="org.eclipse.ui.workbench.texteditor.warning"
markerType="a.b.c.myMarker"
name="a.b.c.myAnnotation"
markerSeverity="1"/>
</extension>
<extension point="org.eclipse.ui.editors.markerAnnotationSpecification">
<specification
annotationType="a.b.c.myAnnotation"
icon="icons/marker.png"
verticalRulerPreferenceKey="myMarkerIndicationInVerticalRuler"
verticalRulerPreferenceValue="true"/>
</extension>
Pitfalls
The super type of the marker must be set to org.eclipse.core.resources.textmarker. Any other value will prevent your custom icon from being used.
When you create a marker in your code make sure its severity matches the severity value specified in the markerSeverity attribute at the org.eclipse.ui.editors.annotationTypes extension point. 1 means warning, etc.
Make sure the icons folder is specified in your build.properties file (or the "build" tab at the plugin editor)
The declaration above will only specify a custom icon. If you want to customize other attributes (color of indication at the overview ruler, etc.) follow the sample from here on which this solution is based.