Java Code Examples for org.eclipse.core.databinding.observable.value.WritableValue#setValue()

The following examples show how to use org.eclipse.core.databinding.observable.value.WritableValue#setValue() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SelectDataWizardPageTest.java    From bonita-studio with GNU General Public License v2.0 6 votes vote down vote up
@Test
public void should_select_first_businessVariable_whenSelecting_businessDataType() {
    final List<Data> availableBusinessData = new ArrayList<Data>();
    final List<Document> availableDocuments = new ArrayList<Document>();
    final Contract contract = aContract().build();
    final BusinessObjectData bd = aBusinessData().build();
    availableBusinessData.add(bd);
    final Document document = ProcessFactory.eINSTANCE.createDocument();
    availableDocuments.add(document);
    final WritableValue selectedDataObservable = new WritableValue();
    selectedDataObservable.setValue(document);
    final SelectDataWizardPage page = new SelectDataWizardPage(contract, availableBusinessData, availableDocuments, selectedDataObservable,
            selectedDataObservable, new GenerationOptions(), store);
    page.setBusinessDataTypeSelected(false);
    final SelectionAdapter bvSelectionAdapter = page.createBusinessVariableSelectionAdapter();
    bvSelectionAdapter.widgetSelected(mock(SelectionEvent.class));
    assertThat(page.isBusinessDataTypeSelected()).isTrue();
    assertThat(selectedDataObservable.getValue()).isEqualTo(bd);
}
 
Example 2
Source File: SelectDataWizardPageTest.java    From bonita-studio with GNU General Public License v2.0 6 votes vote down vote up
@Test
public void should_isPageComplete_ReturnTrue_when_available_documents_is_not_empty_selection_not_empty() {
    final List<Data> availableBusinessData = new ArrayList<Data>();
    final List<Document> availableDocuments = new ArrayList<Document>();
    final Contract contract = aContract().build();
    final BusinessObjectData bd = aBusinessData().build();
    availableBusinessData.add(bd);
    final Document document = ProcessFactory.eINSTANCE.createDocument();
    availableDocuments.add(document);
    final WritableValue selectedDataObservable = new WritableValue();
    selectedDataObservable.setValue(document);
    final SelectDataWizardPage page = new SelectDataWizardPage(contract, availableBusinessData, availableDocuments, selectedDataObservable,
            selectedDataObservable, new GenerationOptions(), store);
    page.setBusinessDataTypeSelected(false);
    assertThat(page.isPageComplete()).isTrue();
}
 
Example 3
Source File: SelectDataWizardPageTest.java    From bonita-studio with GNU General Public License v2.0 6 votes vote down vote up
@Test
public void should_rootInputName_be_dataName_input() {
    final List<Data> availableBusinessData = new ArrayList<Data>();
    final List<Document> availableDocuments = new ArrayList<Document>();
    final Contract contract = aContract().build();
    final BusinessObjectData bd = aBusinessData().withName("myData").build();
    availableBusinessData.add(bd);
    final WritableValue selectedDataObservable = new WritableValue();
    selectedDataObservable.setValue(bd);
    final WritableValue rootNameObservable = new WritableValue();
    final SelectDataWizardPage page = new SelectDataWizardPage(contract, availableBusinessData, availableDocuments, selectedDataObservable,
            rootNameObservable, new GenerationOptions(), store);
    page.setWizard(wizardWithContainer());
    page.createControl(realmWithDisplay.createComposite());
    assertThat(rootNameObservable.getValue()).isEqualTo("myDataInput");
}
 
