Example usage for org.eclipse.jface.databinding.viewers ViewerProperties singleSelection

List of usage examples for org.eclipse.jface.databinding.viewers ViewerProperties singleSelection

Introduction

In this page you can find the example usage for org.eclipse.jface.databinding.viewers ViewerProperties singleSelection.

Prototype

public static IViewerValueProperty singleSelection() 

Source Link

Document

Returns a value property for observing the single selection of a ISelectionProvider .

Usage

From source file:org.bonitasoft.studio.properties.form.sections.general.contributions.DisplayLabelGridPropertySectionContribution.java

License:Open Source License

public void createControl(Composite composite, TabbedPropertySheetWidgetFactory widgetFactory,
        ExtensibleGridPropertySection extensibleGridPropertySection) {
    //      composite.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, true, false,2,1));
    composite.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, true, false));
    composite.setLayout(new GridLayout(1, false));

    if (dataBindingContext != null) {
        dataBindingContext.dispose();/*from   w  w  w .  j a v a 2 s .c o  m*/
    }
    dataBindingContext = new EMFDataBindingContext();
    ExpressionViewer displayLabelViewer = new ExpressionViewer(composite, SWT.BORDER, widgetFactory,
            editingDomain, FormPackage.Literals.WIDGET__DISPLAY_LABEL);
    displayLabelViewer.getControl()
            .setLayoutData(GridDataFactory.fillDefaults().grab(true, false).hint(300, SWT.DEFAULT).create());
    Expression displayLabelExpression = element.getDisplayLabel();
    if (displayLabelExpression == null) {
        displayLabelExpression = ExpressionFactory.eINSTANCE.createExpression();
        editingDomain.getCommandStack().execute(SetCommand.create(editingDomain, element,
                FormPackage.Literals.WIDGET__DISPLAY_LABEL, displayLabelExpression));
    }

    displayLabelViewer.setInput(element);
    dataBindingContext.bindValue(ViewerProperties.singleSelection().observe(displayLabelViewer),
            EMFEditProperties.value(editingDomain, FormPackage.Literals.WIDGET__DISPLAY_LABEL)
                    .observe(element));

}

From source file:org.bonitasoft.studio.properties.form.sections.general.contributions.ShowLabelGridPropertySectionContribution.java

License:Open Source License

