Example usage for org.eclipse.jface.databinding.swt SWTObservables observeEnabled

List of usage examples for org.eclipse.jface.databinding.swt SWTObservables observeEnabled

Introduction

In this page you can find the example usage for org.eclipse.jface.databinding.swt SWTObservables observeEnabled.

Prototype

@Deprecated
public static ISWTObservableValue observeEnabled(Control control) 

Source Link

Document

Returns an observable value tracking the enabled state of the given control

Usage

From source file:org.bonitasoft.studio.condition.ui.expression.ComparisonExpressionEditor.java

License:Open Source License

@Override
public void bindExpression(EMFDataBindingContext dataBindingContext, EObject context,
        Expression inputExpression, ViewerFilter[] viewerTypeFilters, ExpressionViewer expressionViewer) {
    this.inputExpression = inputExpression;
    final IObservableValue contentModelObservable = EMFObservables.observeValue(inputExpression,
            ExpressionPackage.Literals.EXPRESSION__CONTENT);
    final IObservableValue nameModelObservable = EMFObservables.observeValue(inputExpression,
            ExpressionPackage.Literals.EXPRESSION__NAME);
    final IObservableValue dependenciesModelObservable = EMFObservables.observeValue(inputExpression,
            ExpressionPackage.Literals.EXPRESSION__REFERENCED_ELEMENTS);
    final IObservableValue autoDepsModelObservable = EMFObservables.observeValue(inputExpression,
            ExpressionPackage.Literals.EXPRESSION__AUTOMATIC_DEPENDENCIES);
    final IObservableValue returnTypeModelObservable = EMFObservables.observeValue(inputExpression,
            ExpressionPackage.Literals.EXPRESSION__RETURN_TYPE);
    final ISWTObservableValue observeText = SWTObservables
            .observeText(comparisonEditor.getViewer().getControl(), SWT.Modify);
    dataBindingContext.bindValue(observeText, contentModelObservable);
    observeText.addValueChangeListener(new IValueChangeListener() {

        @Override//from   w  w w  .  j  av a 2  s.c om
        public void handleValueChange(ValueChangeEvent event) {
            if (ComparisonExpressionEditor.this.inputExpression.isAutomaticDependencies()) {
                updateDependencies();
            }
        }
    });
    dataBindingContext.bindValue(observeText, nameModelObservable);
    dataBindingContext.bindValue(ViewersObservables.observeInput(dependenciesViewer),
            dependenciesModelObservable);

    UpdateValueStrategy opposite = new UpdateValueStrategy();
    opposite.setConverter(new Converter(Boolean.class, Boolean.class) {

        @Override
        public Object convert(Object fromObject) {
            return !((Boolean) fromObject);
        }
    });

    dataBindingContext.bindValue(SWTObservables.observeSelection(automaticResolutionButton),
            autoDepsModelObservable);
    dataBindingContext.bindValue(SWTObservables.observeSelection(automaticResolutionButton),
            SWTObservables.observeEnabled(addDependencyButton), opposite,
            new UpdateValueStrategy(UpdateValueStrategy.POLICY_NEVER));
    dependencySection.setExpanded(!automaticResolutionButton.getSelection());

    addDependencyButton.setEnabled(!inputExpression.isAutomaticDependencies());
    ControlDecorationSupport.create(dataBindingContext.bindValue(
            ViewersObservables.observeSingleSelection(typeCombo), returnTypeModelObservable), SWT.LEFT);
    typeCombo.getCombo().setEnabled(!inputExpression.isReturnTypeFixed());

    final ExpressionContentProvider provider = new ExpressionContentProvider();
    provider.setContext(context);

    final Set<Expression> filteredExpressions = new HashSet<Expression>();
    Expression[] expressions = provider.getExpressions();
    EObject input = provider.getContext();
    if (expressions != null) {
        filteredExpressions.addAll(Arrays.asList(expressions));
        if (input != null && viewerTypeFilters != null) {
            for (Expression exp : expressions) {
                for (ViewerFilter filter : viewerTypeFilters) {
                    if (filter != null && !filter.select(comparisonEditor.getViewer(), input, exp)) {
                        filteredExpressions.remove(exp);
                    }
                }
            }
        }
    }

    addDependencyButton.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            SelectDependencyDialog dialog = new SelectDependencyDialog(Display.getDefault().getActiveShell(),
                    filteredExpressions,
                    ComparisonExpressionEditor.this.inputExpression.getReferencedElements());
            dialog.open();
        }
    });
}

