blob: 82ffe615a48eb87af4c83f7096577be14e037b8b [file] [log] [blame]
//
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
//
= NetBeans Platform HTML Editor
:jbake-type: platform_tutorial
:jbake-tags: tutorials
:jbake-status: published
:syntax: true
:source-highlighter: pygments
:toc: left
:toc-title:
:icons: font
:experimental:
:description: NetBeans Platform HTML Editor - Apache NetBeans
:keywords: Apache NetBeans Platform, Platform Tutorials, NetBeans Platform HTML Editor
This tutorial provides a very simple and quick introduction to the NetBeans Platform workflow by walking you through the creation of a simple HTML Editor. Though simple to create, the HTML Editor you create will be a mature application because it will reuse the infrastructure provided by the NetBeans Platform, as well as several modules from NetBeans IDE. For example, without any coding, your HTML Editor will have a mature window system, which it reuses from the NetBeans Platform. Once you are done with this tutorial, you will have a general understanding of how to create, build, and run applications on top of the NetBeans Platform.
After you finish this tutorial, you can move on to the link:https://netbeans.apache.org/kb/docs/platform.html[NetBeans Platform learning trail]. The learning trail provides comprehensive tutorials that highlight a wide range of NetBeans APIs for a variety of application types. If you do not want to do a "Hello World" application, you can skip this tutorial and jump straight to the learning trail.
NOTE: This document uses the NetBeans IDE 6.9 Release. If you are using an earlier version, see link:68/nbm-htmleditor.html[the previous version of this document]. If this is your first encounter with the NetBeans Platform, you are recommended to work through the link:nbm-quick-start.html[NetBeans Platform Quick Start] before continuing with this one. If, instead of learning how to create a NetBeans Platform application, you would like to learn how to create a NetBeans plugin, see the link:nbm-google.html[NetBeans Plugin Quick Start].
Optionally, for troubleshooting purposes, you can link:http://plugins.netbeans.org/PluginPortal/faces/PluginDetailPage.jsp?pluginid=6635[download the completed sample] and inspect the sources.
At the end of this tutorial, you will have an HTML Editor that looks like this:
image::images/htmleditor_html-editor-65.png[]
NOTE: Although this a very simple demo application, it is not a toy! It is a _real_ program that supports easy editing of HTML pages, with features such as code completion, validation, and predefined HTML snippets.
The HTML Editor that you create in this tutorial is a rich-client application built "on top of the NetBeans Platform". What this means is that the core of the IDE, which is what the NetBeans Platform _is_, will be the base of your application. On top of the NetBeans Platform, you add the modules that you need and exclude the ones that the IDE needs but that your application doesn't. Here you see some of the IDE's modules, added to the NetBeans Platform, which is its base:
image::images/htmleditor_diagram.png[]
Creating this HTML Editor means generating an application skeleton, excluding the modules and user interface items that you do not need, and then setting the NetBeans IDE's Favorites window as the window that will open by default when the IDE starts. The Favorites window will be rebranded so that it will be a browser for HTML documents. All of these activities are supported by user interface elements in the IDE, as you will learn in this tutorial.
You will see for yourself how simple and easy it is to build, or to be more precise, to _assemble_ a full-featured application on top of the NetBeans Platform. At the end, you are shown how to make the final product easily downloadable and launchable using WebStart.
NOTE: Even though it is a separate product, there is no need to download the NetBeans Platform separately for purposes of this tutorial. You will develop the rich-client application in the IDE and then exclude the modules that are specific to the IDE but that are superfluous to you application.
== Generating the Skeleton Application
When creating an application on the NetBeans Platform, the very first step is to create a NetBeans Platform Application project. The default NetBeans Platform Application project includes _all_ the modules included in the NetBeans Platform as well as _all_ the modules included in NetBeans IDE. Since we do not need all these modules, we will exclude those that we do not need.
[start=1]
1. Using the New Project wizard (Ctrl-Shift-N), create a NetBeans Platform Application Project from the template in the NetBeans modules category, as shown below:
image::images/htmleditor_new-nb-app-wiz-65.png[]
Click Next and name the NetBeans Platform Application project "NetBeansHTMLEditor". Click Finish.
[start=2]
1. We'll start by using the IDE to brand our new application. Right-click the project node, choose Branding, and then make a few changes in the Branding Editor:
* In the Basic panel, make sure that you like the application title for the titlebar, as shown below:
image::images/htmleditor_html-editor-prop-1-69.png[]
* In the Splash Screen panel, notice that you can provide the application's splash screen, and progress bar brandings, as shown below:
image::images/htmleditor_html-editor-prop-2-69.png[]
NOTE: If you do not have a splash screen, use link:images/htmleditor_splash.gif[this one]
.
[start=3]
1. Now that the application has been branded, let's make sure that the modules we need for our HTML editor are available to the application. Right-click the project node, choose Properties, and then go to the Libraries panel in the Project Properties dialog box. Here you see a list of "clusters". A cluster is a collection of related modules. The only clusters that need to be selected are ``ide`` and ``platform`` , as shown below:
image::images/htmleditor_libraries-cust-1-69.png[]
Next, click the "Resolve" button and the required modules will be added to the set of modules needed by modules that you have already selected to be part of the application. The "Resolve" button disappears and no red error messages should remain:
image::images/htmleditor_libraries-cust-2-69.png[]
Now you have the subset of NetBeans modules that are relevant to your HTML Editor. However, even though you need the modules that you now have, you probably do not need all of the user interface elements that these modules give you. In the next sections, you tweak the user interface and customize the window layout specifically for the HTML Editor that you are creating.
== Tweaking the User Interface
You can keep or reject as much of the user interface that your selected modules give you. For example, your HTML Editor probably does not need any or all of the items under the Tools menu. Similarly, maybe there are toolbars or toolbar buttons that you can do without. In this section, you prune the IDE's user interface until you are left with a subset that is useful to your specific rich-client application.
[start=1]
1. Expand the NetBeans Platform Application project, right-click the Modules node and choose Add New, as shown below:
image::images/htmleditor_add-module-69.png[]
The New Project wizard (Ctrl-Shift-N) appears.
[start=2]
1. Name the project ``BrandingModule`` . Click Next.
[start=3]
1. In the Code Name Base field, type ``org.netbeans.brandingmodule`` .
[start=4]
1. Click "Generate XML Layer" and then click Finish.
[start=5]
1. In the branding module, expand the Important Files node and then expand the ``layer.xml`` node. Two subnodes are exposed:
image::images/htmleditor_expanded-xml-layer-69.png[]
[start=6]
1. In the ``<this layer in context>`` node, the IDE shows you a merged view of all folders and files that all modules register in their layers. To exclude items, you can right-click them and choose 'Delete', as shown below:
image::images/htmleditor_this-layer-in-context-69.png[]
The IDE then adds tags to the module's ``layer.xml`` file which, when the module is installed, hides the items that you have deleted. For example, by right-clicking within ``Menu Bar/Edit`` , you can remove menu items from the Edit menu that are not necessary for the HTML Editor. By doing this, you generate snippets such as the following in the ``layer.xml`` file:
[source,xml]
----
<folder name="Menu">
<folder name="Edit">
<file name="org-netbeans-modules-editor-MainMenuAction$StartMacroRecordingAction.instance_hidden"/>
<file name="org-netbeans-modules-editor-MainMenuAction$StopMacroRecordingAction.instance_hidden"/>
</folder>
</folder>
----
The result of the above snippet is that the ``Start Macro Recording`` and ``Stop Macro Recording`` actions provided by another module are removed from the menu by your branding module. To show them again, simply delete the tags above from the ``layer.xml`` file.
[start=7]
1. Use the approach described in the previous step to hide as many toolbars, toolbar buttons, menus, and menu items as you want. When you have completed this stage, look in the ``layer.xml`` file. When you do so, you should see something similar to the following, depending on the items that you have deleted:
[source,xml]
----
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE filesystem PUBLIC "-//NetBeans//DTD Filesystem 1.1//EN" "https://netbeans.org/dtds/filesystem-1_1.dtd">
<filesystem>
<folder name="Menu">
<file name="BuildProject_hidden"/>
<folder name="File">
<file name="Separator2.instance_hidden"/>
<file name="SeparatorNew.instance_hidden"/>
<file name="SeparatorOpen.instance_hidden"/>
<file name="org-netbeans-modules-project-ui-CloseProject.shadow_hidden"/>
<file name="org-netbeans-modules-project-ui-CustomizeProject.shadow_hidden"/>
<file name="org-netbeans-modules-project-ui-NewFile.shadow_hidden"/>
<file name="org-netbeans-modules-project-ui-NewProject.shadow_hidden"/>
<file name="org-netbeans-modules-project-ui-OpenProject.shadow_hidden"/>
<file name="org-netbeans-modules-project-ui-RecentProjects.shadow_hidden"/>
<file name="org-netbeans-modules-project-ui-SetMainProject.shadow_hidden"/>
<file name="org-netbeans-modules-project-ui-groups-GroupsMenu.shadow_hidden"/>
</folder>
<file name="Refactoring_hidden"/>
<file name="RunProject_hidden"/>
<folder name="Window">
<file name="ViewRuntimeTabAction.shadow_hidden"/>
<file name="org-netbeans-modules-project-ui-logical-tab-action.shadow_hidden"/>
<file name="org-netbeans-modules-project-ui-physical-tab-action.shadow_hidden"/>
</folder>
</folder>
</filesystem>
----
== Tweaking the Window Layout
By using the ``<this layer in context>`` node, you can not only delete existing items, but you can also change their content. For example, the HTML Editor works on HTML files, so in contrast to the regular IDE, which works with Java source files and projects as well, it makes sense to show the ``Favorites`` window in the initial layout.
The definition of the window layout is also described as files in layers, all stored under the ``Windows2`` folder. The files in the ``Windows2`` folder are pseudo-human readable XML files defined by the link:http://bits.netbeans.org/dev/javadoc/org-openide-windows/org/openide/windows/doc-files/api.html[ Window System APIs]. They are quite complex but the good news is that, for purposes of our HTML Editor, it is not necessary to understand them fully, as shown below.
[start=1]
1. In your branding module's ``<this layer in context>`` node, look in ``Windows2/Components`` and ``Windows2/Modes`` for the two files highlighted below and named "favorites.settings" and "favorites.wstcref":
image::images/htmleditor_find-favorites2-61.png[]
The first file defines what the component is going to look like and how it gets created. As this does not need to be changed, there is no need to modify the file. The second is more interesting for your purposes, it contains the following:
[source,xml]
----
<tc-ref version="2.0">
<module name="org.netbeans.modules.favorites/1" spec="1.1" />
<tc-id id="favorites" />
<state opened="false" />
</tc-ref>
----
[start=2]
1. Even though most of the XML is cryptic, there is one line which seems promising—without needing to read any kind of documentation, it seems likely that changing the ``false`` to ``true`` is going to make the component opened by default. Do so now.
[start=3]
1. In a similar way you can change the ``CommonPalette.wstcref`` file so that the Component Palete opens by default.
You should now see that your branding module contains a new file, one for each of the files that you changed. In effect, these files override the ones that you found in the previous steps. These have been automatically registered in your module's ``layer.xml`` file.
== Tweaking the Favorites Window
In the subfolders of a NetBeans Platform Application project's ``branding`` folder, which is visible in the Files window, you can override strings defined in the NetBeans Platform sources. In this section, you override strings that define labels used in the Favorites window. For example, you change the "Favorites" label to "HTML Files", because you will use that window specifically for HTML files.
[start=1]
1. Right-click the project node and choose "Branding", as you did earlier in this tutorial. This time, open the Resource Bundles tab of the Branding Editor, as shown below:
image::images/htmleditor_favorites-branding-1.png[]
[start=2]
1. Type "favorites" in the "Search" field, after which the list of strings filters down to those that contain the entered string, as shown below:
image::images/htmleditor_favorites-branding-2.png[]
[start=3]
1. For each string you want to brand, right-click it in the dialog shown in the previous step and choose "Add To Branding". Then type the new string for the selected item.
Later, when you start up the application, you will see that the texts and labels in the Favorites window have changed to those you have defined. This illustrates that you can take a component from the NetBeans Platform and then brand it to meet your business requirements.
== Running the Application
Running your application is as simple as right-clicking the project node and choosing a menu item.
[start=1]
1. Right-click the application's project node and choose Clean All. When you do this, the "build" folders in the application are removed. By deleting these folders, you reset the application to its default state. For example, changes you made to the positions of the windows, at runtime, are stored within the "build" folder. Deleting this folder means that the windows are opened according to the settings in the application, rather than according to their last saved positions, which are stored automatically whenever the application is exited.
[start=2]
1. Right-click the application's project node and choose Run.
[start=3]
1.
After the application is deployed, you can right-click inside the Favorites window and choose a folder containing HTML files, and then open an HTML file, as shown below:
image::images/htmleditor_html-editor-65.png[]
You now have a complete, functioning, HTML Editor, which you created without typing a single line of Java code.
== Distributing the Application
Choose one of two approaches for distributing your application. If you want to maintain as much control over your application as possible, you will use web start (JNLP) to distribute your application over the web. In this scenario, whenever you want to update the application, you will do so locally and let your end users know about the update, which they will automatically have available next time they start up your application over the web. Alternatively, distribute a ZIP file containing your application. The end users will then have the complete application locally available. You would then distribute updates and new features via the update mechanism, described below.
=== Distributing the Application via a ZIP File
To make your application extendable, you need to let your users install modules to enhance the application's functionality. To do so, your application is already bundling the Plugin Manager.
[start=1]
1. Choose the Tools | Plugins menu item and install some plugins that are useful to your HTML Editor. Browse the link:http://plugins.netbeans.org/PluginPortal/[Plugin Portal] to find some suitable ones. This is also how your end users will update their local installation of your application.
[start=2]
1. Right-click the application's project node and choose Build ZIP Distribution.
[start=3]
1.
In the ``dist`` folder (visible in the Files window), you should now be able to see a ZIP file, as follows:
image::images/htmleditor_unzipped-app-69.png[]
NOTE: The application's launcher is created in the ``bin`` folder, as shown above.
=== Distributing the HTML Editor via the Shared NetBeans Web Start Repository
Instead of distributing a ZIP file, let's prepare for a webstart distribution by finetuning the ``master.jnlp`` file that is generated the first time you start the application via "Run JNLP Application". Even though it does the job, it is not yet ready for distribution. At the very least, you need to change the information section to provide better descriptions and icons.
Another change to the standard JNLP infrastructure is the use of a shared JNLP repository on www.netbeans.org. By default, the JNLP application generated for a suite always contains all its modules as well as all the modules it depends on. This may be useful for intranet usage, but it is a bit less practical for wide internet use. When on the internet, it is much better if all the applications built on the NetBeans Platform refer to one repository of NetBeans modules, which means that such modules are shared and do not need to be downloaded more than once.
There is such a repository for NetBeans 6.9. It does not contain all the modules that NetBeans IDE has, but it contains enough to make non-IDE applications like our HTML Editor possible. To use the repository you only need to modify ``platform.properties`` by adding the correct URL:
[source,java]
----
# share the libraries from common repository on netbeans.org
# this URL is for release69 JNLP files:
jnlp.platform.codebase=http://bits.netbeans.org/6.9/jnlp/
----
As soon as the application is started as a JNLP application, all its shared plug-in modules are going to be loaded from netbeans.org and shared with other applications doing the same.
link:http://netbeans.apache.org/community/mailing-lists.html[Send Us Your Feedback]
== See Also
This concludes the NetBeans HTML Editor Tutorial. For more information about creating and developing applications on the NetBeans Platform, see the following resources:
* link:https://netbeans.apache.org/kb/docs/platform.html[Other Related Tutorials]
* link:https://bits.netbeans.org/dev/javadoc/[NetBeans API Javadoc]