New File Type Wizard in NetBeans IDE 7.2

Prior to 7.2, when you use the New File Type wizard to create a new MIME type for the NetBeans Platform, you'd get a folder/file structure like this:

From 7.2 onwards, under the same conditions, you'll get this instead:

A lot less files. That's because the others are created when the module compiles because of the annotations in the AbcDataObject file:

package org.myorg.abcfiletype;

import java.io.IOException;
import org.netbeans.api.templates.TemplateRegistration;
import org.netbeans.core.spi.multiview.MultiViewElement;
import org.netbeans.core.spi.multiview.text.MultiViewEditorElement;
import org.openide.WizardDescriptor;
import org.openide.awt.ActionID;
import org.openide.awt.ActionReference;
import org.openide.awt.ActionReferences;
import org.openide.filesystems.FileObject;
import org.openide.filesystems.MIMEResolver;
import org.openide.loaders.DataObject;
import org.openide.loaders.DataObjectExistsException;
import org.openide.loaders.MultiDataObject;
import org.openide.loaders.MultiFileLoader;
import org.openide.util.Lookup;
import org.openide.util.NbBundle.Messages;
import org.openide.windows.TopComponent;

@Messages({
    "LBL_Abc_LOADER=Files of Abc"
})
@MIMEResolver.ExtensionRegistration(
    displayName = "#LBL_Abc_LOADER",
mimeType = "text/x-abc",
extension = {".abc", ".ABC"})
@DataObject.Registration(
    mimeType = "text/x-abc",
iconBase = "org/myorg/abcfiletype/abc16.png",
displayName = "#LBL_Abc_LOADER",
position = 300)
@ActionReferences({
    @ActionReference(
        path = "Loaders/text/x-abc/Actions",
    id =
    @ActionID(category = "System", id = "org.openide.actions.OpenAction"),
    position = 100,
    separatorAfter = 200),
    @ActionReference(
        path = "Loaders/text/x-abc/Actions",
    id =
    @ActionID(category = "Edit", id = "org.openide.actions.CutAction"),
    position = 300),
    @ActionReference(
        path = "Loaders/text/x-abc/Actions",
    id =
    @ActionID(category = "Edit", id = "org.openide.actions.CopyAction"),
    position = 400,
    separatorAfter = 500),
    @ActionReference(
        path = "Loaders/text/x-abc/Actions",
    id =
    @ActionID(category = "Edit", id = "org.openide.actions.DeleteAction"),
    position = 600),
    @ActionReference(
        path = "Loaders/text/x-abc/Actions",
    id =
    @ActionID(category = "System", id = "org.openide.actions.RenameAction"),
    position = 700,
    separatorAfter = 800),
    @ActionReference(
        path = "Loaders/text/x-abc/Actions",
    id =
    @ActionID(category = "System", id = "org.openide.actions.SaveAsTemplateAction"),
    position = 900,
    separatorAfter = 1000),
    @ActionReference(
        path = "Loaders/text/x-abc/Actions",
    id =
    @ActionID(category = "System", id = "org.openide.actions.FileSystemAction"),
    position = 1100,
    separatorAfter = 1200),
    @ActionReference(
        path = "Loaders/text/x-abc/Actions",
    id =
    @ActionID(category = "System", id = "org.openide.actions.ToolsAction"),
    position = 1300),
    @ActionReference(
        path = "Loaders/text/x-abc/Actions",
    id =
    @ActionID(category = "System", id = "org.openide.actions.PropertiesAction"),
    position = 1400)
})
public class AbcDataObject extends MultiDataObject {

    public AbcDataObject(FileObject pf, MultiFileLoader loader) throws DataObjectExistsException, IOException {
        super(pf, loader);
        registerEditor("text/x-abc", true);
    }

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

    @MultiViewElement.Registration(
        displayName = "#LBL_Abc_EDITOR",
    iconBase = "org/myorg/abcfiletype/abc16.png",
    mimeType = "text/x-abc",
    persistenceType = TopComponent.PERSISTENCE_ONLY_OPENED,
    preferredID = "Abc",
    position = 1000)
    @Messages("LBL_Abc_EDITOR=Source")
    public static MultiViewEditorElement createEditor(Lookup lkp) {
        return new MultiViewEditorElement(lkp);
    }

    @TemplateRegistration(folder = "Other", content = "AbcTemplate.abc")
    public static WizardDescriptor.InstantiatingIterator templateIterator() {
        return null;
    }

}

That means that this tutorial will need to be updated:

http://platform.netbeans.org/tutorials/nbm-filetype.html

Comments:

Hi Geertjan, I tried the wizard and satisfied with overall result. But on the 2nd step of creating new Abc file wizard, the dialog window title is "New AbcTemplate.abc".

Can we change this default title into something more informative, like, "New Abc Diagram"? And I'd like to put a location restraint for newly crreated file to be a certain folder. Do we have to create our own Wizard?

Posted by Dimas Danurwenda on March 14, 2013 at 06:19 AM PDT #

Hi Mr Geertjan Wielenga. Your example only works if and only if I replace "extension = {".abc", ".ABC"}" by "extension = {"abc", "ABC"}". Best regards.

Posted by Julien Gouesse on May 02, 2013 at 07:55 AM PDT #

How do I create a .java MultiViewEditor? Thanks :-)

Posted by cafreitas on June 19, 2013 at 10:09 AM 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

Archives
« April 2014
SunMonTueWedThuFriSat
  
12
13
14
24
25
26
27
28
29
30
   
       
Today