From source file:org.bonitasoft.studio.connectors.ui.preferences.DBConnectorsPreferencePage.java

License:Open Source License

private void bindButtonWithViewer(Button button, TableViewer viewer) {
    UpdateValueStrategy modelToTarget = new UpdateValueStrategy();
    modelToTarget.setConverter(new Converter(Object.class, Boolean.class) {

        @Override/*from   w  ww . j  a va  2s  . c om*/
        public Object convert(Object fromObject) {
            if (fromObject != null) {
                return true;
            } else {
                return false;
            }
        }

    });
    context.bindValue(SWTObservables.observeEnabled(button), ViewersObservables.observeSingleSelection(viewer),
            null, modelToTarget);
}

From source file:org.bonitasoft.studio.connectors.ui.wizard.page.SelectDatabaseOutputTypeWizardPage.java

License:Open Source License

@Override
protected Control doCreateControl(Composite parent, EMFDataBindingContext context) {
    final Composite mainComposite = new Composite(parent, SWT.NONE);
    mainComposite.setLayout(GridLayoutFactory.fillDefaults().numColumns(1).margins(0, 0)
            .extendedMargins(10, 10, 5, 0).create());

    createSelectModeLabelControl(mainComposite);

    scriptExpression = (Expression) getConnectorParameter(getInput(SCRIPT_KEY)).getExpression();
    IObservableValue scriptContentValue = EMFObservables.observeValue(scriptExpression,
            ExpressionPackage.Literals.EXPRESSION__CONTENT);
    scriptContentValue.addValueChangeListener(this);
    outputTypeExpression = (Expression) getConnectorParameter(getInput(OUTPUT_TYPE_KEY)).getExpression();
    outputTypeExpression.setName(OUTPUT_TYPE_KEY);

    final Composite choicesComposite = createGraphicalModeControl(mainComposite, context);
    final Button singleModeRadio = createSingleChoice(choicesComposite, context);
    final Button oneRowModeRadio = createOneRowNColsChoice(choicesComposite, context);
    final Button nRowModeRadio = createNRowsOneColChoice(choicesComposite, context);
    final Button tableModeRadio = createTableChoice(choicesComposite, context);
    final Button scriptModeRadio = createScriptModeControl(mainComposite);

    final IObservableValue singleValue = SWTObservables.observeSelection(singleModeRadio);
    final IObservableValue oneRowValue = SWTObservables.observeSelection(oneRowModeRadio);
    final IObservableValue oneColValue = SWTObservables.observeSelection(nRowModeRadio);
    final IObservableValue tableValue = SWTObservables.observeSelection(tableModeRadio);
    scriptValue = SWTObservables.observeSelection(scriptModeRadio);
    graphicalModeSelectionValue = SWTObservables.observeSelection(gModeRadio);

    radioGroupObservable = new SelectObservableValue(String.class);
    radioGroupObservable.addOption(SINGLE, singleValue);
    radioGroupObservable.addOption(ONE_ROW, oneRowValue);
    radioGroupObservable.addOption(N_ROW, oneColValue);
    radioGroupObservable.addOption(TABLE, tableValue);
    radioGroupObservable.addOption(null, scriptValue);

    context.bindValue(SWTObservables.observeEnabled(alwaysUseScriptCheckbox), scriptValue);
    final UpdateValueStrategy deselectStrategy = new UpdateValueStrategy();
    deselectStrategy.setConverter(new Converter(Boolean.class, Boolean.class) {

        @Override//from w  w  w  .  j a v  a2s  .  c om
        public Object convert(Object fromObject) {
            return false;
        }
    });

    context.bindValue(graphicalModeSelectionValue, SWTObservables.observeSelection(alwaysUseScriptCheckbox),
            deselectStrategy, new UpdateValueStrategy(UpdateValueStrategy.POLICY_NEVER));
    context.bindValue(graphicalModeSelectionValue, SWTObservables.observeEnabled(choicesComposite));

    final UpdateValueStrategy disabledStrategy = new UpdateValueStrategy();
    disabledStrategy.setConverter(new Converter(Boolean.class, Boolean.class) {

        @Override
        public Object convert(Object fromObject) {
            if ((outputTypeExpression.getContent() == null && !(Boolean) fromObject)
                    || SQLQueryUtil.getSelectedColumns(scriptExpression).size() != 1
                            && !SQLQueryUtil.useWildcard(scriptExpression)) {
                return false;
            }
            return fromObject;
        }
    });

    final UpdateValueStrategy disabledStrategy2 = new UpdateValueStrategy();
    disabledStrategy2.setConverter(new Converter(Boolean.class, Boolean.class) {

        @Override
        public Object convert(Object fromObject) {
            if ((outputTypeExpression.getContent() == null && !(Boolean) fromObject)
                    || SQLQueryUtil.useWildcard(scriptExpression)) {
                return false;
            }
            return fromObject;
        }
    });

    radioGroupObservable.addValueChangeListener(new IValueChangeListener() {

        @Override
        public void handleValueChange(ValueChangeEvent event) {
            IWizardPage p = getNextPage();
            if (p instanceof DatabaseConnectorOutputWizardPage) {
                ((DatabaseConnectorOutputWizardPage) p)
                        .updateOutputs((String) event.getObservableValue().getValue());
            }
        }
    });

    context.bindValue(radioGroupObservable,
            EMFObservables.observeValue(outputTypeExpression, ExpressionPackage.Literals.EXPRESSION__CONTENT));
    graphicalModeSelectionValue.addValueChangeListener(new IValueChangeListener() {

        @Override
        public void handleValueChange(ValueChangeEvent event) {
            if ((Boolean) event.getObservableValue().getValue()) {
                if (singleModeRadio.getSelection()) {
                    radioGroupObservable.setValue(SINGLE);
                } else if (oneRowModeRadio.getSelection()) {
                    radioGroupObservable.setValue(ONE_ROW);
                } else if (nRowModeRadio.getSelection()) {
                    radioGroupObservable.setValue(N_ROW);
                } else {
                    radioGroupObservable.setValue(TABLE);
                }
                updateEnabledChoices();
            } else {
                singleModeRadioObserveEnabled.setValue(false);
                nRowsOneColModeRadioObserveEnabled.setValue(false);
                oneRowNColModeRadioObserveEnabled.setValue(false);
                tableObserveEnabled.setValue(false);
            }

        }
    });

    parseQuery();

    return mainComposite;
}