public void createControl(Composite composite, TabbedPropertySheetWidgetFactory widgetFactory,
        ExtensibleGridPropertySection extensibleGridPropertySection) {

    composite.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, true, false));
    composite.setLayout(new GridLayout(3, false));
    if (dataBindingContext != null) {
        dataBindingContext.dispose();//  www  .ja  v  a 2  s. com
    }
    dataBindingContext = new EMFDataBindingContext();
    Button enableLabel = null;

    if (!(element instanceof FormButton)) {
        /* Create the checkbox to hide/show the label */
        enableLabel = widgetFactory.createButton(composite, "", SWT.CHECK); //$NON-NLS-1$
        enableLabel.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false));
        enableLabel.setToolTipText(Messages.GeneralSection_EnableLabel_tooltip);
        dataBindingContext.bindValue(SWTObservables.observeSelection(enableLabel), EMFEditObservables
                .observeValue(editingDomain, element, FormPackage.Literals.WIDGET__SHOW_DISPLAY_LABEL));
    }

    ExpressionViewer displayLabelViewer = new ExpressionViewer(composite, SWT.BORDER, widgetFactory,
            editingDomain, FormPackage.Literals.WIDGET__DISPLAY_LABEL);
    displayLabelViewer.addFilter(new AvailableExpressionTypeFilter(new String[] {
            ExpressionConstants.CONSTANT_TYPE, ExpressionConstants.I18N_TYPE, ExpressionConstants.SCRIPT_TYPE,
            ExpressionConstants.PARAMETER_TYPE, ExpressionConstants.VARIABLE_TYPE }));
    Expression displayLabelExpression = element.getDisplayLabel();
    if (displayLabelExpression == null) {
        displayLabelExpression = ExpressionFactory.eINSTANCE.createExpression();
        editingDomain.getCommandStack().execute(SetCommand.create(editingDomain, element,
                FormPackage.Literals.WIDGET__DISPLAY_LABEL, displayLabelExpression));
    }

    // add validator on the show label field when it is a form button - expression can't be empty
    if (element instanceof FormButton) {
        displayLabelViewer.addExpressionValidator(ExpressionConstants.CONSTANT_TYPE,
                new ExpressionNotEmptyValidator());
    }

    displayLabelViewer.getControl()
            .setLayoutData(GridDataFactory.fillDefaults().grab(true, false).hint(300, SWT.DEFAULT).create());

    displayLabelViewer.setInput(element);
    dataBindingContext.bindValue(ViewerProperties.singleSelection().observe(displayLabelViewer),
            EMFEditProperties.value(editingDomain, FormPackage.Literals.WIDGET__DISPLAY_LABEL)
                    .observe(element));

    if (!(element instanceof FormButton)) {

        /* Create the chekbox to allow HTML for the label or not */
        Button allowHtmlButton = widgetFactory.createButton(composite, Messages.GeneralSection_allowHTML,
                SWT.CHECK);
        dataBindingContext.bindValue(SWTObservables.observeSelection(allowHtmlButton),
                EMFEditObservables.observeValue(editingDomain, element,
                        FormPackage.Literals.WIDGET__ALLOW_HTML_FOR_DISPLAY_LABEL));
        dataBindingContext.bindValue(SWTObservables.observeEnabled(allowHtmlButton),
                SWTObservables.observeSelection(enableLabel));

        /* Enable/disable the combo for the text and the allow html */
        dataBindingContext.bindValue(SWTObservables.observeEnabled(displayLabelViewer.getControl()),
                SWTObservables.observeSelection(enableLabel));
        dataBindingContext.bindValue(SWTObservables.observeEnabled(displayLabelViewer.getTextControl()),
                SWTObservables.observeSelection(enableLabel));
        dataBindingContext.bindValue(SWTObservables.observeEnabled(displayLabelViewer.getButtonControl()),
                SWTObservables.observeSelection(enableLabel));
    }
}

From source file:org.bonitasoft.studio.properties.form.sections.general.contributions.ShowPageLabelContribution.java

License:Open Source License

public void createControl(Composite composite, TabbedPropertySheetWidgetFactory widgetFactory,
        ExtensibleGridPropertySection extensibleGridPropertySection) {
    //      composite.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, true, false,2,1));
    composite.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, true, false));
    composite.setLayout(new GridLayout(3, false));
    if (dataBindingContext != null) {
        dataBindingContext.dispose();/*from   w w w . j  a va2 s. c o  m*/
    }
    dataBindingContext = new EMFDataBindingContext();

    Button enableLabel = widgetFactory.createButton(composite, "", SWT.CHECK); //$NON-NLS-1$
    enableLabel.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false));
    enableLabel.setToolTipText(Messages.GeneralSection_EnableLabel_tooltip);
    dataBindingContext.bindValue(SWTObservables.observeSelection(enableLabel), EMFEditObservables
            .observeValue(editingDomain, element, FormPackage.Literals.FORM__SHOW_PAGE_LABEL));

    enableLabel.setSelection(element.getShowPageLabel() == null || element.getShowPageLabel());

    GridData gData = new GridData(SWT.BEGINNING, SWT.CENTER, false, false);
    gData.widthHint = 250;

    ExpressionViewer pageLabelExpresssionViewer = new ExpressionViewer(composite, SWT.BORDER, widgetFactory,
            FormPackage.Literals.FORM__PAGE_LABEL);
    final Expression pageLabel = element.getPageLabel();
    if (pageLabel == null) {
        editingDomain.getCommandStack().execute(SetCommand.create(editingDomain, element,
                FormPackage.Literals.FORM__PAGE_LABEL, ExpressionFactory.eINSTANCE.createExpression()));
    }
    if (ModelHelper.isAnEntryPageFlowOnAPool(element)) {
        pageLabelExpresssionViewer
                .addFilter(new AvailableExpressionTypeFilter(new String[] { ExpressionConstants.CONSTANT_TYPE,
                        ExpressionConstants.PARAMETER_TYPE, ExpressionConstants.SCRIPT_TYPE }));
    }

    pageLabelExpresssionViewer.setInput(element);
    dataBindingContext.bindValue(ViewerProperties.singleSelection().observe(pageLabelExpresssionViewer),
            EMFEditProperties.value(editingDomain, FormPackage.Literals.FORM__PAGE_LABEL).observe(element));

    pageLabelExpresssionViewer.setMessage(Messages.GeneralSection_EnablePageLabel_tooltip, IStatus.INFO);
    pageLabelExpresssionViewer.getControl().setLayoutData(gData);

    Button allowHTMLButton = widgetFactory.createButton(composite, Messages.GeneralSection_allowHTML,
            SWT.CHECK);
    dataBindingContext.bindValue(SWTObservables.observeSelection(allowHTMLButton), EMFEditObservables
            .observeValue(editingDomain, element, FormPackage.Literals.FORM__ALLOW_HTML_IN_PAGE_LABEL));

    /*Enable/disable the combo for the text and the allow html*/
    dataBindingContext.bindValue(SWTObservables.observeEnabled(pageLabelExpresssionViewer.getControl()),
            SWTObservables.observeSelection(enableLabel));
    dataBindingContext.bindValue(SWTObservables.observeEnabled(allowHTMLButton),
            SWTObservables.observeSelection(enableLabel));
}

