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