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%2Fflag%2FAbstractFlagType.java;h=9627d79fec8a3bf8aa0ada0181344591ed4dc1e2;hp=a11c10319bcc1cb269511f819547d6893cd84a91;hb=HEAD;hpb=80d69fc3f7a2e14c5b9e44a601ba15b0434454a8 diff --git a/bundles/org.simantics.diagram/src/org/simantics/diagram/flag/AbstractFlagType.java b/bundles/org.simantics.diagram/src/org/simantics/diagram/flag/AbstractFlagType.java index a11c10319..9627d79fe 100644 --- a/bundles/org.simantics.diagram/src/org/simantics/diagram/flag/AbstractFlagType.java +++ b/bundles/org.simantics.diagram/src/org/simantics/diagram/flag/AbstractFlagType.java @@ -1,68 +1,68 @@ -/******************************************************************************* - * 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.flag; - -import org.simantics.db.ReadGraph; -import org.simantics.db.Resource; -import org.simantics.db.exception.DatabaseException; -import org.simantics.diagram.stubs.DiagramResource; -import org.simantics.diagram.synchronization.graph.DiagramGraphUtil; -import org.simantics.g2d.elementclass.FlagClass; -import org.simantics.g2d.elementclass.FlagClass.Mode; -import org.simantics.g2d.elementclass.FlagClass.Type; -import org.simantics.structural2.modelingRules.IModelingRules; - -/** - * @author Tuukka Lehtonen - */ -public abstract class AbstractFlagType implements IFlagType { - - protected final Resource flag; - protected final IModelingRules modelingRules; - - public AbstractFlagType(Resource flag, IModelingRules modelingRules) { - if (flag == null) - throw new NullPointerException("null flag"); - if (modelingRules == null) - throw new NullPointerException("null modeling rules"); - this.flag = flag; - this.modelingRules = modelingRules; - } - - protected Type getType(ReadGraph graph) throws DatabaseException { - DiagramResource dr = DiagramResource.getInstance(graph); - FlagClass.Type t = DiagramGraphUtil.toFlagType(dr, graph.getPossibleObject(flag, dr.HasFlagType)); - return t; - } - - protected Mode getMode(ReadGraph graph) throws DatabaseException { - return getMode(graph, flag); - } - - public static Mode getMode(ReadGraph graph, Resource flag) throws DatabaseException { - DiagramResource DIA = DiagramResource.getInstance(graph); - int joinCount = graph.getObjects(flag, DIA.FlagIsJoinedBy).size(); - if(joinCount == 0) - return FlagClass.Mode.Internal; - else if(joinCount == 1) { - for (Resource connectionJoin : graph.getObjects(flag, DIA.FlagIsJoinedBy)) - for (Resource otherFlag : graph.getObjects(connectionJoin, DIA.JoinsFlag)) - if (!flag.equals(otherFlag) - && !DiagramGraphUtil.onSameDiagram(graph, flag, otherFlag)) - return FlagClass.Mode.External; - return FlagClass.Mode.Internal; - } - else - return new FlagClass.External(joinCount); - } - +/******************************************************************************* + * 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.flag; + +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.exception.DatabaseException; +import org.simantics.diagram.stubs.DiagramResource; +import org.simantics.diagram.synchronization.graph.DiagramGraphUtil; +import org.simantics.g2d.elementclass.FlagClass; +import org.simantics.g2d.elementclass.FlagClass.Mode; +import org.simantics.g2d.elementclass.FlagClass.Type; +import org.simantics.structural2.modelingRules.IModelingRules; + +/** + * @author Tuukka Lehtonen + */ +public abstract class AbstractFlagType implements IFlagType { + + protected final Resource flag; + protected final IModelingRules modelingRules; + + public AbstractFlagType(Resource flag, IModelingRules modelingRules) { + if (flag == null) + throw new NullPointerException("null flag"); + if (modelingRules == null) + throw new NullPointerException("null modeling rules"); + this.flag = flag; + this.modelingRules = modelingRules; + } + + protected Type getType(ReadGraph graph) throws DatabaseException { + DiagramResource dr = DiagramResource.getInstance(graph); + FlagClass.Type t = DiagramGraphUtil.toFlagType(dr, graph.getPossibleObject(flag, dr.HasFlagType)); + return t; + } + + protected Mode getMode(ReadGraph graph) throws DatabaseException { + return getMode(graph, flag); + } + + public static Mode getMode(ReadGraph graph, Resource flag) throws DatabaseException { + DiagramResource DIA = DiagramResource.getInstance(graph); + int joinCount = graph.getObjects(flag, DIA.FlagIsJoinedBy).size(); + if(joinCount == 0) + return FlagClass.Mode.Internal; + else if(joinCount == 1) { + for (Resource connectionJoin : graph.getObjects(flag, DIA.FlagIsJoinedBy)) + for (Resource otherFlag : graph.getObjects(connectionJoin, DIA.JoinsFlag)) + if (!flag.equals(otherFlag) + && !DiagramGraphUtil.onSameDiagram(graph, flag, otherFlag)) + return FlagClass.Mode.External; + return FlagClass.Mode.Internal; + } + else + return new FlagClass.External(joinCount); + } + } \ No newline at end of file