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.common.node.IDropTargetNode;
20 import org.simantics.browsing.ui.content.Labeler.Modifier;
21 import org.simantics.browsing.ui.graph.impl.LabelerUtil;
22 import org.simantics.db.ReadGraph;
23 import org.simantics.db.Resource;
24 import org.simantics.db.Session;
25 import org.simantics.db.WriteGraph;
26 import org.simantics.db.exception.DatabaseException;
27 import org.simantics.db.layer0.util.RemoverUtil;
28 import org.simantics.layer0.Layer0;
29 import org.simantics.ui.SimanticsUI;
32 public class Node implements INode, IDropTargetNode {
34 protected Resource resource;
36 public Node(Resource resource) {
37 assert resource != null;
38 this.resource = resource;
41 public Resource getResource() {
46 public String getLabel(ReadGraph g) throws DatabaseException {
47 return LabelerUtil.safeStringRepresentation(g, resource);
51 public ImageDescriptor getImage(ReadGraph graph) throws DatabaseException {
52 return ImageDescriptor.getMissingImageDescriptor();
56 public int getCategory(ReadGraph graph) throws DatabaseException {
61 public Modifier getModifier(Session session, String columnId) {
66 public Collection<?> getChildren(ReadGraph graph) throws DatabaseException {
67 return Collections.emptyList();
71 public boolean hasChildren(ReadGraph g) throws DatabaseException {
72 return !getChildren(g).isEmpty();
76 public Object getAdapter(Class adapter) {
77 if (adapter == Resource.class)
83 public boolean equals(Object obj) {
88 return getClass().equals(obj.getClass()) && resource.equals(((Node)obj).resource);
92 public int hashCode() {
93 return getClass().hashCode()*31 + resource.hashCode();
97 public void handleDrop(Session session, ISelection data) {
101 * For backwards compatibility with the new model browser and browsing framework.
104 public void drop(Object data) {
105 if (data instanceof ISelection) {
106 handleDrop(SimanticsUI.getSession(), (ISelection) data);
111 public void handleDelete(WriteGraph graph) throws DatabaseException {
112 Layer0 l0 = Layer0.getInstance(graph);
113 graph.deny(resource, l0.PartOf);
114 RemoverUtil.remove(graph, resource);