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

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

Introduction

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

Prototype

public static Image getImage(String key) 

Source Link

Document

Returns the image in JFace's image registry with the given key, or null if none.

Usage

From source file:org.jboss.tools.openshift.internal.ui.preferences.OpenShiftPreferencePage.java

License:Open Source License

@Override
public void createFieldEditors() {
    Link link = new Link(getFieldEditorParent(), SWT.WRAP);
    link.setText(/* w  ww  .  j  a  v  a 2  s  .c  o  m*/
            "The OpenShift client binary (oc) is required for features such as Port Forwarding or Log Streaming. "
                    + "You can find more information about how to install it from <a>here</a>.");
    GridDataFactory.fillDefaults().span(3, 1).hint(1, 60).grab(true, false).applyTo(link);
    link.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            new BrowserUtility().checkedCreateExternalBrowser(DOWNLOAD_INSTRUCTIONS_URL,
                    OpenShiftUIActivator.PLUGIN_ID, OpenShiftUIActivator.getDefault().getLog());
        }
    });
    this.cliLocationEditor = new CliFileEditor();
    cliLocationEditor.setFilterPath(SystemUtils.getUserHome());
    cliLocationEditor.setFileExtensions(ocBinary.getExtensions());
    cliLocationEditor.setValidateStrategy(FileFieldEditor.VALIDATE_ON_KEY_STROKE);
    addField(cliLocationEditor);

    ocVersionLabel = new Label(getFieldEditorParent(), SWT.WRAP);
    ocVersionLabel.setFont(JFaceResources.getFontRegistry().getItalic(JFaceResources.DEFAULT_FONT));
    GridDataFactory.fillDefaults().span(3, 1).applyTo(ocVersionLabel);
    ocMessageComposite = new Composite(getFieldEditorParent(), SWT.NONE);
    GridDataFactory.fillDefaults().span(3, 1).applyTo(ocMessageComposite);
    GridLayoutFactory.fillDefaults().numColumns(2).applyTo(ocMessageComposite);
    Label label = new Label(ocMessageComposite, SWT.NONE);
    label.setImage(JFaceResources.getImage(Dialog.DLG_IMG_MESSAGE_WARNING));
    GridDataFactory.fillDefaults().align(SWT.BEGINNING, SWT.TOP).applyTo(label);
    ocMessageLabel = new Label(ocMessageComposite, SWT.NONE);
    GridDataFactory.fillDefaults().grab(true, false).applyTo(ocMessageLabel);
    ocMessageComposite.setVisible(false);
}

From source file:org.jboss.tools.openshift.internal.ui.server.ServerSettingsWizardPage.java

License:Open Source License

private void createInfoControls(Composite container, ServerSettingsWizardPageModel model,
        DataBindingContext dbc) {/* w w w .  jav  a 2  s  .  co  m*/
    Composite composite = new Composite(container, SWT.NONE);
    GridDataFactory.fillDefaults().span(4, 1).applyTo(composite);
    GridLayoutFactory.fillDefaults().numColumns(2).applyTo(composite);

    ValueBindingBuilder.bind(WidgetProperties.visible().observe(composite))
            .to(BeanProperties.value(ServerSettingsWizardPageModel.PROPERTY_OC_BINARY_STATUS).observe(model))
            .converting(new Converter(IStatus.class, Boolean.class) {

                @Override
                public Object convert(Object fromObject) {
                    return !((IStatus) fromObject).isOK();
                }

            }).in(dbc);

    Label label = new Label(composite, SWT.NONE);
    ValueBindingBuilder.bind(WidgetProperties.image().observe(label))
            .to(BeanProperties.value(ServerSettingsWizardPageModel.PROPERTY_OC_BINARY_STATUS).observe(model))
            .converting(new Converter(IStatus.class, Image.class) {

                @Override
                public Object convert(Object fromObject) {
                    switch (((IStatus) fromObject).getSeverity()) {
                    case IStatus.WARNING:
                        return JFaceResources.getImage(Dialog.DLG_IMG_MESSAGE_WARNING);
                    case IStatus.ERROR:
                        return JFaceResources.getImage(Dialog.DLG_IMG_MESSAGE_ERROR);
                    }
                    return null;
                }
            }).in(dbc);

    Link link = new Link(composite, SWT.WRAP);
    ValueBindingBuilder.bind(WidgetProperties.text().observe(link))
            .to(BeanProperties.value(ServerSettingsWizardPageModel.PROPERTY_OC_BINARY_STATUS).observe(model))
            .converting(new Converter(IStatus.class, String.class) {

                @Override
                public Object convert(Object fromObject) {
                    return ((IStatus) fromObject).getMessage();
                }

            }).in(dbc);
    link.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            if ("download".equals(e.text)) {
                new BrowserUtility().checkedCreateExternalBrowser(DOWNLOAD_INSTRUCTIONS_URL,
                        OpenShiftUIActivator.PLUGIN_ID, OpenShiftUIActivator.getDefault().getLog());
            } else {
                int rc = PreferencesUtil.createPreferenceDialogOn(getShell(), OPEN_SHIFT_PREFERENCE_PAGE_ID,
                        new String[] { OPEN_SHIFT_PREFERENCE_PAGE_ID }, null).open();
                if (rc == Dialog.OK) {
                    new Job("Checking oc binary") {

                        @Override
                        protected IStatus run(IProgressMonitor monitor) {
                            OCBinary ocBinary = OCBinary.getInstance();
                            boolean valid = ocBinary.isCompatibleForPublishing(monitor);
                            ServerSettingsWizardPage.this.model
                                    .setOCBinaryStatus(getOCBinaryStatus(valid, ocBinary.getLocation()));
                            return Status.OK_STATUS;
                        }
                    }.schedule();
                }
            }
        }
    });
    GridDataFactory.fillDefaults().hint(600, SWT.DEFAULT).applyTo(link);
    MultiValidator validator = new MultiValidator() {

        @Override
        protected IStatus validate() {
            IObservableValue<IStatus> observable = BeanProperties
                    .value(ServerSettingsWizardPageModel.PROPERTY_OC_BINARY_STATUS).observe(model);
            Status status = (Status) observable.getValue();
            switch (status.getSeverity()) {
            case IStatus.ERROR:
                return OpenShiftUIActivator.statusFactory()
                        .errorStatus(OpenShiftUIMessages.OCBinaryErrorMessage);
            case IStatus.WARNING:
                return OpenShiftUIActivator.statusFactory()
                        .warningStatus(OpenShiftUIMessages.OCBinaryWarningMessage);
            }
            return status;
        }
    };
    dbc.addValidationStatusProvider(validator);
}

From source file:org.jkiss.dbeaver.ui.controls.resultset.StatusLabel.java

License:Apache License

public StatusLabel(@NotNull Composite parent, int style, @Nullable final ResultSetViewer viewer) {
    super(parent, SWT.BORDER);
    this.viewer = viewer;

    setBackgroundMode(SWT.INHERIT_FORCE);

    final GridLayout layout = new GridLayout(3, false);
    layout.marginHeight = 0;//  w  ww . ja  va  2s  . co m
    layout.marginWidth = 2;
    layout.horizontalSpacing = 3;
    setLayout(layout);

    colorDefault = getForeground();
    colorError = JFaceColors.getErrorText(Display.getDefault());
    colorWarning = colorDefault;

    final Image statusImage = JFaceResources.getImage(Dialog.DLG_IMG_MESSAGE_INFO);
    statusIcon = new Label(this, SWT.NONE);
    statusIcon.setImage(statusImage);
    statusIcon.setToolTipText("Status information");
    GridData gd = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING);
    statusIcon.setLayoutData(gd);

    statusText = new Text(this, SWT.SINGLE | SWT.READ_ONLY);
    if (RuntimeUtils.isPlatformWindows()) {
        statusText.setBackground(null);
    } else {
        statusText.setBackground(parent.getBackground());
    }
    gd = new GridData(GridData.FILL_HORIZONTAL);
    gd.minimumHeight = statusImage.getBounds().height;
    statusText.setLayoutData(gd);

    UIUtils.enableHostEditorKeyBindingsSupport(viewer.getSite(), this.statusText);
    UIUtils.addFocusTracker(viewer.getSite(), UIUtils.INLINE_WIDGET_EDITOR_ID, this.statusText);
    this.statusText.addDisposeListener(new DisposeListener() {
        @Override
        public void widgetDisposed(DisposeEvent e) {
            // Unregister from focus service
            UIUtils.removeFocusTracker(viewer.getSite(), statusText);
        }
    });

    final ToolBar tb = new ToolBar(this, SWT.HORIZONTAL);
    final ToolItem detailsIcon = new ToolItem(tb, SWT.NONE);
    detailsIcon.setImage(DBeaverIcons.getImage(UIIcon.TEXTFIELD));
    tb.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING));

    detailsIcon.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            showDetails();
        }
    });
    statusText.addTraverseListener(new TraverseListener() {
        @Override
        public void keyTraversed(TraverseEvent e) {
            if (e.detail == SWT.TRAVERSE_RETURN) {
                showDetails();
            }
        }
    });
}

From source file:org.jkiss.dbeaver.ui.controls.resultset.StatusLabel.java

License:Apache License

public void setStatus(String message, DBPMessageType messageType) {
    if (statusText.isDisposed()) {
        return;/*w  w w.ja  v a2  s.  com*/
    }
    this.messageType = messageType;

    Color fg;
    String statusIconId;
    switch (messageType) {
    case ERROR:
        fg = colorError;
        statusIconId = Dialog.DLG_IMG_MESSAGE_ERROR;
        break;
    case WARNING:
        fg = colorWarning;
        statusIconId = Dialog.DLG_IMG_MESSAGE_WARNING;
        break;
    default:
        fg = colorDefault;
        statusIconId = Dialog.DLG_IMG_MESSAGE_INFO;
        break;
    }
    statusText.setForeground(fg);
    if (message == null) {
        message = "???"; //$NON-NLS-1$
    }
    statusIcon.setImage(JFaceResources.getImage(statusIconId));
    statusText.setText(TextUtils.getSingleLineString(message));
    if (messageType != DBPMessageType.INFORMATION) {
        statusText.setToolTipText(message);
    } else {
        statusText.setToolTipText(null);
    }
}

From source file:org.jkiss.dbeaver.ui.controls.StatusLabel.java

License:Open Source License

public StatusLabel(@NotNull Composite parent, @Nullable final IWorkbenchPartSite site) {
    super(parent, SWT.BORDER);
    setBackgroundMode(SWT.INHERIT_FORCE);

    GridLayout layout = new GridLayout(3, false);
    layout.marginHeight = 2;/*from  www  .  j a  v a2  s.c  om*/
    layout.marginWidth = 2;
    setLayout(layout);

    colorRed = Display.getDefault().getSystemColor(SWT.COLOR_RED);

    statusIcon = new Label(this, SWT.NONE);
    statusIcon.setImage(JFaceResources.getImage(org.eclipse.jface.dialogs.Dialog.DLG_IMG_MESSAGE_INFO));
    statusIcon.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING));

    statusText = new Text(this, SWT.READ_ONLY);
    if (RuntimeUtils.isPlatformWindows()) {
        statusText.setBackground(null);
    } else {
        statusText.setBackground(parent.getBackground());
    }
    statusText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));

    if (site != null) {
        UIUtils.enableHostEditorKeyBindingsSupport(site, this.statusText);
        UIUtils.addFocusTracker(site, UIUtils.INLINE_WIDGET_EDITOR_ID, this.statusText);
        this.statusText.addDisposeListener(new DisposeListener() {
            @Override
            public void widgetDisposed(DisposeEvent e) {
                // Unregister from focus service
                UIUtils.removeFocusTracker(site, statusText);
            }
        });
    }

    Label detailsIcon = new Label(this, SWT.NONE);
    detailsIcon.setImage(DBeaverIcons.getImage(UIIcon.TEXTFIELD));
    detailsIcon.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING));

    detailsIcon.setCursor(getDisplay().getSystemCursor(SWT.CURSOR_HAND));
    detailsIcon.addMouseListener(new MouseAdapter() {
        @Override
        public void mouseUp(MouseEvent e) {
            EditTextDialog.showText(getShell(), CoreMessages.controls_resultset_viewer_dialog_status_title,
                    statusText.getText());
        }
    });
}

From source file:org.jkiss.dbeaver.ui.controls.StatusLabel.java

License:Open Source License

public void setStatus(String status, boolean error) {
    if (statusText.isDisposed()) {
        return;//from www .  ja  v  a2 s . c  o m
    }
    if (error) {
        statusText.setForeground(colorRed);
    } else if (colorRed.equals(statusText.getForeground())) {
        statusText.setForeground(this.getForeground());
    }
    if (status == null) {
        status = "???"; //$NON-NLS-1$
    }
    String statusIconId = error ? org.eclipse.jface.dialogs.Dialog.DLG_IMG_MESSAGE_ERROR
            : org.eclipse.jface.dialogs.Dialog.DLG_IMG_MESSAGE_INFO;
    statusIcon.setImage(JFaceResources.getImage(statusIconId));
    statusText.setText(status);
    if (error) {
        statusText.setToolTipText(status);
    } else {
        statusText.setToolTipText(null);
    }
}

