]> gerrit.simantics Code Review - simantics/3d.git/blob - org.simantics.g3d/src/org/simantics/g3d/property/DoublePropertyManipulator.java
Copyrights
[simantics/3d.git] / org.simantics.g3d / src / org / simantics / g3d / property / DoublePropertyManipulator.java
1 /*******************************************************************************\r
2  * Copyright (c) 2012, 2013 Association for Decentralized Information Management in\r
3  * Industry THTH ry.\r
4  * All rights reserved. This program and the accompanying materials\r
5  * are made available under the terms of the Eclipse Public License v1.0\r
6  * which accompanies this distribution, and is available at\r
7  * http://www.eclipse.org/legal/epl-v10.html\r
8  *\r
9  * Contributors:\r
10  *     VTT Technical Research Centre of Finland - initial API and implementation\r
11  *******************************************************************************/\r
12 package org.simantics.g3d.property;\r
13 \r
14 import java.lang.reflect.Method;\r
15 \r
16 public class DoublePropertyManipulator implements PropertyManipulator {\r
17         \r
18         ValueProvider provider;\r
19         Object input;\r
20         \r
21         boolean editMode;\r
22         String editValue = null;\r
23         \r
24         public DoublePropertyManipulator(ValueProvider provider, Object input) {\r
25                 this.provider = provider;\r
26                 this.input = input;\r
27         }\r
28         \r
29         @Override\r
30         public int getValueCount() {\r
31                 return 1;\r
32         }\r
33         \r
34         @Override\r
35         public String getDescription(int i) {\r
36                 if (i == 0)\r
37                         return "Value";\r
38                 return null;\r
39         }\r
40         \r
41         @Override\r
42         public String getValue(int i) {\r
43                 if (editMode)\r
44                         return editValue;\r
45                 try {\r
46                         return provider.getValue(input).toString();\r
47                 } catch (Exception e) {\r
48                         return null;\r
49                 }\r
50         }\r
51         \r
52         @Override\r
53         public String setValue(String value, int i) {\r
54                 try {\r
55                         editValue = value;\r
56                         provider.setValue(input, Double.parseDouble(value));\r
57                 } catch (Exception e) {\r
58                         return e.getMessage();\r
59                 }\r
60                 return null;\r
61         }\r
62 \r
63         @Override\r
64         public boolean getEditMode() {\r
65                 return editMode;\r
66         }\r
67         \r
68         @Override\r
69         public void setEditMode(boolean b) {\r
70                 editMode = b;\r
71                 if (editMode) {\r
72                         try {\r
73                                 editValue = provider.getValue(input).toString();\r
74                         } catch (Exception e) {\r
75                                 \r
76                         }\r
77                 }\r
78                 \r
79         }\r
80 }\r