Package org.eclipse.e4.xwt.metadata

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


        continue;
      }
      String eventPropertyName = IEventConstants.getEventPropertyName(name);
      String eventName = IEventConstants.getEventName(name);
      IEvent event = metaclass.findEvent(eventName);
      IProperty eventProperty = metaclass.findProperty(eventPropertyName);
     
      try {
        controller.setEvent(event, UserData.getWidget(host), manager, eventProperty, IObservableValueListener.class.getDeclaredMethod("changeValueHandle", Object.class, org.eclipse.swt.widgets.Event.class));
      } catch (Exception e) {
        LoggerManager.log(e);
View Full Code Here


        }
      }
      cacheData = new CacheData();
 
      IMetaclass metaclass = XWT.getMetaclass(dataObject);
      IProperty prop = metaclass.findProperty(propertyName);
      if (prop != null && value != null) {
        cacheData.property = prop;
        Class<?> valueType = value.getClass();
        IConverter converter = XWT.findConvertor(valueType, prop
            .getType());
        Object trueValue = value;
        if (converter != null) {
          trueValue = converter.convert(trueValue);
        }
        cacheData.value = trueValue;
        try {
          Object existingValue = prop.getValue(dataObject);
          return Operator.compare(existingValue, operator, trueValue);
        } catch (Exception e) {
          LoggerManager.log(e);
        }
      }
View Full Code Here

    type = org.eclipse.jface.viewers.Viewer.class;
    metaclass = (IMetaclass) core.getMetaclass(type,
        IConstants.XWT_NAMESPACE);
    if (metaclass != null) {
      IProperty property = metaclass.findProperty("Input");

      metaclass.addProperty(new InputBeanProperty(property));
      metaclass.addProperty(new DataProperty(
          IConstants.XAML_DATA_CONTEXT,
          IUserDataConstants.XWT_DATACONTEXT_KEY));

      metaclass.removeProperty("selection");

      metaclass.addProperty(new DataProperty(
          PropertiesConstants.PROPERTY_BINDING_PATH,
          IUserDataConstants.XWT_PROPERTY_DATA_KEY, String.class));
      metaclass.addProperty(new DataProperty(
          PropertiesConstants.PROPERTY_ITEM_TEXT,
          IUserDataConstants.XWT_PROPERTY_ITEM_TEXT_KEY,
          IBinding.class));
      metaclass.addProperty(new DataProperty(
          PropertiesConstants.PROPERTY_ITEM_IMAGE,
          IUserDataConstants.XWT_PROPERTY_ITEM_IMAGE_KEY,
          IBinding.class));
      metaclass.addProperty(new SingleSelectionBeanProperty(
          PropertiesConstants.PROPERTY_SINGLE_SELECTION));
      metaclass.addProperty(new MultiSelectionBeanProperty(
          PropertiesConstants.PROPERTY_MULTI_SELECTION));
    }

    type = org.eclipse.jface.viewers.AbstractListViewer.class;
    metaclass = (IMetaclass) core.getMetaclass(type,
        IConstants.XWT_NAMESPACE);
    if (metaclass != null) {
      metaclass.addInitializer(new JFaceInitializer());
    }

    type = org.eclipse.jface.viewers.ColumnViewer.class;
    metaclass = (IMetaclass) core.getMetaclass(type,
        IConstants.XWT_NAMESPACE);
    if (metaclass != null) {
      metaclass.addProperty(new DynamicBeanProperty(type, String[].class,
          PropertiesConstants.PROPERTY_COLUMN_PROPERTIES));
      metaclass.addProperty(new ColumnViewerColumnsProperty());

      metaclass.addInitializer(new JFaceInitializer());
    }

    for (Class<?> cls : JFacesHelper.getSupportedElements()) {
      registerMetaclass(cls);
    }
    type = org.eclipse.jface.viewers.TableViewer.class;
    metaclass = (IMetaclass) core.getMetaclass(type,
        IConstants.XWT_NAMESPACE);
    IProperty property = metaclass.findProperty("table");
    if (property instanceof AbstractProperty) {
      AbstractProperty abstractProperty = (AbstractProperty) property;
      abstractProperty.setValueAsParent(true);
    }
   
View Full Code Here

          || 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) {
View Full Code Here

      }
      if (dico != null) {
        UserData.setResources(control, dico);
      }
      if (dataContext != null) {
        IProperty property = widgetMetaclass
            .findProperty(IConstants.XAML_DATA_CONTEXT);
        if (property != null) {
          property.setValue(UserData.getWidget(control), dataContext);
        } else {
          throw new XWTException("DataContext is missing in "
              + widgetMetaclass.getType().getName());
        }
      }