From source file:org.bonitasoft.studio.properties.form.sections.options.contributions.InjectWidgetContribution.java

License:Open Source License

public void createControl(Composite composite, TabbedPropertySheetWidgetFactory widgetFactory,
        ExtensibleGridPropertySection extensibleGridPropertySection) {
    composite.setLayout(new GridLayout(2, false));
    composite.setLayoutData(GridDataFactory.fillDefaults().grab(true, false).create());
    checkbox = widgetFactory.createButton(composite, "", SWT.CHECK);
    expressionViewer = new ExpressionViewer(composite, SWT.BORDER, widgetFactory, editingDomain,
            FormPackage.Literals.WIDGET__INJECT_WIDGET_SCRIPT);
    expressionViewer.getControl().setLayoutData(GridDataFactory.fillDefaults().grab(true, false).create());
    expressionViewer.addFilter(new AvailableExpressionTypeFilter(
            new String[] { ExpressionConstants.PARAMETER_TYPE, ExpressionConstants.VARIABLE_TYPE,
                    ExpressionConstants.SCRIPT_TYPE, ExpressionConstants.CONSTANT_TYPE,
                    ExpressionConstants.FORM_FIELD_TYPE, ExpressionConstants.DOCUMENT_TYPE }));
    //bind/*w  w  w .ja v a  2 s . c  o m*/
    if (context != null) {
        context.dispose();
    }
    if (expressionViewer != null && !expressionViewer.getControl().isDisposed()) {
        context = new EMFDataBindingContext();
        expressionViewer.setInput(getEObject());
        context.bindValue(ViewerProperties.singleSelection().observe(expressionViewer), EMFEditProperties
                .value(editingDomain, FormPackage.Literals.WIDGET__INJECT_WIDGET_SCRIPT).observe(getEObject()));

        context.bindValue(widgetValuePropertySelection.observe(checkbox),
                EMFEditProperties.value(editingDomain, FormPackage.Literals.WIDGET__INJECT_WIDGET_CONDITION)
                        .observe(getEObject()));
        context.bindValue(WidgetProperties.enabled().observe(expressionViewer.getControl()),
                EMFEditProperties.value(editingDomain, FormPackage.Literals.WIDGET__INJECT_WIDGET_CONDITION)
                        .observe(getEObject()),
                never, null);
        context.bindValue(WidgetProperties.enabled().observe(expressionViewer.getTextControl()),
                EMFEditProperties.value(editingDomain, FormPackage.Literals.WIDGET__INJECT_WIDGET_CONDITION)
                        .observe(getEObject()),
                never, null);
        context.bindValue(WidgetProperties.enabled().observe(expressionViewer.getButtonControl()),
                EMFEditProperties.value(editingDomain, FormPackage.Literals.WIDGET__INJECT_WIDGET_CONDITION)
                        .observe(getEObject()),
                never, null);
    }
}

