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

📄 hiddentextcelleditor.java

📁 基于Eclipse RCP开发的管理工具
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
 /*    * Copyright 2006 Marcel Schoffelmeer   *   * 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 com.s10r.manager.view;import java.text.MessageFormat;	// Not using ICU to support standalone JFace scenarioimport org.eclipse.core.runtime.Assert;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.ModifyEvent;import org.eclipse.swt.events.ModifyListener;import org.eclipse.swt.events.MouseAdapter;import org.eclipse.swt.events.MouseEvent;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.widgets.Composite;import org.eclipse.swt.widgets.Control;import org.eclipse.swt.widgets.Text;/** * A cell editor that manages a text entry field. * The cell editor's value is the text string itself. * <p> * This class may be instantiated; it is not intended to be subclassed. * </p> */public class HiddenTextCellEditor extends CellEditor {    /**     * The text control; initially <code>null</code>.     */    protected Text text;    private ModifyListener modifyListener;    /**     * State information for updating action enablement     */    private boolean isSelection = false;    private boolean isDeleteable = false;    private boolean isSelectable = false;    /**     * Default TextCellEditor style     * specify no borders on text widget as cell outline in table already     * provides the look of a border.     */    private static final int defaultStyle = SWT.SINGLE;    /**     * Creates a new text string cell editor with no control     * The cell editor value is the string itself, which is initially the empty     * string. Initially, the cell editor has no cell validator.     *      * @since 2.1     */    public HiddenTextCellEditor() {        setStyle(defaultStyle);            }    /**     * Creates a new text string cell editor parented under the given control.     * The cell editor value is the string itself, which is initially the empty string.      * Initially, the cell editor has no cell validator.     *     * @param parent the parent control     */    public HiddenTextCellEditor(Composite parent) {        this(parent, defaultStyle);    }    /**     * Creates a new text string cell editor parented under the given control.     * The cell editor value is the string itself, which is initially the empty string.      * Initially, the cell editor has no cell validator.     *     * @param parent the parent control     * @param style the style bits     * @since 2.1     */    public HiddenTextCellEditor(Composite parent, int style) {        super(parent, style);    }    /**     * Checks to see if the "deleteable" state (can delete/     * nothing to delete) has changed and if so fire an     * enablement changed notification.     */    private void checkDeleteable() {        boolean oldIsDeleteable = isDeleteable;        isDeleteable = isDeleteEnabled();        if (oldIsDeleteable != isDeleteable) {            fireEnablementChanged(DELETE);        }    }    /**     * Checks to see if the "selectable" state (can select)     * has changed and if so fire an enablement changed notification.     */    private void checkSelectable() {        boolean oldIsSelectable = isSelectable;        isSelectable = isSelectAllEnabled();        if (oldIsSelectable != isSelectable) {            fireEnablementChanged(SELECT_ALL);        }    }    /**     * Checks to see if the selection state (selection /     * no selection) has changed and if so fire an     * enablement changed notification.     */    private void checkSelection() {        boolean oldIsSelection = isSelection;        isSelection = text.getSelectionCount() > 0;        if (oldIsSelection != isSelection) {            fireEnablementChanged(COPY);            fireEnablementChanged(CUT);        }    }    /* (non-Javadoc)     * Method declared on CellEditor.     */    protected Control createControl(Composite parent) {        text = new Text(parent, getStyle());        // text.setEchoChar('*');                text.addSelectionListener(new SelectionAdapter() {            public void widgetDefaultSelected(SelectionEvent e) {                handleDefaultSelection(e);            }        });        text.addKeyListener(new KeyAdapter() {            // hook key pressed - see PR 14201              public void keyPressed(KeyEvent e) {                keyReleaseOccured(e);                // as a result of processing the above call, clients may have                // disposed this cell editor                if ((getControl() == null) || getControl().isDisposed()) {					return;				}                checkSelection(); // see explaination below                checkDeleteable();                checkSelectable();            }        });        text.addTraverseListener(new TraverseListener() {            public void keyTraversed(TraverseEvent e) {                if (e.detail == SWT.TRAVERSE_ESCAPE                        || e.detail == SWT.TRAVERSE_RETURN) {                    e.doit = false;                }            }        });        // We really want a selection listener but it is not supported so we        // use a key listener and a mouse listener to know when selection changes        // may have occured        text.addMouseListener(new MouseAdapter() {            public void mouseUp(MouseEvent e) {                checkSelection();                checkDeleteable();                checkSelectable();            }        });        text.addFocusListener(new FocusAdapter() {            public void focusLost(FocusEvent e) {                HiddenTextCellEditor.this.focusLost();            }        });        text.setFont(parent.getFont());        text.setBackground(parent.getBackground());        text.setText("");//$NON-NLS-1$        text.addModifyListener(getModifyListener());        return text;    }    /**     * The <code>TextCellEditor</code> implementation of     * this <code>CellEditor</code> framework method returns     * the text string.     *     * @return the text string     */    protected Object doGetValue() {        return text.getText();    }    /* (non-Javadoc)     * Method declared on CellEditor.     */    protected void doSetFocus() {        if (text != null) {            text.selectAll();            text.setFocus();            checkSelection();            checkDeleteable();            checkSelectable();        }    }    /**     * The <code>TextCellEditor</code> implementation of     * this <code>CellEditor</code> framework method accepts     * a text string (type <code>String</code>).     *     * @param value a text string (type <code>String</code>)     */    protected void doSetValue(Object value) {        Assert.isTrue(text != null && (value instanceof String));        text.removeModifyListener(getModifyListener());        text.setText((String) value);        text.addModifyListener(getModifyListener());    }    /**     * Processes a modify event that occurred in this text cell editor.

⌨️ 快捷键说明

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