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