org.eclipse.swt.events.SelectionAdapter#widgetSelected ( )源码实例Demo

下面列出了org.eclipse.swt.events.SelectionAdapter#widgetSelected ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: bonita-studio   文件: SelectDataWizardPageTest.java
@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);
}
 
源代码2 项目: bonita-studio   文件: SelectDataWizardPageTest.java
@Test
public void should_select_first_document_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(bd);
    final SelectDataWizardPage page = new SelectDataWizardPage(contract, availableBusinessData, availableDocuments, selectedDataObservable,
            selectedDataObservable, new GenerationOptions(), store);
    page.setBusinessDataTypeSelected(true);
    final SelectionAdapter documentSelectionAdapter = page.createDocumentSelectionAdapter();
    documentSelectionAdapter.widgetSelected(mock(SelectionEvent.class));
    assertThat(page.isBusinessDataTypeSelected()).isFalse();
    assertThat(selectedDataObservable.getValue()).isEqualTo(document);
}
 
@Test
public void should_setAllFieldToInputContractMappingsGenerated_toTrue_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));
    page.setMappings(Lists.newArrayList(rootMapping1, rootMapping2));
    WritableSet<FieldToContractInputMapping> checkedElements = new WritableSet<>();
    checkedElements.addAll(Arrays.asList(rootMapping1, childMapping2));
    SelectionAdapter listener = page.createSelectAllListener(checkedElements);
    listener.widgetSelected(mock(SelectionEvent.class));
    assertThat(rootMapping1.isGenerated()).isTrue();
    assertThat(childMapping1.isGenerated()).isTrue();
    assertThat(childMapping2.isGenerated()).isTrue();
    assertThat(rootMapping2.isGenerated()).isTrue();
}
 
@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();
}
 
@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));
}
 
@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();
}