Package org.eclipse.e4.xwt

Examples of org.eclipse.e4.xwt.XWTException


   */
  public Object convert(Object fromObject) {
    try {
      Class<?> type = XWT.getLoadingContext().loadClass(fromObject.toString());
      if (type == null) {
        throw new XWTException("Class " + fromObject.toString() + " is not found.");       
      }
      return type.newInstance();
    } catch (Exception e) {
      throw new XWTException(e);
    }
  }
View Full Code Here


   * @return Returns the directory file the zip stream extracted.
   */
  private File extractZipToTemporary(InputStream stream) throws IOException {
    File file = new File(System.getProperty("java.io.tmpdir") + "/cb" + System.currentTimeMillis() + Math.random());
    if (!file.mkdir()) {
      throw new XWTException("Folder creation fails: " + file.toString());
    }
    file.deleteOnExit();

    String directory = file.getAbsolutePath();
    ZipInputStream in = new ZipInputStream(stream);
    ZipEntry z;
    while ((z = in.getNextEntry()) != null) {
      if (z.isDirectory()) {
        String name = z.getName();
        name = name.substring(0, name.length() - 1);
        File f = new File(directory + File.separator + name);
        if (!f.mkdir()) {
          throw new XWTException("Folder creation fails: " + f.toString());
        }
        f.deleteOnExit();
      } else {
        File f = new File(directory + File.separator + z.getName());
        if (!f.createNewFile()) {
          throw new XWTException("File creation fails: " + f.toString());
        }
        f.deleteOnExit();
        FileOutputStream out = new FileOutputStream(f);
        byte[] cache = new byte[4096];
        for (int i = in.read(cache); i != -1; i = in.read(cache)) {
View Full Code Here

   */
  public Object convert(Object fromObject) {
    try {
      Class<?> type = XWT.getLoadingContext().loadClass(fromObject.toString());
      if (type == null) {
        throw new XWTException("Class " + fromObject.toString() + " is not found.");       
      }
      return type.newInstance();
    } catch (Exception e) {
      throw new XWTException(e);
    }
  }
View Full Code Here

    } catch (Exception e) {
      if (e instanceof RuntimeException) {
        throw ((RuntimeException) e);
      }

      throw new XWTException(e);
    }
  }
View Full Code Here

          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());
    }

    List<String> delayedAttributes = new ArrayList<String>();
    init(metaclass, targetObject, element, delayedAttributes);
    if (targetObject instanceof Style && element.getChildren().length > 0) {
      Collection<Setter> setters = new ArrayList<Setter>();
      for (DocumentObject doc : element.getChildren()) {
        Object child = doCreate(targetObject, (Element) doc, null,
            Collections.EMPTY_MAP);
        if (!(child instanceof Setter)) {
          throw new XWTException("Setter is expected in Style.");
        }
        setters.add((Setter) child);
      }
      ((Style) targetObject).setSetters(setters
          .toArray(new Setter[setters.size()]));
View Full Code Here

        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

            .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

  protected Object getArrayProperty(Class<?> type, Object swtObject,
      DocumentObject element, String attrName)
      throws IllegalAccessException, InvocationTargetException,
      NoSuchFieldException {
    if (!type.isArray()) {
      throw new XWTException("Type mismatch: property " + attrName
          + " isn't an array.");
    }

    Class<?> arrayType = type.getComponentType();
    if (arrayType != null) {
View Full Code Here

    Collection<Object> collector = null;
    if (type.isInterface()) {
      collector = new ArrayList<Object>();
    } else {
      if (Modifier.isAbstract(type.getModifiers())) {
        LoggerManager.log(new XWTException("Collection "
            + type.getSimpleName() + " is abstract type"));
      }
      try {
        collector = (Collection) type.newInstance();
      } catch (InstantiationException e) {
        LoggerManager.log(new XWTException(e));
      }
    }

    for (DocumentObject childModel : element.getChildren()) {
      if (!(childModel instanceof Element)) {
View Full Code Here

      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) {
            TableItem item = (TableItem) swtObject;
            tableEditor.setItem(item);
            for (DocumentObject doc : element.getChildren()) {
              Control control = (Control) doCreate(
                  ((TableItem) swtObject).getParent(),
                  (Element) doc, null, EMPTY_MAP);
              tableEditor.setEditor(control);
              int column = getColumnValue(element);
              TableEditorHelper.initEditor(item, control, column);
            }
          }
        }
      } else {
        Constructor<?> constructor = type.getConstructor(type);
        if (constructor != null) {
          instance = constructor.newInstance(loader.convertFrom(type,
              content));
          invokeCreatededAction(element, instance);
        } else {
          LoggerManager.log(new XWTException("Constructor \"" + name
              + "(" + type.getSimpleName() + ")\" is not found"));
        }
      }
      List<String> delayedAttributes = new ArrayList<String>();
      init(metaclass, instance, element, delayedAttributes);
View Full Code Here

TOP

Related Classes of org.eclipse.e4.xwt.XWTException

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.