/******************************************************************************* * Copyright (c) 2012, 2013 Association for Decentralized Information Management in * Industry THTH ry. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: * VTT Technical Research Centre of Finland - initial API and implementation *******************************************************************************/ package org.simantics.g3d.property; import java.lang.reflect.Method; public class DoublePropertyManipulator implements PropertyManipulator { ValueProvider provider; Object input; boolean editMode; String editValue = null; public DoublePropertyManipulator(ValueProvider provider, Object input) { this.provider = provider; this.input = input; } @Override public int getValueCount() { return 1; } @Override public String getDescription(int i) { if (i == 0) return "Value"; return null; } @Override public String getValue(int i) { if (editMode) return editValue; try { return provider.getValue(input).toString(); } catch (Exception e) { return null; } } @Override public String setValue(String value, int i) { try { editValue = value; provider.setValue(input, Double.parseDouble(value)); } catch (Exception e) { return e.getMessage(); } return null; } @Override public boolean getEditMode() { return editMode; } @Override public void setEditMode(boolean b) { editMode = b; if (editMode) { try { editValue = provider.getValue(input).toString(); } catch (Exception e) { } } } }