From source file:org.kalypso.contribs.eclipse.jface.wizard.view.WizardView.java

License:Open Source License

/**
 * Creates the dialog's title area./*from   w  w w .  j  av a 2s .  c  o  m*/
 *
 * @param parent
 *          the SWT parent for the title area widgets
 * @return Control with the highest x axis value.
 */
private Control createTitleArea(final Composite parent) {
    // remeber parent in order to change its colors
    m_parent = parent;

    // Determine the background color of the title bar
    final Display display = parent.getDisplay();
    m_defaultTitleBackground = JFaceColors.getBannerBackground(display).getRGB();
    m_defaultTitleForeground = JFaceColors.getBannerForeground(display).getRGB();

    final int verticalSpacing = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_SPACING);
    final int horizontalSpacing = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_SPACING);

    // Dialog image @ right
    m_titleImage = new Label(parent, SWT.CENTER);
    m_titleImage.setImage(JFaceResources.getImage(TitleAreaDialog.DLG_IMG_TITLE_BANNER));
    final FormData imageData = new FormData();
    imageData.top = new FormAttachment(0, verticalSpacing);
    // Note: do not use horizontalSpacing on the right as that would be a
    // regression from
    // the R2.x style where there was no margin on the right and images are
    // flush to the right
    // hand side. see reopened comments in 41172
    imageData.right = new FormAttachment(100, 0); // horizontalSpacing
    m_titleImage.setLayoutData(imageData);
    // Title label @ top, left
    m_titleLabel = new Label(parent, SWT.LEFT);
    m_titleLabel.setFont(JFaceResources.getBannerFont());
    m_titleLabel.setText(" ");//$NON-NLS-1$
    final FormData titleData = new FormData();
    titleData.top = new FormAttachment(0, verticalSpacing);
    titleData.right = new FormAttachment(m_titleImage);
    titleData.left = new FormAttachment(0, horizontalSpacing);
    m_titleLabel.setLayoutData(titleData);
    // Message image @ bottom, left
    m_messageImageLabel = new Label(parent, SWT.CENTER);
    // Message label @ bottom, center
    m_messageLabel = new Text(parent, SWT.WRAP | SWT.READ_ONLY);
    m_messageLabel.setText(" \n "); // two lines//$NON-NLS-1$
    m_messageLabel.setFont(JFaceResources.getDialogFont());

    // Filler labels
    m_leftFillerLabel = new Label(parent, SWT.CENTER);
    m_bottomFillerLabel = new Label(parent, SWT.CENTER);
    setLayoutsForNormalMessage(verticalSpacing, horizontalSpacing);
    determineTitleImageLargest();
    if (m_titleImageLargest)
        return m_titleImage;
    return m_messageLabel;
}

From source file:org.kalypso.contribs.eclipse.jface.wizard.view.WizardView.java

License:Open Source License

/**
 * Display the given error message. The currently displayed message is saved and will be redisplayed when the error
 * message is set to <code>null</code>.
 *
 * @param newErrorMessage//from   w ww .ja v  a2 s  . c  o m
 *          the newErrorMessage to display or <code>null</code>
 */
public void setErrorMessage(final String newErrorMessage) {
    // Any change?
    if (m_errorMessage == null ? newErrorMessage == null : m_errorMessage.equals(newErrorMessage))
        return;
    m_errorMessage = newErrorMessage;

    if (m_messageLabel.isDisposed())
        return;

    if (m_errorMessage == null) {
        if (m_showingError) {
            // we were previously showing an error
            m_showingError = false;
            setMessageBackgrounds(false);
        }
        // show the message
        // avoid calling setMessage in case it is overridden to call
        // setErrorMessage,
        // which would result in a recursive infinite loop
        if (m_message == null) // this should probably never happen since
            // setMessage does this conversion....
            m_message = ""; //$NON-NLS-1$

        updateMessage(m_message);
        m_messageImageLabel.setImage(m_messageImage);
        setImageLabelVisible(m_messageImage != null);
        m_messageLabel.setToolTipText(m_message);
    } else {
        // Add in a space for layout purposes but do not
        // change the instance variable
        final String displayedErrorMessage = " " + m_errorMessage; //$NON-NLS-1$
        updateMessage(displayedErrorMessage);
        m_messageLabel.setToolTipText(m_errorMessage);
        if (!m_showingError) {
            // we were not previously showing an error
            m_showingError = true;
            // lazy initialize the error background color and image
            if (m_errorMsgAreaBackground == null) {
                m_errorMsgAreaBackground = JFaceColors.getErrorBackground(m_messageLabel.getDisplay());
                m_errorMsgImage = JFaceResources.getImage(TitleAreaDialog.DLG_IMG_TITLE_ERROR);
            }
            // show the error
            m_normalMsgAreaBackground = m_messageLabel.getBackground();

            setMessageBackgrounds(!m_useNormalBackground);

            m_messageImageLabel.setImage(m_errorMsgImage);
            setImageLabelVisible(true);
        }
    }
    layoutForNewMessage();
}

