コード例 #1
0
 public void load() {
   master.enableBackButton(false);
   if (!isConsumed) {
     Log.Debug(this, "Overwrite is set to " + master.getStore().getProperty("overwrite", false));
     importXML();
   }
 }
コード例 #2
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);
  }
コード例 #3
0
 public boolean next() {
   try {
     imports();
   } catch (Exception e) {
     Log.Debug(e);
     master.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
   }
   return false;
 }
コード例 #4
0
  private void importXML() {
    master.setCursor(new Cursor(Cursor.WAIT_CURSOR));
    isConsumed = true;
    XMLReader x;
    ArrayList<ArrayList<DatabaseObject>> objs = null;

    if (master.getStore().hasProperty("file")) {
      x = new XMLReader();
      x.setOverwriteExisting(true);
      try {
        x.newDoc(new File(master.getStore().getProperty("file")), false);
        objs = x.getObjects();
        jTable1.setModel(
            ImportTableModel.getModel(objs, !master.getStore().getProperty("overwrite", false)));
        jLabel2.setText(
            jLabel2.getText()
                + " "
                + master.getStore().getProperty("file")
                + " ("
                + jTable1.getRowCount()
                + ")");
        TableFormat.format(jTable1, 0, 0);
        TableFormat.format(jTable1, 1, 33);
        TableFormat.format(jTable1, 2, 100);
      } catch (Exception ex) {
        Popup.error(ex);
        Log.Debug(ex);
      } finally {
        master.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
      }
    }
  }
コード例 #5
0
  @SuppressWarnings("unchecked")
  private void importCsv() {
    master.setCursor(new Cursor(Cursor.WAIT_CURSOR));
    isConsumed = true;
    CSVReaderWriter x;
    Object[][] arr;

    if (master.getStore().hasProperty("file")) {
      x =
          new CSVReaderWriter(
              new File(master.getStore().getProperty("file")),
              master.getStore().getProperty("separator"));
      List<Object[]> d = x.read();
      try {
        d = ArrayUtilities.removeDuplicates(d);
        arr = ArrayUtilities.listToTableArray(d);
        arr = ArrayUtilities.inserValue(arr, null, null);

        jTable1.setModel(new MPTableModel(arr));
        jLabel2.setText(
            jLabel2.getText()
                + " "
                + master.getStore().getProperty("file")
                + " ("
                + jTable1.getRowCount()
                + ")");

      } catch (Exception ex) {
        Popup.error(ex);
        Log.Debug(ex);
      } finally {
        master.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
      }
    }
    //
    //
    //        if (objs != null && objs.size() < 0) {
    //        } else {
    //            Popup.notice(Messages.NO_DATA_FOUND);
    //        }
    //      for (int i = 0; i < objs.size(); i++) {
    //                ArrayList<DatabaseObject> arrayList = objs.get(i);
    //                for (int j = 0; j < arrayList.size(); j++) {
    //                    DatabaseObject databaseObject = arrayList.get(j);
    //                    Log.Debug(this, "Parsing " + databaseObject.getDbIdentity() + " : " +
    // databaseObject.__getCname() + " from file: " + master.getStore().getProperty("file"));
    //                    databaseObject.save();
    //                }
    //            }
  }
コード例 #6
0
  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);
  }