org.netbeans.spi.project.ProjectIconAnnotator

When you have multiple NetBeans Platform application projects, there's no way to see which module belongs to which suite.

Several NetBeans Platform developers have stated they have a problem with this, i.e., it is inconvenient.

Well, I haven't solved that problem.  But I did play with this interesting class which I'd never heard about before:

org.netbeans.spi.project.ProjectIconAnnotator

The result is that now I can distinguish between applications, modules that belong to applications, and modules that are standalone:

I.e., "module1" above is not part of an application and hence doesn't have an icon, as a way to identify it. However, ideally, I'd like the modules belonging to "Paint Application" to have an icon shared with the Paint Application, while a a different icon would be used for the modules plus the suite of other applications.

@ServiceProvider(service = ProjectIconAnnotator.class)
public class SampleProjectIconAnnotator implements ProjectIconAnnotator {

    private final ChangeSupport pcs = new ChangeSupport(this);
    private boolean enabled;

    public @Override
    Image annotateIcon(Project p, Image orig, boolean openedNode) {
        SuiteProject sp = p.getLookup().lookup(SuiteProject.class);
        if (sp != null) {
            enabled = true;
            return 
                    ImageUtilities.mergeImages(ImageUtilities.addToolTipToImage(orig, "Annotated!"),
                    ImageUtilities.loadImage("org/sample/project/icon/annotator/red.png"), 16, 0);
        } else {
            NbModuleProvider mp = p.getLookup().lookup(NbModuleProvider.class);
            if (mp != null && mp.getModuleType().equals(NbModuleType.SUITE_COMPONENT)) {
                enabled = true;
                return 
                        ImageUtilities.mergeImages(ImageUtilities.addToolTipToImage(orig, "Annotated!"),
                        ImageUtilities.loadImage("org/sample/project/icon/annotator/green.png"), 16, 0);
            } else {
                enabled = false;
            }
        }
        return orig;
    }

    public @Override
    void addChangeListener(ChangeListener listener) {
        pcs.addChangeListener(listener);
    }

    public @Override
    void removeChangeListener(ChangeListener listener) {
        pcs.removeChangeListener(listener);
    }

    void setEnabled(boolean enabled) {
        this.enabled = enabled;
        pcs.fireChange();
    }

}

So the above is a solution to a different problem, but interesting anyway. Impl dep needed on apisupport related modules.

Comments:

Note that this code will not work in NB 7.1. Perhaps better to directly load nbproject/project.xml and check for <type>...</>, <standalone/>, <suite-component/>.

Posted by Jesse Glick on July 26, 2011 at 12:04 AM PDT #

Cool post. I can see this one useful for indicating that a project has an external plugin enabled on itself (e.g. Checkstyle, ..., Featureous ;-)).

Posted by Andrzej Olszak on July 26, 2011 at 03:23 AM PDT #

Nice idea ;-)
Now after my holidays I will also have a look at that topic

Greetz from Aachen

Posted by Lukas K on July 28, 2011 at 06:19 PM PDT #

Post a Comment:
  • HTML Syntax: NOT allowed
About

Geertjan Wielenga (@geertjanw) is a Principal Product Manager in the Oracle Developer Tools group living & working in Amsterdam. He is a Java technology enthusiast, evangelist, trainer, speaker, and writer. He blogs here daily.

The focus of this blog is mostly on NetBeans (a development tool primarily for Java programmers), with an occasional reference to NetBeans, and sometimes diverging to topics relating to NetBeans. And then there are days when NetBeans is mentioned, just for a change.

Search

Categories
Archives
« July 2016
SunMonTueWedThuFriSat
     
3
9
15
16
17
18
20
24
25
26
27
28
29
30
31
      
Today