X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=blobdiff_plain;f=bundles%2Forg.simantics.browsing.ui.graph.impl%2Fsrc%2Forg%2Fsimantics%2Fbrowsing%2Fui%2Fgraph%2Fimpl%2FResourceProperty.java;fp=bundles%2Forg.simantics.browsing.ui.graph.impl%2Fsrc%2Forg%2Fsimantics%2Fbrowsing%2Fui%2Fgraph%2Fimpl%2FResourceProperty.java;h=df09d7501842578aa5341cdb8655687cb444a16f;hp=0000000000000000000000000000000000000000;hb=969bd23cab98a79ca9101af33334000879fb60c5;hpb=866dba5cd5a3929bbeae85991796acb212338a08 diff --git a/bundles/org.simantics.browsing.ui.graph.impl/src/org/simantics/browsing/ui/graph/impl/ResourceProperty.java b/bundles/org.simantics.browsing.ui.graph.impl/src/org/simantics/browsing/ui/graph/impl/ResourceProperty.java new file mode 100644 index 000000000..df09d7501 --- /dev/null +++ b/bundles/org.simantics.browsing.ui.graph.impl/src/org/simantics/browsing/ui/graph/impl/ResourceProperty.java @@ -0,0 +1,117 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 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.graph.impl; + +import org.simantics.browsing.ui.common.property.IProperty; +import org.simantics.db.Resource; +import org.simantics.db.common.ResourceArray; + +/** + * @author Tuukka Lehtonen + */ +public class ResourceProperty implements IProperty { + + protected final Type type; + + protected final Resource subject; + protected final Resource predicate; + protected final Resource value; + protected final ResourceArray path; + + public ResourceProperty(Type type, Resource subject, Resource predicate, Resource value, ResourceArray path) { + this.type = type; + this.subject = subject; + this.predicate = predicate; + this.value = value; + this.path = path; + } + + @Override + public Type getType() { + return type; + } + + @SuppressWarnings("unchecked") + @Override + public T getData(Class clazz) { + T t = (T) getAdapter(clazz); + if (t != null) + return t; + throw new ClassCastException("class " + clazz.getCanonicalName() + " not adaptable from " + toString()); + } + + @Override + public String toString() { + return getClass().getSimpleName() + "[subject=" + subject + ", predicate=" + predicate + ", value=" + value + + ", path=" + path + "]"; + } + + @SuppressWarnings({ "rawtypes", "unchecked" }) + @Override + public Object getAdapter(Class adapter) { + return adapt(adapter); + } + + @SuppressWarnings("unchecked") + @Override + public T adapt(Class adapter) { + if (adapter == ResourceArray[].class) + return (T) new ResourceArray[] { new ResourceArray(subject, predicate, value), path }; + if (adapter == ResourceArray.class) + return (T) new ResourceArray(subject, predicate, value); + if (adapter == Resource[].class) + return (T) new Resource[] { subject, predicate, value }; + if (adapter == Resource.class) + // Return the object of the specified statement + return (T) value; + return null; + } + + @Override + public int propertyHashCode() { + final int prime = 31; + int result = 1; + result = prime * result + subject.hashCode(); + result = prime * result + predicate.hashCode(); + result = prime * result + path.hashCode(); + return result; + } + + @Override + public boolean propertyEquals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + ResourceProperty other = (ResourceProperty) obj; + return subject.equals(other.subject) && predicate.equals(other.predicate) && path.equals(other.path); + } + + @Override + public int hashCode() { + return propertyHashCode() * 31 + value.hashCode(); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (!propertyEquals(obj)) + return false; + ResourceProperty other = (ResourceProperty) obj; + return value.equals(other.value) && type.equals(other.type); + + } + +}