Example usage for org.eclipse.jface.fieldassist FieldDecorationRegistry DEC_WARNING

List of usage examples for org.eclipse.jface.fieldassist FieldDecorationRegistry DEC_WARNING

Introduction

In this page you can find the example usage for org.eclipse.jface.fieldassist FieldDecorationRegistry DEC_WARNING.

Prototype

String DEC_WARNING

To view the source code for org.eclipse.jface.fieldassist FieldDecorationRegistry DEC_WARNING.

Click Source Link

Document

Decoration id for the decoration that should be used to cue the user that a field has a warning.

Usage

From source file:ch.unibe.iam.scg.archie.ui.Decorators.java

License:Open Source License

/**
 * @param type//from w  ww .j  a  va  2  s . com
 * @param description 
 * @return FieldDecoration
 */
public static FieldDecoration getFieldDecoration(int type, String description) {
    switch (type) {
    case VALID:
        FieldDecoration validDecoration = registry.getFieldDecoration(DEC_VALID);
        validDecoration.setDescription(description);
        return validDecoration;
    case WARNING:
        FieldDecoration warningDecoration = registry.getFieldDecoration(FieldDecorationRegistry.DEC_WARNING);
        warningDecoration.setDescription(description);
        return warningDecoration;
    case ERROR:
        FieldDecoration errorDecoration = registry.getFieldDecoration(FieldDecorationRegistry.DEC_ERROR);
        errorDecoration.setDescription(description);
        return errorDecoration;
    case QUICKFIX:
        FieldDecoration quickfixDecoration = registry
                .getFieldDecoration(FieldDecorationRegistry.DEC_ERROR_QUICKFIX);
        quickfixDecoration.setDescription(description);
        return quickfixDecoration;
    default:
        return null;
    }
}

From source file:com.android.ide.eclipse.adt.internal.wizards.templates.NewProjectPage.java

License:Open Source License

private void setDecoratorType(ControlDecoration decorator, int severity) {
    String id;/*from   w w  w .jav  a 2s.  c  o m*/
    if (severity == IStatus.ERROR) {
        id = FieldDecorationRegistry.DEC_ERROR;
    } else if (severity == IStatus.WARNING) {
        id = FieldDecorationRegistry.DEC_WARNING;
    } else {
        id = FieldDecorationRegistry.DEC_INFORMATION;
    }
    FieldDecoration errorFieldIndicator = FieldDecorationRegistry.getDefault().getFieldDecoration(id);
    decorator.setImage(errorFieldIndicator.getImage());
}

From source file:com.android.ide.eclipse.adt.internal.wizards.templates.NewTemplatePage.java

License:Open Source License

private void updateDecorator(ControlDecoration decorator, IStatus status, String help) {
    if (help != null && !help.isEmpty()) {
        decorator.setDescriptionText(status != null ? status.getMessage() : help);

        int severity = status != null ? status.getSeverity() : IStatus.OK;
        String id;//from w  w w.  j  a  v a 2 s.com
        if (severity == IStatus.ERROR) {
            id = FieldDecorationRegistry.DEC_ERROR;
        } else if (severity == IStatus.WARNING) {
            id = FieldDecorationRegistry.DEC_WARNING;
        } else {
            id = FieldDecorationRegistry.DEC_INFORMATION;
        }
        FieldDecoration errorFieldIndicator = FieldDecorationRegistry.getDefault().getFieldDecoration(id);
        decorator.setImage(errorFieldIndicator.getImage());
    } else {
        if (status == null || status.isOK()) {
            decorator.hide();
        } else {
            decorator.show();
        }
    }
}

From source file:com.aptana.theme.preferences.ThemePreferencePage.java

License:Open Source License

