popup:org.eclipse.jdt.ui.PackageExplorer not visible for Java projects - eclipse-plugin

I'm writing a plugin for Eclipse to help me with some custom errors and warnings. Started by creating a new plugin project using the wizard, chose the option with the nature and markers in it.
This automatically added a menu item in the project's context menu (popup:org.eclipse.jdt.ui.PackageExplorer?after=additions)
This seemed to work for most projects. Except the projects i needed it for. The menu item simply does not show up for Java projects in the Package Explorer.
I only changed the default ?after to be ?before, so the menu-item is in a location that suited me better (for the projects that it does work on).
Screenshot if what i've got now
That shows it's working on a non-java project in the Package Explorer.
I also added the same menu-item to the Project Explorer, all works fine there.
Here is a link to the plugin.xml i currently have.
The project it DOES NOT work on, is a simple java project freshly generated from the Eclipse "New -> Java Project" wizard. Any other java project doesn't work either.
The project it DOES work on, is freshly generated from the "Plug-in Development -> Update Site Project" wizard.
Stuff i tried:
I know it is not the same as popup:org.eclipse.jdt.ui.PackageExplorer not visible, i'm adding the menu-item to the context menu of a project, not files or directories.
However, i did try using:
<adapt type="org.eclipse.core.resources.IResource">
<test property="org.eclipse.core.resources.contentTypeId" value="org.eclipse.jdt.core.IJavaProject" />
</adapt>
instead of the <instanceof> tags, which also did not work. in fact, removing the whole <instanceof> tag does not even work.
I know it is not the same as Eclipse plugin menu item is not visible, the generated plugin.xml used selection, which i later changed to activeMenuSelection because that matched the documentation, and what the Plug-in Selection Spy says it actually is. Again, no change.
I think it is not the same as How create popup menu item in PackageExplorer only for directories, but i did try to use the suggested code and toyed around with it, no luck.
So, to summarize:
This is my first Eclipse plugin, most of the GUI stuff is generated from the Plug-in Developent wizard. Now i hope a real wizard can lead me to the answers i seek.

The <adapt> tag gave me an idea to adapt the project to an IResource. Then check for natures from inside the <adapt> tag. And that seemed to work!
The Platform Expression Framework page at eclipse.org also helped me understand what each of the tags exactly do.
So, i think my problem was actually similar to the one i linked first (popup:org.eclipse.jdt.ui.PackageExplorer not visible). Feel pretty dumb about that now...
Relevant part of my current plugin.xml:
<visibleWhen checkEnabled="false">
<with variable="activeMenuSelection">
<count value="1" />
<iterate operator="and">
<adapt type="org.eclipse.core.resources.IResource">
<and>
<not>
<test property="org.eclipse.core.resources.projectNature" value="com.mycompany.converterhelper.javaFileNature" />
</not>
<test property="org.eclipse.core.resources.projectNature" value="org.eclipse.jdt.core.javanature" />
</and>
</adapt>
</iterate>
</with>
</visibleWhen>
And a link to the entire plugin.xml
I want to thank Calon for his time and effort :-)

Related

What is required to run a hello world in kotlin with IntellJ