View Full Code Here

      }
      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

    // x:DataContext
    if (loadData.getDataContext() == null) {
      Attribute dataContextAttribute = element
          .getAttribute(IConstants.XAML_DATA_CONTEXT);
      if (dataContextAttribute != null) {
        IProperty property = metaclass
            .findProperty(IConstants.XAML_DATA_CONTEXT);
        Widget composite = (Widget) UserData.getWidget(targetObject);
        DocumentObject documentObject = dataContextAttribute
            .getChildren()[0];
        if (IConstants.XAML_STATICRESOURCES.equals(documentObject
            .getName())
            || IConstants.XAML_DYNAMICRESOURCES
                .equals(documentObject.getName())) {
          String key = documentObject.getContent();
          property.setValue(composite, new StaticResourceBinding(
              composite, key));
        } else if (IConstants.XAML_BINDING.equals(documentObject
            .getName())) {
          Object object = doCreate(targetObject,
              (Element) documentObject, null, EMPTY_MAP);
          property.setValue(composite, object);
        } else {
          LoggerManager.log(new UnsupportedOperationException(
              documentObject.getName()));
        }
      }
    }

    HashSet<String> done = new HashSet<String>();

    Attribute nameAttr = element.getAttribute(IConstants.XAML_X_NAME);
    if (nameAttr == null) {
      nameAttr = element.getAttribute(IConstants.XWT_X_NAMESPACE,
          IConstants.XAML_X_NAME);
    }
    if (nameAttr != null && UserData.getWidget(targetObject) != null) {
      String value = nameAttr.getContent();
      loadData.inject(targetObject, value);

      nameScoped.addNamedObject(value, targetObject);
      done.add(IConstants.XAML_X_NAME);
    }

    for (String attrName : element.attributeNames()) {
      if (IConstants.XWT_X_NAMESPACE.equals(element
          .getAttribute(attrName).getNamespace())) {
        continue;
      } else if (delayedAttributes != null
          && isDelayedProperty(attrName.toLowerCase(), metaclass
              .getType()))
        delayedAttributes.add(attrName);
      else {
        if (!done.contains(attrName)) {
          initAttribute(metaclass, targetObject, element, null,
              attrName);
          done.add(attrName);
        }
      }
    }

    for (String namespace : element.attributeNamespaces()) {
      if (IConstants.XWT_X_NAMESPACE.equals(namespace)) {
        for (String attrName : element.attributeNames(namespace)) {
          if ("class".equalsIgnoreCase(attrName)
              || IConstants.XAML_STYLE.equalsIgnoreCase(attrName)) {
            continue; // done before
          } else if (IConstants.XAML_X_NAME
              .equalsIgnoreCase(attrName)) {
            nameScoped
                .addNamedObject(element.getAttribute(namespace,
                    attrName).getContent(), targetObject);
            done.add(attrName);
          } else if (IConstants.XAML_DATA_CONTEXT
              .equalsIgnoreCase(attrName)) {
            continue; // done before
          } else if (IConstants.XAML_X_ARRAY
              .equalsIgnoreCase(attrName)) {
            IProperty property = metaclass.findProperty(attrName);
            Class<?> type = property.getType();
            Object value = getArrayProperty(type, targetObject,
                element, attrName);
            if (value != null) {
              property.setValue(targetObject, value);
            }
          } else if (IConstants.XAML_RESOURCES
              .equalsIgnoreCase(attrName)) {
            continue;
          } else {
View Full Code Here

    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."));
          }
          currentMetaclass = loader.getMetaclass(target);
View Full Code Here

        .getAttribute(attrName) : element.getAttribute(namespace,
        attrName);
    if (attribute == null) {
      attribute = element.getAttribute(attrName);
    }
    IProperty property = null;
    boolean isAttached = false;
    {
      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) {
        List<String> delayedAttributes = new ArrayList<String>();
        init(propertyMetaclass, value, attribute, delayedAttributes);
        for (String delayed : delayedAttributes) {
View Full Code Here

   * @see
   * com.soyatec.xaswt.core.metadata.IMetaclass#findProperty(java.lang.String)
   */
  public IProperty findProperty(String name) {
    assertInitialize();
    IProperty property = propertyCache.get(normalize(name));
    if (property == null && superClass != null) {
      property = superClass.findProperty(name);
    }
    if (property == null) {
      try {
View Full Code Here

TOP

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

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.