]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/modelBrowser/model/Module.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.modeling.ui / src / org / simantics / modeling / ui / modelBrowser / model / Module.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.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;
28
29 @Deprecated
30 public class Module implements INode, Comparable<Module> {
31
32     public String label;
33     public Resource resource;
34     ModuleParent parent;
35
36     public Module(String label, Resource resource, ModuleParent parent) {
37         this.label = label;
38         this.resource = resource;
39         this.parent = parent;
40     }
41
42     @Override
43     public Collection<?> getChildren(ReadGraph g) {
44         return Collections.emptyList();
45     }
46
47     @Override
48     public ImageDescriptor getImage(ReadGraph g) {
49         return Activator.BULLET_GREEN_ICON;
50     }
51
52     @Override
53     public String getLabel(ReadGraph g) {
54         return label;
55     }
56
57     @Override
58     public boolean equals(Object obj) {
59         if (this == obj)
60             return true;
61         if (obj == null)
62             return false;
63         if (!getClass().equals(obj.getClass()))
64             return false;
65         Module other = (Module)obj;
66         return label.equals(other.label) && resource.equals(other.resource) && ObjectUtils.objectEquals(parent, other.parent);
67     }
68
69     @Override
70     public int hashCode() {
71         return (label.hashCode() * 31 + resource.hashCode()) * 31 + ObjectUtils.hashCode(parent);
72     }
73
74     @Override
75     public Modifier getModifier(final Session session, String columnId) {
76         return null;
77     }
78
79     @Override
80     public int getCategory(ReadGraph graph) {
81         return 0;
82     }
83
84     @Override
85     public void handleDrop(Session session, ISelection selection) {
86     }
87
88     @Override
89     public void handleDelete(WriteGraph graph) throws DatabaseException {
90     }
91
92     @Override
93     public boolean hasChildren(ReadGraph graph) {
94         return false;
95     }
96
97     @SuppressWarnings("unchecked")
98     @Override
99     public Object getAdapter(Class adapter) {
100         if (adapter == Resource.class)
101             return resource;
102         if (adapter == ResourceArray.class) {
103             int len = 1;
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;
111             }
112             return new ResourceArray(result);
113         }
114         return null;
115     }
116
117     @Override
118     public int compareTo(Module arg0) {
119         return label.compareTo(arg0.label);
120     }
121
122 }