]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.structural.ui/src/org/simantics/structural/ui/modelBrowser/contributions/ConnectionLabeler.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.structural.ui / src / org / simantics / structural / ui / modelBrowser / contributions / ConnectionLabeler.java
1 /*******************************************************************************
2  * Copyright (c) 2007, 2010 Association for Decentralized Information Management
3  * in 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.structural.ui.modelBrowser.contributions;
13
14 import org.simantics.browsing.ui.graph.contributor.labeler.LabelerContributor;
15 import org.simantics.databoard.Bindings;
16 import org.simantics.db.ReadGraph;
17 import org.simantics.db.Resource;
18 import org.simantics.db.exception.DatabaseException;
19 import org.simantics.layer0.Layer0;
20 import org.simantics.structural.stubs.StructuralResource2;
21 import org.simantics.structural.ui.modelBrowser.nodes.ConnectionNode;
22 import org.simantics.structural2.utils.StructuralUtils;
23
24 public class ConnectionLabeler extends LabelerContributor<ConnectionNode> {
25
26         @Override
27         public String getLabel(ReadGraph graph, ConnectionNode node) throws DatabaseException {
28                 StructuralResource2 sr = StructuralResource2.getInstance(graph);
29                 StringBuilder sb = new StringBuilder();
30         Layer0 b = Layer0.getInstance(graph);
31                 
32                 {
33                         boolean first = true;
34                         for(Resource component : graph.getObjects(node.connection, sr.Connects)) {
35                                 if(first)
36                                         first = false;
37                                 else
38                                         sb.append(", ");
39                                 sb.append(graph.<String>getRelatedValue(component, b.HasName, Bindings.STRING));                                
40                         }
41                 }
42                 sb.append(" -> ");
43                 {
44                         boolean first = true;
45                         for(Resource relatedConnection : StructuralUtils.getRelatedConnections(graph, node.connection)) {
46                                 if(relatedConnection.equals(node.connection))
47                                         continue;
48                                 for(Resource component : graph.getObjects(relatedConnection, sr.Connects)) {
49                                         if(first)
50                                                 first = false;
51                                         else
52                                                 sb.append(", ");
53                                         sb.append(graph.<String>getRelatedValue(component, b.HasName, Bindings.STRING));                        
54                                 }
55                         }
56                 }
57                 
58                 return sb.toString();
59         }
60         
61         @Override
62         public int getCategory(ReadGraph graph, ConnectionNode node) throws DatabaseException {
63                 return 1;
64         }
65
66 }