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:net.enilink.komma.common.ui.dialogs.DiagnosticDialog.java

License:Open Source License

/**
 * Creates an diagnostic dialog. Note that the dialog will have no visual
 * representation (no widgets) until it is told to open.
 * <p>/*from   w  w  w. ja  va2s. c om*/
 * Normally one should use <code>open</code> to create and open one of
 * these. This constructor is useful only if the diagnostic object being
 * displayed contains child items <it>and </it> you need to specify a mask
 * which will be used to filter the displaying of these children. The
 * diagnostic dialog will only be displayed if there is at least one child
 * diagnostic matching the mask.
 * </p>
 * 
 * @param parentShell
 *            the shell under which to create this dialog
 * @param dialogTitle
 *            the title to use for this dialog, or <code>null</code> to
 *            indicate that the default title should be used
 * @param message
 *            the message to show in this dialog, or <code>null</code> to
 *            indicate that the diagnostic's message should be shown as the
 *            primary message
 * @param diagnostic
 *            the diagnostic to show to the user
 * @param severityMask
 *            the mask to use to filter the displaying of child items, as
 *            per
 *            <code>DiagnosticComposite.severityMatches(Diagnostic, int)</code>
 * @see DiagnosticComposite#severityMatches(Diagnostic, int)
 */
public DiagnosticDialog(Shell parentShell, String dialogTitle, String message, Diagnostic diagnostic,
        int severityMask) {
    super(parentShell);
    this.title = dialogTitle == null ? JFaceResources.getString("Problem_Occurred") : dialogTitle;
    this.message = message == null ? diagnostic.getMessage()
            : JFaceResources.format("Reason", new Object[] { message, diagnostic.getMessage() });
    this.diagnostic = diagnostic;
    this.severityMask = severityMask;
    setShellStyle(getShellStyle() | SWT.RESIZE);
}

From source file:net.sf.kerner.utils.rcp.DoubleFieldEditor.java

License:Open Source License

private static String getMessage_invalidRange(final double min, final double max) {
    final String message = JFaceResources.format("IntegerFieldEditor.errorMessageRange", //$NON-NLS-1$
            new Object[] { new Double(min), new Double(max) });
    return replaceInteger_withDouble(message);
}

From source file:nl.utwente.ce.imageexport.ExceptionErrorDialog.java

License:Open Source License

/**
 * @param parentShell the shell under which to create this dialog
 * @param dialogTitle the title to use for this dialog, or <code>null</code> to indicate that the default title
 *            should be used/*from w ww .  ja  v  a  2s . co  m*/
 * @param message the message to show in this dialog, or <code>null</code> to indicate that the error's message
 *            should be shown as the primary message
 * @param status the error to show to the user
 */
public ExceptionErrorDialog(Shell parentShell, String dialogTitle, String message, IStatus status) {
    super(parentShell);
    this.title = dialogTitle == null ? JFaceResources.getString("Problem_Occurred") : //$NON-NLS-1$
            dialogTitle;
    this.message = message == null ? status.getMessage()
            : JFaceResources.format("Reason", new Object[] { message, status.getMessage() }); //$NON-NLS-1$
    this.status = status;
}

From source file:org.csstudio.ui.util.dialogs.ExceptionDetailsErrorDialog.java

License:Open Source License

/**
 * Creates an error dialog. Note that the dialog will have no visual
 * representation (no widgets) until it is told to open.
 * <p>//  w  w  w  .  j  av a  2  s . c o m
 * Normally one should use <code>openError</code> to create and open one of
 * these. This constructor is useful only if the error object being
 * displayed contains child items <it>and </it> you need to specify a mask
 * which will be used to filter the displaying of these children.
 * </p>
 *
 * @param parentShell
 *            the shell under which to create this dialog
 * @param dialogTitle
 *            the title to use for this dialog, or <code>null</code> to
 *            indicate that the default title should be used
 * @param message
 *            the message to show in this dialog, or <code>null</code> to
 *            indicate that the error's message should be shown as the
 *            primary message
 * @param status
 *            the error to show to the user
 * @param displayMask
 *            the mask to use to filter the displaying of child items, as
 *            per <code>IStatus.matches</code>
 * @see org.eclipse.core.runtime.IStatus#matches(int)
 */
