4 Replies Last post: Jun 7, 2011 2:25 AM by Alexey Java  
Pete Hendry Newbie 4 posts since
Aug 21, 2002
Currently Being Moderated

Jan 30, 2006 2:43 PM

How to change the text/icon displayed for each file/directory in project view

I'd like to add new information to each file in the project view (and possibly package view). This may include the directories/package names as well. This information may be in iconic form or it may be text (prefixed or suffixed to the default text).

 

So, if I have a project view with directory structure

 

  src/

    com/

      example/

        Test.java

 

I may want to show something like

 

  100 src/

    100 com/

      100 example

        89 Test

 

or perhaps an icon before each file to show if it is read-only.

 

If this is possible, then how is it handled differenly if the option to flatten empty packages is selected? So I may want

 

  100 com.example

    89 Test

 

in the package view.

 

Thanks for any pointers. I've gone through the OpenAPI stuff 3 or 4 times now and no joy.

 

It will be nice when this is finally documented to a standard that is usable. I'm sure it is a great API but not really usable currently without a lot of wasted time (which will put off so many plugin writers unfortunately).

Guest
Currently Being Moderated
Jan 30, 2006 3:01 PM in response to: Pete Hendry
Re: How to change the text/icon displayed for each file/directory in project view

Hello Pete,

 

You can achieve this by implementing the TreeStructureProvider interface

and replacing the standard file nodes passed to your modify() method with

your custom nodes inherited from the AbstractTreeNode class. Your implementation

of AbstractTreeNode.update() can modify the icons or text of the node by

setting the fields of the PresentationData instance passed to that method.

 

We understand that the current OpenAPI documentation is not always adequate

for accomplishing complex tasks like this one, but we're constantly working

on improving the documentation.

 

PH> I'd like to add new information to each file in the project view

PH> (and possibly package view). This may include the

PH> directories/package names as well. This information may be in iconic

PH> form or it may be text (prefixed or suffixed to the default text).

PH>

PH> So, if I have a project view with directory structure

PH>

PH> src/

PH> com/

PH> example/

PH> Test.java

PH> I may want to show something like

PH>

PH> 100 src/

PH> 100 com/

PH> 100 example

PH> 89 Test

PH> or perhaps an icon before each file to show if it is read-only.

PH>

PH> If this is possible, then how is it handled differenly if the option

PH> to flatten empty packages is selected? So I may want

PH>

PH> 100 com.example

PH> 89 Test

PH> in the package view.

PH>

PH> Thanks for any pointers. I've gone through the OpenAPI stuff 3 or 4

PH> times now and no joy.

PH>

PH> It will be nice when this is finally documented to a standard that

PH> is usable. I'm sure it is a great API but not really usable

PH> currently without a lot of wasted time (which will put off so many

PH> plugin writers unfortunately).

 

--

Dmitry Jemerov

Software Developer

JetBrains, Inc.

http://www.jetbrains.com

"Develop with pleasure!"

 

 

 

StanAccy Novice 495 posts since
Mar 18, 2003

Dmitry

 

How do you register this new Implementation with IDEA so that the custom code gets called?

StanAccy Novice 495 posts since
Mar 18, 2003
Currently Being Moderated
Feb 11, 2010 11:07 PM in response to: StanAccy
Re: How to change the text/icon displayed for each file/directory in project view

Here's how I got this to work (with no thanks to the SDK documentation):

I make no reps as to whether this is the best way to achieve this functionality.

 

Add the following to your plugins META-INF/plugin.xml:

 

<extensions defaultExtensionNs="com.intellij">
  <iconProvider implementation="com.test.TestIconProvider"/>
</extensions>

 

then implement this class:

 

public class TestIconProvider extends IconProvider
{
private final Icon icon;

public TestIconProvider()
{
  this.icon = IconLoader.getIcon( "test_icon.PNG" );
}

@Override
public Icon getIcon( @NotNull PsiElement psiElement, int i )
{
  Language language = psiElement.getLanguage();
  String languageDisplayName = language.getDisplayName();

  if( !languageDisplayName.equals( "XML" ) )
  {
   return null;
  }

  if( psiElement.getText().contains( "<somespecifcxmlstringthatdefinesyourcustomxml" ) )
  {
   return icon;
  }
  else
  {
   return null;
  }
}
}

Alexey Java Newbie 45 posts since
May 18, 2011
Currently Being Moderated
Jun 7, 2011 2:25 AM in response to: StanAccy
Re: How to change the text/icon displayed for each file/directory in project view

add to the "extensions" section of plugin.xml file:

    <!-- Provides icons for ..... files shown in the Project View -->

    <iconProvider implementation="gw.plugin.ij.MyIconProvider"/>

the class file:

 

public class MyIconProvider extends IconProvider {

  private Map<String, Icon> icons = new HashMap<String, Icon>();

 

  public MyIconProvider() {

    icons.put(GosuClassFileType.EXT, GosuIcons.FILE_CLASS);

    icons.put(GosuProgramFileType.EXT, GosuIcons.FILE_PROG);

    icons.put(GosuEnhancementFileType.EXT, GosuIcons.FILE_ENH);

  }

 

  @Override

  public Icon getIcon(@NotNull PsiElement psiElement, int i) {

    String fileExtension = psiElement.getContainingFile().getVirtualFile().getExtension();

    return icons.get(fileExtension);

  }

}

More Like This

  • Retrieving data ...