]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.browsing.ui.model/src/org/simantics/browsing/ui/model/nodetypes/NodeType.java
Migrated source code from Simantics SVN
[simantics/platform.git] / bundles / org.simantics.browsing.ui.model / src / org / simantics / browsing / ui / model / nodetypes / NodeType.java
1 /*******************************************************************************\r
2  * Copyright (c) 2010, 2011 Association for Decentralized Information Management in\r
3  * 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
8  *\r
9  * Contributors:\r
10  *     VTT Technical Research Centre of Finland - initial API and implementation\r
11  *******************************************************************************/\r
12 package org.simantics.browsing.ui.model.nodetypes;\r
13 \r
14 import java.util.Collection;\r
15 \r
16 import org.simantics.browsing.ui.BuiltinKeys;\r
17 import org.simantics.browsing.ui.NodeContext;\r
18 import org.simantics.browsing.ui.NodeContext.ConstantKey;\r
19 import org.simantics.db.ReadGraph;\r
20 import org.simantics.db.exception.DatabaseException;\r
21 import org.simantics.ui.selection.WorkbenchSelectionElement;\r
22 \r
23 /**\r
24  * Node type specifies the content type and role of the node in \r
25  * the model browser.\r
26  * @author Hannu Niemistö\r
27  */\r
28 public interface NodeType {\r
29 \r
30     public static class TypeKey implements ConstantKey<NodeType> {\r
31         private TypeKey() {}\r
32         @Override\r
33         public String toString() {\r
34             return "TYPE";\r
35         }\r
36     };\r
37     public static final ConstantKey<NodeType> TYPE = new TypeKey();\r
38 \r
39     public static final ConstantKey<?>[] KEY_SEQUENCE = new ConstantKey<?>[] {\r
40         BuiltinKeys.INPUT,\r
41         TYPE\r
42     };\r
43 \r
44     public static final ConstantKey<?>[] KEY_SEQUENCE_EXT = new ConstantKey<?>[] {\r
45         BuiltinKeys.INPUT,\r
46         TYPE,\r
47         BuiltinKeys.UI_CONTEXT,\r
48         BuiltinKeys.BROWSE_CONTEXT,\r
49         BuiltinKeys.ACTION_BROWSE_CONTEXT\r
50     };\r
51     \r
52     /**\r
53      * Creates a node context from the content. If the content is not\r
54      * suitable for this node type, returns null. This method cannot\r
55      * assume anything about the Java type of the content given as\r
56      * a parameter, but if it returns a node its content must be \r
57      * an instance of the Java class given by getContentType.\r
58      */\r
59     NodeContext createNodeContext(ReadGraph graph, Object content) throws DatabaseException;\r
60     \r
61     /**\r
62      * Returns the expected Java type of the content.\r
63      */\r
64     Class<?> getContentType();\r
65     \r
66     /**\r
67      * Tests if this node type inherits (or is equal to) given node type.\r
68      */\r
69     boolean inherits(ReadGraph graph, NodeType superType) throws DatabaseException;\r
70 \r
71     Collection<NodeType> getSuper(ReadGraph g) throws DatabaseException;\r
72 \r
73     String toString(ReadGraph graph) throws DatabaseException; \r
74     \r
75     WorkbenchSelectionElement getWorkbenchSelectionElement(NodeContext context);\r
76 }\r