Example usage for org.eclipse.jface.resource JFaceResources format

List of usage examples for org.eclipse.jface.resource JFaceResources format

Introduction

In this page you can find the example usage for org.eclipse.jface.resource JFaceResources format.

Prototype

public static String format(String key, Object... args) 

Source Link

Document

Returns the formatted message for the given key in JFace's resource bundle.

Usage

From source file:org.xmind.ui.richtext.AlignmentGroup.java

License:Open Source License

public void update(String propertyName) {
    if (widget == null || currentAction == null)
        return;//from ww  w .j a v  a2  s . co  m

    boolean textChanged = propertyName == null || propertyName.equals(IAction.TEXT);
    boolean imageChanged = propertyName == null || propertyName.equals(IAction.IMAGE);
    boolean tooltipTextChanged = propertyName == null || propertyName.equals(IAction.TOOL_TIP_TEXT);
    boolean enableStateChanged = propertyName == null || propertyName.equals(IAction.ENABLED)
            || propertyName.equals(IContributionManagerOverrides.P_ENABLED);
    boolean checkChanged = (currentAction.getStyle() == IAction.AS_CHECK_BOX
            || currentAction.getStyle() == IAction.AS_RADIO_BUTTON)
            && (propertyName == null || propertyName.equals(IAction.CHECKED));
    ToolItem ti = (ToolItem) widget;
    String text = currentAction.getText();
    // the set text is shown only if there is no image or if forced
    // by MODE_FORCE_TEXT
    boolean showText = text != null && !hasImages(currentAction);

    // only do the trimming if the text will be used
    if (showText && text != null) {
        text = Action.removeAcceleratorText(text);
        text = Action.removeMnemonics(text);
    }

    if (textChanged) {
        String textToSet = showText ? text : ""; //$NON-NLS-1$
        boolean rightStyle = (ti.getParent().getStyle() & SWT.RIGHT) != 0;
        if (rightStyle || !ti.getText().equals(textToSet)) {
            // In addition to being required to update the text if
            // it
            // gets nulled out in the action, this is also a
            // workaround
            // for bug 50151: Using SWT.RIGHT on a ToolBar leaves
            // blank space
            ti.setText(textToSet);
        }
    }

    if (imageChanged) {
        // only substitute a missing image if it has no text
        updateImages(!showText);
    }

    if (tooltipTextChanged || textChanged) {
        String toolTip = currentAction.getToolTipText();
        if ((toolTip == null) || (toolTip.length() == 0)) {
            toolTip = text;
        }

        ExternalActionManager.ICallback callback = ExternalActionManager.getInstance().getCallback();
        String commandId = currentAction.getActionDefinitionId();
        if ((callback != null) && (commandId != null) && (toolTip != null)) {
            String acceleratorText = callback.getAcceleratorText(commandId);
            if (acceleratorText != null && acceleratorText.length() != 0) {
                toolTip = JFaceResources.format("Toolbar_Tooltip_Accelerator", //$NON-NLS-1$
                        new Object[] { toolTip, acceleratorText });
            }
        }

        // if the text is showing, then only set the tooltip if
        // different
        if (!showText || toolTip != null && !toolTip.equals(text)) {
            ti.setToolTipText(toolTip);
        } else {
            ti.setToolTipText(null);
        }
    }

    if (enableStateChanged) {
        boolean shouldBeEnabled = currentAction.isEnabled() && isEnabledAllowed();

        if (ti.getEnabled() != shouldBeEnabled) {
            ti.setEnabled(shouldBeEnabled);
        }
    }

    if (checkChanged) {
        boolean bv = currentAction.isChecked();

        if (ti.getSelection() != bv) {
            ti.setSelection(bv);
        }
    }

}

From source file:Presentation.preferences.DoubleFieldEditor.java

License:Open Source License

/**
 * Sets the range of valid values for this field.
 * @param min the minimum allowed value (inclusive)
 * @param max the maximum allowed value (inclusive)
 *///from  w w w  .  ja v a 2  s.c  o m
public void setValidRange(Double min, Double max) {
    minValidValue = min;
    maxValidValue = max;

    setErrorMessage(JFaceResources.format("Entry must be a value between {1} and {2}", //$NON-NLS-1$
            new Object[] { getLabelText(), min, max }));
}