Example #1
0
  private void imports() {
    jProgressBar1.setMinimum(0);
    jProgressBar1.setMaximum(jTable1.getRowCount());

    Runnable runnable =
        new Runnable() {

          public void run() {
            int imp = 0;
            for (int i = 0; i < jTable1.getRowCount(); i++) {
              if ((Boolean) jTable1.getValueAt(i, 1)) {
                master.setCursor(new Cursor(Cursor.WAIT_CURSOR));
                final int p = i;

                String val = "";
                try {
                  DatabaseObject dog = ((DatabaseObject) jTable1.getValueAt(p, 0));
                  if (!dog.saveImport()) {
                    val = "<html><p><font color =red>" + Messages.ERROR_OCCURED;
                  } else {
                    val =
                        "<html><p><font color =green>"
                            + Messages.IMPORTED
                            + " ID: "
                            + dog.__getIDS();
                    imp++;
                  }
                } catch (Exception e) {
                  val =
                      "<html><p><font color =red>" + Messages.ERROR_OCCURED + ": " + e.getMessage();
                } finally {
                  jTable1.setValueAt(val, p, 4);
                  jProgressBar1.setValue(p);

                  master.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
                }
              }
            }
            jProgressBar1.setString(imp + " " + Messages.IMPORTED);
          }
        };
    new Thread(runnable).start();

    master.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
    master.isEnd(true);
  }
  private void imports() {

    jProgressBar1.setMinimum(0);
    jProgressBar1.setMaximum(jTable1.getRowCount() * jTable1.getColumnCount());

    Runnable runnable =
        new Runnable() {

          public void run() {
            int imp = 0;

            for (int i = 0; i < jTable1.getRowCount(); i++) {
              master.setCursor(new Cursor(Cursor.WAIT_CURSOR));

              for (int j = 0; j < jTable1.getColumnCount() - 1; j++) {
                final int p = i;
                boolean existing = false;
                String val = null;
                try {
                  if (jTable1.getValueAt(p, j) != null) {
                    ProductGroup dog = null;
                    try {
                      Log.Debug(this, "Checking for group: " + jTable1.getValueAt(p, j));
                      dog =
                          (ProductGroup)
                              DatabaseObject.getObject(
                                  Context.getProductGroup(), jTable1.getValueAt(p, j).toString());
                      existing = true;
                      Log.Debug(this, "Already existing: " + jTable1.getValueAt(p, j));
                    } catch (NodataFoundException nodataFoundException) {
                      Log.Debug(this, "Create a new group: " + jTable1.getValueAt(p, j));
                      dog = new ProductGroup(jTable1.getValueAt(p, j).toString());
                      dog.setProductgroupsids(1);
                    }

                    if (j > 0) {
                      try {
                        Log.Debug(
                            this, "Checking for parent group: " + jTable1.getValueAt(p, j - 1));
                        dog.setProductgroupsids(
                            DatabaseObject.getObject(
                                    Context.getProductGroup(),
                                    jTable1.getValueAt(p, j - 1).toString())
                                .__getIDS());
                      } catch (NodataFoundException nodataFoundException1) {
                        throw new IllegalStateException(
                            "Parent unknown: " + jTable1.getValueAt(p, j - 1));
                      }
                    }

                    if (!existing) {
                      if (!dog.saveImport()) {
                        val = "<html><p><font color =red>" + Messages.ERROR_OCCURED;
                      } else {
                        val =
                            "<html><p><font color =green>"
                                + Messages.IMPORTED
                                + " ID: "
                                + dog.__getIDS();
                        imp++;
                      }
                    } else {
                      val = "<html><p><font color =blue> Existing ID: " + dog.__getIDS();
                    }
                  }
                } catch (Exception e) {
                  e.printStackTrace();
                  val =
                      "<html><p><font color =red>" + Messages.ERROR_OCCURED + ": " + e.getMessage();
                } finally {
                  if (val != null) {
                    jTable1.setValueAt(val, p, jTable1.getColumnCount() - 1);
                  }
                  jProgressBar1.setValue(p * j);
                  master.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
                }
              }
            }
            jProgressBar1.setString(imp + " " + Messages.IMPORTED);
          }
        };
    new Thread(runnable).start();

    master.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
    master.isEnd(true);
  }