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.content.Labeler.Modifier;
\r
20 import org.simantics.db.ReadGraph;
\r
21 import org.simantics.db.Resource;
\r
22 import org.simantics.db.Session;
\r
23 import org.simantics.db.WriteGraph;
\r
24 import org.simantics.db.common.ResourceArray;
\r
25 import org.simantics.db.exception.DatabaseException;
\r
26 import org.simantics.modeling.ui.Activator;
\r
27 import org.simantics.utils.ObjectUtils;
\r
30 public class Module implements INode, Comparable<Module> {
\r
32 public String label;
\r
33 public Resource resource;
\r
34 ModuleParent parent;
\r
36 public Module(String label, Resource resource, ModuleParent parent) {
\r
38 this.resource = resource;
\r
39 this.parent = parent;
\r
43 public Collection<?> getChildren(ReadGraph g) {
\r
44 return Collections.emptyList();
\r
48 public ImageDescriptor getImage(ReadGraph g) {
\r
49 return Activator.BULLET_GREEN_ICON;
\r
53 public String getLabel(ReadGraph g) {
\r
58 public boolean equals(Object obj) {
\r
63 if (!getClass().equals(obj.getClass()))
\r
65 Module other = (Module)obj;
\r
66 return label.equals(other.label) && resource.equals(other.resource) && ObjectUtils.objectEquals(parent, other.parent);
\r
70 public int hashCode() {
\r
71 return (label.hashCode() * 31 + resource.hashCode()) * 31 + ObjectUtils.hashCode(parent);
\r
75 public Modifier getModifier(final Session session, String columnId) {
\r
80 public int getCategory(ReadGraph graph) {
\r
85 public void handleDrop(Session session, ISelection selection) {
\r
89 public void handleDelete(WriteGraph graph) throws DatabaseException {
\r
93 public boolean hasChildren(ReadGraph graph) {
\r
97 @SuppressWarnings("unchecked")
\r
99 public Object getAdapter(Class adapter) {
\r
100 if (adapter == Resource.class)
\r
102 if (adapter == ResourceArray.class) {
\r
104 for (ModuleParent parent = this.parent; parent != null; parent = parent.parent, ++len);
\r
105 Resource[] result = new Resource[len];
\r
106 result[0] = resource;
\r
107 ModuleParent parent = this.parent;
\r
108 for (int i = 1; i < len; ++i) {
\r
109 result[i] = parent.resource;
\r
110 parent = parent.parent;
\r
112 return new ResourceArray(result);
\r
118 public int compareTo(Module arg0) {
\r
119 return label.compareTo(arg0.label);
\r