]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/modelBrowser/model/Node.java
10eb340f7ceb6f4ef5af28c0412f12c206616d54
[simantics/platform.git] / bundles / org.simantics.modeling.ui / src / org / simantics / modeling / ui / modelBrowser / model / Node.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.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;
30
31 @Deprecated
32 public class Node implements INode, IDropTargetNode {
33
34     protected Resource resource;
35
36     public Node(Resource resource) {
37         assert resource != null;
38         this.resource = resource;
39     }
40
41     public Resource getResource() {
42         return resource;
43     }
44
45     @Override
46     public String getLabel(ReadGraph g) throws DatabaseException {
47         return LabelerUtil.safeStringRepresentation(g, resource);
48     }
49
50     @Override
51     public ImageDescriptor getImage(ReadGraph graph) throws DatabaseException {
52         return ImageDescriptor.getMissingImageDescriptor();
53     }
54
55     @Override
56     public int getCategory(ReadGraph graph) throws DatabaseException {
57         return 0;
58     }
59
60     @Override
61     public Modifier getModifier(Session session, String columnId) {
62         return null;
63     }
64
65     @Override
66     public Collection<?> getChildren(ReadGraph graph) throws DatabaseException {
67         return Collections.emptyList();
68     }
69
70     @Override
71     public boolean hasChildren(ReadGraph g) throws DatabaseException {
72         return !getChildren(g).isEmpty();
73     }
74
75     @Override
76     public Object getAdapter(Class adapter) {
77         if (adapter == Resource.class)
78             return resource;
79         return null;
80     }
81
82     @Override
83     public boolean equals(Object obj) {
84         if(this == obj)
85             return true;
86         if(obj == null)
87             return false;
88         return getClass().equals(obj.getClass()) && resource.equals(((Node)obj).resource);
89     }
90
91     @Override
92     public int hashCode() {
93         return getClass().hashCode()*31 + resource.hashCode();
94     }
95
96     @Override
97     public void handleDrop(Session session, ISelection data) {
98     }
99
100     /**
101      * For backwards compatibility with the new model browser and browsing framework.
102      */
103     @Override
104     public void drop(Object data) {
105         if (data instanceof ISelection) {
106             handleDrop(SimanticsUI.getSession(), (ISelection) data);
107         }
108     }
109
110     @Override
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);
115     }
116
117 }