1 /*******************************************************************************
\r
2 * Copyright (c) 2007, 2010 Association for Decentralized Information Management
\r
3 * in Industry THTH ry.
\r
4 * All rights reserved. This program and the accompanying materials
\r
5 * are made available under the terms of the Eclipse Public License v1.0
\r
6 * which accompanies this distribution, and is available at
\r
7 * http://www.eclipse.org/legal/epl-v10.html
\r
10 * VTT Technical Research Centre of Finland - initial API and implementation
\r
11 *******************************************************************************/
\r
12 package org.simantics.modeling.ui.modelBrowser.model;
\r
14 import java.util.Collection;
\r
15 import java.util.Collections;
\r
17 import org.eclipse.jface.resource.ImageDescriptor;
\r
18 import org.eclipse.jface.viewers.ISelection;
\r
19 import org.simantics.browsing.ui.common.node.IDropTargetNode;
\r
20 import org.simantics.browsing.ui.content.Labeler.Modifier;
\r
21 import org.simantics.browsing.ui.graph.impl.LabelerUtil;
\r
22 import org.simantics.db.ReadGraph;
\r
23 import org.simantics.db.Resource;
\r
24 import org.simantics.db.Session;
\r
25 import org.simantics.db.WriteGraph;
\r
26 import org.simantics.db.exception.DatabaseException;
\r
27 import org.simantics.db.layer0.util.RemoverUtil;
\r
28 import org.simantics.layer0.Layer0;
\r
29 import org.simantics.ui.SimanticsUI;
\r
32 public class Node implements INode, IDropTargetNode {
\r
34 protected Resource resource;
\r
36 public Node(Resource resource) {
\r
37 assert resource != null;
\r
38 this.resource = resource;
\r
41 public Resource getResource() {
\r
46 public String getLabel(ReadGraph g) throws DatabaseException {
\r
47 return LabelerUtil.safeStringRepresentation(g, resource);
\r
51 public ImageDescriptor getImage(ReadGraph graph) throws DatabaseException {
\r
52 return ImageDescriptor.getMissingImageDescriptor();
\r
56 public int getCategory(ReadGraph graph) throws DatabaseException {
\r
61 public Modifier getModifier(Session session, String columnId) {
\r
66 public Collection<?> getChildren(ReadGraph graph) throws DatabaseException {
\r
67 return Collections.emptyList();
\r
71 public boolean hasChildren(ReadGraph g) throws DatabaseException {
\r
72 return !getChildren(g).isEmpty();
\r
76 public Object getAdapter(Class adapter) {
\r
77 if (adapter == Resource.class)
\r
83 public boolean equals(Object obj) {
\r
88 return getClass().equals(obj.getClass()) && resource.equals(((Node)obj).resource);
\r
92 public int hashCode() {
\r
93 return getClass().hashCode()*31 + resource.hashCode();
\r
97 public void handleDrop(Session session, ISelection data) {
\r
101 * For backwards compatibility with the new model browser and browsing framework.
\r
104 public void drop(Object data) {
\r
105 if (data instanceof ISelection) {
\r
106 handleDrop(SimanticsUI.getSession(), (ISelection) data);
\r
111 public void handleDelete(WriteGraph graph) throws DatabaseException {
\r
112 Layer0 l0 = Layer0.getInstance(graph);
\r
113 graph.deny(resource, l0.PartOf);
\r
114 RemoverUtil.remove(graph, resource);
\r