Reuse the Groovy Editor for a Custom File Type

A small trick learned from NetBeans Java Editor guru Jan Lahoda at Devoxx. Note the line in bold, all the rest is generated from the New File Type wizard:

public class GradleDataObject extends MultiDataObject {

    public GradleDataObject(FileObject pf, MultiFileLoader loader) throws DataObjectExistsException, IOException {
        super(pf, loader);
        registerEditor("text/x-gradle", true);
        getLookup().lookup(DataEditorSupport.class).setMIMEType("text/x-groovy");
    }

    @Override
    protected int associateLookup() {
        return 1;
    }

    @MultiViewElement.Registration(displayName = "#LBL_Gradle_EDITOR",
    iconBase = "SET/PATH/TO/ICON/HERE",
    mimeType = "text/x-gradle",
    persistenceType = TopComponent.PERSISTENCE_ONLY_OPENED,
    preferredID = "Gradle",
    position = 1000)
    @Messages("LBL_Gradle_EDITOR=Source")
    public static MultiViewEditorElement createEditor(Lookup lkp) {
        return new MultiViewEditorElement(lkp);
    }
    
}

By the way, wondering about "associateLookup" with the return value "1"? That's new in 7.1, read all about it here. The lower portion of the code above is also new in 7.1., enabling you to plug visual panels into your editor via annotations. Also, "registerEditor" is new too, and very cool, handling a lot of work for you, as explained here.

Comments:

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

Archives
« April 2014
SunMonTueWedThuFriSat
  
12
13
14
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today