private void exportFile() {
    try {
      boolean currentRowOnly = chkCurrentRow.isSelected();
      File file =
          File.createTempFile("Export", "." + cboType.getSelectedItem().getValue().toString());
      childs.clear();
      for (Checkbox chkSeletionTab : chkSelectionTabForExport) {
        if (chkSeletionTab.isChecked()) {
          childs.add((GridTab) chkSeletionTab.getAttribute("tabBinding"));
        }
      }

      exporter.export(panel.getActiveGridTab(), childs, currentRowOnly, file, indxDetailSelected);

      winExportFile.onClose();
      winExportFile = null;
      AMedia media = null;
      media =
          new AMedia(
              exporter.getSuggestedFileName(panel.getActiveGridTab()),
              null,
              exporter.getContentType(),
              file,
              true);
      Filedownload.save(media);
    } catch (Exception e) {
      throw new AdempiereException(e);
    } finally {
      if (winExportFile != null) winExportFile.onClose();
    }
  }
  public void initComponents() {
    lblDocumentNo = new Label(Util.cleanAmp(Msg.translate(Env.getCtx(), "DocumentNo")));
    lblDescription = new Label(Msg.translate(Env.getCtx(), "Description"));
    lblDateOrdered = new Label(Msg.translate(Env.getCtx(), "DateOrdered"));
    lblOrderRef = new Label(Msg.translate(Env.getCtx(), "POReference"));
    lblGrandTotal = new Label(Msg.translate(Env.getCtx(), "GrandTotal"));

    txtDocumentNo = new Textbox();
    txtDescription = new Textbox();
    txtOrderRef = new Textbox();

    dateFrom = new Datebox();
    dateTo = new Datebox();

    amountFrom = new NumberBox(false);
    amountTo = new NumberBox(false);

    isSoTrx = new Checkbox();
    isSoTrx.setLabel(Msg.translate(Env.getCtx(), "IsSOTrx"));
    isSoTrx.setChecked(!"N".equals(Env.getContext(Env.getCtx(), p_WindowNo, "IsSOTrx")));
    MLookup lookupBP = MLookupFactory.get(Env.getCtx(), p_WindowNo, 0, 3499, DisplayType.Search);
    editorBPartner =
        new WSearchEditor(
            lookupBP, Msg.translate(Env.getCtx(), "C_BPartner_ID"), "", true, false, true);
    editorBPartner.addValueChangeListener(this);
  }
  /** Show list tab can export for user selection */
  protected void displayExportTabSelection() {
    initTabInfo();

    exporter = getExporter();
    if (exporter == null) {
      Events.echoEvent("onExporterException", winExportFile, null);
    }

    // clear list checkbox selection to recreate with new reporter
    selectionTabRow.getChildren().clear();
    Vlayout vlayout = new Vlayout();
    selectionTabRow.appendChild(new Space());
    selectionTabRow.appendChild(vlayout);
    vlayout.appendChild(new Label(Msg.getMsg(Env.getCtx(), "SelectTabToExport")));

    chkSelectionTabForExport = new ArrayList<Checkbox>();
    boolean isHasSelectionTab = false;
    boolean isSelectTabDefault = false;
    // with 2Pack, default is export all child tab
    if (exporter.getClass().getName().equals("org.adempiere.pipo2.GridTab2PackExporter")) {
      isSelectTabDefault = true;
    }
    // for to make each export tab with one checkbox
    for (GridTab child : childs) {
      Checkbox chkSelectionTab = new Checkbox();
      chkSelectionTab.setLabel(child.getName());
      // just allow selection tab can export
      if (!exporter.isExportableTab(child)) {
        continue;
      }
      if (child.getTabNo() == indxDetailSelected || isSelectTabDefault) {
        chkSelectionTab.setSelected(true);
      }
      chkSelectionTab.setAttribute("tabBinding", child);
      vlayout.appendChild(chkSelectionTab);
      chkSelectionTabForExport.add(chkSelectionTab);
      isHasSelectionTab = true;
    }

    // in case no child tab can export. clear selection area
    if (isHasSelectionTab == false) {
      selectionTabRow.getChildren().clear();
    }
  }
 /** Zoom */
 public void zoom() {
   log.info("");
   Integer C_Order_ID = getSelectedRowKey();
   if (C_Order_ID == null) return;
   MQuery query = new MQuery("C_Order");
   query.addRestriction("C_Order_ID", MQuery.EQUAL, C_Order_ID);
   query.setRecordCount(1);
   int AD_WindowNo = getAD_Window_ID("C_Order", isSoTrx.isSelected());
   AEnv.zoom(AD_WindowNo, query);
 } //	zoom
Exemple #5
0
  /** Query and create TableInfo */
  private void loadTableInfo() {
    Timestamp payDate = (Timestamp) fieldPayDate.getValue();
    miniTable.setColorCompare(payDate);
    log.config("PayDate=" + payDate);

    BankInfo bi = (BankInfo) fieldBankAccount.getSelectedItem().getValue();

    ValueNamePair paymentRule = (ValueNamePair) fieldPaymentRule.getSelectedItem().getValue();
    KeyNamePair bpartner = (KeyNamePair) fieldBPartner.getSelectedItem().getValue();
    KeyNamePair docType = (KeyNamePair) fieldDtype.getSelectedItem().getValue();

    loadTableInfo(bi, payDate, paymentRule, onlyDue.isSelected(), bpartner, docType, miniTable);

    calculateSelection();
  } //  loadTableInfo
Exemple #6
0
  /**
   * Static Init
   *
   * @throws Exception
   */
  private void zkInit() throws Exception {
    //
    form.appendChild(mainPanel);
    mainPanel.appendChild(mainLayout);
    mainPanel.setStyle("width: 100%; height: 100%; padding: 0; margin: 0");
    mainLayout.setHeight("100%");
    mainLayout.setWidth("99%");
    parameterPanel.appendChild(parameterLayout);
    //
    labelBankAccount.setText(Msg.translate(Env.getCtx(), "C_BankAccount_ID"));
    fieldBankAccount.addActionListener(this);
    labelBPartner.setText(Msg.translate(Env.getCtx(), "C_BPartner_ID"));
    fieldBPartner.addActionListener(this);
    bRefresh.addActionListener(this);
    labelPayDate.setText(Msg.translate(Env.getCtx(), "PayDate"));
    labelPaymentRule.setText(Msg.translate(Env.getCtx(), "PaymentRule"));
    fieldPaymentRule.addActionListener(this);
    labelDtype.setText(Msg.translate(Env.getCtx(), "C_DocType_ID"));
    fieldDtype.addActionListener(this);
    //
    labelBankBalance.setText(Msg.translate(Env.getCtx(), "CurrentBalance"));
    labelBalance.setText("0");
    onlyDue.setText(Msg.getMsg(Env.getCtx(), "OnlyDue"));
    dataStatus.setText(" ");
    dataStatus.setPre(true);
    //
    bGenerate.addActionListener(this);
    bCancel.addActionListener(this);
    //
    North north = new North();
    north.setStyle("border: none");
    mainLayout.appendChild(north);
    north.appendChild(parameterPanel);

    Rows rows = parameterLayout.newRows();
    Row row = rows.newRow();
    row.appendChild(labelBankAccount.rightAlign());
    row.appendChild(fieldBankAccount);
    row.appendChild(labelBankBalance.rightAlign());
    Panel balancePanel = new Panel();
    balancePanel.appendChild(labelCurrency);
    balancePanel.appendChild(labelBalance);
    row.appendChild(balancePanel);
    row.appendChild(new Space());

    row = rows.newRow();
    row.appendChild(labelBPartner.rightAlign());
    row.appendChild(fieldBPartner);
    row.appendChild(new Space());
    row.appendChild(onlyDue);
    row.appendChild(new Space());

    row = rows.newRow();
    row.appendChild(labelDtype.rightAlign());
    row.appendChild(fieldDtype);
    row.appendChild(new Space());
    row.appendChild(new Space());
    row.appendChild(new Space());

    row = rows.newRow();
    row.appendChild(labelPayDate.rightAlign());
    row.appendChild(fieldPayDate.getComponent());
    row.appendChild(labelPaymentRule.rightAlign());
    row.appendChild(fieldPaymentRule);
    row.appendChild(bRefresh);

    South south = new South();
    south.setStyle("border: none");
    mainLayout.appendChild(south);
    southPanel = new Panel();
    southPanel.appendChild(dataStatus);
    south.appendChild(southPanel);
    Center center = new Center();
    mainLayout.appendChild(center);
    center.appendChild(miniTable);
    //
    commandPanel.addButton(bGenerate);
    commandPanel.getButton(ConfirmPanel.A_OK).setVisible(false);
  } //  jbInit
  /** execute export action */
  public void export() {
    exporterMap = new HashMap<String, IGridTabExporter>();
    extensionMap = new HashMap<String, String>();
    List<IGridTabExporter> exporterList =
        EquinoxExtensionLocator.instance().list(IGridTabExporter.class).getExtensions();
    for (IGridTabExporter exporter : exporterList) {
      String extension = exporter.getFileExtension();
      if (!extensionMap.containsKey(extension)) {
        extensionMap.put(extension, exporter.getFileExtensionLabel());
        exporterMap.put(extension, exporter);
      }
    }

    if (winExportFile == null) {
      winExportFile = new Window();
      winExportFile.setTitle(
          Msg.getMsg(Env.getCtx(), "Export") + ": " + panel.getActiveGridTab().getName());
      winExportFile.setWidth("450px");
      winExportFile.setClosable(true);
      winExportFile.setBorder("normal");
      winExportFile.setStyle("position:absolute");
      winExportFile.setSclass("popup-dialog");
      winExportFile.setWidgetAttribute(AdempiereWebUI.WIDGET_INSTANCE_NAME, "exportAction");

      cboType.setMold("select");

      cboType.getItems().clear();
      for (Map.Entry<String, String> entry : extensionMap.entrySet()) {
        cboType.appendItem(entry.getKey() + " - " + entry.getValue(), entry.getKey());
      }

      cboType.setSelectedIndex(0);
      cboType.addActionListener(this);

      Vbox vb = new Vbox();
      vb.setWidth("100%");
      winExportFile.appendChild(vb);

      Vlayout vlayout = new Vlayout();
      vlayout.setSclass("dialog-content");
      vb.appendChild(vlayout);

      Grid grid = GridFactory.newGridLayout();
      vlayout.appendChild(grid);

      Columns columns = new Columns();
      Column column = new Column();
      column.setHflex("min");
      columns.appendChild(column);
      column = new Column();
      column.setHflex("1");
      columns.appendChild(column);
      grid.appendChild(columns);

      Rows rows = new Rows();
      grid.appendChild(rows);

      Row row = new Row();
      rows.appendChild(row);
      row.appendChild(new Label(Msg.getMsg(Env.getCtx(), "FilesOfType")));
      row.appendChild(cboType);
      cboType.setHflex("1");

      row = new Row();
      rows.appendChild(row);
      row.appendChild(new Space());
      chkCurrentRow.setLabel(Msg.getMsg(Env.getCtx(), "ExportCurrentRowOnly"));
      chkCurrentRow.setSelected(true);
      row.appendChild(chkCurrentRow);

      selectionTabRow = new Row();
      rows.appendChild(selectionTabRow);

      LayoutUtils.addSclass("dialog-footer", confirmPanel);
      vb.appendChild(confirmPanel);
      confirmPanel.addActionListener(this);
    }
    displayExportTabSelection();
    panel.getComponent().getParent().appendChild(winExportFile);
    panel.showBusyMask(winExportFile);
    LayoutUtils.openOverlappedWindow(panel.getComponent(), winExportFile, "middle_center");
    winExportFile.addEventListener(DialogEvents.ON_WINDOW_CLOSE, this);
    winExportFile.addEventListener("onExporterException", this);
  }
  @Override
  protected void setParameters(PreparedStatement pstmt, boolean forCount) throws SQLException {
    int index = 1;
    if (txtDocumentNo.getText().length() > 0) pstmt.setString(index++, getSQLText(txtDocumentNo));
    if (txtDescription.getText().length() > 0) pstmt.setString(index++, getSQLText(txtDescription));
    if (txtOrderRef.getText().length() > 0) pstmt.setString(index++, getSQLText(txtOrderRef));
    //
    if (editorBPartner.getValue() != null) {
      Integer bp = (Integer) editorBPartner.getValue();
      pstmt.setInt(index++, bp.intValue());
      log.fine("BPartner=" + bp);
    }
    //

    Date fromD = null;
    Date toD = null;
    Timestamp from = null;
    Timestamp to = null;
    try {
      if (dateFrom.getValue() != null) {
        fromD = dateFrom.getValue();
        from = new Timestamp(fromD.getTime());
      }
    } catch (WrongValueException e) {

    }
    try {
      if (dateTo.getValue() != null) {
        toD = dateTo.getValue();
        to = new Timestamp(toD.getTime());
      }
    } catch (WrongValueException e) {

    }

    log.fine("Date From=" + from + ", To=" + to);
    if (from == null && to != null) {
      pstmt.setTimestamp(index++, to);
    } else if (from != null && to == null) {
      pstmt.setTimestamp(index++, from);
    } else if (from != null && to != null) {
      pstmt.setTimestamp(index++, from);
      pstmt.setTimestamp(index++, to);
    }

    //
    BigDecimal fromBD = null;
    BigDecimal toBD = null;
    Double fromAmt = null;
    Double toAmt = null;

    if (amountFrom.getText() != null && amountFrom.getText().trim().length() > 0) {
      try {
        fromAmt = Double.parseDouble(amountFrom.getText());
        fromBD = BigDecimal.valueOf(fromAmt);
      } catch (Exception e) {

      }
    }

    if (amountTo.getText() != null && amountTo.getText().trim().length() > 0) {
      try {
        toAmt = Double.parseDouble(amountTo.getText());
        toBD = BigDecimal.valueOf(toAmt);
      } catch (Exception e) {

      }
    }

    if (fromBD == null && toBD != null) {
      pstmt.setBigDecimal(index++, toBD);
    } else if (fromBD != null && toBD == null) {
      pstmt.setBigDecimal(index++, fromBD);
    } else if (fromBD != null && toBD != null) {
      pstmt.setBigDecimal(index++, fromBD);
      pstmt.setBigDecimal(index++, toBD);
    }

    pstmt.setString(index++, isSoTrx.isChecked() ? "Y" : "N");
  }