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
10 * VTT Technical Research Centre of Finland - initial API and implementation
\r
11 *******************************************************************************/
\r
12 package org.simantics.modeling.ui.modelBrowser.model;
\r
14 import java.util.ArrayList;
\r
15 import java.util.Collection;
\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
26 public class Interface extends Node {
\r
28 Resource instance; // may be null
\r
31 public Interface(Resource resource, Resource instance, boolean isLeaf) {
\r
33 this.instance = instance;
\r
34 this.isLeaf = isLeaf;
\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
51 public ImageDescriptor getImage(ReadGraph g) {
\r
52 return Activator.INTERFACE_ICON;
\r
56 public String getLabel(ReadGraph g) throws DatabaseException {
\r
57 return "Interface [" + getChildren(g).size() + "]";
\r
61 public boolean equals(Object obj) {
\r
66 if(!getClass().equals(obj.getClass()))
\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
75 public int hashCode() {
\r
76 return (getClass().hashCode()*31 + (instance == null ? 0 : instance.hashCode()))*31 + resource.hashCode();
\r