From source file:org.bonitasoft.studio.properties.form.sections.useraids.contributions.ExamplePropertySectionContribution.java

License:Open Source License

public void createControl(Composite composite, TabbedPropertySheetWidgetFactory widgetFactory,
        ExtensibleGridPropertySection extensibleGridPropertySection) {
    composite.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
    composite.setLayout(GridLayoutFactory.fillDefaults().numColumns(2).margins(20, 0).create());
    if (dataBindingContext != null) {
        dataBindingContext.dispose();/*  ww  w. java 2s  .co  m*/
    }

    dataBindingContext = new EMFDataBindingContext();
    ExpressionViewer exampleMessageViewer = new ExpressionViewer(composite, SWT.BORDER, widgetFactory,
            editingDomain, FormPackage.Literals.FORM_FIELD__EXAMPLE_MESSAGE);
    exampleMessageViewer.getControl().setLayoutData(GridDataFactory.fillDefaults().grab(true, false).create());
    Expression exampleMessageExpression = element.getExampleMessage();
    if (exampleMessageExpression == null) {
        exampleMessageExpression = ExpressionFactory.eINSTANCE.createExpression();
        editingDomain.getCommandStack().execute(SetCommand.create(editingDomain, element,
                FormPackage.Literals.FORM_FIELD__EXAMPLE_MESSAGE, exampleMessageExpression));
    }
    exampleMessageViewer.setMessage(Messages.UserAidsSection_Example_Tooltip, IStatus.INFO);
    dataBindingContext.bindValue(ViewerProperties.singleSelection().observe(exampleMessageViewer),
            EMFEditProperties.value(editingDomain, FormPackage.Literals.FORM_FIELD__EXAMPLE_MESSAGE)
                    .observe(element));

    exampleMessageViewer.addFilter(new AvailableExpressionTypeFilter(
            new String[] { ExpressionConstants.CONSTANT_TYPE, ExpressionConstants.VARIABLE_TYPE,
                    ExpressionConstants.PARAMETER_TYPE, ExpressionConstants.SCRIPT_TYPE }));

    exampleMessageViewer.setInput(element);

    ComboViewer positionViewer = new ComboViewer(composite);
    positionViewer.setContentProvider(new ArrayContentProvider());
    positionViewer.setLabelProvider(new LabelPositionLabelProvider());
    positionViewer.setInput(new LabelPosition[] { LabelPosition.DOWN, LabelPosition.UP });
    dataBindingContext.bindValue(ViewersObservables.observeSingleSelection(positionViewer), EMFEditObservables
            .observeValue(editingDomain, element, FormPackage.Literals.FORM_FIELD__EXAMPLE_MESSAGE_POSITION));
}

From source file:org.bonitasoft.studio.properties.form.sections.useraids.contributions.HintGridPropertySectionContribution.java

License:Open Source License

public void createControl(Composite composite, TabbedPropertySheetWidgetFactory widgetFactory,
        ExtensibleGridPropertySection extensibleGridPropertySection) {
    composite.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
    composite.setLayout(GridLayoutFactory.fillDefaults().numColumns(1).margins(20, 0).create());
    if (dataBindingContext != null) {
        dataBindingContext.dispose();//from   w  w w .  j  a v a2s .c o  m
    }
    dataBindingContext = new EMFDataBindingContext();
    ExpressionViewer hintViewer = new ExpressionViewer(composite, SWT.BORDER, widgetFactory, editingDomain,
            FormPackage.Literals.WIDGET__HELP_MESSAGE);
    hintViewer.getControl().setLayoutData(GridDataFactory.fillDefaults().grab(true, false).create());
    Expression hintExpression = element.getHelpMessage();
    if (hintExpression == null) {
        hintExpression = ExpressionFactory.eINSTANCE.createExpression();
        editingDomain.getCommandStack().execute(SetCommand.create(editingDomain, element,
                FormPackage.Literals.WIDGET__HELP_MESSAGE, hintExpression));
    }
    dataBindingContext.bindValue(ViewerProperties.singleSelection().observe(hintViewer),
            EMFEditProperties.value(editingDomain, FormPackage.Literals.WIDGET__HELP_MESSAGE).observe(element));

    hintViewer.addFilter(new AvailableExpressionTypeFilter(
            new String[] { ExpressionConstants.CONSTANT_TYPE, ExpressionConstants.VARIABLE_TYPE,
                    ExpressionConstants.PARAMETER_TYPE, ExpressionConstants.SCRIPT_TYPE }));

    hintViewer.setInput(element);
    hintViewer.setMessage(Messages.UserAidsSection_Hint_tooltip, IStatus.INFO);

}

