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