From source file:org.bonitasoft.studio.connectors.ui.wizard.page.SelectDatabaseOutputTypeWizardPage.java

License:Open Source License

protected void parseQuery() {
    if (graphicalModeSelectionValue != null) {
        IObservableValue enableGraphicalMode = SWTObservables.observeEnabled(gModeRadio);
        if (SQLQueryUtil.isGraphicalModeSupportedFor(scriptExpression)) {
            enableGraphicalMode.setValue(true);
            if (!editing) {
                graphicalModeSelectionValue.setValue(true);
                if (outputTypeExpression.getContent() != null) {
                    radioGroupObservable.setValue(outputTypeExpression.getContent());
                } else {
                    radioGroupObservable.setValue(TABLE);
                }// w ww. j a v a  2 s.  c o m
            } else if (outputTypeExpression.getContent() == null) {
                graphicalModeSelectionValue.setValue(false);
            }
            updateEnabledChoices();
        } else {
            enableGraphicalMode.setValue(false);
            graphicalModeSelectionValue.setValue(false);
            scriptValue.setValue(true);
            radioGroupObservable.setValue(null);
        }
    }
}

From source file:org.bonitasoft.studio.connectors.ui.wizard.page.SelectDatabaseOutputTypeWizardPage.java

License:Open Source License

protected void updateQuery() {
    if (graphicalModeSelectionValue != null) {
        IObservableValue enableGraphicalMode = SWTObservables.observeEnabled(gModeRadio);
        if (SQLQueryUtil.isGraphicalModeSupportedFor(scriptExpression)) {
            enableGraphicalMode.setValue(true);
            updateEnabledChoices();// ww w . j ava2s.com
        } else {
            enableGraphicalMode.setValue(false);
            graphicalModeSelectionValue.setValue(false);
            scriptValue.setValue(true);
            radioGroupObservable.setValue(null);
        }
    }
}

