This section describes the full process of writing and deploying extension modules. We will compose a simple module and show how to make Together recognize it.
Let us say we want to develop a simple module which can be used as a startup and as regular module. This time we are not very interested in the module's functionality, so it must display just a short message, for the sake of simplicity.
Since we want to be able to run the module as a startup and as a
regular Together module, we must implement both com.togethersoft.openapi.ide.IdeScript
and com.togethersoft.openapi.ide.IdeStartup interfaces.
To output messages to the Together Message pane, we must use the com.togethersoft.openapi.ide.message.IdeMessageManagerAccess
and com.togethersoft.openapi.ide.message.IdeMessageType
interfaces (see the API documentation in $TOGETHER_HOME$/doc/api).
Important: Each new module must define its own package in the
com.togethersoft.modulespackage.
The only thing left is the name of the module. Let's name it MyFirstModule.
Below is the source code listing. If you want to try this out,
create a directory
%TOGETHER_HOME%\modules\com\togethersoft\modules\myFirstModule and
save this code as MyFirstModule.java.
//the MyFirstModule.java filepackage com.togethersoft.modules.myFirstModule;import com.togethersoft.openapi.ide.IdeContext;import com.togethersoft.openapi.ide.IdeScript;import com.togethersoft.openapi.ide.IdeStartup;import com.togethersoft.openapi.ide.message.IdeMessageManagerAccess;import com.togethersoft.openapi.ide.message.IdeMessageType;public class MyFirstModule implements IdeScript, IdeStartup{public void run(IdeContext context){ //regular modules perform this methodIdeMessageManagerAccess.printMessage(IdeMessageType.INFORMATION,"This is my first module. It was called as a regular Together module.");}public void autorun(){ //startup modules perform this methodIdeMessageManagerAccess.printMessage(IdeMessageType.INFORMATION,"This is my first module. It was called as a startup module."); //this will appear in the Message pane when Together is loadedSystem.out.println("This is my first module. It was called as a startup module."); //this will appear in the console window at the startup}}
If you run Together now and open Modules tab of the Explorer, you'll discover that MyFirstModule isn't shown. This is because we haven't informed Together about what we were going to do with the module.
We do this through a manifest file. A manifest file is a simple text file with the .def extension. It contains some information about the usage of a module.
Startup modules are modules
that load when Together starts. If your module is to be a startup
module, the manifest must contain the line:
Startup = true
For regular (i.e. non-startup) modules the line Script = true.
This should be the first line of the manifest file. Each manifest file must have a minimum of one line... either Startup = true or Script = true . You can put both lines if you want the module to run automatically on startup and you want to be able to run it during the Together session.
The manifest file can contain some other lines that provide additional information to Together so that the module appears in, and is accessible from the Together UI.
You can specify a visible name for the module by adding this line to
the manifest file:
Name =
Visible Name
The string after the equality sign will be displayed as the name of the module in the Modules tab of the Explorer. In this example exercise, we'll specify a "Visible Name".
You can specify where your module should appear in the Explorer's Modules
tab. For example, you can display it in the existing Sample
folder, or you can cause a new folder to appear. To specify the
Modules tab location, add this line to the manifest file:
Folder =
"<Folder name>"
<Folder name>" can be anything you want. Examples:
Folder = "Sample"
(module
appears in the existing Sample folder node of the Modules tab)
Folder = "My first module" (module appears in a new folder "My first module" in the Modules tab)
You can cause the module to be displayed in the Modules submenu of
the speedmenu for classes, interfaces, attributes and operations. Add
this line:
PopupMenuItem
= true
You can cause the module to show up in the Modules submenu of the
speedmenus of elements having a specific shapetype
(see the explanation of this term in the documentation for the
property RwiProperty.SHAPE_TYPE
in the API documentation).
Briefly, by optional addition of a constraint using the shapetype
parameter, you can make the module appear in the the
"Modules" submenu only for operations, or only for
attributes, or only for classes and interfaces. Two lines are
required to accomplish this: the line specified in the previous
section, and an addition line as shown below:
PopupMenuItem
= true
PopupConstraints
= "shapeType=<shapetype identifier>"
Only for operations:
PopupMenuItem = true
PopupConstraints = "shapeType=Operation"
Only for attributes:
PopupMenuItem = true
PopupConstraints = "shapeType=Attributes"
Only for lasses and interfaces:
PopupMenuItem = true
PopupConstraints = "shapeType=Class"
Note that since classes and interfaces have the same shapetype (i.e. "Class"), you can't selectively limit the appearance of a module to just interfaces via the manifest file. Do not worry, this can be done, but you will have to do a little more work in the module. There is a module in the %TOGETHER_HOME%\modules\com\togethersoft\modules\tutorial which shows how to do it.
Only for actors:
PopupMenuItem = true
PopupConstraints =
"shapeType=Actor"
RwiShapeType
interface (see the API documentation).
The manifest file must satisfy these conditions:
Its name must be exactly the name of the module's main class
(the class implementing IdeStartup or IdeScript interfaces).
Its location must be somewhere under the directories specified in the $TOGETHER_HOME$/config/scriptloader.config file. This file defines two possible root directories for manifest files:
Since MyFirstModule can be used as both kinds of modules (startup and runnable during session), we will use both of the module declaration lines (Script = true, Startup = true). Invoke your text editor and create the manifest file now. Add the following lines:
Script = trueStartup = trueName = My First ModuleFolder = "MyFirstModuleFolder"
Save the file as: %TOGETHER_HOME%\modules\com\togethersoft\modules\myFirstModule\MyFirstModule.def
Now you have to compile the module's source code. You can do so using Together, or your favorite Java compiler. Remember to include the %TOGETHER_HOME%\lib\openapi.jar file containing API classes in your compiler's classpath.
Keep module's .class file(s) in the same directory where the manifest file and sources reside. If you keep .class files somewhere else, make sure that their relative path matches the path of the manifest file counting from %TOGETHER_HOME%\modules\com\togethersoft\modules or %TOGETHER_HOME%\classes\com\togethersoft\modules .
For example, if your manifest file is modules\com\togethersoft\modules\coolModule\CoolModule.def, then your .class files must be somewhere in the classpath under the directory com\togethersoft\modules\coolModule\.
Once again, especially for your first modules, it's recommended to keep the .class files in the same directory as the manifest (.def) file and the sources. The best way is to keep them all together in a separate directory under %TOGETHER_HOME%\modules\com\togethersoft\modules.
Once you have compiled the module, run Together (if you compiled the
module using Together, close it and run again. If the console window
is on, you should see the module's startup message - that marks when
it was called at the startup, and when it performed autorun
method. Note, that although autorun method contains two
output commands, only one console message appears . When Together is
loading, its message pane is not visible, so all the messages written
to it at the startup will be displayed only after Together finishes loading.
When Together is loaded, select the Modules tab in the Explorer. Expand the All modules folder. You should see the "MyFirstModuleFolder" node with the "My First Module" files. One file is the module's source, another is the compiled .class file. Select either file, right-click, and choose "Run" (for the source file this command will cause Together to try to compile it, and run then. If you wish to use your home-brewed compilation results, select the .class file) If the message pane is open, you should see a module's message.
Congratulations, you have just deployed your first Together module!
It is highly recommended to sequentially comment out each of the manifest file's line to feel that this makes the module work in only one mode. Try it:
Script = true;Startup = trueName = This is my first module.
and
;Script = trueStartup = trueName = This is my first module.
(You will have to restart Together after each change in the manifest file to see the difference)
The .def and .java files of the module described in this document are not provided with Together... that's to make you create your own first module :-). Once you create it, deploy it, and run it, you will find it a matter of minutes to create new modules.
After you successfully deploy and run this example (please do it. If you are going to write modules, this will save you a lot of time later), look through the sample modules located in the %TOGETHER_HOME%\modules\com\togethersoft\modules directory. Pay attention to the tutorial folder, containing a set of sample modules demonstrating the usage of Together's open API.
Try to take something from the first "lesson" modules in the tutorial folder, and use it in a new module (or, simply rename a tutorial's lesson to be your second module).
If you get some compilation errors, please check that you:
import all the required API interfaces/classes
added all the required libraries to the compiler's classpath
use API methods properly. See API documentation in %TOGETHER_HOME%/doc.
Also, you may face these common problems:
Everything compiles without errors, but you can't find your module in Together's "Modules" tab.
Almost certainly, you didn't compose a .def file at all, or didn't place it under the directories specified by the scriptloader.config file (by default, these are specified as %TOGETHER_HOME%\modules\com\togethersoft\modules and %TOGETHER_HOME%\classes\com\togethersoft\modules)
Everything compiles without errors, and .def file is located Okay, but you still can't find your module in Together's "Modules" tab.
Most likely, you made a spelling error in the lines Startup = true or Script = true in the .def file.
Or, the name of the manifest file is not identical to the name of the module. In this case Together will write something like "The manifest file c:\together\modules\com\togethersoft\modules\coolModule\CoolSript.def exists but Together either cannot find or cannot read its associated module files." in the message page.
Everything compiles without errors, you see your module's folder in the "Modules" tab, but there are only Java sources (assuming you want to see and run the compiled module)
Make sure module's .class files located in the right place so that Together can find them. It was discussed in this document earlier (if you keep .class files where the .def file is, you won't encounter such a problem).
Everything compiles without errors, you see the module's compiled class in the "Modules" tab, but your module doesn't seem to work.
We highly recommend to mark the start and finish of each of your modules (regular and startup) with appropriate messages in the Message pane. This instantly clarifies whether your module was actually run or not. For example:
IdeMessageManagerAccess.printMessage(IdeMessageType.INFORMATION,"MyCoolModule : started"); //startIdeMessageManagerAccess.printMessage(IdeMessageType.INFORMATION,"MyCoolModule : finished"); //finish