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.
Related
I have a perspective which i have made, and a bunch of views i would like to be able to display on this perspective. If i go Window -> Show View -> Other and then select my view it works fine. However i would like to show a view by default upon opening the perspective and place it where the project explorer usually would be.
But nothing i do seems to change anything and i cannot find any reason why.
I have been using this code to try to change the location of this view but it doesn't even open the view by default. can someone point me in the right direction on how to open a view by default and place it where the project explorer usually would be?
public class PerspectiveFactory1 implements IPerspectiveFactory {
public void createInitialLayout(IPageLayout layout) {
layout.addView("VIEW_ID_HERE", IPageLayout.LEFT,
IPageLayout.RATIO_MAX, IPageLayout.ID_PROJECT_EXPLORER);
}
}
Thanks in advance
Here is my plugin.xml
<plugin>
<extension
point="org.eclipse.ui.perspectives">
<perspective
class="packageName.PerspectiveFactory1"
fixed="true"
id="PerspectiveID"
name="Software Application">
</perspective>
</extension>
<extension
point="org.eclipse.ui.perspectiveExtensions">
<perspectiveExtension
targetID="PerspectiveID">
<view
class="packageName.ShowApplications"
icon="icons/sample.gif"
id="packageName.ShowApplications"
minimized="false"
moveable="false"
name="listApps"
ratio="0.5"
relationship="left"
visible="true">
</view>
Since you don't have the project explorer in that perspective you can't use its id in the reference id parameter to addView. Instead use the editor area id which is always allowed:
layout.addView("view id", IPageLayout.LEFT,
0.3f, layout.getEditorArea());
You may also have to Reset the perspective if it has been open before to get the new layout picked up (Window > Perspective > Reset Perspective).
The view must be defined using the org.eclipse.ui.views extension point.
You can also use the org.eclipse.ui.perspectiveExtensions to define the position of a view in the perspective instead of the perspective factory - but this still requires the view to be defined using org.eclipse.ui.views.
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 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.
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