]> &api-questions;

The main purpose of this API is to allow third-party customizations of editor tabs. Instead of implementing many interfaces and creating various UI delegates it is possible to create a simple decorator-like class that can customize the appearance of a specific editor tab. For example change tabs background color according to file type or project type, change its icon etc.

The API will be covered by unit tests.

The API is already implemented in org.netbeans.core.multitabs package.

To customize the rendering of (some) editor tabs one needs subclass TabDecorator class and register it in the global Lookup.

The example below shows a decorator that removes file extension from Java source files to have shorter tabs to show more file names without the need for scrolling.

ServiceProvider(service = TabDecorator.class, position = 1000)
public class MyTabDecorator extends TabDecorator {

    public String getText( TabData tab ) {
        String res = tab.getText();
        if( null != res )
            res = res.replace( ".java", "");
        return res;
    }
}
              

If one needs a custom editor tab displayer for example to have special tab layout or special layout of scrolling buttons etc it is necessary to subclass TabDisplayer class and register an instance of TabDisplayerFactory in the global Lookup.


public class MyTabDisplayer extends TabDisplayer {

    public MyTabDisplayer( TabDataModel model ) {
        super( model );
    }

    ServiceProvider(service = TabDisplayerFactory.class)
    public static class MyTabDisplayerFactory extends TabDisplayerFactory {
        public TabDisplayer createTabDisplayer( TabDataModel tabModel, int orientation ) {
            return new MyTabDisplayer( tabModel );
        }
    }

    //implement all abstract methods here
}
          

Allow easy customization of editor tabs.

This API doesn't not deprecate or replace any existing APIs.

Yes

No

Yes

1.6 or better.

JRE

The module depends on org.netbeans.swing.tabcontrol module (it reuses its data model) and on org.netbeans.core.windows module as it implements some of its tab container interfaces and classes.

It is platform independent.

No other dependencies.

JAR only

Yes

Only package org.netbeans.core.multitabs is exported as public.

Does not matter

No

No

No

No

No

No

No

No

The API creates/uses Swing components which should be access from EDT only.

No custom data flavors.

No custom d'n'd

No file formats

The module checks the global lookup for an instance of org.netbeans.core.multitabs.TabDisplayerFactory to see if other than the default implementation of multi-tabs is available.

The default implementation of multi-tabs also looks for org.netbeans.core.multitabs.TabDecorator instances to check if any third party wants to change the editor tab rendering.

The module registers an instance of org.netbeans.swing.tabcontrol.customtabs.TabbedComponentFactory to provide custom implementation of editor tabs displayer.

No

No

No

No

It's just a JTable showing an editor tab in each cell.

No

No

Does not apply

All the code will be executed in EDT, NetBeans slowness detector should kick-in when third-party plugin takes too much time.

No

No

No

Yes, it is used to register its options panel into Tools - Options window.

No

NbPreferences are used to store user settings in Tools - Options window.

No

No

No