Package org.eclipse.e4.xwt.metadata

Examples of org.eclipse.e4.xwt.metadata.IMetaclass


        if (clr instanceof Widget) {
          UserData.setCLR((Widget) clr, clr);
        }
      } else if (currentTagType != null
          && currentTagType.isAssignableFrom(type)) {
        IMetaclass metaclass = loader.getMetaclass(type);
        Object instance = metaclass.newInstance(parameters);
        loadData.setClr(instance);
        // use x:Class's instance
        if (instance instanceof Widget) {
          UserData.setCLR((Widget) instance, instance);
        }
View Full Code Here


  protected void initAttribute(IMetaclass metaclass, Object targetObject,
      Element element, String namespace, String attrName)
      throws Exception {
    if (attrName.indexOf('.') != -1) {
      String[] segments = attrName.split("\\.");
      IMetaclass currentMetaclass = metaclass;
      Object target = targetObject;
      for (int i = 0; i < segments.length - 1; i++) {
        IProperty property = currentMetaclass.findProperty(segments[i]);
        if (property != null) {
          target = property.getValue(target);
          if (target == null) {
            LoggerManager.log(new XWTException("Property \""
                + segments[i] + "\" is null."));
View Full Code Here

      String namePrefix = attribute.getNamePrefix();
      if (namePrefix == null) {
        property = metaclass.findProperty(propertyName);
      } else {
        //
        IMetaclass metaclassAttached = loader.getMetaclass(namePrefix,
            attribute.getNamespace());
        if (metaclassAttached != null) {
          property = metaclassAttached.findProperty(propertyName);
          isAttached = true;
        } else {
          LoggerManager.log(attribute.getNamespace() + " -> "
              + namePrefix + " is not found.");
          return;
        }
      }
    }

    if (propertyName.equals(IConstants.XAML_DATA_CONTEXT)) {
      property = null;
    }
    if (IConstants.XAML_COMMAND.equalsIgnoreCase(propertyName)
        && ICommand.class.isAssignableFrom(property.getType())
        && (target instanceof Widget)) {
      addCommandExecuteListener(attribute.getContent(), (Widget) target);
    }
    if (property == null) {
      if (options.get(IXWTLoader.DESIGN_MODE_PROPERTY) == Boolean.TRUE) {
        return;
      }
      // prepare event
      IEvent event = metaclass.findEvent(attrName);
      if (event == null) {
        return;
      }
      // add events for controls and items.
      if (!(target instanceof Widget)) {
        return;
      }
      loadData.updateEvent(context, (Widget) target, event, attribute
          .getContent());
      return;
    }

    String contentValue = attribute.getContent();
    if ("MenuItem".equalsIgnoreCase(element.getName())
        && "Text".equalsIgnoreCase(attrName)) {
      Attribute attributeAccelerator = element
          .getAttribute("Accelerator");
      if (attributeAccelerator != null) {
        contentValue = contentValue + '\t'
            + getContentValue(attributeAccelerator.getContent());
      }
    }

    if (contentValue != null && "Accelerator".equalsIgnoreCase(attrName)) {
      contentValue = XWTMaps.getCombAccelerator(contentValue);
      if (contentValue.contains("'")) {
        contentValue = removeSubString(contentValue, "'");
      }
    }
    if (contentValue != null
        && (Image.class.isAssignableFrom(property.getType()))) {
      contentValue = getImagePath(attribute, contentValue);
    }
    if (contentValue != null
        && (URL.class.isAssignableFrom(property.getType()))) {
      contentValue = getSourceURL(contentValue);
    }
    Object value = null;
    DocumentObject[] children = attribute.getChildren();
    boolean usingExistingValue = false;
    if (contentValue == null) {
      Class<?> type = property.getType();
      if (Collection.class.isAssignableFrom(type)) {
        value = getCollectionProperty(type, target, attribute, attrName);
      } else {
        Object directTarget = null;
        if (TableViewerColumn.class.isAssignableFrom(type)
            && attrName.equalsIgnoreCase("columns")) {
          children = DocumentObjectSorter.sortWithAttr(children,
              "Index").toArray(
              new DocumentObject[children.length]);
        } else {
          try {
            Object propertyValue = property.getValue(target);
            if (UserData.getWidget(propertyValue) != null) {
              directTarget = propertyValue;
              // use the existing property value as parent,
              // not need to add the constraint
              if (!property.isValueAsParent()) {
                type = null;
                usingExistingValue = true;
              }
            }
          } catch (Exception e) {
          }
        }
        if (directTarget == null) {
          directTarget = target;
        }

        for (DocumentObject child : children) {
          String name = child.getName();
          String ns = child.getNamespace();
          if (name.equalsIgnoreCase(IConstants.XAML_X_STATIC)
              && ns.equals(IConstants.XWT_X_NAMESPACE)) {
            value = getStaticValue(child);
          } else if (name
              .equalsIgnoreCase(IConstants.XAML_STATICRESOURCES)
              && ns.equals(IConstants.XWT_NAMESPACE)) {
            String key = child.getContent();
            value = new StaticResourceBinding(loadData
                .getCurrentWidget(), key);
          } else if ((IConstants.XWT_X_NAMESPACE.equals(ns) && IConstants.XAML_X_ARRAY
              .equalsIgnoreCase(name))) {
            value = getArrayProperty(property.getType(),
                directTarget, child, name);
          } else if (property.getType().isArray()) {
            value = getArrayProperty(property.getType(),
                directTarget, attribute, name);
            break;
          } else if (isAssignableFrom(element, TableColumn.class)
              && isAssignableFrom(child, TableEditor.class)) {
            value = child;
          } else if (TableViewerColumn.class
              .isAssignableFrom(property.getType())
              && attribute.getContent() != null) {
            value = attribute.getContent();
          } else {
            if ("Null".equals(child.getName()) && IConstants.XWT_X_NAMESPACE.equals(child.getNamespace())) {
              property.setValue(directTarget, null);
              return;
            } else {
              value = doCreate(directTarget, (Element) child, type,
                  EMPTY_MAP);
              if (value == null
                  && type != null
                  && !(type == Table.class
                      && "TableColumn"
                          .equals(child.getName()) && Table.class
                      .isInstance(directTarget))) {
                throw new XWTException(child.getName()
                    + " cannot be a content of "
                    + type.getName() + " "
                    + target.getClass().getName() + "."
                    + property.getName());
              }
              if (value instanceof IDynamicBinding) {
                ((IDynamicBinding) value).setType(attrName);
              }
            }
          }
        }
      }
    }
    if (contentValue != null && value == null
        && !IConstants.XAML_COMMAND.equalsIgnoreCase(propertyName)) {
      if (property.getType().isInstance(Class.class)) {
        int index = contentValue.lastIndexOf(':');
        if (index != -1) {
          String prefix = contentValue.substring(0, index);
          contentValue = findNamespace(attribute, prefix)
              + contentValue.substring(index);
        }
      }
      value = loader.convertFrom(property.getType(), contentValue);
    }
    if (!usingExistingValue) {
      if (value != null) {
        Class<?> propertyType = property.getType();
        if (!propertyType.isAssignableFrom(value.getClass())
            || (value instanceof IBinding && !(IBinding.class
                .isAssignableFrom(propertyType)))) {
          Object orginalValue = value;
          IConverter converter = loader.findConvertor(value
              .getClass(), propertyType);
          if (converter != null) {
            value = converter.convert(value);
            if (value != null
                && orginalValue instanceof IBinding
                && !propertyType.isAssignableFrom(value
                    .getClass())) {
              converter = loader.findConvertor(value.getClass(),
                  propertyType);
              if (converter != null) {
                value = converter.convert(value);
              } else {
                LoggerManager.log(new XWTException("Convertor "
                    + value.getClass().getSimpleName()
                    + "->" + propertyType.getSimpleName()
                    + " is not found"));
              }
            }
          } else {
            LoggerManager.log(new XWTException("Convertor "
                + value.getClass().getSimpleName() + "->"
                + propertyType.getSimpleName()
                + " is not found"));
          }
        }
        if (isAttached) {
          UserData.setLocalData(target, property, value);
        } else {
          property.setValue(target, value);
        }
      } else {
        if (value == null) {
          value = property.getValue(target);
        }
        if (value != null) {
          // create children.
          for (DocumentObject child : children) {
            String name = child.getName();
            String ns = child.getNamespace();
            if (!IConstants.XWT_X_NAMESPACE.equals(ns)
                || !IConstants.XAML_X_ARRAY
                    .equalsIgnoreCase(name)) {
              Class<?> type = property.getType();
              if (!Collection.class.isAssignableFrom(type)) {
                doCreate(value, (Element) child, null,
                    EMPTY_MAP);
              }
            }
          }
        }
      }
    }

    if (attribute.attributeNames(IConstants.XWT_NAMESPACE).length > 0) {
      IMetaclass propertyMetaclass = loader.getMetaclass(property
          .getType());
      if (value == null) {
        value = property.getValue(target);
      }
      if (value != null) {
View Full Code Here

    String namespace = element.getNamespace();
    if (IConstants.XWT_X_NAMESPACE.equalsIgnoreCase(namespace)
        && IConstants.XAML_X_NULL.equalsIgnoreCase(name)) {
      return null;
    }
    IMetaclass metaclass = loader.getMetaclass(name, namespace);
    if (metaclass == null) {
      return null;
    }
    return metaclass.getType();
  }
View Full Code Here

    if (childElement != null && parent != null
        && !(parent instanceof Widget)) {
      //
      // Add to default property identified by the type
      //
      IMetaclass parentMetaclass = XWT.getMetaclass(parent);
      IProperty[] properties = parentMetaclass.getProperties();
      IProperty useProperty = null;
      int count = 0;
      Class<?> childType = childElement.getClass();

      for (IProperty property : properties) {
View Full Code Here

        oldValue = false;
      }
      value.setValue(!oldValue);
    }
   
    IMetaclass metaclass = XWT.getMetaclass(host);
   
    // TODO this conversion should be simplied
    String eventName = ModelUtils.normalizePropertyName(property.getEvent().getName());
    IEventGroup eventGroup = metaclass.getEventGroup(eventName);
    if (eventGroup != null) {
      eventGroup.fireEvent(this, property);
    }
  }
View Full Code Here

    if (map == null) {
      map = new HashMap<String, IObservableValue>();
    }
    map.put(property.getName(), observableValue);
   
    IMetaclass metaclass = XWT.getMetaclass(host);
    // TODO it is not clean.
    EventProperty eventProperty  = (EventProperty) property;
   
    // TODO this conversion should be simplied
    String eventName = ModelUtils.normalizePropertyName(eventProperty.getEvent().getName());   
    IEventGroup eventGroup = metaclass.getEventGroup(eventName);
    if (eventGroup != null) {
      eventGroup.registerEvent(this, property);
    }
  }
View Full Code Here

                  return field.getInt(null);
                }
              }
            }
            else {
              IMetaclass metaclass = XWT.getMetaclass(className, IConstants.XWT_NAMESPACE);
              if (metaclass != null) {
                Class<?> type = metaclass.getType();
                if (type != null) {
                  String memberName = str.substring(index+1);
                  Field field = type.getField(memberName);
                  if (Modifier.isStatic(field.getModifiers())) {
                    return field.getInt(null);
View Full Code Here

  public static Class<?> getValueType(Class<?> type, String propertyName) {
    if (type == null || propertyName == null || propertyName.indexOf(".") != -1) {
      return null;
    }
    try {
      IMetaclass metaclass = XWT.getMetaclass(type);
      IProperty property = metaclass.findProperty(propertyName);
      if (property != null) {
        return property.getType();
      }
    } catch (Exception e) {
      LoggerManager.log(e);
View Full Code Here

          field.set(target, value);
          return;
        }
      }
     
      IMetaclass metaclass = XWT.getMetaclass(type);
      IProperty property = metaclass.findProperty(propertyName);
      if (property != null) {
        property.setValue(target, value);
      }
    } catch (Exception e) {
      e.printStackTrace();
View Full Code Here

TOP

Related Classes of org.eclipse.e4.xwt.metadata.IMetaclass

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.