blob: 3cee760435159b0e8cb71416778b9e4a23ae52ca [file] [log] [blame]
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<!-- -*- xhtml -*- -->
<title>File Type Integration Tutorial for NetBeans Platform 6.5</title>
<link rel="stylesheet" type="text/css" href="https://netbeans.org/netbeans.css">
<meta name="AUDIENCE" content="NBUSER">
<meta name="TYPE" content="ARTICLE">
<meta name="EXPIRES" content="N">
<meta name="developer" content="gwielenga@netbeans.org">
<meta name="indexed" content="y">
<meta name="description"
content="A short guide to using the Nodes API.">
<!-- Copyright (c) 2005 Sun Microsystems, Inc. All rights reserved. -->
<!-- Use is subject to license terms.-->
</head>
<body>
<h1>File Type Integration Tutorial</h1>
<p>This tutorial shows you how to write a module that lets the IDE,
or any other application built on the NetBeans Platform, recognize a new file type.
<p><b class="notes">Note:</b> This document uses the NetBeans IDE 6.5 Release. If you
are using NetBeans IDE 6.x, see <a href="60/nbm-filetype.html">the 6.1 version
of this document</a>.
<p><b>Contents</b></p>
<img src="../images/articles/65/netbeans-stamp65.gif" class="stamp" width="114" height="114" alt="Content on this page applies to NetBeans IDE 6.5" title="Content on this page applies to NetBeans IDE 6.5"> </p>
<ul class="toc">
<li><a href="#intro">Introduction to File Type Integration</a></li>
<li><a href="#creating">Creating the Module Project</a></li>
<li><a href="#recognizing">Recognizing Abc Files</a></li>
<li><a href="#install">Installing and Trying Out the Functionality</a></li>
<li><a href="#adding">Creating Features for Abc Files</a></li>
<ul>
<li><a href="#action">Adding an Action</a>
<li><a href="#topcomponent">Opening the File into a Window</a>
<li><a href="#multiview">Creating a Multiview Window</a>
</ul>
<li><a href="#share">Creating a Shareable Binary</a></li>
</ul>
<p><b>To follow this tutorial, you need the software and resources listed in the following
table.</b></p>
<table>
<tbody>
<tr>
<th class="tblheader" scope="col">Software or Resource</th>
<th class="tblheader" scope="col">Version Required</th>
</tr>
<tr>
<td class="tbltd1"><a href="https://netbeans.org/downloads/index.html">NetBeans IDE</a></td>
<td class="tbltd1">version 6.5</td>
</tr>
<tr>
<td class="tbltd1"><a href="http://java.sun.com/javase/downloads/index.jsp">Java Developer Kit (JDK)</a></td>
<td class="tbltd1">Version 6 or<br/>version 5</td>
</tr>
</tbody>
</table>
<h2 class="tutorial"><a name="intro"></a>Introduction to File Type Integration</h2>
<p>File types that are recognized in the IDE have their own icons, menu items, and behavior.
The "files" being shown are <tt>FileObjects</tt>&#8212;wrappers
around <tt>java.io.File</tt> or, in the case of configuration files, typically wrappers around data stored in some other way,
such as inside XML files in modules. What you actually <i>see</i> are <tt>Nodes</tt>, which provide functionality like actions
and localized names to objects like files. In between <tt>Nodes</tt> and <tt>FileObjects</tt> are <tt>DataObjects</tt>.
A <tt>DataObject</tt> is like a <tt>FileObject</tt>, except that it knows what kind of file is being shown, and there are
usually different types of <tt>DataObject</tt> for files with different extensions and XML files with different namespaces.
Each <tt>DataObject</tt> is provided by a different module, each implementing support for one or more file types&#8212;for example,
the Image module makes it possible to recognize and open <tt>.gif</tt> and <tt>.png</tt> files.
<p>A module that recognizes a file type installs a <tt>DataLoader</tt>&#8212;a factory for a file-type-specific <tt>DataObject</tt>.
When a folder is expanded, the IDE asks each known <tt>DataLoader</tt>, "Do you know what this is?" The first one that says
"Yes" creates the <tt>DataObject</tt> for the file. In order to actually display something for each file, the system calls
<tt>DataObject.getNodeDelegate()</tt> for each <tt>DataObject</tt> and the <tt>Nodes</tt> are what you actually see in the IDE.
<p>Below, the diagram on the left shows what each item mentioned above makes available:
<p><p align="left"><img src="../images/tutorials/filetype/diagram-dataobject2.png" alt="Diagram.">
<p>In this tutorial, you create a module that installs a <tt>DataLoader</tt> for imaginary "Abc" files
(<tt>.abc</tt> file extension). By default, a file with the "abc" extension is treated as any other file that
the IDE does not recognize&#8212;it is treated as a text file and, as a result, the IDE provides the same functionality for
Abc files as it does for text files. Once you have created the module, you will be shown how to enhance it
with functionality that will be available to Abc files only. When you complete the development cycle, you can easily let others make use of
your module&#8212;the IDE lets you create a binary that you can send to others, who can then install it through the
Update Center.
<!-- ===================================================================================== -->
<h2 class="tutorial"><a name="creating"></a>Creating the Module Project</h2>
<p>In this section, we use a wizard to create the source structure that every NetBeans module requires. The
source structure consists of certain folders in specific places and a set of files that are
always needed. For example, every NetBeans module requires a <tt>nbproject</tt> folder, which holds
the project's metadata, and a <tt>layer.xml</tt> file, for declarative registration of items
such as toolbar buttons and windows.
<ol>
<li>Choose File &gt; New Project (Ctrl-Shift-N). Under Categories, select NetBeans Modules. Under Projects,
select Module and click Next.</li>
<li>In the Name and Location panel, type <tt>AbcFileType</tt> in Project Name.
Change the
Project Location to any directory on your computer, such as <tt>c:\mymodules</tt>. Leave the Standalone Module radiobutton
selected. The panel should now look as follows:
<p><p align="left"><img src="../images/tutorials/filetype/65-projectwizard1.png" alt="Step 1 of New Project wizard.">
<p>Click Next.
<li>In the Basic Module Configuration panel, type <tt>org.myorg.abcfiletype</tt>
as the Code Name Base.
Add spaces to the suggested Module Display Name, so that it is changed to <tt>Abc File Type</tt>.
Select the "Generate XML Layer" checkbox and
leave the location of the localizing bundle and XML layer as they are,
so that they will be stored in a
package with the name <tt>org/myorg/abcfiletype</tt>. The panel should now look as follows:
<p><p align="left"><img src="../images/tutorials/filetype/65-projectwizard2.png" alt="Step 2 of New Project wizard.">
<li>Click Finish.</ol>
<p> The IDE creates the <tt>Abc File Type</tt>
project. The project contains all of your sources and
project metadata, such as the project's Ant build script. The project
opens in the IDE. You can view its logical structure in the Projects window (Ctrl-1) and its
file structure in the Files window (Ctrl-2). For example, the Projects window should now look as follows:
<p><p align="left"><img src="../images/tutorials/filetype/65-projectswindow1.png" alt="Initial Projects window.">
<br />
<!-- ===================================================================================== -->
<h2><a name="recognizing"></a>Recognizing Abc Files</h2>
<p>In this section, we use a wizard to create the classes necessary for
recognizing Abc files as being distinct from all other files. As discussed
at the start of this tutorial, we need a data object and a data loader, as
well as a MIME type resolver, and registration entries in the <tt>layer.xml</tt> file,
to do so. The New File Type wizard will create all of these for us.
<ol>
<li>Right-click the project node and
choose New &gt; File Type.</li>
<li>In the File Recognition panel, do the following:
<p><ul><li>Type <tt>text/x-abc</tt> in the MIME Type edit box.
<li>Type <tt>.abc .ABC</tt> in the by Filename Extension edit box.</ul>
<p>The File Recognition panel should now look as follows:
<p><p align="left"><img border="1" src="../images/tutorials/filetype/60-filewizard1.png" alt="Step 1 of New File wizard.">
<p>Note the following about the fields in the File Recognition panel:
<ul>
<li><b>MIME Type.</b> Specifies the data object's unique MIME type.
<li>by
<ul><li><b>Filename Extension.</b> Specifies one or more file extensions that the IDE will recognize
as belonging to the specified MIME type. The file extension can optionally be preceded
by a dot. Separators are commas, spaces, or both. Therefore, all of the following are valid:
<p><ul><li><tt>.abc,.def</tt>
<li><tt>.abc .def</tt>
<li><tt>abc def</tt>
<li><tt>abc,.def ghi, .wow</tt></ul>
<p>Let's imagine that Abc files be case-sensitive. For
this reason, you specify <i>two</i> MIME types in this tutorial&#8212;<tt>.abc</tt> and <tt>.ABC</tt>.
<li><b>XML Root Element.</b> Specifies a unique namespace that distinguishes the XML file
type from all other XML file types. Since many XML files have the same extension (<tt>xml</tt>),
the IDE distinguishes between
XML files via their XML root elements. More specifically, the IDE can distinguish between namespaces and
the first XML element in XML files. You can use this to, for example, distinguish
between a JBoss deployment descriptor and a WebLogic deployment descriptor. Once you have made
this distinction, you can ensure that menu items added to the JBoss deployment descriptor's contextual menu
are not available to the WebLogic deployment descriptor. For an example, see
the <a href="nbm-palette-api2.html">NetBeans Component Palette Module Tutorial</a>.
</ul></ul>
<p>Click Next.
<li>In the Name and Location panel, type <tt>Abc</tt> as the Class Name Prefix
and browse to any 16x16 pixel image file as the new file type's icon, as shown below.
<p align="left"><p><p align="left"><img src="../images/tutorials/filetype/65-filewizard2.png" alt="Step 2 of New File wizard.">
<p><b>Note:</b> You can use any icon of a 16x16 pixel dimension. If you like, you can
click on this one and save it locally, and then
specify it in the wizard step above: <img src="../images/tutorials/filetype/Datasource.gif" alt="Datasource.gif">
<li>Click Finish.
<p><p>The Projects window should now look as follows:
<p><p align="left"><img src="../images/tutorials/filetype/65-projectswindow2.png" alt="Final Projects window."></ol>
<p>Each of the newly generated files is briefly introduced:
<ul>
<li><b>AbcDataObject.java.</b> Wraps a <tt>FileObject</tt>. DataObjects are produced by DataLoaders.
For more information, see <a href="http://wiki.netbeans.org/wiki/view/DevFaqDataObject">What is a DataObject?</a>.
<li><b>AbcResolver.xml.</b> Maps the <tt>.abc</tt> and <tt>.ABC</tt> extensions to the MIME type. The <tt>AbcDataLoader</tt> only
recognizes the MIME type; it does not know about the file extension.
<li><b>AbcTemplate.abc.</b> Provides the basis of a file template that is registered
in the <tt>layer.xml</tt> such that it will be installed in the New File dialog
as a new template.
<li><b>AbcDataObjectTest.java.</b> JUnit test class for the <tt>DataObject</tt>.
</ul>
</p>
<p>In the <tt>layer.xml</tt> file, you should see the following:
<pre>&lt;folder name="Loaders"&gt;
&lt;folder name="text"&gt;
&lt;folder name="x-abc"&gt;
&lt;folder name="Actions"&gt;
&lt;file name="org-myorg-abcfiletype-MyAction.shadow"&gt;
&lt;attr name="originalFile" stringvalue="Actions/Edit/org-myorg-abcfiletype-MyAction.instance"/&gt;
&lt;attr name="position" intvalue="600"/&gt;
&lt;/file&gt;
&lt;file name="org-openide-actions-CopyAction.instance"&gt;
&lt;attr name="position" intvalue="100"/&gt;
&lt;/file&gt;
&lt;file name="org-openide-actions-CutAction.instance"&gt;
&lt;attr name="position" intvalue="200"/&gt;
&lt;/file&gt;
&lt;file name="org-openide-actions-DeleteAction.instance"&gt;
&lt;attr name="position" intvalue="300"/&gt;
&lt;/file&gt;
&lt;file name="org-openide-actions-FileSystemAction.instance"&gt;
&lt;attr name="position" intvalue="400"/&gt;
&lt;/file&gt;
&lt;file name="org-openide-actions-OpenAction.instance"&gt;
&lt;attr name="position" intvalue="500"/&gt;
&lt;/file&gt;
&lt;file name="org-openide-actions-PropertiesAction.instance"&gt;
&lt;attr name="position" intvalue="700"/&gt;
&lt;/file&gt;
&lt;file name="org-openide-actions-RenameAction.instance"&gt;
&lt;attr name="position" intvalue="800"/&gt;
&lt;/file&gt;
&lt;file name="org-openide-actions-SaveAsTemplateAction.instance"&gt;
&lt;attr name="position" intvalue="900"/&gt;
&lt;/file&gt;
&lt;file name="org-openide-actions-ToolsAction.instance"&gt;
&lt;attr name="position" intvalue="1000"/&gt;
&lt;/file&gt;
&lt;file name="sep-1.instance"&gt;
&lt;attr name="instanceClass" stringvalue="javax.swing.JSeparator"/&gt;
&lt;attr name="position" intvalue="1100"/&gt;
&lt;/file&gt;
&lt;file name="sep-2.instance"&gt;
&lt;attr name="instanceClass" stringvalue="javax.swing.JSeparator"/&gt;
&lt;attr name="position" intvalue="1200"/&gt;
&lt;/file&gt;
&lt;file name="sep-3.instance"&gt;
&lt;attr name="instanceClass" stringvalue="javax.swing.JSeparator"/&gt;
&lt;attr name="position" intvalue="1300"/&gt;
&lt;/file&gt;
&lt;file name="sep-4.instance"&gt;
&lt;attr name="instanceClass" stringvalue="javax.swing.JSeparator"/&gt;
&lt;attr name="position" intvalue="1400"/&gt;
&lt;/file&gt;
&lt;/folder&gt;
&lt;folder name="Factories"&gt;
&lt;file name="AbcDataLoader.instance"&gt;
&lt;attr name="SystemFileSystem.icon" urlvalue="nbresloc:/org/myorg/abcfiletype/Datasource.gif"/&gt;
&lt;attr name="dataObjectClass" stringvalue="org.myorg.abcfiletype.AbcDataObject"/&gt;
&lt;attr name="instanceCreate" methodvalue="org.openide.loaders.DataLoaderPool.factory"/&gt;
&lt;attr name="mimeType" stringvalue="text/x-abc"/&gt;
&lt;/file&gt;
&lt;/folder&gt;
&lt;/folder&gt;
&lt;/folder&gt;
&lt;/folder&gt;</pre>
<br />
<!-- ======================================================================================= -->
<h2><a name="install"></a>Installing and Trying Out the Functionality</h2>
<p>Let's now install the module and then use the basic
functionality we've created so far.
The IDE uses an Ant build script to build and install your module. The build
script is created for you
when you create the project.</p>
<div class="indent">
<ol>
<li>In the Projects window, right-click the <tt>Abc File Type</tt> project and choose Run.
<p><p>A new instance of the IDE starts, installing your module into itself.
<li>Use the New Project dialog (Ctrl-Shift-N)
to create any kind of application in the IDE.
<li>Right-click the application node and choose New &gt; Other. In the Other
category, a template is available for working with the new file type:
<p><p align="left"><img border="1" src="../images/tutorials/filetype/60-action4.png" alt="Dummy template."></p>
<p>Complete the wizard and you will have created a template that
can be used for starting off the user's work with the given file type.</p>
<p class="tips">If you want to provide default code via the template, add the code to the
<tt>AbcTemplate.abc</tt> file that the New File Type wizard created for you.
</ol>
</div>
<br />
<!-- ===================================================================================== -->
<h2><a name="adding"></a>Creating Features for Abc Files</h2>
<p>Now that the NetBeans Platform is able to distinguish Abc files from all other types of files,
it is time to add features specifically for these types of files. In this section, we add a menu
item on the right-click contextual menu of the file's node in the explorer windows, such as in
the Projects window, and we enable the file to open into a window, instead of into an editor.
<div class="indent">
<h3 class="tutorial"><a name="action"></a>Adding an Action</h3>
<p>In this subsection, we use the New Action wizard to create a Java class that
will perform an action for our file type. The wizard will also register the class
in the <tt>layer.xml</tt> file such that the user will be able to invoke the
action from the right-click contextual menu of the file type's node in an explorer window.
<ol>
<li>Right-click the project node and
choose New &gt; Action.</li>
<li>In the Action Type panel, click Conditionally Enabled. Type <tt>AbcDataObject</tt>, which
is the name of the data object generated above by the New File Type wizard, as shown below:
<p><p align="left"><img border="1" src="../images/tutorials/filetype/60-action1.png" alt="Step 1 of New Action wizard.">
<p>Click Next.
<li>In the GUI Registration panel, select the 'Edit' category in the Category drop-down list.
The Category drop-down list controls where an action is shown in the Keyboard Shortcuts editor in the IDE.
<p><p>Next, Unselect Global Menu Item and then select File Type Contect Menu Item.
In the Content Type drop-down list, select the MIME type you specified above in the New File Type
wizard, as shown below:
<p align="left"><p><p align="left"><img border="1" src="../images/tutorials/filetype/60-action2.png" alt="Step 2 of New Action wizard.">
<p>Notice that you can set the position of the menu item and that you
can separate the menu item from the item before it and after it. Click Next.
<li>In the Name and Location panel, type <tt>MyAction</tt> as the Class Name
and type <tt>My Action</tt> as the Display Name. Menu items provided by contextual menus
do not display icons. Therefore, click Finish and <tt>MyAction.java</tt> is added to the <tt>org.myorg.abcfiletype</tt> package.
<li>In the Source Editor, add some code to the action's <tt>performAction</tt> method:
<pre class="examplecode">protected void performAction(Node[] activatedNodes) {
AbcDataObject abcDataObject = activatedNodes[0].getLookup().lookup(AbcDataObject.class);
FileObject f = abcDataObject.getPrimaryFile();
String displayName = FileUtil.getFileDisplayName(f);
String msg = "I am " + displayName + ". Hear me roar!";
NotifyDescriptor nd = new NotifyDescriptor.Message(msg);
DialogDisplayer.getDefault().notify(nd);
}</pre>
<p>Press Ctrl-Shift-I. The IDE automatically adds import statements to the top of the class.</p>
<p class="tips">Some code
is still underlined in red, to indicate that not all of the required packages are on the classpath.
Right-click the project node, choose Properties, and click Libraries in the Project Properties dialog box.
Click add at the top of the Libraries pane and add the Dialogs API.</p>
<p>In the <tt>MyAction.java</tt> class, press Ctrl-Shift-I again. The red underlining disappears because
the IDE finds the required packages in the Dialogs API.</p>
<li>In the Important Files node, expand XML Layer. The two nodes <tt>&lt;this layer&gt;</tt> and <tt>&lt;this layer in context&gt;</tt>,
together with their subnodes, make up the <a href="https://platform.netbeans.org/tutorials/nbm-glossary.html">System Filesystem</a> Browser. Expand <tt>&lt;this layer&gt;</tt>, expand <tt>Loaders</tt>,
continue expanding nodes until you see the <tt>Action</tt> that you created above.
<li>Drag-and-drop <tt>My Action</tt> so that it appears below the <tt>Open</tt> action, as shown below:
<p align="left"><p><p align="left"><img border="1" src="../images/tutorials/filetype/60-action3.png" alt="System Filesystem Browser.">
<p>As you can see from the last two steps, the System Filesystem Browser can be used to quickly reorganize
the sequence of the items that are registered in the System Filesystem.
<li>Run the module again, as you did in the previous section.
<li>Create an ABC file, using the template shown
in the previous section, and right-click the file's node in one of the
explorer views, such as in the Projects window or Favorites window.
<p><p>Notice that the Abc file has the icon
you assigned to it in its module and that the list of actions defined in its <tt>layer.xml</tt> file
is available from the right-click contextual menu:
<p><p align="left"><img border="1" src="../images/tutorials/filetype/60-dummytemplate.png" alt="Final Projects window.">
<li>Choose the new menu item, the Abc file's name and location are shown:
<p><p align="left"><img border="1" src="../images/tutorials/filetype/60-information.png" alt="Information.">
</ol>
<p>You now know how to create a new action that appears in the context
menu of a file of the given type, in the Projects window, Files window
or the Favorites window.</p>
<h3 class="tutorial"><a name="topcomponent"></a>Opening the File into a Window</h3>
<p>By default, when the user opens a file of the type that we have defined in this tutorial,
the file will open into a basic editor. However, sometimes you may want to create a visual
representation of the file, and let the user drag and drop widgets onto the visual representation.
The first step in creating such a user interface is to let the user open the file into a window.
This subsection shows you how to do that.
<ol>
<li>Right-click the project node and
choose New &gt; Window Component. Set "editor" for Window Position
and "Open on Application Start", as shown below:
<p><p><p align="left"><img src="../images/tutorials/filetype/65-topc-1.png" alt="Step 1 of New Action wizard.">
<li>Click Next and type "Abc" as the Class Name Prefix:
<p><p><p align="left"><img src="../images/tutorials/filetype/65-topc-2.png" alt="Step 1 of New Action wizard."></p>
<p>Click Finish.</p>
</li>
<li>Change the <tt>DataObject</tt> to use <tt><a href="http://bits.netbeans.org/dev/javadoc/org-openide-loaders/org/openide/loaders/OpenSupport.html">OpenSupport</a></tt> instead of DataEditorSupport,
by changing the <tt>DataObject's</tt> constructor as follows:
<p><pre>public AbcDataObject(FileObject pf, MultiFileLoader loader)
throws DataObjectExistsException, IOException {
super(pf, loader);
CookieSet cookies = getCookieSet();
<b>//cookies.add((Node.Cookie) DataEditorSupport.create(this, getPrimaryEntry(), cookies));
cookies.add((Node.Cookie) new AbcOpenSupport(getPrimaryEntry()));</b>
}</pre>
<li>Create the <tt><a href="http://bits.netbeans.org/dev/javadoc/org-openide-loaders/org/openide/loaders/OpenSupport.html">OpenSupport</a></tt> class:
<p><pre>class AbcOpenSupport extends OpenSupport implements OpenCookie, CloseCookie {
public AbcOpenSupport(AbcDataObject.Entry entry) {
super(entry);
}
protected CloneableTopComponent createCloneableTopComponent() {
AbcDataObject dobj = (AbcDataObject) entry.getDataObject();
AbcTopComponent tc = new AbcTopComponent();
tc.setDisplayName(dobj.getName());
return tc;
}
}</pre>
<p class="tips">Tweak the TopComponent to extend CloneableTopComponent,
instead of TopComponent. Set the TopComponent's class modifier, and its
constructor's modifier, to public instead
of private.
</ol>
<p>Run the module again and then,
when an Abc file is opened, the <tt>OpenSupport</tt> class handles the
opening, such that it opens the file into the <tt>TopComponent</tt> instead
of the basic editor that <tt>DataEditorSupport</tt> provides:
<p><p align="left"><img src="../images/tutorials/filetype/65-topc-3.png" alt="Step 1 of New Action wizard."></p>
<p class="tips">The <a href="https://platform.netbeans.org/tutorials/nbm-visual_library.html">NetBeans Visual Library Tutorial</a>
provides an example of what you can do
to develop the TopComponent further such that
it will visually display the content of a file
that corresponds to the file type defined in this tutorial.</p>
<br />
<!-- ======================================================================================= -->
<h3><a name="multiview"></a>Creating a Multiview Window</h3>
<p>Now that we are able to open a file into a window, let's make the window
more interesting. We'll create a multiview window. The first tab of
a multiview window is typically used to display a visual representation
of the file, while the second tab typically shows the source view. More
than two tabs can also be provided, each tab providing further levels
of detail about the opened file.
<ol>
<li>Right-click the project node and choose Properties. In the Project
Properties dialog, choose Libraries, and click Add.
Set a dependency on "MultiView Windows". Click OK and then
click OK again to exit the Project Properties dialog.
<li><p>For each tab that you want to create in the multiview window, create a class that
implements <tt>MultiViewDescription</tt> and <tt>Serializable</tt>.</p><p>For
purposes of this tutorial, start by creating a class called
<tt>AbcMultiviewDescription1</tt>, implementing the specified classes:</p>
<pre>public class AbcMultiviewDescription1 implements MultiViewDescription, Serializable {
public int getPersistenceType() {
throw new UnsupportedOperationException("Not supported yet.");
}
public String getDisplayName() {
throw new UnsupportedOperationException("Not supported yet.");
}
public Image getIcon() {
throw new UnsupportedOperationException("Not supported yet.");
}
public HelpCtx getHelpCtx() {
throw new UnsupportedOperationException("Not supported yet.");
}
public String preferredID() {
throw new UnsupportedOperationException("Not supported yet.");
}
public MultiViewElement createElement() {
throw new UnsupportedOperationException("Not supported yet.");
}
}</pre>
<p class="tips">In the <tt>AbcMultiviewDescription1</tt> class above,
the method <tt>createElement()</tt> returns a MultiViewElement.
What you want to return here is your <tt>TopComponent</tt>, which
we will do in the next step.</p>
<li>Rewrite the class signature. To provide a multiview element for
the description in the previous step, we need to extend <tt>JPanel</tt>
instead of <tt>TopComponent</tt> and we need to implement
<tt>MultiViewElement</tt>:
<pre>public final class AbcTopComponent extends JPanel implements MultiViewElement {</pre>
<p>In the <tt>TopComponent</tt>, you now need to delete (or comment out) the methods
<tt>findInstance()</tt>, <tt>getPersistenceType()</tt>, <tt>writeReplace()</tt>
and <tt>preferredID()</tt>.
<li>For the moment, provide very simple
implementations of each of the required methods. Start by defining
a new <tt>JToolbar</tt> at the top of the <tt>TopComponent</tt> class:
<pre>private JToolBar toolbar = new JToolBar();</pre>
<p>Next, implement the methods as follows:
<pre> public JComponent getVisualRepresentation() {
return this;
}
public JComponent getToolbarRepresentation() {
return toolbar;
}
public void setMultiViewCallback(MultiViewElementCallback arg0) {
}
public CloseOperationState canCloseElement() {
return null;
}
public Action[] getActions() {
return new Action[]{};
}
public Lookup getLookup() {
return Lookups.singleton(this);
}
public void componentShowing() {
}
public void componentHidden() {
}
public void componentActivated() {
}
public void componentDeactivated() {
}
public UndoRedo getUndoRedo() {
return UndoRedo.NONE;
}</pre>
<li>Now you can redefine the <tt>AbcMultiviewDescription1</tt> as follows:
<pre>public class AbcMultiviewDescription1 implements MultiViewDescription, Serializable {
public int getPersistenceType() {
return TopComponent.PERSISTENCE_ALWAYS;
}
public String getDisplayName() {
return "Tab 1";
}
public Image getIcon() {
return ImageUtilities.loadImage("/org/myorg/abcfiletype/Datasource.gif");
}
public HelpCtx getHelpCtx() {
return null;
}
public String preferredID() {
return "AbcMultiviewDescription1";
}
public MultiViewElement createElement() {
return new AbcTopComponent();
}
}</pre>
<li>Change the <tt>createCloneableTopComponent</tt> method in the
<tt>OpenSupport</tt> class to open your <tt>TopComponent</tt>
via the <tt>MultiViewDescription</tt> class you created above:
<pre>protected CloneableTopComponent createCloneableTopComponent() {
// Create an array of multiview descriptors:
AbcMultiviewDescription1 firstTab = new AbcMultiviewDescription1();
MultiViewDescription[] descriptionArray = { firstTab };
// Create the multiview window:
CloneableTopComponent tc = MultiViewFactory.createCloneableMultiView(descriptionArray, firstTab, null);
tc.setDisplayName(entry.getDataObject().getName());
return tc;
}</pre>
<p class="tips">The second argument
in <tt>MultiViewFactory.createCloneableMultiView</tt> determines which of
the tabs is open by default. Here it is <tt>firstTab</tt>, the tab defined by
<tt>AbcMultiViewDescription1</tt>.</p>
<li><p>Install and open the file again. Now you have a multiview window with one tab:</p>
<p><img border="1" src="../images/tutorials/filetype/65-mvdeployed.png" alt="multiview deployed">
</ol>
<p>You now have a single tab in a multiview window. For each additional tab,
create a new <tt>MultiviewDescription</tt> class, with a new <tt>JPanel</tt>,
and then instantiate the <tt>MultiViewDescription</tt> class in the
<tt>OpenSupport</tt> extension class, as shown above.
</div>
<!-- ======================================================================================= -->
<h2><a name="share"></a>Creating a Shareable Module Binary</h2>
<p>Now that the module is complete, you can let others use it. To do so, you
need to create a binary "NBM" (NetBeans module) file and distribute it.
<div class="indent">
<ol>
<li>In the Projects window, right-click the <tt>Abc File Type</tt> project and choose Create NBM.
<p><p>The NBM file is created and you can view it in the Files window (Ctrl-2):
<p><p align="left"><img border="1" src="../images/tutorials/filetype/60-shareable-nbm.png" alt="Shareable NBM.">
<li>Make it available to others via, for example, the
<a href="http://plugins.netbeans.org/PluginPortal/">NetBeans Plugin Portal</a>.
The recipient should
use the Plugin Manager (Tools &gt; Plugins) to install it.
</ol>
</div>
<!-- ======================================================================================== -->
<br>
<div class="feedback-box"><a href="https://netbeans.org/about/contact_form.html?to=3&amp;subject=Feedback:%20File%20Type%20Module%20Tutorial">Send Us Your Feedback</a></div>
<br style="clear:both;" />
<!-- ======================================================================================== -->
<h2><a name="nextsteps"></a>Next Steps</h2>
<p>For more information about creating and developing NetBeans modules, see the following resources:
<ul>
<li><a href="https://platform.netbeans.org/index.html">NetBeans Platform Homepage</a></li>
<li><a href="https://netbeans.org/download/dev/javadoc/">NetBeans API List (Current Development Version)</a></li>
<li><a href="https://netbeans.org/kb/trails/platform.html">Other Related Tutorials</a></li></ul>
</p>
<!-- ======================================================================================== -->
<!--
<h2><a name="version"></a>Versioning </h2>
<p>
<table width="76%" >
<tbody>
<tr>
<td>
<div align="left"><b>Version</b></div>
</td>
<td>
<div align="left"><b>Date</b></div>
</td>
<td>
<div align="left"><b>Changes</b></div>
</td>
</tr>
<tr>
<td>
1
</td>
<td>
25 August 2005
</td>
<td>
<ul><li>Initial version.
<li>To do:
<ul><li>Add post-creation customizations (i.e., the "Extending Support for the New File Type" section).
<li>Explain what the generated files are for (placeholders currently).
<li>Explain the layer file's entries.
<li>Explain the first File Type panel (placeholders currently).
<li>Maybe create a separate tutorial for recognizing XML files.</ul></ul>
</td>
</tr>
<tr>
<td>
2
</td>
<td>
23 September 2005
</td>
<td>
<ul><li>A lot of info added from the FAQ and added the Action wizard and System Filesystem Browser.
<li>To do:
<ul><li>Explain <tt>LoaderBeanInfo.java</tt> and <tt>Resolver.xml</tt> (one line each)
<li>Maybe create a separate tutorial for recognizing XML files.
<li>Using Tomcat GIF maybe not good idea.
<li>Maybe the action should do something useful.
<li>Maybe direct links to FAQ not good idea.
<li>Probably more needed on <tt>layer.xml</tt> file.
<li>Maybe other useful apisupport functionality could be added to this scenario.
<li>More info needed on MIME types.
<li>The introductory paragraphs should be illustrated with a graphic. A diagram to
show relationship between node, dataobject, fileobject, dataloader, etc.</ul></ul>
</td>
</tr>
<tr>
<td>
3
</td>
<td>
28 September 2005
</td>
<td>
<ul><li>Integrated comments from Jesse Glick.
<li>To do:
<ul> <li>More info needed on MIME types.
<li>The introductory paragraphs should be illustrated with a graphic. A diagram to
show relationship between node, dataobject, fileobject, dataloader, etc.
<li>Many Javadoc links to be added (also for <tt>performAction</tt>.
<li>Info on cookies, cookie actions, cookie classes needed.
<li>Action ended up in text-html even though I chose my own mime type.
<li>Need to explain or link to explanation for instance, shadow, etc.
<li>Platform Manager needs to be mentioned in the context of installing
in target platform.
<li>Show how to add properties to the property sheet.</ul></ul>
</td>
</tr>
<tr>
<td>
4
</td>
<td>
4 October 2005
</td>
<td>
<ul><li>Added two diagrams in the introductory paragraphs, from Tim Boudreau's JavaOne presentation.
<li>To do:
<ul> <li>More info needed on MIME types.
<li>Many Javadoc links to be added (also for <tt>performAction</tt>).
<li>Need to create section near the start: "Related FAQs":
<ul><li>Info on cookies, cookie actions, cookie classes needed.
<li>Need to explain or link to explanation for instance, shadow, etc.
<li>DataLoader, DataObject, etc.</ul>
<li>Platform Manager needs to be mentioned in the context of installing
in target platform.
<li>Show how to add properties to the property sheet.
<li>Mention the dummy template that you get, how to modify it,
and how to set the description in the New File wizard.</ul></ul>
</td>
</tr>
<tr>
<td>
4
</td>
<td>
4 November 2005
</td>
<td>
<ul><li>Added downloadable source code, new 'Installing the Sample' section, and link to
Syntax Highlighting tutorial at the end.
<li>To do:
<ul> <li>Same items as on 4 October still to be done.</ul>
</td>
</tr>
<tr>
<td>
5
</td>
<td>
29 November 2005
</td>
<td>
<ul><li>Added links to brand new Component Palette tutorial.
<li>To do:
<ul> <li>Same items as on 4 October still to be done.</ul>
</td>
</tr>
<tr>
<td>
6
</td>
<td>
21 April 2006
</td>
<td>
<ul><li>Changed the title from "DataLoader Module Tutorial" to "Recognizing a File Type Tutorial".
<li>To do:
<ul> <li>Same items as on 4 October still to be done.</ul>
</td>
</tr>
<tr>
<td>
7
</td>
<td>
17 November 2007
</td>
<td>
<ul><li>Updated the whole tutorial to 6.0, replaced all screenshots, and
now [because the 6.0 IDE already provides support for manifest files], the
tutorial focuses on imaginary Abc files.
<li>To do:
<ul> <li>Need to replace the download, which is the same as before, dealing with manifest files.
<li>Same items as on 4 October still to be done.
<li>Added OpenSupport into TopComponent, with a reference to Visual Library.</ul>
<li>Changed title to File Type Integration Tutorial
<li>Tweaked several places throughout tutorial, for 6.0
</td>
</tr>
<tr>
<td>
8
</td>
<td>
15 April 2008
</td>
<td>
Updated the styles (badge, table of contents, required software table)
to the new format.
</td>
</tr>
<tr>
<td>
9
</td>
<td>
16 July 2008
</td>
<td>
Created new version for 6.5, because of changes to the
way file type recognition is done in that release. To do:
<ul>
<li>6.5-specific badge
<li>Required software table
<li>Search for DataNode, BeanInfo, DataLoader and reword
<li>Check screenshots
<li>Make sure all the sections work as before
</ul>
</td>
</tr>
<tr>
<td>
10
</td>
<td>
4 April 2009
</td>
<td>
Worked through everything and added the multiview section.
</td>
</tr>
</tbody>
</table>
-->
</body>
</html>