]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/modelBrowser/model/Interface.java
Migrated source code from Simantics SVN
[simantics/platform.git] / bundles / org.simantics.modeling.ui / src / org / simantics / modeling / ui / modelBrowser / model / Interface.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.ArrayList;\r
15 import java.util.Collection;\r
16 \r
17 import org.eclipse.jface.resource.ImageDescriptor;\r
18 import org.simantics.db.ReadGraph;\r
19 import org.simantics.db.Resource;\r
20 import org.simantics.db.exception.DatabaseException;\r
21 import org.simantics.modeling.ui.Activator;\r
22 import org.simantics.structural.stubs.StructuralResource2;\r
23 import org.simantics.structural2.utils.StructuralUtils;\r
24 \r
25 @Deprecated\r
26 public class Interface extends Node {\r
27         \r
28         Resource instance; // may be null\r
29         boolean isLeaf;\r
30         \r
31         public Interface(Resource resource, Resource instance, boolean isLeaf) {\r
32                 super(resource);\r
33                 this.instance = instance;\r
34                 this.isLeaf = isLeaf;\r
35         }\r
36 \r
37         @Override\r
38         public Collection<?> getChildren(ReadGraph g) throws DatabaseException {\r
39                 Collection<Resource> resources = \r
40                         StructuralUtils.getPropertyRelations(g, resource);\r
41                 Collection<INode> nodes = new ArrayList<INode>(resources.size());\r
42                 StructuralResource2 sr = StructuralResource2.getInstance(g);\r
43                 for(Resource r : resources) {\r
44                         if (g.hasStatement(resource, sr.Binds))\r
45                                 nodes.add(new Parameter(g, r, instance, isLeaf));\r
46                 }\r
47                 return nodes;\r
48         }\r
49 \r
50         @Override\r
51         public ImageDescriptor getImage(ReadGraph g) {\r
52                 return Activator.INTERFACE_ICON;\r
53         }\r
54         \r
55         @Override\r
56         public String getLabel(ReadGraph g) throws DatabaseException {\r
57                 return "Interface [" + getChildren(g).size() + "]";\r
58         }\r
59         \r
60         @Override\r
61         public boolean equals(Object obj) {\r
62                 if(this == obj)\r
63                         return true;\r
64                 if(obj == null)\r
65                         return false;\r
66                 if(!getClass().equals(obj.getClass()))\r
67                         return false;\r
68                 Interface other = (Interface)obj;\r
69                 return resource.equals(other.resource)\r
70                         && (instance == null ? other.instance==null : instance.equals(other.instance))\r
71                         && isLeaf == other.isLeaf;\r
72         }\r
73         \r
74         @Override\r
75         public int hashCode() {\r
76                 return (getClass().hashCode()*31 + (instance == null ? 0 : instance.hashCode()))*31 + resource.hashCode();\r
77         }\r
78 \r
79 }\r