| | | | Browse by category |
Question
How can I customize a view template implementation given in an Application Framework application?
Answer
Imagine you prefer each buffer window in Composer to draw a lined grid instead of a dotted grid. When using Application Framework, and provided you already have the IlvGrid
subclass that draws a grid of lines, making this feature available requires a few additional steps that are detailed here.
Originally, the method that attaches a grid to a manager view is the IlvManagerView.setGrid(IlvGrid)
method. In Composer, this method is used within the protected IlvJDocumentManagerView.installGrid()
method. IlvJDocumentManagerView has a specialized subclass, IlvJDocumentGrapherView
, that is declared as the main view template when creating a new document, thanks to the composer.xml file:
<appframe>
<settings>
<!-- -->
<documentTemplate name="Grapher"
documentJavaClass="ilog.views.composer.docview.IlvGrapherDocument" ...>
<containerTemplates>
<containerTemplate name="Default"
allowMultipleContainers="true"
frameMaximized="false"
visible="true"
closeDocumentOnClose="true">
<viewTemplate
javaClass="ilog.views.composer.docview.IlvJDocumentGrapherView"/>
</containerTemplate>
</containerTemplates>
</documentTemplate>
<!-- -->
</settings>
</appframe>
The recommended way to override the view template is to create a plugin
which has settings to redefine the default container template and its attached view
container. The new plugin is composed of the following files:
- plugin.xml:The definition file for the new plugin. It references the new appframe settings to be applied as well as the class instance responsible for starting up the plugin.
- gridline.xml: The Application Framework settings file responsible for redefining the default container template and its associated view template.
- GridLineExtension.java: The plugin installation class.
- IlvGridLinedGrapherView.java: The new view template class. Its installGrid function has been overridden and sets up an instance of a lined grid.
- IlvLinedGrid.java: An IlvGrid subclass. Its draw function draws lines instead of a matrix of points.
In JVIEWS_HOME/bin/composer/extensions/, create a gridline folder. Use the available plugins, graphlayout and prototypes, as an example to create the same folders with the same directory structure that includes these files. Another important task is to compile the source files and package them into a jar. To achieve this task, you can edit JVIEWS_HOME/bin/composer/build.xml like:
<!-- Builds the jar files from the ${composer.classes} directory -->
<target name='composer.jar' depends='full-compile'>
<jar jarfile='composer.jar'>
<fileset dir='${composer.classes}'>
<include name='ilog/views/composer/**'/>
<exclude name='ilog/views/composer/graphlayout/**'/>
<exclude name='ilog/views/composer/prototypes/**'/>
<exclude name='ilog/views/composer/gridline/**'/>
</fileset>
<fileset dir='src/resources'>
<include name='**'/>
</fileset>
</jar>
</target>
<target name='full-compile' depends='compile'>
<!-- place here what you need for your extensions to compile and deploy -->
<javac destdir='${composer.classes}'
debug='${compile.debug}'
optimize='${compile.optimize}'
source='${compile.source}'
target='${compile.target}'>
<classpath refid='compile.path'/>
<src path='${composer.extensions}/graphlayout/src/java'/>
<include name='ilog/views/composer/graphlayout/**/*.java'/>
<src path='${composer.extensions}/prototypes/src/java'/>
<include name='ilog/views/composer/prototypes/**/*.java'/>
<src path='${composer.extensions}/gridline/src/java'/>
<include name='ilog/views/composer/gridline/**/*.java'/>
</javac>
<jar jarfile='${composer.extensions}/graphlayout/graphlayoutplugin.jar'>
<fileset dir='${composer.classes}'>
<include name='ilog/views/composer/graphlayout/**'/>
</fileset>
<fileset dir='${composer.extensions}/graphlayout/resources'>
<include name='**'/>
</fileset>
</jar>
<jar jarfile='${composer.extensions}/prototypes/prototypesplugin.jar'>
<fileset dir='${composer.classes}'>
<include name='ilog/views/composer/prototypes/**'/>
</fileset>
<fileset dir='${composer.extensions}/prototypes/resources'>
<include name='**'/>
</fileset>
</jar>
<jar jarfile="${composer.extensions}/gridline/gridlineplugin.jar">
<fileset dir='${composer.classes}'>
<include name="ilog/views/composer/gridline/**"/>
</fileset>
<fileset dir='${composer.extensions}/gridline/resources'>
<include name='**'/>
</fileset>
</jar>
</target>
<target name='compile'>
<mkdir dir='${composer.classes}'/>
<javac srcdir='src/java'
destdir='${composer.classes}'
debug='${compile.debug}'
optimize='${compile.optimize}'
source='${compile.source}'
target='${compile.target}'>
<classpath refid='compile.path'/>
<include name='**/*.java'/>
</javac>
</target>
<!-- Cleans the files generated by a compilation -->
<target name='clean'
description='cleans up the directory'>
<delete dir='${composer.classes}' quiet='true'/>
<delete file='composer.jar' quiet='true'/>
</target>
<!-- copy the plugin.xml files required for the plugins to be read -->
<target name='run.prepare'>
<copy tofile='extensions/graphlayout/plugin.xml'
file='extensions/graphlayout/resources/plugin.xml'/>
<copy tofile='extensions/prototypes/plugin.xml'
file='extensions/prototypes/resources/plugin.xml'/>
<copy tofile='extensions/gridline/plugin.xml'
file='extensions/gridline/resources/plugin.xml'/>
</target>
Let's take a closer look at the Application Framework settings attached to the gridline plugin, that is, the gridline.xml file. A special tag,<AddRemove>, is meant to apply changes to an existing configuration as it allows you to change the container template definition file and its attached view template. You cannot change the view template only as it does not have any name attribute. The solution is to remove and redefine the default container template. The gridline.xml file will look as follows:
<?xml version="1.0"?>
<appframe>
<settings cascading="applyDiff">
<documentTemplate name="Grapher">
<containerTemplates>
<AddRemove>
<Remove idType="id" type="containerTemplate" id="Default"/>
<Insert idType="index" type="containerTemplate" id="0">
<containerTemplate name="Default" allowMultipleContainers="true" frameMaximized="false"visible="true"
closeDocumentOnClose="true">
<viewTemplate javaClass="ilog.views.composer.gridline.IlvGridLinedGrapherView"/>
</containerTemplate>
</Insert>
</AddRemove>
</containerTemplates>
</documentTemplate>
</settings>
</appframe>
Finally, run build.sh for UNIX or build.bat for Windows to rebuild Composer with the new plugin. Run the Composer, click on the buffer window to bring it to focus then at the top toolbar click on "Tools" then "Grid...". This will open the "Grid Configuration" dialog box. Check the "Visible" box then press "OK". You will now see a grid composed of lines instead of dots.
For your convenience, the attached ZIP archive contains the files discussed in this FAQ except for build.xml as each version of Composer has a slightly different build.xml file. You will have to manually edit build.xml as discussed.