Java Code for Building Blocks

Building blocks, except shallow blocks, are accompanied by Java classes. These Java classes contain the code for the operations and variables declared in the block. If Java code depends on other libraries, bind them to the building block.

Extension and Implementation of Interfaces

The Java class for a building block may, just as any other Java class, extend a base class and implement different interfaces. We recommend the following:

  • Only extend the recommended building block classes, such as no.ntnu.item.arctis.runtime.Block. This is the default for most templates. Blocks specialized for certain platforms may extend other classes. These classes offer access to the blockID of a block.
  • If for some reason you must extend another class for the building block, implement interface IArctisBuildingBlock to obtain the blockID. Since the generated runtime creates the class, you may not declare any constructors manually. (The runtime either uses the default constructor or the one generated which sets all the instance parameters.)
  • Do not implement interfaces in the block class that can be realized by anonymous classes. This is generally considered bad programming practice. For instance, instead of making a block that contains a UI list implement a selection listener interface, such a selection listener should be contributed by an extra class or by an anonymous class declared within a method.

Constructor

The constructor for a building block Java class is created by the SDK automatically, if necessary. This constructor is used for example to initialize parameters for the block. You should not edit the Java constructor of a building block, since it is generated automatically to keep it in sync with the instance parameters of the building block. A good place to initialize variables is dedicated Java method which is called when the block is started.