X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.diagram%2Fsrc%2Forg%2Fsimantics%2Fdiagram%2Fadapter%2FTypeGroup.java;h=7e4cb0e37bc7d448eb3a79fea764a4bcc6d908bf;hb=e3f46ffc9d4a6930adc83ebb8e6730f19708cc94;hp=8e2db2488381c4caf6dbb137f34e6425b080ecc5;hpb=0ae2b770234dfc3cbb18bd38f324125cf0faca07;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.diagram/src/org/simantics/diagram/adapter/TypeGroup.java b/bundles/org.simantics.diagram/src/org/simantics/diagram/adapter/TypeGroup.java index 8e2db2488..7e4cb0e37 100644 --- a/bundles/org.simantics.diagram/src/org/simantics/diagram/adapter/TypeGroup.java +++ b/bundles/org.simantics.diagram/src/org/simantics/diagram/adapter/TypeGroup.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * Copyright (c) 2007, 2018 Association for Decentralized Information Management * in Industry THTH ry. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 @@ -29,17 +29,21 @@ import org.simantics.db.procedure.SetListener; import org.simantics.diagram.stubs.DiagramResource; import org.simantics.layer0.Layer0; import org.simantics.scenegraph.profile.Group; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** * @author Tuukka Lehtonen */ public class TypeGroup implements Group { + private static final Logger LOGGER = LoggerFactory.getLogger(TypeGroup.class); + private final Collection types; private final String name; public TypeGroup(String name, Resource type) { - this(name); + this(name, new Resource[] { type }); } public TypeGroup(String name, Resource... types) { @@ -47,6 +51,26 @@ public class TypeGroup implements Group { this.name = name; } + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + types.hashCode(); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + TypeGroup other = (TypeGroup) obj; + return types.equals(other.types); + } + /** * Initialize TypeGroup from a DIAGRAM.Group instance. * @@ -63,13 +87,13 @@ public class TypeGroup implements Group { } @Override - public void trackItems(RequestProcessor processor, final Resource runtimeDiagram, final SetListener listener) { + public void trackItems(RequestProcessor processor, final Resource runtimeDiagram, final SetListener listener) throws DatabaseException { if (types.isEmpty()) { System.out.println("TypeGroup has no types!"); return; } - processor.asyncRequest(new BinaryRead, Collection>(runtimeDiagram, types) { + processor.syncRequest(new BinaryRead, Collection>(runtimeDiagram, types) { @Override public Set perform(ReadGraph graph) throws DatabaseException { @@ -83,14 +107,17 @@ public class TypeGroup implements Group { // for (Resource t : types) // System.out.println("\t" + NameUtils.getSafeName(graph, t, true)); - Collection elements = graph.syncRequest(new OrderedSet(realDiagram)); - for (Resource element : elements) { -// System.out.println("checking element " + NameUtils.getSafeName(graph, element, true)); - Collection elementTypes = graph.getTypes(element); - if (!Collections.disjoint(types, elementTypes)) - result.add(element); + if (graph.hasStatement(realDiagram)) { + Collection elements = graph.syncRequest(new OrderedSet(realDiagram)); + for (Resource element : elements) { + // System.out.println("checking element " + NameUtils.getSafeName(graph, element, true)); + Collection elementTypes = graph.getTypes(element); + if (!Collections.disjoint(types, elementTypes)) + result.add(element); + } + } else { + LOGGER.warn("Most likely after deleting a diagram or something therefore no ordered set can be found for {}", realDiagram); } - return result; }