From source file:org.bonitasoft.studio.properties.form.sections.useraids.contributions.TooltipGridPropertySectionContribution.java

License:Open Source License

public void createControl(Composite composite, TabbedPropertySheetWidgetFactory widgetFactory,
        ExtensibleGridPropertySection extensibleGridPropertySection) {
    composite.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
    composite.setLayout(GridLayoutFactory.fillDefaults().numColumns(1).margins(20, 0).create());
    if (dataBindingContext != null) {
        dataBindingContext.dispose();//from ww w.j  a v a2  s.c  o  m
    }
    dataBindingContext = new EMFDataBindingContext();
    ExpressionViewer tooltipViewer = new ExpressionViewer(composite, SWT.BORDER, widgetFactory, editingDomain,
            FormPackage.Literals.WIDGET__TOOLTIP);
    tooltipViewer.getControl().setLayoutData(GridDataFactory.fillDefaults().grab(true, false).create());
    Expression tooltipexpression = element.getTooltip();
    if (tooltipexpression == null) {
        tooltipexpression = ExpressionFactory.eINSTANCE.createExpression();
        editingDomain.getCommandStack().execute(SetCommand.create(editingDomain, element,
                FormPackage.Literals.WIDGET__TOOLTIP, tooltipexpression));
    }
    dataBindingContext.bindValue(ViewerProperties.singleSelection().observe(tooltipViewer),
            EMFEditProperties.value(editingDomain, FormPackage.Literals.WIDGET__TOOLTIP).observe(element));

    tooltipViewer.addFilter(new AvailableExpressionTypeFilter(
            new String[] { ExpressionConstants.CONSTANT_TYPE, ExpressionConstants.VARIABLE_TYPE,
                    ExpressionConstants.PARAMETER_TYPE, ExpressionConstants.SCRIPT_TYPE }));

    tooltipViewer.setInput(element);
    tooltipViewer.setMessage(Messages.UserAidsSection_Tooltip_tooltip, IStatus.INFO);
}

From source file:org.bonitasoft.studio.properties.sections.document.DocumentPropertySection.java

License:Open Source License

