Eclipse RCP Binding Service Sometimes Doesn't find key binding conflicts - eclipse-rcp

My RCP app has key binding conflicts among some of the features I've included, which are shown on the console at launch. Because many of my users are new to Eclipse, I want to handle this for them, so I detect the conflicts and remove them by assigning one command in each conflicting pair to an unused custom context.
This works as desired, except that sometimes the binding service fails to find the conflicts, even though they're reported on the console. This is how I search for the conflicts:
IBindingService bs =
PlatformUI.getWorkbench().getService(IBindingService.class);
KeySequence keySequence = ...//key sequence known to have binding conflicts
Collection<Binding> bindings =
bs.getConflictsFor(KeySequence.getInstance(keySequence));
After changing the context for some of the conflicting bindings, I save them all (with type set to USER) via bs.savePreferences(bs.getActiveScheme(), bindings.toArray(new Binding[0]));
When I do the above on a fresh workspace, the conflicts are resolved as expected for subsequent launches. Then to test the ability to restore them (in case some users want to specify a different resolution) I click "Restore Defaults" on the General-> Keys preference page. Sometimes when I do this, I see the conflicts logged on the console. In this case, I know that when I restart the app, it will once again find the conflicts.
But sometimes I don't see the console message when I restore the default bindings. In that case, for every subsequent launch of the app, the conflicts will be reported on the console, but the binding service will not find them. If I click "Restore Defaults" one more time, or launch in a fresh workspace, then the binding service will find the conflicts.
When the app is in the state where conflicts are reported on the console but not by the binding service, the file org.eclipse.ui.workbench.prefs in the settings area has the following entry: org.eclipse.ui.commands=<?xml version\="1.0" encoding\="UTF-8"?>\n<org.eclipse.ui.commands/>
I can't find any predictor of when the problem will occur or not. It seems to just randomly occur, close to 50% of the time after restoring the default bindings. Since starting in a fresh workspace fixes the problem, it seems that relevant state is being stored somewhere in addition to the org.eclipse.core.runtime settings file, but I have no idea where.
EDIT: I found the scenario in which it breaks. If I launch the app and it saves the customized bindings through the binding service, and then I click "Restore Defaults" (as opposed to relaunching the app and then restoring) I get into the failed state mentioned above.
At that point, the customized bindings are not in the org.eclipse.ui.workbench.prefs settings file, and the app model (workbench.xmi in org.eclipse.e4.workbench) has <bindings> elements with the same key sequence in the same parent <bindingtables> element, but the binding service is not reporting any conflicts (though the console log does). This seems like a bug. I'll report it as such unless someone thinks otherwise.
EDIT2: I failed to notice at first, but the problem is that in the failed state, there is (in the application model xmi file) a child <tags> element for the binding with value deleted. If I manually remove that tag, then the binding service recognizes the conflict. So here now is the actual problem, I think:
When I reset defaults for the key bindings in the same application
session in which I saved customized bindings, the default bindings
that were restored are tagged as deleted in the application model.

I resolved the problem by adding a line which reads the binding information from the registry and preferences, and overwrites the information in the binding service. I added this line after the code which saves the customized binding preferences.
IBindingService bs = ...
bs.savePreferences(bs.getActiveScheme(), bindings.toArray(new Binding[0]));
bs.readRegistryAndPreferences(null); //Added this line

Related

The meaning of profile contents checkboxes

