]> gerrit.simantics Code Review - simantics/3d.git/commitdiff
Double array properties 39/3439/1
authorMarko Luukkainen <marko.luukkainen@semantum.fi>
Fri, 1 Nov 2019 13:04:58 +0000 (15:04 +0200)
committerMarko Luukkainen <marko.luukkainen@semantum.fi>
Fri, 1 Nov 2019 13:04:58 +0000 (15:04 +0200)
gitlab #44

Change-Id: I51188808ae8aafa47030716e839bc22497c947c7

org.simantics.g3d/src/org/simantics/g3d/property/AnnotatedPropertyTabContributorFactory.java
org.simantics.g3d/src/org/simantics/g3d/property/DefaultPropertyManipulatorFactory.java
org.simantics.g3d/src/org/simantics/g3d/property/DoubleArrayPropertyManipulator.java [new file with mode: 0644]
org.simantics.g3d/src/org/simantics/g3d/property/DoubleArrayPropertyManipulator2.java [new file with mode: 0644]
org.simantics.g3d/src/org/simantics/g3d/property/DoublePropertyManipulator.java
org.simantics.g3d/src/org/simantics/g3d/property/StringPropertyManipulator.java
org.simantics.g3d/src/org/simantics/g3d/property/VectorPropertyManipulator.java

index f0fe47ece8be37c8f0403842bb1423abfde4f2f9..7198ead22ba6ccd9ad96cc30303158f9a9b9f317 100644 (file)
@@ -18,6 +18,7 @@ import java.lang.reflect.Method;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Collections;
+import java.util.Comparator;
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.LinkedHashMap;
@@ -81,7 +82,6 @@ import org.simantics.g3d.scenegraph.structural.IStructuralNode;
 import org.simantics.g3d.tools.AdaptationUtils;
 import org.simantics.selectionview.IPropertyTab;
 import org.simantics.selectionview.IPropertyTab2;
-import org.simantics.utils.datastructures.Callback;
 import org.simantics.utils.datastructures.MapList;
 
 public class AnnotatedPropertyTabContributorFactory implements PropertyTabContributorFactory {
@@ -250,6 +250,7 @@ public class AnnotatedPropertyTabContributorFactory implements PropertyTabContri
        
        private static interface IPropertyItem {
                public String getTabId();
+               public String getName();
        }
        
        private static class PropertyItem implements IPropertyItem{
@@ -276,6 +277,11 @@ public class AnnotatedPropertyTabContributorFactory implements PropertyTabContri
                public String getTabId() {
                        return tabId;
                }
+               
+               @Override
+               public String getName() {
+                   return name;
+               }
        }
        
        private static class CompoundPropertyItem implements IPropertyItem{
@@ -302,6 +308,11 @@ public class AnnotatedPropertyTabContributorFactory implements PropertyTabContri
                public String getTabId() {
                        return tabId;
                }
+               
+               @Override
+        public String getName() {
+            return name;
+        }
        }
        
        private static class AnnotatedPropertyTabContributor implements PropertyTabContributor {
@@ -338,7 +349,7 @@ public class AnnotatedPropertyTabContributorFactory implements PropertyTabContri
                
                private TableViewer viewer;
                
-               private IG3DNode node;
+               private INode node;
                private NodeMap<?,?,?> nodeMap;
                
                private List<TableViewerColumn> valueColumns = new ArrayList<TableViewerColumn>();
@@ -389,27 +400,6 @@ public class AnnotatedPropertyTabContributorFactory implements PropertyTabContri
                                }
                        });
                        
