Skip to content

Start for some asciidoc enhancements, incl. links in source code frag… #537

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion netbeans.apache.org/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ task preprocessContentStatics(type: Copy,
into generatedContentDir
filteringCharset 'UTF-8'
includeEmptyDirs false
include "**/*.html.yml", "**/*.md.yml", "**/*.html", "**/*.md", "**/*.asciidoc", "fonts/**", "**/.htaccess", "**/*.xml.gz", "**/*.txt"
include "**/*.html.yml", "**/*.md.yml", "**/*.html", "**/*.md", "**/*.asciidoc", "fonts/**", "**/.htaccess", "**/*.xml.gz", "**/*.txt", "**/.jbakeignore"
exclude "/templates/**", "/css/**", "fonts/**", "kb/docs/**/section**"

def mergeList = []
Expand Down
1 change: 1 addition & 0 deletions netbeans.apache.org/src/content/tutorials/inc/.jbakeignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
:syntax: true
:source-highlighter: pygments
:toc: left
:toc-title:
:icons: font
:nb-api-version: dev
:nb-api-base-url: https://bits.netbeans.org/{nb-api-version}/javadoc/
include::module-links.asciidoc[]
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
:nbm-org-openide-io: link:{nb-api-base-url}org-openide-io/overview-summary.html[I/O APIs]
:nbm-org-openide-nodes: link:{nb-api-base-url}org-openide-nodes/overview-summary.html[Nodes API]
:nbm-org-openide-text: link:{nb-api-base-url}org-openide-text/overview-summary.html[Text API]
:nbm-org-openide-util-ui: link:{nb-api-base-url}org-openide-util-ui/overview-summary.html[Utilities API]
:nbm-org-openide-windows: link:{nb-api-base-url}org-openide-windows/overview-summary.html[Window System API]
52 changes: 15 additions & 37 deletions netbeans.apache.org/src/content/tutorials/nbm-xmleditor.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,10 @@
:jbake-type: platform-tutorial
:jbake-tags: tutorials
:jbake-status: published
:syntax: true
:source-highlighter: pygments
:toc: left
:toc-title:
:icons: font
:experimental:
:description: NetBeans XML Editor Extension Module Tutorial - Apache NetBeans
:keywords: Apache NetBeans Platform, Platform Tutorials, NetBeans XML Editor Extension Module Tutorial
include::inc/attributes.asciidoc[]

This tutorial demonstrates how to create a module that extends the functionality offered by one of NetBeans IDE's editors. The IDE has several editors—for example, the XML editor, the Java editor, the JSP editor, and the SQL editor. Normally all the IDE's editors are referred to collectively as the Source Editor. However, each of the editors is distinct—its functionality is targeted at the file type for which it exists.

Expand All @@ -43,14 +39,10 @@ Before you start writing the module, you have to make sure you that your project

=== Creating the Module Project


[start=1]
1. Choose File > New Project (Ctrl+Shift+N). Under Categories, select NetBeans Modules. Under Projects, select Module. Click Next.

[start=2]
1. In the Name and Location panel, type ``ShowXMLStructure`` in the Project Name field. Change the Project Location to any directory on your computer. Click Next.

[start=3]
1. In the Basic Module Configuration panel, type ``org.netbeans.modules.showxmlstructure`` in Code Name Base. Click Finish.

The IDE creates the ``ShowXMLStructure`` 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).
Expand All @@ -61,43 +53,38 @@ The IDE creates the ``ShowXMLStructure`` project. The project contains all of
You will need to subclass several classes that belong to the NetBeans APIs. Each is declared as a module dependency.


[start=1]
1. In the Projects window, right-click the Libraries node and choose Add Module Dependency:

[start=2]
1. Search for each of the following APIs in the Add Module Dependency dialog, select the API, and then click OK to confirm it:

* ``I/O APIs``
* ``Nodes API``
* ``Text API``
* ``Utilities API``
* ``Window System API``
* ``{nbm-org-openide-io}``
* ``{nbm-org-openide-nodes}``
* ``{nbm-org-openide-text}``
* ``{nbm-org-openide-util-ui}``
* ``{nbm-org-openide-windows}``

In the Projects window, you should see the above included in the list of dependencies.

== Coding the Module

In this section, you use the New Action wizard to create a new Java class, which is annotated such that the user will be able to invoke it after right-clicking within the XML Editor.

[start=1]
1. Right-click the project node and choose New > Other. Under Categories, select Module Development. Under Projects, select Action. Click Next.

[start=2]
1. In the Action Type panel, click Conditionally Enabled. Select `` link:http://bits.netbeans.org/dev/javadoc/org-openide-text/org/openide/cookies/EditorCookie.html[EditorCookie]`` . Because of this selection, the Action will be enabled when an EditorCookie is available in the Lookup. That will be the case whenever a document is open in the Source Editor. Click Next.
1. In the Action Type panel, click Conditionally Enabled. Select `` link:{nb-api-base-url}/org-openide-text/org/openide/cookies/EditorCookie.html[EditorCookie]`` . Because of this selection, the Action will be enabled when an EditorCookie is available in the Lookup. That will be the case whenever a document is open in the Source Editor. Click Next.

[start=3]
1. 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.

+
--
Next, select Editor Context Menu Item and then select the ``text/xml`` MIME type.

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.
--

[start=4]
1. In the Name and Location panel, type ``ShowXMLStructureActionListener`` as the Class Name and type ``Show XML Structure`` as the Display Name. Menu items provided by contextual menus do not display icons. Therefore, click Finish and ``ShowXMLStructureActionListener.java`` is added to the package. The content of the file is as follows:

[source,java]
+
[source,java,subs="+attributes,+macros"]
----

package org.netbeans.modules.showxmlstructure;

import java.awt.event.ActionEvent;
Expand All @@ -108,7 +95,7 @@ import org.openide.awt.ActionRegistration;
import org.openide.cookies.EditorCookie;
import org.openide.util.NbBundle.Messages;

@ActionID(
{nb-api-base-url}org-openide-awt/org/openide/awt/ActionID.html[@ActionID](
category = "Edit",
id = "org.netbeans.modules.showxmlstructure.ShowXMLStructureActionListener")
@ActionRegistration(
Expand All @@ -131,13 +118,10 @@ public final class ShowXMLStructureActionListener implements ActionListener {
}
----


[start=5]
1. In the Source Editor, fill out the ``actionPerformed`` method as follows, after reading and understanding the comments in the code:

+
[source,java]
----

@Override
public void actionPerformed(ActionEvent ev) {
// "XML Structure" tab is created in Output Window for writing the list of tags:
Expand Down Expand Up @@ -183,13 +167,11 @@ public void actionPerformed(ActionEvent ev) {
}
----


[start=6]
1. You will need these import statements:

+
[source,java]
----

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.IOException;
Expand All @@ -210,18 +192,14 @@ import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
----


== Building and Installing the Module

In the Projects window, right-click the ``ShowXMLStructure`` project and choose Run.

The module is built and installed in the target IDE or Platform. The target IDE or Platform opens so that you can try out your new module. The default target IDE or Platform is the installation used by the current instance of the development IDE.


[start=1]
1. Open an XML file and right-click anywhere in the Source Editor. Notice the new popup menu item called "Show XML Structure".

[start=2]
1. Choose the menu item and notice that the tag handler prints all the elements and attributes to the Output window (Ctrl-4), which is at at the bottom of the IDE.

link:http://netbeans.apache.org/community/mailing-lists.html[Send Us Your Feedback]
Expand Down