]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/modelBrowser/model/Module.java
Migrated source code from Simantics SVN
[simantics/platform.git] / bundles / org.simantics.modeling.ui / src / org / simantics / modeling / ui / modelBrowser / model / Module.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.content.Labeler.Modifier;\r
20 import org.simantics.db.ReadGraph;\r
21 import org.simantics.db.Resource;\r
22 import org.simantics.db.Session;\r
23 import org.simantics.db.WriteGraph;\r
24 import org.simantics.db.common.ResourceArray;\r
25 import org.simantics.db.exception.DatabaseException;\r
26 import org.simantics.modeling.ui.Activator;\r
27 import org.simantics.utils.ObjectUtils;\r
28 \r
29 @Deprecated\r
30 public class Module implements INode, Comparable<Module> {\r
31 \r
32     public String label;\r
33     public Resource resource;\r
34     ModuleParent parent;\r
35 \r
36     public Module(String label, Resource resource, ModuleParent parent) {\r
37         this.label = label;\r
38         this.resource = resource;\r
39         this.parent = parent;\r
40     }\r
41 \r
42     @Override\r
43     public Collection<?> getChildren(ReadGraph g) {\r
44         return Collections.emptyList();\r
45     }\r
46 \r
47     @Override\r
48     public ImageDescriptor getImage(ReadGraph g) {\r
49         return Activator.BULLET_GREEN_ICON;\r
50     }\r
51 \r
52     @Override\r
53     public String getLabel(ReadGraph g) {\r
54         return label;\r
55     }\r
56 \r
57     @Override\r
58     public boolean equals(Object obj) {\r
59         if (this == obj)\r
60             return true;\r
61         if (obj == null)\r
62             return false;\r
63         if (!getClass().equals(obj.getClass()))\r
64             return false;\r
65         Module other = (Module)obj;\r
66         return label.equals(other.label) && resource.equals(other.resource) && ObjectUtils.objectEquals(parent, other.parent);\r
67     }\r
68 \r
69     @Override\r
70     public int hashCode() {\r
71         return (label.hashCode() * 31 + resource.hashCode()) * 31 + ObjectUtils.hashCode(parent);\r
72     }\r
73 \r
74     @Override\r
75     public Modifier getModifier(final Session session, String columnId) {\r
76         return null;\r
77     }\r
78 \r
79     @Override\r
80     public int getCategory(ReadGraph graph) {\r
81         return 0;\r
82     }\r
83 \r
84     @Override\r
85     public void handleDrop(Session session, ISelection selection) {\r
86     }\r
87 \r
88     @Override\r
89     public void handleDelete(WriteGraph graph) throws DatabaseException {\r
90     }\r
91 \r
92     @Override\r
93     public boolean hasChildren(ReadGraph graph) {\r
94         return false;\r
95     }\r
96 \r
97     @SuppressWarnings("unchecked")\r
98     @Override\r
99     public Object getAdapter(Class adapter) {\r
100         if (adapter == Resource.class)\r
101             return resource;\r
102         if (adapter == ResourceArray.class) {\r
103             int len = 1;\r
104             for (ModuleParent parent = this.parent; parent != null; parent = parent.parent, ++len);\r
105             Resource[] result = new Resource[len];\r
106             result[0] = resource;\r
107             ModuleParent parent = this.parent;\r
108             for (int i = 1; i < len; ++i) {\r
109                 result[i] = parent.resource;\r
110                 parent = parent.parent;\r
111             }\r
112             return new ResourceArray(result);\r
113         }\r
114         return null;\r
115     }\r
116 \r
117     @Override\r
118     public int compareTo(Module arg0) {\r
119         return label.compareTo(arg0.label);\r
120     }\r
121 \r
122 }\r