private void jButton2ActionPerformed(
      java.awt.event.ActionEvent evt) { // GEN-FIRST:event_jButton2ActionPerformed

    // Get all selected paths...
    if (MainFrame.getMainInstance().getActiveReportFrame() == null || getJTableFields() == null) {
      return;
    }

    DefaultTableModel dtm = (DefaultTableModel) getJTableFields().getModel();

    TreePath[] paths = jTree1.getSelectionPaths();
    if (paths == null) return;
    for (int i = 0; i < paths.length; ++i) {
      boolean valid = true;
      TreePath tp = paths[i];

      TreeJRField tjrf =
          (TreeJRField) ((DefaultMutableTreeNode) tp.getLastPathComponent()).getUserObject();
      String returnType = Misc.getJRFieldType(tjrf.getObj().getName());
      it.businesslogic.ireport.JRField field =
          new it.businesslogic.ireport.JRField(tjrf.getField().getName(), returnType);
      field.setDescription(tjrf.getField().getDescription());
      Vector row = new Vector();
      row.addElement(field);
      row.addElement(field.getClassType());
      row.addElement(field.getDescription());

      if (isComboVisible() && jComboBox1.getSelectedItem() instanceof FieldClassWrapper) {
        FieldClassWrapper cw = (FieldClassWrapper) jComboBox1.getSelectedItem();
        field.setName(cw.getFieldName() + "." + field.getDescription());
        field.setDescription(field.getName());
      }

      // Check for duplicates fields...
      boolean found = fieldAlreadyExists(field);
      String baseName = field.getName();
      for (int j = 1; isPathOnDescription() && found; ++j) {
        field.setName(baseName + "_" + j);
        found = fieldAlreadyExists(field);
      }

      if (!found) {
        dtm.addRow(row);
        getJTableFields()
            .getSelectionModel()
            .addSelectionInterval(
                getJTableFields().getRowCount() - 1, getJTableFields().getRowCount() - 1);
      }
    }
  } // GEN-LAST:event_jButton2ActionPerformed
  public void exploreBean(DefaultMutableTreeNode root, String classname, String parentPath) {
    try {

      root.removeAllChildren();
      if (parentPath.length() > 0) parentPath += ".";

      MainFrame.reportClassLoader.rescanLibDirectory();
      Class clazz = Class.forName(classname, true, MainFrame.reportClassLoader);

      java.beans.PropertyDescriptor[] pd =
          org.apache.commons.beanutils.PropertyUtils.getPropertyDescriptors(clazz);
      for (int nd = 0; nd < pd.length; ++nd) {
        String fieldName = pd[nd].getName();
        if (pd[nd].getPropertyType() != null && pd[nd].getReadMethod() != null) {
          String returnType = pd[nd].getPropertyType().getName();
          it.businesslogic.ireport.JRField field =
              new it.businesslogic.ireport.JRField(Misc.getJRFieldType(fieldName), returnType);
          if (isPathOnDescription()) {
            field.setDescription(parentPath + fieldName);
          } else {
            field.setName(parentPath + fieldName);
          }

          TreeJRField jtf = new TreeJRField();

          jtf.setField(field);
          jtf.setObj(pd[nd].getPropertyType());

          boolean bChildrens = true;
          if (pd[nd].getPropertyType().isPrimitive()
              || pd[nd].getPropertyType().getName().startsWith("java.lang.")) {
            bChildrens = false;
          }
          root.add(new DefaultMutableTreeNode(jtf, bChildrens));
        }
      }

      jTree1.expandPath(new TreePath(root.getPath()));
      jTree1.updateUI();

    } catch (ClassNotFoundException cnf) {
      javax.swing.JOptionPane.showMessageDialog(
          this,
          I18n.getFormattedString(
              "messages.BeanInspectorPanel.classNotFoundError",
              "Class not found error!!\nCheck your classpath and retry!\n{0}",
              new Object[] {cnf.getMessage()}),
          I18n.getString("message.title.error", "Error"),
          javax.swing.JOptionPane.ERROR_MESSAGE);
      return;
    } catch (Exception ex) {
      javax.swing.JOptionPane.showMessageDialog(
          this,
          ex.getMessage(),
          I18n.getString("message.title.error", "Error"),
          javax.swing.JOptionPane.ERROR_MESSAGE);
      return;
    }
  }
  /*
   * This method apply the new value for the specified property
   * The oldValue can be wrong or null if a multiselection was performed
   * return true if the object is modified...
   */
  private boolean applyNewFieldProperty(
      JRField field, String propertyName, Object oldValue, Object newValue) {
    if (propertyName == null) return false;

    boolean objectModified = true;

    if (propertyName.equals("fieldName")) {
      SubDataset paramSubdataset = Misc.getObjectSubDataset(getJrf().getReport(), field);
      if (paramSubdataset != null && newValue != null) {
        for (int i = 0; i < paramSubdataset.getFields().size(); ++i) {
          JRField f = (JRField) paramSubdataset.getFields().get(i);
          if (f.getName().equals(newValue)) {
            ((SheetProperty) this.getSheetProperty(propertyName))
                .setLabelError(
                    I18n.getString(
                        "messages.JRFieldDialog.DuplicatedFieldName",
                        "A field with this name already exists!"));
            ((SheetProperty) this.getSheetProperty(propertyName)).updateLabel();
            return false;
          }
        }

        field.setName("" + newValue);
        ((SheetProperty) this.getSheetProperty(propertyName)).setLabelError(null);
        ((SheetProperty) this.getSheetProperty(propertyName)).updateLabel();
      }
    } else if (propertyName.equals("fieldDescription")) {
      if (newValue != null) {
        field.setDescription("" + newValue);
      }
    } else if (propertyName.equals("fieldProperties")) {
      if (newValue != null && newValue instanceof List) {
        field.setProperties((List) newValue);
      }
    } else if (propertyName.equals("fieldClassType")) {
      if (newValue != null) {
        field.setClassType("" + newValue);
      }
    }

    return objectModified;
  }