--- /dev/null
+/*******************************************************************************\r
+ * Copyright (c) 2011 Association for Decentralized Information Management in\r
+ * 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.profile;\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.content.ConnectionUtil;\r
+import org.simantics.diagram.flag.FlagUtil;\r
+import org.simantics.diagram.stubs.DiagramResource;\r
+import org.simantics.modeling.ModelingResources;\r
+\r
+/**\r
+ * @author Tuukka Lehtonen\r
+ */\r
+public abstract class ComponentTextStyle extends TextStyle {\r
+\r
+ public ComponentTextStyle() {\r
+ super();\r
+ }\r
+\r
+ public ComponentTextStyle(double xOffset, double yOffset) {\r
+ super(xOffset, yOffset);\r
+ }\r
+\r
+ @Override\r
+ protected Resource getConfigurationComponent(ReadGraph graph, Resource element) throws DatabaseException {\r
+ ModelingResources MOD = ModelingResources.getInstance(graph);\r
+ Resource component = graph.getPossibleObject(element, MOD.ElementToComponent);\r
+ if (component != null)\r
+ return component;\r
+\r
+ DiagramResource DIA = DiagramResource.getInstance(graph);\r
+ if (graph.isInstanceOf(element, DIA.Flag) && FlagUtil.isExternal(graph, element)) {\r
+ for (Resource connector : graph.getObjects(element, DIA.Flag_ConnectionPoint)) {\r
+ Resource connection = ConnectionUtil.getConnection(graph, connector);\r
+ component = graph.getPossibleObject(connection, MOD.ElementToComponent);\r
+ if (component != null)\r
+ return component;\r
+ }\r
+ }\r
+ return null;\r
+ }\r
+\r
+}
\ No newline at end of file