Search in sources :

Example 11 with IUiContentProvider

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

the class UiConfigurationTest method test_UpdateValueStrategy.

public void test_UpdateValueStrategy() 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());
    // 
    List<IUiContentProvider> providers = Lists.newArrayList();
    BindingUiContentProviderContext context = new BindingUiContentProviderContext();
    context.setDirection("Target");
    // 
    binding.getTargetStrategy().createContentProviders(providers, context);
    assertEquals(2, providers.size());
    // ---------------------------------------------------------------------------
    assertInstanceOf(UpdateStrategyUiContentProvider.class, providers.get(0));
    assertInstanceOf(ChooseClassConfiguration.class, ReflectionUtils.getFieldObject(providers.get(0), "m_configuration"));
    ChooseClassConfiguration actual = getConfiguration(providers.get(0));
    // 
    ChooseClassConfiguration expected = new ChooseClassConfiguration();
    expected.setDialogFieldLabel("UpdateValueStrategy:");
    expected.setDefaultValues(new String[] { "POLICY_UPDATE", "POLICY_NEVER", "POLICY_ON_REQUEST", "POLICY_CONVERT" });
    expected.setValueScope("org.eclipse.core.databinding.UpdateValueStrategy");
    expected.setRetargetClassName("org.eclipse.core.databinding.UpdateValueStrategy", "POLICY_UPDATE");
    expected.setBaseClassName("org.eclipse.core.databinding.UpdateValueStrategy");
    expected.setConstructorParameters(ArrayUtils.EMPTY_CLASS_ARRAY);
    expected.setEmptyClassErrorMessage("Target strategy class is empty.");
    expected.setErrorMessagePrefix("Target strategy");
    // 
    assertEquals(expected, actual);
    // ---------------------------------------------------------------------------
    assertInstanceOf(UpdateStrategyPropertiesUiContentProvider.class, providers.get(1));
    // 
    List<IUiContentProvider> subProviders = (List<IUiContentProvider>) ReflectionUtils.getFieldObject(providers.get(1), "m_providers");
    assertEquals(4, subProviders.size());
    assertInstanceOf(ValidatorUiContentProvider.class, subProviders.get(0));
    assertInstanceOf(ValidatorUiContentProvider.class, subProviders.get(1));
    assertInstanceOf(ValidatorUiContentProvider.class, subProviders.get(2));
    assertInstanceOf(ConverterUiContentProvider.class, subProviders.get(3));
    // ---------------------------------------------------------------------------
    ChooseClassConfiguration afterConvertValidatorActual = getConfiguration(subProviders.get(0));
    // 
    ChooseClassConfiguration afterConvertValidatorExpected = new ChooseClassConfiguration();
    afterConvertValidatorExpected.setDialogFieldLabel("AfterConvertValidator:");
    afterConvertValidatorExpected.setValueScope("org.eclipse.core.databinding.validation.IValidator");
    afterConvertValidatorExpected.setClearValue("N/S");
    afterConvertValidatorExpected.setBaseClassName("org.eclipse.core.databinding.validation.IValidator");
    afterConvertValidatorExpected.setConstructorParameters(ArrayUtils.EMPTY_CLASS_ARRAY);
    afterConvertValidatorExpected.setEmptyClassErrorMessage(context.getDirection() + " \"AfterConvertValidator\" class is empty.");
    afterConvertValidatorExpected.setErrorMessagePrefix(context.getDirection() + " \"AfterConvertValidator\"");
    // 
    assertEquals(afterConvertValidatorExpected, afterConvertValidatorActual);
    // ---------------------------------------------------------------------------
    ChooseClassConfiguration afterGetValidatorActual = getConfiguration(subProviders.get(1));
    // 
    ChooseClassConfiguration afterGetValidatorExpected = new ChooseClassConfiguration();
    afterGetValidatorExpected.setDialogFieldLabel("AfterGetValidator:");
    afterGetValidatorExpected.setValueScope("org.eclipse.core.databinding.validation.IValidator");
    afterGetValidatorExpected.setClearValue("N/S");
    afterGetValidatorExpected.setBaseClassName("org.eclipse.core.databinding.validation.IValidator");
    afterGetValidatorExpected.setConstructorParameters(ArrayUtils.EMPTY_CLASS_ARRAY);
    afterGetValidatorExpected.setEmptyClassErrorMessage(context.getDirection() + " \"AfterGetValidator\" class is empty.");
    afterGetValidatorExpected.setErrorMessagePrefix(context.getDirection() + " \"AfterGetValidator\"");
    // 
    assertEquals(afterGetValidatorExpected, afterGetValidatorActual);
    // ---------------------------------------------------------------------------
    ChooseClassConfiguration beforeSetValidatorActual = getConfiguration(subProviders.get(2));
    // 
    ChooseClassConfiguration beforeSetValidatorExpected = new ChooseClassConfiguration();
    beforeSetValidatorExpected.setDialogFieldLabel("BeforeSetValidator:");
    beforeSetValidatorExpected.setValueScope("org.eclipse.core.databinding.validation.IValidator");
    beforeSetValidatorExpected.setClearValue("N/S");
    beforeSetValidatorExpected.setBaseClassName("org.eclipse.core.databinding.validation.IValidator");
    beforeSetValidatorExpected.setConstructorParameters(ArrayUtils.EMPTY_CLASS_ARRAY);
    beforeSetValidatorExpected.setEmptyClassErrorMessage(context.getDirection() + " \"BeforeSetValidator\" class is empty.");
    beforeSetValidatorExpected.setErrorMessagePrefix(context.getDirection() + " \"BeforeSetValidator\"");
    // 
    assertEquals(beforeSetValidatorExpected, beforeSetValidatorActual);
    // ---------------------------------------------------------------------------
    ChooseClassConfiguration converterActual = getConfiguration(subProviders.get(3));
    // 
    ChooseClassConfiguration converterExpected = new ChooseClassConfiguration();
    converterExpected.setDialogFieldLabel("Converter:");
    converterExpected.setValueScope("org.eclipse.core.databinding.conversion.IConverter");
    converterExpected.setClearValue("N/S");
    converterExpected.setBaseClassName("org.eclipse.core.databinding.conversion.IConverter");
    converterExpected.setConstructorParameters(ArrayUtils.EMPTY_CLASS_ARRAY);
    converterExpected.setEmptyClassErrorMessage("Target converter class is empty.");
    converterExpected.setErrorMessagePrefix("Target converter");
    // 
    assertEquals(converterExpected, converterActual);
}
Also used : BindingUiContentProviderContext(org.eclipse.wb.internal.rcp.databinding.model.context.BindingUiContentProviderContext) DatabindingsProvider(org.eclipse.wb.internal.rcp.databinding.DatabindingsProvider) BindingInfo(org.eclipse.wb.internal.rcp.databinding.model.context.BindingInfo) List(java.util.List) 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)

Example 12 with IUiContentProvider

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

the class AbstractViewerInputBindingInfo method createContentProviders.

// //////////////////////////////////////////////////////////////////////////
// 
// Editing
// 
// //////////////////////////////////////////////////////////////////////////
@Override
public void createContentProviders(List<IUiContentProvider> providers, IPageListener listener, DatabindingsProvider provider) throws Exception {
    if (m_isColumnViewer) {
        List<WidgetBindableInfo> viewerColumns = Lists.newArrayList();
        // prepare viewer columns
        WidgetBindableInfo viewerControlBindable = (WidgetBindableInfo) m_viewerBindable.getParent();
        for (IObserveInfo observe : viewerControlBindable.getChildren(ChildrenContext.ChildrenForMasterTable)) {
            WidgetBindableInfo widgetBindable = (WidgetBindableInfo) observe;
            // extract columns
            if (widgetBindable.getJavaInfo() instanceof ItemInfo) {
                for (IObserveInfo subObserve : widgetBindable.getChildren(ChildrenContext.ChildrenForMasterTable)) {
                    WidgetBindableInfo subWidgetBindable = (WidgetBindableInfo) subObserve;
                    // extract viewer columns
                    if (subWidgetBindable.getJavaInfo() instanceof ViewerColumnInfo) {
                        viewerColumns.add(subWidgetBindable);
                    }
                }
            }
        }
        // 
        if (!viewerColumns.isEmpty()) {
            // prepare element type provider
            VirtualEditingSupportInfo.IElementTypeProvider elementTypeProvider = null;
            for (IUiContentProvider contentProvider : providers) {
                // wrap Viewer editor
                if (contentProvider instanceof InputElementUiContentProvider) {
                    final InputElementUiContentProvider inputElementContentProvider = (InputElementUiContentProvider) contentProvider;
                    elementTypeProvider = new VirtualEditingSupportInfo.IElementTypeProvider() {

                        @Override
                        public Class<?> getElementType() throws Exception {
                            return inputElementContentProvider.getChoosenClass();
                        }
                    };
                    break;
                }
                // wrap TreeViewer editor
                if (contentProvider instanceof TreeInputElementUiContentProvider) {
                    final TreeInputElementUiContentProvider inputElementContentProvider = (TreeInputElementUiContentProvider) contentProvider;
                    elementTypeProvider = new VirtualEditingSupportInfo.IElementTypeProvider() {

                        @Override
                        public Class<?> getElementType() throws Exception {
                            return inputElementContentProvider.getCurrentElementType();
                        }
                    };
                    break;
                }
            }
            // prepare configuration
            ViewerColumnsConfiguration configuration = new ViewerColumnsConfiguration(this, elementTypeProvider, viewerColumns, m_editingSupports);
            // prepare provider
            providers.add(new ViewerColumnsUiContentProvider(configuration));
        }
    }
}
Also used : IObserveInfo(org.eclipse.wb.internal.core.databinding.model.IObserveInfo) ItemInfo(org.eclipse.wb.internal.swt.model.widgets.ItemInfo) IUiContentProvider(org.eclipse.wb.internal.core.databinding.ui.editor.IUiContentProvider) ViewerColumnsUiContentProvider(org.eclipse.wb.internal.rcp.databinding.ui.contentproviders.ViewerColumnsUiContentProvider) ViewerColumnInfo(org.eclipse.wb.internal.rcp.model.jface.viewers.ViewerColumnInfo) TreeInputElementUiContentProvider(org.eclipse.wb.internal.rcp.databinding.ui.contentproviders.TreeInputElementUiContentProvider) ViewerColumnsConfiguration(org.eclipse.wb.internal.rcp.databinding.ui.contentproviders.ViewerColumnsConfiguration) TreeInputElementUiContentProvider(org.eclipse.wb.internal.rcp.databinding.ui.contentproviders.TreeInputElementUiContentProvider) InputElementUiContentProvider(org.eclipse.wb.internal.rcp.databinding.ui.contentproviders.InputElementUiContentProvider) WidgetBindableInfo(org.eclipse.wb.internal.rcp.databinding.model.widgets.bindables.WidgetBindableInfo)

