X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=org.simantics.g3d%2Fsrc%2Forg%2Fsimantics%2Fg3d%2Fproperty%2FMethodWithMapValueProvider.java;h=8fad88979690dbf266f796982b52c314bd4d1221;hb=refs%2Fchanges%2F29%2F3629%2F1;hp=256de3acc4bc0f31bae759f98831b10cda89f826;hpb=87b3241ec277ba3d8e414b26186a032c9cdcaeed;p=simantics%2F3d.git diff --git a/org.simantics.g3d/src/org/simantics/g3d/property/MethodWithMapValueProvider.java b/org.simantics.g3d/src/org/simantics/g3d/property/MethodWithMapValueProvider.java index 256de3ac..8fad8897 100644 --- a/org.simantics.g3d/src/org/simantics/g3d/property/MethodWithMapValueProvider.java +++ b/org.simantics.g3d/src/org/simantics/g3d/property/MethodWithMapValueProvider.java @@ -1,6 +1,19 @@ +/******************************************************************************* + * Copyright (c) 2012, 2013 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.g3d.property; import java.lang.reflect.Method; +import java.lang.reflect.ParameterizedType; +import java.lang.reflect.Type; import java.util.HashMap; import java.util.Map; @@ -18,9 +31,12 @@ public class MethodWithMapValueProvider implements ValueProvider { @Override public Object getValue(Object obj) throws Exception{ + @SuppressWarnings("unchecked") Map map = (Map)getter.invoke(obj); return map.get(key); } + + @SuppressWarnings("unchecked") @Override public void setValue(Object obj, Object value) throws Exception { Map map = new HashMap(); @@ -28,4 +44,11 @@ public class MethodWithMapValueProvider implements ValueProvider { map.put(key, value); setter.invoke(obj,map); } + + @Override + public Class getValueType() { + // The return type of the getter should be a java.util.Map. + Type[] typeArguments = ((ParameterizedType)getter.getGenericReturnType()).getActualTypeArguments(); + return (Class) typeArguments[1]; + } }