Example 4
Source File: AvailableDataValidatorTest.java    From bonita-studio with GNU General Public License v2.0 6 votes vote down vote up
@Test
public void testValidate_KO_forNoBusinessDataSelected() throws Exception {
    final WritableValue selectedDataObservable = new WritableValue();
    final BusinessObjectData businessObjectData = aBusinessData().withClassname("org.test.Employee").build();
    selectedDataObservable.setValue(businessObjectData);
    final List<Data> availableBusinessData = new ArrayList<>();
    availableBusinessData.add(ProcessFactory.eINSTANCE.createData());

    final BusinessObjectModelRepositoryStore<BusinessObjectModelFileStore> businessObjectStore = mock(
            BusinessObjectModelRepositoryStore.class);
    when(businessObjectStore.getBusinessObjectByQualifiedName(businessObjectData.getClassName()))
            .thenReturn(Optional.empty());
    assertThat(
            new AvailableDataValidator(availableBusinessData, selectedDataObservable, new ArrayList<Document>(),
                    businessObjectStore)
                            .validate().isOK()).isFalse();
}
 
Example 5
Source File: AvailableDataValidatorTest.java    From bonita-studio with GNU General Public License v2.0 6 votes vote down vote up
@Test
public void testValidate_OK() throws Exception {
    final WritableValue selectedDataObservable = new WritableValue();
    final BusinessObjectData businessObjectData = aBusinessData().withClassname("org.test.Employee").build();
    selectedDataObservable.setValue(businessObjectData);
    final List<Data> availableBusinessData = new ArrayList<>();
    availableBusinessData.add(ProcessFactory.eINSTANCE.createData());

    final BusinessObjectModelRepositoryStore businessObjectStore = mock(BusinessObjectModelRepositoryStore.class);
    when(businessObjectStore.getBusinessObjectByQualifiedName(businessObjectData.getClassName()))
            .thenReturn(Optional.of(new BusinessObject()));
    assertThat(
            new AvailableDataValidator(availableBusinessData, selectedDataObservable, new ArrayList<Document>(),
                    businessObjectStore)
                            .validate().isOK()).isTrue();
}
 
Example 6
Source File: ContractInputTreeViewerTest.java    From bonita-studio with GNU General Public License v2.0 6 votes vote down vote up
/**
 * @throws java.lang.Exception
 */
@Before
public void setUp() throws Exception {
    parent = realm.createComposite();
    FileActionDialog.setDisablePopup(true);
    inputTreeViewer = new ContractInputTreeViewer(parent, new FormToolkit(parent.getDisplay()), progressService, sharedImages);
    final ContractInputController inputController = spy(new ContractInputController(new FakeProgressService()));
    doReturn(new TransactionalEditingDomainImpl(new ProcessItemProviderAdapterFactory())).when(inputController).editingDomain(any(Contract.class));
    inputTreeViewer.initialize(inputController, messageManager, new EMFDataBindingContext());
    final WritableValue contractObservableValue = new WritableValue();
    final Contract contract = ProcessFactory.eINSTANCE.createContract();
    input = ProcessFactory.eINSTANCE.createContractInput();
    input.setName("name");
    input.setType(ContractInputType.TEXT);
    contract.getInputs().add(input);
    aTask().build().setContract(contract);
    contractObservableValue.setValue(contract);
    inputTreeViewer.setInput(contractObservableValue);
}
 
Example 7
Source File: EmptySelectionMultivalidatorTest.java    From bonita-studio with GNU General Public License v2.0 6 votes vote down vote up
@Test
public void shouldReturnWarningWhenOneElementIsMandatoryAndNotChecked() {
    final IObservableSet checkedElements = new WritableSet();
    final FieldToContractInputMapping rootMapping1 = new RelationFieldToContractInputMapping(Mockito.mock(RelationField.class));
    final SimpleField simpleField1 = new SimpleField();
    simpleField1.setNullable(false);
    final SimpleField simpleField2 = new SimpleField();
    simpleField2.setNullable(true);
    final SimpleFieldToContractInputMapping childMapping1 = new SimpleFieldToContractInputMapping(simpleField1);
    childMapping1.setGenerated(false);
    final SimpleFieldToContractInputMapping childMapping2 = new SimpleFieldToContractInputMapping(simpleField2);
    rootMapping1.addChild(childMapping1);
    rootMapping1.addChild(childMapping2);
    final FieldToContractInputMapping rootMapping2 = new RelationFieldToContractInputMapping(Mockito.mock(RelationField.class));
    checkedElements.add(rootMapping1);
    checkedElements.add(rootMapping2);
    checkedElements.add(childMapping2);
    final WritableValue selectedDataObservable = new WritableValue();
    final BusinessObjectData businessObjectData = aBusinessData().withClassname("org.test.Employee").build();
    selectedDataObservable.setValue(businessObjectData);
    final EmptySelectionMultivalidator multiValidator = new EmptySelectionMultivalidator(selectedDataObservable, checkedElements,
            Lists.newArrayList(rootMapping1, rootMapping2), aPool().build(),new WritableValue<GenerationOptions.EditMode>(EditMode.CREATE, EditMode.class));
    assertThat(multiValidator.validate().isOK()).isFalse();
}
 
