--- /dev/null
+/*******************************************************************************\r
+ * Copyright (c) 2007, 2010 Association for Decentralized Information Management\r
+ * in Industry THTH ry.\r
+ * All rights reserved. This program and the accompanying materials\r
+ * are made available under the terms of the Eclipse Public License v1.0\r
+ * which accompanies this distribution, and is available at\r
+ * http://www.eclipse.org/legal/epl-v10.html\r
+ *\r
+ * Contributors:\r
+ * VTT Technical Research Centre of Finland - initial API and implementation\r
+ *******************************************************************************/\r
+package org.simantics.modeling.ui.modelBrowser.model;\r
+\r
+import java.util.Collection;\r
+import java.util.Collections;\r
+\r
+import org.eclipse.jface.resource.ImageDescriptor;\r
+import org.eclipse.jface.viewers.ISelection;\r
+import org.simantics.browsing.ui.common.node.IDropTargetNode;\r
+import org.simantics.browsing.ui.content.Labeler.Modifier;\r
+import org.simantics.browsing.ui.graph.impl.LabelerUtil;\r
+import org.simantics.db.ReadGraph;\r
+import org.simantics.db.Resource;\r
+import org.simantics.db.Session;\r
+import org.simantics.db.WriteGraph;\r
+import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.db.layer0.util.RemoverUtil;\r
+import org.simantics.layer0.Layer0;\r
+import org.simantics.ui.SimanticsUI;\r
+\r
+@Deprecated\r
+public class Node implements INode, IDropTargetNode {\r
+\r
+ protected Resource resource;\r
+\r
+ public Node(Resource resource) {\r
+ assert resource != null;\r
+ this.resource = resource;\r
+ }\r
+\r
+ public Resource getResource() {\r
+ return resource;\r
+ }\r
+\r
+ @Override\r
+ public String getLabel(ReadGraph g) throws DatabaseException {\r
+ return LabelerUtil.safeStringRepresentation(g, resource);\r
+ }\r
+\r
+ @Override\r
+ public ImageDescriptor getImage(ReadGraph graph) throws DatabaseException {\r
+ return ImageDescriptor.getMissingImageDescriptor();\r
+ }\r
+\r
+ @Override\r
+ public int getCategory(ReadGraph graph) throws DatabaseException {\r
+ return 0;\r
+ }\r
+\r
+ @Override\r
+ public Modifier getModifier(Session session, String columnId) {\r
+ return null;\r
+ }\r
+\r
+ @Override\r
+ public Collection<?> getChildren(ReadGraph graph) throws DatabaseException {\r
+ return Collections.emptyList();\r
+ }\r
+\r
+ @Override\r
+ public boolean hasChildren(ReadGraph g) throws DatabaseException {\r
+ return !getChildren(g).isEmpty();\r
+ }\r
+\r
+ @Override\r
+ public Object getAdapter(Class adapter) {\r
+ if (adapter == Resource.class)\r
+ return resource;\r
+ return null;\r
+ }\r
+\r
+ @Override\r
+ public boolean equals(Object obj) {\r
+ if(this == obj)\r
+ return true;\r
+ if(obj == null)\r
+ return false;\r
+ return getClass().equals(obj.getClass()) && resource.equals(((Node)obj).resource);\r
+ }\r
+\r
+ @Override\r
+ public int hashCode() {\r
+ return getClass().hashCode()*31 + resource.hashCode();\r
+ }\r
+\r
+ @Override\r
+ public void handleDrop(Session session, ISelection data) {\r
+ }\r
+\r
+ /**\r
+ * For backwards compatibility with the new model browser and browsing framework.\r
+ */\r
+ @Override\r
+ public void drop(Object data) {\r
+ if (data instanceof ISelection) {\r
+ handleDrop(SimanticsUI.getSession(), (ISelection) data);\r
+ }\r
+ }\r
+\r
+ @Override\r
+ public void handleDelete(WriteGraph graph) throws DatabaseException {\r
+ Layer0 l0 = Layer0.getInstance(graph);\r
+ graph.deny(resource, l0.PartOf);\r
+ RemoverUtil.remove(graph, resource);\r
+ }\r
+\r
+}\r