Add custom markers to java editor in eclipse - java

I've been trying to add custom markers to eclipse editor for many many hours (days) and I just can't get it to work.
I can add problem markers well and without any issues by extending them on my own plugin.xml. It does everything I want EXCEPT the icon for the marker. I want a different icon.
Here's What I have:
plugin.xml
<extension
point="org.eclipse.ui.editors.annotationTypes">
<type
markerType="Plugin.MyMarker"
name="Plugin.MyMarker"/>
</extension>
<extension
id="MyMarker"
point="org.eclipse.core.resources.markers">
<super type="org.eclipse.core.resources.textmarker" />
<!-- <super type="org.eclipse.core.resources.problemmarker" /> --><!-- if I remove this comment, all works... But I don't want that icon-->
<persistent value="true"/>
</extension>
<extension
id="Plugin.markerAnnotationSpecifications"
point="org.eclipse.ui.editors.markerAnnotationSpecification">
<specification
annotationType="Plugin.MyMarker"
colorPreferenceKey="Plugin.markerColor"
colorPreferenceValue="100,100,100"
contributesToHeader="false"
highlightPreferenceKey="Plugin.markerHighlight"
highlightPreferenceValue="true"
includeOnPreferencePage="true"
icon="icons/icon_mine.gif"
label="My beautiful label"
overviewRulerPreferenceKey="Plugin.markerOverview"
overviewRulerPreferenceValue="true"
presentationLayer="0"
symbolicIcon="warning"
textPreferenceKey="Plugin.tarkerText"
textPreferenceValue="true"
textStylePreferenceKey="Plugin.textStyle"
textStylePreferenceValue="BOX"
verticalRulerPreferenceKey="Plugin.markerRuler"
verticalRulerPreferenceValue="true" />
MyPlugin.java
IMarker myMarker = file.createMarker("Plugin.MyMarker");
if(!myMarker.exists()){
Activator.myLog.log(new Status(Status.ERROR, LOG_PLUGIN_NAME, 15, "There's no marker!", null));
}
myMarker.setAttribute(IMarker.SEVERITY, IMarker.SEVERITY_WARNING);
myMarker.setAttribute(IMarker.MESSAGE, "Txt:\nabc");
myMarker.setAttribute(IMarker.PRIORITY, IMarker.PRIORITY_HIGH);
myMarker.setAttribute(IMarker.LINE_NUMBER, line);
myMarker.setAttribute(IMarker.CHAR_START, searchStart);
myMarker.setAttribute(IMarker.CHAR_END, searchEnd);
The marker image is here: icon="icons/icon_mine.gif"
If I use the code as it is above, the annotation appears in the menu under the annotations (General>Editors>TextEditors>Annotations)option with the correct image and the correct options as I would expect it to be.
Other log messages that I placed in the code confirm that that code executes well same as the results if I just change that line I commented in the XML (see the XML comment).
But still, I can't see anything telling me if the marker is actually being applied or an error (or anything in the log or the console, on that matter). It is as if I didn't setup anything and nothing is happening.
Any help is welcome

Please do check that the ids of each <extension> must start with the same substring as as the package of the project. I see you using Plugin as the package and packages usually start with low case letters.
Please try renaming the prefixes of the ids to plugin. (low case) instead of Plugin.

Related

Add QuickAccess TextField to an eclipse RCP application

I have an eclipse RCP application (RCP version 4.12.0.v20190605-1801) using SWT. I want to add the eclipse QuickAccess TextField as search bar to my project like in the Java eclipse IDE (which is also available by pressing ctrl + 3).
I have scoured the documentation and the only thing I have found is the following:
#Override
protected void fillCoolBar(ICoolBarManager coolBar) {
// ToolBar File & Additions
IToolBarManager fileToolBar = new ToolBarManager(coolBar.getStyle());
fileToolBar.add(ActionFactory.SHOW_QUICK_ACCESS.create(window)); // window == class attribute
// Add some other stuff
}
This produces a QuickAccess button in my case, but no TextField. It works the same way if you click on it, but I would prefer to have the TextField as it is more clear to the user.
I only found threads on how to remove the TextField, but not how to add it, e.g. SO post here. So I guess it must be a somewhat built in feature.
If anyone's interested it is for the JCrypTool project:
GitHub link
File on GitHub containing the above function call for building the toolbar
Hope I didn't miss anything important, thanks for your help in advance.
I now settled on a slightly different solution.
I included the QuickAccess entry as Extension in my plugin.xml where I define my toolbar. Instead of an input text, it is now a button (depicting a magnifier icon). I took this approach because it is quite easy to implement using the RCP extension points.
This is a (reduced) version of what my plugin.xml looks like now. The relevant part is the extension point org.eclipse.ui.menus which calls org.eclipse.ui.window.quickAccess
<?xml version="1.0" encoding="UTF-8"?>
<?eclipse version="3.4"?>
<plugin>
<extension id="application" point="org.eclipse.core.runtime.applications">
<application>
<run class="org.jcryptool.core.Application"/>
</application>
</extension>
<extension point="org.eclipse.ui.menus">
<menuContribution
allPopups="false"
locationURI="toolbar:org.jcryptool.core.searchToolbar">
<command
commandId="org.eclipse.ui.window.quickAccess"
icon="icons/searchIcon.png"
style="push">
</command>
</menuContribution>
</extension>
<extension id="product" point="org.eclipse.core.runtime.products">
<product application="org.jcryptool.core.application" name="JCrypTool">
<property name="appName" value="JCrypTool"/>
<property name="cssTheme" value="org.jcryptool.themes.default"/>
</product>
</extension>
</plugin>
This looks like this:
For a really fancy implementation I guess you have to write some code for it. But as quite nice RCP solution it's ok for me.

