]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/modelBrowser/model/Node.java
Migrated source code from Simantics SVN
[simantics/platform.git] / bundles / org.simantics.modeling.ui / src / org / simantics / modeling / ui / modelBrowser / model / Node.java
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
8  *\r
9  * Contributors:\r
10  *     VTT Technical Research Centre of Finland - initial API and implementation\r
11  *******************************************************************************/\r
12 package org.simantics.modeling.ui.modelBrowser.model;\r
13 \r
14 import java.util.Collection;\r
15 import java.util.Collections;\r
16 \r
17 import org.eclipse.jface.resource.ImageDescriptor;\r
18 import org.eclipse.jface.viewers.ISelection;\r
19 import org.simantics.browsing.ui.common.node.IDropTargetNode;\r
20 import org.simantics.browsing.ui.content.Labeler.Modifier;\r
21 import org.simantics.browsing.ui.graph.impl.LabelerUtil;\r
22 import org.simantics.db.ReadGraph;\r
23 import org.simantics.db.Resource;\r
24 import org.simantics.db.Session;\r
25 import org.simantics.db.WriteGraph;\r
26 import org.simantics.db.exception.DatabaseException;\r
27 import org.simantics.db.layer0.util.RemoverUtil;\r
28 import org.simantics.layer0.Layer0;\r
29 import org.simantics.ui.SimanticsUI;\r
30 \r
31 @Deprecated\r
32 public class Node implements INode, IDropTargetNode {\r
33 \r
34     protected Resource resource;\r
35 \r
36     public Node(Resource resource) {\r
37         assert resource != null;\r
38         this.resource = resource;\r
39     }\r
40 \r
41     public Resource getResource() {\r
42         return resource;\r
43     }\r
44 \r
45     @Override\r
46     public String getLabel(ReadGraph g) throws DatabaseException {\r
47         return LabelerUtil.safeStringRepresentation(g, resource);\r
48     }\r
49 \r
50     @Override\r
51     public ImageDescriptor getImage(ReadGraph graph) throws DatabaseException {\r
52         return ImageDescriptor.getMissingImageDescriptor();\r
53     }\r
54 \r
55     @Override\r
56     public int getCategory(ReadGraph graph) throws DatabaseException {\r
57         return 0;\r
58     }\r
59 \r
60     @Override\r
61     public Modifier getModifier(Session session, String columnId) {\r
62         return null;\r
63     }\r
64 \r
65     @Override\r
66     public Collection<?> getChildren(ReadGraph graph) throws DatabaseException {\r
67         return Collections.emptyList();\r
68     }\r
69 \r
70     @Override\r
71     public boolean hasChildren(ReadGraph g) throws DatabaseException {\r
72         return !getChildren(g).isEmpty();\r
73     }\r
74 \r
75     @Override\r
76     public Object getAdapter(Class adapter) {\r
77         if (adapter == Resource.class)\r
78             return resource;\r
79         return null;\r
80     }\r
81 \r
82     @Override\r
83     public boolean equals(Object obj) {\r
84         if(this == obj)\r
85             return true;\r
86         if(obj == null)\r
87             return false;\r
88         return getClass().equals(obj.getClass()) && resource.equals(((Node)obj).resource);\r
89     }\r
90 \r
91     @Override\r
92     public int hashCode() {\r
93         return getClass().hashCode()*31 + resource.hashCode();\r
94     }\r
95 \r
96     @Override\r
97     public void handleDrop(Session session, ISelection data) {\r
98     }\r
99 \r
100     /**\r
101      * For backwards compatibility with the new model browser and browsing framework.\r
102      */\r
103     @Override\r
104     public void drop(Object data) {\r
105         if (data instanceof ISelection) {\r
106             handleDrop(SimanticsUI.getSession(), (ISelection) data);\r
107         }\r
108     }\r
109 \r
110     @Override\r
111     public void handleDelete(WriteGraph graph) throws DatabaseException {\r
112         Layer0 l0 = Layer0.getInstance(graph);\r
113         graph.deny(resource, l0.PartOf);\r
114         RemoverUtil.remove(graph, resource);\r
115     }\r
116 \r
117 }\r