private void createTokenEditTable(Composite composite) {
    // FIXME allow drag and drop to sort items in the table!
    Composite comp = new Composite(composite, SWT.NONE);
    GridData gridData = new GridData(SWT.FILL, SWT.FILL, true, true);
    gridData.heightHint = 200;/*from   ww w .  j  a v a 2 s .c o m*/
    comp.setLayoutData(gridData);
    TableColumnLayout layout = new TableColumnLayout();
    comp.setLayout(layout);
    final Table table = new Table(comp, SWT.FULL_SELECTION | SWT.SINGLE | SWT.V_SCROLL);
    table.setHeaderVisible(true);
    table.setLinesVisible(false);
    // Hack to force a specific row height
    table.addListener(SWT.MeasureItem, new Listener() {
        public void handleEvent(Event event) {
            event.height = ROW_HEIGHT;
        }
    });
    // Hack to draw the underline in first column
    table.addListener(SWT.PaintItem, new Listener() {
        public void handleEvent(Event event) {
            if ((event.detail & SWT.FOREGROUND) != 0 && event.index == 0) {
                TableItem item = (TableItem) event.item;
                ThemeRule token = (ThemeRule) item.getData();
                if ((token.getTextAttribute().style & TextAttribute.UNDERLINE) != 0) {
                    int y = event.getBounds().y + event.getBounds().height - 6;
                    int x2 = event.getBounds().width;
                    Color oldFG = event.gc.getForeground();
                    Color fg;
                    RGBa rgb = token.getTextAttribute().foreground;
                    if (rgb == null) {
                        fg = ThemePlugin.getDefault().getColorManager().getColor(getTheme().getForeground());
                    } else {
                        fg = ThemePlugin.getDefault().getColorManager().getColor(rgb.toRGB());
                    }
                    event.gc.setForeground(fg);
                    event.gc.drawLine(0, y, x2, y);
                    event.gc.setForeground(oldFG);
                    event.detail &= ~SWT.FOREGROUND;
                }
            }
        }
    });

    Listener selectionOverride = new Listener() {
        public void handleEvent(Event event) {
            if ((event.detail & SWT.SELECTED) != 0) {
                Scrollable scrollable = (Scrollable) event.widget;
                Rectangle clientArea = scrollable.getClientArea();
                int clientWidth = clientArea.width;

                GC gc = event.gc;
                Color oldBackground = gc.getBackground();

                gc.setBackground(ThemePlugin.getDefault().getColorManager()
                        .getColor(getTheme().getSelectionAgainstBG()));
                gc.fillRectangle(clientArea.x, event.y, clientWidth, event.height);
                gc.setBackground(oldBackground);

                event.detail &= ~SWT.SELECTED;
                event.detail &= ~SWT.BACKGROUND;

                // force foreground color. Otherwise on dark themes we get black FG (all the time on Win, on
                // non-focus for Mac)
                gc.setForeground(
                        ThemePlugin.getDefault().getColorManager().getColor(getTheme().getForeground()));
            }
        }
    };
    table.addListener(SWT.EraseItem, selectionOverride);

    tableViewer = new TableViewer(table);
    tableViewer.setContentProvider(new IStructuredContentProvider() {

        private Theme theme;

        public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
            this.theme = (Theme) newInput;
        }

        public void dispose() {

        }

        public Object[] getElements(Object inputElement) {
            return theme.getTokens().toArray();
        }
    });
    tableViewer.setLabelProvider(new TokenLabelProvider());
    tableViewer.getTable().addMouseListener(new MouseAdapter() {
        @Override
        public void mouseDown(MouseEvent e) {
            Table table = tableViewer.getTable();
            // If user is clicking in the FG/BG column when it's empty, pop open a color dialog
            int fgColX = table.getColumn(0).getWidth(); // scope col width
            int fgColWidth = table.getColumn(1).getWidth(); // fg col width
            int bgColX = fgColX + fgColWidth;
            int bgColWidth = table.getColumn(2).getWidth() + 2;

            if (e.x > fgColX && e.x < (fgColX + fgColWidth)) {
                // user clicked in FG column
                ColorDialog colorDialog = new ColorDialog(table.getShell());
                colorDialog.setRGB(getTheme().getForeground());
                RGB newRGB = colorDialog.open();
                if (newRGB == null) {
                    return; // no color selected, don't change a thing!
                }
                TableItem tableItem = table.getItem(new Point(e.x, e.y));
                ThemeRule token = (ThemeRule) tableItem.getData();
                int index = table.indexOf(tableItem);
                getTheme().updateRule(index, token.updateFG(new RGBa(newRGB)));
            } else if (e.x > bgColX && e.x < (bgColX + bgColWidth)) // is user clicking in the BG column?
            {
                ColorDialog colorDialog = new ColorDialog(table.getShell());
                colorDialog.setRGB(getTheme().getBackground());
                RGB newRGB = colorDialog.open();
                if (newRGB == null) {
                    return; // no color selected, don't change a thing!
                }
                TableItem tableItem = table.getItem(new Point(e.x, e.y));
                ThemeRule token = (ThemeRule) tableItem.getData();
                int index = table.indexOf(tableItem);
                getTheme().updateRule(index, token.updateBG(new RGBa(newRGB)));
            } else {
                return;
            }

            tableViewer.refresh();
            addCustomTableEditorControls();
        }
    });

    TableViewerColumn column = new TableViewerColumn(tableViewer, SWT.NONE);
    final TableColumn tokenName = column.getColumn();
    tokenName.setText("Element"); //$NON-NLS-1$
    layout.setColumnData(tokenName, new ColumnWeightData(100, true));
    column.setLabelProvider(new ColumnLabelProvider() {
        public String getText(Object element) {
            ThemeRule token = (ThemeRule) element;
            return token.getName();
        }

        public Color getForeground(Object element) {
            ThemeRule token = (ThemeRule) element;
            // TODO How do we handle alpha?
            RGBa fg = token.getTextAttribute().foreground;
            if (fg == null)
                return ThemePlugin.getDefault().getColorManager().getColor(getTheme().getForeground());
            return ThemePlugin.getDefault().getColorManager().getColor(fg.toRGB());
        }

        public Color getBackground(Object element) {
            ThemeRule token = (ThemeRule) element;
            // TODO How do we handle alpha?
            RGBa bg = token.getTextAttribute().background;
            if (bg == null)
                return ThemePlugin.getDefault().getColorManager().getColor(getTheme().getBackground());
            return ThemePlugin.getDefault().getColorManager().getColor(bg.toRGB());
        }

        public Font getFont(Object element) {
            ThemeRule token = (ThemeRule) element;
            if (token.getTextAttribute().style == 0) // TODO Limit to only checking for bold or italic
                return fFont;
            return lazyFont(fFont, token.getTextAttribute().style);
        }
    });

    column.setEditingSupport(new EditingSupport(tableViewer) {

        private TextCellEditor cellEditor;

        @Override
        protected void setValue(Object element, Object value) {
            ThemeRule token = (ThemeRule) element;
            String newName = (String) value;
            if (newName.equals(token.getName())) {
                return;
            }
            // update the token in the theme
            int index = getTheme().getTokens().indexOf(token);
            getTheme().updateRule(index, token.setName(newName));
            tableViewer.refresh();
        }

        @Override
        protected Object getValue(Object element) {
            ThemeRule token = (ThemeRule) element;
            return token.getName();
        }

        @Override
        protected CellEditor getCellEditor(Object element) {
            ThemeRule token = (ThemeRule) element;
            cellEditor = new TextCellEditor(table);
            cellEditor.setValue(token.getName());
            return cellEditor;
        }

        @Override
        protected boolean canEdit(Object element) {
            return true;
        }
    });

    column = new TableViewerColumn(tableViewer, SWT.NONE);
    final TableColumn foreground = column.getColumn();
    foreground.setResizable(false);
    foreground.setText(Messages.ThemePreferencePage_ForegroundColumnLabel);
    layout.setColumnData(foreground, new ColumnPixelData(30, false));
    column.setLabelProvider(new ColumnLabelProvider() {
        @Override
        public String getText(Object element) {
            return ""; //$NON-NLS-1$
        }
    });

    column = new TableViewerColumn(tableViewer, SWT.NONE);
    final TableColumn background = column.getColumn();
    background.setResizable(false);
    background.setText(Messages.ThemePreferencePage_BackgroundColumnLabel);
    layout.setColumnData(background, new ColumnPixelData(30, false));
    column.setLabelProvider(new ColumnLabelProvider() {
        @Override
        public String getText(Object element) {
            return ""; //$NON-NLS-1$
        }
    });

    final TableColumn fontStyle = new TableColumn(table, SWT.NONE);
    fontStyle.setResizable(false);
    fontStyle.setText(Messages.ThemePreferencePage_FontStyleColumnLabel);
    layout.setColumnData(fontStyle, new ColumnPixelData(75, false));

    Composite editTokenList = new Composite(composite, SWT.NONE);
    editTokenList.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    GridLayout grid = new GridLayout(2, false);
    editTokenList.setLayout(grid);

    Composite buttons = new Composite(editTokenList, SWT.NONE);
    GridLayout buttonsLayout = new GridLayout(2, true);
    buttonsLayout.marginWidth = 0;
    buttonsLayout.horizontalSpacing = 0;
    buttons.setLayout(buttonsLayout);

    fAddTokenButton = new Button(buttons, SWT.PUSH | SWT.FLAT);
    fAddTokenButton.setBounds(0, 0, 16, 16);
    fAddTokenButton.setLayoutData(new GridData(GridData.FILL_BOTH));
    fAddTokenButton.setText(Messages.ThemePreferencePage_AddTokenLabel);
    fAddTokenButton.addSelectionListener(this);
    fRemoveTokenButton = new Button(buttons, SWT.PUSH | SWT.FLAT);
    fRemoveTokenButton.setLayoutData(new GridData(GridData.FILL_BOTH));
    fRemoveTokenButton.setText(Messages.ThemePreferencePage_RemoveTokenLabel);
    fRemoveTokenButton.addSelectionListener(this);

    Composite textField = new Composite(editTokenList, SWT.NONE);
    textField.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    textField.setLayout(new GridLayout(2, false));
    Label addTokenLabel = new Label(textField, SWT.RIGHT);
    addTokenLabel.setText(Messages.ThemePreferencePage_ScopeSelectoreLabel);

    fScopeText = new Combo(textField, SWT.SINGLE | SWT.BORDER);
    GridData data = new GridData(GridData.FILL_HORIZONTAL);
    fScopeText.setLayoutData(data);
    for (String preset : tokenTypeNames) {
        fScopeText.add(preset);
    }
    table.addSelectionListener(this);
    fScopeSelectorDecoration = new ControlDecoration(fScopeText, SWT.RIGHT);
    fScopeText.addModifyListener(new ModifyListener() {

        public void modifyText(ModifyEvent e) {
            // Update the scope selector for the current token!
            TableItem[] selection = table.getSelection();
            if (selection == null || selection.length == 0) {
                return;
            }
            TableItem item = selection[0];
            ThemeRule rule = (ThemeRule) item.getData();

            String scopeSelectorText = fScopeText.getText();
            // Validate the value isn't a duplicate!
            ScopeSelector selector = new ScopeSelector(scopeSelectorText);
            ThemeRule match = getTheme().getRuleForSelector(selector);
            if (scopeSelectorText.length() > 0 && match != null && match != rule) {
                FieldDecoration dec = FieldDecorationRegistry.getDefault()
                        .getFieldDecoration(FieldDecorationRegistry.DEC_WARNING);
                fScopeSelectorDecoration.setImage(dec.getImage());
                fScopeSelectorDecoration.setDescriptionText(MessageFormat
                        .format(Messages.ThemePreferencePage_DuplicateScopeSelectorRules, match.getName()));
                fScopeText.setForeground(Display.getDefault().getSystemColor(SWT.COLOR_RED));
            } else {
                fScopeSelectorDecoration.setDescriptionText(null);
                fScopeSelectorDecoration.setImage(null);
                fScopeText.setForeground(null);
            }

            int index = table.indexOf(item);
            ThemeRule newRule = rule.setScopeSelector(selector);
            getTheme().updateRule(index, newRule);
            item.setData(newRule);
        }
    });

    addDNDToTable(table);
}