Example 13 with IUiContentProvider

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

the class DatabindingsProvider method getContentProviders.

// //////////////////////////////////////////////////////////////////////////
// 
// UI editing
// 
// //////////////////////////////////////////////////////////////////////////
@Override
public List<IUiContentProvider> getContentProviders(IBindingInfo ibinding, IPageListener listener) throws Exception {
    List<IUiContentProvider> providers = Lists.newArrayList();
    BindingInfo binding = (BindingInfo) ibinding;
    binding.createContentProviders(providers, listener, this);
    return providers;
}
Also used : BindingInfo(org.eclipse.wb.internal.rcp.databinding.xwt.model.BindingInfo) IBindingInfo(org.eclipse.wb.internal.core.databinding.model.IBindingInfo) AbstractBindingInfo(org.eclipse.wb.internal.rcp.databinding.model.AbstractBindingInfo) IUiContentProvider(org.eclipse.wb.internal.core.databinding.ui.editor.IUiContentProvider)

Example 14 with IUiContentProvider

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

the class DatabindingsProvider method getContentProviders.

// //////////////////////////////////////////////////////////////////////////
// 
// Editing
// 
// //////////////////////////////////////////////////////////////////////////
public List<IUiContentProvider> getContentProviders(IBindingInfo ibinding, IPageListener listener) throws Exception {
    List<IUiContentProvider> providers = Lists.newArrayList();
    BindingInfo binding = (BindingInfo) ibinding;
    binding.createContentProviders(m_rootInfo.getBindings(), providers, listener, this);
    return providers;
}
Also used : JTableBindingInfo(org.eclipse.wb.internal.swing.databinding.model.bindings.JTableBindingInfo) JComboBoxBindingInfo(org.eclipse.wb.internal.swing.databinding.model.bindings.JComboBoxBindingInfo) ColumnBindingInfo(org.eclipse.wb.internal.swing.databinding.model.bindings.ColumnBindingInfo) BindingInfo(org.eclipse.wb.internal.swing.databinding.model.bindings.BindingInfo) JListBindingInfo(org.eclipse.wb.internal.swing.databinding.model.bindings.JListBindingInfo) DetailBindingInfo(org.eclipse.wb.internal.swing.databinding.model.bindings.DetailBindingInfo) AutoBindingInfo(org.eclipse.wb.internal.swing.databinding.model.bindings.AutoBindingInfo) VirtualBindingInfo(org.eclipse.wb.internal.swing.databinding.model.bindings.VirtualBindingInfo) IBindingInfo(org.eclipse.wb.internal.core.databinding.model.IBindingInfo) IUiContentProvider(org.eclipse.wb.internal.core.databinding.ui.editor.IUiContentProvider)

