Examples of IMetaclass


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

  protected void setBindingContext(IMetaclass metaclass, Object targetObject,
      ResourceDictionary dico, Object bindingContext)
      throws IllegalAccessException, InvocationTargetException,
      NoSuchFieldException {
    Object control = null;
    IMetaclass widgetMetaclass = metaclass;
    if (JFacesHelper.isViewer(targetObject)) {
      Widget widget = JFacesHelper.getControl(targetObject);
      widgetMetaclass = loader.getMetaclass(widget.getClass());
      control = targetObject;
    } else if (targetObject instanceof Widget) {
      control = (Widget) targetObject;
    } else {
      control = loadData.getCurrentWidget();
    }
    if (control != null) {
      if (targetObject instanceof IDynamicBinding) {
        IDynamicBinding dynamicBinding = (IDynamicBinding) targetObject;
        dynamicBinding.setControl(control);
        dynamicBinding.setHost(loadData.getHost());
      }
      if (dico != null) {
        UserData.setResources(control, dico);
      }
      if (bindingContext != null) {
        IProperty property = widgetMetaclass
            .findProperty(IConstants.XAML_BINDING_CONTEXT);
        if (property != null) {
          property.setValue(UserData.getWidget(control),
              bindingContext);
        } else {
          throw new XWTException("DataContext is missing in "
              + widgetMetaclass.getType().getName());
        }
      }
    }
  }
View Full Code Here

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

  }

  protected int getColumnIndex(Element columnElement) {
    String name = columnElement.getName();
    String namespace = columnElement.getNamespace();
    IMetaclass metaclass = loader.getMetaclass(name, namespace);
    int index = -1;
    Class<?> type = metaclass.getType();
    if (TableViewerColumn.class.isAssignableFrom(type)) {
      DocumentObject parent = columnElement.getParent();
      List<DocumentObject> children = DocumentObjectSorter.sortWithAttr(
          parent.getChildren(), "Index");
      index = children.indexOf(columnElement);
View Full Code Here

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

      return null;
    }
    try {
      Class<?> type = NamespaceHelper.loadCLRClass(context
          .getLoadingContext(), name, namespace);
      IMetaclass metaclass = loader.getMetaclass(name, namespace);
      if (type == null) {
        if (metaclass != null)
          type = metaclass.getType();
      }
      if (metaclass == null) {
        throw new XWTException("Class for " + name + " is not found.");
      }
      // type = expected type;
      // Need to support the
      String content = element.getContent();
      Object instance = null;
      if (content == null) {
        instance = metaclass.newInstance(new Object[] { swtObject });
        invokeCreatededAction(element, instance);
        if (instance instanceof TableEditor) {
          // TODO should be moved into IMetaclass
          TableEditor tableEditor = (TableEditor) instance;
          if (swtObject instanceof TableItem) {
View Full Code Here

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

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

  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

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

      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

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

    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

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

    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

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

        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

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

    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
TOP
Copyright © 2018 www.massapi.com. 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.