Example usage for org.eclipse.jface.fieldassist ControlDecoration dispose

List of usage examples for org.eclipse.jface.fieldassist ControlDecoration dispose

Introduction

In this page you can find the example usage for org.eclipse.jface.fieldassist ControlDecoration dispose.

Prototype

public void dispose() 

Source Link

Document

Dispose this ControlDecoration.

Usage

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

License:Open Source License

@SuppressWarnings("unused") // SWT constructors have side effects and aren't unused
private void onEnter() {
    TemplateMetadata template = mValues.getTemplateHandler().getTemplate();
    if (template == mShowingTemplate) {
        return;/* www.  jav a2 s.co m*/
    }
    mShowingTemplate = template;

    Composite parent = (Composite) getControl();

    Control[] children = parent.getChildren();
    if (children.length > 0) {
        for (Control c : parent.getChildren()) {
            c.dispose();
        }
        for (ControlDecoration decoration : mDecorations.values()) {
            decoration.dispose();
        }
        mDecorations.clear();
    }

    Composite container = new Composite(parent, SWT.NULL);
    container.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 2, 1));
    GridLayout gl_container = new GridLayout(3, false);
    gl_container.horizontalSpacing = 10;
    container.setLayout(gl_container);

    if (mChooseProject) {
        // Project: [button]
        String tooltip = "The Android Project where the new resource will be created.";
        Label projectLabel = new Label(container, SWT.NONE);
        projectLabel.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
        projectLabel.setText("Project:");
        projectLabel.setToolTipText(tooltip);

        ProjectChooserHelper helper = new ProjectChooserHelper(getShell(), null /* filter */);
        mProjectButton = new ProjectCombo(helper, container, mValues.project);
        mProjectButton.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 2, 1));
        mProjectButton.setToolTipText(tooltip);
        mProjectButton.addSelectionListener(this);

        //Label projectSeparator = new Label(container, SWT.SEPARATOR | SWT.HORIZONTAL);
        //projectSeparator.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false, 3, 1));
    }

    // Add parameters
    mFirst = null;
    String thumb = null;
    if (template != null) {
        thumb = template.getThumbnailPath();
        String title = template.getTitle();
        if (title != null && !title.isEmpty()) {
            setTitle(title);
        }
        String description = template.getDescription();
        if (description != null && !description.isEmpty()) {
            setDescription(description);
        }

        Map<String, String> defaults = mValues.defaults;
        Set<String> seen = null;
        if (LintUtils.assertionsEnabled()) {
            seen = new HashSet<String>();
        }

        List<Parameter> parameters = template.getParameters();
        for (Parameter parameter : parameters) {
            Parameter.Type type = parameter.type;

            if (type == Parameter.Type.SEPARATOR) {
                Label separator = new Label(container, SWT.SEPARATOR | SWT.HORIZONTAL);
                separator.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false, 3, 1));
                continue;
            }

            String id = parameter.id;
            assert id != null && !id.isEmpty() : ATTR_ID;
            Object value = defaults.get(id);
            if (value == null) {
                value = parameter.value;
            }

            String name = parameter.name;
            String help = parameter.help;

            // Required
            assert name != null && !name.isEmpty() : ATTR_NAME;
            // Ensure id's are unique:
            assert seen != null && seen.add(id) : id;

            // Skip attributes that were already provided by the surrounding
            // context. For example, when adding into an existing project,
            // provide the minimum SDK automatically from the project.
            if (mValues.hidden != null && mValues.hidden.contains(id)) {
                continue;
            }

            switch (type) {
            case STRING: {
                // TODO: Look at the constraints to add validators here
                // TODO: If I type.equals("layout") add resource validator for layout
                // names
                // TODO: If I type.equals("class") make class validator

                // TODO: Handle package and id better later
                Label label = new Label(container, SWT.NONE);
                label.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
                label.setText(name);

                Text text = new Text(container, SWT.BORDER);
                text.setData(parameter);
                parameter.control = text;

                if (parameter.constraints.contains(Constraint.EXISTS)) {
                    text.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));

                    Button button = new Button(container, SWT.FLAT);
                    button.setData(parameter);
                    button.setText("...");
                    button.addSelectionListener(this);
                } else {
                    text.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 2, 1));
                }

                boolean hasValue = false;
                if (value instanceof String) {
                    String stringValue = (String) value;
                    hasValue = !stringValue.isEmpty();
                    text.setText(stringValue);
                    mValues.parameters.put(id, value);
                }

                if (!hasValue) {
                    if (parameter.constraints.contains(Constraint.EMPTY)) {
                        text.setMessage("Optional");
                    } else if (parameter.constraints.contains(Constraint.NONEMPTY)) {
                        text.setMessage("Required");
                    }
                }

                text.addModifyListener(this);
                text.addFocusListener(this);

                if (mFirst == null) {
                    mFirst = text;
                }

                if (help != null && !help.isEmpty()) {
                    text.setToolTipText(help);
                    ControlDecoration decoration = createFieldDecoration(id, text, help);
                }
                break;
            }
            case BOOLEAN: {
                Label label = new Label(container, SWT.NONE);
                label.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));

                Button checkBox = new Button(container, SWT.CHECK);
                checkBox.setText(name);
                checkBox.setData(parameter);
                parameter.control = checkBox;
                checkBox.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 2, 1));

                if (value instanceof Boolean) {
                    Boolean selected = (Boolean) value;
                    checkBox.setSelection(selected);
                    mValues.parameters.put(id, value);
                }

                checkBox.addSelectionListener(this);
                checkBox.addFocusListener(this);

                if (mFirst == null) {
                    mFirst = checkBox;
                }

                if (help != null && !help.isEmpty()) {
                    checkBox.setToolTipText(help);
                    ControlDecoration decoration = createFieldDecoration(id, checkBox, help);
                }
                break;
            }
            case ENUM: {
                Label label = new Label(container, SWT.NONE);
                label.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
                label.setText(name);

                Combo combo = createOptionCombo(parameter, container, mValues.parameters, this, this);
                combo.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 2, 1));

                if (mFirst == null) {
                    mFirst = combo;
                }

                if (help != null && !help.isEmpty()) {
                    ControlDecoration decoration = createFieldDecoration(id, combo, help);
                }
                break;
            }
            case SEPARATOR:
                // Already handled above
                assert false : type;
                break;
            default:
                assert false : type;
            }
        }
    }

    // Preview
    mPreview = new ImageControl(parent, SWT.NONE, null);
    mPreview.setDisposeImage(false); // Handled manually in this class
    GridData gd_mImage = new GridData(SWT.CENTER, SWT.CENTER, false, false, 1, 1);
    gd_mImage.widthHint = PREVIEW_WIDTH + 2 * PREVIEW_PADDING;
    mPreview.setLayoutData(gd_mImage);

    Label separator = new Label(parent, SWT.SEPARATOR | SWT.HORIZONTAL);
    GridData separatorData = new GridData(SWT.FILL, SWT.TOP, true, false, 3, 1);
    separatorData.heightHint = 16;
    separator.setLayoutData(separatorData);

    // Generic help
    mHelpIcon = new Label(parent, SWT.NONE);
    mHelpIcon.setLayoutData(new GridData(SWT.RIGHT, SWT.TOP, false, false, 1, 1));
    Image icon = IconFactory.getInstance().getIcon("quickfix");
    mHelpIcon.setImage(icon);
    mHelpIcon.setVisible(false);
    mTipLabel = new Label(parent, SWT.WRAP);
    mTipLabel.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1));

    setPreview(thumb);

    parent.layout(true, true);
    // TODO: This is a workaround for the fact that (at least on OSX) you end up
    // with some visual artifacts from the control decorations in the upper left corner
    // (outside the parent widget itself) from the initial control decoration placement
    // prior to layout. Therefore, perform a redraw. A better solution would be to
    // delay creation of the control decorations until layout has been performed.
    // Let's do that soon.
    parent.getParent().redraw();
}

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

License:Open Source License

@SuppressWarnings("unused") // SWT constructors have side effects and aren't unused
private void onEnter() {
    TemplateMetadata template = mValues.getTemplateHandler().getTemplate();
    if (template == mShowingTemplate) {
        return;// www .j a va  2  s.  co m
    }
    mShowingTemplate = template;

    Composite parent = (Composite) getControl();

    Control[] children = parent.getChildren();
    if (children.length > 0) {
        for (Control c : parent.getChildren()) {
            c.dispose();
        }
        for (ControlDecoration decoration : mDecorations.values()) {
            decoration.dispose();
        }
        mDecorations.clear();
    }

    Composite container = new Composite(parent, SWT.NULL);
    container.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 2, 1));
    GridLayout gl_container = new GridLayout(3, false);
    gl_container.horizontalSpacing = 10;
    container.setLayout(gl_container);

    if (mChooseProject) {
        // Project: [button]
        String tooltip = "The Android Project where the new resource will be created.";
        Label projectLabel = new Label(container, SWT.NONE);
        projectLabel.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
        projectLabel.setText("Project:");
        projectLabel.setToolTipText(tooltip);

        ProjectChooserHelper helper = new ProjectChooserHelper(getShell(), null /* filter */);
        mProjectButton = new ProjectCombo(helper, container, mValues.project);
        mProjectButton.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 2, 1));
        mProjectButton.setToolTipText(tooltip);
        mProjectButton.addSelectionListener(this);

        //Label projectSeparator = new Label(container, SWT.SEPARATOR | SWT.HORIZONTAL);
        //projectSeparator.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false, 3, 1));
    }

    // Add parameters
    mFirst = null;
    String thumb = null;
    if (template != null) {
        thumb = template.getThumbnailPath();
        String title = template.getTitle();
        if (title != null && !title.isEmpty()) {
            setTitle(title);
        }
        String description = template.getDescription();
        if (description != null && !description.isEmpty()) {
            setDescription(description);
        }

        Map<String, String> defaults = mValues.defaults;
        Set<String> seen = null;
        if (LintUtils.assertionsEnabled()) {
            seen = new HashSet<String>();
        }

        List<Parameter> parameters = template.getParameters();
        mParameters = new ArrayList<Parameter>(parameters.size());
        for (Parameter parameter : parameters) {
            Parameter.Type type = parameter.type;

            if (type == Parameter.Type.SEPARATOR) {
                Label separator = new Label(container, SWT.SEPARATOR | SWT.HORIZONTAL);
                separator.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false, 3, 1));
                continue;
            }

            String id = parameter.id;
            assert id != null && !id.isEmpty() : ATTR_ID;
            mParameters.add(parameter);
            String value = defaults.get(id);
            if (value == null) {
                value = parameter.initial;
            }

            String name = parameter.name;
            String help = parameter.help;

            // Required
            assert name != null && !name.isEmpty() : ATTR_NAME;
            // Ensure id's are unique:
            assert seen != null && seen.add(id) : id;

            // Skip attributes that were already provided by the surrounding
            // context. For example, when adding into an existing project,
            // provide the minimum SDK automatically from the project.
            if (mValues.hidden != null && mValues.hidden.contains(id)) {
                continue;
            }

            switch (type) {
            case STRING: {
                // TODO: Look at the constraints to add validators here
                // TODO: If I type.equals("layout") add resource validator for layout
                // names
                // TODO: If I type.equals("class") make class validator

                // TODO: Handle package and id better later
                Label label = new Label(container, SWT.NONE);
                label.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
                label.setText(name);

                Text text = new Text(container, SWT.BORDER);
                text.setData(parameter);
                parameter.control = text;

                if (parameter.constraints.contains(Parameter.Constraint.EXISTS)) {
                    text.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));

                    Button button = new Button(container, SWT.FLAT);
                    button.setData(parameter);
                    button.setText("...");
                    button.addSelectionListener(this);
                } else {
                    text.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 2, 1));
                }

                if (value != null && !value.isEmpty()) {
                    text.setText(value);
                    mValues.parameters.put(id, value);
                }

                text.addModifyListener(this);
                text.addFocusListener(this);

                if (mFirst == null) {
                    mFirst = text;
                }

                if (help != null && !help.isEmpty()) {
                    text.setToolTipText(help);
                    ControlDecoration decoration = createFieldDecoration(id, text, help);
                }
                break;
            }
            case BOOLEAN: {
                Label label = new Label(container, SWT.NONE);
                label.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));

                Button checkBox = new Button(container, SWT.CHECK);
                checkBox.setText(name);
                checkBox.setData(parameter);
                parameter.control = checkBox;
                checkBox.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 2, 1));

                if (value != null && !value.isEmpty()) {
                    Boolean selected = Boolean.valueOf(value);
                    checkBox.setSelection(selected);
                    mValues.parameters.put(id, value);
                }

                checkBox.addSelectionListener(this);
                checkBox.addFocusListener(this);

                if (mFirst == null) {
                    mFirst = checkBox;
                }

                if (help != null && !help.isEmpty()) {
                    checkBox.setToolTipText(help);
                    ControlDecoration decoration = createFieldDecoration(id, checkBox, help);
                }
                break;
            }
            case ENUM: {
                Label label = new Label(container, SWT.NONE);
                label.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
                label.setText(name);

                Combo combo = new Combo(container, SWT.READ_ONLY);
                combo.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 2, 1));

                List<Element> options = DomUtilities.getChildren(parameter.element);
                assert options.size() > 0;
                int selected = 0;
                List<String> ids = Lists.newArrayList();
                List<Integer> minSdks = Lists.newArrayList();
                List<String> labels = Lists.newArrayList();
                for (int i = 0, n = options.size(); i < n; i++) {
                    Element option = options.get(i);
                    String optionId = option.getAttribute(ATTR_ID);
                    assert optionId != null && !optionId.isEmpty() : ATTR_ID;
                    String isDefault = option.getAttribute(ATTR_DEFAULT);
                    if (isDefault != null && !isDefault.isEmpty() && Boolean.valueOf(isDefault)) {
                        selected = i;
                    }
                    NodeList childNodes = option.getChildNodes();
                    assert childNodes.getLength() == 1 && childNodes.item(0).getNodeType() == Node.TEXT_NODE;
                    String optionLabel = childNodes.item(0).getNodeValue().trim();

                    String minApiString = option.getAttribute(ATTR_MIN_API);
                    int minSdk = 1;
                    if (minApiString != null && !minApiString.isEmpty()) {
                        try {
                            minSdk = Integer.parseInt(minApiString);
                        } catch (NumberFormatException nufe) {
                            // Templates aren't allowed to contain codenames, should
                            // always be an integer
                            AdtPlugin.log(nufe, null);
                            minSdk = 1;
                        }
                    }
                    minSdks.add(minSdk);
                    ids.add(optionId);
                    labels.add(optionLabel);
                }
                combo.setData(parameter);
                parameter.control = combo;
                combo.setData(ATTR_ID, ids.toArray(new String[ids.size()]));
                combo.setData(ATTR_MIN_API, minSdks.toArray(new Integer[minSdks.size()]));
                assert labels.size() > 0;
                combo.setItems(labels.toArray(new String[labels.size()]));
                combo.select(selected);
                mValues.parameters.put(id, ids.get(selected));

                combo.addSelectionListener(this);
                combo.addFocusListener(this);

                if (mFirst == null) {
                    mFirst = combo;
                }

                if (help != null && !help.isEmpty()) {
                    combo.setToolTipText(help);
                    ControlDecoration decoration = createFieldDecoration(id, combo, help);
                }
                break;
            }
            case SEPARATOR:
                // Already handled above
                assert false : type;
                break;
            default:
                assert false : type;
            }
        }
    }

    // Preview
    mPreview = new ImageControl(parent, SWT.NONE, null);
    GridData gd_mImage = new GridData(SWT.CENTER, SWT.CENTER, false, false, 1, 1);
    gd_mImage.widthHint = PREVIEW_WIDTH + 2 * PREVIEW_PADDING;
    mPreview.setLayoutData(gd_mImage);

    Label separator = new Label(parent, SWT.SEPARATOR | SWT.HORIZONTAL);
    GridData separatorData = new GridData(SWT.FILL, SWT.TOP, true, false, 3, 1);
    separatorData.heightHint = 16;
    separator.setLayoutData(separatorData);

    // Generic help
    mHelpIcon = new Label(parent, SWT.NONE);
    mHelpIcon.setLayoutData(new GridData(SWT.RIGHT, SWT.TOP, false, false, 1, 1));
    Image icon = IconFactory.getInstance().getIcon("quickfix");
    mHelpIcon.setImage(icon);
    mHelpIcon.setVisible(false);
    mTipLabel = new Label(parent, SWT.WRAP);
    mTipLabel.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1));

    if (thumb != null && !thumb.isEmpty()) {
        setPreview(thumb);
    }

    parent.layout(true, true);
    // TODO: This is a workaround for the fact that (at least on OSX) you end up
    // with some visual artifacts from the control decorations in the upper left corner
    // (outside the parent widget itself) from the initial control decoration placement
    // prior to layout. Therefore, perform a redraw. A better solution would be to
    // delay creation of the control decorations until layout has been performed.
    // Let's do that soon.
    parent.getParent().redraw();
}

From source file:gov.redhawk.ide.sad.internal.ui.properties.PropertiesViewerControlFactory.java

License:Open Source License

@Override
public Control createControl(CellEditDescriptor ced, final XViewer xv) {
    IStructuredSelection ss = (IStructuredSelection) xv.getSelection();
    Object editElement = ss.getFirstElement();
    if (ced.getInputField().equals(PropertiesViewerFactory.EXTERNAL.getId())) {
        if (editElement instanceof ViewerProperty<?>) {
            final ViewerProperty<?> prop = (ViewerProperty<?>) editElement;
            if (prop.getParent() instanceof ViewerComponent) {

                final Combo combo = new Combo(xv.getTree(), ced.getSwtStyle());
                combo.setItems(new String[] { "", prop.getDefinition().getId() });
                final ControlDecoration dec = new ControlDecoration(combo, SWT.TOP | SWT.LEFT);
                combo.addDisposeListener(new DisposeListener() {

                    @Override/*  www.  j  av  a 2s . com*/
                    public void widgetDisposed(DisposeEvent e) {
                        dec.dispose();
                    }
                });
                dec.setImage(PlatformUI.getWorkbench().getSharedImages()
                        .getImage(ISharedImages.IMG_DEC_FIELD_ERROR));
                dec.hide();
                dec.setShowOnlyOnFocus(true);
                dec.setShowHover(true);
                dec.setDescriptionText("Duplicate external property ID");

                final SoftwareAssembly sad = ScaEcoreUtils.getEContainerOfType(prop.getComponentInstantiation(),
                        SoftwareAssembly.class);
                combo.addModifyListener(new ModifyListener() {

                    @Override
                    public void modifyText(ModifyEvent e) {
                        String currentValue = prop.getExternalID();
                        if (currentValue != null && currentValue.equals(combo.getText())) {
                            dec.hide();
                        } else if (isUniqueProperty(combo.getText(), sad)) {
                            dec.hide();
                        } else {
                            dec.show();
                        }
                    }
                });
                return combo;
            }
        }
        return null;
    } else if (ced.getInputField().equals(PropertiesViewerFactory.SAD_VALUE.getId())) {
        if (editElement instanceof ViewerSimpleProperty) {
            final ViewerSimpleProperty simpleProp = (ViewerSimpleProperty) editElement;
            final Simple simple = simpleProp.getDefinition();
            if (simple.getType() == PropertyValueType.BOOLEAN) {
                Combo combo = new Combo(xv.getTree(), ced.getSwtStyle() | SWT.READ_ONLY);
                combo.setItems(new String[] { "", "true", "false" });
                return combo;
            } else if (simple.getEnumerations() != null) {
                Combo combo = new Combo(xv.getTree(), ced.getSwtStyle() | SWT.READ_ONLY);
                List<String> values = new ArrayList<String>(simple.getEnumerations().getEnumeration().size());
                for (Enumeration v : simple.getEnumerations().getEnumeration()) {
                    values.add(v.getLabel());
                }
                Collections.sort(values);
                combo.setItems(values.toArray(new String[values.size()]));
                return combo;
            } else {
                final Text text = new Text(xv.getTree(), ced.getSwtStyle());
                final ControlDecoration dec = new ControlDecoration(text, SWT.TOP | SWT.LEFT);
                text.addDisposeListener(new DisposeListener() {

                    @Override
                    public void widgetDisposed(DisposeEvent e) {
                        dec.dispose();
                    }
                });
                dec.setImage(PlatformUI.getWorkbench().getSharedImages()
                        .getImage(ISharedImages.IMG_DEC_FIELD_ERROR));
                dec.hide();
                dec.setShowOnlyOnFocus(true);
                dec.setShowHover(true);
                if (simple.isComplex()) {
                    dec.setDescriptionText("Value must of of type complex " + simple.getType());
                } else {
                    dec.setDescriptionText("Value must of of type " + simple.getType());
                }
                text.addModifyListener(new ModifyListener() {

                    @Override
                    public void modifyText(ModifyEvent e) {
                        if (simpleProp.checkValue(text.getText())) {
                            dec.hide();
                        } else {
                            dec.show();
                        }
                    }
                });
                return text;
            }
        } else if (editElement instanceof ViewerSequenceProperty) {
            final ViewerSequenceProperty seqProperty = (ViewerSequenceProperty) editElement;
            final Text text = new Text(xv.getTree(), ced.getSwtStyle());
            final ControlDecoration dec = new ControlDecoration(text, SWT.TOP | SWT.LEFT);
            text.addDisposeListener(new DisposeListener() {

                @Override
                public void widgetDisposed(DisposeEvent e) {
                    dec.dispose();
                }
            });
            dec.setImage(
                    PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_DEC_FIELD_ERROR));
            dec.hide();
            dec.setShowOnlyOnFocus(true);
            dec.setShowHover(true);
            if (seqProperty.getDefinition().isComplex()) {
                dec.setDescriptionText(
                        "Value must of of type complex " + seqProperty.getDefinition().getType() + "[]");
            } else {
                dec.setDescriptionText("Value must of of type " + seqProperty.getDefinition().getType() + "[]");
            }
            text.addModifyListener(new ModifyListener() {

                @Override
                public void modifyText(ModifyEvent event) {
                    try {
                        String[] newValue = PropertiesViewerConverter.split(text.getText());
                        if (seqProperty.checkValues(newValue)) {
                            dec.hide();
                        } else {
                            dec.show();
                        }
                    } catch (IllegalArgumentException e) {
                        dec.show();
                    }

                }
            });
            return text;
        } else if (editElement instanceof ViewerStructSequenceProperty) {
            final Button button = new Button(xv.getTree(), SWT.PUSH);
            button.setText("Edit");
            return button;
        } else if (editElement instanceof ViewerStructSequenceSimpleProperty) {
            // TODO
            return null;
        }
    }
    return super.createControl(ced, xv);
}

From source file:org.carrot2.workbench.core.ui.AttributeList.java

License:Open Source License

/**
 * Adds validation overlay component to the control.
 *//*from w  w  w  .j  av  a 2 s  .  c  o m*/
private void addValidationOverlay(final AttributeDescriptor descriptor, final IAttributeEditor editor,
        final Object defaultValue, final Control label) {
    final ControlDecoration decoration = new ControlDecoration(label, SWT.LEFT | SWT.BOTTOM);
    decoration.hide();

    final FieldDecoration fieldDecoration = FieldDecorationRegistry.getDefault()
            .getFieldDecoration(FieldDecorationRegistry.DEC_ERROR);

    decoration.setImage(fieldDecoration.getImage());
    decoration.setDescriptionText("Invalid value");

    final IAttributeListener validationListener = new InvalidStateDecorationListener(decoration, descriptor,
            defaultValue);

    globalEventsProvider.addAttributeListener(validationListener);
    editor.addAttributeListener(validationListener);

    label.addDisposeListener(new DisposeListener() {
        public void widgetDisposed(DisposeEvent e) {
            globalEventsProvider.removeAttributeListener(validationListener);
            editor.removeAttributeListener(validationListener);
            decoration.dispose();
        }
    });
}

From source file:org.ebayopensource.turmeric.eclipse.ui.SOABasePage.java

License:Open Source License

@Override
public void dispose() {
    super.dispose();
    for (ControlDecoration dec : errorDecorations.values()) {
        dec.dispose();
    }/*www.jav  a 2  s  . c  o  m*/
    errorDecorations.clear();
    for (ControlDecoration dec : controlDecorations.values()) {
        dec.dispose();
    }
    controlDecorations.clear();
}

From source file:org.eclipse.dltk.ui.wizards.ControlDecorationManager.java

License:Open Source License

public void dispose() {
    for (ControlDecoration decoration : decorations.values()) {
        decoration.hide();//from   www .  j  ava  2  s  . c  o m
        decoration.dispose();
    }
    decorations.clear();
}

From source file:org.eclipse.mylyn.internal.bugzilla.ui.editor.BugzillaTaskEditorPage.java

License:Open Source License

@Override
public void doSubmit() {
    TaskAttribute summaryAttribute = getModel().getTaskData().getRoot()
            .getMappedAttribute(TaskAttribute.SUMMARY);
    if (summaryAttribute != null && summaryAttribute.getValue().length() == 0) {
        getTaskEditor().setMessage(//  w w  w  .  j a v a 2 s  .  c  o m
                Messages.BugzillaTaskEditorPage_Please_enter_a_short_summary_before_submitting,
                IMessageProvider.ERROR);
        AbstractTaskEditorPart part = getPart(ID_PART_SUMMARY);
        if (part != null) {
            part.setFocus();
        }
        return;
    }

    TaskAttribute componentAttribute = getModel().getTaskData().getRoot()
            .getMappedAttribute(BugzillaAttribute.COMPONENT.getKey());
    if (componentAttribute != null && componentAttribute.getValue().length() == 0) {
        getTaskEditor().setMessage(Messages.BugzillaTaskEditorPage_Please_select_a_component_before_submitting,
                IMessageProvider.ERROR);
        AbstractTaskEditorPart part = getPart(ID_PART_ATTRIBUTES);
        if (part != null) {
            part.setFocus();
        }
        return;
    }

    TaskAttribute descriptionAttribute = getModel().getTaskData().getRoot()
            .getMappedAttribute(TaskAttribute.DESCRIPTION);
    if (descriptionAttribute != null && descriptionAttribute.getValue().length() == 0
            && getModel().getTaskData().isNew()) {
        getTaskEditor().setMessage(Messages.BugzillaTaskEditorPage_Please_enter_a_description_before_submitting,
                IMessageProvider.ERROR);
        AbstractTaskEditorPart descriptionPart = getPart(ID_PART_DESCRIPTION);
        if (descriptionPart != null) {
            descriptionPart.setFocus();
        }
        return;
    }
    TaskAttribute targetMilestoneAttribute = getModel().getTaskData().getRoot()
            .getMappedAttribute(BugzillaAttribute.TARGET_MILESTONE.getKey());
    if (targetMilestoneAttribute != null && targetMilestoneAttribute.getValue().length() == 0
            && getModel().getTaskData().isNew()) {
        getTaskEditor().setMessage(
                Messages.BugzillaTaskEditorPage_Please_enter_a_target_milestone_before_submitting,
                IMessageProvider.ERROR);
        AbstractTaskEditorPart descriptionPart = getPart(ID_PART_ATTRIBUTES);
        if (descriptionPart != null) {
            descriptionPart.setFocus();
        }
        return;
    }

    TaskAttribute attributeOperation = getModel().getTaskData().getRoot()
            .getMappedAttribute(TaskAttribute.OPERATION);
    if (attributeOperation != null) {
        if ("duplicate".equals(attributeOperation.getValue())) { //$NON-NLS-1$
            TaskAttribute originalOperation = getModel().getTaskData().getRoot()
                    .getAttribute(TaskAttribute.PREFIX_OPERATION + attributeOperation.getValue());
            String inputAttributeId = originalOperation.getMetaData()
                    .getValue(TaskAttribute.META_ASSOCIATED_ATTRIBUTE_ID);
            if (inputAttributeId != null && !inputAttributeId.equals("")) { //$NON-NLS-1$
                TaskAttribute inputAttribute = attributeOperation.getTaskData().getRoot()
                        .getAttribute(inputAttributeId);
                if (inputAttribute != null) {
                    String dupValue = inputAttribute.getValue();
                    if (dupValue == null || dupValue.equals("")) { //$NON-NLS-1$
                        getTaskEditor().setMessage(
                                Messages.BugzillaTaskEditorPage_Please_enter_a_bugid_for_duplicate_of_before_submitting,
                                IMessageProvider.ERROR);
                        AbstractTaskEditorPart part = getPart(ID_PART_ACTIONS);
                        if (part != null) {
                            part.setFocus();
                        }
                        return;
                    }
                }
            }
        }
    }

    if (getModel().getTaskData().isNew()) {
        TaskAttribute productAttribute = getModel().getTaskData().getRoot()
                .getMappedAttribute(TaskAttribute.PRODUCT);
        if (productAttribute != null && productAttribute.getValue().length() > 0) {
            getModel().getTaskRepository().setProperty(IBugzillaConstants.LAST_PRODUCT_SELECTION,
                    productAttribute.getValue());
        }
        TaskAttribute componentSelectedAttribute = getModel().getTaskData().getRoot()
                .getMappedAttribute(TaskAttribute.COMPONENT);
        if (componentSelectedAttribute != null && componentSelectedAttribute.getValue().length() > 0) {
            getModel().getTaskRepository().setProperty(IBugzillaConstants.LAST_COMPONENT_SELECTION,
                    componentSelectedAttribute.getValue());
        }
    }

    // Force the most recent known good token onto the outgoing task data to ensure submit
    // bug#263318
    TaskAttribute attrToken = getModel().getTaskData().getRoot().getAttribute(BugzillaAttribute.TOKEN.getKey());
    if (attrToken != null) {
        String tokenString = getModel().getTask().getAttribute(BugzillaAttribute.TOKEN.getKey());
        if (tokenString != null) {
            attrToken.setValue(tokenString);
        }
    }
    for (ControlDecoration decoration : errorDecorations) {
        decoration.hide();
        decoration.dispose();
    }
    errorDecorations.clear();
    editorsWithError.clear();
    if (!checkCanSubmit(IMessageProvider.ERROR)) {
        return;
    }
    getTaskEditor().setMessage("", IMessageProvider.NONE); //$NON-NLS-1$
    super.doSubmit();
}

From source file:org.eclipse.mylyn.internal.bugzilla.ui.editor.BugzillaTaskEditorPage.java

License:Open Source License

/**
 * @param fieldDecoration//from   w w w  .jav a  2 s .c o  m
 * @param message
 * @param newPersonProposalMap
 * @param editor
 */
private void decorateEditorWithError(FieldDecoration fieldDecoration, FieldDecoration fieldDecorationWarning,
        String message, Map<String, String> newPersonProposalMap, AbstractAttributeEditor editor) {
    final Control control = editor.getControl();

    final ControlDecoration decoration = new ControlDecoration(control, SWT.LEFT | SWT.DOWN);
    decoration.setImage(
            newPersonProposalMap.size() == 1 ? fieldDecorationWarning.getImage() : fieldDecoration.getImage());
    IBindingService bindingService = (IBindingService) PlatformUI.getWorkbench()
            .getService(IBindingService.class);
    if (message != null && !message.equals("")) { //$NON-NLS-1$
        decoration.setDescriptionText(message);
        errorDecorations.add(decoration);
    } else {
        decoration
                .setDescriptionText(NLS.bind(Messages.BugzillaTaskEditorPage_Content_Assist_for_Error_Available,
                        bindingService.getBestActiveBindingFormattedFor(
                                ContentAssistCommandAdapter.CONTENT_PROPOSAL_COMMAND)));
        errorDecorations.add(decoration);

        final PersonAttributeEditor personEditor = ((PersonAttributeEditor) editor);
        final PersonProposalProvider personProposalProvider = (PersonProposalProvider) personEditor
                .getContentAssistCommandAdapter().getContentProposalProvider();
        personProposalProvider.setErrorProposals(newPersonProposalMap);

        editorsWithError.add(personEditor);
        if (newPersonProposalMap.size() == 1) {
            personEditor.setValue(newPersonProposalMap.keySet().iterator().next());

        }
        personEditor.getText().addModifyListener(new ModifyListener() {

            public void modifyText(ModifyEvent e) {
                decoration.hide();
                errorDecorations.remove(decoration);
                decoration.dispose();
                personProposalProvider.setErrorProposals(null);
            }
        });
    }
}