Example 8
Source File: CreateContractInputFromBusinessObjectWizardPageTest.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void should_CheckedElementsList_Contains_AllFieldToInputContractMappingsGenerated_whenSelectingAllFields() {
    BusinessObjectData data = aBusinessData().withName("employee").withClassname("org.company.Employee").build();
    Contract contract = aContract().build();
    Pool process = aPool().havingContract(contract).build();
    process.getData().add(data);
    GenerationOptions options = new GenerationOptions();
    BusinessObjectModelRepositoryStore<BusinessObjectModelFileStore> store = mock(
            BusinessObjectModelRepositoryStore.class);
    WritableValue<BusinessObjectData> selectedDataObservable = new WritableValue<>();
    selectedDataObservable.setValue(data);
    WritableValue<String> rootNameObservable = new WritableValue<>();
    rootNameObservable.setValue("employeeInput");
    WritableList<FieldToContractInputMapping> fieldToContractInputMappingsObservable = new WritableList<>();
    CreateContractInputFromBusinessObjectWizardPage page = new CreateContractInputFromBusinessObjectWizardPage(
            process, options,
            selectedDataObservable, new FieldToContractInputMappingFactory(store),
            fieldToContractInputMappingsObservable,
            store);
    FieldToContractInputMapping rootMapping1 = new RelationFieldToContractInputMapping(
            Mockito.mock(RelationField.class));
    SimpleFieldToContractInputMapping childMapping1 = new SimpleFieldToContractInputMapping(
            Mockito.mock(SimpleField.class));
    SimpleFieldToContractInputMapping childMapping2 = new SimpleFieldToContractInputMapping(
            Mockito.mock(SimpleField.class));
    rootMapping1.addChild(childMapping1);
    rootMapping1.addChild(childMapping2);
    FieldToContractInputMapping rootMapping2 = new RelationFieldToContractInputMapping(
            Mockito.mock(RelationField.class));
    WritableSet<FieldToContractInputMapping> checkedElements = new WritableSet<>();
    checkedElements.addAll(Arrays.asList(rootMapping1, childMapping2));
    page.setMappings(Lists.newArrayList(rootMapping1, rootMapping2));
    SelectionAdapter listener = page.createSelectAllListener(checkedElements);
    listener.widgetSelected(mock(SelectionEvent.class));
    assertThat(checkedElements.size()).isEqualTo(4);
    assertThat(checkedElements)
            .containsAll(Lists.newArrayList(rootMapping1, rootMapping2, childMapping1, childMapping2));
}
 
Example 9
Source File: EmptySelectionMultivalidatorTest.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void shouldReturnOkStatusWhenAtLeastOneElementIsChecked() {
    final IObservableSet checkedElements = new WritableSet();
    checkedElements.add(mock(FieldToContractInputMapping.class));
    final WritableValue selectedDataObservable = new WritableValue();
    final BusinessObjectData businessObjectData = aBusinessData().withClassname("org.test.Employee").build();
    selectedDataObservable.setValue(businessObjectData);
    final EmptySelectionMultivalidator multiValidator = new EmptySelectionMultivalidator(selectedDataObservable, checkedElements,
            new ArrayList<FieldToContractInputMapping>(), aPool().build(),new WritableValue<GenerationOptions.EditMode>(EditMode.CREATE, EditMode.class));
    assertThat(multiValidator.validate().isOK()).isTrue();
}
 
