-/*******************************************************************************\r
- * Copyright (c) 2007, 2010 Association for Decentralized Information Management\r
- * in Industry THTH ry.\r
- * All rights reserved. This program and the accompanying materials\r
- * are made available under the terms of the Eclipse Public License v1.0\r
- * which accompanies this distribution, and is available at\r
- * http://www.eclipse.org/legal/epl-v10.html\r
- *\r
- * Contributors:\r
- * VTT Technical Research Centre of Finland - initial API and implementation\r
- *******************************************************************************/\r
-package org.simantics.diagram.flag;\r
-\r
-import org.simantics.db.ReadGraph;\r
-import org.simantics.db.Resource;\r
-import org.simantics.db.exception.DatabaseException;\r
-import org.simantics.diagram.stubs.DiagramResource;\r
-import org.simantics.diagram.synchronization.graph.DiagramGraphUtil;\r
-import org.simantics.g2d.elementclass.FlagClass;\r
-import org.simantics.g2d.elementclass.FlagClass.Mode;\r
-import org.simantics.g2d.elementclass.FlagClass.Type;\r
-import org.simantics.structural2.modelingRules.IModelingRules;\r
-\r
-/**\r
- * @author Tuukka Lehtonen\r
- */\r
-public abstract class AbstractFlagType implements IFlagType {\r
-\r
- protected final Resource flag;\r
- protected final IModelingRules modelingRules;\r
-\r
- public AbstractFlagType(Resource flag, IModelingRules modelingRules) {\r
- if (flag == null)\r
- throw new NullPointerException("null flag");\r
- if (modelingRules == null)\r
- throw new NullPointerException("null modeling rules");\r
- this.flag = flag;\r
- this.modelingRules = modelingRules;\r
- }\r
-\r
- protected Type getType(ReadGraph graph) throws DatabaseException {\r
- DiagramResource dr = DiagramResource.getInstance(graph);\r
- FlagClass.Type t = DiagramGraphUtil.toFlagType(dr, graph.getPossibleObject(flag, dr.HasFlagType));\r
- return t;\r
- }\r
-\r
- protected Mode getMode(ReadGraph graph) throws DatabaseException {\r
- return getMode(graph, flag);\r
- }\r
-\r
- public static Mode getMode(ReadGraph graph, Resource flag) throws DatabaseException {\r
- int joinCount = graph.getObjects(flag, DiagramResource.getInstance(graph).FlagIsJoinedBy).size();\r
- if(joinCount == 0)\r
- return FlagClass.Mode.Internal;\r
- else if(joinCount == 1) {\r
- Resource otherFlag = FlagUtil.getPossibleCounterpart(graph, flag);\r
- if(otherFlag == null /* FIXME just to get around npe */ || \r
- DiagramGraphUtil.onSameDiagram(graph, flag, otherFlag))\r
- return FlagClass.Mode.Internal;\r
- else\r
- return FlagClass.Mode.External;\r
- }\r
- else\r
- return new FlagClass.External(joinCount);\r
- }\r
-\r
+/*******************************************************************************
+ * 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);
+ }
+