Platform Module

Provides global platform functions like preferences, event bus or the command framework.

Method Overview

Method Description
adapt() Adapt object to target type.
executeCommand() Execute a command from the command framework.
getService() Get a platform service.
getSystemProperty() Get a system property value
postEvent() Post an event on the event broker.
readPreferences() Read a preferences value.
runProcess() Run an external process.
waitForEvent() Wait for a given event on the event bus.
writePreferences() Set a preferences value.

Methods

adapt

Object adapt(Object source, Class<T> target)

Adapt object to target type. Try to get an adapter for an object.

source
object to adapt
target
target class to adapt to

adapted object or null

executeCommand

void executeCommand(String commandId, [Map<K, V> parameters])

Execute a command from the command framework. As we have no UI available, we do not pass a control to the command. Hence HandlerUtil.getActive... commands will very likely fail.

commandId
full id of the command to execute
parameters
command parametersOptional: defaults to <null>.
ExecutionException
If the handler has problems executing this command.
NotDefinedException
If the command you are trying to execute is not defined.
NotEnabledException
If the command you are trying to execute is not enabled.
NotHandledException
If there is no handler.

getService

Object getService(Class<T> type)

Get a platform service.

type
service type

service instance or null

getSystemProperty

String getSystemProperty(String key)

Get a system property value

key
key to query

system property for key

postEvent

void postEvent(String topic, [Object data], [long delay])

Post an event on the event broker. If delay is set, the event will be posted after the given amount of time asynchronously. In any case this method returns immediately.

topic
topic to post
data
topic dataOptional: defaults to <null>.
delay
delay to post this even in [ms]Optional: defaults to <0>.

readPreferences

Object readPreferences(String node, String key, [Object defaultValue])

Read a preferences value. The defaultValue is optional, but contains type information if used. Provide instances of Boolean, Integer, Double, Float, Long, byte[], or String to get the appropriate return value of same type.

node
node to read from
key
key name to read from
defaultValue
default value to use, if value is not setOptional: defaults to <"">.

preference value or null

runProcess

Process runProcess(String name, [String args])

Run an external process. The process is started in the background and a FutureX object is returned. Query the result for finished state, output and error streams of the executed process.

name
program to run (with full path if necessary)
args
program argumentsOptional: defaults to <null>.

process object to track proces execution

IOException
if an I/O error occurs

waitForEvent

Event waitForEvent(String topic, [long timeout])

Wait for a given event on the event bus.

topic
topic to subscribe for
timeout
maximum time to wait for event in [ms]. Use 0 to wait without timeout.Optional: defaults to <0>.

posted event or null in case of a timeout

InterruptedException
when the script thread gets interrupted

writePreferences

void writePreferences(String node, String key, Object value)

Set a preferences value. Valid types for value are: Boolean, Integer, Double, Float, Long, byte[], and String.

node
node to write to
key
key to store to
value
value to store