use of org.eclipse.wb.internal.swing.databinding.model.properties.PropertyInfo in project windowbuilder by eclipse.
the class DatabindingsProvider method createSwingBinding.
private IBindingInfo createSwingBinding(ObserveInfo component, ObserveInfo componentProperty, ObserveInfo model, ObserveInfo modelProperty) throws Exception {
// check swing binding type
if (componentProperty.getCreationType() != ObserveCreationType.SelfProperty) {
return null;
}
if (modelProperty.getCreationType() != ObserveCreationType.ListSelfProperty && modelProperty.getCreationType() != ObserveCreationType.ListProperty) {
return null;
}
// create strategy
UpdateStrategyInfo strategy = new UpdateStrategyInfo(UpdateStrategyInfo.Value.READ);
// create properties
PropertyInfo componentAstProperty = createProperty(component, componentProperty);
PropertyInfo modelAstProperty = createProperty(model, modelProperty);
// create binding
switch(component.getCreationType()) {
case JListBinding:
return new JListBindingInfo(strategy, component, componentProperty, componentAstProperty, model, modelProperty, modelAstProperty);
case JTableBinding:
return new JTableBindingInfo(strategy, component, componentProperty, componentAstProperty, model, modelProperty, modelAstProperty);
case JComboBoxBinding:
return new JComboBoxBindingInfo(strategy, component, componentProperty, componentAstProperty, model, modelProperty, modelAstProperty);
}
//
return null;
}
use of org.eclipse.wb.internal.swing.databinding.model.properties.PropertyInfo in project windowbuilder by eclipse.
the class DatabindingsProvider method createBinding.
public IBindingInfo createBinding(IObserveInfo target, IObserveInfo targetProperty, IObserveInfo model, IObserveInfo modelProperty) throws Exception {
// prepare ObserveInfo's
ObserveInfo targetObserve = (ObserveInfo) target;
ObserveInfo targetPropertyObserve = (ObserveInfo) targetProperty;
ObserveInfo modelObserve = (ObserveInfo) model;
ObserveInfo modelPropertyObserve = (ObserveInfo) modelProperty;
// check virtual bindings
if (targetObserve.getCreationType() == ObserveCreationType.VirtualBinding || modelObserve.getCreationType() == ObserveCreationType.VirtualBinding) {
return new VirtualBindingInfo(targetObserve, targetPropertyObserve, createProperty(targetObserve, targetPropertyObserve), modelObserve, modelPropertyObserve, createProperty(modelObserve, modelPropertyObserve));
}
// check swing bindings
if (targetObserve.getCreationType() != ObserveCreationType.AutoBinding) {
IBindingInfo binding = createSwingBinding(targetObserve, targetPropertyObserve, modelObserve, modelPropertyObserve);
if (binding != null) {
return binding;
}
}
if (modelObserve.getCreationType() != ObserveCreationType.AutoBinding) {
IBindingInfo binding = createSwingBinding(modelObserve, modelPropertyObserve, targetObserve, targetPropertyObserve);
if (binding != null) {
return binding;
}
}
// auto bindings
UpdateStrategyInfo strategy = new UpdateStrategyInfo(UpdateStrategyInfo.Value.READ);
PropertyInfo targetAstProperty = createProperty(targetObserve, targetPropertyObserve);
PropertyInfo modelAstProperty = createProperty(modelObserve, modelPropertyObserve);
//
return new AutoBindingInfo(strategy, targetObserve, targetPropertyObserve, targetAstProperty, modelObserve, modelPropertyObserve, modelAstProperty);
}
use of org.eclipse.wb.internal.swing.databinding.model.properties.PropertyInfo in project windowbuilder by eclipse.
the class DatabindingsProvider method createProperty.
private PropertyInfo createProperty(ObserveInfo observe, ObserveInfo observeProperty) throws Exception {
PropertyInfo astProperty = observeProperty.createProperty(observe);
//
if (observeProperty.canShared()) {
for (BindingInfo binding : m_rootInfo.getBindings()) {
// check target
PropertyInfo targetAstProperty = binding.getTargetAstProperty();
if (targetAstProperty.getClass() == astProperty.getClass()) {
if (binding.getTarget() == observe && binding.getTargetProperty() == observeProperty || targetAstProperty.canShared(astProperty)) {
return targetAstProperty;
}
}
// check model
PropertyInfo modelAstProperty = binding.getModelAstProperty();
if (modelAstProperty.getClass() == astProperty.getClass()) {
if (binding.getModel() == observe && binding.getModelProperty() == observeProperty || modelAstProperty.canShared(astProperty)) {
return modelAstProperty;
}
}
}
}
//
return astProperty;
}
use of org.eclipse.wb.internal.swing.databinding.model.properties.PropertyInfo in project windowbuilder by eclipse.
the class DataBindingsRootInfo method createAutoBindingForObjectToProperty.
/**
* Bindings.createAutoBinding(UpdateStrategy, SS, TS, Property<TS, TV>, [String])
*/
private BindingInfo createAutoBindingForObjectToProperty(AstEditor editor, String signature, MethodInvocation invocation, Expression[] arguments, IModelResolver resolver) throws Exception {
// strategy
UpdateStrategyInfo strategyInfo = createStrategy(arguments[0]);
// model object
ObserveInfo model = getObserveInfo(arguments[1]);
if (model == null) {
AbstractParser.addError(editor, MessageFormat.format(Messages.DataBindingsRootInfo_errModelArgumentNotFound, arguments[1]), new Throwable());
return null;
}
// model properties
IGenericType[] types = GenericUtils.getReturnTypeArguments(editor, invocation, 3);
PropertyInfo modelAstProperty = new ObjectPropertyInfo(types[0]);
ObserveInfo modelProperty = modelAstProperty.getObserveProperty(model);
Assert.isNotNull(modelProperty);
assertEquals(modelProperty, modelAstProperty);
// target object
ObserveInfo target = getObserveInfo(arguments[2]);
if (target == null) {
AbstractParser.addError(editor, MessageFormat.format(Messages.DataBindingsRootInfo_errTargetArgumentNotFound, arguments[2]), new Throwable());
return null;
}
// target AST property
PropertyInfo targetAstProperty = (PropertyInfo) resolver.getModel(arguments[3]);
if (targetAstProperty == null) {
AbstractParser.addError(editor, MessageFormat.format(Messages.DataBindingsRootInfo_errTargetPropertyArgumentNotFound, arguments[3]), new Throwable());
return null;
}
// target property
ObserveInfo targetProperty = targetAstProperty.getObserveProperty(target);
if (targetProperty == null) {
AbstractParser.addError(editor, MessageFormat.format(Messages.DataBindingsRootInfo_errTargetProperty2NotFound, arguments[2], arguments[3]), new Throwable());
targetProperty = createDefaultProperty(targetAstProperty);
} else {
assertObserves(types, 1, target, targetAstProperty, targetProperty);
}
// binding
return addBinding(editor, signature, arguments, new AutoBindingInfo(strategyInfo, target, targetProperty, targetAstProperty, model, modelProperty, modelAstProperty));
}
use of org.eclipse.wb.internal.swing.databinding.model.properties.PropertyInfo in project windowbuilder by eclipse.
the class DataBindingsRootInfo method createBindingForListPropertyToJComponent.
/**
* SwingBindings.createJListBinding(UpdateStrategy, SS, Property<SS, List<E>>, JList, [String]) <br>
* SwingBindings.createJTableBinding(UpdateStrategy, SS, Property<SS, List<E>>, JTable, [String])<br>
* SwingBindings.createJComboBoxBinding(UpdateStrategy, SS, Property<SS, List<E>>, JComboBox,
* [String])
*/
private BindingInfo createBindingForListPropertyToJComponent(AstEditor editor, String signature, MethodInvocation invocation, Expression[] arguments, IModelResolver resolver, Constructor<? extends BindingInfo> constructor) throws Exception {
// strategy
UpdateStrategyInfo strategyInfo = createStrategy(arguments[0]);
// model object
ObserveInfo model = getObserveInfo(arguments[1]);
if (model == null) {
AbstractParser.addError(editor, MessageFormat.format(Messages.DataBindingsRootInfo_errModelArgumentNotFound, arguments[1]), new Throwable());
return null;
}
// model AST property
IGenericType[] types = GenericUtils.getReturnTypeArguments(editor, invocation, 2);
GenericUtils.assertEquals(model.getObjectType(), types[1]);
PropertyInfo modelAstProperty = (PropertyInfo) resolver.getModel(arguments[2]);
if (modelAstProperty == null) {
AbstractParser.addError(editor, MessageFormat.format(Messages.DataBindingsRootInfo_errModelPropertyArgumentNotFound, arguments[2]), new Throwable());
return null;
}
// model property
ObserveInfo modelProperty = modelAstProperty.getObserveProperty(model);
if (modelProperty == null) {
AbstractParser.addError(editor, MessageFormat.format(Messages.DataBindingsRootInfo_errModelProperty2NotFound, arguments[1], arguments[2]), new Throwable());
modelProperty = createDefaultProperty(modelAstProperty);
}
// target object
ObserveInfo target = getComponentObserveInfo(arguments[3]);
if (target == null) {
AbstractParser.addError(editor, MessageFormat.format(Messages.DataBindingsRootInfo_errTargetArgumentNotFound, arguments[3]), new Throwable());
return null;
}
// target properties
PropertyInfo targetAstProperty = new ObjectPropertyInfo(target.getObjectType());
ObserveInfo targetProperty = targetAstProperty.getObserveProperty(target);
Assert.isNotNull(targetProperty);
assertEquals(targetProperty, targetAstProperty);
//
Assert.isTrue(DatabindingsProvider.isSwingBinding(model, modelProperty) != DatabindingsProvider.isSwingBinding(target, targetProperty));
// binding
return addBinding(editor, signature, arguments, constructor.newInstance(strategyInfo, target, targetProperty, targetAstProperty, model, modelProperty, modelAstProperty));
}
Aggregations