Search in sources :

Example 1 with IPageListener

use of org.eclipse.wb.internal.core.databinding.ui.editor.IPageListener in project windowbuilder by eclipse.

the class UiConfigurationTest method test_BindingInfo.

public void test_BindingInfo() throws Exception {
    CompositeInfo shell = DatabindingTestUtils.parseTestSource(this, new String[] { "import org.eclipse.core.databinding.Binding;", "public class Test {", "  protected Shell m_shell;", "  private DataBindingContext m_bindingContext;", "  public static void main(String[] args) {", "    Test test = new Test();", "    test.open();", "  }", "  public void open() {", "    Display display = new Display();", "    createContents();", "    m_shell.open();", "    m_shell.layout();", "    while (!m_shell.isDisposed()) {", "      if (!display.readAndDispatch()) {", "        display.sleep();", "      }", "    }", "  }", "  protected void createContents() {", "    m_shell = new Shell();", "    m_bindingContext = initDataBindings();", "  }", "  private DataBindingContext initDataBindings() {", "    IObservableValue observeValue = BeansObservables.observeValue(getClass(), \"name\");", "    IObservableValue observeWidget = SWTObservables.observeText(m_shell);", "    DataBindingContext bindingContext = new DataBindingContext();", "    bindingContext.bindValue(observeWidget, observeValue, null, null);", "    return bindingContext;", "  }", "}" });
    assertNotNull(shell);
    // 
    DatabindingsProvider provider = getDatabindingsProvider();
    // 
    assertEquals(1, provider.getBindings().size());
    assertInstanceOf(BindingInfo.class, provider.getBindings().get(0));
    BindingInfo binding = (BindingInfo) provider.getBindings().get(0);
    // 
    assertNotNull(binding.getTargetStrategy());
    // 
    IPageListener listener = new IPageListener() {

        @Override
        public void setTitleImage(Image image) {
        }

        @Override
        public void setTitle(String title) {
        }

        @Override
        public void setPageComplete(boolean complete) {
        }

        @Override
        public void setMessage(String newMessage) {
        }

        @Override
        public void setErrorMessage(String newMessage) {
        }
    };
    // 
    List<IUiContentProvider> providers = provider.getContentProviders(binding, listener);
    // 
    assertEquals(10, providers.size());
    // ---------------------------------------------------------------------------
    assertInstanceOf(LabelUiContentProvider.class, providers.get(0));
    assertEquals("Target:", ReflectionUtils.getFieldObject(providers.get(0), "m_title"));
    assertEquals("m_shell.text", ReflectionUtils.getFieldObject(providers.get(0), "m_value"));
    // ---------------------------------------------------------------------------
    assertInstanceOf(SwtDelayUiContentProvider.class, providers.get(1));
    // ---------------------------------------------------------------------------
    assertInstanceOf(UpdateStrategyUiContentProvider.class, providers.get(2));
    assertInstanceOf(ChooseClassConfiguration.class, ReflectionUtils.getFieldObject(providers.get(2), "m_configuration"));
    ChooseClassConfiguration actualTargetStrategy = getConfiguration(providers.get(2));
    // 
    ChooseClassConfiguration expectedTargetStrategy = new ChooseClassConfiguration();
    expectedTargetStrategy.setDialogFieldLabel("UpdateValueStrategy:");
    expectedTargetStrategy.setDefaultValues(new String[] { "POLICY_UPDATE", "POLICY_NEVER", "POLICY_ON_REQUEST", "POLICY_CONVERT" });
    expectedTargetStrategy.setValueScope("org.eclipse.core.databinding.UpdateValueStrategy");
    expectedTargetStrategy.setRetargetClassName("org.eclipse.core.databinding.UpdateValueStrategy", "POLICY_UPDATE");
    expectedTargetStrategy.setBaseClassName("org.eclipse.core.databinding.UpdateValueStrategy");
    expectedTargetStrategy.setConstructorParameters(ArrayUtils.EMPTY_CLASS_ARRAY);
    expectedTargetStrategy.setEmptyClassErrorMessage("Target strategy class is empty.");
    expectedTargetStrategy.setErrorMessagePrefix("Target strategy");
    // 
    assertEquals(expectedTargetStrategy, actualTargetStrategy);
    // ---------------------------------------------------------------------------
    assertInstanceOf(UpdateStrategyPropertiesUiContentProvider.class, providers.get(3));
    // 
    List<IUiContentProvider> subProvidersTargetStrategy = (List<IUiContentProvider>) ReflectionUtils.getFieldObject(providers.get(3), "m_providers");
    assertEquals(4, subProvidersTargetStrategy.size());
    assertInstanceOf(ValidatorUiContentProvider.class, subProvidersTargetStrategy.get(0));
    assertInstanceOf(ValidatorUiContentProvider.class, subProvidersTargetStrategy.get(1));
    assertInstanceOf(ValidatorUiContentProvider.class, subProvidersTargetStrategy.get(2));
    assertInstanceOf(ConverterUiContentProvider.class, subProvidersTargetStrategy.get(3));
    // ---------------------------------------------------------------------------
    ChooseClassConfiguration afterConvertValidatorActualTarget = getConfiguration(subProvidersTargetStrategy.get(0));
    // 
    ChooseClassConfiguration afterConvertValidatorExpectedTarget = new ChooseClassConfiguration();
    afterConvertValidatorExpectedTarget.setDialogFieldLabel("AfterConvertValidator:");
    afterConvertValidatorExpectedTarget.setValueScope("org.eclipse.core.databinding.validation.IValidator");
    afterConvertValidatorExpectedTarget.setClearValue("N/S");
    afterConvertValidatorExpectedTarget.setBaseClassName("org.eclipse.core.databinding.validation.IValidator");
    afterConvertValidatorExpectedTarget.setConstructorParameters(ArrayUtils.EMPTY_CLASS_ARRAY);
    afterConvertValidatorExpectedTarget.setEmptyClassErrorMessage("Target \"AfterConvertValidator\" class is empty.");
    afterConvertValidatorExpectedTarget.setErrorMessagePrefix("Target \"AfterConvertValidator\"");
    // 
    assertEquals(afterConvertValidatorExpectedTarget, afterConvertValidatorActualTarget);
    // ---------------------------------------------------------------------------
    ChooseClassConfiguration afterGetValidatorActualTarget = getConfiguration(subProvidersTargetStrategy.get(1));
    // 
    ChooseClassConfiguration afterGetValidatorExpectedTarget = new ChooseClassConfiguration();
    afterGetValidatorExpectedTarget.setDialogFieldLabel("AfterGetValidator:");
    afterGetValidatorExpectedTarget.setValueScope("org.eclipse.core.databinding.validation.IValidator");
    afterGetValidatorExpectedTarget.setClearValue("N/S");
    afterGetValidatorExpectedTarget.setBaseClassName("org.eclipse.core.databinding.validation.IValidator");
    afterGetValidatorExpectedTarget.setConstructorParameters(ArrayUtils.EMPTY_CLASS_ARRAY);
    afterGetValidatorExpectedTarget.setEmptyClassErrorMessage("Target \"AfterGetValidator\" class is empty.");
    afterGetValidatorExpectedTarget.setErrorMessagePrefix("Target \"AfterGetValidator\"");
    // 
    assertEquals(afterGetValidatorExpectedTarget, afterGetValidatorActualTarget);
    // ---------------------------------------------------------------------------
    ChooseClassConfiguration beforeSetValidatorActualTarget = getConfiguration(subProvidersTargetStrategy.get(2));
    // 
    ChooseClassConfiguration beforeSetValidatorExpectedTarget = new ChooseClassConfiguration();
    beforeSetValidatorExpectedTarget.setDialogFieldLabel("BeforeSetValidator:");
    beforeSetValidatorExpectedTarget.setValueScope("org.eclipse.core.databinding.validation.IValidator");
    beforeSetValidatorExpectedTarget.setClearValue("N/S");
    beforeSetValidatorExpectedTarget.setBaseClassName("org.eclipse.core.databinding.validation.IValidator");
    beforeSetValidatorExpectedTarget.setConstructorParameters(ArrayUtils.EMPTY_CLASS_ARRAY);
    beforeSetValidatorExpectedTarget.setEmptyClassErrorMessage("Target \"BeforeSetValidator\" class is empty.");
    beforeSetValidatorExpectedTarget.setErrorMessagePrefix("Target \"BeforeSetValidator\"");
    // 
    assertEquals(beforeSetValidatorExpectedTarget, beforeSetValidatorActualTarget);
    // ---------------------------------------------------------------------------
    ChooseClassConfiguration converterActualTarget = getConfiguration(subProvidersTargetStrategy.get(3));
    // 
    ChooseClassConfiguration converterExpectedTarget = new ChooseClassConfiguration();
    converterExpectedTarget.setDialogFieldLabel("Converter:");
    converterExpectedTarget.setValueScope("org.eclipse.core.databinding.conversion.IConverter");
    converterExpectedTarget.setClearValue("N/S");
    converterExpectedTarget.setBaseClassName("org.eclipse.core.databinding.conversion.IConverter");
    converterExpectedTarget.setConstructorParameters(ArrayUtils.EMPTY_CLASS_ARRAY);
    converterExpectedTarget.setEmptyClassErrorMessage("Target converter class is empty.");
    converterExpectedTarget.setErrorMessagePrefix("Target converter");
    // 
    assertEquals(converterExpectedTarget, converterActualTarget);
    // ---------------------------------------------------------------------------
    assertInstanceOf(SeparatorUiContentProvider.class, providers.get(4));
    // ---------------------------------------------------------------------------
    assertInstanceOf(LabelUiContentProvider.class, providers.get(5));
    assertEquals("Model:", ReflectionUtils.getFieldObject(providers.get(5), "m_title"));
    assertEquals("getClass().name", ReflectionUtils.getFieldObject(providers.get(5), "m_value"));
    // ---------------------------------------------------------------------------
    assertInstanceOf(UpdateStrategyUiContentProvider.class, providers.get(6));
    assertInstanceOf(ChooseClassConfiguration.class, ReflectionUtils.getFieldObject(providers.get(6), "m_configuration"));
    ChooseClassConfiguration actualModelStrategy = getConfiguration(providers.get(6));
    // 
    ChooseClassConfiguration expectedModelStrategy = new ChooseClassConfiguration();
    expectedModelStrategy.setDialogFieldLabel("UpdateValueStrategy:");
    expectedModelStrategy.setDefaultValues(new String[] { "POLICY_UPDATE", "POLICY_NEVER", "POLICY_ON_REQUEST", "POLICY_CONVERT" });
    expectedModelStrategy.setValueScope("org.eclipse.core.databinding.UpdateValueStrategy");
    expectedModelStrategy.setRetargetClassName("org.eclipse.core.databinding.UpdateValueStrategy", "POLICY_UPDATE");
    expectedModelStrategy.setBaseClassName("org.eclipse.core.databinding.UpdateValueStrategy");
    expectedModelStrategy.setConstructorParameters(ArrayUtils.EMPTY_CLASS_ARRAY);
    expectedModelStrategy.setEmptyClassErrorMessage("Model strategy class is empty.");
    expectedModelStrategy.setErrorMessagePrefix("Model strategy");
    // 
    assertEquals(expectedModelStrategy, actualModelStrategy);
    // ---------------------------------------------------------------------------
    assertInstanceOf(UpdateStrategyPropertiesUiContentProvider.class, providers.get(7));
    // 
    List<IUiContentProvider> subProvidersModelStrategy = (List<IUiContentProvider>) ReflectionUtils.getFieldObject(providers.get(7), "m_providers");
    assertEquals(4, subProvidersModelStrategy.size());
    assertInstanceOf(ValidatorUiContentProvider.class, subProvidersModelStrategy.get(0));
    assertInstanceOf(ValidatorUiContentProvider.class, subProvidersModelStrategy.get(1));
    assertInstanceOf(ValidatorUiContentProvider.class, subProvidersModelStrategy.get(2));
    assertInstanceOf(ConverterUiContentProvider.class, subProvidersModelStrategy.get(3));
    // ---------------------------------------------------------------------------
    ChooseClassConfiguration afterConvertValidatorActualModel = getConfiguration(subProvidersModelStrategy.get(0));
    // 
    ChooseClassConfiguration afterConvertValidatorExpectedModel = new ChooseClassConfiguration();
    afterConvertValidatorExpectedModel.setDialogFieldLabel("AfterConvertValidator:");
    afterConvertValidatorExpectedModel.setValueScope("org.eclipse.core.databinding.validation.IValidator");
    afterConvertValidatorExpectedModel.setClearValue("N/S");
    afterConvertValidatorExpectedModel.setBaseClassName("org.eclipse.core.databinding.validation.IValidator");
    afterConvertValidatorExpectedModel.setConstructorParameters(ArrayUtils.EMPTY_CLASS_ARRAY);
    afterConvertValidatorExpectedModel.setEmptyClassErrorMessage("Model \"AfterConvertValidator\" class is empty.");
    afterConvertValidatorExpectedModel.setErrorMessagePrefix("Model \"AfterConvertValidator\"");
    // 
    assertEquals(afterConvertValidatorExpectedModel, afterConvertValidatorActualModel);
    // ---------------------------------------------------------------------------
    ChooseClassConfiguration afterGetValidatorActualModel = getConfiguration(subProvidersModelStrategy.get(1));
    // 
    ChooseClassConfiguration afterGetValidatorExpectedModel = new ChooseClassConfiguration();
    afterGetValidatorExpectedModel.setDialogFieldLabel("AfterGetValidator:");
    afterGetValidatorExpectedModel.setValueScope("org.eclipse.core.databinding.validation.IValidator");
    afterGetValidatorExpectedModel.setClearValue("N/S");
    afterGetValidatorExpectedModel.setBaseClassName("org.eclipse.core.databinding.validation.IValidator");
    afterGetValidatorExpectedModel.setConstructorParameters(ArrayUtils.EMPTY_CLASS_ARRAY);
    afterGetValidatorExpectedModel.setEmptyClassErrorMessage("Model \"AfterGetValidator\" class is empty.");
    afterGetValidatorExpectedModel.setErrorMessagePrefix("Model \"AfterGetValidator\"");
    // 
    assertEquals(afterGetValidatorExpectedModel, afterGetValidatorActualModel);
    // ---------------------------------------------------------------------------
    ChooseClassConfiguration beforeSetValidatorActualModel = getConfiguration(subProvidersModelStrategy.get(2));
    // 
    ChooseClassConfiguration beforeSetValidatorExpectedModel = new ChooseClassConfiguration();
    beforeSetValidatorExpectedModel.setDialogFieldLabel("BeforeSetValidator:");
    beforeSetValidatorExpectedModel.setValueScope("org.eclipse.core.databinding.validation.IValidator");
    beforeSetValidatorExpectedModel.setClearValue("N/S");
    beforeSetValidatorExpectedModel.setBaseClassName("org.eclipse.core.databinding.validation.IValidator");
    beforeSetValidatorExpectedModel.setConstructorParameters(ArrayUtils.EMPTY_CLASS_ARRAY);
    beforeSetValidatorExpectedModel.setEmptyClassErrorMessage("Model \"BeforeSetValidator\" class is empty.");
    beforeSetValidatorExpectedModel.setErrorMessagePrefix("Model \"BeforeSetValidator\"");
    // 
    assertEquals(beforeSetValidatorExpectedModel, beforeSetValidatorActualModel);
    // ---------------------------------------------------------------------------
    ChooseClassConfiguration converterActualModel = getConfiguration(subProvidersModelStrategy.get(3));
    // 
    ChooseClassConfiguration converterExpectedModel = new ChooseClassConfiguration();
    converterExpectedModel.setDialogFieldLabel("Converter:");
    converterExpectedModel.setValueScope("org.eclipse.core.databinding.conversion.IConverter");
    converterExpectedModel.setClearValue("N/S");
    converterExpectedModel.setBaseClassName("org.eclipse.core.databinding.conversion.IConverter");
    converterExpectedModel.setConstructorParameters(ArrayUtils.EMPTY_CLASS_ARRAY);
    converterExpectedModel.setEmptyClassErrorMessage("Model converter class is empty.");
    converterExpectedModel.setErrorMessagePrefix("Model converter");
    // 
    assertEquals(converterExpectedModel, converterActualModel);
    // ---------------------------------------------------------------------------
    assertInstanceOf(SeparatorUiContentProvider.class, providers.get(8));
    // ---------------------------------------------------------------------------
    assertInstanceOf(BindingContentProvider.class, providers.get(9));
}
Also used : DatabindingsProvider(org.eclipse.wb.internal.rcp.databinding.DatabindingsProvider) BindingInfo(org.eclipse.wb.internal.rcp.databinding.model.context.BindingInfo) IPageListener(org.eclipse.wb.internal.core.databinding.ui.editor.IPageListener) List(java.util.List) Image(org.eclipse.swt.graphics.Image) CompositeInfo(org.eclipse.wb.internal.swt.model.widgets.CompositeInfo) IUiContentProvider(org.eclipse.wb.internal.core.databinding.ui.editor.IUiContentProvider) ChooseClassConfiguration(org.eclipse.wb.internal.core.databinding.ui.editor.contentproviders.ChooseClassConfiguration)

Aggregations

List (java.util.List)1 Image (org.eclipse.swt.graphics.Image)1 IPageListener (org.eclipse.wb.internal.core.databinding.ui.editor.IPageListener)1 IUiContentProvider (org.eclipse.wb.internal.core.databinding.ui.editor.IUiContentProvider)1 ChooseClassConfiguration (org.eclipse.wb.internal.core.databinding.ui.editor.contentproviders.ChooseClassConfiguration)1 DatabindingsProvider (org.eclipse.wb.internal.rcp.databinding.DatabindingsProvider)1 BindingInfo (org.eclipse.wb.internal.rcp.databinding.model.context.BindingInfo)1 CompositeInfo (org.eclipse.wb.internal.swt.model.widgets.CompositeInfo)1