The new version of VSCode 1.75 contains the new function Profiles, which I was waiting for.
It looks like you can install, activate or deactivate extensions in each profile, without affecting the other profiles.
So far I only managed to install, activate or deactivate extensions via the extension manager, or via the view page of the respective extension.
There is this new view that can be displayed via [Settings-Wheel]-[profiles]-[show contents]
There you can find a checkbox for each extension.
Intuitively, one would assume that the extensions for a profile can be either completely switched on or off (install) or at least activated / deactivated.
For me this checkbox has none of the mentioned effects.
The profiles work nevertheless, as said, with an activated profile extensions can be installed and uninstalled, the profiles can then be switched, and a profiles extension states get properly restored when reselected.
However, the view with these checkboxes seems largely pointless to me at the moment.
So my question is: what is their purpose?
Should their purpose be what I suspected, and the feature just isn't "ready" yet?
The checkboxes are for exporting the profile without including undesired configuration options. For example, the "UI State" option will save the currently open menus and submenus as a part of the profile's configuration, which you likely don't really want in most cases.
Notably, when I created a new blank profile and accessed this menu the only field present was the UI State, which implies that if a field is the same as the default configuration it won't be saved to the file.
When you export, you can name the profile and either save it locally as a ".code-profile" file, or upload it directly to GitHub as a gist. The file uses a syntax that I believe is unique, though it's very possible I just don't know it. It would be nice to have a simple JSON schema, but I'm sure the community is going to automate the hell out of this process within a few weeks/days.
I'm pretty sure the purpose of those checkboxes is to select whether or not each extension gets exported as part of the profile. Presumably they are all activated upon importing the profile and installing those profile extensions.

eclipse e4 restore perspective on startup automatically

We all know that by default eclipse saves application state in workbench.xmi and then recreates perspective only if this file is absent. However, I've got a project on e4 which ignores this file even though it exists and -clearPersistentState is NOT specified in arguments. I think there should be some piece of code somewhere responsible for this but the project is too big I don't know how to track it down. My goal is to make this app to use workbench.xmi once again to restore perspective.
To investigate why this happens I want to know which eclipse method is responsible for perspective restoration so I could make sure that this project at least launches this method. That's the main question.
The less main and the less clear question is how this default restoration behavior can be avoided? I mean where should I look for the possible source of this problem? Could there be some option in some .xml which makes the project forget about workbench.xmi? Could it be some sort of startup handler which manually restores default perspective? Maybe some hint about which methods are possibly should be involved in this so I could search for them. Any help is appreciated. Thanks in advance.
-UPDATE-
So it turned out that the problem arises because the project UI is defined in fragments rather than in main Application.e4xmi and eclipse has a bug due to which fragments UI merge with main application after previous state restoration thus replacing restored settings with predefined ones. This bug is discussed in this thread.
This useful article describes how one can manually save and load various application components. Another useful source of inspiration is the source code of ResourceHandler itself.
The main E4Application class controls loading and saving the application model.
E4Application calls a class implementing IModelResourceHandler to load and save the model and the persisted state. It is possible for an application to use its own version of IModelResourceHandler but normally the default org.eclipse.e4.ui.internal.workbench.ResourceHandler is used.
ResourceHandler uses the clearPersistedState, persistState and the deprecated deltaRestore options to control loading the persisted state. These values can be set by command line options.
Add apply="initial" to fragment tag in your plugin.xml to restore stored perspective from workbench.xmi
Example:
<fragment
uri="fragment.e4xmi"
apply="initial">
</fragment>

Is there auto-syncing in netbeans for external changes

