Creating a Visual Panel

Visual Panels has gained a lot of momentum recently as a platform for developing quick system management applications for the OpenSolaris desktop.

Creating a basic application, or "panel", for VP is fairly straightforward:

  1. Implement the PanelDescriptor interface.
  2. Extend the abstract Control class.
  3. Create a jar file with all code and resources.
  4. Deploy your panel on the server to be managed.

Let's look at each of these steps in more depth while creating a basic panel that shows the current date and time. Future posts will elaborate on this example to turn it into a useful administration panel.

Notes:

  1. This discussion assumes Visual Panels is installed on the server you wish to manage.
  2. The source for all examples discussed here can be found in the Visual Panels Mercurial repository (see "Get the source") under usr/src/java/vpanels/panels/examples.

Implement PanelDescriptor

The PanelDescriptor interface is the entry point of the panel into Visual Panels. It describes to the framework how the panel should be integrated into the client.

Here we implement this interface in TimePanelDescriptor.java:

1. public class TimePanelDescriptor extends AbstractSwingPanelDescriptor { 2. 3. private Control control; 4. 5. /\*\* 6. \* Constructs a {@code TimePanelDescriptor}. 7. \* 8. \* @param id 9. \* a unique identifier for this Panel, taken from the panel 10. \* registration 11. \* 12. \* @param context 13. \* a handle to interact with the Visual Panels client 14. \*/ 15. public TimePanelDescriptor(String id, ClientContext context) { 16. super(id, context); 17. control = new TimeControl(this); 18. }

TimePanelDescriptor extends from AbstractSwingPanelDescriptor (1), which provides default implementations for many of the PanelDescriptor methods.

Visual Panels requires a PanelDescriptor subclass to define a public constructor with the id (8) and context (12) arguments described above. The first is derived from the panel registration and is mostly used internally by the framework. The latter, a ClientContext, provides hooks into various exposed features of the Visual Panels client, like connection monitoring, logging, and help management.

As a ManagedObject, TimePanelDescriptor must implement the getName method to provide a user-friendly name for use in the client:

19. @Override 20. public String getName() { 21. return Finder.getString("panel.time1.name"); 22. }

Finally, the getControl method points the client to the panel's top-level Control, a TimeControl created on line 17:

23. @Override 24. public Control getControl() { 25. return control; 26. } 27. }

Extend Control

The Control class governs the UI and navigation flow of the panel. It is the "C" component of "MVC".

In this example, we create TimeControl.java:

1. public class TimeControl extends SwingControl<TimePanelDescriptor, TimePanel> { 2. 3. public TimeControl(TimePanelDescriptor descriptor) { 4. super(descriptor.getId(), descriptor.getName(), descriptor); 5. } 6. 7. @Override 8. protected TimePanel createComponent() { 9. return new TimePanel(); 10. } 11. 12. @Override 13. protected void initComponent() { 14. Date date = new Date(); 15. getComponent().getSpinnerDateModel().setValue(date); 16. }

TimeControl extends SwingControl (1), which provides a default, Swing-based implemention of the Control class.

The SwingControl class controls the creation and display of a single java.awt.Component. In this example that Component's type is defined as a TimePanel (1) (see TimePanel.java), then created within the createComponent method (8). This method is called by the superclass the first time the TimeControl is started.

Finally, the TimePanel is initialized on line 15. The initComponent method is called by the superclass each time the TimeControl is started. In this simple implementation, we simply update the model with the current date.

Create a jar file

Once our classes have been created, we need to add them to a jar file, along with any other classes we use, to a jar file:

% jar cf vpanels-panels-examples.jar \\ org/opensolaris/os/vp/panels/example/time1

Don't worry about including other jar dependencies in this jar's manifest -- they'll be accounted for in the next step.

Deploy your panel

The first step in deploying your panel is to copy the jar file created in the last step to some directory on the server:

# cp vpanels-panels-examples.jar /usr/share/vpanels/panel

Next, create a deployment descriptor that describes the panel and identifies the jar to use:

1. <?xml version="1.0"?> 2. <!DOCTYPE panel SYSTEM "/usr/share/lib/xml/dtd/vpanel.dtd.1"> 3. <panel name='example-time1'> 4. <description xml:lang='C'>Application to set the time and date.</description> 5. <custom type='swing'> 6. <mainclass>org.opensolaris.os.vp.panels.example.time1.client.swing.TimePanelDescriptor</mainclass> 7. <approot>/usr/share/vpanels</approot> 8. <file>panel/vpanels-panels-examples.jar</file> 9. </custom> 10. </panel>

Line 3 specifies a name ("example-time1") that will be used to launch your panel.

Line 4 specifies a description that may be used within the UI to provide further detail about your panel.

Line 6 specifies the full class name of your PanelDescriptor subclass.

Line 8 identifies where you copied your jar file on the server. That location is relative to the approot directory on line 7.

The final step in deployment is to copy this descriptor to the /usr/share/vpanels/panels directory on the sever:

# cp example-time1.xml /usr/share/vpanels/panels

Run your panel

Your panel is ready to run at this point:

% /usr/bin/vp example-time1

Or, if you are running on a different host than the server on which you deployed your panel:

% /usr/bin/vp -h server example-time1

The resulting, if limited, UI is shown below:

Undeploy your panel

To undeploy your panel, simply remove the jar file and deployment descriptor from the file system:

# rm /usr/share/vpanels/panels/example-time1.xml \\ /usr/share/vpanels/panel/vpanels-panels-examples.jar
Comments:

Thanks, I'm looking forward to hopefully creating my own panels. Great start thus far.

Posted by Patrick on May 28, 2009 at 07:33 AM EDT #

Post a Comment:
  • HTML Syntax: NOT allowed
About

stephentalley

Search

Categories
Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today