Package de.innovationgate.eclipse.utils.ui

Source Code of de.innovationgate.eclipse.utils.ui.DoubleValueCellEditor

/*******************************************************************************
* Copyright (c) 2009, 2010 Innovation Gate GmbH.
* 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:
*     Innovation Gate GmbH - initial API and implementation
******************************************************************************/

package de.innovationgate.eclipse.utils.ui;

import org.eclipse.jface.viewers.ICellEditorValidator;
import org.eclipse.jface.viewers.TextCellEditor;
import org.eclipse.swt.widgets.Composite;

public class DoubleValueCellEditor extends TextCellEditor {

    public DoubleValueCellEditor(Composite composite) {
        super(composite);
        setValidator(new ICellEditorValidator() {
            public String isValid(Object object) {
                if (object instanceof Number) {
                    return null;
                } else {
                    String string = (String) object;
                    try {
                        Double.parseDouble(string);
                        return null;
                    }
                    catch (NumberFormatException e) {
                        return e.getMessage();
                    }
                }
            }
        });
    }

    public Object doGetValue() {
        return new Double(Double.parseDouble((String) super.doGetValue()));
    }

    public void doSetValue(Object value) {
        super.doSetValue(value.toString());
    }

}
TOP

Related Classes of de.innovationgate.eclipse.utils.ui.DoubleValueCellEditor

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.