]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.browsing.ui/src/org/simantics/browsing/ui/BuiltinKeys.java
Migrated source code from Simantics SVN
[simantics/platform.git] / bundles / org.simantics.browsing.ui / src / org / simantics / browsing / ui / BuiltinKeys.java
diff --git a/bundles/org.simantics.browsing.ui/src/org/simantics/browsing/ui/BuiltinKeys.java b/bundles/org.simantics.browsing.ui/src/org/simantics/browsing/ui/BuiltinKeys.java
new file mode 100644 (file)
index 0000000..c8792c6
--- /dev/null
@@ -0,0 +1,527 @@
+/*******************************************************************************\r
+ * Copyright (c) 2007, 2010 Association for Decentralized Information Management\r
+ * in Industry THTH ry.\r
+ * All rights reserved. This program and the accompanying materials\r
+ * are made available under the terms of the Eclipse Public License v1.0\r
+ * which accompanies this distribution, and is available at\r
+ * http://www.eclipse.org/legal/epl-v10.html\r
+ *\r
+ * Contributors:\r
+ *     VTT Technical Research Centre of Finland - initial API and implementation\r
+ *******************************************************************************/\r
+package org.simantics.browsing.ui;\r
+\r
+import java.util.Collection;\r
+\r
+import org.simantics.browsing.ui.NodeContext.ConstantKey;\r
+import org.simantics.browsing.ui.NodeContext.ParametrizedPrimitiveQueryKey;\r
+import org.simantics.browsing.ui.NodeContext.PrimitiveQueryKey;\r
+import org.simantics.browsing.ui.NodeContext.QueryKey;\r
+import org.simantics.browsing.ui.content.CheckedStateFactory;\r
+import org.simantics.browsing.ui.content.ComparableContext;\r
+import org.simantics.browsing.ui.content.ComparableContextFactory;\r
+import org.simantics.browsing.ui.content.ImageDecorator;\r
+import org.simantics.browsing.ui.content.ImageDecoratorFactory;\r
+import org.simantics.browsing.ui.content.Imager;\r
+import org.simantics.browsing.ui.content.ImagerFactory;\r
+import org.simantics.browsing.ui.content.LabelDecorator;\r
+import org.simantics.browsing.ui.content.LabelDecoratorFactory;\r
+import org.simantics.browsing.ui.content.Labeler;\r
+import org.simantics.browsing.ui.content.LabelerFactory;\r
+import org.simantics.browsing.ui.content.PrunedChildrenResult;\r
+import org.simantics.browsing.ui.content.Viewpoint;\r
+import org.simantics.browsing.ui.content.ViewpointContribution;\r
+import org.simantics.browsing.ui.content.ViewpointContributionFactory;\r
+import org.simantics.browsing.ui.content.ViewpointFactory;\r
+\r
+/**\r
+ * Keys and key classes for different queries and graph explorer nodes.\r
+ * \r
+ * <p>\r
+ * <code>QueryKey</code> instances are for identifying normal queries to be\r
+ * performed. Also {@link NodeQueryProcessor}s, i.e. the query implementations,\r
+ * use them to identify the query that they are capable of answering (see\r
+ * {@link NodeQueryProcessor#getIdentifier()} method).\r
+ * </p>\r
+ * \r
+ * <p>\r
+ * Both <code>PrimitiveQueryKey</code> instances and\r
+ * <code>ParametrizedPrimitiveQueryKey</code> classes are used for identifying\r
+ * queries that are performed by {@link PrimitiveQueryProcessor}s.\r
+ * </p>\r
+ * \r
+ * TODO: specify for every query key or query key class: description, query dependencies, query return value\r
+ */\r
+public interface BuiltinKeys {\r
+\r
+    public static class InputKey implements ConstantKey<Object> {\r
+        private InputKey() {}\r
+        @Override\r
+        public String toString() {\r
+            return "INPUT";\r
+        }\r
+    };\r
+\r
+    /**\r
+     * This key is used for storing the main input object into a\r
+     * {@link NodeContext}.\r
+     * \r
+     * <p>\r
+     * See <code>org.simantics.browsing.ui.common.NodeContextBuilder</code> and\r
+     * <code>org.simantics.browsing.ui.common.NodeContextUtil</code> for ways of\r
+     * creating NodeContext instances.\r
+     */\r
+    public static final ConstantKey<Object> INPUT = new InputKey();\r
+\r
+    public static class UIContextKey implements ConstantKey<String> {\r
+        private UIContextKey() {}\r
+        @Override\r
+        public String toString() {\r
+            return "UI_CONTEXT";\r
+        }\r
+    };\r
+\r
+    /**\r
+     * This key is used for storing the node-specific ui context into a\r
+     * {@link NodeContext}.\r
+     * \r
+     * <p>\r
+     * See <code>org.simantics.browsing.ui.common.NodeContextBuilder</code> and\r
+     * <code>org.simantics.browsing.ui.common.NodeContextUtil</code> for ways of\r
+     * creating NodeContext instances.\r
+     */\r
+    public static final ConstantKey<String> UI_CONTEXT = new UIContextKey();\r
+    \r
+    public static class BrowseContextKey implements ConstantKey<Object> {\r
+        private BrowseContextKey() {}\r
+        @Override\r
+        public String toString() {\r
+            return "BROWSE_CONTEXT";\r
+        }\r
+    };\r
+\r
+    /**\r
+     * This key is used for storing the node-specific BrowseContext input object into a\r
+     * {@link NodeContext}.\r
+     * \r
+     * <p>\r
+     * See <code>org.simantics.browsing.ui.common.NodeContextBuilder</code> and\r
+     * <code>org.simantics.browsing.ui.common.NodeContextUtil</code> for ways of\r
+     * creating NodeContext instances.\r
+     */\r
+    public static final ConstantKey<Object> BROWSE_CONTEXT = new BrowseContextKey();\r
+\r
+    public static class ActionBrowseContextKey implements ConstantKey<Object> {\r
+        private ActionBrowseContextKey() {}\r
+        @Override\r
+        public String toString() {\r
+            return "ACTION_BROWSE_CONTEXT";\r
+        }\r
+    };\r
+\r
+    /**\r
+     * This key is used for storing the node-specific ActionBrowseContext input\r
+     * object into a {@link NodeContext}.\r
+     * \r
+     * <p>\r
+     * See <code>org.simantics.browsing.ui.common.NodeContextBuilder</code> and\r
+     * <code>org.simantics.browsing.ui.common.NodeContextUtil</code> for ways of\r
+     * creating NodeContext instances.\r
+     */\r
+    public static final ConstantKey<Object> ACTION_BROWSE_CONTEXT = new ActionBrowseContextKey();\r
+\r
+    public static class FilterKey implements ConstantKey<String> {\r
+        private FilterKey() {}\r
+        @Override\r
+        public String toString() {\r
+            return "FILTER";\r
+        }\r
+    };\r
+\r
+    /**\r
+     * This key is used for storing the filter string object into it a\r
+     * {@link NodeContext}. The value is used by primitive query viewpoints to\r
+     * perform pruning.\r
+     * \r
+     * <p>\r
+     * See <code>org.simantics.browsing.ui.common.NodeContextBuilder</code> and\r
+     * <code>org.simantics.browsing.ui.common.NodeContextUtil</code> for ways of\r
+     * creating NodeContext instances.\r
+     */\r
+    public static final ConstantKey<String> FILTER = new FilterKey();\r
+\r
+    public static final QueryKey<Viewpoint> SELECTED_VIEWPOINT = new QueryKey<Viewpoint>() {\r
+        @Override\r
+        public String toString() {\r
+            return "SELECTED_VIEWPOINT";\r
+        }\r
+    };\r
+\r
+    public static final QueryKey<String> ACTIVE_FILTER = new QueryKey<String>() {\r
+        @Override\r
+        public String toString() {\r
+            return "ACTIVE_FILTER";\r
+        }\r
+    };\r
+\r
+    public static final QueryKey<Collection<ViewpointContribution>> VIEWPOINT_CONTRIBUTIONS = new QueryKey<Collection<ViewpointContribution>>() {\r
+        @Override\r
+        public String toString() {\r
+            return "VIEWPOINT_CONTRIBUTIONS";\r
+        }\r
+    };\r
+\r
+    /**\r
+     * A query for all available viewpoint factories for the current input.\r
+     * <p>\r
+     * Depends on: {@link #INPUT}\r
+     * <p>\r
+     * Returns: a non-null collection\r
+     */\r
+    public static final QueryKey<Collection<ViewpointFactory>> VIEWPOINT_FACTORIES = new QueryKey<Collection<ViewpointFactory>>() {\r
+        @Override\r
+        public String toString() {\r
+            return "VIEWPOINT_FACTORIES";\r
+        }\r
+    };\r
+\r
+    public static class SelectedViewpointFactoryKey extends ParametrizedPrimitiveQueryKey<ViewpointFactory> {\r
+        public SelectedViewpointFactoryKey(Collection<ViewpointFactory> factories) {\r
+            super(factories);\r
+            assert factories != null;\r
+        }\r
+        @Override\r
+        public String getKeyName() {\r
+            return "SELECTED_VIEWPOINT_FACTORY";\r
+        }\r
+    };\r
+\r
+    public static class ViewpointKey extends ParametrizedPrimitiveQueryKey<Viewpoint> {\r
+        public ViewpointKey(ViewpointFactory factory) {\r
+            super(factory);\r
+            assert factory != null;\r
+        }\r
+        @Override\r
+        public String getKeyName() {\r
+            return "VIEWPOINT";\r
+        }\r
+    };\r
+\r
+    public static class ViewpointContributionKey extends ParametrizedPrimitiveQueryKey<ViewpointContribution> {\r
+        public ViewpointContributionKey(ViewpointContributionFactory factory) {\r
+            super(factory);\r
+            assert factory != null;\r
+        }\r
+        @Override\r
+        public String getKeyName() {\r
+            return "VIEWPOINT_CONTRIBUTION";\r
+        }\r
+    };\r
+\r
+    /**\r
+     * Used by <code>GraphExplorer.setTextAndImage</code>.\r
+     */\r
+    public static final QueryKey<Collection<LabelDecoratorFactory>> LABEL_DECORATOR_FACTORIES = new QueryKey<Collection<LabelDecoratorFactory>>() {\r
+        @Override\r
+        public String toString() {\r
+            return "LABEL_DECORATOR_FACTORIES";\r
+        }\r
+    };\r
+    /**\r
+     * Used by <code>GraphExplorer.setTextAndImage</code>.\r
+     */\r
+    public static final QueryKey<Collection<LabelDecorator>> LABEL_DECORATORS = new QueryKey<Collection<LabelDecorator>>() {\r
+        @Override\r
+        public String toString() {\r
+            return "LABEL_DECORATORS";\r
+        }\r
+    };\r
+    /**\r
+     * Used by <code>GraphExplorer.setTextAndImage</code>.\r
+     */\r
+    public static final QueryKey<Collection<ImageDecoratorFactory>> IMAGE_DECORATOR_FACTORIES = new QueryKey<Collection<ImageDecoratorFactory>>() {\r
+        @Override\r
+        public String toString() {\r
+            return "IMAGE_DECORATOR_FACTORIES";\r
+        }\r
+    };\r
+    /**\r
+     * Used by <code>GraphExplorer.setTextAndImage</code>.\r
+     */\r
+    public static final QueryKey<Collection<ImageDecorator>> IMAGE_DECORATORS = new QueryKey<Collection<ImageDecorator>>() {\r
+        @Override\r
+        public String toString() {\r
+            return "IMAGE_DECORATORS";\r
+        }\r
+    };\r
+\r
+    public static final QueryKey<Labeler> SELECTED_LABELER = new QueryKey<Labeler>() {\r
+        @Override\r
+        public String toString() {\r
+            return "SELECTED_LABELER";\r
+        }\r
+    };\r
+\r
+    public static final QueryKey<Imager> SELECTED_IMAGER = new QueryKey<Imager>() {\r
+        @Override\r
+        public String toString() {\r
+            return "SELECTED_IMAGER";\r
+        }\r
+    };\r
+\r
+    public static final QueryKey<Collection<LabelDecoratorFactory>> SELECTED_LABEL_DECORATOR_FACTORIES = new QueryKey<Collection<LabelDecoratorFactory>>() {\r
+        @Override\r
+        public String toString() {\r
+            return "SELECTED_LABEL_DECORATOR_FACTORIES";\r
+        }\r
+    };\r
+\r
+    public static final QueryKey<Collection<ImageDecoratorFactory>> SELECTED_IMAGE_DECORATOR_FACTORIES = new QueryKey<Collection<ImageDecoratorFactory>>() {\r
+        @Override\r
+        public String toString() {\r
+            return "SELECTED_IMAGE_DECORATOR_FACTORIES";\r
+        }\r
+    };\r
+\r
+    /**\r
+     * A query for all available labeler factories for the current input.\r
+     * <p>\r
+     * Depends on: {@link #INPUT}\r
+     * <p>\r
+     * Returns: a non-null collection\r
+     */\r
+    public static final QueryKey<Collection<LabelerFactory>> LABELER_FACTORIES = new QueryKey<Collection<LabelerFactory>>() {\r
+        @Override\r
+        public String toString() {\r
+            return "LABELER_FACTORIES";\r
+        }\r
+    };\r
+\r
+    /**\r
+     * A query for all available imager factories for the current input.\r
+     * <p>\r
+     * Depends on: {@link #INPUT}\r
+     * <p>\r
+     * Returns: a non-null collection\r
+     */\r
+    public static final QueryKey<Collection<ImagerFactory>> IMAGER_FACTORIES = new QueryKey<Collection<ImagerFactory>>() {\r
+        @Override\r
+        public String toString() {\r
+            return "IMAGER_FACTORIES";\r
+        }\r
+    };\r
+\r
+    public static class LabelerKey extends ParametrizedPrimitiveQueryKey<Labeler> {\r
+        public LabelerKey(LabelerFactory factory) {\r
+            super(factory);\r
+            assert factory != null;\r
+        }\r
+        @Override\r
+        public String getKeyName() {\r
+            return "LABELER";\r
+        }\r
+    };\r
+\r
+    public static class CheckedStateKey extends ParametrizedPrimitiveQueryKey<CheckedState> {\r
+        public CheckedStateKey(CheckedStateFactory factory) {\r
+            super(factory);\r
+            assert factory != null;\r
+        }\r
+        @Override\r
+        public String getKeyName() {\r
+            return "CHECK_STATE";\r
+        }\r
+    };\r
+\r
+    public static class LabelDecoratorKey extends ParametrizedPrimitiveQueryKey<LabelDecorator> {\r
+        public LabelDecoratorKey(LabelDecoratorFactory factory) {\r
+            super(factory);\r
+            assert factory != null;\r
+        }\r
+        @Override\r
+        public String getKeyName() {\r
+            return "LABEL_DECORATOR";\r
+        }\r
+    };\r
+\r
+    public static class ImagerKey extends ParametrizedPrimitiveQueryKey<Imager> {\r
+        public ImagerKey(ImagerFactory factory) {\r
+            super(factory);\r
+            assert factory != null;\r
+        }\r
+        @Override\r
+        public String getKeyName() {\r
+            return "IMAGER";\r
+        }\r
+    };\r
+\r
+    public static class ImageDecoratorKey extends ParametrizedPrimitiveQueryKey<ImageDecorator> {\r
+        public ImageDecoratorKey(ImageDecoratorFactory factory) {\r
+            super(factory);\r
+            assert factory != null;\r
+        }\r
+        @Override\r
+        public String getKeyName() {\r
+            return "IMAGE_DECORATOR";\r
+        }\r
+    };\r
+\r
+    /**\r
+     * A query that returns a collection of {@link SelectionRequest}s based on\r
+     * the current input. The selection requests are used to dictate whether a\r
+     * child INodeContext of the input INodeContext gets filtered out from the\r
+     * result of the {@link #PRUNED_CHILDREN} query.\r
+     * \r
+     * <p>\r
+     * The query is free to return <code>null</code> if there are no filters for\r
+     * the query input.\r
+     * </p>\r
+     */\r
+    public static final PrimitiveQueryKey<Collection<SelectionRequest>> SELECTION_REQUESTS = new PrimitiveQueryKey<Collection<SelectionRequest>>() {\r
+        @Override\r
+        public String toString() {\r
+            return "SELECTION_REQUEST";\r
+        }\r
+    };\r
+\r
+    //------------------------------------------------------------------------\r
+\r
+    /**\r
+     * A query that requests for the currently selected viewpoint of a node\r
+     * context, gets all of its children from the viewpoint and prunes the set\r
+     * of children based on active filters (selection requests).\r
+     * <p>\r
+     * Depends on: {@link #SELECTED_VIEWPOINT}, {@link #SELECTION_REQUESTS}\r
+     * <p>\r
+     * Returns: A {@link PrunedChildrenResult} which contains the pruned set of\r
+     * children as INodeContext[] and the original amount of children before\r
+     * pruning them.\r
+     */\r
+    public static final QueryKey<PrunedChildrenResult> PRUNED_CHILDREN = new QueryKey<PrunedChildrenResult>() {\r
+        @Override\r
+        public String toString() {\r
+            return "PRUNED_CHILDREN";\r
+        }\r
+    };\r
+\r
+    /**\r
+     * A query to transform INodeContext's into ComparableContexts that can be\r
+     * sorted.\r
+     * <p>\r
+     * Depends on: {@link #PRUNED_CHILDREN}\r
+     * <p>\r
+     * Returns: ComparableContext[] of the same size as the input or\r
+     * <code>null</code> if no selected ComparableFactory could be discovered\r
+     * which indicates that child nodes cannot be sorted.\r
+     */\r
+    public static final QueryKey<ComparableContext[]> COMPARABLE_CHILDREN = new QueryKey<ComparableContext[]>() {\r
+        @Override\r
+        public String toString() {\r
+            return "COMPARABLE_CHILDREN";\r
+        }\r
+    };\r
+\r
+    /**\r
+     * A query for all available comparable factories for the current input.\r
+     * <p>\r
+     * Depends on: {@link #INPUT}\r
+     * <p>\r
+     * Returns: a non-null collection\r
+     */\r
+    public static final QueryKey<Collection<ComparableContextFactory>> COMPARABLE_FACTORIES = new QueryKey<Collection<ComparableContextFactory>>() {\r
+        @Override\r
+        public String toString() {\r
+            return "COMPARABLE_FACTORIES";\r
+        }\r
+    };\r
+\r
+    public static class SelectedComparableFactoryKey extends ParametrizedPrimitiveQueryKey<ComparableContextFactory> {\r
+        public SelectedComparableFactoryKey(Collection<ComparableContextFactory> factories) {\r
+            super(factories);\r
+            assert factories != null;\r
+        }\r
+        @Override\r
+        public String getKeyName() {\r
+            return "SELECTED_COMPARABLE_FACTORY";\r
+        }\r
+    }\r
+\r
+    /**\r
+     * Returns the final child nodes for a node after pruning and sorting them.\r
+     * If you need to discover the set of children for a node you should use\r
+     * {@link BuiltinKeys#PRUNED_CHILDREN} instead if you don't need the\r
+     * sorting. To get the non-pruned set of all children of a node\r
+     * <p>\r
+     * Depends on: {@link BuiltinKeys#COMPARABLE_CHILDREN},\r
+     * {@link BuiltinKeys#PRUNED_CHILDREN}\r
+     * <p>\r
+     * Returns: an array of {@link NodeContext}s.\r
+     */\r
+    public static final QueryKey<NodeContext[]> FINAL_CHILDREN = new QueryKey<NodeContext[]>() {\r
+        @Override\r
+        public String toString() {\r
+            return "FINAL_CHILDREN";\r
+        }\r
+    };\r
+\r
+    /**\r
+     * Returns whether a node is expanded in the UI or not.\r
+     * <p>\r
+     * Returns: {@link Boolean#TRUE} if expanded, {@link Boolean#FALSE} if not.\r
+     */\r
+    public static final PrimitiveQueryKey<Boolean> IS_EXPANDED = new PrimitiveQueryKey<Boolean>() {\r
+        @Override\r
+        public String toString() {\r
+            return "IS_EXPANDED";\r
+        }\r
+    };\r
+\r
+    /**\r
+     * Tells whether a node is "checked" in the UI or not. This only takes\r
+     * effect if the GraphExplorer was created with support for checkedness\r
+     * visualisation.\r
+     * <p>\r
+     * Returns: {@link CheckedState}\r
+     */\r
+    public static final QueryKey<CheckedState> IS_CHECKED = new QueryKey<CheckedState>() {\r
+        @Override\r
+        public String toString() {\r
+            return "IS_CHECKED";\r
+        }\r
+    };\r
+\r
+    /**\r
+     * Returns how many children should maximally be shown for a node. By\r
+     * default the set of shown children is pruned if there are too many of them\r
+     * to be shown.\r
+     * <p>\r
+     * Returns:\r
+     * <ul>\r
+     * <li>0 < x &le; {@value Integer#MAX_VALUE} to tell the maximum amount of\r
+     * children to show</li>\r
+     * <li><code>null</code> indicates don't care</li>\r
+     * </ul>\r
+     * May not return < 0.\r
+     */\r
+    public static final PrimitiveQueryKey<Integer> SHOW_MAX_CHILDREN = new PrimitiveQueryKey<Integer>() {\r
+        @Override\r
+        public String toString() {\r
+            return "SHOW_MAX_CHILDREN";\r
+        }\r
+    };\r
+\r
+    public static class IsRootKey implements ConstantKey<Object> {\r
+        private IsRootKey() {}\r
+        @Override\r
+        public String toString() {\r
+            return "IS_ROOT";\r
+        }\r
+    };\r
+\r
+    /**\r
+     * Set to {@link Boolean#TRUE} for a NodeContext that describes the root\r
+     * input of a {@link GraphExplorer}.\r
+     */\r
+    public static final ConstantKey<Object> IS_ROOT = new IsRootKey();\r
+\r
+}\r