-/*******************************************************************************\r
- * Copyright (c) 2007, 2010 Association for Decentralized Information Management\r
- * in Industry THTH ry.\r
- * All rights reserved. This program and the accompanying materials\r
- * are made available under the terms of the Eclipse Public License v1.0\r
- * which accompanies this distribution, and is available at\r
- * http://www.eclipse.org/legal/epl-v10.html\r
- *\r
- * Contributors:\r
- * VTT Technical Research Centre of Finland - initial API and implementation\r
- *******************************************************************************/\r
-package org.simantics.browsing.ui.graph.impl;\r
-\r
-import org.simantics.browsing.ui.common.property.IProperty;\r
-import org.simantics.db.Resource;\r
-import org.simantics.db.common.ResourceArray;\r
-\r
-/**\r
- * @author Tuukka Lehtonen\r
- */\r
-public class ResourceProperty implements IProperty {\r
-\r
- protected final Type type;\r
-\r
- protected final Resource subject;\r
- protected final Resource predicate;\r
- protected final Resource value;\r
- protected final ResourceArray path;\r
-\r
- public ResourceProperty(Type type, Resource subject, Resource predicate, Resource value, ResourceArray path) {\r
- this.type = type;\r
- this.subject = subject;\r
- this.predicate = predicate;\r
- this.value = value;\r
- this.path = path;\r
- }\r
-\r
- @Override\r
- public Type getType() {\r
- return type;\r
- }\r
-\r
- @SuppressWarnings("unchecked")\r
- @Override\r
- public <T> T getData(Class<T> clazz) {\r
- T t = (T) getAdapter(clazz);\r
- if (t != null)\r
- return t;\r
- throw new ClassCastException("class " + clazz.getCanonicalName() + " not adaptable from " + toString());\r
- }\r
-\r
- @Override\r
- public String toString() {\r
- return getClass().getSimpleName() + "[subject=" + subject + ", predicate=" + predicate + ", value=" + value\r
- + ", path=" + path + "]";\r
- }\r
-\r
- @SuppressWarnings({ "rawtypes", "unchecked" })\r
- @Override\r
- public Object getAdapter(Class adapter) {\r
- return adapt(adapter);\r
- }\r
-\r
- @SuppressWarnings("unchecked")\r
- @Override\r
- public <T> T adapt(Class<T> adapter) {\r
- if (adapter == ResourceArray[].class)\r
- return (T) new ResourceArray[] { new ResourceArray(subject, predicate, value), path };\r
- if (adapter == ResourceArray.class)\r
- return (T) new ResourceArray(subject, predicate, value);\r
- if (adapter == Resource[].class)\r
- return (T) new Resource[] { subject, predicate, value };\r
- if (adapter == Resource.class)\r
- // Return the object of the specified statement\r
- return (T) value;\r
- return null;\r
- }\r
-\r
- @Override\r
- public int propertyHashCode() {\r
- final int prime = 31;\r
- int result = 1;\r
- result = prime * result + subject.hashCode();\r
- result = prime * result + predicate.hashCode();\r
- result = prime * result + path.hashCode();\r
- return result;\r
- }\r
-\r
- @Override\r
- public boolean propertyEquals(Object obj) {\r
- if (this == obj)\r
- return true;\r
- if (obj == null)\r
- return false;\r
- if (getClass() != obj.getClass())\r
- return false;\r
- ResourceProperty other = (ResourceProperty) obj;\r
- return subject.equals(other.subject) && predicate.equals(other.predicate) && path.equals(other.path);\r
- }\r
-\r
- @Override\r
- public int hashCode() {\r
- return propertyHashCode() * 31 + value.hashCode();\r
- }\r
-\r
- @Override\r
- public boolean equals(Object obj) {\r
- if (this == obj)\r
- return true;\r
- if (!propertyEquals(obj))\r
- return false;\r
- ResourceProperty other = (ResourceProperty) obj;\r
- return value.equals(other.value) && type.equals(other.type);\r
-\r
- }\r
-\r
-}\r
+/*******************************************************************************
+ * 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> T getData(Class<T> 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> T adapt(Class<T> 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);
+
+ }
+
+}