コード例 #1
0
  public void doFinish(IProgressMonitor monitor) {
    monitor.beginTask("Exporting ", rowCount);

    try {
      switch (ComboFile) {
        case 0:
          WritableWorkbook myWorkbook = null;
          String str = null;
          try {
            str = command.Command_Int("SELECT COUNT(*) FROM " + sCollection);
          } catch (Exception e) {
            e.printStackTrace();
          }
          if (Integer.parseInt(str) > 50000) {
            int j = 0;
            int k = 0;
            int m = 0;
            while (k * 50000 < Integer.parseInt(str)) {
              if (Integer.parseInt(str) > 100000)
                myWorkbook = Workbook.createWorkbook(new File(sFullPath + "(" + m + ")" + ".xls"));
              else {
                myWorkbook = Workbook.createWorkbook(new File(sFullPath + ".xls"));
              }
              int l = 0;
              for (; k * 50000 < Integer.parseInt(str); k++) {
                myWorkbook.createSheet("Sheet" + k, k);
                WritableSheet mySheet = myWorkbook.getSheet(l);
                String sImsi = "";
                for (int i = 0; i < oColumns.size(); i++) {
                  sImsi = oColumns.get(i);
                  WritableCellFormat ColumnFormat = new WritableCellFormat();
                  ColumnFormat.setAlignment(Alignment.CENTRE);
                  ColumnFormat.setVerticalAlignment(VerticalAlignment.CENTRE);
                  ColumnFormat.setBackground(Colour.GRAY_25);
                  mySheet.setColumnView(i, (sImsi.trim().length() * 2));
                  jxl.write.Label oColumnLabel = null;
                  oColumnLabel = new jxl.write.Label(i, 0, sImsi, ColumnFormat);
                  mySheet.addCell(oColumnLabel);
                }
                sQuery = "selectattr " + sAttr + "'limit " + 50000 + "offset " + (j) * 50000 + "'";
                ArrayList<String> oExcel = command.Command_Excel(sQuery);
                int nTotal = oExcel.size() / oColumns.size();
                int nColumn = oColumns.size();
                int nCount = 0;
                for (int nRow = 1; nRow <= nTotal; nRow++) {
                  for (int nCol = 0; nCol < nColumn; nCol++) {
                    jxl.write.Label numberLabels = null;
                    numberLabels = new jxl.write.Label(nCol, nRow, oExcel.get(nCount++));
                    mySheet.addCell(numberLabels);
                  }
                  monitor.worked(1);
                }
                j++;
                l++;
                if (l == 2) {
                  k++;
                  break;
                }
              }
              m++;
              myWorkbook.write();
              myWorkbook.close();
            }
          } else if (Integer.parseInt(str) < 50000) {
            myWorkbook = Workbook.createWorkbook(new File(sFullPath + ".xls"));
            WritableSheet mySheet = myWorkbook.createSheet(sCollection.replaceAll("/", "_"), 0);

            String sImsi = "";
            for (int i = 0; i < oColumns.size(); i++) {
              sImsi = oColumns.get(i);

              WritableCellFormat ColumnFormat = new WritableCellFormat();
              ColumnFormat.setAlignment(Alignment.CENTRE);
              ColumnFormat.setVerticalAlignment(VerticalAlignment.CENTRE);
              ColumnFormat.setBackground(Colour.GRAY_25);
              mySheet.setColumnView(i, (sImsi.trim().length() * 2));
              jxl.write.Label oColumnLabel = null;

              oColumnLabel = new jxl.write.Label(i, 0, sImsi, ColumnFormat);
              mySheet.addCell(oColumnLabel);
            }

            ArrayList<String> oExcel = command.Command_Excel(sQuery);

            int nTotal = oExcel.size() / oColumns.size();
            int nColumn = oColumns.size();

            int nCount = 0;
            for (int nRow = 1; nRow <= nTotal; nRow++) {
              for (int nCol = 0; nCol < nColumn; nCol++) {
                jxl.write.Label numberLabels = null;
                numberLabels = new jxl.write.Label(nCol, nRow, oExcel.get(nCount++));
                mySheet.addCell(numberLabels);
              }
              monitor.worked(1);
            }
            myWorkbook.write();
            myWorkbook.close();
          }
          final int sheet = lblsheet;
          final int File;
          if ((lblsheet / 2) == 0) {
            File = 1;
          } else {
            File = (lblsheet / 2);
          }
          if (istrue == true) {
            getShell()
                .getDisplay()
                .syncExec(
                    new Runnable() {
                      public void run() {
                        MessageDialog.openInformation(
                            getShell(),
                            "AMGA_Mangaer",
                            "Success : Files have been saved["
                                + sFullPath
                                + (page2.getComboFile() == 0 ? ".xls" : ".txt")
                                + "]"
                                + "\r\n"
                                + "File : "
                                + File
                                + " Sheet : "
                                + sheet);
                      }
                    });
          }

          break;
        case 1:
          // Txt
          String sDelimited = "";
          switch (ComboString) {
            case 0:
              sDelimited = "\t";
              break;
            case 1:
              sDelimited = " ";
              break;
            case 2:
              sDelimited = ",";
              break;
            default:
              break;
          }

          String sTitle = "";

          if (p1btnselection == true) {

            sQuery = "selectattr " + sAttr + " ' '";
            for (int i = 0; i < oColumns.size(); i++) {
              sTitle = sTitle + oColumns.get(i) + sDelimited;
            }
          } else {
            sQuery = p1_1text;
            String Query = sQuery;
            ArrayList<String> ooColumn = new ArrayList<String>();
            int nQuery = 0;
            // selectattr
            for (int i = 0; i < Query.length(); i++) {
              if (Query.charAt(i) == '\'') {
                nQuery = i;
                break;
              }
            }
            StringTokenizer st1 = new StringTokenizer(Query.substring(0, nQuery), " ");
            while (st1.hasMoreElements()) {
              String sTemp = (String) st1.nextElement();
              if (sTemp.trim().charAt(0) == '/') {
                ooColumn.add(sTemp);
              }
            }

            for (int i = 0; i < ooColumn.size(); i++) {
              sTitle = sTitle + ooColumn.get(i).substring(page1.str.length() + 1) + sDelimited;
            }

            nColumnCount = ooColumn.size();
          }
          ArrayList<String> oTxt = null;
          try {
            oTxt = command.Command_Txt(sQuery, sDelimited, nColumnCount);
          } catch (Exception e) {
            final String str1 = e.getLocalizedMessage();
            getShell()
                .getDisplay()
                .syncExec(
                    new Runnable() {
                      public void run() {
                        MessageDialog.openError(getShell(), "AMGA_Mangaer", str1);
                      }
                    });
            istrue = false;
          }
          oTxt.add(0, sTitle);
          BufferedWriter out = new BufferedWriter(new FileWriter(sFullPath + ".txt"));
          for (int i = 0; i < oTxt.size(); i++) {
            out.write(oTxt.get(i));
            out.newLine();
            monitor.worked(1);
          }
          out.close();
          if (istrue == true) {
            getShell()
                .getDisplay()
                .syncExec(
                    new Runnable() {
                      public void run() {
                        MessageDialog.openInformation(
                            getShell(),
                            "AMGA_Mangaer",
                            "Success : Files have been saved["
                                + sFullPath
                                + (page2.getComboFile() == 0 ? ".xls" : ".txt")
                                + "]");
                      }
                    });
          }
          break;
        default:
          break;
      }
    } catch (Exception e) {
      final String str = e.getLocalizedMessage();
      getShell()
          .getDisplay()
          .syncExec(
              new Runnable() {
                public void run() {
                  MessageDialog.openError(getShell(), "AMGA_Mangaer", str);
                }
              });
    }
  }
