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);
}
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));
}
}
}
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;
}
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;
}
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();
}
Aggregations