]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.diagram/src/org/simantics/diagram/profile/ComponentTextStyle.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.diagram / src / org / simantics / diagram / profile / ComponentTextStyle.java
1 /*******************************************************************************
2  * Copyright (c) 2011 Association for Decentralized Information Management in
3  * Industry THTH ry.
4  * All rights reserved. This program and the accompanying materials
5  * are made available under the terms of the Eclipse Public License v1.0
6  * which accompanies this distribution, and is available at
7  * http://www.eclipse.org/legal/epl-v10.html
8  *
9  * Contributors:
10  *     VTT Technical Research Centre of Finland - initial API and implementation
11  *******************************************************************************/
12 package org.simantics.diagram.profile;
13
14 import org.simantics.db.ReadGraph;
15 import org.simantics.db.Resource;
16 import org.simantics.db.exception.DatabaseException;
17 import org.simantics.diagram.content.ConnectionUtil;
18 import org.simantics.diagram.flag.FlagUtil;
19 import org.simantics.diagram.stubs.DiagramResource;
20 import org.simantics.modeling.ModelingResources;
21
22 /**
23  * @author Tuukka Lehtonen
24  */
25 public abstract class ComponentTextStyle extends TextStyle {
26
27     public ComponentTextStyle() {
28         super();
29     }
30
31     public ComponentTextStyle(double xOffset, double yOffset) {
32         super(xOffset, yOffset);
33     }
34
35     @Override
36     protected Resource getConfigurationComponent(ReadGraph graph, Resource element) throws DatabaseException {
37         ModelingResources MOD = ModelingResources.getInstance(graph);
38         Resource component = graph.getPossibleObject(element, MOD.ElementToComponent);
39         if (component != null)
40             return component;
41
42         DiagramResource DIA = DiagramResource.getInstance(graph);
43         if (graph.isInstanceOf(element, DIA.Flag) && FlagUtil.isExternal(graph, element)) {
44             for (Resource connector : graph.getObjects(element, DIA.Flag_ConnectionPoint)) {
45                 Resource connection = ConnectionUtil.getConnection(graph, connector);
46                 component = graph.getPossibleObject(connection, MOD.ElementToComponent);
47                 if (component != null)
48                     return component;
49             }
50         }
51         return null;
52     }
53
54 }