コード例 #2
0
ファイル: ExportPage1.java プロジェクト: omeryounus/amga-gui
  @Override
  public IWizardPage getNextPage() {
    ExportPage2 page2 = (ExportPage2) getWizard().getPage("ExportPage2");
    ExportPage1_1 page1_1 = (ExportPage1_1) getWizard().getPage("ExportPage1_1");
    if (btnall.getSelection() == true) {
      page2.combo.select(0);
      page2.combo_string.setEnabled(false);
      page2.lbllsheet.setText("# Excel sheet : ");
      page2.lbltip.setText(
          "\u203BTips :\r\n1. One file consists of max 7 sheats including 50,000 entries (Total : 350,000 entries)\r\n\r\r\n2. In case of a large scale of metadata, we recommend you to choose text format.");
      page2.combo.setEnabled(true);
      try {
        list = command.Command_Excel("SELECT COUNT(*) FROM " + str);
        double strr = Integer.parseInt(list.get(1));
        double strs = Math.ceil(strr / 50000);
        page2.setSheetcount((int) strs);
        double strf = Math.ceil(strr / 50000 / 2);
        page2.lblfile.setText("" + (int) strf);
        page2.lblsheet.setText("" + (int) strs);
        page2.lblrow.setText("" + (int) strr);
      } catch (Exception e1) {
        page2.lblrow.setText("0");
        page2.lblsheet.setText("0");
        page2.lblfile.setText("0");
      }
      return page2;
    } else {
      try {
        Boolean switchonplain = false;
        Boolean switchonacls = false;
        ArrayList<String> attrList = new ArrayList<String>();
        attrList = command.Command_ACL("stat " + str);
        if (attrList != null) {
          if (attrList.size() > 2) {
            String str = attrList.get(1);
            if (str.indexOf("plain") > 0) {
              switchonplain = true;
            }
            if (str.indexOf("acls") > 0) {
              switchonacls = true;
            }
          }
        }
        ArrayList<String> oList = command.Command_listAttr(str);
        String stemp = "selectattr ";
        String[] atemp;
        if (switchonplain == false) {
          stemp += " " + str + ":" + "FILE";
        }
        for (int i = 0; i < oList.size(); i++) {
          atemp = oList.get(i).split(":");
          stemp += " " + str + ":" + atemp[0];
        }
        if (switchonacls == true) {
          stemp += " " + str + ":" + "ACL";
        }
        stemp += "      '  '  ";
        page1_1.text_editor.setText("" + stemp);

      } catch (Exception e) {
        // TODO: handle exception
      }
      page2.lblrow.setText("-");
      page2.combo_string.setEnabled(true);
      page2.lblfile.setText("" + 1);
      page2.lbllsheet.setText("");
      page2.lblsheet.setText("");
      page2.lbltip.setText("");
      page2.combo.select(1);
      page2.combo.setEnabled(false);
      return page1_1;
    }
  }