Difference between revisions of "Org.simantics.browsing.ui"
m |
|||
(9 intermediate revisions by 2 users not shown) | |||
Line 3: | Line 3: | ||
== Concepts == | == Concepts == | ||
; Query Key | ; Query Key | ||
− | : An object that identifies the query to be performed. Query keys are capable of identifying the query processor to be used for actually performing the query. See the [[svn:foundation/trunk/org.simantics.browsing.ui/src/org/simantics/browsing/ui/ | + | : An object that identifies the query to be performed. Query keys are capable of identifying the query processor to be used for actually performing the query. See the [[svn:foundation/browsing/trunk/org.simantics.browsing.ui/src/org/simantics/browsing/ui/NodeContext.java|base class for all keys]]: |
<blockquote> | <blockquote> | ||
<pre> | <pre> | ||
Line 25: | Line 25: | ||
== Basic Usage == | == Basic Usage == | ||
− | |||
− | |||
− | |||
# Use <code>org.simantics.browsing.ui.GraphExplorerFactory</code> to construct new instances of the SWT-based GraphExplorer control. | # Use <code>org.simantics.browsing.ui.GraphExplorerFactory</code> to construct new instances of the SWT-based GraphExplorer control. | ||
# Setup layouts for the GraphExplorer control as you normally would in SWT | # Setup layouts for the GraphExplorer control as you normally would in SWT | ||
# Initialize data sources (<code>DataSourceProvider</code>) for the graph explorer (<code>GraphExplorer.setDataSource(DataSourceProvider)</code>) | # Initialize data sources (<code>DataSourceProvider</code>) for the graph explorer (<code>GraphExplorer.setDataSource(DataSourceProvider)</code>) | ||
#* For example, the graph database is one possible data source. | #* For example, the graph database is one possible data source. | ||
− | # Initialize | + | # Initialize an [[svn:foundation/browsing/trunk/org.simantics.browsing.ui.common/src/org/simantics/browsing/ui/common/EvaluatorData.java|EvaluatorData]] for your explorer. Preferably use [[svn:foundation/browsing/trunk/org.simantics.browsing.ui.graph.impl/src/org/simantics/browsing/ui/graph/impl/Evaluators.java|Evaluators.load(...)]] to do this. |
+ | # Initialize all needed query processors for your purposes with the previously loaded EvaluatorData as an argument (<code>GraphExplorer.setProcessor(NodeQueryProcessor)</code>, <code>GraphExplorer.setPrimitiveProcessor(PrimitiveQueryProcessor)</code>) | ||
# Set root input (<code>GraphExplorer.setRoot(Object)</code>) | # Set root input (<code>GraphExplorer.setRoot(Object)</code>) | ||
=== Query System === | === Query System === | ||
− | |||
The explorer content production process is based solely on ''queries''. Abstractly speaking, a query is just a request for an answer to a question. | The explorer content production process is based solely on ''queries''. Abstractly speaking, a query is just a request for an answer to a question. | ||
Each potentially visible element in a GraphExplorer will have its own ''node context'' (see [[svn:foundation/browsing/trunk/org.simantics.browsing.ui/src/org/simantics/browsing/ui/NodeContext.java|NodeContext]]). Queries are always performed on a single node context. | Each potentially visible element in a GraphExplorer will have its own ''node context'' (see [[svn:foundation/browsing/trunk/org.simantics.browsing.ui/src/org/simantics/browsing/ui/NodeContext.java|NodeContext]]). Queries are always performed on a single node context. | ||
Line 63: | Line 60: | ||
Internally a GraphExplorer implementation shall also bind certain top-level queries to actual UI elements. If such queries with bound UI elements are updated, the UI elements shall be updated also. For example in the case of a tree this implies updating the label or image of the tree node. | Internally a GraphExplorer implementation shall also bind certain top-level queries to actual UI elements. If such queries with bound UI elements are updated, the UI elements shall be updated also. For example in the case of a tree this implies updating the label or image of the tree node. | ||
− | === | + | === Basic Query hierarchy === |
− | [[Image: | + | WARNING: IMAGE IS OUT OF DATE |
+ | |||
+ | [[Image:Graph-explorer-queries.png|center|thumb|700px|alt=Visual query order representation|Visual representation of the order in which the basic graph explorer query processors work to produce and render the explored content on the screen.]] | ||
== Selection handling == | == Selection handling == | ||
Line 74: | Line 73: | ||
=== Resource selection example === | === Resource selection example === | ||
+ | |||
<source lang="Java"> | <source lang="Java"> | ||
ISelectionProvider provider = (ISelectionProvider) explorer.getAdapter(ISelectionProvider.class); | ISelectionProvider provider = (ISelectionProvider) explorer.getAdapter(ISelectionProvider.class); | ||
if (provider != null) { | if (provider != null) { | ||
ISelection selection = provider.getSelection(); | ISelection selection = provider.getSelection(); | ||
+ | |||
+ | // For single-selection browsers or assuming a single-selection on a multi-select browser | ||
Resource object = ISelectionUtils.getSinglePossibleKey(selection, SelectionHints.KEY_MAIN, Resource.class); | Resource object = ISelectionUtils.getSinglePossibleKey(selection, SelectionHints.KEY_MAIN, Resource.class); | ||
+ | |||
+ | // For multi-selections | ||
+ | List<Resource> objects = ISelectionUtils.getPossibleKeys(selection, SelectionHints.KEY_MAIN, Resource.class); | ||
} | } | ||
</source> | </source> |
Latest revision as of 13:51, 4 February 2011
There exists a more tutorial like manual.
Contents
Concepts
- Query Key
- An object that identifies the query to be performed. Query keys are capable of identifying the query processor to be used for actually performing the query. See the base class for all keys:
/** * Do not implement this directly, look at {@link PrimitiveQueryKey} and * {@link QueryKey} instead. */ public static interface CacheKey<T> { /** * This method must return a unique object that is used to decide which * QueryProcessor is used to calculate the query result. * * The returned value is compared only using object identity (==), not * equals. * * @return the identifier of this processor */ Object processorIdenfitier(); }
Basic Usage
- Use
org.simantics.browsing.ui.GraphExplorerFactory
to construct new instances of the SWT-based GraphExplorer control. - Setup layouts for the GraphExplorer control as you normally would in SWT
- Initialize data sources (
DataSourceProvider
) for the graph explorer (GraphExplorer.setDataSource(DataSourceProvider)
)- For example, the graph database is one possible data source.
- Initialize an EvaluatorData for your explorer. Preferably use Evaluators.load(...) to do this.
- Initialize all needed query processors for your purposes with the previously loaded EvaluatorData as an argument (
GraphExplorer.setProcessor(NodeQueryProcessor)
,GraphExplorer.setPrimitiveProcessor(PrimitiveQueryProcessor)
) - Set root input (
GraphExplorer.setRoot(Object)
)
Query System
The explorer content production process is based solely on queries. Abstractly speaking, a query is just a request for an answer to a question. Each potentially visible element in a GraphExplorer will have its own node context (see NodeContext). Queries are always performed on a single node context.
Producing content for the visualized graph is generally a matter of doing the following things:
- Finding the children of an element that can be shown
- Possibly filtering the children
- Possibly sorting the children
- Producing labels and images for visible elements
All of these steps are done through different named queries. All queries are identified by query keys. Keys can be either singleton instances or parametrized classes. For example the query BuiltinKeys.SELECTED_VIEWPOINT is used to find out the selected viewpoint for an input context that is used to produce the child node contexts of the specified input context. Queries are performed using this interface:
<source lang="java"> public interface NodeQueryManager {
<T> T query(INodeContext context, QueryKey<T> key) throws NoQueryProcessorException; <T> T query(INodeContext context, PrimitiveQueryKey<T> key) throws NoQueryProcessorException;
} </source>
The most important things to know about the query system are:
- The query system automatically generates and keeps track of dependencies between queries.
- Query results can be updated by the result producer. Updates potentially causes the results of all dependent queries to be updated too. The query manager will propagate these changes automatically and update the UI where necessary.
- The whole query system runs in the single UI control thread (SWT thread). Therefore by implementing potentially blocking queries you will also potentially block the UI. This does not differ in any way from standard SWT/JFace.
- Contrary to the basic JFace framework, the query system provides support for implementing non-blocking primitive queries by making their completion asynchronous. The goal is to perform the real work in background threads. Asynchronously completing queries will always return a placeholder result immediately and update the query result later once the background thread complete their work. The query system will ensure for you that any queries depending on the particular primitive query result will also be updated.
Internally a GraphExplorer implementation shall also bind certain top-level queries to actual UI elements. If such queries with bound UI elements are updated, the UI elements shall be updated also. For example in the case of a tree this implies updating the label or image of the tree node.
Basic Query hierarchy
WARNING: IMAGE IS OUT OF DATE
Selection handling
A GraphExplorer
is an IPostSelectionProvider
. Adapt a GraphExplorer
into ISelectionProvider
or IPostSelectionProvider
through GraphExplorer.getAdapter(ISelectionProvider.class)
.
The selections produced by it will always contain NodeContext
instances. These are produced by Viewpoint
s. The basic implementations of NodeContext are constructed by NodeContextBuilder
. A NodeContext must always contain an object value for the BuiltinKeys.INPUT
key (see NodeContext.getConstant(ConstantKey<T>)
). Note that NodeContext extends IAdaptable
which takes all possible measures to adapt the INPUT value into the desired object class.
Resource selection example
<source lang="Java"> ISelectionProvider provider = (ISelectionProvider) explorer.getAdapter(ISelectionProvider.class); if (provider != null) {
ISelection selection = provider.getSelection();
// For single-selection browsers or assuming a single-selection on a multi-select browser Resource object = ISelectionUtils.getSinglePossibleKey(selection, SelectionHints.KEY_MAIN, Resource.class);
// For multi-selections List<Resource> objects = ISelectionUtils.getPossibleKeys(selection, SelectionHints.KEY_MAIN, Resource.class);
} </source>