From source file:org.kalypso.contribs.eclipse.jface.wizard.view.WizardView.java

License:Open Source License

/**
 * Sets the message for this dialog with an indication of what type of message it is.
 * <p>/*from   ww  w  .  j  a va 2 s  .  c om*/
 * The valid message types are one of <code>NONE</code>,<code>INFORMATION</code>,<code>WARNING</code>, or
 * <code>ERROR</code>.
 * </p>
 * <p>
 * Note that for backward compatibility, a message of type <code>ERROR</code> is different than an error message (set
 * using <code>setErrorMessage</code>). An error message overrides the current message until the error message is
 * cleared. This method replaces the current message and does not affect the error message.
 * </p>
 *
 * @param newMessage
 *          the message, or <code>null</code> to clear the message
 * @param newType
 *          the message type
 * @since 2.0
 */
public void setMessage(final String newMessage, final int newType) {
    Image newImage = null;
    if (newMessage != null) {
        switch (newType) {
        case IMessageProvider.NONE:
            break;
        case IMessageProvider.INFORMATION:
            newImage = JFaceResources.getImage(Dialog.DLG_IMG_MESSAGE_INFO);
            break;
        case IMessageProvider.WARNING:
            newImage = JFaceResources.getImage(Dialog.DLG_IMG_MESSAGE_WARNING);
            break;
        case IMessageProvider.ERROR:
            newImage = JFaceResources.getImage(Dialog.DLG_IMG_MESSAGE_ERROR);
            break;
        }
    }
    showMessage(newMessage, newImage);
}

From source file:org.locationtech.udig.ui.filter.ExpressionViewer.java

License:Open Source License

/**
 * Creates an ExpressionViewer using the provided style.
 * <ul>/*  ww  w  .  ja v a 2  s  . com*/
 * <li>SWT.SINGLE - A simple text field showing the expression using extended CQL notation
 * <li>
 * <li>SWT.MULTI - A multi line text field</li>
 * <li>SWT.READ_ONLY - read only display of a expression</li>
 * </ul>
 * 
 * @param parent
 * @param style
 */
public ExpressionViewer(Composite parent, int style) {
    control = new Composite(parent, SWT.NO_SCROLL) {
        public void setEnabled(boolean enabled) {
            super.setEnabled(enabled);
            config.setEnabled(enabled);
            if (delegate != null) {
                config.setEnabled(enabled);
            }
            if (input != null && input.getFeedback() != null && input.getFeedback().getControl() != null) {
                input.getFeedback().getControl().setEnabled(enabled);
            }
        }
    };

    control.setLayout(new MigLayout("insets 0", "[fill][]", "[fill]"));

    pageBook = new PageBook(control, SWT.NO_SCROLL);
    pageBook.setLayoutData("cell 0 0,grow,width 200:100%:100%,height 18:75%:100%");

    placeholder = new Label(pageBook, SWT.SINGLE);
    placeholder.setText("Choose expression editor");

    delegate = new CQLExpressionViewer(pageBook, style);
    delegate.addSelectionChangedListener(listener);
    pageBook.showPage(delegate.getControl());

    this.pages = new HashMap<String, IExpressionViewer>();
    pages.put(ExpressionViewerFactory.CQL_EXPRESSION_VIEWER, delegate);

    config = new Label(control, SWT.SINGLE);
    config.setImage(JFaceResources.getImage(PopupDialog.POPUP_IMG_MENU));
    config.setLayoutData("cell 1 0,aligny top,height 16!, width 16!");

    createContextMenu(config);
    config.addMouseListener(new MouseAdapter() {
        public void mouseDown(org.eclipse.swt.events.MouseEvent e) {
            Menu menu = config.getMenu();
            if (menu != null) {
                menu.setVisible(true);
            }
        }
    });
    this.style = style;
}