Exemplo n.º 1
0
 protected void initObjectClass(Class<E> clazz) {
   Field[] fields = clazz.getDeclaredFields();
   this.dialogInputs = new JComponent[fields.length * 2];
   for (int i = 0; i < fields.length; i++) {
     this.dialogInputs[2 * i] = new JLabel(fields[i].getName());
     this.dialogInputs[2 * i + 1] = (i == 0) ? getTextField() : getTextArea();
   }
   this.dialogInputs[1].setEnabled(false);
   Class[] classes = new Class[fields.length];
   for (int i = 0; i < classes.length; i++) {
     classes[i] = String.class;
   }
   try {
     this.constructor = clazz.getConstructor(classes);
   } catch (NoSuchMethodException ignored) {
   }
 }
  /**
   * Construct a variable
   *
   * @param aType the type
   * @param aName the name
   * @param aValue the value
   */
  public Variable(Class<?> aType, String aName, Object aValue) {
    type = aType;
    name = aName;
    value = aValue;
    fields = new ArrayList<Field>();

    // find all fields if we have a class type except we don't expand strings and null values

    if (!type.isPrimitive() && !type.isArray() && !type.equals(String.class) && value != null) {
      // get fields from the class and all superclasses
      for (Class<?> c = value.getClass(); c != null; c = c.getSuperclass()) {
        Field[] fs = c.getDeclaredFields();
        AccessibleObject.setAccessible(fs, true);

        // get all nonstatic fields
        for (Field f : fs) if ((f.getModifiers() & Modifier.STATIC) == 0) fields.add(f);
      }
    }
  }