Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » Java Development Tools (JDT) » Changing the icon of a CompilationUnitEditor at runtime
Changing the icon of a CompilationUnitEditor at runtime [message #1833508] Thu, 15 October 2020 11:19 Go to next message
Dirk Olmes is currently offline Dirk OlmesFriend
Messages: 26
Registered: July 2009
Junior Member
When I have a lot of editors open I sometimes lose track of where I'm actually editing. This mainly happens when I'm developing unit tests and I have to look around in the code in other editors.

I came up with the idea to change the icon of the "main editor" I'm working in. I created a subclass of CompilationUnitEditor and working my way from there via JavaEditorErrorTickUpdater and JavaUILabelProvider I was able to install a custom subclass of JavaElementImageProvider that allows me to switch out the icon.

While that approach works (I've been using that plugin for quite some time now) it's a faily hacky thing to do. I have to poke around with reflection in the various classes because most of the fields are private and instantiated from within the class that holds it.

Does anyone have a better solution to this? Or would there be a chance to open up the JDT API a bit so I can implement my plugin using more "legal" APIs?
Re: Changing the icon of a CompilationUnitEditor at runtime [message #1833523 is a reply to message #1833508] Thu, 15 October 2020 16:10 Go to previous messageGo to next message
David M. Karr is currently offline David M. KarrFriend
Messages: 801
Registered: July 2009
Senior Member
I'm not familiar with the internals, but I'm just trying to figure out what you're asking for. It doesn't seem like it has any relation to JDT. What do you mean by "where I'm actually editing"? Obviously, that is the currently focused editor tab, but you must be referring to something else.

Are you perhaps referring to the problem of being able to get back to the CUT (code under test) when you're looking at the unit test for a class? This is one nice feature of the "MoreUnit" plugin. that makes it easy to jump back and forth between the unit test and the CUT (it also has intelligence to figure out which unit test methods and which CUT methods to go to, depending on the current method in focus).
Re: Changing the icon of a CompilationUnitEditor at runtime [message #1833529 is a reply to message #1833523] Fri, 16 October 2020 06:51 Go to previous messageGo to next message
Dirk Olmes is currently offline Dirk OlmesFriend
Messages: 26
Registered: July 2009
Junior Member
David M. Karr wrote on Thu, 15 October 2020 12:10
I'm not familiar with the internals, but I'm just trying to figure out what you're asking for. It doesn't seem like it has any relation to JDT. What do you mean by "where I'm actually editing"? Obviously, that is the currently focused editor tab, but you must be referring to something else.


Thanks for you reply, David.
Maybe I need to explain my motivation a bit better. When I'm programming I typically have quite a few editor tabs open. One editor tab contains the code that I'm actually writing while the other tabs are open because I need to look at some different parts of the code, Maven POMs, XML config files, whatever.

It's all about editor tab navigation - once I leave the tab that contains the code that I'm writing and look at a different editor tab I have a hard time jumping back. Was it the first editor tab? The second one? Or the second last one? This is what sparked the idea for the plugin: if I could change the icon of the editor tab that I'm currently working in it would be very easy to jump back where I came from.

A picture probably tells more than a thousand words so I have attached a screenshot with my plugin in action. It should be fairly obvious which is the editor I'm currently writing code in :-)
Re: Changing the icon of a CompilationUnitEditor at runtime [message #1833531 is a reply to message #1833529] Fri, 16 October 2020 07:32 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33140
Registered: July 2009
Senior Member
I often run into this type of issue. I'll have 30-80 editors open after debugging, stopping at breakpoints, navigating via F3 to various declarations to look at APIs. Then I want to get back to my "important" editor where I was doing the actual work. Hopefully I can use "Back" or the "Previous Edit Location" buttons to find it easily. But often with Back, the tool bar changes depending on the editor type and then location of the Back button changes, so I hit wrong button. Then one is left with the "where oh where is that darn editor" problem. I suppose I could Detach it , or split the editor area, but with a split editor area, both areas start to fill up again and then I have the same problem again.

It seems to me though that what you're describing as a solution is much more general than just JDT. I.e., it seems to me that it would indeed be useful to have a general UI capability to mark any editor tab (one or more?) as "favorite" such that it is visibly decorated in a somewhat eye-catching way so that one can easily find it visually. But rather than implementing that as a separate plugin, where you'll always have the problem of digging deep in the internals, instead contributing such a thing directly to the Platform UI project so it's generally available everywhere (via the context menu on the editor tabs).

It's a very welcoming community for contributions:

https://wiki.eclipse.org/Platform/How_to_Contribute
https://wiki.eclipse.org/Platform_UI/How_to_Contribute/Oomph
https://wiki.eclipse.org/Eclipse_Platform_SDK_Provisioning


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Changing the icon of a CompilationUnitEditor at runtime [message #1833555 is a reply to message #1833531] Fri, 16 October 2020 19:21 Go to previous messageGo to next message
David M. Karr is currently offline David M. KarrFriend
Messages: 801
Registered: July 2009
Senior Member
I guess the "Bookmarks" facility comes close. You can set a bookmark in a critical file, and put the Bookmarks view in a convenient place, and as long as you don't use too many bookmarks (like, only one), you can just double click on the bookmark to get back to the "main" file. Unfortunately, it appears that bookmarks aren't available for all file types. It doesn't work in pom.xml files, for instance.
Re: Changing the icon of a CompilationUnitEditor at runtime [message #1833631 is a reply to message #1833531] Tue, 20 October 2020 06:47 Go to previous messageGo to next message
Dirk Olmes is currently offline Dirk OlmesFriend
Messages: 26
Registered: July 2009
Junior Member
Ed Merks wrote on Fri, 16 October 2020 03:32
It seems to me though that what you're describing as a solution is much more general than just JDT. I.e., it seems to me that it would indeed be useful to have a general UI capability to mark any editor tab (one or more?) as "favorite" such that it is visibly decorated in a somewhat eye-catching way so that one can easily find it visually. But rather than implementing that as a separate plugin, where you'll always have the problem of digging deep in the internals, instead contributing such a thing directly to the Platform UI project so it's generally available everywhere (via the context menu on the editor tabs).


Thanks for the heads up, Ed. I'm afraid, though that such an extension of the Platform UI is a bit over my head. I wouldn't even know where to start digging into it.

If you could give me any tips (in addition to those you already gave) I'd be very thankful.
Re: Changing the icon of a CompilationUnitEditor at runtime [message #1833675 is a reply to message #1833631] Wed, 21 October 2020 06:45 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 33140
Registered: July 2009
Senior Member
I would start by opening a Bugzilla enhancement request.

https://bugs.eclipse.org/bugs/enter_bug.cgi?product=Platform&component=UI&version=4.18

Describe what you would like to enhance and make it clear that you want to do the work of doing the enhancing yourself as a contribution. Ask those folks where the best place would be to get started (assuming they agree this would be a good enhancement).


Ed Merks
Professional Support: https://www.macromodeling.com/
Previous Topic:Selected string not delete while type new string.
Next Topic:After updating to 2020-09, Java support is gone
Goto Forum:
  


Current Time: Thu Apr 25 07:33:37 GMT 2024

Powered by FUDForum. Page generated in 0.03536 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top