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