Community
Participate
Working Groups
I have a working piece of code for SpinnerCellEditor. Can u plz. tell me how to add this to eclipse cvs ?
Attach it here as a patch and someone on our team will review it on your behalf.
// SpinnerCellEditor is based on the code of ComboboxCellEditor ... package com.tibco.cep.eclipse.editor.resource.presentation.uifields; import org.eclipse.jface.viewers.CellEditor; import org.eclipse.swt.SWT; import org.eclipse.swt.events.FocusAdapter; import org.eclipse.swt.events.FocusEvent; import org.eclipse.swt.events.KeyAdapter; import org.eclipse.swt.events.KeyEvent; import org.eclipse.swt.events.SelectionAdapter; import org.eclipse.swt.events.SelectionEvent; import org.eclipse.swt.events.TraverseEvent; import org.eclipse.swt.events.TraverseListener; import org.eclipse.swt.graphics.GC; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Control; import org.eclipse.swt.widgets.Spinner; /** * This is a cell editor to display a spinner. * * @author kaniska * */ public class SpinnerCellEditor extends CellEditor { /** * The zero-based index of the selected item. */ int selection; /** * The custom spinner control. */ Spinner spinner; /** * Default SpinnerCellEditor style */ private static final int defaultStyle = SWT.NONE; public SpinnerCellEditor() { setStyle(defaultStyle); } public SpinnerCellEditor(Composite parent) { super(parent, defaultStyle); } protected Control createControl(Composite parent) { spinner = new Spinner(parent, SWT.NONE); spinner.setMinimum(0); spinner.setMaximum(1024); spinner.setSelection(0); spinner.setIncrement(1); spinner.setSize(120, 80); spinner.addKeyListener(new KeyAdapter() { // hook key pressed - see PR 14201 public void keyPressed(KeyEvent e) { keyReleaseOccured(e); } }); spinner.addSelectionListener(new SelectionAdapter() { public void widgetDefaultSelected(SelectionEvent event) { applyEditorValueAndDeactivate(); } public void widgetSelected(SelectionEvent event) { selection = spinner.getSelection(); } }); spinner.addTraverseListener(new TraverseListener() { public void keyTraversed(TraverseEvent e) { if (e.detail == SWT.TRAVERSE_ESCAPE || e.detail == SWT.TRAVERSE_RETURN) { e.doit = false; } } }); spinner.addFocusListener(new FocusAdapter() { public void focusLost(FocusEvent e) { SpinnerCellEditor.this.focusLost(); } }); return spinner; } /** * The <code>SpinnerCellEditor</code> implementation of * this <code>CellEditor</code> framework method returns * the zero-based index of the current selection. * * @return the zero-based index of the current selection wrapped * as an <code>Integer</code> */ protected Object doGetValue() { return new Integer(selection); } /* (non-Javadoc) * Method declared on CellEditor. */ protected void doSetFocus() { spinner.setFocus(); } /** * */ protected void doSetValue(Object value) { if(null != value && ((String)value).length()>0) selection = new Integer((String)value).intValue(); else selection = 0; spinner.setSelection(selection); } public LayoutData getLayoutData() { LayoutData layoutData = super.getLayoutData(); if ((spinner == null) || spinner.isDisposed()) layoutData.minimumWidth = 30; else { // make the spinner 10 characters wide GC gc = new GC(spinner); layoutData.minimumWidth = (gc.getFontMetrics() .getAverageCharWidth() * 10) + 10; gc.dispose(); } return layoutData; } void applyEditorValueAndDeactivate() { // must set the selection before getting value selection = spinner.getSelection(); Object newValue = doGetValue(); markDirty(); boolean isValid = isCorrect(newValue); setValueValid(isValid); fireApplyEditorValue(); deactivate(); } /* * (non-Javadoc) * @see org.eclipse.jface.viewers.CellEditor#focusLost() */ protected void focusLost() { if (isActivated()) { applyEditorValueAndDeactivate(); } } /* * (non-Javadoc) * @see org.eclipse.jface.viewers.CellEditor#keyReleaseOccured(org.eclipse.swt.events.KeyEvent) */ protected void keyReleaseOccured(KeyEvent keyEvent) { if (keyEvent.character == '\u001b') { // Escape character fireCancelEditor(); } else if (keyEvent.character == '\t') { // tab key applyEditorValueAndDeactivate(); } } }
Changing to enhancement.
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet. If you have further information on the current state of the bug, please add it. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant.