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