| /******************************************************************************* |
| * Copyright (c) 2018 Agence spatiale canadienne / Canadian Space Agency |
| * 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: |
| * Pierre Allard, |
| * Regent L'Archeveque, |
| * Sebastien Gemme - initial API and implementation |
| * |
| * SPDX-License-Identifier: EPL-1.0 |
| * |
| *******************************************************************************/ |
| package org.eclipse.apogy.common.widgets.ui; |
| |
| import org.eclipse.jface.preference.FieldEditor; |
| import org.eclipse.swt.SWT; |
| import org.eclipse.swt.layout.GridData; |
| import org.eclipse.swt.widgets.Composite; |
| import org.eclipse.swt.widgets.Display; |
| import org.eclipse.swt.widgets.Label; |
| import org.eclipse.swt.widgets.Spinner; |
| |
| public class SpinnerFieldEditor extends FieldEditor { |
| |
| private Composite editorcomp; |
| |
| private Spinner spinner; |
| |
| /** |
| * Creates a SpinnerFieldEditor Example usage: |
| * |
| * <pre> |
| * SpinnerFieldEditor spinner = new SpinnerFieldEditor("Spinner.Example", "Port:", page); |
| * </pre> |
| * |
| * @param name the name of the preference this field editor works on. |
| * @param label the label text of the field editor |
| * @param parent the parent of the field editor's control |
| */ |
| public SpinnerFieldEditor(String name, String label, Composite parent) { |
| super(name, label, parent); |
| } |
| |
| /** |
| * adjust the field edtior for n-columns |
| */ |
| @Override |
| protected void adjustForNumColumns(int numColumns) { |
| ((GridData) this.editorcomp.getLayoutData()).horizontalSpan = numColumns; |
| } |
| |
| /** |
| * Fill the components into the grid |
| */ |
| @Override |
| protected void doFillIntoGrid(Composite parent, int numColumns) { |
| this.editorcomp = parent; |
| |
| GridData griddata = new GridData(GridData.FILL_HORIZONTAL); |
| griddata.horizontalSpan = numColumns; |
| this.editorcomp.setLayoutData(griddata); |
| |
| Label label = getLabelControl(this.editorcomp); |
| griddata = new GridData(); |
| label.setLayoutData(griddata); |
| |
| this.spinner = new Spinner(this.editorcomp, SWT.BORDER); |
| griddata = new GridData(); |
| this.spinner.setLayoutData(griddata); |
| this.spinner.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_LIST_BACKGROUND)); |
| } |
| |
| /** |
| * Returns this field editor's spinner control. |
| * |
| * @return Spinner the spinner of the field editor |
| */ |
| public Spinner getSpinner() { |
| return this.spinner; |
| } |
| |
| /* |
| * (non-Javadoc) Method declared on FieldEditor. |
| */ |
| @Override |
| protected void doLoad() { |
| int loadedint = getPreferenceStore().getInt(getPreferenceName()); |
| this.spinner.setSelection(loadedint); |
| } |
| |
| /* |
| * (non-Javadoc) Method declared on FieldEditor. |
| */ |
| @Override |
| protected void doLoadDefault() { |
| int loadedint = getPreferenceStore().getDefaultInt(getPreferenceName()); |
| this.spinner.setSelection(loadedint); |
| } |
| |
| /* |
| * (non-Javadoc) Method declared on FieldEditor. |
| */ |
| @Override |
| protected void doStore() { |
| getPreferenceStore().setValue(getPreferenceName(), this.spinner.getSelection()); |
| } |
| |
| /* |
| * (non-Javadoc) Method declared on FieldEditor. |
| */ |
| @Override |
| public int getNumberOfControls() { |
| return 2; |
| } |
| |
| } |