From source file:org.bonitasoft.studio.connectors.ui.wizard.page.SelectDatabaseOutputTypeWizardPage.java

License:Open Source License

protected Button createSingleChoice(final Composite choicesComposite, EMFDataBindingContext context) {
    final Button singleRadio = new Button(choicesComposite, SWT.RADIO);
    singleRadio.setLayoutData(GridDataFactory.fillDefaults().grab(false, false).create());
    singleRadio.setText(Messages.singleValue);

    final Label singleIcon = new Label(choicesComposite, SWT.NONE);
    singleIcon.setLayoutData(GridDataFactory.swtDefaults().align(SWT.BEGINNING, SWT.CENTER).indent(15, 0)
            .grab(true, false).create());

    final UpdateValueStrategy selectImageStrategy = new UpdateValueStrategy();
    selectImageStrategy.setConverter(new Converter(Boolean.class, Image.class) {

        @Override//from  w  w  w . j  av  a  2s  . c o  m
        public Object convert(Object fromObject) {
            if ((Boolean) fromObject) {
                return Pics.getImage("single_placeholder.png", ConnectorPlugin.getDefault());
            } else {
                return Pics.getImage("single_placeholder_disabled.png", ConnectorPlugin.getDefault());
            }

        }

    });
    singleModeRadioObserveEnabled = SWTObservables.observeEnabled(singleRadio);
    context.bindValue(SWTObservables.observeImage(singleIcon), singleModeRadioObserveEnabled, null,
            selectImageStrategy);

    return singleRadio;
}

From source file:org.bonitasoft.studio.connectors.ui.wizard.page.SelectDatabaseOutputTypeWizardPage.java

License:Open Source License

protected Button createOneRowNColsChoice(final Composite choicesComposite, EMFDataBindingContext context) {
    final Button oneRowRadio = new Button(choicesComposite, SWT.RADIO);
    oneRowRadio.setLayoutData(GridDataFactory.fillDefaults().grab(false, false).create());
    oneRowRadio.setText(Messages.oneRowNCol);

    final ControlDecoration oneRowDeco = new ControlDecoration(oneRowRadio, SWT.RIGHT);
    oneRowDeco.setImage(Pics.getImage(PicsConstants.hint));
    oneRowDeco.setDescriptionText(Messages.oneRowHint);

    final Label oneRowIcon = new Label(choicesComposite, SWT.NONE);
    oneRowIcon.setLayoutData(GridDataFactory.swtDefaults().align(SWT.BEGINNING, SWT.CENTER).indent(15, 0)
            .grab(true, false).create());

    final UpdateValueStrategy selectImageStrategy = new UpdateValueStrategy();
    selectImageStrategy.setConverter(new Converter(Boolean.class, Image.class) {

        @Override/*from   ww  w .  j a  v  a  2  s  .  co  m*/
        public Object convert(Object fromObject) {
            if ((Boolean) fromObject) {
                return Pics.getImage("row_placeholder.png", ConnectorPlugin.getDefault());
            } else {
                return Pics.getImage("row_placeholder_disabled.png", ConnectorPlugin.getDefault());
            }

        }

    });
    oneRowNColModeRadioObserveEnabled = SWTObservables.observeEnabled(oneRowRadio);
    context.bindValue(SWTObservables.observeImage(oneRowIcon), oneRowNColModeRadioObserveEnabled, null,
            selectImageStrategy);

    return oneRowRadio;
}

From source file:org.bonitasoft.studio.connectors.ui.wizard.page.SelectDatabaseOutputTypeWizardPage.java

License:Open Source License

