package org.simantics.diagram.symbolcontribution; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Status; import org.simantics.db.ReadGraph; import org.simantics.db.Resource; import org.simantics.db.common.primitiverequest.PossibleAdapter; import org.simantics.db.common.procedure.adapter.TransientCacheAsyncListener; import org.simantics.db.exception.DatabaseException; import org.simantics.diagram.internal.Activator; import org.simantics.diagram.stubs.DiagramResource; /** * @author Tuukka Lehtonen */ public class SymbolProviderFactories { public static boolean accept(ReadGraph graph, DiagramResource DIA, Resource contribution, Resource diagram) throws DatabaseException { String name = graph.getPossibleAdapter(contribution, String.class); if (name == null) return false; for (Resource filterR : graph.getObjects(contribution, DIA.HasSymbolContributionFilter)) { try { SymbolContributionFilter filter = graph.syncRequest( new PossibleAdapter(filterR, SymbolContributionFilter.class), TransientCacheAsyncListener. instance()); if (filter == null || !filter.accept(graph, contribution, filterR, diagram)) { return false; } } catch (DatabaseException e) { // If any errors happen when requesting for the filter, we can // only assume that the graph related to their definitions is // somehow corrupted. In this case we must assume that the filter // did not pass since it did not work properly and true checking // could not be performed to completion. Activator.getDefault().getLog().log(new Status(IStatus.ERROR, Activator.PLUGIN_ID, "Filter " + filterR + " testing failed", e)); return false; } } return true; } }