public DBSource[] getSelectedDBSources() {
    List<TableNode> tables = new ArrayList<TableNode>();
    TreePath[] treePath;
    try {
      treePath = getTableTree().getSelectionPaths();
      if (treePath == null) return new DBSource[0];
      for (int i = 0; i < treePath.length; i++) {
        Object selectedObject =
            ((DefaultMutableTreeNode) treePath[i].getLastPathComponent()).getUserObject();
        if (selectedObject instanceof TableNode) tables.add(((TableNode) selectedObject));
      }
    } catch (SQLException e) {
      ErrorMessages.error(I18N.getString(""));
      e.printStackTrace();
    } catch (DriverException e) {
      e.printStackTrace();
    }

    final DBSource[] dbSources = new DBSource[tables.size()];
    int i = 0;
    for (TableNode table : tables) {
      dbSources[i] = firstPanel.getDBSource();
      dbSources[i].setTableName(table.getName());
      dbSources[i].setSchemaName(table.getSchema());
      i++;
    }
    return dbSources;
  }
  private JTree getTableTree() throws SQLException, DriverException {
    if (tableTree == null) {

      DBDriver dbDriver = firstPanel.getDBDriver();
      final Connection connection = firstPanel.getConnection();
      final String[] schemas = dbDriver.getSchemas(connection);
      OutputManager om = Services.getService(OutputManager.class);

      DefaultMutableTreeNode rootNode =
          // new DefaultMutableTreeNode ("Schemas");
          new DefaultMutableTreeNode(connection.getCatalog());

      // Add Data to the tree
      for (String schema : schemas) {

        final TableDescription[] tableDescriptions =
            dbDriver.getTables(connection, null, schema, null, new String[] {"TABLE"});
        final TableDescription[] viewDescriptions =
            dbDriver.getTables(connection, null, schema, null, new String[] {"VIEW"});

        if (tableDescriptions.length == 0 && viewDescriptions.length == 0) {
          continue;
        }

        // list schemas
        DefaultMutableTreeNode schemaNode = new DefaultMutableTreeNode(new SchemaNode(schema));
        rootNode.add(schemaNode);

        // list Tables
        DefaultMutableTreeNode tableNode =
            new DefaultMutableTreeNode(I18N.getString("orbisgis.org.orbisgis.core.db.tables"));

        // we send possible loading errors to the Output window
        DriverException[] exs = dbDriver.getLastNonBlockingErrors();
        if (exs.length != 0) {
          for (int i = 0; i < exs.length; i++) {
            om.println(exs[i].getMessage(), Color.ORANGE);
          }
        }

        if (tableDescriptions.length > 0) {
          schemaNode.add(tableNode);
          for (TableDescription tableDescription : tableDescriptions) {
            tableNode.add(new DefaultMutableTreeNode(new TableNode(tableDescription)));
          }
        }

        // list View
        DefaultMutableTreeNode viewNode =
            new DefaultMutableTreeNode(I18N.getString("orbisgis.org.orbisgis.core.db.views"));
        if (viewDescriptions.length > 0) {
          schemaNode.add(viewNode);
          for (TableDescription viewDescription : viewDescriptions) {
            viewNode.add(new DefaultMutableTreeNode(new ViewNode(viewDescription)));
          }
        }
      }

      connection.close();

      tableTree = new JTree(rootNode);
      tableTree.setRootVisible(true);
      tableTree.setShowsRootHandles(true);
      tableTree.setCellRenderer(new TableTreeCellRenderer());
    }
    return tableTree;
  }