Example 10
Source File: DefaultReturnTypeResolverTest.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void should_return_setter_parameter_return_type_for_JAVA_METHOD_OPERATOR_operator() throws Exception {
    WritableValue writableValue = new WritableValue();
    writableValue.setValue(anOperation()
            .havingLeftOperand(anExpression().withReturnType(String.class.getName()))
            .havingOperator(anOperator().withType(ExpressionConstants.JAVA_METHOD_OPERATOR).havingInputTypes(Boolean.class.getName()))
            .havingRightOperand(anExpression()).build());
    final DefaultReturnTypeResolver defaultReturnTypeResolver = new DefaultReturnTypeResolver(writableValue);

    final String returnType = defaultReturnTypeResolver.guessRightOperandReturnType();

    assertThat(returnType).isEqualTo(Boolean.class.getName());
}
 
Example 11
Source File: ProcessElementNameContributionTest.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void should_validationStatusProvider_fail_name_with_reservedKeywords() throws Exception {
    final WritableValue targetValue = new WritableValue();
    final WritableValue modelValue = new WritableValue();
    dbc.bindValue(targetValue, modelValue);
    final MultiValidator validationStatusProvider = nameGridPropertySectionContribution.nameValidationStatusProvider(targetValue);
    dbc.addValidationStatusProvider(validationStatusProvider);

    targetValue.setValue("content");

    assertThat(((IStatus) validationStatusProvider.getValidationStatus().getValue()).isOK()).isFalse();
    assertThat(modelValue.getValue()).isEqualTo(targetValue.getValue()).isEqualTo("content");
}
 
Example 12
Source File: ContractInputObservableFactoryTest.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void should_createObservable_return_contract_input_observable_list() throws Exception {
    final WritableValue contractObservable = new WritableValue(Realm.getDefault());
    contractObservable.setValue(ProcessFactory.eINSTANCE.createContract());
    final IObservable observable = contractInputObservableFactory.createObservable(contractObservable);
    assertThat(observable).isInstanceOf(IObservableList.class);
    assertThat(((IObservableList) observable).getElementType()).isEqualTo(ProcessPackage.Literals.CONTRACT__INPUTS);
}
 
Example 13
Source File: MultipleContractInputValidatorTest.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void should_not_fail_when_updating_validation_and_contract_input_is_not_null() throws Exception {
    final WritableValue selectionObservable = new WritableValue();
    final WritableValue viewerInputObservable = new WritableValue();
    final EMFDataBindingContext emfDataBindingContext = new EMFDataBindingContext();
    final Document document = aDocument().withDocumentType(DocumentType.CONTRACT).build();
    emfDataBindingContext.addValidationStatusProvider(new MultipleContractInputValidator(document,
            selectionObservable, viewerInputObservable));

    selectionObservable.setValue(aContractInput().build());

    assertThat(statusFromContext(emfDataBindingContext)).isOK();
}
 
