/******************************************************************************* * Copyright (c) 2007, 2010 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 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: * VTT Technical Research Centre of Finland - initial API and implementation *******************************************************************************/ package org.simantics.diagram.symbolcontribution; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; import java.util.Comparator; import org.simantics.databoard.Bindings; import org.simantics.db.ReadGraph; import org.simantics.db.Resource; import org.simantics.db.common.request.BinaryRead; import org.simantics.db.common.request.ObjectsWithSupertype; import org.simantics.db.common.utils.NameUtils; import org.simantics.db.exception.DatabaseException; import org.simantics.diagram.stubs.DiagramResource; import org.simantics.diagram.symbollibrary.ISymbolGroup; import org.simantics.diagram.symbollibrary.ISymbolItem; import org.simantics.layer0.Layer0; /** * A basic SymbolProviderFactory implementation for the graph database. It is * capable of loading an ISymbolProvider from BasicSymbolContribution instances * like the following: * *
* _ : DIA.BasicSymbolContribution * DIA.BasicSymbolContributionHasSymbolLibrary * MySymbolLibrary1 * MySymbolLibrary2 ** * @author Tuukka Lehtonen */ public class BasicSymbolProviderFactory implements SymbolProviderFactory { Resource contribution; Resource diagram; public BasicSymbolProviderFactory(Resource contribution, Resource diagram) { this.contribution = contribution; this.diagram = diagram; } @Override public int hashCode() { final int prime = 31; int result = 1; result = prime * result + ((contribution == null) ? 0 : contribution.hashCode()); result = prime * result + ((diagram == null) ? 0 : diagram.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; BasicSymbolProviderFactory other = (BasicSymbolProviderFactory) obj; if (contribution == null) { if (other.contribution != null) return false; } else if (!contribution.equals(other.contribution)) return false; if (diagram == null) { if (other.diagram != null) return false; } else if (!diagram.equals(other.diagram)) return false; return true; } @Override public ISymbolProvider create(ReadGraph g) throws DatabaseException { return g.syncRequest(new LoadRequest(contribution, diagram)); } /* * Note: this cannot be ResourceRead since it must never be * classified as immutable because of possible dynamic filters */ static class LoadRequest extends BinaryRead