X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=org.simantics.g3d%2Fsrc%2Forg%2Fsimantics%2Fg3d%2Fproperty%2FComboPropertyManipulator.java;h=a1ea44c33260bd8b151cc6974b6e91a00e5d53f8;hb=2041d6564531fe794072ddfe345773de1cab60a3;hp=45a3b99adb3f3ec2a5284eb36b2133f6791fbee6;hpb=2a4aa4460d5df9da6b348adb2f5ba8c46b071520;p=simantics%2F3d.git diff --git a/org.simantics.g3d/src/org/simantics/g3d/property/ComboPropertyManipulator.java b/org.simantics.g3d/src/org/simantics/g3d/property/ComboPropertyManipulator.java index 45a3b99a..a1ea44c3 100644 --- a/org.simantics.g3d/src/org/simantics/g3d/property/ComboPropertyManipulator.java +++ b/org.simantics.g3d/src/org/simantics/g3d/property/ComboPropertyManipulator.java @@ -2,6 +2,8 @@ package org.simantics.g3d.property; import java.util.List; +import org.simantics.utils.datastructures.Arrays; + public class ComboPropertyManipulator implements PropertyManipulator{ ComboValueProvider provider; @@ -29,9 +31,20 @@ public class ComboPropertyManipulator implements PropertyManipulator{ @Override public String getValue(int i) { try { - Integer value = (Integer)provider.getValue(input); - if (value == null) return null; - return getItems()[value]; + Object rawValue = provider.getValue(input); + if (rawValue == null) { + return null; + } + else if (rawValue instanceof Integer) { + Integer value = (Integer)rawValue; + return getItems()[value]; + } + else if (rawValue instanceof Enum) { + return rawValue.toString(); + } + else { + return null; + } } catch (Exception e) { return null; } @@ -40,7 +53,14 @@ public class ComboPropertyManipulator implements PropertyManipulator{ @Override public String setValue(String value, int i) { try { - provider.setValue(input, Integer.parseInt(value)); + int intValue = Integer.parseInt(value); + Class valueType = provider.getValueType(); + if (Enum.class.isAssignableFrom(valueType)) { + provider.setValue(input, valueType.getEnumConstants()[intValue]); + } + else { + provider.setValue(input, intValue); + } } catch (Exception e) { return e.getMessage(); } @@ -72,8 +92,14 @@ public class ComboPropertyManipulator implements PropertyManipulator{ public Integer getValueIndex() { try { - Integer value = (Integer)provider.getValue(input); - return value; + Object value = provider.getValue(input); + Class valueType = provider.getValueType(); + if (valueType.isEnum()) { + return Arrays.indexOf(valueType.getEnumConstants(), value); + } + else { + return (Integer) value; + } } catch (Exception e) { return null; }