Example 14
Source File: GeneratedScriptPreviewPageTest.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void testShouldBeGeneratedWhenPageIsVisible() throws JavaModelException, BusinessObjectInstantiationException {
    final BusinessObjectData data = aBusinessData().withName("employee").withClassname("org.company.Employee").build();
    final Pool process = aPool().havingContract(aContract()).build();
    process.getData().add(data);
    final WritableValue selectedDataObservable = new WritableValue();
    selectedDataObservable.setValue(data);
    final WritableValue rootNameObservable = new WritableValue();
    rootNameObservable.setValue(data.getName() + "Input");
    final WritableList fieldToContactInputMappingsObservable = new WritableList();
    final SimpleFieldToContractInputMapping mapping = new SimpleFieldToContractInputMapping(
            SimpleFieldBuilder.aStringField(
                    "firstName").build());
    fieldToContactInputMappingsObservable.add(mapping);

    final BusinessObjectModelRepositoryStore<BusinessObjectModelFileStore> store = mock(
            BusinessObjectModelRepositoryStore.class);
    when(repositoryAccessor.getRepositoryStore(BusinessObjectModelRepositoryStore.class)).thenReturn(store);
    when(store.getBusinessObjectByQualifiedName("org.company.Employee"))
            .thenReturn(Optional.of(BusinessObjectBuilder.aBO("org.company.Employee")
                    .withField(SimpleFieldBuilder.aStringField("firstName").build()).build()));
    when(sourceViewerFactory.createSourceViewer(any(Composite.class), any(Boolean.class))).thenReturn(groovyViewer);
    when(groovyViewer.getSourceViewer()).thenReturn(sourceViewer);
    when(groovyViewer.getDocument()).thenReturn(document);
    when(expressionBuilder.toExpression(any(BusinessObjectData.class), any(FieldToContractInputMapping.class),
            anyBoolean())).thenReturn(
                    aGroovyScriptExpression().build());

    final GeneratedScriptPreviewPage previewPage = new GeneratedScriptPreviewPage(rootNameObservable,
            fieldToContactInputMappingsObservable,
            selectedDataObservable, repositoryAccessor, operationBuilder, expressionBuilder, sourceViewerFactory);
    final IWizard wizard = mock(IWizard.class);
    when(wizard.getContainer()).thenReturn(new TestWizardContainer(realmWithDisplay.getShell()));
    previewPage.setWizard(wizard);
    previewPage.createControl(realmWithDisplay.createComposite());
    previewPage.setVisible(true);

    assertThat(previewPage.getRootContractInputGenerator()).isNotNull();
    assertThat(previewPage.getRootContractInputGenerator().getInitialValueExpression()).isNotNull();
}
 
Example 15
Source File: MultipleContractInputValidatorTest.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void should_not_fail_when_updating_viewer_input_and_contract_input_is_null() throws Exception {
    final WritableValue selectionObservable = new WritableValue();
    final WritableValue viewerInputObservable = new WritableValue();
    final EMFDataBindingContext emfDataBindingContext = new EMFDataBindingContext();
    emfDataBindingContext.addValidationStatusProvider(new MultipleContractInputValidator(aDocument().withDocumentType(DocumentType.CONTRACT).build(),
            selectionObservable, viewerInputObservable));

    viewerInputObservable.setValue(newArrayList(aContractInput().build()));

    assertThat(statusFromContext(emfDataBindingContext)).isOK();
}
 
Example 16
Source File: CreateContractInputFromBusinessObjectWizardPageTest.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void should_setAllFieldToInputContractMappingsGenerated_toFalse_whenDeselectingAllFields() {
    BusinessObjectData data = aBusinessData().withName("employee").withClassname("org.company.Employee").build();
    Contract contract = aContract().build();
    Pool process = aPool().havingContract(contract).build();
    process.getData().add(data);
    GenerationOptions options = new GenerationOptions();
    BusinessObjectModelRepositoryStore<BusinessObjectModelFileStore> store = mock(
            BusinessObjectModelRepositoryStore.class);
    WritableValue<BusinessObjectData> selectedDataObservable = new WritableValue<>();
    selectedDataObservable.setValue(data);
    WritableValue<String> rootNameObservable = new WritableValue<>();
    rootNameObservable.setValue("employeeInput");
    WritableList<FieldToContractInputMapping> fieldToContractInputMappingsObservable = new WritableList<>();
    CreateContractInputFromBusinessObjectWizardPage page = new CreateContractInputFromBusinessObjectWizardPage(
            process, options,
            selectedDataObservable, new FieldToContractInputMappingFactory(store),
            fieldToContractInputMappingsObservable,
            store);
    FieldToContractInputMapping rootMapping1 = new RelationFieldToContractInputMapping(
            Mockito.mock(RelationField.class));
    SimpleFieldToContractInputMapping childMapping1 = new SimpleFieldToContractInputMapping(
            Mockito.mock(SimpleField.class));
    SimpleFieldToContractInputMapping childMapping2 = new SimpleFieldToContractInputMapping(
            Mockito.mock(SimpleField.class));
    rootMapping1.addChild(childMapping1);
    rootMapping1.addChild(childMapping2);
    FieldToContractInputMapping rootMapping2 = new RelationFieldToContractInputMapping(
            Mockito.mock(RelationField.class));
    page.setMappings(Lists.newArrayList(rootMapping1, rootMapping2));
    WritableSet<FieldToContractInputMapping> checkedElements = new WritableSet<>();
    checkedElements.addAll(Arrays.asList(rootMapping1, childMapping2));
    SelectionAdapter listener = page.createDeselectAllListener(checkedElements);
    listener.widgetSelected(mock(SelectionEvent.class));
    assertThat(rootMapping1.isGenerated()).isFalse();
    assertThat(childMapping1.isGenerated()).isFalse();
    assertThat(childMapping2.isGenerated()).isFalse();
    assertThat(rootMapping2.isGenerated()).isFalse();
}
 
