]> gerrit.simantics Code Review - simantics/3d.git/blob - org.simantics.g3d/src/org/simantics/g3d/property/BooleanPropertyManipulator.java
Copyrights
[simantics/3d.git] / org.simantics.g3d / src / org / simantics / g3d / property / BooleanPropertyManipulator.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 BooleanPropertyManipulator 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 BooleanPropertyManipulator(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                         return provider.getValue(input).toString();\r
46                 } catch (Exception e) {\r
47                         return null;\r
48                 }\r
49         }\r
50         \r
51         @Override\r
52         public String setValue(String value, int i) {\r
53                 try {\r
54                         editValue = value;\r
55                         provider.setValue(input, Boolean.parseBoolean(value));\r
56                 } catch (Exception e) {\r
57                         return e.getMessage();\r
58                 }\r
59                 return null;\r
60         }\r
61         \r
62         @Override\r
63         public boolean getEditMode() {\r
64                 return editMode;\r
65         }\r
66         \r
67         @Override\r
68         public void setEditMode(boolean b) {\r
69                 editMode = b;\r
70                 if (editMode) {\r
71                         try {\r
72                                 editValue = provider.getValue(input).toString();\r
73                         } catch (Exception e) {\r
74                                 \r
75                         }\r
76                 }\r
77                 \r
78         }\r
79 \r
80 }\r