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