From source file:com.motorola.studio.android.emulator.device.ui.StartupOptionsComposite.java

License:Apache License

/**
 * Create widgets to enable user to input data for fields of text or number type
 * /*from   ww  w.  j ava 2s.c  o m*/
 * @param parent composite where the widgets will be attached to
 * @param startupOption the corresponding startup option
 */
private void createWidgetsForTextOrNumberType(final Composite parent, final StartupOption startupOption) {
    // create input text with calc button
    if (startupOption.getName().equals(SCALE)) {
        final Text inputText = new Text(parent, SWT.SINGLE | SWT.BORDER);
        inputText.setText(startupOption.getValue());
        startupOption.setValueWidget(inputText);
        inputText.setLayoutData(new GridData(SWT.FILL, SWT.NULL, true, false));
        inputText.addModifyListener(new ModifyListener() {
            public void modifyText(ModifyEvent e) {
                startupOption.setValue(inputText.getText());
                notifyCompositeChangeListeners();
            }
        });

        Button calc = new Button(parent, SWT.PUSH);
        calc.setText(EmulatorNLS.UI_DpiScale_Calculator);
        GridData calcData = new GridData(SWT.NULL, SWT.NULL, false, false);
        calc.setLayoutData(calcData);
        calc.addSelectionListener(new SelectionAdapter() {
            @Override
            public void widgetSelected(SelectionEvent e) {
                DpiScaleCalculatorDialog dialog = new DpiScaleCalculatorDialog(new Shell(parent.getShell()),
                        skin);
                if (dialog.open() == Dialog.OK) {
                    for (StartupOptionsGroup group : StartupOptionsMgt.getStartupOptionsGroupsList()) {
                        for (StartupOption startupOption : group.getStartupOptions()) {
                            if (startupOption.getName().equals(SCALE)) {
                                startupOption.setChecked(true);
                                startupOption.setValue(dialog.getResultScaleValue());
                                startupOption.updateUI();
                            }
                        }
                    }
                }
            }
        });
        calc.setEnabled(canCalculateScale);
        if (!canCalculateScale) {
            ControlDecoration controlDecoration = new ControlDecoration(inputText, SWT.LEFT | SWT.TOP);
            controlDecoration.setDescriptionText(
                    EmulatorNLS.StartupOptionsComposite_Error_Loading_Skin_Cant_Calculate_Scale);
            FieldDecoration fieldDecoration = FieldDecorationRegistry.getDefault()
                    .getFieldDecoration(FieldDecorationRegistry.DEC_WARNING);
            controlDecoration.setImage(fieldDecoration.getImage());
        }
    }
    // create input text
    else if ((startupOption.getPreDefinedValues() == null)
            || (startupOption.getPreDefinedValues().size() == 0)) {
        final Text inputText = new Text(parent, SWT.SINGLE | SWT.BORDER);
        inputText.setText(startupOption.getValue());
        startupOption.setValueWidget(inputText);
        inputText.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 2, 1));
        inputText.addModifyListener(new ModifyListener() {
            public void modifyText(ModifyEvent e) {
                startupOption.setValue(inputText.getText());
                notifyCompositeChangeListeners();
            }
        });
    }
    // create combobox
    else {
        final Combo combo = new Combo(parent, SWT.READ_ONLY);
        startupOption.setValueWidget(combo);
        int selectedIndex = 0;
        for (String preDefinedValue : startupOption.getPreDefinedValues()) {
            combo.add(preDefinedValue);
            if (startupOption.getValue().equals(preDefinedValue)) {
                combo.select(selectedIndex);
            } else {
                selectedIndex++;
            }
        }
        combo.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 2, 1));
        combo.addModifyListener(new ModifyListener() {
            public void modifyText(ModifyEvent e) {
                startupOption.setValue(combo.getText());
                notifyCompositeChangeListeners();
            }
        });
    }
}