Example 15 with IUiContentProvider

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

the class TabContainerUiContentProvider method updateFromObject.

// //////////////////////////////////////////////////////////////////////////
// 
// Update
// 
// //////////////////////////////////////////////////////////////////////////
protected final void updateFromObject(List<IUiContentProvider> providers) throws Exception {
    if (providers.isEmpty() && m_configuration.isCreateEmptyPage()) {
        createEmptyPage();
    } else {
        boolean selection = true;
        for (IUiContentProvider contentProvider : providers) {
            createPage(-1, contentProvider, selection);
            selection = false;
        }
        configure();
    }
    m_listener.calculateFinish();
}
Also used : IUiContentProvider(org.eclipse.wb.internal.core.databinding.ui.editor.IUiContentProvider)

Aggregations

IUiContentProvider (org.eclipse.wb.internal.core.databinding.ui.editor.IUiContentProvider)22 List (java.util.List)6 Point (org.eclipse.swt.graphics.Point)5 ChooseClassConfiguration (org.eclipse.wb.internal.core.databinding.ui.editor.contentproviders.ChooseClassConfiguration)5 DatabindingsProvider (org.eclipse.wb.internal.rcp.databinding.DatabindingsProvider)5 BindingInfo (org.eclipse.wb.internal.rcp.databinding.model.context.BindingInfo)5 CompositeInfo (org.eclipse.wb.internal.swt.model.widgets.CompositeInfo)5 BindingUiContentProviderContext (org.eclipse.wb.internal.rcp.databinding.model.context.BindingUiContentProviderContext)4 ColumnBindingInfo (org.eclipse.wb.internal.swing.databinding.model.bindings.ColumnBindingInfo)3 IBindingInfo (org.eclipse.wb.internal.core.databinding.model.IBindingInfo)2 UiContentProviderComposite (org.eclipse.wb.internal.core.databinding.ui.editor.UiContentProviderComposite)2 AbstractBindingInfo (org.eclipse.wb.internal.rcp.databinding.model.AbstractBindingInfo)2 KnownElementsObservableInfo (org.eclipse.wb.internal.rcp.databinding.model.widgets.input.KnownElementsObservableInfo)2 BeansListObservableFactoryInfo (org.eclipse.wb.internal.rcp.databinding.model.widgets.input.designer.BeansListObservableFactoryInfo)2 BeansObservableFactoryInfo (org.eclipse.wb.internal.rcp.databinding.model.widgets.input.designer.BeansObservableFactoryInfo)2 BeansSetObservableFactoryInfo (org.eclipse.wb.internal.rcp.databinding.model.widgets.input.designer.BeansSetObservableFactoryInfo)2 TreeObservableLabelProviderInfo (org.eclipse.wb.internal.rcp.databinding.model.widgets.input.designer.TreeObservableLabelProviderInfo)2 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)1 CTabItem (org.eclipse.swt.custom.CTabItem)1 ScrolledComposite (org.eclipse.swt.custom.ScrolledComposite)1