X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=blobdiff_plain;f=bundles%2Forg.simantics.diagram%2Fsrc%2Forg%2Fsimantics%2Fdiagram%2Fsymbolcontribution%2FIndexRootSymbolProviderFactory.java;h=b0c28da10142fab393889f3b1e27af59c51fd674;hp=da9c542a1f71de357f56b51d03d2fa3af2739454;hb=HEAD;hpb=969bd23cab98a79ca9101af33334000879fb60c5 diff --git a/bundles/org.simantics.diagram/src/org/simantics/diagram/symbolcontribution/IndexRootSymbolProviderFactory.java b/bundles/org.simantics.diagram/src/org/simantics/diagram/symbolcontribution/IndexRootSymbolProviderFactory.java index da9c542a1..b0c28da10 100644 --- a/bundles/org.simantics.diagram/src/org/simantics/diagram/symbolcontribution/IndexRootSymbolProviderFactory.java +++ b/bundles/org.simantics.diagram/src/org/simantics/diagram/symbolcontribution/IndexRootSymbolProviderFactory.java @@ -1,109 +1,109 @@ -/******************************************************************************* - * 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 org.simantics.db.ReadGraph; -import org.simantics.db.Resource; -import org.simantics.db.common.request.BinaryRead; -import org.simantics.db.exception.DatabaseException; -import org.simantics.db.layer0.adapter.Instances; -import org.simantics.diagram.stubs.DiagramResource; -import org.simantics.diagram.symbollibrary.ISymbolGroup; -import org.simantics.layer0.Layer0; - -/** - * - * @author Antti Villberg - */ -public class IndexRootSymbolProviderFactory implements SymbolProviderFactory { - - Resource indexRoot; - Resource diagram; - - public IndexRootSymbolProviderFactory(Resource indexRoot, Resource diagram) { - this.indexRoot = indexRoot; - this.diagram = diagram; - } - - @Override - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + ((diagram == null) ? 0 : diagram.hashCode()); - result = prime * result + ((indexRoot == null) ? 0 : indexRoot.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; - IndexRootSymbolProviderFactory other = (IndexRootSymbolProviderFactory) obj; - if (diagram == null) { - if (other.diagram != null) - return false; - } else if (!diagram.equals(other.diagram)) - return false; - if (indexRoot == null) { - if (other.indexRoot != null) - return false; - } else if (!indexRoot.equals(other.indexRoot)) - return false; - return true; - } - - @Override - public ISymbolProvider create(ReadGraph g) throws DatabaseException { - return g.syncRequest(new LoadRequest(indexRoot, diagram)); - } - - static class LoadRequest extends BinaryRead { - public LoadRequest(Resource contribution, Resource diagram) { - super(contribution, diagram); - } - @Override - public ISymbolProvider perform(ReadGraph graph) throws DatabaseException { - - Layer0 L0 = Layer0.getInstance(graph); - DiagramResource dr = DiagramResource.getInstance(graph); - - Collection groups = new ArrayList(); - - if (parameter != null) { - Instances query = graph.adapt(dr.SymbolReferenceLibrary, Instances.class); - for(Resource library : query.find(graph, parameter)) { - if (SymbolProviderFactories.accept(graph, dr, library, parameter2)) { - groups.add(BasicSymbolProviderFactory.createGroup(graph, library, L0.IsRelatedTo, parameter2)); - } - } - } - - return new SymbolProvider(groups); - } - } - - static class SymbolProvider extends AbstractSymbolProvider { - public SymbolProvider(Collection groups) { - super(); - setSymbolGroup(groups); - lockGroups(); - } - } - -} +/******************************************************************************* + * 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 org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.common.request.BinaryRead; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.layer0.adapter.Instances; +import org.simantics.diagram.stubs.DiagramResource; +import org.simantics.diagram.symbollibrary.ISymbolGroup; +import org.simantics.layer0.Layer0; + +/** + * + * @author Antti Villberg + */ +public class IndexRootSymbolProviderFactory implements SymbolProviderFactory { + + Resource indexRoot; + Resource diagram; + + public IndexRootSymbolProviderFactory(Resource indexRoot, Resource diagram) { + this.indexRoot = indexRoot; + this.diagram = diagram; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((diagram == null) ? 0 : diagram.hashCode()); + result = prime * result + ((indexRoot == null) ? 0 : indexRoot.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; + IndexRootSymbolProviderFactory other = (IndexRootSymbolProviderFactory) obj; + if (diagram == null) { + if (other.diagram != null) + return false; + } else if (!diagram.equals(other.diagram)) + return false; + if (indexRoot == null) { + if (other.indexRoot != null) + return false; + } else if (!indexRoot.equals(other.indexRoot)) + return false; + return true; + } + + @Override + public ISymbolProvider create(ReadGraph g) throws DatabaseException { + return g.syncRequest(new LoadRequest(indexRoot, diagram)); + } + + static class LoadRequest extends BinaryRead { + public LoadRequest(Resource contribution, Resource diagram) { + super(contribution, diagram); + } + @Override + public ISymbolProvider perform(ReadGraph graph) throws DatabaseException { + + Layer0 L0 = Layer0.getInstance(graph); + DiagramResource dr = DiagramResource.getInstance(graph); + + Collection groups = new ArrayList(); + + if (parameter != null) { + Instances query = graph.adapt(dr.SymbolReferenceLibrary, Instances.class); + for(Resource library : query.find(graph, parameter)) { + if (SymbolProviderFactories.accept(graph, dr, library, parameter2)) { + groups.add(BasicSymbolProviderFactory.createGroup(graph, library, L0.IsRelatedTo, parameter2)); + } + } + } + + return new SymbolProvider(groups); + } + } + + static class SymbolProvider extends AbstractSymbolProvider { + public SymbolProvider(Collection groups) { + super(); + setSymbolGroup(groups); + lockGroups(); + } + } + +}