import org.eclipse.core.runtime.SubMonitor;
import org.simantics.Simantics;
import org.simantics.db.Issue;
+import org.simantics.db.ReadGraph;
import org.simantics.db.Resource;
import org.simantics.db.Session;
+import org.simantics.db.Statement;
import org.simantics.db.VirtualGraph;
import org.simantics.db.WriteGraph;
import org.simantics.db.common.request.WriteRequest;
return result;
}
+ /**
+ * Checks if the specified <code>resourceToCheckForLinks</code> is linked to
+ * anything else besides itself and <code>excludeLinksTo</code>.
+ *
+ * <p>
+ * This is used to if an issue context is still valid. We consider any issue
+ * context that is not attached to something else besides its issue context to
+ * be an invalid issue. Assertions and L0.InstanceOf do not count as external
+ * links.
+ *
+ * @param graph database access handle
+ * @param resourceToCheckForLinks the resource to check for "external" links
+ * @param excludeLinksTo exclude links to this resource from evaluation
+ * @return <code>true</code> if there are links, <code>false</code> otherwise
+ * @throws DatabaseException
+ */
+ public static boolean isLinkedToOtherThan(ReadGraph graph, Resource resourceToCheckForLinks,
+ Resource excludeLinksTo)
+ throws DatabaseException
+ {
+ Layer0 L0 = Layer0.getInstance(graph);
+ for (Statement stm : graph.getStatements(resourceToCheckForLinks, L0.IsWeaklyRelatedTo)) {
+ if (stm.isAsserted(resourceToCheckForLinks))
+ continue;
+ if (stm.getPredicate().equals(L0.InstanceOf))
+ continue;
+ Resource o = stm.getObject();
+ if (o.equals(excludeLinksTo) || o.equals(resourceToCheckForLinks))
+ continue;
+
+ return true;
+ }
+ return false;
+ }
+
}