X

Geertjan's Blog

  • July 25, 2011

org.netbeans.spi.project.ProjectIconAnnotator

Geertjan Wielenga
Product Manager

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.

Join the discussion

Comments ( 3 )
  • Jesse Glick Tuesday, July 26, 2011

    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/>.


  • Andrzej Olszak Tuesday, July 26, 2011

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


  • Lukas K Friday, July 29, 2011

    Nice idea ;-)

    Now after my holidays I will also have a look at that topic

    Greetz from Aachen


Please enter your name.Please provide a valid email address.Please enter a comment.CAPTCHA challenge response provided was incorrect. Please try again.