Creating a view plug-in to display "Hello World" text
| Note Before you begin working through this article, please ensure you have:
|
Purpose
To create a view plug-in that displays a string of text.
Theory
A view plug-in will enable you to present data in a specific format, rather than using the views that are automatically shipped with the Erudine Behaviour Engine. The view plug-in API enables you to create display panels that can be turned on and off depending upon the behaviour within knowledge nodes; this is a very powerful graphical interface tool. In this exercise, you will create a view plug-in to display the text "Hello World", unit test it to ensure it works correctly and then integrate it into the Erudine Behaviour Engine, by deploying it and then running it.
Actions
Creating a view plug-in
To create a view plug-in to display a string of text:
- Open Eclipse.
- Create a Java class with the following details:
- Class Name HelloWorldViewPlugIn
- Package Name exercise.viewPlugIn.helloWorld
- Interface IViewPlugIn
- Collapse the src/java folder and expand the resources folder.
- Open the HelloWorldViewPlugIn_GetView.java file.
- Copy the following text from the file into the getView method of the HelloWorldViewPlugIn class:
return new JLabel( "Hello World!" );
This text will create a Java Swing component that will be displayed when using the view plug-in. The Java Swing component will create a JLabel that will appear below the conceptual graph in the Conclusions & Justification screen.
- Open the HelloWorldViewPlugIn_GetDescription.java file.
Copy the following text from the file into the getDescription method of the class:
return new ViewPlugInDescription( "Hello World View", "Examples", "HelloWorldViewPlugIn demonstrates the usage of a simple viewPlugIn.");
This text will create the following details for the new view plug-in:
- Name Name of the view plug-in, which will appear whenever the plug-in can be selected from a list or menu.
- Grouping A category for the view plug-ins, so that similar plug-ins can be grouped together on lists or menus.
- Description A textual description of what the plug-in does, which may include HTML tags that format the text when it is displayed to the user. An example of using HTML is given in the completed version of this exercise.
- Press Ctrl + Shift + O to organise the imports.
- Save the HelloWorldViewPlugin class.
You will now test the view plug-in to check it works correctly.
Unit testing a view plug-in
To unit test the HelloWorldViewPlugIn class:
- Whilst still in Eclipse, collapse the resources folder and expand the src/unit folder.
- Expand the exercise.viewPlugIn.helloWorld package.
- Open the HelloWorldViewPlugInTest class to display its contents.
- Ensure all code is uncommented, except the line that starts with pass. You can uncomment lines of code by removing '//' from the beginning of any lines code where it appears.
- Press Ctrl + Shift + O to organise the imports.
- Right click on the Java code and select Run As > JUnit Test from the context menu.
This runs the tests contained in HelloWorldViewPlugInTest class against the HelloWorldViewPlugIn class that has been created in this exercise.
If the tests are successful, the JUnit bar in the top left of the screen will change to green.
This confirms that the view plug-in has been correctly implemented, - If you understand Java code, then examine the testGetView method, which checks that the correct Java Swing component is created in the plug-in and that the component contains the correct text.
You will now preview the effects of running the view plug-in. - Right click on the Java code and select Run As > Java Application from the context menu.
The ViewPlugInViewer utility class creates a JFrame and the view plug-in creates a view within the frame. Therefore, the results of running the view plug-in are displayed in a JFrame. - Close the frame containing the HelloWorld view plug-in.
Integrating a view plug-in
Once the view plug-in has been unit tested, the next step is to deploy it into the Erudine Behaviour Engine and then run the plug-in from within the Erudine Behaviour Engine.
To deploy and run the HelloWorld view plug-in:
- Whilst still in Eclipse, deploy the HelloWorld view plug-in by using the information here: Deploying extensions.
- Open the Erudine Behaviour Engine.
- Select New Model from the File menu
- Right click and select Property > Conceptual Graph Property from the context menu, to create a new node.
- In the dialog box, enter Node1 as the name of the node and click OK .
A new node called Node 1 is created. - Double click on the new node to display its contents in the Conclusion and Justification screen.
- Right click in a blank space in the Conclusion tab and select Add [int:Entity] from the context menu.
- Enter HelloWorld as the Entity Type and click OK .
- Select the Accept Without Justification box, in the top right corner.

- Click the OK button at the bottom of the screen.
- Right click on the HelloWorld concept and select Add View Plug-in from the context menu.
The View Plug-ins dialog box is displayed. - From the Examples folder, select the HelloWorld view plug-in and click OK .
- Click OK at the bottom of the screen, to accept the default justification.
The text HelloWorld! appears in the bottom half of the Conclusion pane, to show that the view plug-in has been successfully added. - Close the Erudine Behaviour Engine.
- Close Eclipse.
Platform: all
EBE Version: 2.4
Category: Development Training Guide
Author: Patrick Peisker