Geertjan's Blog

  • December 17, 2011

Reuse the Groovy Editor for a Custom File Type

Geertjan Wielenga
Product Manager

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");
protected int associateLookup() {
return 1;
@MultiViewElement.Registration(displayName = "#LBL_Gradle_EDITOR",
mimeType = "text/x-gradle",
persistenceType = TopComponent.PERSISTENCE_ONLY_OPENED,
preferredID = "Gradle",
position = 1000)
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.

Be the first to comment

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