public ExceptionDetailsErrorDialog(Shell parentShell, String dialogTitle, String message, IStatus status,
        int displayMask) {
    super(parentShell);
    this.title = dialogTitle == null ? JFaceResources.getString("Problem_Occurred") : //$NON-NLS-1$
            dialogTitle;
    this.message = message == null ? status.getMessage()
            : JFaceResources.format("Reason", new Object[] { message, status.getMessage() }); //$NON-NLS-1$
    this.status = status;
    this.displayMask = displayMask;
}

From source file:org.ebayopensource.turmeric.eclipse.utils.ui.SOAErrorDialog.java

License:Open Source License

/**
 * Instantiates a new sOA error dialog./*  w ww .jav  a2 s.com*/
 *
 * @param parent the parent
 * @param title the title
 * @param message the message
 * @param status the status
 * @param mask the mask
 * @param needLineBreak the need line break
 * @param needLineTitle the need line title
 * @param needCancelButton the need cancel button
 * @param changeButtonLabel the change button label
 */
public SOAErrorDialog(Shell parent, String title, String message, IStatus status, int mask,
        boolean needLineBreak, boolean needLineTitle, boolean needCancelButton, boolean changeButtonLabel) {
    super(parent);
    errorDialogTitle = title;
    if (errorDialogTitle == null) {
        errorDialogTitle = JFaceResources.getString("Problem_Occurred");
    }

    this.message = message == null ? status.getMessage()
            : JFaceResources.format("Reason", new Object[] { message, status.getMessage() }); //$NON-NLS-1$
    this.status = status;
    this.filterMask = mask;
    setShellStyle(getShellStyle() | SWT.RESIZE | SWT.MAX);// #added by wecai
    this.hasLineBreak = needLineBreak;
    this.hasLineTitle = needLineTitle;
    this.hasCancelButton = needCancelButton;
    this.buttonLabelChange = changeButtonLabel;
}

From source file:org.eclipse.egit.ui.internal.preferences.DoublePreferencesPreferencePage.java

License:Open Source License

private void saveSecondaryPreferenceStore() {
    IPreferenceStore store = getSecondaryPreferenceStore();
    if (store != null && store.needsSaving() && (store instanceof IPersistentPreferenceStore)) {
        try {/*from  w ww  .  j av a 2s . c  om*/
            ((IPersistentPreferenceStore) store).save();
        } catch (IOException e) {
            String message = JFaceResources.format("PreferenceDialog.saveErrorMessage", //$NON-NLS-1$
                    new Object[] { getTitle(), e.getMessage() });
            Policy.getStatusHandler().show(new Status(IStatus.ERROR, Activator.getPluginId(), message, e),
                    JFaceResources.getString("PreferenceDialog.saveErrorTitle")); //$NON-NLS-1$
        }
    }
}

From source file:org.eclipse.gmf.internal.codegen.popup.actions.DiagnosticsDialog.java

License:Open Source License

/**
 * Creates an diagnostic dialog. Note that the dialog will have no visual
 * representation (no widgets) until it is told to open.
 * <p>//from   www.j a  v  a 2 s.c  om
 * 
 * @param parentShell
 *            the shell under which to create this dialog
 * @param dialogTitle
 *            the title to use for this dialog, or <code>null</code> to
 *            indicate that the default title should be used
 * @param dialogMessage
 *            the message to show in this dialog, or <code>null</code> to
 *            indicate that the error's message should be shown as the
 *            primary message
 * @param diagnostic
 *            the diagnostic grouping all errors to be shown to the user
 * @param dialogButtonLabels array of labels for buttons to create in the dialog button bar
 * @param dialogButtonIDs array of IDs for buttons to create in the dialog button bar
 * @param defaultDialogButtonIndex the index of the default button
 */
public DiagnosticsDialog(Shell parentShell, String dialogTitle, String dialogMessage, Diagnostic diagnostic,
        String[] dialogButtonLabels, int[] dialogButtonIDs, int defaultDialogButtonIndex) {
    super(parentShell);

    if (diagnostic == null) {
        throw new IllegalArgumentException("Null diagnostic"); //$NON-NLS-1$
    }

    this.title = (dialogTitle == null) ? JFaceResources.getString("Problem_Occurred") : dialogTitle; //$NON-NLS-1$
    this.message = (dialogMessage == null) ? diagnostic.getMessage()
            : JFaceResources.format("Reason", new Object[] { dialogMessage, diagnostic.getMessage() }); //$NON-NLS-1$;

    this.rootDiagnotic = diagnostic;
    this.shouldIncludeTopLevelErrorInDetails = true;

    assert dialogButtonIDs != null && dialogButtonLabels != null;
    assert dialogButtonIDs.length == dialogButtonLabels.length;
    assert defaultDialogButtonIndex >= 0 && defaultDialogButtonIndex < dialogButtonIDs.length;

    buttonIDs = dialogButtonIDs;
    buttonLabels = dialogButtonLabels;
    defaultButtonIndex = defaultDialogButtonIndex;

    setShellStyle(getShellStyle() | SWT.RESIZE);
}

