Modules FAQ

1. What is a module?

The module is a Java class that implements the IdeScript or the IdeStartup interface, or both. (You can find these interfaces in the com.togethersoft.openapi.ide package).

When implementing the IdeScript interface, you must define the run(IdeContext) method; when implementing IdeStartup interface, you must define the autorun() method.

2. What is the difference between these interfaces (and modules implementing them)?

The IdeStartup interface defines a module whose autorun() method will be invoked automatically during Together's startup process. This mehtod should perform some module-specific actions such as registering a menu command item with an appropriate listener. After it finishes executing, the autorun() method will not be invoked again during the current Together user session.

The IdeScript interface defines a module that can be invoked at any time, and any number of times during a user session by calling its run(IdeContext) method. An IdeContext (com.togethersoft.openapi.ide.IdeContext) instance being passed to the run method contains information about selection at the moment you ran the module.

3. What's the difference between a module and a script?

The difference is mostly semantic. Both modules and scripts can use the Together API to interact with Together or access model information and process it. In Together documentation, module refers to a program written in Java and compiled using a Java compiler and executed using the same JVM as Together at runtime. Script refers scripting code that is interpreted by appropriate Together subsystems at runtime. Currently TCL and JPython are supported as scripting languages, but this support may become deprecated in the future. For long-term compatibility, using Java is recommended.

4. Where should my modules be located?

At this moment, a module defines its own subpackage with a name matching the name of the module, and located in the module package. For example:

  package module.InsertTags;

import com.togethersoft.openapi.ide.IdeContext;
import com.togethersoft.openapi.ide.IdeScript;

public class InsertTags implements IdeScript{
public void run(IdeContext context){
}
}

5. How do I register a module?

  1. Complile a module. (Let's say you have compiled the InsertTags module shown above)

  2. Make a manifest file for your module. A manifest file is a simple text file which allows Together to identify the kind of a module.

    The extension of a manifest file is .def, and the file name is the name of a module. It must be located in the classpath according to the package of the module. (For example, InsertTags's manifest file is %root%/modules/com/togethesoft/modules/inserttags/InsertTags.def)

    A manifest file cosists of only one string:

    (For example, since InsertTags is a IdeScript it contains Script=true)

6. How do I run a module?

7. How about an example?

Here are two example modules for writing "Hello world".

  1. Startup script. This script writes the message at Together's startup process.

     
    package script.HelloWorldAutorun;

    import com.togethersoft.openapi.ide.IdeStartup;
    public class HelloWorldAutorun implements IdeStartup {
    public void autorun(){
    System.out.println("Hello world from HelloWorldAutorun script!!!");
    }
    }

    After compilation compose the file %root%//script/HelloWorldAutorun/HelloWorldAutorun.def with the line Startup=true in it.

  2. Script impementing IdeScript interface.

    package script.HelloWorld;

    import com.togethersoft.openapi.ide.IdeContext;
    import com.togethersoft.openapi.ide.IdeScript;
    public class HelloWorld implements IdeScript {
    public void run(IdeContext context){
    System.out.println("Hello World!!!");
    }
    }

    After compilation compose the file %root%//script/HelloWorld/HelloWorld.def with the line Script=true in it. Now open a project and locate this script in "modules" tab of the Explorer. Right-click on it and select the "Run" command.