diff options
Diffstat (limited to 'plugins/infra/ui/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/editors/MultipleDoubleEditor.java')
-rw-r--r-- | plugins/infra/ui/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/editors/MultipleDoubleEditor.java | 88 |
1 files changed, 78 insertions, 10 deletions
diff --git a/plugins/infra/ui/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/editors/MultipleDoubleEditor.java b/plugins/infra/ui/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/editors/MultipleDoubleEditor.java index 7629b33e550..6e32bf34bee 100644 --- a/plugins/infra/ui/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/editors/MultipleDoubleEditor.java +++ b/plugins/infra/ui/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/editors/MultipleDoubleEditor.java @@ -1,5 +1,5 @@ /***************************************************************************** - * Copyright (c) 2014 CEA LIST. + * Copyright (c) 2014, 2017 CEA LIST. * * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 @@ -7,10 +7,14 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: + * Fanch BONNABESSE (ALL4TEC) fanch.bonnabesse@all4tec.net - Bug 521902 *****************************************************************************/ package org.eclipse.papyrus.infra.widgets.editors; +import org.eclipse.jface.viewers.CellEditor; +import org.eclipse.jface.viewers.ICellEditorValidator; +import org.eclipse.jface.viewers.TextCellEditor; import org.eclipse.papyrus.infra.widgets.selectors.RealSelector; import org.eclipse.swt.widgets.Composite; @@ -18,9 +22,8 @@ import org.eclipse.swt.widgets.Composite; public class MultipleDoubleEditor extends MultipleStringEditor<RealSelector> { /** - * Constructs an Editor for multiple double values - * The widget is a List, with controls to move values up/down, add values - * and remove values. + * Constructs an Editor for multiple double values. + * The widget is a List, with controls to move values up/down, add values and remove values. * * @param parent * The Composite in which this editor is created @@ -32,9 +35,8 @@ public class MultipleDoubleEditor extends MultipleStringEditor<RealSelector> { } /** - * Constructs an Editor for multiple double values - * The widget is a List, with controls to move values up/down, add values - * and remove values. + * Constructs an Editor for multiple double values. + * The widget is a List, with controls to move values up/down, add values and remove values. * * @param parent * The Composite in which this editor is created @@ -48,9 +50,8 @@ public class MultipleDoubleEditor extends MultipleStringEditor<RealSelector> { } /** - * Constructs an Editor for multiple double values - * The widget is a List, with controls to move values up/down, add values - * and remove values. + * Constructs an Editor for multiple double values. + * The widget is a List, with controls to move values up/down, add values and remove values. * * @param parent * The Composite in which this editor is created @@ -67,4 +68,71 @@ public class MultipleDoubleEditor extends MultipleStringEditor<RealSelector> { super(parent, style, new RealSelector(), ordered, unique, label); } + /** + * Constructs an Editor for multiple double values. + * The widget is a List, with controls to move values up/down, add values and remove values. + * + * @param parent + * The Composite in which this editor is created + * @param directCreation + * Indicates if the creation and modification are directed. + * @param style + * The List's style + * + * @since 3.1 + */ + public MultipleDoubleEditor(Composite parent, boolean directCreation, int style) { + super(parent, style, new RealSelector(), directCreation); + } + + /** + * {@inheritDoc} + */ + @Override + protected CellEditor createCellEditor(Object element) { + return new DoubleCellEditor(tree); + } + + /** + * {@inheritDoc} + */ + @Override + protected Object getDefaultValue() { + return new Double(0); + } + + /** + * This cell editor ensures that only Double values are supported. + */ + private static class DoubleCellEditor extends TextCellEditor { + public DoubleCellEditor(Composite composite) { + super(composite); + setValidator(new ICellEditorValidator() { + public String isValid(Object object) { + if (object instanceof Double) { + return null; + } else { + String string = (String) object; + try { + Double.parseDouble(string); + return null; + } catch (NumberFormatException exception) { + return exception.getMessage(); + } + } + } + }); + } + + @Override + public Object doGetValue() { + return Double.parseDouble((String) super.doGetValue()); + } + + @Override + public void doSetValue(Object value) { + super.doSetValue(value.toString()); + } + } + } |