Change the presentation properties of AbstractTreeNode

I need to change the presentation icons of an AbstractTreeNode. The method abstractTreeNode.getPresentation() returns a new instance of PresentationData everytime and setting the new icons in this will naturally not change the icons of the AbstractTreeNode.

When the myOpenIcon member of the AbstractTreeNode is an instance of RowIcon I am able to change the icon at the first location in the RowIcon to achieve what I need to. But when it is an instance of CachedImageIcon I need to set the myOpenIcon member to a new value.

How can this be done?

I have tried AbstractTreeNode.update() but am not sure how it will pickup the new value.

Edited by: Dhwani Katagade on Apr 17, 2008 3:26 PM

7 comments
Comment actions Permalink

Hello Dhwani,

I need to change the presentation icons of an AbstractTreeNode. The
method abstractTreeNode.getPresentation() returns a new instance of
PresentationData everytime and setting the new icons in this will
naturally not change the icons of the AbstractTreeNode.

When the myOpenIcon member of the AbstractTreeNode is an instance of
RowIcon I am able to change the icon at the first location in the
RowIcon to achieve what I need to. But when it is an instance of
CachedImageIcon I need to set the myOpenIcon member to a new value.

How can this be done?


In which exactly tree do you need to change the presentation? It is not in
general allowed to make arbitrary changes to items of the tree you don't
own - this won't work correctly. In many cases (for example, in project view)
there is specific customization API that lets you provide your own getPresentation()
implementation.

--
Dmitry Jemerov
Development Lead
JetBrains, Inc.
http://www.jetbrains.com/
"Develop with Pleasure!"


0
Comment actions Permalink

Hi Dmitry,

I am trying to modify the icons on the ProjectViewNode in the ProjectView. I have an implementation of TreeStructureProvider.modify(...) and in this method i check for certain conditions and add icon decorations to the standard IntelliJ icons. I am able to modify the icons for file elements since these icons are instances of RowIcon. All i have to do is get the zeroth icon from the RowIcon, use to it create a LayeredIcon and put it in the zeroth location of the RowIcon.

But in case of folder icons, they are not RowIcons. They are plain CachedImageIcon instances. I essentially have to replace them in the ProjectViewNode object. Now what is the right way of doing this? Or am i loking at the problem in the wrong way?

0
Comment actions Permalink

Hello Dhwani,

Most likely the right way to achieve what you need is to register an ApplicationComponent
implementing the IconProvider interface. This will allow you to easily modify
icons for certain PSI elements wherever they appear (in the project view,
structure view etc.)

I am trying to modify the icons on the ProjectViewNode in the
ProjectView. I have an implementation of
TreeStructureProvider.modify(...) and in this method i check for
certain conditions and add icon decorations to the standard IntelliJ
icons. I am able to modify the icons for file elements since these
icons are instances of RowIcon. All i have to do is get the zeroth
icon from the RowIcon, use to it create a LayeredIcon and put it in
the zeroth location of the RowIcon.

But in case of folder icons, they are not RowIcons. They are plain
CachedImageIcon instances. I essentially have to replace them in the
ProjectViewNode object. Now what is the right way of doing this? Or am
i loking at the problem in the wrong way?

--
Dmitry Jemerov
Development Lead
JetBrains, Inc.
http://www.jetbrains.com/
"Develop with Pleasure!"


0
Comment actions Permalink

Hi Dmitry,

What we need to do is modify the existing icon of an element in the Project View depending on its Vcs status. For instance if the element is modified we overlay a small modified icon on the default icon for the element.

I tried the approach that you had suggested. I created an ApplicationComponent implementing the IconProvider interface. In the getIcon(PsiElement element, int flags) method we get an instance of the PsiElement. The actual object passed is one of the many sub types of PsiElement. But how can we get the default icon for the specific object type? Say if a PsiClass object is passed then how can we get the default icon for it? As I understand it, presentation objects are not associated at this level. To provide a clean solution for what we want to do, we will have to get the default icon for any subtype of PsiElement and then overlay it with our element status icon.

I have seen that the Icons class has constants for all the icons. These could be used but it would involve a dirty switch case like approach. Your pointers would be greatly helpful.

thanks
dk

0
Comment actions Permalink

Hello Dhwani,

you can use element.getIcon(flags) to get the original icon if you guard your IconProvider
implementation against recursive calls. Here's an example:
http://svn.jetbrains.org/idea/Trunk/bundled/xpath/xpath-lang/src/org/intellij/lang/xpath/xslt/impl/XsltStuffProvider.java

Sascha

Hi Dmitry,

What we need to do is modify the existing icon of an element in the Project View depending on its Vcs status. For instance if the element is modified we overlay a small modified icon on the default icon for the element.

I tried the approach that you had suggested. I created an ApplicationComponent implementing the IconProvider interface. In the getIcon(PsiElement element, int flags) method we get an instance of the PsiElement. The actual object passed is one of the many sub types of PsiElement. But how can we get the default icon for the specific object type? Say if a PsiClass object is passed then how can we get the default icon for it? As I understand it, presentation objects are not associated at this level. To provide a clean solution for what we want to do, we will have to get the default icon for any subtype of PsiElement and then overlay it with our element status icon.

I have seen that the Icons class has constants for all the icons. These could be used but it would involve a dirty switch case like approach. Your pointers would be greatly helpful.

thanks
dk

0
Comment actions Permalink

Hello Dhwani,

What we need to do is modify the existing icon of an element in the
Project View depending on its Vcs status. For instance if the element
is modified we overlay a small modified icon on the default icon for
the element.


You're going against the flow of IntelliJ IDEA. :) IntelliJ IDEA displays
file statuses with colors of item names rather than icons. This is implemented
consistently, and correctly updated, across all views where this information
should be displayed. You get this functionality for free if you implement
correctly one VCS plugin interface (ChangeProvider).

Of course if you really want to be unlike all other VCS integration plugins,
you can probably implement what you want (and maybe even fix all the bugs
with your status icons not getting updated correctly when the status of the
files changes), but please consider if it's really the best investment of
your resources and the best solution for users of your plugin.

Note also that a class icon, for example, can already have up to four different
overlay icons, one in each corner. We feel that adding yet another icon on
top of all those will add too much clutter.

--
Dmitry Jemerov
Development Lead
JetBrains, Inc.
http://www.jetbrains.com/
"Develop with Pleasure!"


0
Comment actions Permalink

Hi Dmitry,

I appreciate and completely understand your suggestion to put us on the right track regarding going with the flow of IntelliJ Idea. But the sad part is that I am not designing this feature but just fixing an issue with it. Our plugin already has overlay icons to mark the status and they do change with the status. The issue that I have to fix is that these status marker icons do not get displayed on folder and package icons.

Following the suggestion given by Sascha I am now able to display the marker icons on file and class elements. They also nicely show up in other places where the class icon is displayed. But the problem with folder icons still persists. They do not show the overlaid icons. I traced through the code and it works as expected. I do get the icon for the folder and I am able to replace it with the modified icon too.

Are the icons for folders cached somewhere, or are they globally used? Please help.

thanks
dk

0

Please sign in to leave a comment.