]> gerrit.simantics Code Review - simantics/3d.git/blob - org.simantics.g3d/src/org/simantics/g3d/property/IntegerPropertyManipulator.java
Combo property support for annotated property tabs
[simantics/3d.git] / org.simantics.g3d / src / org / simantics / g3d / property / IntegerPropertyManipulator.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 \r
15 public class IntegerPropertyManipulator implements PropertyManipulator {\r
16         \r
17         ValueProvider provider;\r
18         Object input;\r
19         \r
20         boolean editMode;\r
21         String editValue = null;\r
22         \r
23         public IntegerPropertyManipulator(ValueProvider provider, Object input) {\r
24                 this.provider = provider;\r
25                 this.input = input;\r
26         }\r
27         \r
28         @Override\r
29         public int getValueCount() {\r
30                 return 1;\r
31         }\r
32         \r
33         @Override\r
34         public String getDescription(int i) {\r
35                 if (i == 0)\r
36                         return "Value";\r
37                 return null;\r
38         }\r
39         \r
40         @Override\r
41         public String getValue(int i) {\r
42                 if (editMode)\r
43                         return editValue;\r
44                 try {\r
45                         Object value = provider.getValue(input);\r
46                         if (value == null) return null;\r
47                         return value.toString();\r
48                 } catch (Exception e) {\r
49                         return null;\r
50                 }\r
51         }\r
52         \r
53         @Override\r
54         public String setValue(String value, int i) {\r
55                 try {\r
56                         editValue = value;\r
57                         provider.setValue(input, Integer.parseInt(value));\r
58                 } catch (Exception e) {\r
59                         return e.getMessage();\r
60                 }\r
61                 return null;\r
62         }\r
63         \r
64         @Override\r
65         public boolean getEditMode() {\r
66                 return editMode;\r
67         }\r
68         \r
69         @Override\r
70         public void setEditMode(boolean b) {\r
71                 editMode = b;\r
72                 if (editMode) {\r
73                         try {\r
74                                 editValue = provider.getValue(input).toString();\r
75                         } catch (Exception e) {\r
76                                 \r
77                         }\r
78                 }\r
79                 \r
80         }\r
81 \r
82 }\r