From source file:com.netxforge.screens.editing.base.util.DecorationService.java

License:Open Source License

public ControlDecoration getWarningDecoration(Control control) {
    ControlDecoration deco = new ControlDecoration(control, SWT.LEFT | SWT.CENTER);
    FieldDecoration fieldDecoration = FieldDecorationRegistry.getDefault()
            .getFieldDecoration(FieldDecorationRegistry.DEC_WARNING);
    deco.setImage(fieldDecoration.getImage());
    deco.hide();//w  w  w .  j  a  v  a  2  s  .com
    return deco;
}

From source file:com.nokia.tools.variant.common.ui.wizards.dialogfields.DialogField.java

License:Open Source License

protected FieldDecoration getWarningDecoration() {
    if (warningDecoration == null) {
        FieldDecoration standardWarning = FieldDecorationRegistry.getDefault()
                .getFieldDecoration(FieldDecorationRegistry.DEC_WARNING);
        if (getWarningMessage() == null) {
            warningDecoration = standardWarning;
        } else {/*  w  ww. ja  v  a 2  s .  c om*/
            warningDecoration = new FieldDecoration(standardWarning.getImage(), getWarningMessage());
        }
    }
    return warningDecoration;
}

From source file:com.siteview.mde.internal.ui.launcher.ProgramBlock.java