From source file:org.eclipse.wst.command.internal.env.ui.dialog.MessageDialog.java

License:Open Source License

/**
 * Creates an error dialog. Note that the dialog will have no visual
 * representation (no widgets) until it is told to open.
 * <p>/*from w w  w . ja  v  a2  s .  c  o m*/
 * Normally one should use <code>openError</code> to create and open one of
 * these. This constructor is useful only if the error object being displayed
 * contains child items <it>and</it> you need to specify a mask which will
 * be used to filter the displaying of these children.
 * </p>
 * 
 * @param parentShell
 *            the shell under which to create this dialog
 * @param dialogTitle
 *            the title to use for this dialog, or <code>null</code> to
 *            indicate that the default title should be used
 * @param message
 *            the message to show in this dialog, or <code>null</code> to
 *            indicate that the error's message should be shown as the
 *            primary message
 * @param status
 *            the error to show to the user
 * @param displayMask
 *            the mask to use to filter the displaying of child items, as per
 *            <code>Status.matches</code>
 */
public MessageDialog(Shell parentShell, String dialogTitle, String message, IStatus status, int displayMask) {
    super(parentShell);
    this.title = dialogTitle == null ? JFaceResources.getString("Problem_Occurred") : //$NON-NLS-1$
            dialogTitle;
    this.message = message == null ? status.getMessage()
            : JFaceResources.format("Reason", new Object[] { message, status.getMessage() }); //$NON-NLS-1$
    this.status = status;
    statusList = Arrays.asList(status.getChildren());
    this.displayMask = displayMask;
    setShellStyle(SWT.DIALOG_TRIM | SWT.RESIZE | SWT.APPLICATION_MODAL);
}

From source file:org.modelio.api.ui.ModelioWizardDialog.java

License:Apache License

/**
 * Update the receiver for the new page.
 * @param page// w  w  w  .j  av a2  s  .  c  om
 */
@objid("bc21ab54-120f-11e2-b5c6-002564c97630")
void updateForPage(final IWizardPage page) {
    // ensure this page belongs to the current wizard
    if (this.wizard != page.getWizard()) {
        setWizard(page.getWizard());
    }
    // ensure that page control has been created
    // (this allows lazy page control creation)
    if (page.getControl() == null) {
        page.createControl(this.pageContainer);
        // the page is responsible for ensuring the created control is
        // accessible via getControl.
        Assert.isNotNull(page.getControl(),
                JFaceResources.format(JFaceResources.getString("WizardDialog.missingSetControl"), //$NON-NLS-1$
                        new Object[] { page.getName() }));
        // ensure the dialog is large enough for this page
        updateSize(page);
    }
    // make the new page visible
    IWizardPage oldPage = this.currentPage;
    this.currentPage = page;

    this.currentPage.setVisible(true);
    if (oldPage != null) {
        oldPage.setVisible(false);
    }
    // update the dialog controls
    update();
}

From source file:org.springframework.ide.eclipse.boot.dash.util.ToolbarPulldownContributionItem.java

License:Open Source License

/**
 * Synchronizes the UI with the given property.
 *
 * @param propertyName/*  w  w w .  j  av  a  2s. c o m*/
 *            the name of the property, or <code>null</code> meaning all
 *            applicable properties
 */
