⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 celleditor.java

📁 jfa2ce 源码帮助开发人员更好的理解运用
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/******************************************************************************* * Copyright (c) 2000, 2006 IBM Corporation and others. * 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: *     IBM Corporation - initial API and implementation *******************************************************************************/package org.eclipse.jface.viewers;import org.eclipse.core.runtime.ListenerList;import org.eclipse.jface.util.Assert;import org.eclipse.jface.util.IPropertyChangeListener;import org.eclipse.jface.util.PropertyChangeEvent;import org.eclipse.jface.util.SafeRunnable;import org.eclipse.swt.SWT;import org.eclipse.swt.events.KeyEvent;import org.eclipse.swt.widgets.Composite;import org.eclipse.swt.widgets.Control;/** * Abstract base class for cell editors. Implements property change listener handling, * and SWT window management. * <p> * Subclasses implement particular kinds of cell editors. This package contains various * specialized cell editors: * <ul> *   <li><code>TextCellEditor</code> - for simple text strings</li> *   <li><code>ColorCellEditor</code> - for colors</li> *   <li><code>ComboBoxCellEditor</code> - value selected from drop-down combo box</li> *   <li><code>CheckboxCellEditor</code> - boolean valued checkbox</li> *   <li><code>DialogCellEditor</code> - value from arbitrary dialog</li> * </ul> * </p> */public abstract class CellEditor {    /**     * List of cell editor listeners (element type: <code>ICellEditorListener</code>).     */    private ListenerList listeners = new ListenerList();    /**     * List of cell editor property change listeners      * (element type: <code>IPropertyChangeListener</code>).     */    private ListenerList propertyChangeListeners = new ListenerList();    /**     * Indicates whether this cell editor's current value is valid.     */    private boolean valid = false;    /**     * Optional cell editor validator; <code>null</code> if none.     */    private ICellEditorValidator validator = null;    /**     * The error message string to display for invalid values;     * <code>null</code> if none (that is, the value is valid).     */    private String errorMessage = null;    /**     * Indicates whether this cell editor has been changed recently.     */    private boolean dirty = false;    /**     * This cell editor's control, or <code>null</code>     * if not created yet.     */    private Control control = null;    /**     * Default cell editor style     */    private static final int defaultStyle = SWT.NONE;    /**     * This cell editor's style     */    private int style = defaultStyle;    /**      * Struct-like layout data for cell editors, with reasonable defaults     * for all fields.     */    public static class LayoutData {        /**         * Horizontal alignment; <code>SWT.LEFT</code> by default.         */        public int horizontalAlignment = SWT.LEFT;        /**         * Indicates control grabs additional space; <code>true</code> by default.         */        public boolean grabHorizontal = true;        /**         * Minimum width in pixels; <code>50</code> pixels by default.         */        public int minimumWidth = 50;    }    /**     * Property name for the copy action     */    public static final String COPY = "copy"; //$NON-NLS-1$    /**     * Property name for the cut action     */    public static final String CUT = "cut"; //$NON-NLS-1$    /**     * Property name for the delete action     */    public static final String DELETE = "delete"; //$NON-NLS-1$    /**     * Property name for the find action     */    public static final String FIND = "find"; //$NON-NLS-1$    /**     * Property name for the paste action     */    public static final String PASTE = "paste"; //$NON-NLS-1$    /**     * Property name for the redo action     */    public static final String REDO = "redo"; //$NON-NLS-1$    /**     * Property name for the select all action     */    public static final String SELECT_ALL = "selectall"; //$NON-NLS-1$    /**     * Property name for the undo action     */    public static final String UNDO = "undo"; //$NON-NLS-1$    /**     * Creates a new cell editor with no control      * The cell editor has no cell validator.     * @since 2.1     */    protected CellEditor() {    }    /**     * Creates a new cell editor under the given parent control.     * The cell editor has no cell validator.     *     * @param parent the parent control     */    protected CellEditor(Composite parent) {        this(parent, defaultStyle);    }    /**     * Creates a new cell editor under the given parent control.     * The cell editor has no cell validator.     *     * @param parent the parent control     * @param style the style bits     * @since 2.1     */    protected CellEditor(Composite parent, int style) {        this.style = style;        create(parent);    }    /**     * Activates this cell editor.     * <p>     * The default implementation of this framework method     * does nothing. Subclasses may reimplement.     * </p>     */    public void activate() {    }    /**     * Adds a listener to this cell editor.     * Has no effect if an identical listener is already registered.     *     * @param listener a cell editor listener     */    public void addListener(ICellEditorListener listener) {        listeners.add(listener);    }    /**     * Adds a property change listener to this cell editor.     * Has no effect if an identical property change listener      * is already registered.     *     * @param listener a property change listener     */    public void addPropertyChangeListener(IPropertyChangeListener listener) {        propertyChangeListeners.add(listener);    }    /**     * Creates the control for this cell editor under the given parent control.     * <p>     * This framework method must be implemented by concrete     * subclasses.     * </p>     *     * @param parent the parent control     * @return the new control, or <code>null</code> if this cell editor has no control     */    protected abstract Control createControl(Composite parent);    /**     * Creates the control for this cell editor under the given parent control.     *      * @param parent the parent control     * @since 2.1     */    public void create(Composite parent) {        Assert.isTrue(control == null);        control = createControl(parent);        // See 1GD5CA6: ITPUI:ALL - TaskView.setSelection does not work        // Control is created with getVisible()==true by default.        // This causes composite.setFocus() to work incorrectly.        // The cell editor's control grabs focus instead, even if it is not active.        // Make the control invisible here by default.        deactivate();    }    /**     * Hides this cell editor's control. Does nothing if this      * cell editor is not visible.     */    public void deactivate() {        if (control != null && !control.isDisposed()) {			control.setVisible(false);		}    }    /**     * Disposes of this cell editor and frees any associated SWT resources.     */    public void dispose() {        if (control != null && !control.isDisposed()) {            control.dispose();        }        control = null;    }    /**     * Returns this cell editor's value.     * <p>     * This framework method must be implemented by concrete subclasses.     * </p>     *     * @return the value of this cell editor     * @see #getValue     */    protected abstract Object doGetValue();    /**     * Sets the focus to the cell editor's control.     * <p>     * This framework method must be implemented by concrete subclasses.     * </p>     *     * @see #setFocus     */    protected abstract void doSetFocus();    /**     * Sets this cell editor's value.     * <p>     * This framework method must be implemented by concrete subclasses.     * </p>     *     * @param value the value of this cell editor     * @see #setValue     */    protected abstract void doSetValue(Object value);    /**     * Notifies all registered cell editor listeners of an apply event.     * Only listeners registered at the time this method is called are notified.     *     * @see ICellEditorListener#applyEditorValue     */    protected void fireApplyEditorValue() {        Object[] array = listeners.getListeners();        for (int i = 0; i < array.length; i++) {            final ICellEditorListener l = (ICellEditorListener) array[i];            SafeRunnable.run(new SafeRunnable() {                public void run() {                    l.applyEditorValue();                }            });        }    }    /**     * Notifies all registered cell editor listeners that editing has been     * canceled.     *     * @see ICellEditorListener#cancelEditor     */    protected void fireCancelEditor() {        Object[] array = listeners.getListeners();        for (int i = 0; i < array.length; i++) {            final ICellEditorListener l = (ICellEditorListener) array[i];            SafeRunnable.run(new SafeRunnable() {                public void run() {                    l.cancelEditor();                }            });        }    }    /**     * Notifies all registered cell editor listeners of a value change.     *     * @param oldValidState the valid state before the end user changed the value     * @param newValidState the current valid state     * @see ICellEditorListener#editorValueChanged     */    protected void fireEditorValueChanged(final boolean oldValidState,            final boolean newValidState) {        Object[] array = listeners.getListeners();        for (int i = 0; i < array.length; i++) {            final ICellEditorListener l = (ICellEditorListener) array[i];            SafeRunnable.run(new SafeRunnable() {                public void run() {                    l.editorValueChanged(oldValidState, newValidState);                }            });        }    }    /**     * Notifies all registered property listeners     * of an enablement change.     *     * @param actionId the id indicating what action's enablement has changed.     */    protected void fireEnablementChanged(final String actionId) {        Object[] array = propertyChangeListeners.getListeners();        for (int i = 0; i < array.length; i++) {            final IPropertyChangeListener l = (IPropertyChangeListener) array[i];            SafeRunnable.run(new SafeRunnable() {                public void run() {                    l.propertyChange(new PropertyChangeEvent(this, actionId,                            null, null));                }            });        }    }    /**     * Sets the style bits for this cell editor.     *      * @param style the SWT style bits for this cell editor     * @since 2.1     */    public void setStyle(int style) {        this.style = style;    }    /**     * Returns the style bits for this cell editor.     *     * @return the style for this cell editor     * @since 2.1     */    public int getStyle() {        return style;    }    /**     * Returns the control used to implement this cell editor.     *     * @return the control, or <code>null</code> if this cell editor has no control     */    public Control getControl() {        return control;    }    /**     * Returns the current error message for this cell editor.     *      * @return the error message if the cell editor is in an invalid state,     *  and <code>null</code> if the cell editor is valid     */    public String getErrorMessage() {        return errorMessage;    }    /**     * Returns a layout data object for this cell editor.     * This is called each time the cell editor is activated     * and controls the layout of the SWT table editor.     * <p>     * The default implementation of this method sets the      * minimum width to the control's preferred width.     * Subclasses may extend or reimplement.     * </p>     *     * @return the layout data object      */    public LayoutData getLayoutData() {        LayoutData result = new LayoutData();        Control control = getControl();        if (control != null) {            result.minimumWidth = control.computeSize(SWT.DEFAULT, SWT.DEFAULT,                    true).x;        }        return result;    }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -