Example usage for org.eclipse.jface.viewers ComboViewer ComboViewer

List of usage examples for org.eclipse.jface.viewers ComboViewer ComboViewer

Introduction

In this page you can find the example usage for org.eclipse.jface.viewers ComboViewer ComboViewer.

Prototype

public ComboViewer(Composite parent, int style) 

Source Link

Document

Creates a combo viewer on a newly-created combo control under the given parent.

Usage

From source file:org.bonitasoft.studio.expression.editor.operation.OperatorSelectionDialog.java

License:Open Source License

@Override
protected Control createDialogArea(Composite parent) {
    final Composite mainComposite = new Composite(parent, SWT.NONE);
    mainComposite/*from   ww  w. j  ava2 s.  c o m*/
            .setLayoutData(GridDataFactory.fillDefaults().grab(true, true).hint(300, SWT.DEFAULT).create());
    mainComposite.setLayout(GridLayoutFactory.fillDefaults().numColumns(2).margins(10, 10).create());
    final Label operatorType = new Label(mainComposite, SWT.NONE);
    operatorType.setText(Messages.operatorType);

    final ComboViewer operatorViewer = new ComboViewer(mainComposite, SWT.READ_ONLY | SWT.BORDER);
    operatorViewer.getCombo().setLayoutData(GridDataFactory.fillDefaults().grab(true, false).create());

    operatorViewer.setContentProvider(new ArrayContentProvider());
    operatorViewer.setLabelProvider(new OperatorLabelProvider());
    operatorViewer.addFilter(new ViewerFilter() {

        @Override
        public boolean select(Viewer viewer, Object parentElement, Object element) {
            Expression exp = operation.getLeftOperand();
            if (exp != null && !exp.getReferencedElements().isEmpty()
                    && ExpressionConstants.VARIABLE_TYPE.equals(exp.getType())) {
                EObject data = exp.getReferencedElements().get(0);
                if (data instanceof BusinessObjectData) {
                    return element.equals(ExpressionConstants.CREATE_BUSINESS_DATA_OPERATOR)
                            || element.equals(ExpressionConstants.JAVA_METHOD_OPERATOR);
                } else if (data instanceof JavaObjectData) {
                    return element.equals(ExpressionConstants.ASSIGNMENT_OPERATOR)
                            || element.equals(ExpressionConstants.JAVA_METHOD_OPERATOR);
                } else if (data instanceof XMLData) {
                    return element.equals(ExpressionConstants.ASSIGNMENT_OPERATOR)
                            || element.equals(ExpressionConstants.XPATH_UPDATE_OPERATOR);
                } else {
                    return element.equals(ExpressionConstants.ASSIGNMENT_OPERATOR);
                }
            } else if (exp != null && !exp.getReferencedElements().isEmpty()
                    && ExpressionConstants.DOCUMENT_REF_TYPE.equals(exp.getType())) {
                return element.equals(ExpressionConstants.SET_DOCUMENT_OPERATOR);
            }
            return element.equals(ExpressionConstants.ASSIGNMENT_OPERATOR);
        }
    });

    operatorViewer.setInput(operatorTypeList);

    section = new Section(mainComposite, Section.NO_TITLE);
    section.setLayoutData(GridDataFactory.fillDefaults().grab(true, false).span(2, 1).create());

    Expression exp = operation.getLeftOperand();
    for (IOperatorEditor opEditor : operatorEditors) {
        if (!opEditor.appliesTo(exp) && opEditor.appliesTo(operator.getType())) {
            operator.setType(ExpressionConstants.ASSIGNMENT_OPERATOR);
        }
    }
    createOperatorEditorFor(section, operator.getType(), operator, exp);

    context.bindValue(ViewersObservables.observeSingleSelection(operatorViewer),
            EMFObservables.observeValue(operator, ExpressionPackage.Literals.OPERATOR__TYPE));
    operatorViewer.addSelectionChangedListener(this);

    return mainComposite;
}