]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/modelBrowser/model/Module.java
Migrated source code from Simantics SVN
[simantics/platform.git] / bundles / org.simantics.modeling.ui / src / org / simantics / modeling / ui / modelBrowser / model / Module.java
diff --git a/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/modelBrowser/model/Module.java b/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/modelBrowser/model/Module.java
new file mode 100644 (file)
index 0000000..e054eb0
--- /dev/null
@@ -0,0 +1,122 @@
+/*******************************************************************************\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.content.Labeler.Modifier;\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.common.ResourceArray;\r
+import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.modeling.ui.Activator;\r
+import org.simantics.utils.ObjectUtils;\r
+\r
+@Deprecated\r
+public class Module implements INode, Comparable<Module> {\r
+\r
+    public String label;\r
+    public Resource resource;\r
+    ModuleParent parent;\r
+\r
+    public Module(String label, Resource resource, ModuleParent parent) {\r
+        this.label = label;\r
+        this.resource = resource;\r
+        this.parent = parent;\r
+    }\r
+\r
+    @Override\r
+    public Collection<?> getChildren(ReadGraph g) {\r
+        return Collections.emptyList();\r
+    }\r
+\r
+    @Override\r
+    public ImageDescriptor getImage(ReadGraph g) {\r
+        return Activator.BULLET_GREEN_ICON;\r
+    }\r
+\r
+    @Override\r
+    public String getLabel(ReadGraph g) {\r
+        return label;\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
+        if (!getClass().equals(obj.getClass()))\r
+            return false;\r
+        Module other = (Module)obj;\r
+        return label.equals(other.label) && resource.equals(other.resource) && ObjectUtils.objectEquals(parent, other.parent);\r
+    }\r
+\r
+    @Override\r
+    public int hashCode() {\r
+        return (label.hashCode() * 31 + resource.hashCode()) * 31 + ObjectUtils.hashCode(parent);\r
+    }\r
+\r
+    @Override\r
+    public Modifier getModifier(final Session session, String columnId) {\r
+        return null;\r
+    }\r
+\r
+    @Override\r
+    public int getCategory(ReadGraph graph) {\r
+        return 0;\r
+    }\r
+\r
+    @Override\r
+    public void handleDrop(Session session, ISelection selection) {\r
+    }\r
+\r
+    @Override\r
+    public void handleDelete(WriteGraph graph) throws DatabaseException {\r
+    }\r
+\r
+    @Override\r
+    public boolean hasChildren(ReadGraph graph) {\r
+        return false;\r
+    }\r
+\r
+    @SuppressWarnings("unchecked")\r
+    @Override\r
+    public Object getAdapter(Class adapter) {\r
+        if (adapter == Resource.class)\r
+            return resource;\r
+        if (adapter == ResourceArray.class) {\r
+            int len = 1;\r
+            for (ModuleParent parent = this.parent; parent != null; parent = parent.parent, ++len);\r
+            Resource[] result = new Resource[len];\r
+            result[0] = resource;\r
+            ModuleParent parent = this.parent;\r
+            for (int i = 1; i < len; ++i) {\r
+                result[i] = parent.resource;\r
+                parent = parent.parent;\r
+            }\r
+            return new ResourceArray(result);\r
+        }\r
+        return null;\r
+    }\r
+\r
+    @Override\r
+    public int compareTo(Module arg0) {\r
+        return label.compareTo(arg0.label);\r
+    }\r
+\r
+}\r