Programming JMap Pro Extensions

 

To program JMap Pro extensions, it is important to follow a set of simple rules. This section describes these programming rules.

JMapClientExtension class

The first step towards developing a JMap Pro extension consists of programming a class derived from the abstract class JMapClientExtension. This class contains the following 3 methods, which are called at different moments in the life cycle of the extension:

JMapClientExtension class methods

init(JMapApplicationContext, Map<String, String>)

This method is called when the extension is loaded by the JMap Pro application. At this point, the graphical interfaces have not yet been initialized. In this method, you can put any code that will prepare the operation of your extension. This could include loading a settings file, verifying dependencies, etc. The method receives an instance of JMapApplicationContext as a parameter. This class provides access to all the resources of the JMap application.

The method also receives a collection (map) of parameters. These parameters provide useful information for the extension. See below for more information.

initGUI()

This method is called by the JMap application when its graphical interface has been initialized. In this method, you should put the code that initializes the GUI of your extension. This could include adding buttons or toolbars, menus, windows, etc. See the GUI Integration section for more information. This GUI will allow users to access the functions offered by your extension.

destroy()

This method is called by the JMap application just before it exits. In this method, you must put the code required to terminate your extension. This could include the code to release resources, save settings, etc.

Parameters are passed to the extension with the init() method, using a Map<String, String> collection. In JMap, there are two predefined parameters that match constants defined in the JMapClientExtension class:

- EXTENSION_PARAMETER_GUI_VISIBLE: Indicates whether the extension's GUI components (other than toolbars) must be visible when the application is launched.

- EXTENSION_PARAMETER_TOOLBAR_VISIBLE: Indicates whether the extension's toolbars must be visible when the application is launched.

These parameters contain ​​true or false values and they are set by the JMap Administrator when a JMap Pro application is deployed. Your extension must comply with these parameters. An extension can also receive its own settings, which would be set by the JMap Administrator.

The following code example shows how to access the settings from the init() method.

 
public void init(JMapApplicationContext appContext, Map<String, String> mapExtensionParameters)
{
  String param = mapExtensionParameters.get(JMapClientExtension.EXTENSION_PARAMETER_TOOLBAR_VISIBLE);
  boolean toolbarVisible = Boolean.parseBoolean(param);
 
  ...
}

 

JMapApplicationContext class

The JMapApplicationContext class is very useful for extension development because it provides access to a set of general application resources. This class is a singleton. Therefore, the instance can easily be accessed from anywhere using the static JMapApplicationContext.getInstance() method.

Most commonly used methods of the JMapApplicationContext class

getConnection()

Returns the instance of the connection (JMapSrvConnection class) to JMap Server.

getFrame()

Returns the instance of the main application window.

getViewManager()

Returns the instance of the View Manager (ViewManager class) of the application.

getApplication()

Returns the instance of the JMap application (JMapApplication class).

getJMapHome()

Returns the path to the main JMap folder on the user's computer. This is where JMap writes its data.

JMapApplication class

The JMapApplication class represents the JMap application. It offers methods that provide access to application resources (GUI, event logs, etc.). It also provides methods to perform tasks in a simple way (create a new map, close the project, etc.).

Most commonly used methods of the JMapApplication class

createNewView()

Creates a new map view that automatically appears in the application.

getCurrentProject()

Returns the instance of the project (Project class) opened in the application.

getGuiService()

Returns the instance of the application's JMapGuiService class. See the GUI Integration section for more information.

getLogger()

Returns the instance of the application's Logger class. Used to record messages from your extension in the JMap application's logs.