How to show undo and redo actions in toolbar in rcp application

I am working on an rcp application with a toolbar for quick access to certain actions, including undo and redo. My problem is that these two specific actions don't show up in the toolbar. I have located the cause to the workbench.xmi file that is generated when the application launches. A tag persistedState with an attribute key="persp.hiddenItems" contains persp.hideToolbarSC:org.eclipse.ui.edit.undo,persp.hideToolbarSC:org.eclipse.ui.edit.redo in the value="..." attribute. If I delete these entries from workbench.xmi, the undo and redo actions show up in the toolbar as they should.
My question is: What can I do so that org.eclipse.ui.edit.undo and org.eclipse.ui.edit.redo don't end up in this attribute to begin with?
I originally used eclipse neon without this problem, but when updating to eclipse 2018-12 this started happening.
Edit:
I finally got it to work by changing the IDs of my undo and redo actions to something else. I had to set the ID with setId(...) and setActionDefinedId(...) in the actions' constructors, and then the commands had to be defined in plugin.xml under <extension point="org.eclipse.ui.commands"> in a <command id="..." name="Undo"></command> tag.
This solutions feels more like a workaround than an actual solution, but it works for me.
This is set by the hiddenToolBarItem element of the org.eclipse.ui.perspectiveExtensions extension point.
The org.eclipse.ui.ide plug-in uses this to disable these tool-bar items:
<extension
point="org.eclipse.ui.perspectiveExtensions">
<perspectiveExtension targetID="*">
<!--
disable "print" button which is defined by org.eclipse.ui.actions.ActionFactory.PRINT
and contributed by org.eclipse.ui.internal.ide.WorkbenchActionBuilder
-->
<hiddenToolBarItem id="print" />
<!--
disable "undo" button which is defined by org.eclipse.ui.actions.ActionFactory.UNDO
and contributed by org.eclipse.ui.internal.ide.WorkbenchActionBuilder
-->
<hiddenToolBarItem id="org.eclipse.ui.edit.undo" />
<!--
disable "redo" button which is defined by org.eclipse.ui.actions.ActionFactory.REDO
and contributed by org.eclipse.ui.internal.ide.WorkbenchActionBuilder
-->
<hiddenToolBarItem id="org.eclipse.ui.edit.redo" />
</perspectiveExtension>
</extension>
I don't see a way to clear this other than leaving out the plug-in.
I ran into the same problem. Undo/Redo disappeared after upgrading to 2019 eclipse.
One way to override the hardcoding in org.eclipse.ui.ide global perspective setting is to modify the perspective state directly. E.g. in ApplicationWorkbenchWindowAdvisor.postWindowOpen()
WorkbenchPage page = (WorkbenchPage) PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
String str = page.getCurrentPerspective().getPersistedState().get(ModeledPageLayout.HIDDEN_ITEMS_KEY);
str=str.replace("persp.hideToolbarSC:org.eclipse.ui.edit.undo,", "");
str=str.replace("persp.hideToolbarSC:org.eclipse.ui.edit.redo,", "");
page.getCurrentPerspective().getPersistedState().put(ModeledPageLayout.HIDDEN_ITEMS_KEY,str);

Configure Application Toolbar

I want to customize the application toolbar to my own needs. A long time ago I played around (and did some impressive customizations) with the AbstractPresentationFactory.
However this extension point was removed and replaced with... not sure, the documentation states it's org.eclipse.e4.ui.css.swt.theme, but I don't see how that extension point helps my cause at all.
I managed to guess my way into implementing a solution that makes my texts blue:
plugin.xml
<extension point="org.eclipse.e4.ui.css.swt.theme">
<theme basestylesheeturi="content/test.css"
id="myFirstTheme"
label="My First Theme" />
</extension>
<extension id="application" point="org.eclipse.core.runtime.products">
<product application="org.acme.project" name="Project">
<property name="cssTheme" value="myFirstTheme" />
</product>
</extension>
test.css
Text {
color: COLOR-CYAN;
}
Now what? How do I configure the main toolbar using that mechanism? Is there any documentation how the CSS file should look like and what can be configured? Or any kind of rule?
(Since Google only shows "Hello World" examples and source code, I assume there is yet again no documentation. In that case the precise problem I'm facing is: I want to make toolbar buttons bigger and add text below the image.)

Markers view shows my marker with a red square insted of error/warning icon

I created my own marker based on the ibm tutorial Best practices for developing Eclipse plugins
Using markers, annotations, and decorators.
In my plugin xml
I have something like this:
<extension point="org.eclipse.core.resources.markers"
id="com.ibm.mymarkers.mymarker"
name="My error">
<super type="org.eclipse.core.resources.textmarker"/>
<super type="org.eclipse.core.resources.marker"/>
<persistent value="true"/>
</extension>
I tried also with different super types such as
<super type="org.eclipse.core.resources.problemmarker"/>
When I create the marker i set :
marker.setAttribute(IMarker.SEVERITY, IMarker.SEVERITY_ERROR);
The problem is that the markers are shown in the markers view but without an icon (basically a red square) how can I define an icon for these markers...?
I tried the simple example from Vogella but still I don't see any image the marker is created but no image.
IMarker marker = res.createMarker(IMarker.TASK);
marker.setAttribute(IMarker.MESSAGE, "This a a task");
marker.setAttribute(IMarker.PRIORITY, IMarker.PRIORITY_HIGH);
Am I maybe missing some plugin that contains this images?
Try adding an extension of type org.eclipse.ui.ide.markerImageProviders
<extension point="org.eclipse.ui.ide.markerImageProviders">
<imageprovider
markertype="com.ibm.mymarkers.mymarker"
icon="marker.png"
id="myImageProvider">
</imageprovider>
</extension>
EDIT
It seems the aforementioned extension point doesn't work (!).
Take a look at this SO question.

Eclipse-Plugin with submenu. How to handle JavaProjects and Projects?

I want to write an Eclipse-plugin that performs an Action with a selected Project. I used the plugin Template with submenu. My plugin.xml looks like this :
<extension
point="org.eclipse.ui.popupMenus">
<objectContribution
objectClass="org.eclipse.core.internal.resources.Project"
id="testplugin2.contribution1">
<menu
label="Propertie Manager"
path="additions"
id="testplugin2.menu1">
<separator
name="group1">
</separator>
</menu>
<action
label="list all *.properties"
class="testplugin2.popup.actions.ListPropertiesAction"
menubarPath="testplugin2.menu1/group1"
enablesFor="1"
id="testplugin2.projectAction">
</action>
</objectContribution>
</extension>
this works fine for everything but javaProjects. It turns out that javaProjects are not Projects. I want this Action to appear when a javaProjects or a normal Projects is selected and not if something else is selected.
How can I make the submenu appeare exactly if a javaProject or a Project is selected?
I didn't test it, but maybe this works:
<objectcontribution ...>
<visibility>
<objectClass
name="org.eclipse.jdt.core.IJavaProject" />
</visibility>
</objectContribution>
You can also try "enablement" instead of "visibility".
eclipse help pages on popup menus
Make sure the adaptable property of your object contribution is set to true (it defaults to false):
adaptable="true"
#iain suggestion to target the interface is also good practice.
Just tried your example and the menus were showing as expected on a Java project.
Always bear in mind adpatability to org.eclipse.core.resources.IResource in general to ensure your menus, actions to be consistently displayed and enabled (whatever the explorer or actual object class being rendered).
Finally, beware that the org.eclipse.ui.popupMenus extension point is deprecated.
Though in my experience using it is faster and easier than the recommended org.eclipse.ui.commands, you may end up having a hard time migrating all your menus when it is removed (that is, if it is removed at some point).
Cheers,
You should not reference the internal class in you object class. You should use the public interface instead
objectClass="org.eclipse.core.internal.resources.Project"
Try
objectClass="org.eclipse.core.IProject"
I haven't tried this but IJavaProject should adapt to the IProject, so this should work for both.

Categories

Resources