1 /*******************************************************************************
\r
2 * Copyright (c) 2007, 2010 Association for Decentralized Information Management
\r
3 * in Industry THTH ry.
\r
4 * All rights reserved. This program and the accompanying materials
\r
5 * are made available under the terms of the Eclipse Public License v1.0
\r
6 * which accompanies this distribution, and is available at
\r
7 * http://www.eclipse.org/legal/epl-v10.html
\r
10 * VTT Technical Research Centre of Finland - initial API and implementation
\r
11 *******************************************************************************/
\r
12 package org.simantics.browsing.ui;
\r
14 import java.util.Collection;
\r
16 import org.simantics.browsing.ui.NodeContext.ConstantKey;
\r
17 import org.simantics.browsing.ui.NodeContext.ParametrizedPrimitiveQueryKey;
\r
18 import org.simantics.browsing.ui.NodeContext.PrimitiveQueryKey;
\r
19 import org.simantics.browsing.ui.NodeContext.QueryKey;
\r
20 import org.simantics.browsing.ui.content.CheckedStateFactory;
\r
21 import org.simantics.browsing.ui.content.ComparableContext;
\r
22 import org.simantics.browsing.ui.content.ComparableContextFactory;
\r
23 import org.simantics.browsing.ui.content.ImageDecorator;
\r
24 import org.simantics.browsing.ui.content.ImageDecoratorFactory;
\r
25 import org.simantics.browsing.ui.content.Imager;
\r
26 import org.simantics.browsing.ui.content.ImagerFactory;
\r
27 import org.simantics.browsing.ui.content.LabelDecorator;
\r
28 import org.simantics.browsing.ui.content.LabelDecoratorFactory;
\r
29 import org.simantics.browsing.ui.content.Labeler;
\r
30 import org.simantics.browsing.ui.content.LabelerFactory;
\r
31 import org.simantics.browsing.ui.content.PrunedChildrenResult;
\r
32 import org.simantics.browsing.ui.content.Viewpoint;
\r
33 import org.simantics.browsing.ui.content.ViewpointContribution;
\r
34 import org.simantics.browsing.ui.content.ViewpointContributionFactory;
\r
35 import org.simantics.browsing.ui.content.ViewpointFactory;
\r
38 * Keys and key classes for different queries and graph explorer nodes.
\r
41 * <code>QueryKey</code> instances are for identifying normal queries to be
\r
42 * performed. Also {@link NodeQueryProcessor}s, i.e. the query implementations,
\r
43 * use them to identify the query that they are capable of answering (see
\r
44 * {@link NodeQueryProcessor#getIdentifier()} method).
\r
48 * Both <code>PrimitiveQueryKey</code> instances and
\r
49 * <code>ParametrizedPrimitiveQueryKey</code> classes are used for identifying
\r
50 * queries that are performed by {@link PrimitiveQueryProcessor}s.
\r
53 * TODO: specify for every query key or query key class: description, query dependencies, query return value
\r
55 public interface BuiltinKeys {
\r
57 public static class InputKey implements ConstantKey<Object> {
\r
58 private InputKey() {}
\r
60 public String toString() {
\r
66 * This key is used for storing the main input object into a
\r
67 * {@link NodeContext}.
\r
70 * See <code>org.simantics.browsing.ui.common.NodeContextBuilder</code> and
\r
71 * <code>org.simantics.browsing.ui.common.NodeContextUtil</code> for ways of
\r
72 * creating NodeContext instances.
\r
74 public static final ConstantKey<Object> INPUT = new InputKey();
\r
76 public static class UIContextKey implements ConstantKey<String> {
\r
77 private UIContextKey() {}
\r
79 public String toString() {
\r
80 return "UI_CONTEXT";
\r
85 * This key is used for storing the node-specific ui context into a
\r
86 * {@link NodeContext}.
\r
89 * See <code>org.simantics.browsing.ui.common.NodeContextBuilder</code> and
\r
90 * <code>org.simantics.browsing.ui.common.NodeContextUtil</code> for ways of
\r
91 * creating NodeContext instances.
\r
93 public static final ConstantKey<String> UI_CONTEXT = new UIContextKey();
\r
95 public static class BrowseContextKey implements ConstantKey<Object> {
\r
96 private BrowseContextKey() {}
\r
98 public String toString() {
\r
99 return "BROWSE_CONTEXT";
\r
104 * This key is used for storing the node-specific BrowseContext input object into a
\r
105 * {@link NodeContext}.
\r
108 * See <code>org.simantics.browsing.ui.common.NodeContextBuilder</code> and
\r
109 * <code>org.simantics.browsing.ui.common.NodeContextUtil</code> for ways of
\r
110 * creating NodeContext instances.
\r
112 public static final ConstantKey<Object> BROWSE_CONTEXT = new BrowseContextKey();
\r
114 public static class ActionBrowseContextKey implements ConstantKey<Object> {
\r
115 private ActionBrowseContextKey() {}
\r
117 public String toString() {
\r
118 return "ACTION_BROWSE_CONTEXT";
\r
123 * This key is used for storing the node-specific ActionBrowseContext input
\r
124 * object into a {@link NodeContext}.
\r
127 * See <code>org.simantics.browsing.ui.common.NodeContextBuilder</code> and
\r
128 * <code>org.simantics.browsing.ui.common.NodeContextUtil</code> for ways of
\r
129 * creating NodeContext instances.
\r
131 public static final ConstantKey<Object> ACTION_BROWSE_CONTEXT = new ActionBrowseContextKey();
\r
133 public static class FilterKey implements ConstantKey<String> {
\r
134 private FilterKey() {}
\r
136 public String toString() {
\r
142 * This key is used for storing the filter string object into it a
\r
143 * {@link NodeContext}. The value is used by primitive query viewpoints to
\r
147 * See <code>org.simantics.browsing.ui.common.NodeContextBuilder</code> and
\r
148 * <code>org.simantics.browsing.ui.common.NodeContextUtil</code> for ways of
\r
149 * creating NodeContext instances.
\r
151 public static final ConstantKey<String> FILTER = new FilterKey();
\r
153 public static final QueryKey<Viewpoint> SELECTED_VIEWPOINT = new QueryKey<Viewpoint>() {
\r
155 public String toString() {
\r
156 return "SELECTED_VIEWPOINT";
\r
160 public static final QueryKey<String> ACTIVE_FILTER = new QueryKey<String>() {
\r
162 public String toString() {
\r
163 return "ACTIVE_FILTER";
\r
167 public static final QueryKey<Collection<ViewpointContribution>> VIEWPOINT_CONTRIBUTIONS = new QueryKey<Collection<ViewpointContribution>>() {
\r
169 public String toString() {
\r
170 return "VIEWPOINT_CONTRIBUTIONS";
\r
175 * A query for all available viewpoint factories for the current input.
\r
177 * Depends on: {@link #INPUT}
\r
179 * Returns: a non-null collection
\r
181 public static final QueryKey<Collection<ViewpointFactory>> VIEWPOINT_FACTORIES = new QueryKey<Collection<ViewpointFactory>>() {
\r
183 public String toString() {
\r
184 return "VIEWPOINT_FACTORIES";
\r
188 public static class SelectedViewpointFactoryKey extends ParametrizedPrimitiveQueryKey<ViewpointFactory> {
\r
189 public SelectedViewpointFactoryKey(Collection<ViewpointFactory> factories) {
\r
191 assert factories != null;
\r
194 public String getKeyName() {
\r
195 return "SELECTED_VIEWPOINT_FACTORY";
\r
199 public static class ViewpointKey extends ParametrizedPrimitiveQueryKey<Viewpoint> {
\r
200 public ViewpointKey(ViewpointFactory factory) {
\r
202 assert factory != null;
\r
205 public String getKeyName() {
\r
206 return "VIEWPOINT";
\r
210 public static class ViewpointContributionKey extends ParametrizedPrimitiveQueryKey<ViewpointContribution> {
\r
211 public ViewpointContributionKey(ViewpointContributionFactory factory) {
\r
213 assert factory != null;
\r
216 public String getKeyName() {
\r
217 return "VIEWPOINT_CONTRIBUTION";
\r
222 * Used by <code>GraphExplorer.setTextAndImage</code>.
\r
224 public static final QueryKey<Collection<LabelDecoratorFactory>> LABEL_DECORATOR_FACTORIES = new QueryKey<Collection<LabelDecoratorFactory>>() {
\r
226 public String toString() {
\r
227 return "LABEL_DECORATOR_FACTORIES";
\r
231 * Used by <code>GraphExplorer.setTextAndImage</code>.
\r
233 public static final QueryKey<Collection<LabelDecorator>> LABEL_DECORATORS = new QueryKey<Collection<LabelDecorator>>() {
\r
235 public String toString() {
\r
236 return "LABEL_DECORATORS";
\r
240 * Used by <code>GraphExplorer.setTextAndImage</code>.
\r
242 public static final QueryKey<Collection<ImageDecoratorFactory>> IMAGE_DECORATOR_FACTORIES = new QueryKey<Collection<ImageDecoratorFactory>>() {
\r
244 public String toString() {
\r
245 return "IMAGE_DECORATOR_FACTORIES";
\r
249 * Used by <code>GraphExplorer.setTextAndImage</code>.
\r
251 public static final QueryKey<Collection<ImageDecorator>> IMAGE_DECORATORS = new QueryKey<Collection<ImageDecorator>>() {
\r
253 public String toString() {
\r
254 return "IMAGE_DECORATORS";
\r
258 public static final QueryKey<Labeler> SELECTED_LABELER = new QueryKey<Labeler>() {
\r
260 public String toString() {
\r
261 return "SELECTED_LABELER";
\r
265 public static final QueryKey<Imager> SELECTED_IMAGER = new QueryKey<Imager>() {
\r
267 public String toString() {
\r
268 return "SELECTED_IMAGER";
\r
272 public static final QueryKey<Collection<LabelDecoratorFactory>> SELECTED_LABEL_DECORATOR_FACTORIES = new QueryKey<Collection<LabelDecoratorFactory>>() {
\r
274 public String toString() {
\r
275 return "SELECTED_LABEL_DECORATOR_FACTORIES";
\r
279 public static final QueryKey<Collection<ImageDecoratorFactory>> SELECTED_IMAGE_DECORATOR_FACTORIES = new QueryKey<Collection<ImageDecoratorFactory>>() {
\r
281 public String toString() {
\r
282 return "SELECTED_IMAGE_DECORATOR_FACTORIES";
\r
287 * A query for all available labeler factories for the current input.
\r
289 * Depends on: {@link #INPUT}
\r
291 * Returns: a non-null collection
\r
293 public static final QueryKey<Collection<LabelerFactory>> LABELER_FACTORIES = new QueryKey<Collection<LabelerFactory>>() {
\r
295 public String toString() {
\r
296 return "LABELER_FACTORIES";
\r
301 * A query for all available imager factories for the current input.
\r
303 * Depends on: {@link #INPUT}
\r
305 * Returns: a non-null collection
\r
307 public static final QueryKey<Collection<ImagerFactory>> IMAGER_FACTORIES = new QueryKey<Collection<ImagerFactory>>() {
\r
309 public String toString() {
\r
310 return "IMAGER_FACTORIES";
\r
314 public static class LabelerKey extends ParametrizedPrimitiveQueryKey<Labeler> {
\r
315 public LabelerKey(LabelerFactory factory) {
\r
317 assert factory != null;
\r
320 public String getKeyName() {
\r
325 public static class CheckedStateKey extends ParametrizedPrimitiveQueryKey<CheckedState> {
\r
326 public CheckedStateKey(CheckedStateFactory factory) {
\r
328 assert factory != null;
\r
331 public String getKeyName() {
\r
332 return "CHECK_STATE";
\r
336 public static class LabelDecoratorKey extends ParametrizedPrimitiveQueryKey<LabelDecorator> {
\r
337 public LabelDecoratorKey(LabelDecoratorFactory factory) {
\r
339 assert factory != null;
\r
342 public String getKeyName() {
\r
343 return "LABEL_DECORATOR";
\r
347 public static class ImagerKey extends ParametrizedPrimitiveQueryKey<Imager> {
\r
348 public ImagerKey(ImagerFactory factory) {
\r
350 assert factory != null;
\r
353 public String getKeyName() {
\r
358 public static class ImageDecoratorKey extends ParametrizedPrimitiveQueryKey<ImageDecorator> {
\r
359 public ImageDecoratorKey(ImageDecoratorFactory factory) {
\r
361 assert factory != null;
\r
364 public String getKeyName() {
\r
365 return "IMAGE_DECORATOR";
\r
370 * A query that returns a collection of {@link SelectionRequest}s based on
\r
371 * the current input. The selection requests are used to dictate whether a
\r
372 * child INodeContext of the input INodeContext gets filtered out from the
\r
373 * result of the {@link #PRUNED_CHILDREN} query.
\r
376 * The query is free to return <code>null</code> if there are no filters for
\r
380 public static final PrimitiveQueryKey<Collection<SelectionRequest>> SELECTION_REQUESTS = new PrimitiveQueryKey<Collection<SelectionRequest>>() {
\r
382 public String toString() {
\r
383 return "SELECTION_REQUEST";
\r
387 //------------------------------------------------------------------------
\r
390 * A query that requests for the currently selected viewpoint of a node
\r
391 * context, gets all of its children from the viewpoint and prunes the set
\r
392 * of children based on active filters (selection requests).
\r
394 * Depends on: {@link #SELECTED_VIEWPOINT}, {@link #SELECTION_REQUESTS}
\r
396 * Returns: A {@link PrunedChildrenResult} which contains the pruned set of
\r
397 * children as INodeContext[] and the original amount of children before
\r
400 public static final QueryKey<PrunedChildrenResult> PRUNED_CHILDREN = new QueryKey<PrunedChildrenResult>() {
\r
402 public String toString() {
\r
403 return "PRUNED_CHILDREN";
\r
408 * A query to transform INodeContext's into ComparableContexts that can be
\r
411 * Depends on: {@link #PRUNED_CHILDREN}
\r
413 * Returns: ComparableContext[] of the same size as the input or
\r
414 * <code>null</code> if no selected ComparableFactory could be discovered
\r
415 * which indicates that child nodes cannot be sorted.
\r
417 public static final QueryKey<ComparableContext[]> COMPARABLE_CHILDREN = new QueryKey<ComparableContext[]>() {
\r
419 public String toString() {
\r
420 return "COMPARABLE_CHILDREN";
\r
425 * A query for all available comparable factories for the current input.
\r
427 * Depends on: {@link #INPUT}
\r
429 * Returns: a non-null collection
\r
431 public static final QueryKey<Collection<ComparableContextFactory>> COMPARABLE_FACTORIES = new QueryKey<Collection<ComparableContextFactory>>() {
\r
433 public String toString() {
\r
434 return "COMPARABLE_FACTORIES";
\r
438 public static class SelectedComparableFactoryKey extends ParametrizedPrimitiveQueryKey<ComparableContextFactory> {
\r
439 public SelectedComparableFactoryKey(Collection<ComparableContextFactory> factories) {
\r
441 assert factories != null;
\r
444 public String getKeyName() {
\r
445 return "SELECTED_COMPARABLE_FACTORY";
\r
450 * Returns the final child nodes for a node after pruning and sorting them.
\r
451 * If you need to discover the set of children for a node you should use
\r
452 * {@link BuiltinKeys#PRUNED_CHILDREN} instead if you don't need the
\r
453 * sorting. To get the non-pruned set of all children of a node
\r
455 * Depends on: {@link BuiltinKeys#COMPARABLE_CHILDREN},
\r
456 * {@link BuiltinKeys#PRUNED_CHILDREN}
\r
458 * Returns: an array of {@link NodeContext}s.
\r
460 public static final QueryKey<NodeContext[]> FINAL_CHILDREN = new QueryKey<NodeContext[]>() {
\r
462 public String toString() {
\r
463 return "FINAL_CHILDREN";
\r
468 * Returns whether a node is expanded in the UI or not.
\r
470 * Returns: {@link Boolean#TRUE} if expanded, {@link Boolean#FALSE} if not.
\r
472 public static final PrimitiveQueryKey<Boolean> IS_EXPANDED = new PrimitiveQueryKey<Boolean>() {
\r
474 public String toString() {
\r
475 return "IS_EXPANDED";
\r
480 * Tells whether a node is "checked" in the UI or not. This only takes
\r
481 * effect if the GraphExplorer was created with support for checkedness
\r
484 * Returns: {@link CheckedState}
\r
486 public static final QueryKey<CheckedState> IS_CHECKED = new QueryKey<CheckedState>() {
\r
488 public String toString() {
\r
489 return "IS_CHECKED";
\r
494 * Returns how many children should maximally be shown for a node. By
\r
495 * default the set of shown children is pruned if there are too many of them
\r
500 * <li>0 < x ≤ {@value Integer#MAX_VALUE} to tell the maximum amount of
\r
501 * children to show</li>
\r
502 * <li><code>null</code> indicates don't care</li>
\r
504 * May not return < 0.
\r
506 public static final PrimitiveQueryKey<Integer> SHOW_MAX_CHILDREN = new PrimitiveQueryKey<Integer>() {
\r
508 public String toString() {
\r
509 return "SHOW_MAX_CHILDREN";
\r
513 public static class IsRootKey implements ConstantKey<Object> {
\r
514 private IsRootKey() {}
\r
516 public String toString() {
\r
522 * Set to {@link Boolean#TRUE} for a NodeContext that describes the root
\r
523 * input of a {@link GraphExplorer}.
\r
525 public static final ConstantKey<Object> IS_ROOT = new IsRootKey();
\r