I have a Mac (Catalina OS) with Java 15 and IntelliJ 2020.2 (community edition) installed. The kotlin plugin is also installed. When I create a new Kotlin Project, add a main function, then there is way to run it, there is no 'Start' Button next to the main function. The problem is obviously that it doesn't find the runtime. The iml file looks as follows
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="KotlinJavaRuntime" level="project" />
</component>
</module>
When I click on 'add framework support', I can add a new KotlinJavaRuntime which then just appends an <orderEntry> to the iml file with the name KotlinJavaRuntime (2).
I don't want to use maven or gradle here. I know that gradle can resolve the dependencies for me. I just want a plain vanilla Kotlin hello world project. The documentation has a 'Getting Started with IntelliJ IDEA' section which just mentions the Kotlin plugin for IntelliJ. There seems to be no requirement to have gradle or maven installed, the plugin should do it.
I know that you can use brew install kotlin to install the SDK manually, but then the documentation is wrong and the plugin alone cannot run Kotlin with a prior manual installation of the SDK or the usage of maven/gradle.
I think I know what happened in this case.
The Kotlin Code was loaded as an 'IntelliJ' Module inside a Java project that was using maven. In IntelliJ there's a hidden folder .idea/libraries/ which was missing the description of the Kotlin Runtime (this makes sense, since the dependencies were managed via maven). I have restarted and created a new project from scratch. This time you'll see the file .idea/libraries/KotlinJavaRuntime.xml, which is exactly what is referenced from the iml file. The .idea folder is very magic. For me the confusion is that modules in IntelliJ are not really isolated from the project, they share - like in this case - the .idea folder.
I hope this helps also other users.
If you created the kotlin-file yourself, you have to tell IntelliJ that it should run this file.
Normally shows a run icon next to your main method.
run button/icon
Option 2: Right Click on the file containing the main method and see if there is a run this file option.
Option 3: add run config manually
Click add config which should be on the left of the run button (don't mind that it is disabled)
Click + and choose Kotlin.
Set main class to MainKt which is the default for kotlin

Modify the icon of an eclipse template plugin

Followed the steps here and created an eclipse plugin based on the Hello World, Command template - exported it, dropped in the plugins folder of my eclipse install and I saw the menu and toolbar entries alright.
Then I had the idea to modify the icon it showed in the toolbar item. Modified the plugin.xml as in (git diff):
<menuContribution locationURI="toolbar:org.eclipse.ui.main.toolbar?after=additions">
<toolbar id="gr.uoa.di.regas.eclipse.poc.toolbars.sampleToolbar">
<command
commandId="gr.uoa.di.regas.eclipse.poc.commands.sampleCommand"
- icon="icons/sample.gif"
+ icon="icons/my_icon.gif"
tooltip="Say hello world"
id="gr.uoa.di.regas.eclipse.poc.toolbars.sampleCommand">
</command>
</toolbar>
</menuContribution>
</extension>
and of course added my_icon.gif into the icons directory. Initially eclipse just kept loading the old icon till I deleted it and reexported just to see the little square that means 'icon not found'
So how do I change the icon ? Also where are the specifications for the icon - can't find any ?
EDIT: renamed the icon to icon.gif thinking the underscores might be the issue - nothing changed - of note that eclipse went ahead and renamed the icon in the plugin.xml (I renamed through the package explorer) - so the setup seems correct - eclipse knows about icon.gif.
EDIT2: the repo for the plugin: https://github.com/Utumno/eclipse_poc

Cannot contribute extension from a fragment

I am working on a set of plugins and fragments on eclipse 4.3 (Kepler) but using the 3.x model.
One plugin contains part of the application model and has a fragment which contributes some model editors. (This seems right to me - tell me if it's unnecessarily complicated)
In the main app these editor contributions are not listed. I changed the fragment to a plugin and the editors became visible.
I could change the fragment to a plugin but this would mean that I have to expose more of the model.
I could move the fragment to the host plugin but this would mean mixing model and view (perhaps not a big deal)
Is it generally not possible to contribute from a fragment or have I done something wrong?
Here is the fragment:
<?xml version="1.0" encoding="UTF-8"?>
<?eclipse version="3.4"?>
<fragment>
<extension
point="org.eclipse.ui.editors">
<editor
class="com.acme.atf.device.ui.editors.NullConfigEditor"
default="false"
id="827299e9-6039-4a76-bfa6-08ef2d7f8724"
name="VariableEditor">
</editor>
<editor
class="com.acme.atf.device.ui.editors.SerialConfigEditor"
default="false"
id="cbaba4b2-8380-4ae5-9896-542cf97ca8cc"
name="SerialEditor">
</editor>
</extension>
Further information
The plugin hierarchy looks like this: (P=plugin, F=fragment)
com.acme.atf.app (P)
com.acme.atf.device (P)
com.acme.atf.device.help (F)
com.acme.atf.device.ui (F)
com.acme.atf.model (P)
com.acme.atf.core.ui (P)
An action in com.acme.atf.app attempts to load an editor (which happens to be in device.ui) which cannot be found. If I change device.uito a plugin then the editor is found.
Just managed to solve very similar problem with Eclipse 4.4.1. Unfortunately, the solution was to use clean workspace (I've imported my projects from Git).
Before that, I tried "playing" with version numbers of host and fragment, singleton flags, recreating fragment project, cleaning all projects and configuration of my RCP app. Also, I used OSGI console trying to get some additional info, but it reported only that:
Host plug-in org.aaa.bbb is in ACTIVE state (with no fragments)
Fragment bundle is in INSTALLED state (reporting "Unresolved requirement: Fragment-Host: org.aaa.bbb")
I think this is a bug and garbaged workspace (launch) configuration may be the cause. Hope this helps someone.

How to enable autoscroll to/from source permanently for all new project imports?

I like the "Autoscroll to/from source" features. Every time I import a new project, I will always enable them. However, it gets annoying when you have to do that every time for a new import. I googled, but couldn't find out how. How can I enable them permanently?
There is now a free IntelliJ plugin to remember Autoscroll to/from Source settings:
Jetbrains repository: Autoscroll Save Plugin
Instructions to use:
Download Autoscroll Save plugin and restart IntelliJ
Open an IntelliJ project and set desired autoscroll to and from settings
Use Ctrl-Alt-Shift END
All IntelliJ projects opened or created in future will now inherit your desired Autoscroll to/from Source settings.
If you have any feedback on the plugin, please click on the author (vikingsteve) on the plugin page and use "Send email" function.
Edit: I was just at a java conference and spoke to some of the Jetbrains devs from St Petersbourg. After thanking them for developing IntelliJ, I asked them about this, and I understand that since they are really busy with other things they don't have time right now to make this default functionality in IntelliJ.
So, in the meantime, please try out the Autoscroll Save plugin - from everyone I spoke to at the conference, it works for them without problem.
This is currently not possible.
The auto-scroll settings are Project specific and are stored in the .idea/workspace.xml file :
Accessing Default Project Settings and Structure documents how to change the default settings used by new projects. Unfortunately, the autoscroll settings are not amongst the ones that can be set there.
A bit more digging shows that the default project is represented by .IntelliJIdea12\config\options\project.default.xml and it does not have settings for autoScroll specified. (Out of curiosity, I tried copying in the following in that file :
<component name="ProjectView">
<navigator currentView="ProjectPane" proportions="" version="1" splitterProportion="0.5">
<flattenPackages />
<showMembers />
<showModules />
<showLibraryContents />
<hideEmptyPackages />
<abbreviatePackageNames />
<autoscrollToSource ProjectPane="true" />
<autoscrollFromSource ProjectPane="true" />
<sortByType />
</navigator>
</component>
But that was not picked up by new projects.
)

Editing CodeBlocks WxSmiths project

I have an old project done in CodeBlocks WxSmiths. I copied it across to my new computer and now I cannot make any changes to the project! I can add items to a panel on the main frame (and the preview looks fine) but the changes are discarded when I compile and run the project. All I get is the old project executable without my new additions! (I did clean build as well). Or in other words a main frame cpp file and header file is not getting updated with the new changes I make to the form. The files are not read-only. Do anybody have any ideas as why this happens?
This most likely is the case when you have wxSmith files pointing to incorrect source files.
Open the project file (using your favorite editor) and check the Extensions xml tag:
<Extensions>
<code_completion />
<debugger />
<wxsmith version="1">
<gui name="wxWidgets" src="src/wxExampleApp.cpp" main="wxExample" init_handlers="necessary" language="CPP" />
<resources>
<wxPanel wxs="wxsmith/somePanel.wxs" src="src/somePanel.cpp" hdr="src/somePanel.h" name="windowTabPanel" language="CPP" />
</resources>
</wxsmith>
<envvars />
</Extensions>
Make sure that your src and hdr files point to the correct source files you have in your project.
Otherwise wxSmith won't be able to update those files based on the changes made from the RAD view.