Difference between revisions of "Org.simantics.views"
(→SWT) |
|||
(One intermediate revision by the same user not shown) | |||
Line 8: | Line 8: | ||
== Modelling == | == Modelling == | ||
+ | |||
+ | The scene graph hierarchy is defined by the property http://www.simantics.org/Views-1.0/HasChildren which evaluates to list of resources. | ||
=== Composite === | === Composite === | ||
Line 83: | Line 85: | ||
root.createControls(body); | root.createControls(body); | ||
+ | </pre> | ||
+ | |||
+ | A typical modelled view such as org.simantics.selectionview.ModelledTabContribution tracks the workspace selection and writes the selection value in the runtime resource. | ||
+ | |||
+ | <pre> | ||
+ | graph.claimLiteral(runtime, VIEW.Runtime_HasVariable, uri, Bindings.STRING); | ||
+ | </pre> | ||
+ | |||
+ | A modelled view then defines e.g. a value of a Text control by a function, which depends on the input. | ||
+ | |||
+ | <pre> | ||
+ | @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); | ||
+ | } | ||
+ | </pre> | ||
+ | |||
+ | Another function can depend on some state written by other controls (user input). | ||
+ | |||
+ | <pre> | ||
+ | @SCLValue(type = "ReadGraph -> Resource -> Variable -> String") | ||
+ | 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); | ||
+ | } | ||
</pre> | </pre> |
Latest revision as of 13:49, 24 October 2011
Modelled views are structural models of graphical user interfaces defined in org.simantics.views*
Contents
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.
Modelling
The scene graph hierarchy is defined by the property http://www.simantics.org/Views-1.0/HasChildren which evaluates to list of resources.
Composite
Composites are used mainly to lay out other controls.
Label
Labels display read-only text.
Text
Text represents an editable text, which produces instant notification of any changes.
Button
Button represents a standard button.
Combo
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
Explorer represents a browse context as tree.
TabFolder
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
Combo2 is a variation of Combo.
Implementation
SWT
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) { @Override public Resource perform(WriteGraph graph) throws DatabaseException { return graph.newResource(); } }); SWTViewLoaderProcess loader = new SWTViewLoaderProcess(null, null); SWTRoot root = loader.load(viewURI, runtime); root.createControls(body);
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).
@SCLValue(type = "ReadGraph -> Resource -> Variable -> String") 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); }