juanotto commented on code in PR #23:
URL:
https://github.com/apache/netbeans-antora-tutorials/pull/23#discussion_r2476400875
##########
modules/ROOT/pages/tutorials/nbm-selection-1.adoc:
##########
@@ -503,146 +503,160 @@ import org.openide.util.NbBundle;
import org.openide.util.lookup.Lookups;
import org.openide.windows.TopComponent;
----
-
-The line `associateLookup(Lookups.singleton(obj));` will create a `Lookup`
that contains only one object - the new instance of `Event` - and assign that
`Lookup` to be what is returned by `MyEditor.getLookup()`. While this is an
artificial example, you can imagine how `Event` might represent a file, an
entity in a database, or anything else you might want to edit or view. Probably
you can also imagine one component that allows you to select or edit multiple
unique instances of `Event`, which will be the subject of the next tutorial.
-
-To make your editor component at least somewhat interesting (though it doesn't
actually edit anything), you set the text fields' values to values from the
`Event`, so you have something to display.
++
+The line `associateLookup(Lookups.singleton(obj));` creates a `Lookup`
containing one object - the new `Event` instance.
+This becomes what `MyEditor.getLookup()` returns. While this is a simple
example, you can imagine `Event` representing a
+file, database entity, or anything else you want to edit or view. You could
also have a component that lets you select
+or edit multiple `Event` instances, which is covered in the next tutorial.
++
+To make the editor component interesting (though it doesn't actually edit
anything), you set the text fields to display
+values from the `Event`.
== Running the Code
-Now you're ready to run the tutorial. Simply right click `EventManager`, the
application which contains your three modules, and choose Run from the popup
menu. When the IDE opens, simply choose Window > Open Editor to invoke your
action. Do this a couple of times, so that there are several of your editor
components open. Your singleton `MyViewer` window should also be open. Notice
how the `MyViewer` window's contents change as you click different tabs, as
shown here:
-
-image::tutorials/selection-1_result1.png[]
+Now you're ready to run the tutorial. Right click `EventManager` and choose
Run. When the IDE opens, choose
+Window > Open Editor to invoke your action. Do this a few times to open
several editor components. Your `MyViewer`
+window should also be open. Notice how the `MyViewer` window content changes
as you click different tabs:
-If you click in the Viewer window, or close all of the editor windows, note
that the text changes to "[no selection]", as shown below:
+image::tutorials/selection-1_nb27_result1.png[]
-image::tutorials/selection-1_result2.png[]
+If you click in the Viewer window or close all editor windows, the text
changes to "[no selection]".
-NOTE: If you do not see the `MyViewer` window, you probably did not check the
checkbox in the wizard to open it on system start - simply go to the Window
menu and choose MyViewer to display it.
+NOTE: If you don't see the `MyViewer` window, you probably didn't check the
"open on system start" checkbox in the
+wizard. Go to the Window menu and choose MyViewer to display it.
== So, What's the Point?
-So the key point of this tutorial is the way the code is split into three
modules: the My Viewer module knows nothing about the My Editor module, and
either one can run by itself. They only share a common dependency on My API.
That means two things: 1. My Viewer and My Editor can be developed and shipped
independently, and 2. Any module that wants to provide a different sort of
editor than My Editor can do so, and the viewer component will work perfectly
with it, as long as the replacement editor offers an instance of `Event` from
its Lookup.
-
-To really picture the value of this, imagine `Event` were something much more
complex; imagine that `MyEditor` is an image editor, and ` Event` represents an
image being edited. The thing that's powerful here is that you could replace
`MyEditor` with, say, an SVG vector-based editor, and the viewer component
(presumably showing attributes of the currently edited image) will work
transparently with that new editor. It is this model of doing things that is
the reason you can add new tools into the NetBeans IDE that work against Java
files, and they will work in different versions of NetBeans, and that you can
have an alternate editor (such as the form editor) for Java files and all the
components and actions that work against Java files still work when the form
editor is used.
+The key point is how the code is split into three modules: My Viewer knows
nothing about My Editor, and either can run
+independently. They only share a dependency on My API. This means:
-This is very much the way NetBeans works with Java and other source files-in
their case, the thing that is available from the editor's Lookup is a `
xref:wiki::wiki/DevFaqDataObject.adoc[DataObject]`, and components like
Navigator and the Property Sheet are simply watching what object is being made
available by the focused `TopComponent`.
+1. My Viewer and My Editor can be developed and shipped independently
+2. Any module can provide a different editor and the viewer will work with it,
as long as the new editor offers an
+`Event` from its Lookup
-Another valuable thing about this approach is that often people are migrating
existing applications to the NetBeans Platform. The object that is part of the
data model, in that case, is probably existing, working code that should not be
changed in order to integrate it into NetBeans. By keeping the data model's API
in a separate module, the NetBeans integration can be kept separate from the
core business logic.
+To understand the value, imagine `Event` is something complex - say `MyEditor`
is an image editor and `Event` represents
+an image being edited. You could replace `MyEditor` with an SVG vector editor,
and the viewer (showing image attributes)
+would work transparently with the new editor. This is why you can add new
tools to NetBeans IDE that work with Java
+files - they work across different NetBeans versions, and alternative editors
(like the form editor) still work with all
+components and actions that work with Java files.
+This is how NetBeans IDE works with Java and other source files. The thing
available from the editor's Lookup is
+a xref:wiki::wiki/DevFaqDataObject.adoc[DataObject], and components like
Navigator and Property Sheet watch what object
+the focused `TopComponent` provides.
-== Changing Selected Objects on the Fly
-
-To make it really evident how powerful this approach can be, you'll take one
more step, and add a button to your editor component that lets it replace the
`Event` it has with a new one on the fly.
+This approach is also valuable when migrating existing applications to the
NetBeans Platform. The data model object is
+probably existing, working code that shouldn't change for NetBeans
integration. By keeping the data model API in a
+separate module, NetBeans integration stays separate from core business logic.
-[start=1]
-1. Open `MyEditor` in the form editor (click the Design toolbar button in the
editor toolbar), and drag a `Button` (javax.swing.JButton) to it.
-
-[start=2]
-1. Set the `text` property of the JButton to "Replace".
+== Changing Selected Objects on the Fly
-image::tutorials/selection-1_replace1.png[]
+To show how powerful this approach is, you'll add a button to your editor that
replaces the `Event` with a new one
+on the fly.
-[start=3]
-1. Right click the `JButton` and choose Events > Action > actionPerformed.
-image::tutorials/selection-1_replace2.png[]
+1. Open `MyEditor` in the form editor (click the Design button) and drag a
`Button` (javax.swing.JButton) to it.
-This will cause the code editor to open with the cursor in an event handler
method. Make that method call `updateContent()`.
+2. Set the button's `text` property to "Replace".
+3. Right click the `JButton` and choose Events > Action > actionPerformed.
++
+This opens the code editor with the cursor in an event handler method. Make
the method call `updateContent()`:
++
[source,java]
----
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
updateContent();
}
----
-
-Implement the missing method:
-
++
+Add the missing method:
++
[source,java]
----
- private void updateContent() {
- Event obj = new Event();
- jTextField1.setText ("Event #" + obj.getIndex());
- jTextField2.setText ("Created: " + obj.getDate());
- setDisplayName ("MyEditor " + obj.getIndex());
- content.set(Collections.singleton (obj), null);
- }
+private void updateContent() {
+ Event obj = new Event();
+ jTextField1.setText ("Event #" + obj.getIndex());
+ jTextField2.setText ("Created: " + obj.getDate());
+ setDisplayName ("MyEditor " + obj.getIndex());
+ content.set(Collections.singleton (obj), null);
+}
Review Comment:
Doing! I should have caught that!
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists