we need to refactor the command listeners little bit to create a listener for the netbeans platform so that the output is seen on the output window.
Rename ConsoleCommandListener to BaseCmdOutput. It should have a printWriter property that takes a PrintWriter. It should have a no-arg constructor. Note that the listeners are intended to be reused i.e., they should be usable for both PUI and GUI. By default, the property could take java`s PrintWriter from PrintStream System.out. This will write to the standard output for the cpnsole app and to the log for the platform app. To use the output window in the platform app, we need to pass the PrintWriter io.getOut() as shown below.
Netbeans platform code snippet for output window
InputOutput io = IOProvider.getDefault().getIO("Task", true);
io.getOut().println("Info message");
io.getErr().println("error message");
io.getOut().close();
io.getErr().close();
Setting the printWriter property is little involved. We need to think further on this.
The objects that listen to command output could vary greatly. Multiple listeners could listen to the same command and process the output differently, even the same output could be reported differently. For example, one could be a textual display while another being a graphical component.
Generally, the job of a listener could be divided into processing and reporting. We would like to reuse the processing part and have plug-in behavior for the reporting part.
Let us categorize all listener implementations based on the reporting as either textual or dispatching graphical components. We would like to reuse the textual listeners by setting their print writers. This customization should be available both at the individual level and at the global level i.e., for all textual listeners.
This should be a base listener implementation for the textual listener, namely, TextualCommandOutput and GraphicalCommandOutput. TextualCommandOutput would have a public printWriter property and GraphicalCommandOutput would have amethod dispatching a JComponent.
Note that different applications provide different implementations of the event framework but they reuse the command and their listeners.
For PUI: setting the printWriter property for the EventImpl (base event implementation for the PUI client) would enable that property for all hooked textual listeners. To customize a particular listener (e.g., to set a different printWriter for it) one can provide a corresponding builder. While processing the listeners EventImpl would check for listeners or builders and ask the builder to create the listener and verify that the build is a listener.
GUI: Using propery editors properties for multiple listeners can be altered at a time or a individual listeners could be customized. To enable the output window one needs to pass a special print writer to all the textual listeners and this can be done in the same manner as for PUI. During the instantiation of EventImpl (for GUI) pass the correct print writer to all textual listeners.