&& constraintType != null && constraintType == Class.class) {
DocumentObject[] children = element.getChildren();
if (children != null && children.length > 0) {
if (children[0] instanceof Element) {
Element type = (Element) children[0];
IMetaclass metaclass = loader.getMetaclass(type
.getName(), type.getNamespace());
if (metaclass != null) {
return metaclass.getType();
}
}
} else {
String content = element.getContent();
return loader.convertFrom(Class.class, content);
}
}
return null;
}
IMetaclass metaclass = loader.getMetaclass(name, namespace);
if (constraintType != null
&& !(IBinding.class.isAssignableFrom(metaclass.getType()))
&& (!constraintType.isAssignableFrom(metaclass.getType()))) {
if (!constraintType.isArray()
|| !constraintType.getComponentType().isAssignableFrom(
metaclass.getType())) {
return null;
}
}
Object targetObject = null;
Integer styleValue = getStyleValue(element, styles);
if (parent == null || metaclass.getType() == Shell.class) {
if (dataBindingTrack != null) {
dataBindingTrack.addWidgetElement(element);
}
Shell shell = null;
if (styleValue == null || styleValue == -1) {
styleValue = SWT.CLOSE | SWT.TITLE | SWT.MIN | SWT.MAX
| SWT.RESIZE;
}
Display display = Display.getDefault();
shell = new Shell(display, styleValue);
targetObject = shell;
invokeCreatededAction(element, targetObject);
loadData.setCurrentWidget(shell);
if (metaclass.getType() != Shell.class) {
shell.setLayout(new FillLayout());
return doCreate(targetObject, element, constraintType, options);
} else {
if (bindingContext != null) {
setBindingContext(metaclass, targetObject, dico,
bindingContext);
}
if (dataContext != null) {
setDataContext(metaclass, targetObject, dico, dataContext);
}
}
pushStack(parent);
// for Shell
Attribute classAttribute = element.getAttribute(
IConstants.XWT_X_NAMESPACE, IConstants.XAML_X_CLASS);
if (classAttribute != null) {
String className = classAttribute.getContent();
loadShellCLR(className, shell);
}
} else {
pushStack(parent);
//
// load the content in case of UserControl
//
Class<?> type = metaclass.getType();
URL file = type.getResource(type.getSimpleName()
+ IConstants.XWT_EXTENSION_SUFFIX);
if (file != null && nameScoped != null) {
if (parent instanceof Composite) {
Object childDataContext = getDataContext(element,
(Widget) parent);
Object childBindingContext = getBindingContext(element,
(Widget) parent);
if (dataContext != null) {
childDataContext = dataContext;
}
if (bindingContext != null) {
childBindingContext = bindingContext;
}
Map<String, Object> nestedOptions = new HashMap<String, Object>();
nestedOptions.put(IXWTLoader.CONTAINER_PROPERTY, parent);
if (styleValue != null) {
nestedOptions.put(IXWTLoader.INIT_STYLE_PROPERTY,
styleValue);
}
nestedOptions.put(IXWTLoader.DATACONTEXT_PROPERTY,
childDataContext);
nestedOptions.put(IXWTLoader.BINDING_CONTEXT_PROPERTY,
childBindingContext);
nestedOptions.put(RESOURCE_LOADER_PROPERTY, this);
targetObject = loader.loadWithOptions(file, nestedOptions);
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());
}