From Developer Documents
Revision as of 13:49, 24 October 2011 by Antti Villberg (talk | contribs) (→‎Modelling)
Jump to navigation Jump to search

Modelled views are structural models of graphical user interfaces defined in org.simantics.views*

Basic concepts

A modelled view is a structural model of controls. The model configuration can be evaluated to produce a scene graph as defined in org.simantics.scenegraph. A single view configuration can be evaluated into multiple different scene graphs with different node types (e.g. SWT, AWT, PDF, HTML). The evaluation is done in the context of org.simantics.db.layer0.variable.Variable.

The properties of controls in a modelled view are often defined as functions of an external input assigned to the evaluation context e.g. a view can be defined to represent the current workspace selection. In the control hierarchy, relative references can also be modelled e.g. an action can be applied on an output of a specific control. It is also possible to declare a substructure of controls as a type such that some properties in the substructure are defined as functions of some interface properties declared in the type and defined in instances of that type.


The scene graph hierarchy is defined by the property which evaluates to list of resources.


Composites are used mainly to lay out other controls.


Labels display read-only text.


Text represents an editable text, which produces instant notification of any changes.


Button represents a standard button.


Combo represents a standard drop-down.

Tracked Text

Tracked text represents an editable text, which produces change notifications only when the editing operation ends.


Explorer represents a browse context as tree.


Tab folders represent a stack of composites.

Scrolled Composite

Scrolled composite is a composite which does not impose its size restrictions on its children.


Combo2 is a variation of Combo.



SWT view scene graphs are created using org.simantics.views.swt.SWTViewLoaderProcess. The loader creates a scene graph based on org.simantics.views.swt.client.base.ISWTViewNode, which allows for creating the view under a SWT composite.

public interface ISWTViewNode extends INode {

	Control getControl();
	IWorkbenchSite getSite();
	void createControls(Composite parent);

The loader requires a virtual runtime resource which is used to store transient model data served by the context Variable.

VirtualGraph vg = session.getService(VirtualGraph.class);
Resource runtime = session.sync(new WriteResultRequest<Resource>(vg) {
    public Resource perform(WriteGraph graph) throws DatabaseException {
        return graph.newResource();

SWTViewLoaderProcess loader = new SWTViewLoaderProcess(null, null);
SWTRoot root = loader.load(viewURI, runtime);

A typical modelled view such as org.simantics.selectionview.ModelledTabContribution tracks the workspace selection and writes the selection value in the runtime resource.

graph.claimLiteral(runtime, VIEW.Runtime_HasVariable, uri, Bindings.STRING);

A modelled view then defines e.g. a value of a Text control by a function, which depends on the input.

@SCLValue(type = "ReadGraph -> Resource -> Variable -> String")
public static Object getName(ReadGraph graph, Resource resource, Variable context) throws DatabaseException {
    Variable var = ViewUtils.getVariableSelection(graph, context);
    return var.getPropertyValue(graph, Variables.NAME, Bindings.String);

Another function can depend on some state written by other controls (user input).

public static Object getModelName(ReadGraph graph, Resource resource, Variable context) throws DatabaseException {
    DomainResource DR = DomainResource.getInstance(graph);
    return ViewUtils.getParameter(graph, context, DR.ExportWizard_SelectedModel, Bindings.STRING);