X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=blobdiff_plain;f=bundles%2Forg.simantics.browsing.ui.model%2Fsrc%2Forg%2Fsimantics%2Fbrowsing%2Fui%2Fmodel%2Fnodetypes%2FSpecialNodeType.java;h=ddd6113ff57ca77ee6f0e08ca0a7f54ec4836ebf;hp=9020abd57f8cd0ba271fd1270807a42ed87d62ff;hb=0ae2b770234dfc3cbb18bd38f324125cf0faca07;hpb=24e2b34260f219f0d1644ca7a138894980e25b14 diff --git a/bundles/org.simantics.browsing.ui.model/src/org/simantics/browsing/ui/model/nodetypes/SpecialNodeType.java b/bundles/org.simantics.browsing.ui.model/src/org/simantics/browsing/ui/model/nodetypes/SpecialNodeType.java index 9020abd57..ddd6113ff 100644 --- a/bundles/org.simantics.browsing.ui.model/src/org/simantics/browsing/ui/model/nodetypes/SpecialNodeType.java +++ b/bundles/org.simantics.browsing.ui.model/src/org/simantics/browsing/ui/model/nodetypes/SpecialNodeType.java @@ -1,127 +1,127 @@ -/******************************************************************************* - * Copyright (c) 2010, 2011 Association for Decentralized Information Management in - * Industry THTH ry. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * VTT Technical Research Centre of Finland - initial API and implementation - *******************************************************************************/ -package org.simantics.browsing.ui.model.nodetypes; - -import java.util.Collection; -import java.util.Collections; - -import org.eclipse.core.runtime.Platform; -import org.osgi.framework.Bundle; -import org.simantics.browsing.ui.NodeContext; -import org.simantics.browsing.ui.common.NodeContextBuilder; -import org.simantics.db.ReadGraph; -import org.simantics.db.Resource; -import org.simantics.db.Statement; -import org.simantics.db.common.utils.NameUtils; -import org.simantics.db.exception.DatabaseException; -import org.simantics.db.layer0.variable.Variable; -import org.simantics.ui.selection.WorkbenchSelectionElement; -import org.simantics.viewpoint.ontology.ViewpointResource; - -public class SpecialNodeType implements NodeType { - public Resource resource; - Class contentType; - - public SpecialNodeType(Resource resource, Class contentType) { - this.resource = resource; - this.contentType = contentType; - } - - public static SpecialNodeType create(ReadGraph g, Resource r) throws DatabaseException { - ViewpointResource vr = ViewpointResource.getInstance(g); - String contentTypeName = g.getPossibleRelatedValue(r, vr.HasContentType); - Class contentType; - if("Resource".equals(contentTypeName)) - contentType = Resource.class; - else if("Statement".equals(contentTypeName)) - contentType = Statement.class; - else if("Variable".equals(contentTypeName)) - contentType = Variable.class; - else { - contentType = Object.class; - if(contentTypeName != null) - try { - String bundleId = g.getPossibleRelatedValue(r, vr.HasBundle); - Bundle bundle = null; - if (bundleId != null) { - bundle = Platform.getBundle(bundleId); - if (bundle == null) - System.err.println("Referenced bundle '" + bundleId + "' not found in platform."); - } - if (bundle != null) - contentType = bundle.loadClass(contentTypeName); - else - contentType = Class.forName(contentTypeName); - } catch (ClassNotFoundException e) { - System.err.println("Unknown content type " + contentTypeName); - } - else - System.err.println("Content type is NULL."); - } - return new SpecialNodeType(r, contentType); - } - - @Override - public NodeContext createNodeContext(ReadGraph graph, Object content) - throws DatabaseException { - if(contentType.isInstance(content)) - return NodeContextBuilder.buildWithData(KEY_SEQUENCE, - new Object[] {content, this} - ); - else - return null; - } - - @Override - public Class getContentType() { - return contentType; - } - - @Override - public int hashCode() { - return resource.hashCode(); - } - - @Override - public boolean equals(Object obj) { - if (this == obj) - return true; - if (obj == null) - return false; - if (getClass() != obj.getClass()) - return false; - SpecialNodeType other = (SpecialNodeType) obj; - return resource.equals(other.resource); - } - - @Override - public boolean inherits(ReadGraph graph, NodeType superType) { - // Special node type does not support inheritance - return equals(superType); - } - - @Override - public Collection getSuper(ReadGraph g) { - return Collections.emptyList(); - } - - @Override - public String toString(ReadGraph graph) throws DatabaseException { - return "(" + NameUtils.getSafeName(graph, resource) + ")"; - } - - @Override - public WorkbenchSelectionElement getWorkbenchSelectionElement(NodeContext context) { - return null; - } - -} +/******************************************************************************* + * Copyright (c) 2010, 2011 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.browsing.ui.model.nodetypes; + +import java.util.Collection; +import java.util.Collections; + +import org.eclipse.core.runtime.Platform; +import org.osgi.framework.Bundle; +import org.simantics.browsing.ui.NodeContext; +import org.simantics.browsing.ui.common.NodeContextBuilder; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.Statement; +import org.simantics.db.common.utils.NameUtils; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.layer0.variable.Variable; +import org.simantics.ui.selection.WorkbenchSelectionElement; +import org.simantics.viewpoint.ontology.ViewpointResource; + +public class SpecialNodeType implements NodeType { + public Resource resource; + Class contentType; + + public SpecialNodeType(Resource resource, Class contentType) { + this.resource = resource; + this.contentType = contentType; + } + + public static SpecialNodeType create(ReadGraph g, Resource r) throws DatabaseException { + ViewpointResource vr = ViewpointResource.getInstance(g); + String contentTypeName = g.getPossibleRelatedValue(r, vr.HasContentType); + Class contentType; + if("Resource".equals(contentTypeName)) + contentType = Resource.class; + else if("Statement".equals(contentTypeName)) + contentType = Statement.class; + else if("Variable".equals(contentTypeName)) + contentType = Variable.class; + else { + contentType = Object.class; + if(contentTypeName != null) + try { + String bundleId = g.getPossibleRelatedValue(r, vr.HasBundle); + Bundle bundle = null; + if (bundleId != null) { + bundle = Platform.getBundle(bundleId); + if (bundle == null) + System.err.println("Referenced bundle '" + bundleId + "' not found in platform."); + } + if (bundle != null) + contentType = bundle.loadClass(contentTypeName); + else + contentType = Class.forName(contentTypeName); + } catch (ClassNotFoundException e) { + System.err.println("Unknown content type " + contentTypeName); + } + else + System.err.println("Content type is NULL."); + } + return new SpecialNodeType(r, contentType); + } + + @Override + public NodeContext createNodeContext(ReadGraph graph, Object content) + throws DatabaseException { + if(contentType.isInstance(content)) + return NodeContextBuilder.buildWithData(KEY_SEQUENCE, + new Object[] {content, this} + ); + else + return null; + } + + @Override + public Class getContentType() { + return contentType; + } + + @Override + public int hashCode() { + return resource.hashCode(); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + SpecialNodeType other = (SpecialNodeType) obj; + return resource.equals(other.resource); + } + + @Override + public boolean inherits(ReadGraph graph, NodeType superType) { + // Special node type does not support inheritance + return equals(superType); + } + + @Override + public Collection getSuper(ReadGraph g) { + return Collections.emptyList(); + } + + @Override + public String toString(ReadGraph graph) throws DatabaseException { + return "(" + NameUtils.getSafeName(graph, resource) + ")"; + } + + @Override + public WorkbenchSelectionElement getWorkbenchSelectionElement(NodeContext context) { + return null; + } + +}