-                       int valueCount = 0;
-                       for (IPropertyItem item : contibutedItems) {
-                               if (item instanceof PropertyItem) {
-                                       PropertyManipulator manipulator = createManipulator((PropertyItem)item, null);
-                                       if (manipulator == null)
-                                               continue;
-                                       if (valueCount < manipulator.getValueCount())
-                                               valueCount = manipulator.getValueCount();
-                               } else if (item instanceof CompoundPropertyItem) {
-                                       if (valueCount < 1)
-                                               valueCount = 1;
-                               }
-                       }
-                       for (int i = 0; i < valueCount; i++) {
-                               TableViewerColumn value = new TableViewerColumn(viewer, SWT.LEFT);
-                               //value.getColumn().setText("Value " + (i+1));
-                               value.getColumn().setText("");
-                               value.getColumn().setWidth(200);
-                               valueColumns.add(value);
-                               //value.setEditingSupport(new )
-                       }
                        viewer.getTable().setHeaderVisible(true);
                        viewer.getTable().setLinesVisible(true);
                        viewer.addSelectionChangedListener(new ISelectionChangedListener() {
@@ -547,7 +537,7 @@ public class AnnotatedPropertyTabContributorFactory implements PropertyTabContri
                @Override
                public void setInput(ISessionContext context, ISelection selection,
                                boolean force) {
-                       Collection<IG3DNode> nodes = AdaptationUtils.adaptToCollection(selection, IG3DNode.class);
+                       Collection<INode> nodes = AdaptationUtils.adaptToCollection(selection, INode.class);
                        if (nodes.size() != 1) {
                                if (node != null) {
                                        node.removeListener(this);
@@ -555,7 +545,7 @@ public class AnnotatedPropertyTabContributorFactory implements PropertyTabContri
                                }
                                return;
                        }
-                       IG3DNode n = nodes.iterator().next();
+                       INode n = nodes.iterator().next();
                        if (node != null) {
                                if (!node.equals(n)) {
                                        node.removeListener(this);
@@ -568,11 +558,11 @@ public class AnnotatedPropertyTabContributorFactory implements PropertyTabContri
                
                
                
-               private void setInput(IG3DNode node) {
+               private void setInput(INode node) {
                        this.node = node;
                        this.node.addListener(this);
                        // resolve nodemap
-                       IG3DNode n = node;
+                       INode n = node;
                        while (true) {
                                if (n == null) {
                                        nodeMap = null;
@@ -586,16 +576,7 @@ public class AnnotatedPropertyTabContributorFactory implements PropertyTabContri
                                n = (IG3DNode)n.getParent();
                        }
                        boolean readOnly =  (node instanceof IStructuralNode && ((IStructuralNode)node).isPartOfInstantiatedModel() && !((IStructuralNode)node).isInstantiatedModelRoot());
-                       // create label providers
-                       PropertyValueLabelProvider2 p = new PropertyValueLabelProvider2(this);
-                       int index = 0;
-                       for (TableViewerColumn c : valueColumns) {
-                               c.setLabelProvider(p);
-                               if (!readOnly) {
-                                       PropertyEditingSupport support = new PropertyEditingSupport(this, viewer, index++, nodeMap);
-                                       c.setEditingSupport(support);
-                               }
-                       }
+                       
                        resolvedItems.clear();
                        manipulators.clear();
                        for (IPropertyItem item : contibutedItems) {
@@ -613,6 +594,36 @@ public class AnnotatedPropertyTabContributorFactory implements PropertyTabContri
                                }
                        }
                        
+                       int valueCount = 0;
+                       for (PropertyManipulator manipulator : manipulators.values()) {
+                           if (valueCount < manipulator.getValueCount())
+                   valueCount = manipulator.getValueCount();
+                       }
+            for (int i = 0; i < valueCount; i++) {
+                TableViewerColumn value = new TableViewerColumn(viewer, SWT.LEFT);
+                //value.getColumn().setText("Value " + (i+1));
+                value.getColumn().setText("");
+                value.getColumn().setWidth(200);
+                valueColumns.add(value);
+                //value.setEditingSupport(new )
+            }
+            
+            // create label providers
+            PropertyValueLabelProvider2 p = new PropertyValueLabelProvider2(this);
+            int index = 0;
+            for (TableViewerColumn c : valueColumns) {
+                c.setLabelProvider(p);
+                if (!readOnly) {
+                    PropertyEditingSupport support = new PropertyEditingSupport(this, viewer, index++, nodeMap);
+                    c.setEditingSupport(support);
+                }
+            }
+                       Collections.sort(resolvedItems, new Comparator<IPropertyItem>() {
+                           @Override
+                           public int compare(IPropertyItem o1, IPropertyItem o2) {
+                               return o1.getName().compareTo(o2.getName());
+                           }
+            });
                        viewer.getTable().setEnabled(!readOnly);
                        viewer.setInput(resolvedItems);
                }
index 9266575f80cbfef3614ae8af4c39654b48a9c532..1ad899458fcd8edc4cd373e86c8decae1fea37a9 100644 (file)
@@ -1,49 +1,51 @@
-/*******************************************************************************\r
- * Copyright (c) 2012, 2013 Association for Decentralized Information Management in\r
- * 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.g3d.property;\r
-\r
-import java.lang.reflect.Method;\r
-\r
-import javax.vecmath.Quat4d;\r
-import javax.vecmath.Vector3d;\r
-\r
-public class DefaultPropertyManipulatorFactory implements PropertyManipulatorFactory {\r
-       \r
-       @Override\r
-       public Class<? extends PropertyManipulator> get(Method get, Object value) {\r
-               Class<?> returnValue = null;\r
-               if (get != null)\r
-                       returnValue = get.getReturnType();\r
-               else\r
-                       returnValue = value.getClass();\r
-               if (Double.class.equals(returnValue))\r
-                       return DoublePropertyManipulator.class;\r
-               if (Vector3d.class.equals(returnValue))\r
-                       return VectorPropertyManipulator.class;\r
-               if (Quat4d.class.equals(returnValue))\r
-                       return QuatPropertyManipulator.class;\r
-               if (String.class.equals(returnValue))\r
-                       return StringPropertyManipulator.class;\r
-               if (Integer.class.equals(returnValue))\r
-                       return IntegerPropertyManipulator.class;\r
-               if (Boolean.class.equals(returnValue))\r
-                       return BooleanPropertyManipulator.class;\r
-               if(double.class.equals(returnValue)) \r
-                       return DoublePropertyManipulator.class;\r
-               if(int.class.equals(returnValue))\r
-                       return IntegerPropertyManipulator.class;\r
-               if(boolean.class.equals(returnValue))\r
-                       return BooleanPropertyManipulator.class;\r
-               throw new RuntimeException("Cannot handle value " + returnValue.getName() + " for method " + get);\r
-       }\r
-\r
-}\r
+/*******************************************************************************
+ * 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 javax.vecmath.Quat4d;
+import javax.vecmath.Vector3d;
+
+public class DefaultPropertyManipulatorFactory implements PropertyManipulatorFactory {
+       
+       @Override
+       public Class<? extends PropertyManipulator> get(Method get, Object value) {
+               Class<?> returnValue = null;
+               if (get != null)
+                       returnValue = get.getReturnType();
+               else
+                       returnValue = value.getClass();
+               if (Double.class.equals(returnValue))
+                       return DoublePropertyManipulator.class;
+               if (Vector3d.class.equals(returnValue))
+                       return VectorPropertyManipulator.class;
+               if (Quat4d.class.equals(returnValue))
+                       return QuatPropertyManipulator.class;
+               if (String.class.equals(returnValue))
+                       return StringPropertyManipulator.class;
+               if (Integer.class.equals(returnValue))
+                       return IntegerPropertyManipulator.class;
+               if (Boolean.class.equals(returnValue))
+                       return BooleanPropertyManipulator.class;
+               if(double.class.equals(returnValue)) 
+                       return DoublePropertyManipulator.class;
+               if(int.class.equals(returnValue))
+                       return IntegerPropertyManipulator.class;
+               if(boolean.class.equals(returnValue))
+                       return BooleanPropertyManipulator.class;
+               if (double[].class.equals(returnValue))
+                   return DoubleArrayPropertyManipulator.class;
+               throw new RuntimeException("Cannot handle value " + returnValue.getName() + " for method " + get);
+       }
+
+}
diff --git a/org.simantics.g3d/src/org/simantics/g3d/property/DoubleArrayPropertyManipulator.java b/org.simantics.g3d/src/org/simantics/g3d/property/DoubleArrayPropertyManipulator.java
new file mode 100644 (file)
index 0000000..bfaa4a5
--- /dev/null
@@ -0,0 +1,99 @@
+/*******************************************************************************
+ * 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.util.Arrays;
+
+public class DoubleArrayPropertyManipulator implements PropertyManipulator {
+       
+       ValueProvider provider;
+       Object input;
+       
+       boolean editMode;
+       double[] editValue = null;
+       
+       public DoubleArrayPropertyManipulator(ValueProvider provider, Object input) {
+               this.provider = provider;
+               this.input = input;
+       }
+       
+       @Override
+    public int getValueCount() {
+        return 1;
+    }
+       
+       @Override
+    public String getDescription(int i) {
+        return "Value";
+    }
+       
+       private double[] getValue() {
+        try {
+            return (double[])provider.getValue(input);
+        } catch (Exception e) {
+            return new double[0];
+        }
+    }
+       
+       @Override
+       public String getValue(int i) {
+               if (editMode) {
+                   return Arrays.toString(editValue);
+               }
+               try {
+                   double[] val = getValue();
+                   return Arrays.toString(val);
+               } catch (Exception e) {
+                       return null;
+               }
+       }
+       
+       @Override
+       public String setValue(String value, int i) {
+               try {
+                   value = value.trim();
+                       if (value.startsWith("[") && value.endsWith("]")) {
+                           value = value.substring(1,value.length()-1);
+                           String vals[] = value.split(",");
+                           double val[] = new double[vals.length];
+                           for (int j = 0; j < vals.length; j++) {
+                               val[j] = Double.parseDouble(vals[j]);
+                           }
+                           provider.setValue(input, val);    
+                       } else {
+                           return "Input must be values between [] characters separated with ,";
+                       }
+                       
+               } catch (Exception e) {
+                       return e.getMessage();
+               }
+               return null;
+       }
+
+       @Override
+       public boolean getEditMode() {
+               return editMode;
+       }
+       
+       @Override
+       public void setEditMode(boolean b) {
+               editMode = b;
+               if (editMode) {
+                       try {
+                               editValue = getValue();
+                       } catch (Exception e) {
+                               
+                       }
+               }
+               
+       }
+}
diff --git a/org.simantics.g3d/src/org/simantics/g3d/property/DoubleArrayPropertyManipulator2.java b/org.simantics.g3d/src/org/simantics/g3d/property/DoubleArrayPropertyManipulator2.java
new file mode 100644 (file)
index 0000000..82e9a06
--- /dev/null
@@ -0,0 +1,103 @@
+/*******************************************************************************
+ * 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;
+
+public class DoubleArrayPropertyManipulator2 implements PropertyManipulator {
+       
+       ValueProvider provider;
+       Object input;
+       
+       boolean editMode;
+       double[] editValue = null;
+       
+       public DoubleArrayPropertyManipulator2(ValueProvider provider, Object input) {
+               this.provider = provider;
+               this.input = input;
+       }
+       
+       @Override
+    public int getValueCount() {
+        return getValue().length+1;
+    }
+       
+       @Override
+    public String getDescription(int i) {
+        return "Value " + i;
+    }
+       
+       private double[] getValue() {
+        try {
+            return (double[])provider.getValue(input);
+        } catch (Exception e) {
+            return new double[0];
+        }
+    }
+       
+       @Override
+       public String getValue(int i) {
+               if (editMode) {
+                   if (i < editValue.length)
+                       return Double.toString(editValue[i]);
+                       return "";
+               }
+               try {
+                   double[] val = getValue();
+                   if (val.length == i)
+                       return "New";
+            if (val.length < i)
+                return null;
+            return Double.toString(val[i]);
+               } catch (Exception e) {
+                       return null;
+               }
+       }
+       
+       @Override
+       public String setValue(String value, int i) {
+               try {
+                       double[] val = editValue;
+                       if (value.length() == 0 && i == val.length -1) {
+                           double[] newVal = new double[val.length-1];
+                System.arraycopy(val, 0, newVal, 0, val.length-1);
+                val = newVal;
+                       } else if (i < val.length)
+                           val[i] = Double.parseDouble(value);
+                       else if (i == val.length) {
+                           double[] newVal = new double[val.length+1];
+                           System.arraycopy(val, 0, newVal, 0, val.length);
+                           val = newVal;
+                       }
+                       provider.setValue(input, val);
+               } catch (Exception e) {
+                       return e.getMessage();
+               }
+               return null;
+       }
+
+       @Override
+       public boolean getEditMode() {
+               return editMode;
+       }
+       
+       @Override
+       public void setEditMode(boolean b) {
+               editMode = b;
+               if (editMode) {
+                       try {
+                               editValue = getValue();
+                       } catch (Exception e) {
+                               
+                       }
+               }
+               
+       }
+}
index 9c23332b923ce505898a42fef0ec97762f5f8fe1..47f6ca7d21fb93066971e9982c93485bad242573 100644 (file)
@@ -1,80 +1,78 @@
-/*******************************************************************************\r
- * Copyright (c) 2012, 2013 Association for Decentralized Information Management in\r
- * 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.g3d.property;\r
-\r
-import java.lang.reflect.Method;\r
-\r
-public class DoublePropertyManipulator implements PropertyManipulator {\r
-       \r
-       ValueProvider provider;\r
-       Object input;\r
-       \r
-       boolean editMode;\r
-       String editValue = null;\r
-       \r
-       public DoublePropertyManipulator(ValueProvider provider, Object input) {\r
-               this.provider = provider;\r
-               this.input = input;\r
-       }\r
-       \r
-       @Override\r
-       public int getValueCount() {\r
-               return 1;\r
-       }\r
-       \r
-       @Override\r
-       public String getDescription(int i) {\r
-               if (i == 0)\r
-                       return "Value";\r
-               return null;\r
-       }\r
-       \r
-       @Override\r
-       public String getValue(int i) {\r
-               if (editMode)\r
-                       return editValue;\r
-               try {\r
-                       return provider.getValue(input).toString();\r
-               } catch (Exception e) {\r
-                       return null;\r
-               }\r
-       }\r
-       \r
-       @Override\r
-       public String setValue(String value, int i) {\r
-               try {\r
-                       editValue = value;\r
-                       provider.setValue(input, Double.parseDouble(value));\r
-               } catch (Exception e) {\r
-                       return e.getMessage();\r
-               }\r
-               return null;\r
-       }\r
-\r
-       @Override\r
-       public boolean getEditMode() {\r
-               return editMode;\r
-       }\r
-       \r
-       @Override\r
-       public void setEditMode(boolean b) {\r
-               editMode = b;\r
-               if (editMode) {\r
-                       try {\r
-                               editValue = provider.getValue(input).toString();\r
-                       } catch (Exception e) {\r
-                               \r
-                       }\r
-               }\r
-               \r
-       }\r
-}\r
+/*******************************************************************************
+ * 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;
+
+public class DoublePropertyManipulator implements PropertyManipulator {
+       
+       ValueProvider provider;
+       Object input;
+       
+       boolean editMode;
+       String editValue = null;
+       
+       public DoublePropertyManipulator(ValueProvider provider, Object input) {
+               this.provider = 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) {
+               if (editMode)
+                       return editValue;
+               try {
+                       return provider.getValue(input).toString();
+               } catch (Exception e) {
+                       return null;
+               }
+       }
+       
+       @Override
+       public String setValue(String value, int i) {
+               try {
+                       editValue = value;
+                       provider.setValue(input, Double.parseDouble(value));
+               } catch (Exception e) {
+                       return e.getMessage();
+               }
+               return null;
+       }
+
+       @Override
+       public boolean getEditMode() {
+               return editMode;
+       }
+       
+       @Override
+       public void setEditMode(boolean b) {
+               editMode = b;
+               if (editMode) {
+                       try {
+                               editValue = provider.getValue(input).toString();
+                       } catch (Exception e) {
+                               
+                       }
+               }
+               
+       }
+}
index 415dd2d77e78bda21fbc8caaee491c90b8aeb435..775240e67837387d360a936a3d0e9331cc1e0ed0 100644 (file)
@@ -1,80 +1,81 @@
-/*******************************************************************************\r
- * Copyright (c) 2012, 2013 Association for Decentralized Information Management in\r
- * 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.g3d.property;\r
-\r
-import java.lang.reflect.Method;\r
-\r
-public class StringPropertyManipulator implements PropertyManipulator {\r
-       \r
-       ValueProvider provider;\r
-       Object input;\r
-       \r
-       boolean editMode;\r
-       String editValue = null;\r
-       \r
-       public StringPropertyManipulator(ValueProvider provider, Object input) {\r
-               this.provider = provider;\r
-               this.input = input;\r
-       }\r
-       \r
-       @Override\r
-       public int getValueCount() {\r
-               return 1;\r
-       }\r
-       \r
-       @Override\r
-       public String getDescription(int i) {\r
-               if (i == 0)\r
-                       return "Value";\r
-               return null;\r
-       }\r
-       \r
-       @Override\r
-       public String getValue(int i) {\r
-               if (editMode)\r
-                       return editValue;\r
-               try {\r
-                       return provider.getValue(input).toString();\r
-               } catch (Exception e) {\r
-                       return null;\r
-               }\r
-       }\r
-       \r
-       @Override\r
-       public String setValue(String value, int i) {\r
-               try {\r
-                       editValue = value;\r
-                       provider.setValue(input, value);\r
-               } catch (Exception e) {\r
-                       return e.getMessage();\r
-               }\r
-               return null;\r
-       }\r
-\r
-       @Override\r
-       public boolean getEditMode() {\r
-               return editMode;\r
-       }\r
-       \r
-       @Override\r
-       public void setEditMode(boolean b) {\r
-               editMode = b;\r
-               if (editMode) {\r
-                       try {\r
-                               editValue = provider.getValue(input).toString();\r
-                       } catch (Exception e) {\r
-                               \r
-                       }\r
-               }\r
-               \r
-       }\r
-}\r
+/*******************************************************************************
+ * 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;
+
+public class StringPropertyManipulator implements PropertyManipulator {
+       
+       ValueProvider provider;
+       Object input;
+       
+       boolean editMode;
+       String editValue = null;
+       
+       public StringPropertyManipulator(ValueProvider provider, Object input) {
+               this.provider = 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) {
+               if (editMode)
+                       return editValue;
+               try {
+                   Object o = provider.getValue(input);
+                   if (o == null)
+                       return null;
+                       return o.toString();
+               } catch (Exception e) {
+                       return null;
+               }
+       }
+       
+       @Override
+       public String setValue(String value, int i) {
+               try {
+                       editValue = value;
+                       provider.setValue(input, value);
+               } catch (Exception e) {
+                       return e.getMessage();
+               }
+               return null;
+       }
+
+       @Override
+       public boolean getEditMode() {
+               return editMode;
+       }
+       
+       @Override
+       public void setEditMode(boolean b) {
+               editMode = b;
+               if (editMode) {
+                       try {
+                               editValue = provider.getValue(input).toString();
+                       } catch (Exception e) {
+                               
+                       }
+               }
+               
+       }
+}
index 7a8df5e1ce83648ad759e1007c8e5984bae53abd..e0a8021925ff87635da054ced8170e9c71926a13 100644 (file)
-/*******************************************************************************\r
- * Copyright (c) 2012, 2013 Association for Decentralized Information Management in\r
- * 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.g3d.property;\r
-\r
-import java.lang.reflect.InvocationTargetException;\r
-import java.lang.reflect.Method;\r
-\r
-import javax.vecmath.Vector3d;\r
-\r
-public class VectorPropertyManipulator implements PropertyManipulator {\r
-       \r
-       ValueProvider provider;\r
-       protected Object input;\r
-       \r
-       boolean editMode;\r
-       Vector3d editValue = null;\r
-       \r
-       public VectorPropertyManipulator(ValueProvider provider, Object input) {\r
-               this.provider = provider;\r
-               this.input = input;\r
-       }\r
-       \r
-       @Override\r
-       public int getValueCount() {\r
-               return 3;\r
-       }\r
-       \r
-       @Override\r
-       public String getDescription(int i) {\r
-               if (i == 0)\r
-                       return "X";\r
-               if (i == 1)\r
-                       return "Y";\r
-               if (i == 2)\r
-                       return "Z";\r
-               return null;\r
-       }\r
-       \r
-       @Override\r
-       public String getValue(int i) {\r
-               try {\r
-                       Vector3d v = _getValue();\r
-                       if (v == null)\r
-                               return null;\r
-                       if (i == 0)\r
-                               return Double.toString(v.x);\r
-                       if (i == 1)\r
-                               return Double.toString(v.y);\r
-                       if (i == 2)\r
-                               return Double.toString(v.z);\r
-                       return null;\r
-               } catch (Exception e) {\r
-                       return null;\r
-               }\r
-       }\r
-       \r
-       @Override\r
-       public String setValue(String value, int i) {\r
-               try {\r
-                       Double d = Double.parseDouble(value);\r
-                       Vector3d v = _getValue();\r
-                       v = new Vector3d(v.x, v.y, v.z);\r
-                       if (i == 0)\r
-                               v.x = d;\r
-                       if (i == 1)\r
-                               v.y = d;\r
-                       if (i == 2)\r
-                               v.z = d;\r
-                       editValue = v;\r
-                       setValue(v);\r
-               } catch (Exception e) {\r
-                       return e.getMessage();\r
-               }\r
-               return null;\r
-       }\r
-       \r
-       protected void setValue(Vector3d v) throws Exception {\r
-               provider.setValue(input, v);\r
-       }\r
-       \r
-       private Vector3d _getValue() throws Exception{\r
-               if (editMode)\r
-                       return editValue;\r
-               return (Vector3d) provider.getValue(input);\r
-       }\r
-       \r
-       @Override\r
-       public boolean getEditMode() {\r
-               return editMode;\r
-       }\r
-       \r
-       @Override\r
-       public void setEditMode(boolean b) {\r
-               editMode = b;\r
-               if (editMode) {\r
-                       try {\r
-                               editValue = (Vector3d) provider.getValue(input);\r
-                       } catch (Exception e) {\r
-                               \r
-                       }\r
-               }\r
-               \r
-       }\r
-\r
-}\r
+/*******************************************************************************
+ * 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 javax.vecmath.Vector3d;
+
+public class VectorPropertyManipulator implements PropertyManipulator {
+       
+       ValueProvider provider;
+       protected Object input;
+       
+       boolean editMode;
+       Vector3d editValue = null;
+       
+       public VectorPropertyManipulator(ValueProvider provider, Object input) {
+               this.provider = provider;
+               this.input = input;
+       }
+       
+       @Override
+       public int getValueCount() {
+               return 3;
+       }
+       
+       @Override
+       public String getDescription(int i) {
+               if (i == 0)
+                       return "X";
+               if (i == 1)
+                       return "Y";
+               if (i == 2)
+                       return "Z";
+               return null;
+       }
+       
+       @Override
+       public String getValue(int i) {
+               try {
+                       Vector3d v = _getValue();
+                       if (v == null)
+                               return null;
+                       if (i == 0)
+                               return Double.toString(v.x);
+                       if (i == 1)
+                               return Double.toString(v.y);
+                       if (i == 2)
+                               return Double.toString(v.z);
+                       return null;
+               } catch (Exception e) {
+                       return null;
+               }
+       }
+       
+       @Override
+       public String setValue(String value, int i) {
+               try {
+                       Double d = Double.parseDouble(value);
+                       Vector3d v = _getValue();
+                       v = new Vector3d(v.x, v.y, v.z);
+                       if (i == 0)
+                               v.x = d;
+                       if (i == 1)
+                               v.y = d;
+                       if (i == 2)
+                               v.z = d;
+                       editValue = v;
+                       setValue(v);
+               } catch (Exception e) {
+                       return e.getMessage();
+               }
+               return null;
+       }
+       
+       protected void setValue(Vector3d v) throws Exception {
+               provider.setValue(input, v);
+       }
+       
+       private Vector3d _getValue() throws Exception{
+               if (editMode)
+                       return editValue;
+               return (Vector3d) provider.getValue(input);
+       }
+       
+       @Override
+       public boolean getEditMode() {
+               return editMode;
+       }
+       
+       @Override
+       public void setEditMode(boolean b) {
+               editMode = b;
+               if (editMode) {
+                       try {
+                               editValue = (Vector3d) provider.getValue(input);
+                       } catch (Exception e) {
+                               
+                       }
+               }
+               
+       }
+
+}