]> gerrit.simantics Code Review - simantics/3d.git/blob - org.simantics.g3d/src/org/simantics/g3d/property/StringPropertyManipulator.java
Double array properties
[simantics/3d.git] / org.simantics.g3d / src / org / simantics / g3d / property / StringPropertyManipulator.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 StringPropertyManipulator implements PropertyManipulator {
15         
16         ValueProvider provider;
17         Object input;
18         
19         boolean editMode;
20         String editValue = null;
21         
22         public StringPropertyManipulator(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                     Object o = provider.getValue(input);
45                     if (o == null)
46                         return null;
47                         return o.toString();
48                 } catch (Exception e) {
49                         return null;
50                 }
51         }
52         
53         @Override
54         public String setValue(String value, int i) {
55                 try {
56                         editValue = value;
57                         provider.setValue(input, value);
58                 } catch (Exception e) {
59                         return e.getMessage();
60                 }
61                 return null;
62         }
63
64         @Override
65         public boolean getEditMode() {
66                 return editMode;
67         }
68         
69         @Override
70         public void setEditMode(boolean b) {
71                 editMode = b;
72                 if (editMode) {
73                         try {
74                                 editValue = provider.getValue(input).toString();
75                         } catch (Exception e) {
76                                 
77                         }
78                 }
79                 
80         }
81 }