Example 17
Source File: SingleContractInputValidatorTest.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void should_fail_when_updating_viewer_selection_and_contract_input_is_null() throws Exception {
    final WritableValue selectionObservable = new WritableValue(aContractInput().build(), ContractInput.class);
    final WritableValue viewerInputObservable = new WritableValue();
    final EMFDataBindingContext emfDataBindingContext = new EMFDataBindingContext();
    emfDataBindingContext.addValidationStatusProvider(new SingleContractInputValidator(aDocument().withDocumentType(DocumentType.CONTRACT).build(),
            selectionObservable, viewerInputObservable));

    selectionObservable.setValue(null);

    assertThat(statusFromContext(emfDataBindingContext)).isNotOK();
}
 
Example 18
Source File: SelectDataWizardPageTest.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void should_isPageComplete_ReturnTrue_when_available_data_is_not_empty_selection_not_empty() {
    final List<Data> availableBusinessData = new ArrayList<Data>();
    final List<Document> availableDocuments = new ArrayList<Document>();
    final Contract contract = aContract().build();
    availableBusinessData.add(aBusinessData().build());
    final WritableValue selectedDataObservable = new WritableValue();
    selectedDataObservable.setValue(new Object());
    final SelectDataWizardPage page = new SelectDataWizardPage(contract, availableBusinessData, availableDocuments, selectedDataObservable,
            selectedDataObservable, new GenerationOptions(), store);
    assertThat(page.isPageComplete()).isTrue();
}
 
