]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/modelBrowser/model/Connection.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.modeling.ui / src / org / simantics / modeling / ui / modelBrowser / model / Connection.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.modeling.ui.modelBrowser.model;
13
14 import java.util.Collection;
15 import java.util.Collections;
16
17 import org.eclipse.jface.resource.ImageDescriptor;
18 import org.eclipse.jface.viewers.ISelection;
19 import org.simantics.browsing.ui.content.Labeler.Modifier;
20 import org.simantics.db.ReadGraph;
21 import org.simantics.db.Resource;
22 import org.simantics.db.Session;
23 import org.simantics.db.WriteGraph;
24 import org.simantics.db.exception.DatabaseException;
25 import org.simantics.layer0.Layer0;
26 import org.simantics.modeling.ui.Activator;
27
28 @Deprecated
29 public class Connection implements INode {
30
31     Resource source;
32     Resource sourceRelation;
33     Resource target;
34     Resource targetRelation;
35     Resource connection;
36
37     public Connection(Resource connection, Resource source,
38             Resource sourceRelation, Resource target, Resource targetRelation) {
39         this.connection = connection;
40         this.source = source;
41         this.sourceRelation = sourceRelation;
42         this.target = target;
43         this.targetRelation = targetRelation;
44     }
45
46     @Override
47     public Collection<?> getChildren(ReadGraph g) {
48         return Collections.EMPTY_LIST;
49     }
50
51     @Override
52     public ImageDescriptor getImage(ReadGraph g) {
53         if(connection == null)
54             return Activator.ARROW_LEFT_ICON;
55         else
56             return Activator.CONNECTION_ICON;
57     }
58
59     @Override
60     public String getLabel(ReadGraph g) throws DatabaseException {
61
62         Layer0 b = Layer0.getInstance(g);
63
64         String targetName = g.getPossibleRelatedValue(target, b.HasName);
65         if(targetName == null)
66             targetName = "";
67
68         String relationName = g.getPossibleRelatedValue(targetRelation, b.HasName);
69         if(relationName == null)
70             relationName = "";
71
72         return targetName + "." + relationName;
73     }
74
75     @Override
76     public int getCategory(ReadGraph graph) {
77         return 0;
78     }
79
80     @Override
81     public void handleDrop(Session session, ISelection selection) {
82     }
83
84     @Override
85     public void handleDelete(WriteGraph graph) throws DatabaseException {
86     }
87
88     @Override
89     public boolean hasChildren(ReadGraph g) {
90         return false;
91     }
92
93     @Override
94     public Object getAdapter(Class adapter) {
95         if(adapter.isAssignableFrom(Resource.class))
96             return connection;
97         return null;
98     }
99
100     @Override
101     public Modifier getModifier(Session session, String columnId) {
102         return null;
103     }
104
105 }