I know netbeans syncs the original files once I save, but if there is a file changed externally is there a way for netbeans to recognize this and either tell me to re-sync it or automatically resync it with the new changes?
Here's what makes this behavior possible:
NetBeans 6.9 contains a feature that automatically looks for external changes to keep informations about files up-to-date. We have some reports that it can slow down NetBeans mainly, when an open project has many folders. When NetBeans find out that files were externally changed, it re-scans the files to keep data up-to-date that are used with features like code completion, navigation etc. Unfortunately the notification and following re-scanning can take some time and during this time many mentioned features are waiting for the finishing of scanning. There is option Enable auto-scanning of sources that can switch off this behavior. The option you can find it in Options dialog, Miscellaneous category and Files tab.
The default behavior is that NetBeans also looks for external changes when the main window gets focus. This is can be during developing a web application very often when user switches between browser and IDE. The mentioned option also switch this off.
When you switch off option Enable auto-scanning of sources you can still keep the information up-to-date, just invoke Scan for External Changes action from Sources menu manually.
(Here's the original article by Petr Pisl)
I find it counterproductive to leave this setting on, as sometimes auto-loading external changes to a file opened in the UI without asking for permission first can ruin your day when you're forced to make small local changes that you don't want replicated in your repository. I'm sure other people can think of more reasons to advocate for "warn before loading external changes" behavior to be implemented in NB. That is one of the reasons why I like Eclipse better sometimes.

Eclipse auto refresh (after custom builder) does not discover new files

This is not another of many "how do I have Eclipse auto refresh" questions. My problem is that it does but not entirely.
In a workspace with multiple projects the compilation of one causes source code to be generated in other(s) (that exist purely for this purpose - no manually written source code there). Source code is generated during the main compilation itself (i.e. not a custom builder, but a plugin for the Scala compiler, but that should be irrelevant).
What I've done so far is:
Add a dummy custom (ant) builder AFTER the standard one and set it to "refresh selected resources" - the source folder of those generated projects.
Also add a dummy custom (ant) builder BEFORE the standard (Java) builder of generated projects that refresh the same thing. Actually I tried various versions - just the source folder, the entire project, or the entire workspace with the same outcome. Note that those generated projects are set to depend on the project whose compilation generates their source code.
In Window -> Preferences -> General -> Workspace enabled "Refresh using native hooks or polling" in addition to "Refresh on access". I also tried disabling "Refresh on access" (leaving only the other one). Same outcome.
Tried with Eclipse Indigo (3.7 SR2 20120216-1857) and Juno (4.2.2 M20130204-1200), both 64-bit Windows versions. Additional plugins are installed, most notably Scala IDE (multiple different versions both for Scala 2.9 and 2.10 ending with Scala IDE 3.0.0). Same outcome.
... and that outcome is that Eclipse does indeed notice the files that have been modified. In whatever was the best combination of settings of the above (forgot) I was even able to get it to notice that some files that used to be generated no longer are and have them disappear (although I still had to collapse the tree and re-expand it, but no F5 was needed).
However, I never got to have it automatically discover that a brand new file that did not exist before was created. In my case that also yields compilation errors (since the modified files that it does discover have changed refer to the code in new files it does not notice).
Simple F5 solves the problem, but it is killing me, as I am trying to roll this environment to other developers and I'd hate having to tell them "You know, you have to (keep) push(ing) F5 every time you...".
Is it possible that this is still impossible in Eclipse? Does anyone know of a plugin (if not a direct solution) that can help?
As I noted in comments, discovering new folders (Java packages) also does not seem to be a problem. Just new files in existing folders.
Thanks!
UPDATE
With all the refresh things I did in place I noticed something I did not before.
I make the change in the project that causes code generation (was trying to test if it is the re-appearance of previously disappearing file is an issue or otherwise). This time I was just renaming one method which caused a name of the generated source file (Java class) to be changed as well.
As "Build automatically" is enabled, Eclipse begins the build. Very quickly it discovers an error and complains about it - one generated class that was modified now refers to a class Eclipse does not see yet (because refresh is incomplete - saw the modified file, but still believed that the file that no longer exists is there and did not see the new file).
Build actually continues. Progress goes up and down, appears and disappears a number of times, building other dependent projects. All the time the error is listed and marked in the Package Explorer on the modified class.
After the build seemingly completes (with that error in it, some minutes later), the refresh completes (!!!). Package Explorer is updated, the old file disappears, the new file appears, the error disappears, etc. I initially attributed this to me switching windows and triggering the refresh that way but I made sure I touched nothing the last time - just made the change and pushed Ctrl+S to save it.
This may mean that the 'condition' is not so bad (one just has to be very patient and have nerves of steel). Investigating further. Thanks to all who are or may be doing the same! The question is still why are there two refreshes with the first one being incomplete?

Why does my Eclipse project have phantom debugger breakpoints?

I've got a small project which, when run in the Eclipse debugger, always seems to stop in FileInputStream.class line 106, where files are opened. There are no breakpoints set, but Eclipse behaves exactly as if I have a breakpoint here. If I clear all breakpoints, it still happens.
I have a second much-larger project in the same Eclipse workspace which does not suffer from this problem.
I just moved the smaller project off of my old Linux machine, where I developed it in Europa Eclipse and had this problem, onto my new Windows machine, where I continue to see the problem in Ganymede Eclipse. The problem persists across operating systems and across Eclipse versions, yet apparently not across projects. I don't get it! I grepped through every file in this project's directory and couldn't find anything that might be a file somehow directing Eclipse to stop in FileInputStream.
Further info: the apparent breakpoint is actually not for line 106 of FileInputStream; it appears to be an Exception breakpoint for FileNotFoundException, being thrown from native code called from that line in FileInputStream. But again, I don't appear to have any breakpoints set at all. Are Exception breakpoints defined somewhere else?
Did you try to un-select
Window > Preferences > Java > Debug : Suspend execution on uncaught exceptions
? (as mentioned in this thread, for instance)
Why does Eclipse work that way?
It goes back to 2002, when the breakpoint object hierarchy has been stripped down.
In order to set a breakpoint, with the old API, a client required Java Model Objects - such as IType, IField, etc.
With the new API, all that is required by the debug model is type names, field names, etc.
This allows clients to set breakpoints when Java Model Objects are not available.
Clients now specify the resource to associate a breakpoint with (before we constrained it to the associated Java Model resources).
Breakpoints can now also be "hidden". That is, they need not be registered with the breakpoint manager.
Breakpoints can also be selectively persisted (markers only allowed all/none of a marker type to be persisted).
This makes the debug model more flexible, and gives clients more building blocks.
This has also simplified some part of our Java debug implementation - for example, the feature "suspend on any uncaught exception", simply sets a breakpoint for the type named "java.lang.Throwable", rather than a specific IType in a specific project.
The breakpoint is not registered with the breakpoint manager (i.e. hidden) - it is only known and used by one client.
Another example is the "run to line breakpoint". The IJavaRunToLineBreakpoint has been removed, as its special functionality is no longer required. Now, the Java debug ui simply creates a "line breakpoint" that is hidden, non persisted, and has a hit count of 1. This is an example of providing building blocks to clients.
I had a similar problem but the accepted solution did not work for me. I am doing Eclipse Android development and had set some breakpoints and later unset them. Even though I disabled them Eclipse kept stopping execution at these phantom breakpoints. The solution for me was to open the Breakpoints window:
Window > Show View > Other...
Debug > Breakpoints
Then right click any breakpoint and select "Remove All"
Unfortunately you have to reset all your valid breakpoints, but this worked for me and has prevented much angst and frustration going forward.
Some pictures to guide others:
For those who don't find other solutions useful, I found my personal solution to my problem. I work with a .jar library which is generated by building another project into the workspace. If I set a breakpoint in a .java into the library project, then the breakpoint will be triggered when debugging the final project. However when debugger pauses the execution the .class file is shown which has its own breakpoints and therefore the breakpoint set into the .java file is not shown here!
Solution:
In order to remove the breakpoint you have to remove the breakpoint into the .java file, in the library project.
I ran into an issue where a source file had persistent markers for breakpoints that didn't exist. I tried cleaning the project, doing a full build, restarting Eclipse - nothing worked.
I went digging through the Eclipse metadata, and found the projects .markers file. Deleting that file finally fixed the issue.
For anyone else having this issue, open your workspace directory, then navigate to .metadata/.plugins/org.eclipse.core.resources/.projects/your project, then rename/remove file .markers.
For example, if your workspace folder is ~/workspace, and your project is named Foo, you could do:
$ mv ~/workspace/.metadata/.plugins/org.eclipse.core.resources/.projects/Foo/.markers ~/safe.Foo.markers
For those who didn't find a solution from the previous answers, they can try what solved my problem. It is I think similar to HAL9000 problem/solution
If you have two classes with the same name (in two different projects) the breakpoints on the one, apply on the other one as well. Both of them show in the "Breakpoints" window.
Solution: If you remove the breakpoint from the class - with the same name - that you are not using it removes the breakpoint from the class you are debugging.