@Override
public void update(String propertyName) {
    if (widget != null) {
        // determine what to do
        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 = (action.getStyle() == IAction.AS_CHECK_BOX
                || action.getStyle() == IAction.AS_RADIO_BUTTON)
                && (propertyName == null || propertyName.equals(IAction.CHECKED));

        if (widget instanceof ToolItem) {
            ToolItem ti = (ToolItem) widget;
            String text = action.getText();
            // the set text is shown only if there is no image or if forced
            // by MODE_FORCE_TEXT
            boolean showText = text != null && ((getMode() & MODE_FORCE_TEXT) != 0 || !hasImages(action));

            // 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 = action.getToolTipText();
                if ((toolTip == null) || (toolTip.length() == 0)) {
                    toolTip = text;
                }

                ExternalActionManager.ICallback callback = ExternalActionManager.getInstance().getCallback();
                String commandId = action.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 = action.isEnabled() && isEnabledAllowed();

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

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

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

        if (widget instanceof MenuItem) {
            MenuItem mi = (MenuItem) widget;

            if (textChanged) {
                int accelerator = 0;
                String acceleratorText = null;
                IAction updatedAction = getAction();
                String text = null;
                accelerator = updatedAction.getAccelerator();
                ExternalActionManager.ICallback callback = ExternalActionManager.getInstance().getCallback();

                // Block accelerators that are already in use.
                if ((accelerator != 0) && (callback != null) && (callback.isAcceleratorInUse(accelerator))) {
                    accelerator = 0;
                }

                /*
                 * Process accelerators on GTK in a special way to avoid Bug
                 * 42009. We will override the native input method by
                 * allowing these reserved accelerators to be placed on the
                 * menu. We will only do this for "Ctrl+Shift+[0-9A-FU]".
                 */
                final String commandId = updatedAction.getActionDefinitionId();
                if ((Util.isGtk()) && (callback instanceof IBindingManagerCallback) && (commandId != null)) {
                    final IBindingManagerCallback bindingManagerCallback = (IBindingManagerCallback) callback;
                    final IKeyLookup lookup = KeyLookupFactory.getDefault();
                    final TriggerSequence[] triggerSequences = bindingManagerCallback
                            .getActiveBindingsFor(commandId);
                    for (int i = 0; i < triggerSequences.length; i++) {
                        final TriggerSequence triggerSequence = triggerSequences[i];
                        final Trigger[] triggers = triggerSequence.getTriggers();
                        if (triggers.length == 1) {
                            final Trigger trigger = triggers[0];
                            if (trigger instanceof KeyStroke) {
                                final KeyStroke currentKeyStroke = (KeyStroke) trigger;
                                final int currentNaturalKey = currentKeyStroke.getNaturalKey();
                                if ((currentKeyStroke
                                        .getModifierKeys() == (lookup.getCtrl() | lookup.getShift()))
                                        && ((currentNaturalKey >= '0' && currentNaturalKey <= '9')
                                                || (currentNaturalKey >= 'A' && currentNaturalKey <= 'F')
                                                || (currentNaturalKey == 'U'))) {
                                    accelerator = currentKeyStroke.getModifierKeys() | currentNaturalKey;
                                    acceleratorText = triggerSequence.format();
                                    break;
                                }
                            }
                        }
                    }
                }

                if (accelerator == 0) {
                    if ((callback != null) && (commandId != null)) {
                        acceleratorText = callback.getAcceleratorText(commandId);
                    }
                }

                IContributionManagerOverrides overrides = null;

                if (getParent() != null) {
                    overrides = getParent().getOverrides();
                }

                if (overrides != null) {
                    text = getParent().getOverrides().getText(this);
                }

                mi.setAccelerator(accelerator);

                if (text == null) {
                    text = updatedAction.getText();
                }

                if (text != null && acceleratorText == null) {
                    // use extracted accelerator text in case accelerator
                    // cannot be fully represented in one int (e.g.
                    // multi-stroke keys)
                    acceleratorText = LegacyActionTools.extractAcceleratorText(text);
                    if (acceleratorText == null && accelerator != 0) {
                        acceleratorText = Action.convertAccelerator(accelerator);
                    }
                }

                if (text == null) {
                    text = ""; //$NON-NLS-1$
                } else {
                    text = Action.removeAcceleratorText(text);
                }

                if (acceleratorText == null) {
                    mi.setText(text);
                } else {
                    mi.setText(text + '\t' + acceleratorText);
                }
            }

            if (imageChanged) {
                updateImages(false);
            }

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

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

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

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

            return;
        }

        if (widget instanceof Button) {
            Button button = (Button) widget;

            if (imageChanged) {
                updateImages(false);
            }

            if (textChanged) {
                String text = action.getText();
                boolean showText = text != null && ((getMode() & MODE_FORCE_TEXT) != 0 || !hasImages(action));
                // only do the trimming if the text will be used
                if (showText) {
                    text = Action.removeAcceleratorText(text);
                }
                String textToSet = showText ? text : ""; //$NON-NLS-1$
                button.setText(textToSet);
            }

            if (tooltipTextChanged) {
                button.setToolTipText(action.getToolTipText());
            }

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

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

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

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