protected Button createNRowsOneColChoice(final Composite choicesComposite, EMFDataBindingContext context) {
    final Button oneColRadio = new Button(choicesComposite, SWT.RADIO);
    oneColRadio.setLayoutData(GridDataFactory.fillDefaults().grab(false, false).create());
    oneColRadio.setText(Messages.nRowOneCol);

    final ControlDecoration oneColDeco = new ControlDecoration(oneColRadio, SWT.RIGHT);
    oneColDeco.setImage(Pics.getImage(PicsConstants.hint));
    oneColDeco.setDescriptionText(Messages.oneColHint);

    final Label oneColIcon = new Label(choicesComposite, SWT.NONE);
    oneColIcon.setLayoutData(GridDataFactory.swtDefaults().align(SWT.BEGINNING, SWT.CENTER).indent(15, 0)
            .grab(true, false).create());

    final UpdateValueStrategy selectImageStrategy = new UpdateValueStrategy();
    selectImageStrategy.setConverter(new Converter(Boolean.class, Image.class) {

        @Override//from   w  ww .  ja va2  s  .  c om
        public Object convert(Object fromObject) {
            if ((Boolean) fromObject) {
                return Pics.getImage("column_placeholder.png", ConnectorPlugin.getDefault());
            } else {
                return Pics.getImage("column_placeholder_disabled.png", ConnectorPlugin.getDefault());
            }

        }

    });

    nRowsOneColModeRadioObserveEnabled = SWTObservables.observeEnabled(oneColRadio);
    context.bindValue(SWTObservables.observeImage(oneColIcon), nRowsOneColModeRadioObserveEnabled, null,
            selectImageStrategy);

    return oneColRadio;

}

From source file:org.bonitasoft.studio.connectors.ui.wizard.page.SelectDatabaseOutputTypeWizardPage.java

License:Open Source License

protected Button createTableChoice(final Composite choicesComposite, EMFDataBindingContext context) {
    final Button tableRadio = new Button(choicesComposite, SWT.RADIO);
    tableRadio.setLayoutData(GridDataFactory.fillDefaults().grab(false, false).create());
    tableRadio.setText(Messages.nRowsNcolumns);

    final ControlDecoration tableDeco = new ControlDecoration(tableRadio, SWT.RIGHT);
    tableDeco.setImage(Pics.getImage(PicsConstants.hint));
    tableDeco.setDescriptionText(Messages.tableHint);

    final Label tableIcon = new Label(choicesComposite, SWT.NONE);
    tableIcon.setLayoutData(GridDataFactory.swtDefaults().align(SWT.BEGINNING, SWT.CENTER).indent(15, 0)
            .grab(true, false).create());

    final UpdateValueStrategy selectImageStrategy = new UpdateValueStrategy();
    selectImageStrategy.setConverter(new Converter(Boolean.class, Image.class) {

        @Override//from  w w  w.  j a v  a 2 s .  co  m
        public Object convert(Object fromObject) {
            if ((Boolean) fromObject) {
                return Pics.getImage("table_placeholder.png", ConnectorPlugin.getDefault());
            } else {
                return Pics.getImage("table_placeholder_disabled.png", ConnectorPlugin.getDefault());
            }

        }

    });
    tableObserveEnabled = SWTObservables.observeEnabled(tableRadio);
    context.bindValue(SWTObservables.observeImage(tableIcon), tableObserveEnabled, null, selectImageStrategy);

    return tableRadio;
}

From source file:org.bonitasoft.studio.connectors.ui.wizard.page.SelectEventConnectorNameAndDescWizardPage.java

License:Open Source License