protected void bindDetails(final IObservableValue documentSelected) {
    if (nameBinding != null) {
        nameBinding.dispose();/* w w  w.j  a  va  2s.  c  o  m*/
    }
    if (decorationSupport != null) {
        decorationSupport.dispose();
    }
    IObservableValue externalUrlObserved = EMFEditProperties
            .value(getEditingDomain(), ProcessPackage.Literals.DOCUMENT__URL).observeDetail(documentSelected);
    emfDataBindingContext.bindValue(ViewerProperties.singleSelection().observe(documentUrlViewer),
            externalUrlObserved);
    documentUrlViewer.setInput(documentSelected);

    IObservableValue mimeTypeObserved = EMFEditProperties
            .value(getEditingDomain(), ProcessPackage.Literals.DOCUMENT__MIME_TYPE)
            .observeDetail(documentSelected);
    emfDataBindingContext.bindValue(ViewerProperties.singleSelection().observe(documentMimeTypeViewer),
            mimeTypeObserved);
    documentMimeTypeViewer.setInput(documentSelected);

    final UpdateValueStrategy targetToModel = new UpdateValueStrategy();

    targetToModel.setAfterGetValidator(new InputLengthValidator(Messages.name, 50));
    targetToModel.setBeforeSetValidator(new DocumentNameValidator(documentListViewer));

    final IObservableValue nameObserved = EMFEditProperties
            .value(getEditingDomain(), ProcessPackage.Literals.ELEMENT__NAME).observeDetail(documentSelected);

    nameBinding = emfDataBindingContext.bindValue(
            SWTObservables.observeDelayedValue(500, SWTObservables.observeText(documentNameText, SWT.Modify)),
            nameObserved, targetToModel, null);

    decorationSupport = ControlDecorationSupport.create(nameBinding, SWT.LEFT);

    nameObserved.addValueChangeListener(new IValueChangeListener() {
        @Override
        public void handleValueChange(ValueChangeEvent event) {
            if (documentListViewer != null && !documentListViewer.getList().isDisposed()) {
                documentListViewer.refresh();
            }
        }
    });

    IObservableValue descriptionObserved = EMFEditProperties
            .value(getEditingDomain(), ProcessPackage.Literals.ELEMENT__DOCUMENTATION)
            .observeDetail(documentSelected);
    emfDataBindingContext.bindValue(SWTObservables.observeDelayedValue(500,
            SWTObservables.observeText(documentDescriptionText, SWT.Modify)), descriptionObserved);

    IObservableValue internalTypeObserved = EMFEditProperties
            .value(getEditingDomain(), ProcessPackage.Literals.DOCUMENT__IS_INTERNAL)
            .observeDetail(documentSelected);
    emfDataBindingContext.bindValue(SWTObservables.observeSelection(internalCheckbox), internalTypeObserved);

    IObservableValue documentInternalIDObserved = EMFEditProperties
            .value(getEditingDomain(), ProcessPackage.Literals.DOCUMENT__DEFAULT_VALUE_ID_OF_DOCUMENT_STORE)
            .observeDetail(documentSelected);
    emfDataBindingContext.bindValue(
            SWTObservables.observeDelayedValue(500, SWTObservables.observeText(documentTextId, SWT.Modify)),
            documentInternalIDObserved);

    IObservableValue externalTypeObserved = EMFEditProperties
            .value(getEditingDomain(), ProcessPackage.Literals.DOCUMENT__IS_INTERNAL)
            .observeDetail(documentSelected);
    emfDataBindingContext.bindValue(SWTObservables.observeSelection(externalCheckbox), externalTypeObserved,
            new UpdateValueStrategy() {
                @Override
                public Object convert(Object value) {
                    return super.convert(!(Boolean) value);
                }
            }, new UpdateValueStrategy() {
                @Override
                public Object convert(Object value) {
                    return super.convert(!(Boolean) value);
                }
            });

    emfDataBindingContext.bindValue(SWTObservables.observeEnabled(documentUrlViewer.getTextControl()),
            externalTypeObserved, new UpdateValueStrategy() {
                @Override
                public Object convert(Object value) {
                    return super.convert(!(Boolean) value);
                }
            }, new UpdateValueStrategy() {
                @Override
                public Object convert(Object value) {
                    return super.convert(!(Boolean) value);
                }
            });
    emfDataBindingContext.bindValue(SWTObservables.observeEnabled(documentUrlViewer.getButtonControl()),
            externalTypeObserved, new UpdateValueStrategy() {
                @Override
                public Object convert(Object value) {
                    return super.convert(!(Boolean) value);
                }
            }, new UpdateValueStrategy() {
                @Override
                public Object convert(Object value) {
                    return super.convert(!(Boolean) value);
                }
            });

    emfDataBindingContext.bindValue(SWTObservables.observeEnabled(documentTextId), internalTypeObserved);
    emfDataBindingContext.bindValue(SWTObservables.observeEnabled(browseButton), internalTypeObserved);
}

From source file:org.bonitasoft.studio.properties.sections.forms.ConfirmationPropertySection.java

License:Open Source License