Example 19
Source File: CreateContractInputFromBusinessObjectWizardPageTest.java    From bonita-studio with GNU General Public License v2.0 4 votes vote down vote up
@Test
public void should_selectAllMandatoryAttributes_whenClickingOnMandatoryAttributes() {
    BusinessObjectData data = aBusinessData().withName("employee").withClassname("org.company.Employee").build();
    Contract contract = aContract().build();
    Pool process = aPool().havingContract(contract).build();
    process.getData().add(data);
    GenerationOptions options = new GenerationOptions();
    BusinessObjectModelRepositoryStore<BusinessObjectModelFileStore> store = mock(
            BusinessObjectModelRepositoryStore.class);
    WritableValue<BusinessObjectData> selectedDataObservable = new WritableValue<>();
    selectedDataObservable.setValue(data);
    WritableValue<String> rootNameObservable = new WritableValue<>();
    rootNameObservable.setValue("employeeInput");
    WritableList<FieldToContractInputMapping> fieldToContractInputMappingsObservable = new WritableList<>();
    CreateContractInputFromBusinessObjectWizardPage page = new CreateContractInputFromBusinessObjectWizardPage(
            process, options,
            selectedDataObservable, new FieldToContractInputMappingFactory(store),
            fieldToContractInputMappingsObservable,
            store);
    RelationField rootMandatoryField = Mockito.mock(RelationField.class);
    RelationField rootOptionalField = Mockito.mock(RelationField.class);
    SimpleField childOptionalField = Mockito.mock(SimpleField.class);
    SimpleField childMandatoryField = Mockito.mock(SimpleField.class);
    when(rootMandatoryField.isNullable()).thenReturn(false);
    when(rootOptionalField.isNullable()).thenReturn(true);
    when(childOptionalField.isNullable()).thenReturn(true);
    when(childMandatoryField.isNullable()).thenReturn(false);
    FieldToContractInputMapping rootMappingMandatoryField = new RelationFieldToContractInputMapping(
            rootMandatoryField);
    SimpleFieldToContractInputMapping childMappingOptional = new SimpleFieldToContractInputMapping(
            childOptionalField);
    SimpleFieldToContractInputMapping childMappingMandatory = new SimpleFieldToContractInputMapping(
            childMandatoryField);
    rootMappingMandatoryField.addChild(childMappingOptional);
    rootMappingMandatoryField.addChild(childMappingMandatory);
    rootMappingMandatoryField.setGenerated(false);
    FieldToContractInputMapping rootMappingOptionalField = new RelationFieldToContractInputMapping(
            rootOptionalField);
    rootMappingOptionalField.setGenerated(false);
    childMappingOptional.setGenerated(false);
    childMappingMandatory.setGenerated(false);
    page.setMappings(Lists.newArrayList(rootMappingMandatoryField, rootMappingOptionalField));
    WritableSet<FieldToContractInputMapping> checkedElements = new WritableSet<>();
    SelectionAdapter listener = page.createMandatoryAttributesSelectionListener(checkedElements);
    listener.widgetSelected(mock(SelectionEvent.class));
    assertThat(checkedElements.size()).isEqualTo(2);
    assertThat(checkedElements.contains(rootMappingMandatoryField)).isTrue();
    assertThat(checkedElements.contains(rootMappingOptionalField)).isFalse();
    assertThat(checkedElements.contains(childMappingOptional)).isFalse();
    assertThat(checkedElements.contains(childMappingMandatory)).isTrue();
}
 
Example 20
Source File: EssentialsPage.java    From thym with Eclipse Public License 1.0 4 votes vote down vote up
private void bindAuthor(DataBindingContext bindingContext) {
	//
	final WritableValue value = new WritableValue();
	if (getWidget() != null) {
		Author author = getWidget().getAuthor();
		if (author == null) {
			value.setValue(new DummyAuthor());
		} else {
			value.setValue(author);
		}
		authorListener = new PropertyChangeListener() {

			@Override
			public void propertyChange(final PropertyChangeEvent evt) {
				value.getRealm().exec(new Runnable() {
					@Override
					public void run() {
						if (evt.getNewValue() == null) {
							value.setValue(new DummyAuthor());
						} else {
							value.setValue(evt.getNewValue());
						}
					}
				});
			}
		};
		getWidget().addPropertyChangeListener("author", authorListener);
	}
	//
	IObservableValue observeTextTxtAuthornameObserveWidget = WidgetProperties.text(SWT.Modify)
			.observe(txtAuthorname);
	IObservableValue authornameGetWidgetObserveValue = BeanProperties.value("name").observeDetail(value);
	UpdateValueStrategy strategy = new UpdateValueStrategy();
	strategy.setConverter(new StringToDisplayableStringConverter());
	bindingContext.bindValue(observeTextTxtAuthornameObserveWidget, authornameGetWidgetObserveValue, null,
			strategy);
	//
	IObservableValue observeTextTxtEmailObserveWidget = WidgetProperties.text(SWT.Modify).observe(txtEmail);
	IObservableValue authoremailGetWidgetObserveValue = BeanProperties.value("email").observeDetail(value);
	bindingContext.bindValue(observeTextTxtEmailObserveWidget, authoremailGetWidgetObserveValue, null, null);
	//
	IObservableValue observeTextTxtUrlObserveWidget = WidgetProperties.text(SWT.Modify).observe(txtUrl);
	IObservableValue authorhrefGetWidgetObserveValue = BeanProperties.value("href").observeDetail(value);
	bindingContext.bindValue(observeTextTxtUrlObserveWidget, authorhrefGetWidgetObserveValue, null, null);
}