License:Open Source License

protected void createProductSection(Composite parent) {
    fProductButton = new Button(parent, SWT.RADIO);
    fProductButton.setText(MDEUIMessages.ProgramBlock_runProduct);
    fProductButton.addSelectionListener(fListener);

    fProductCombo = SWTFactory.createCombo(parent, SWT.DROP_DOWN, 1, TargetPlatform.getProducts());
    fProductCombo.addSelectionListener(fListener);
    fProductCombo.addModifyListener(fListener);

    fProductComboDecoration = new ControlDecoration(fProductCombo, SWT.TOP | SWT.LEFT);
    FieldDecoration warningDecoration = FieldDecorationRegistry.getDefault()
            .getFieldDecoration(FieldDecorationRegistry.DEC_WARNING);
    fProductComboDecoration.setDescriptionText(MDEUIMessages.ProgramBlock_productDecorationWarning0);
    fProductComboDecoration.setImage(warningDecoration.getImage());

}

From source file:com.teamcenter.hendrickson.schmgr.operations.Validator.java

License:MIT License

Image getFieldDecorationImage(String type) {

    String Icontype = FieldDecorationRegistry.DEC_INFORMATION;

    if (type.equals("error")) {

        Icontype = FieldDecorationRegistry.DEC_ERROR;

    } else if (type.equals("warn")) {

        Icontype = FieldDecorationRegistry.DEC_WARNING;

    } else if (type.equals("required")) {

        Icontype = FieldDecorationRegistry.DEC_REQUIRED;

    } else if (type.equals("content")) {

        Icontype = FieldDecorationRegistry.DEC_CONTENT_PROPOSAL;

    } else if (type.equals("quickfix")) {

        Icontype = FieldDecorationRegistry.DEC_ERROR_QUICKFIX;

    } else {//from  w  ww  .  j  av a2  s  .  c  om

        Icontype = FieldDecorationRegistry.DEC_INFORMATION;

    }

    Image image = FieldDecorationRegistry.getDefault().getFieldDecoration(Icontype).getImage();

    if (type.equals("correct"))
        return image = ResourceManager.getPluginImage("example", "icons/tick.png");
    else
        return image;
}

From source file:com.xse.eclipseui.widgets.AbstractBaseWidget.java

License:Open Source License

protected boolean handleValidationResult(final IStatus status) {
    if (Status.OK_STATUS != status) {
        this.controlDecoration.setDescriptionText(status.getMessage());

        final FieldDecoration fieldDecoration;
        if (status.getSeverity() == IStatus.WARNING) {
            fieldDecoration = FieldDecorationRegistry.getDefault()
                    .getFieldDecoration(FieldDecorationRegistry.DEC_WARNING);
        } else if (status.getSeverity() == IStatus.INFO) {
            fieldDecoration = FieldDecorationRegistry.getDefault()
                    .getFieldDecoration(FieldDecorationRegistry.DEC_INFORMATION);
        } else {/*from  w  ww  . ja  va 2s .com*/
            fieldDecoration = FieldDecorationRegistry.getDefault()
                    .getFieldDecoration(FieldDecorationRegistry.DEC_ERROR);
        }

        this.controlDecoration.setImage(fieldDecoration.getImage());
        this.controlDecoration.show();

        return false;
    }

    return true;
}