@Override
public void setInput(IWorkbenchPart part, ISelection selection) {
    super.setInput(part, selection);
    PageFlow tempPageFlow = null;//www.jav a  2  s .c o m
    if (getEObject() instanceof Lane) {
        tempPageFlow = (PageFlow) getEObject().eContainer();
    }
    if (getEObject() instanceof PageFlow) {
        tempPageFlow = (PageFlow) getEObject();
    }
    if (tempPageFlow != null/* && lastEObject != tempPageFlow */) {
        // lastEObject = tempPageFlow;
        pageFlow = tempPageFlow;
    }
    if (context != null) {
        context.dispose();
    }

    confirmationPath.removeSelectionListener(widgetClickedListener);
    AssociatedFile confTemplate = getPageFlow().getConfirmationTemplate();
    confirmationPath.setText(confTemplate != null ? confTemplate.getPath() : ""); //$NON-NLS-1$
    confirmationPath.addSelectionListener(widgetClickedListener);

    context = new EMFDataBindingContext();
    Expression confirmationMessageExpression = getPageFlow().getConfirmationMessage();
    if (confirmationMessageExpression == null) {
        confirmationMessageExpression = ExpressionFactory.eINSTANCE.createExpression();
        getEditingDomain().getCommandStack().execute(SetCommand.create(getEditingDomain(), getPageFlow(),
                ProcessPackage.Literals.PAGE_FLOW__CONFIRMATION_MESSAGE, confirmationMessageExpression));
    }
    context.bindValue(ViewerProperties.singleSelection().observe(confirmationMessage),
            EMFEditProperties.value(getEditingDomain(), ProcessPackage.Literals.PAGE_FLOW__CONFIRMATION_MESSAGE)
                    .observe(pageFlow));
    confirmationMessage.setInput(pageFlow);
    refreshConfirmationEnablement();
}

From source file:org.bonitasoft.studio.properties.sections.general.TransitionCondition.java

License:Open Source License