From source file:org.eclipse.mylyn.internal.bugzilla.ui.search.BugzillaSearchPage.java

License:Open Source License

@Override
public boolean isPageComplete() {
    setMessage(""); //$NON-NLS-1$
    if (errorDecorations.size() > 0) {
        for (ControlDecoration decoration : errorDecorations) {
            decoration.hide();//from   w  ww .  j a  va  2 s .c o  m
            decoration.dispose();
        }
        errorDecorations.clear();
    }
    if (daysText != null) {
        String days = daysText.getText();
        if (days.length() > 0) {
            try {
                if (Integer.parseInt(days) < 0) {
                    throw new NumberFormatException();
                }
            } catch (NumberFormatException ex) {
                if (getContainer() != null) {
                    setMessage(NLS.bind(Messages.BugzillaSearchPage_Number_of_days_must_be_a_positive_integer,
                            days), IMessageProvider.ERROR);
                } else {
                    ErrorDialog.openError(getShell(), Messages.BugzillaSearchPage_ValidationTitle,
                            Messages.BugzillaSearchPage_Number_of_days_is_invalid,
                            new Status(IStatus.ERROR, BugzillaUiPlugin.ID_PLUGIN, NLS.bind(
                                    Messages.BugzillaSearchPage_days_must_be_an_positve_integer_value_but_is,
                                    days)));

                }
                return false;
            }
        }
    }
    if (emailPattern != null) {
        String email = emailPattern.getText();
        if (email.length() > 0) {
            boolean selectionMade = false;
            for (Button button : emailButtons) {
                if (button.getSelection()) {
                    selectionMade = true;
                    break;
                }
            }
            if (!selectionMade) {
                FieldDecorationRegistry registry = FieldDecorationRegistry.getDefault();
                FieldDecoration fieldDecoration = registry
                        .getFieldDecoration(FieldDecorationRegistry.DEC_ERROR);
                final ControlDecoration decoration = new ControlDecoration(emailPattern, SWT.LEFT | SWT.DOWN);
                decoration.setImage(fieldDecoration.getImage());
                decoration.setDescriptionText(NLS.bind(Messages.BugzillaSearchPage_ValidationMessage,
                        new String[] { Messages.BugzillaSearchPage_Email.replace('&', ' '),
                                Messages.BugzillaSearchPage_owner, Messages.BugzillaSearchPage_reporter,
                                Messages.BugzillaSearchPage_cc, Messages.BugzillaSearchPage_commenter,
                                Messages.BugzillaSearchPage_qacontact }));
                errorDecorations.add(decoration);
                if (getContainer() != null) {
                    setMessage(NLS.bind(Messages.BugzillaSearchPage_ValidationMessage,
                            new String[] { Messages.BugzillaSearchPage_Email.replace('&', ' '),
                                    Messages.BugzillaSearchPage_owner, Messages.BugzillaSearchPage_reporter,
                                    Messages.BugzillaSearchPage_cc, Messages.BugzillaSearchPage_commenter,
                                    Messages.BugzillaSearchPage_qacontact }),
                            IMessageProvider.ERROR);
                }
                return false;
            }
        }
    }
    if (emailPattern2 != null) {
        String email2 = emailPattern2.getText();
        if (email2.length() > 0) {
            boolean selectionMade = false;
            for (Button button : emailButtons2) {
                if (button.getSelection()) {
                    selectionMade = true;
                    break;
                }
            }
            if (!selectionMade) {
                FieldDecorationRegistry registry = FieldDecorationRegistry.getDefault();
                FieldDecoration fieldDecoration = registry
                        .getFieldDecoration(FieldDecorationRegistry.DEC_ERROR);
                final ControlDecoration decoration = new ControlDecoration(emailPattern, SWT.LEFT | SWT.DOWN);
                decoration.setImage(fieldDecoration.getImage());
                decoration.setDescriptionText(NLS.bind(Messages.BugzillaSearchPage_ValidationMessage,
                        new String[] { Messages.BugzillaSearchPage_Email_2.replace('&', ' '),
                                Messages.BugzillaSearchPage_owner, Messages.BugzillaSearchPage_reporter,
                                Messages.BugzillaSearchPage_cc, Messages.BugzillaSearchPage_commenter,
                                Messages.BugzillaSearchPage_qacontact }));
                errorDecorations.add(decoration);
                if (getContainer() != null) {
                    setMessage(NLS.bind(Messages.BugzillaSearchPage_ValidationMessage,
                            new String[] { Messages.BugzillaSearchPage_Email_2.replace('&', ' '),
                                    Messages.BugzillaSearchPage_owner, Messages.BugzillaSearchPage_reporter,
                                    Messages.BugzillaSearchPage_cc, Messages.BugzillaSearchPage_commenter,
                                    Messages.BugzillaSearchPage_qacontact }),
                            IMessageProvider.ERROR);
                }
                return false;
            }
        }
    }
    if (getWizard() == null) {
        return canQuery();
    } else {
        if (super.isPageComplete()) {
            if (canQuery()) {
                return true;
            }
        }
        return false;
    }
}

From source file:org.eclipse.mylyn.internal.web.tasks.WebQueryWizardPage.java

License:Open Source License

@Override
public void dispose() {
    for (ControlDecoration decoration : decorations) {
        decoration.dispose();
    }//from   w  w w .  j ava 2s  .  co  m
    super.dispose();
}