1 /*******************************************************************************
2 * Copyright (c) 2007, 2010 Association for Decentralized Information Management
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
10 * VTT Technical Research Centre of Finland - initial API and implementation
11 *******************************************************************************/
12 package org.simantics.modeling.ui.modelBrowser.model;
14 import java.util.Collection;
15 import java.util.Collections;
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;
29 public class Connection implements INode {
32 Resource sourceRelation;
34 Resource targetRelation;
37 public Connection(Resource connection, Resource source,
38 Resource sourceRelation, Resource target, Resource targetRelation) {
39 this.connection = connection;
41 this.sourceRelation = sourceRelation;
43 this.targetRelation = targetRelation;
47 public Collection<?> getChildren(ReadGraph g) {
48 return Collections.EMPTY_LIST;
52 public ImageDescriptor getImage(ReadGraph g) {
53 if(connection == null)
54 return Activator.ARROW_LEFT_ICON;
56 return Activator.CONNECTION_ICON;
60 public String getLabel(ReadGraph g) throws DatabaseException {
62 Layer0 b = Layer0.getInstance(g);
64 String targetName = g.getPossibleRelatedValue(target, b.HasName);
65 if(targetName == null)
68 String relationName = g.getPossibleRelatedValue(targetRelation, b.HasName);
69 if(relationName == null)
72 return targetName + "." + relationName;
76 public int getCategory(ReadGraph graph) {
81 public void handleDrop(Session session, ISelection selection) {
85 public void handleDelete(WriteGraph graph) throws DatabaseException {
89 public boolean hasChildren(ReadGraph g) {
94 public Object getAdapter(Class adapter) {
95 if(adapter.isAssignableFrom(Resource.class))
101 public Modifier getModifier(Session session, String columnId) {