private void refreshBindings() {
    if (conditionSection != null && !conditionSection.isDisposed()) {
        if (dataBindingContext != null) {
            dataBindingContext.dispose();
        }// w ww.  j  a v  a 2  s  .co m

        IConverter conditionConverter = new Converter(Boolean.class, Boolean.class) {

            @Override
            public Object convert(Object fromObject) {
                if (transition != null && transition.getSource() instanceof CatchLinkEvent) {
                    return false;
                }

                return !(Boolean) fromObject;
            }
        };

        IConverter defaultConverter = new Converter(Boolean.class, Boolean.class) {

            @Override
            public Object convert(Object fromObject) {
                if (transition != null && transition.getSource() instanceof CatchLinkEvent) {
                    return false;
                } else {
                    SourceElement elem = transition.getSource();
                    boolean alreadyExistDefault = false;
                    for (Connection c : elem.getOutgoing()) {
                        if (c instanceof SequenceFlow) {
                            if (((SequenceFlow) c).isIsDefault() && !c.equals(transition)) {
                                alreadyExistDefault = true;
                            }
                        }
                    }
                    if (alreadyExistDefault) {
                        return false;
                    } else {
                        return true;
                    }
                }

            }
        };

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

            @Override
            public Object convert(Object fromObject) {
                if ((Boolean) fromObject) {
                    return SequenceFlowConditionType.EXPRESSION;
                } else {
                    return SequenceFlowConditionType.DECISION_TABLE;
                }
            }
        });

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

            @Override
            public Object convert(Object fromObject) {
                if ((Boolean) fromObject) {
                    return SequenceFlowConditionType.DECISION_TABLE;
                } else {
                    return SequenceFlowConditionType.EXPRESSION;
                }
            }
        });

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

            @Override
            public Object convert(Object fromObject) {
                if (fromObject == SequenceFlowConditionType.EXPRESSION) {
                    return true;
                } else {
                    return false;
                }
            }
        });

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

            @Override
            public Object convert(Object fromObject) {
                if (fromObject == SequenceFlowConditionType.DECISION_TABLE) {
                    return true;
                } else {
                    return false;
                }
            }
        });

        dataBindingContext = new EMFDataBindingContext();

        IObservableValue typeValue = EMFEditObservables.observeValue(editingDomain, transition,
                ProcessPackage.Literals.SEQUENCE_FLOW__CONDITION_TYPE);
        typeValue.addValueChangeListener(new IValueChangeListener() {

            @Override
            public void handleValueChange(ValueChangeEvent event) {
                if (conditionSection != null && !conditionSection.isDisposed()) {
                    if (event.diff.getNewValue() == SequenceFlowConditionType.EXPRESSION
                            && (conditionViewer == null || conditionViewer.getControl().isDisposed())) {
                        if (conditionSection.getClient() != null) {
                            conditionSection.getClient().dispose();
                        }
                        conditionSection.setClient(createExpressionComposite(conditionSection, widgetFactory));
                        conditionSection.setExpanded(true);
                    } else if (event.diff.getNewValue() == SequenceFlowConditionType.DECISION_TABLE
                            && (conditionViewer != null && !conditionViewer.getControl().isDisposed())) {
                        if (conditionSection.getClient() != null) {
                            conditionSection.getClient().dispose();
                        }
                        conditionSection
                                .setClient(createDecisionTableComposite(conditionSection, widgetFactory));
                        conditionSection.setExpanded(true);
                    }
                    refreshBindings();
                }
            }
        });

        dataBindingContext.bindValue(SWTObservables.observeSelection(useExpressionCondition), typeValue,
                useExpressionTargetToModel, useExpressionModelToTarget);
        dataBindingContext.bindValue(SWTObservables.observeSelection(useDecisionTable), typeValue,
                useDescisionTargetToModel, useDecisionModelToTarget);

        dataBindingContext.bindValue(SWTObservables.observeSelection(defaultCheckBox), EMFEditObservables
                .observeValue(editingDomain, transition, ProcessPackage.Literals.SEQUENCE_FLOW__IS_DEFAULT));

        dataBindingContext.bindValue(SWTObservables.observeEnabled(defaultCheckBox),
                EMFEditObservables.observeValue(editingDomain, transition,
                        ProcessPackage.Literals.SEQUENCE_FLOW__IS_DEFAULT),
                new UpdateValueStrategy().setConverter(defaultConverter),
                new UpdateValueStrategy().setConverter(defaultConverter));

        if (conditionViewer != null && !conditionViewer.getControl().isDisposed()) {
            dataBindingContext.bindValue(SWTObservables.observeEnabled(conditionViewer.getTextControl()),
                    EMFEditObservables.observeValue(editingDomain, transition,
                            ProcessPackage.Literals.SEQUENCE_FLOW__IS_DEFAULT),
                    new UpdateValueStrategy().setConverter(conditionConverter),
                    new UpdateValueStrategy().setConverter(conditionConverter));

            dataBindingContext.bindValue(SWTObservables.observeEnabled(conditionViewer.getToolbar()),
                    EMFEditObservables.observeValue(editingDomain, transition,
                            ProcessPackage.Literals.SEQUENCE_FLOW__IS_DEFAULT),
                    new UpdateValueStrategy().setConverter(conditionConverter),
                    new UpdateValueStrategy().setConverter(conditionConverter));

            conditionViewer.setEditingDomain(editingDomain);
            dataBindingContext.bindValue(ViewerProperties.singleSelection().observe(conditionViewer),
                    EMFEditProperties.value(editingDomain, ProcessPackage.Literals.SEQUENCE_FLOW__CONDITION)
                            .observe(transition));
            conditionViewer.setInput(transition);

            dataBindingContext.bindValue(SWTObservables.observeSelection(useExpressionCondition),
                    SWTObservables.observeEnabled(conditionViewer.getControl()));
        }

        dataBindingContext.bindValue(SWTObservables.observeEnabled(useExpressionCondition),
                EMFEditObservables.observeValue(editingDomain, transition,
                        ProcessPackage.Literals.SEQUENCE_FLOW__IS_DEFAULT),
                new UpdateValueStrategy().setConverter(conditionConverter),
                new UpdateValueStrategy().setConverter(conditionConverter));

        dataBindingContext.bindValue(SWTObservables.observeEnabled(useDecisionTable),
                EMFEditObservables.observeValue(editingDomain, transition,
                        ProcessPackage.Literals.SEQUENCE_FLOW__IS_DEFAULT),
                new UpdateValueStrategy().setConverter(conditionConverter),
                new UpdateValueStrategy().setConverter(conditionConverter));

        if (updateTableButton != null && !updateTableButton.isDisposed()) {
            dataBindingContext.bindValue(SWTObservables.observeEnabled(updateTableButton),
                    EMFEditObservables.observeValue(editingDomain, transition,
                            ProcessPackage.Literals.SEQUENCE_FLOW__IS_DEFAULT),
                    new UpdateValueStrategy().setConverter(conditionConverter),
                    new UpdateValueStrategy().setConverter(conditionConverter));

        }
    }
}