1 /*******************************************************************************
\r
2 * Copyright (c) 2007, 2012 Association for Decentralized Information Management in
\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.sysdyn.ui.browser.nodeTypes;
\r
14 import java.util.Collection;
\r
15 import java.util.Collections;
\r
16 import java.util.WeakHashMap;
\r
18 import org.simantics.browsing.ui.NodeContext;
\r
19 import org.simantics.browsing.ui.common.NodeContextBuilder;
\r
20 import org.simantics.browsing.ui.model.nodetypes.NodeType;
\r
21 import org.simantics.browsing.ui.model.nodetypes.SpecialNodeType;
\r
22 import org.simantics.db.ReadGraph;
\r
23 import org.simantics.db.Resource;
\r
24 import org.simantics.db.common.utils.NameUtils;
\r
25 import org.simantics.db.exception.DatabaseException;
\r
26 import org.simantics.ui.selection.WorkbenchSelectionElement;
\r
29 * Experimental node type for Module symbols. Copied mostly from {@link SpecialNodeType}.
\r
30 * Not necessary needed.
\r
32 * @author Teemu Lempinen
\r
35 public class ModuleSymbolNodeType implements NodeType {
\r
37 private Resource resource;
\r
38 private Class<?> contentType;
\r
40 private static final WeakHashMap<Resource, ModuleSymbolNodeType> nodeTypeCache =
\r
41 new WeakHashMap<Resource, ModuleSymbolNodeType>();
\r
43 public ModuleSymbolNodeType(Resource resource) {
\r
44 this.resource = resource;
\r
45 this.contentType = Resource.class;
\r
48 public static ModuleSymbolNodeType create(Resource entityType) {
\r
49 synchronized(nodeTypeCache) {
\r
50 ModuleSymbolNodeType result = nodeTypeCache.get(entityType);
\r
51 if(result == null) {
\r
52 result = new ModuleSymbolNodeType(entityType);
\r
53 nodeTypeCache.put(entityType, result);
\r
60 public NodeContext createNodeContext(ReadGraph graph, Object content)
\r
61 throws DatabaseException {
\r
62 if(contentType.isInstance(content))
\r
63 return NodeContextBuilder.buildWithData(KEY_SEQUENCE,
\r
64 new Object[] {content, this}
\r
71 public Class<?> getContentType() {
\r
76 public int hashCode() {
\r
77 return resource.hashCode();
\r
81 public boolean equals(Object obj) {
\r
86 if (getClass() != obj.getClass())
\r
88 ModuleSymbolNodeType other = (ModuleSymbolNodeType) obj;
\r
89 return resource.equals(other.resource);
\r
93 public boolean inherits(ReadGraph graph, NodeType superType) {
\r
94 // Special node type does not support inheritance
\r
95 return equals(superType);
\r
99 public Collection<NodeType> getSuper(ReadGraph g) {
\r
100 return Collections.emptyList();
\r
104 public String toString(ReadGraph graph) throws DatabaseException {
\r
105 return "(" + NameUtils.getSafeName(graph, resource) + ")";
\r
109 public WorkbenchSelectionElement getWorkbenchSelectionElement(NodeContext context) {
\r