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

📄 fieldeditor.java

📁 jfa2ce 源码帮助开发人员更好的理解运用
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
    /**     * Returns the label control.      *     * @return the label control, or <code>null</code>     *  if no label control has been created     */    protected Label getLabelControl() {        return label;    }    /**     * Returns this field editor's label component.     * <p>     * The label is created if it does not already exist     * </p>     *     * @param parent the parent     * @return the label control     */    public Label getLabelControl(Composite parent) {        if (label == null) {            label = new Label(parent, SWT.LEFT);            label.setFont(parent.getFont());            String text = getLabelText();            if (text != null) {				label.setText(text);			}            label.addDisposeListener(new DisposeListener() {                public void widgetDisposed(DisposeEvent event) {                    label = null;                }            });        } else {            checkParent(label, parent);        }        return label;    }    /**     * Returns this field editor's label text.     *     * @return the label text     */    public String getLabelText() {        return labelText;    }    /**     * Returns the number of basic controls this field editor consists of.     *     * @return the number of controls     */    public abstract int getNumberOfControls();    /**     * Returns the name of the preference this field editor operates on.     *     * @return the name of the preference     */    public String getPreferenceName() {        return preferenceName;    }    /**     * Returns the preference page in which this field editor     * appears.     *     * @return the preference page, or <code>null</code> if none     * @deprecated use #getPage()     */    protected PreferencePage getPreferencePage() {    	if(page != null && page instanceof PreferencePage) {			return (PreferencePage) page;		}    	return null;    }        /**     * Return the DialogPage that the receiver is sending     * updates to.     *      * @return DialogPage or <code>null</code> if it      * has not been set.     *      * @since 3.1     */    protected DialogPage getPage(){    	return page;    }    /**     * Returns the preference store used by this field editor.     *     * @return the preference store, or <code>null</code> if none     * @see #setPreferenceStore     */    public IPreferenceStore getPreferenceStore() {        return preferenceStore;    }    /**     * Initialize the field editor with the given preference name and label.     *      * @param name the name of the preference this field editor works on     * @param text the label text of the field editor     */    protected void init(String name, String text) {        Assert.isNotNull(name);        Assert.isNotNull(text);        preferenceName = name;        this.labelText = text;    }    /**     * Returns whether this field editor contains a valid value.     * <p>     * The default implementation of this framework method     * returns <code>true</code>. Subclasses wishing to perform     * validation should override both this method and     * <code>refreshValidState</code>.     * </p>     *      * @return <code>true</code> if the field value is valid,     *   and <code>false</code> if invalid     * @see #refreshValidState()     */    public boolean isValid() {        return true;    }    /**     * Initializes this field editor with the preference value from     * the preference store.     */    public void load() {        if (preferenceStore != null) {            isDefaultPresented = false;            doLoad();            refreshValidState();        }    }    /**     * Initializes this field editor with the default preference value     * from the preference store.     */    public void loadDefault() {        if (preferenceStore != null) {            isDefaultPresented = true;            doLoadDefault();            refreshValidState();        }    }    /**     * Returns whether this field editor currently presents the     * default value for its preference.     *      * @return <code>true</code> if the default value is presented,     *   and <code>false</code> otherwise     */    public boolean presentsDefaultValue() {        return isDefaultPresented;    }    /**     * Refreshes this field editor's valid state after a value change     * and fires an <code>IS_VALID</code> property change event if     * warranted.     * <p>     * The default implementation of this framework method does     * nothing. Subclasses wishing to perform validation should override     * both this method and <code>isValid</code>.     * </p>     *     * @see #isValid     */    protected void refreshValidState() {    }    /**     * Sets the focus to this field editor.     * <p>     * The default implementation of this framework method     * does nothing. Subclasses may reimplement.     * </p>     */    public void setFocus() {        // do nothing;    }    /**     * Sets this field editor's label text.     * The label is typically presented to the left of the entry field.     *     * @param text the label text     */    public void setLabelText(String text) {        Assert.isNotNull(text);        labelText = text;        if (label != null) {			label.setText(text);		}    }    /**     * Sets the name of the preference this field editor operates on.     * <p>     * The ability to change this allows the same field editor object     * to be reused for different preferences.     * </p>     * <p>     * For example: <p>     * <pre>     * 	...     *  editor.setPreferenceName("font");     * 	editor.load();     * </pre>     * </p>     *     * @param name the name of the preference     */    public void setPreferenceName(String name) {        preferenceName = name;    }    /**     * Sets the preference page in which this field editor     * appears.     *     * @param preferencePage the preference page, or <code>null</code> if none     * @deprecated use #setPage(DialogPage)     */    public void setPreferencePage(PreferencePage preferencePage) {        setPage(preferencePage);    }        /**     * Set the page to be the receiver.	 * @param dialogPage	 * 	 * @since 3.1	 */	public void setPage(DialogPage dialogPage) {		page = dialogPage;			}	/**     * Sets the preference store used by this field editor.     *     * @param store the preference store, or <code>null</code> if none     * @see #getPreferenceStore     */    public void setPreferenceStore(IPreferenceStore store) {        preferenceStore = store;    }    /**     * Sets whether this field editor is presenting the default value.     *     * @param booleanValue <code>true</code> if the default value is being presented,     *  and <code>false</code> otherwise     */    protected void setPresentsDefaultValue(boolean booleanValue) {        isDefaultPresented = booleanValue;    }    /**     * Sets or removes the property change listener for this field editor.     * <p>     * Note that field editors can support only a single listener.     * </p>     *     * @param listener a property change listener, or <code>null</code>     *  to remove     */    public void setPropertyChangeListener(IPropertyChangeListener listener) {        propertyChangeListener = listener;    }    /**     * Shows the given error message in the page for this     * field editor if it has one.     *     * @param msg the error message     */    protected void showErrorMessage(String msg) {        if (page != null) {			page.setErrorMessage(msg);		}    }    /**     * Shows the given message in the page for this     * field editor if it has one.     *     * @param msg the message     */    protected void showMessage(String msg) {        if (page != null) {			page.setErrorMessage(msg);		}    }    /**     * Stores this field editor's value back into the preference store.     */    public void store() {        if (preferenceStore == null) {			return;		}        if (isDefaultPresented) {            preferenceStore.setToDefault(preferenceName);        } else {            doStore();        }    }    /**     * Set the GridData on button to be one that is spaced for the     * current font.     * @param button the button the data is being set on.     */    protected void setButtonLayoutData(Button button) {        GridData data = new GridData(GridData.HORIZONTAL_ALIGN_FILL);        // Compute and store a font metric        GC gc = new GC(button);        gc.setFont(button.getFont());        FontMetrics fontMetrics = gc.getFontMetrics();        gc.dispose();        int widthHint = org.eclipse.jface.dialogs.Dialog                .convertVerticalDLUsToPixels(fontMetrics,                        IDialogConstants.BUTTON_WIDTH);        data.widthHint = Math.max(widthHint, button.computeSize(SWT.DEFAULT,                SWT.DEFAULT, true).x);        button.setLayoutData(data);    }    /**     * Set whether or not the controls in the field editor     * are enabled.     * @param enabled The enabled state.     * @param parent The parent of the controls in the group.     *  Used to create the controls if required.     */    public void setEnabled(boolean enabled, Composite parent) {        getLabelControl(parent).setEnabled(enabled);    }}

⌨️ 快捷键说明

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