protected void createConnectorFailsControls(Composite composite, EMFDataBindingContext context) {
    Label connectorFailsLabel = new Label(composite, SWT.NONE);
    connectorFailsLabel.setText(Messages.connectorCrashLabel);
    connectorFailsLabel.setLayoutData(GridDataFactory.fillDefaults().align(SWT.END, SWT.CENTER).create());

    if (connector.eContainingFeature() == ProcessPackage.Literals.PAGE_FLOW__PAGE_FLOW_CONNECTORS
            || container instanceof Form || container instanceof SubmitFormButton) {

        Label connectorFailText = new Label(composite, SWT.NONE);
        connectorFailText.setText(Messages.connectorFails_throwException);
        connectorFailText//w w w .j av  a 2s.c  om
                .setLayoutData(GridDataFactory.fillDefaults().align(SWT.BEGINNING, SWT.CENTER).create());

        connector.setThrowErrorEvent(false);
        connector.setIgnoreErrors(false);
        connector.setNamedError("");

    } else {

        final Combo connectorFailsCombo = new Combo(composite, SWT.READ_ONLY);
        connectorFailsCombo.add(Messages.connectorFails_crash);
        connectorFailsCombo.add(Messages.connectorFails_ignore);

        // Throw Event are not allowed in Connector in forms
        if (!(container instanceof Form || container instanceof SubmitFormButton)) {
            connectorFailsCombo.add(Messages.connectorFails_throwEvent);
        }

        UpdateValueStrategy ignoreEventStrategyTarget = new UpdateValueStrategy();
        ignoreEventStrategyTarget.setConverter(new Converter(String.class, Boolean.class) {

            @Override
            public Object convert(Object from) {
                if (from != null) {
                    return from.toString().equals(Messages.connectorFails_ignore);
                }
                return Boolean.FALSE;
            }
        });
        UpdateValueStrategy ignoreEventStrategyModel = new UpdateValueStrategy();
        ignoreEventStrategyModel.setConverter(new Converter(Boolean.class, String.class) {

            @Override
            public Object convert(Object from) {
                if ((Boolean) from) {
                    return Messages.connectorFails_ignore;
                } else if (connector.isThrowErrorEvent()) {
                    return Messages.connectorFails_throwEvent;
                }
                return Messages.connectorFails_crash;
            }
        });

        context.bindValue(WidgetProperties.text().observe(connectorFailsCombo),
                EMFObservables.observeValue(connector, ProcessPackage.Literals.CONNECTOR__IGNORE_ERRORS),
                ignoreEventStrategyTarget, ignoreEventStrategyModel);

        UpdateValueStrategy throwEventStrategyTarget = new UpdateValueStrategy();
        throwEventStrategyTarget.setConverter(new Converter(String.class, Boolean.class) {

            @Override
            public Object convert(Object from) {
                if (from != null) {
                    return from.toString().equals(Messages.connectorFails_throwEvent);
                }
                return Boolean.FALSE;
            }
        });

        UpdateValueStrategy throwEventStrategyModel = new UpdateValueStrategy();
        throwEventStrategyModel.setConverter(new Converter(Boolean.class, String.class) {

            @Override
            public Object convert(Object from) {
                if ((Boolean) from) {
                    return Messages.connectorFails_throwEvent;
                } else if (connector.isIgnoreErrors()) {
                    return Messages.connectorFails_ignore;
                }
                return Messages.connectorFails_crash;
            }
        });
        context.bindValue(WidgetProperties.text().observe(connectorFailsCombo),
                EMFObservables.observeValue(connector, ProcessPackage.Literals.CONNECTOR__THROW_ERROR_EVENT),
                throwEventStrategyTarget, throwEventStrategyModel);

        Label namedErrorEvent = new Label(composite, SWT.NONE);
        namedErrorEvent.setText(Messages.connectorFails_namedError);
        namedErrorEvent.setLayoutData(GridDataFactory.fillDefaults().align(SWT.END, SWT.CENTER).create());

        final Text namedErrorText = new Text(composite, SWT.BORDER);
        namedErrorText.setTextLimit(255);
        namedErrorText.setLayoutData(GridDataFactory.fillDefaults().grab(true, false).create());

        UpdateValueStrategy enableNamedErrorStrategyTarget = new UpdateValueStrategy();
        enableNamedErrorStrategyTarget.setConverter(new Converter(String.class, Boolean.class) {

            @Override
            public Object convert(Object from) {
                if (from != null) {
                    return from.toString().equals(Messages.connectorFails_throwEvent);
                }
                return Boolean.FALSE;
            }
        });

        context.bindValue(SWTObservables.observeText(namedErrorText, SWT.Modify),
                EMFObservables.observeValue(connector, ProcessPackage.Literals.CONNECTOR__NAMED_ERROR));
        namedErrorText.setEnabled(connector.isThrowErrorEvent());
        context.bindValue(WidgetProperties.text().observe(connectorFailsCombo),
                SWTObservables.observeEnabled(namedErrorText), enableNamedErrorStrategyTarget,
                new UpdateValueStrategy(UpdateValueStrategy.POLICY_NEVER));

    }
}