From c1ceb1dbf10ba8e21d2d728716cc0d55c131792b Mon Sep 17 00:00:00 2001 From: Johannes Eder <eder@fortiss.org> Date: Tue, 17 Oct 2017 08:00:43 +0000 Subject: [PATCH] Spinner editing support --- .../AbstractIntegerSpinnerEditingSupport.java | 107 ++++++++++++++++++ 1 file changed, 107 insertions(+) create mode 100644 org.fortiss.tooling.base.ui/trunk/src/org/fortiss/tooling/base/ui/tablecell/AbstractIntegerSpinnerEditingSupport.java diff --git a/org.fortiss.tooling.base.ui/trunk/src/org/fortiss/tooling/base/ui/tablecell/AbstractIntegerSpinnerEditingSupport.java b/org.fortiss.tooling.base.ui/trunk/src/org/fortiss/tooling/base/ui/tablecell/AbstractIntegerSpinnerEditingSupport.java new file mode 100644 index 000000000..430fb79a2 --- /dev/null +++ b/org.fortiss.tooling.base.ui/trunk/src/org/fortiss/tooling/base/ui/tablecell/AbstractIntegerSpinnerEditingSupport.java @@ -0,0 +1,107 @@ +/*--------------------------------------------------------------------------+ +$Id: codetemplates.xml 1 2011-01-01 00:00:01Z hoelzl $ +| | +| Copyright 2017 fortiss GmbH | +| | +| Licensed under the Apache License, Version 2.0 (the "License"); | +| you may not use this file except in compliance with the License. | +| You may obtain a copy of the License at | +| | +| http://www.apache.org/licenses/LICENSE-2.0 | +| | +| Unless required by applicable law or agreed to in writing, software | +| distributed under the License is distributed on an "AS IS" BASIS, | +| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | +| See the License for the specific language governing permissions and | +| limitations under the License. | ++--------------------------------------------------------------------------*/ +package org.fortiss.tooling.base.ui.tablecell; + +import org.eclipse.emf.ecore.EObject; +import org.eclipse.jface.viewers.CellEditor; +import org.eclipse.jface.viewers.ColumnViewer; +import org.eclipse.jface.viewers.EditingSupport; +import org.eclipse.swt.SWT; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Spinner; + +/** + * + * @author eder + * @author $Author: bayha $ + * @version $Rev: 18709 $ + * @ConQAT.Rating GREEN Hash: 31B4795F99F85B3C5C363D1368F79245 + */ +public abstract class AbstractIntegerSpinnerEditingSupport extends EditingSupport { + /** + * Constructor. + * + * @param viewer + * The {@link ColumnViewer} this {@link EditingSupport} is used in. + */ + protected AbstractIntegerSpinnerEditingSupport(ColumnViewer viewer) { + super(viewer); + } + + /** + * Retrieves the maximum value for the spinner. + * + * @return Maximum value. + */ + protected int getSpinnerMaximum() { + return Integer.MAX_VALUE; + } + + /** + * Retrieves the minimum value for the spinner. + * + * @return Minimum value. + */ + protected int getSpinnerMinimum() { + return 1; + } + + /** {@inheritDoc} */ + @Override + protected CellEditor getCellEditor(Object element) { + if(element instanceof EObject) { + return new CellEditor((Composite)getViewer().getControl()) { + + Spinner spinner; + + /** {@inheritDoc} */ + @Override + protected Control createControl(Composite parent) { + spinner = new Spinner(parent, SWT.NONE); + + spinner.setMinimum(getSpinnerMinimum()); + spinner.setMaximum(getSpinnerMaximum()); + + return spinner; + } + + /** {@inheritDoc} */ + @Override + protected Object doGetValue() { + return spinner.getSelection(); + } + + /** {@inheritDoc} */ + @Override + protected void doSetFocus() { + spinner.setFocus(); + } + + /** {@inheritDoc} */ + @Override + protected void doSetValue(Object value) { + if(value instanceof Integer) { + spinner.setSelection((int)value); + } + } + }; + } + return null; + } +} -- GitLab