X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=org.simantics.g3d%2Fsrc%2Forg%2Fsimantics%2Fg3d%2Fproperty%2FComboPropertyManipulator.java;fp=org.simantics.g3d%2Fsrc%2Forg%2Fsimantics%2Fg3d%2Fproperty%2FComboPropertyManipulator.java;h=45a3b99adb3f3ec2a5284eb36b2133f6791fbee6;hb=2a4aa4460d5df9da6b348adb2f5ba8c46b071520;hp=0000000000000000000000000000000000000000;hpb=5ed9e84f079af0000885f74a91845bb298e9a362;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 new file mode 100644 index 00000000..45a3b99a --- /dev/null +++ b/org.simantics.g3d/src/org/simantics/g3d/property/ComboPropertyManipulator.java @@ -0,0 +1,89 @@ +package org.simantics.g3d.property; + +import java.util.List; + +public class ComboPropertyManipulator implements PropertyManipulator{ + + ComboValueProvider provider; + Object input; + + boolean editMode; + + public ComboPropertyManipulator(ValueProvider provider, Object input) { + this.provider = (ComboValueProvider)provider; + this.input = input; + } + + @Override + public int getValueCount() { + return 1; + } + + @Override + public String getDescription(int i) { + if (i == 0) + return "Value"; + return null; + } + + @Override + public String getValue(int i) { + try { + Integer value = (Integer)provider.getValue(input); + if (value == null) return null; + return getItems()[value]; + } catch (Exception e) { + return null; + } + } + + @Override + public String setValue(String value, int i) { + try { + provider.setValue(input, Integer.parseInt(value)); + } catch (Exception e) { + return e.getMessage(); + } + return null; + } + + @Override + public boolean getEditMode() { + return editMode; + } + + @Override + public void setEditMode(boolean b) { + editMode = b; + } + + public String[] getItems() { + try { + List vals = provider.getValues(input); + String arr[] = new String[vals.size()]; + for (int i = 0; i < vals.size(); i++) { + arr[i] = vals.get(i).toString(); + } + return arr; + } catch (Exception e) { + return new String[0]; + } + } + + public Integer getValueIndex() { + try { + Integer value = (Integer)provider.getValue(input); + return value; + } catch (Exception e) { + return null; + } + } + + public Integer indexOf(String value) { + String[] items = getItems(); + for (int i = 0; i < items.length; i++) + if (items[i].equals(value)) + return i; + return -1; + } +}