Package org.eclipse.e4.xwt.internal.xml

Examples of org.eclipse.e4.xwt.internal.xml.Attribute


        if (!message.toString().equals("")) {
          content += "+ ";
        }
        content = content + element.getName();
        if (XWT.isTracking(Tracking.NAME)) {
          Attribute nameAttr = element.getAttribute("Name");
          if (nameAttr == null) {
            nameAttr = element.getAttribute(IConstants.XWT_X_NAMESPACE, "Name");
          }
          if (nameAttr != null) {
            content += " <" + nameAttr.getContent() + ">";
          }
        }
        message.append(content);
        if (XWT.isTracking(Tracking.DATABINDING)) {
          if (keys.contains(element)) {
View Full Code Here


    String bindingMessage = "";
    if (swtObject instanceof Binding) {
      String error = "";
      Binding newInstance = (Binding) swtObject;
      String path = null;
      Attribute attr = element.getAttribute("Path");
      if (null == attr)
        attr = element.getAttribute("path");
      if (null != attr)
        path = attr.getContent();
      Object dataContext2 = null;
      try {
        dataContext2 = newInstance.getValue(null);
        if (path != null && path.length() > 0) {
          String[] paths = path.trim().split("\\.");
View Full Code Here

  public static List<DocumentObject> sortWithAttr(DocumentObject[] sourceArray, Comparator<Element> comparator, String attrName) {
    List<DocumentObject> columnsList = new LinkedList<DocumentObject>();
    for (DocumentObject column : sourceArray) {
      Element columnElement = (Element) column;
      Attribute indexAttr = columnElement.getAttribute(attrName);
      if (indexAttr == null) {
        columnsList.add(column);
      }
    }

    List<Element> tempList = new LinkedList<Element>();
    for (DocumentObject column : sourceArray) {
      Element columnElement = (Element) column;
      Attribute indexAttr = columnElement.getAttribute(attrName);
      if (indexAttr != null) {
        tempList.add(columnElement);
      }
    }

    if (comparator == null) {
      comparator = new AttrComparator(attrName);
    }
    Collections.sort(tempList, comparator);

    for (Element columnElement : tempList) {
      Attribute indexAttr = columnElement.getAttribute(attrName);
      try {
        int index = Integer.parseInt(indexAttr.getContent());
        columnsList.add(index, columnElement);
      } catch (Exception e) {
        columnsList.add(columnsList.size(), columnElement);
      }
    }
View Full Code Here

    public AttrComparator(String attrName) {
      this.attrName = attrName;
    }

    public int compare(Element e1, Element e2) {
      Attribute attr1 = e1.getAttribute(attrName);
      Attribute attr2 = e2.getAttribute(attrName);
      String compare1 = attr1.getContent();
      String compare2 = attr2.getContent();
      if (compare1 == null || compare2 == null) {
        return 0;
      }
      try {
        int index1 = Integer.parseInt(compare1);
View Full Code Here

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

  protected void applyStyles(Element element, Object targetObject) throws Exception {
    if (targetObject instanceof Widget) {
      Widget widget = (Widget) targetObject;
      Map<String, Object> dico = UserData.getLocalResources(widget);
      Attribute attribute = element
          .getAttribute(IConstants.XAML_RESOURCES);
      if (attribute == null) {
        attribute = element.getAttribute(IConstants.XWT_NAMESPACE,
            IConstants.XAML_RESOURCES);
      }
      if (attribute != null) {
        if (attribute.getChildren().length > 0) {
          if (dico == null) {
            dico = new ResourceDictionary();
            UserData.setResources(widget, dico);
          }

          for (DocumentObject doc : attribute.getChildren()) {
            Element elem = (Element) doc;
            Object doCreate = doCreate(widget, elem, null,
                EMPTY_MAP);
            Attribute keyAttribute = elem.getAttribute(
                IConstants.XWT_X_NAMESPACE,
                IConstants.XAML_X_KEY);
            if (keyAttribute == null) {
              keyAttribute = elem.getAttribute(
                  IConstants.XWT_X_NAMESPACE,
                  IConstants.XAML_X_TYPE);
            }
            if (keyAttribute != null) {
              dico.put(keyAttribute.getContent(), doCreate);
            }
            if (doCreate instanceof IStyle) {
              IStyle style = (IStyle) doCreate;
              loadData.addStyle(style);
            }
View Full Code Here

      Object dataContext = loadData.getDataContext();
      if (dataContext != null) {
        return dataContext;
      }
      {
        Attribute dataContextAttribute = element
            .getAttribute(IConstants.XAML_DATA_CONTEXT);
        if (dataContextAttribute != null) {
          Widget composite = (Widget) swtObject;
          DocumentObject documentObject = dataContextAttribute
              .getChildren()[0];
          if (IConstants.XAML_STATICRESOURCES.equals(documentObject
              .getName())
              || IConstants.XAML_DYNAMICRESOURCES
                  .equals(documentObject.getName())) {
View Full Code Here

  protected Object getBindingContext(Element element, Widget swtObject) {
    // x:DataContext
    try {
      {
        Attribute dataContextAttribute = element
            .getAttribute(IConstants.XAML_BINDING_CONTEXT);
        if (dataContextAttribute != null) {
          Widget composite = (Widget) swtObject;
          DocumentObject documentObject = dataContextAttribute
              .getChildren()[0];
          if (IConstants.XAML_STATICRESOURCES.equals(documentObject
              .getName())
              || IConstants.XAML_DYNAMICRESOURCES
                  .equals(documentObject.getName())) {
View Full Code Here

    previous.end();
  }

  protected Integer getStyleValue(Element element, int styles) {
    Attribute attribute = element.getAttribute(IConstants.XWT_X_NAMESPACE,
        IConstants.XAML_STYLE);
    if (attribute == null) {
      if (styles != -1) {
        return styles;
      }
      return null;
    }
    if (styles == -1) {
      return (Integer) loader.findConvertor(String.class, Integer.class)
          .convert(attribute.getContent());
    }
    return styles
        | (Integer) loader.findConvertor(String.class, Integer.class)
            .convert(attribute.getContent());
  }
View Full Code Here

      installTableEditors((TableItem) targetObject);
    }

    // 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 {
            if (!done.contains(attrName)) {
              initAttribute(metaclass, targetObject, element,
                  namespace, attrName);
              done.add(attrName);
            }
          }
        }
        continue;
      }

      for (String attrName : element.attributeNames(namespace)) {
        if (IConstants.XAML_X_NAME.equalsIgnoreCase(attrName)
            && (targetObject instanceof Widget)) {
          continue;
        }
        if (!done.contains(attrName)) {
          initAttribute(metaclass, targetObject, element, namespace,
              attrName);
          done.add(attrName);
        }
      }
    }
    for (String attrName : element.attributeNames()) {
      if (IConstants.XAML_X_NAME.equalsIgnoreCase(attrName)
          && UserData.getWidget(targetObject) != null) {
        continue;
      }
      if (!done.contains(attrName)
          && !delayedAttributes.contains(attrName)) {
        initAttribute(metaclass, targetObject, element, null, attrName);
        done.add(attrName);
      }
    }

    //
    // handle foreigner namespace
    //
    for (String namespace : element.attributeNamespaces()) {
      if (XWT.isXWTNamespace(namespace)) {
        continue;
      }
      INamespaceHandler namespaceHandler = loader
          .getNamespaceHandler(namespace);
      if (namespaceHandler != null) {
        for (String attrName : element.attributeNames(namespace)) {
          Attribute attribute = element.getAttribute(namespace,
              attrName);
          Widget widget = UserData.getWidget(loadData
              .getCurrentWidget());
          namespaceHandler.handleAttribute(widget, targetObject,
              attrName, attribute.getContent());
        }
      }
    }
  }
View Full Code Here

TOP

Related Classes of org.eclipse.e4.xwt.internal.xml.Attribute

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.