if (targetObject == null) {
return null;
}
invokeCreatededAction(element, targetObject);
} else
throw new XWTException(
"Cannot add user control: Parent is not a composite");
} else {
Object[] parameters = null;
if (TableViewerColumn.class.isAssignableFrom(type)) {
int columnIndex = getColumnIndex(element);
parameters = (styleValue != null ? new Object[] { parent,
styleValue, columnIndex } : new Object[] { parent,
SWT.NONE, columnIndex });
} else {
parameters = (styleValue != null ? new Object[] { parent,
styleValue } : new Object[] { parent });
}
// x:Class
{
Attribute classAttribute = element
.getAttribute(IConstants.XWT_X_NAMESPACE,
IConstants.XAML_X_CLASS);
if (classAttribute != null) {
String className = classAttribute.getContent();
targetObject = loadCLR(className, parameters, metaclass
.getType(), options);
} else {
Object clr = options.get(XWTLoader.CLASS_PROPERTY);
if (clr != null) {
loadData.setClr(clr);
}
}
if (targetObject == null) {
targetObject = metaclass.newInstance(parameters);
invokeCreatededAction(element, targetObject);
Widget widget = UserData.getWidget(targetObject);
if (widget != null) {
Object clr = loadData.getClr();
if (clr != null) {
UserData.setCLR(widget, clr);
}
}
} else {
metaclass = loader.getMetaclass(targetObject);
}
}
if (targetObject == null) {
return null;
}
}
}
Widget widget = UserData.getWidget(targetObject);
if (widget != null) {
loadData.setCurrentWidget(targetObject);
}
if (scopedObject == null && widget != null) {
scopedObject = widget;
nameScoped = new ScopeKeeper((parent == null ? null : UserData
.findScopeKeeper((Widget) parent)), widget);
UserData.bindNameContext((Widget) widget, nameScoped);
}
// set first data context and resource dictionary
setDataContext(metaclass, targetObject, dico, dataContext);
if (bindingContext != null) {
setBindingContext(metaclass, targetObject, dico, bindingContext);
}
applyStyles(element, targetObject);
if (dataBindingTrack != null) {
dataBindingTrack.tracking(targetObject, element, dataContext);
}
// set parent relationship and viewer
if (targetObject instanceof Widget) {
if (parent != null) {
UserData.setParent(targetObject, parent);
}
} else if (JFacesHelper.isViewer(targetObject)) {
UserData.setParent(targetObject, parent);
UserData.setViewer(targetObject, targetObject);
} else if (targetObject instanceof TableItemProperty.Cell) {
((TableItemProperty.Cell) targetObject)
.setParent((TableItem) parent);
}
for (Map.Entry<String, Object> entry : options.entrySet()) {
String key = entry.getKey();
if (IXWTLoader.CONTAINER_PROPERTY.equalsIgnoreCase(key)
|| IXWTLoader.INIT_STYLE_PROPERTY.equalsIgnoreCase(key)
|| IXWTLoader.DATACONTEXT_PROPERTY.equalsIgnoreCase(key)
|| IXWTLoader.BINDING_CONTEXT_PROPERTY
.equalsIgnoreCase(key)
|| IXWTLoader.RESOURCE_DICTIONARY_PROPERTY
.equalsIgnoreCase(key)
|| IXWTLoader.CLASS_PROPERTY.equalsIgnoreCase(key)
|| IXWTLoader.LOADED_CALLBACK.equalsIgnoreCase(key)
|| IXWTLoader.CREATED_CALLBACK.equalsIgnoreCase(key)
|| IXWTLoader.BEFORE_PARSING_CALLBACK.equalsIgnoreCase(key)
|| IXWTLoader.DESIGN_MODE_PROPERTY.equalsIgnoreCase(key)) {
continue;
}
IProperty property = metaclass.findProperty(key);
if (property == null) {
throw new XWTException("Property " + key + " not found.");
}
property.setValue(targetObject, entry.getValue());
}
List<String> delayedAttributes = new ArrayList<String>();
init(metaclass, targetObject, element, delayedAttributes);
if (targetObject instanceof Style && element.getChildren().length > 0) {
Collection<Setter> setters = new ArrayList<Setter>();
for (DocumentObject doc : element.getChildren()) {
Object child = doCreate(targetObject, (Element) doc, null,
Collections.EMPTY_MAP);
if (!(child instanceof Setter)) {
throw new XWTException("Setter is expected in Style.");
}
setters.add((Setter) child);
}
((Style) targetObject).setSetters(setters
.toArray(new Setter[setters.size()]));