/**
 * Title: JAllInOne ERP/CRM application
 *
 * <p>Description: Filter frame used to view the accounting journal.
 *
 * <p>Copyright: Copyright (C) 2006 Mauro Carniel
 *
 * <p>This file is part of JAllInOne ERP/CRM application. This application is free software; you can
 * redistribute it and/or modify it under the terms of the (LGPL) Lesser General Public License as
 * published by the Free Software Foundation;
 *
 * <p>GNU LESSER GENERAL PUBLIC LICENSE Version 2.1, February 1999
 *
 * <p>This application is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU Library General Public License for more details.
 *
 * <p>You should have received a copy of the GNU Library General Public License along with this
 * library; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139,
 * USA.
 *
 * <p>The author may be contacted at: [email protected]
 *
 * @author Mauro Carniel
 * @version 1.0
 */
public class JournalFilterFrame extends InternalFrame {
  JPanel mainPanel = new JPanel();
  JPanel buttonsPanel = new JPanel();
  GridBagLayout gridBagLayout1 = new GridBagLayout();
  LabelControl labelFromDate = new LabelControl();
  LabelControl labelToDate = new LabelControl();
  LabelControl labelFromItemNr = new LabelControl();
  DateControl controlFromDate = new DateControl();
  DateControl controlToDate = new DateControl();
  NumericControl controlFromItemNr = new NumericControl();
  GenericButton printButton = new GenericButton(new ImageIcon(ClientUtils.getImage("printer.gif")));
  LabelControl labelCompanyCode = new LabelControl();
  ComboBoxControl controlCompaniesCombo = new ComboBoxControl();

  public JournalFilterFrame() {
    try {
      jbInit();

      // set domain in combo box...
      ClientApplet applet =
          ((ApplicationClientFacade) MDIFrame.getInstance().getClientFacade()).getMainClass();
      ButtonCompanyAuthorizations bca = applet.getAuthorizations().getCompanyBa();
      ArrayList companiesList = bca.getCompaniesList("ACC05");
      Domain domain = new Domain("DOMAIN_ACC05");
      for (int i = 0; i < companiesList.size(); i++) {
        if (applet
            .getAuthorizations()
            .getCompanyBa()
            .isInsertEnabled("ACC05", companiesList.get(i).toString()))
          domain.addDomainPair(companiesList.get(i), companiesList.get(i).toString());
      }
      controlCompaniesCombo.setDomain(domain);
      controlCompaniesCombo.getComboBox().setSelectedIndex(0);

      setSize(400, 200);
      MDIFrame.getInstance().add(this);
    } catch (Exception e) {
      e.printStackTrace();
    }
  }

  private void jbInit() throws Exception {
    printButton.setToolTipText(
        ClientSettings.getInstance().getResources().getResource("print journal"));
    printButton.addActionListener(new JournalFilterFrame_printButton_actionAdapter(this));
    controlCompaniesCombo.setAttributeName("companyCodeSys01WAR01");

    this.setTitle(ClientSettings.getInstance().getResources().getResource("print journal"));
    buttonsPanel.setBorder(BorderFactory.createEtchedBorder());
    mainPanel.setLayout(gridBagLayout1);
    labelFromDate.setText("from date");
    labelToDate.setText("to date");
    labelFromItemNr.setText("from item number");
    labelCompanyCode.setText("companyCodeSys01WAR01");
    this.getContentPane().add(mainPanel, BorderLayout.CENTER);
    this.getContentPane().add(buttonsPanel, BorderLayout.SOUTH);
    buttonsPanel.add(printButton, null);
    mainPanel.add(
        labelCompanyCode,
        new GridBagConstraints(
            0,
            0,
            1,
            1,
            0.0,
            0.0,
            GridBagConstraints.WEST,
            GridBagConstraints.NONE,
            new Insets(5, 5, 5, 5),
            0,
            0));
    mainPanel.add(
        labelFromDate,
        new GridBagConstraints(
            0,
            1,
            1,
            1,
            0.0,
            0.0,
            GridBagConstraints.WEST,
            GridBagConstraints.NONE,
            new Insets(5, 5, 5, 5),
            0,
            0));
    mainPanel.add(
        labelToDate,
        new GridBagConstraints(
            0,
            2,
            1,
            1,
            0.0,
            0.0,
            GridBagConstraints.WEST,
            GridBagConstraints.NONE,
            new Insets(5, 5, 5, 5),
            0,
            0));
    mainPanel.add(
        labelFromItemNr,
        new GridBagConstraints(
            0,
            3,
            1,
            1,
            0.0,
            1.0,
            GridBagConstraints.NORTHWEST,
            GridBagConstraints.NONE,
            new Insets(5, 5, 5, 5),
            0,
            0));
    mainPanel.add(
        controlCompaniesCombo,
        new GridBagConstraints(
            1,
            0,
            1,
            1,
            0.0,
            0.0,
            GridBagConstraints.WEST,
            GridBagConstraints.NONE,
            new Insets(5, 5, 5, 5),
            0,
            0));
    mainPanel.add(
        controlFromDate,
        new GridBagConstraints(
            1,
            1,
            1,
            1,
            0.0,
            0.0,
            GridBagConstraints.WEST,
            GridBagConstraints.NONE,
            new Insets(5, 5, 5, 5),
            0,
            0));
    mainPanel.add(
        controlToDate,
        new GridBagConstraints(
            1,
            2,
            1,
            1,
            0.0,
            0.0,
            GridBagConstraints.WEST,
            GridBagConstraints.NONE,
            new Insets(5, 5, 5, 5),
            0,
            0));
    mainPanel.add(
        controlFromItemNr,
        new GridBagConstraints(
            1,
            3,
            1,
            1,
            1.0,
            0.0,
            GridBagConstraints.NORTHWEST,
            GridBagConstraints.NONE,
            new Insets(5, 5, 5, 5),
            0,
            0));
    Calendar cal = Calendar.getInstance();
    cal.set(cal.DAY_OF_MONTH, 1);
    cal.set(cal.MONTH, 0);
    controlFromDate.setValue(cal.getTime());
    controlToDate.setValue(new Date());
  }

  void printButton_actionPerformed(ActionEvent e) {
    if (controlFromDate.getValue() == null || controlToDate.getValue() == null) {
      JOptionPane.showMessageDialog(
          ClientUtils.getParentFrame(this),
          ClientSettings.getInstance().getResources().getResource("please set a from/to date"),
          ClientSettings.getInstance().getResources().getResource("Attention"),
          JOptionPane.WARNING_MESSAGE);
      return;
    }
    if (controlCompaniesCombo.getValue() == null) {
      JOptionPane.showMessageDialog(
          ClientUtils.getParentFrame(this),
          ClientSettings.getInstance().getResources().getResource("please select a company"),
          ClientSettings.getInstance().getResources().getResource("Attention"),
          JOptionPane.WARNING_MESSAGE);
      return;
    }

    HashMap params = new HashMap();
    params.put("COMPANY_CODE", controlCompaniesCombo.getValue());
    params.put("START_DATE", controlFromDate.getValue());
    params.put("END_DATE", controlToDate.getValue());
    if (controlFromItemNr.getValue() != null)
      params.put(
          "FROM_PROGRESSIVE",
          " and ACC05_JOURNAL_HEADER.PROGRESSIVE>=" + controlFromItemNr.getValue());
    else params.remove("FROM_PROGRESSIVE");

    HashMap map = new HashMap();
    map.put(ApplicationConsts.COMPANY_CODE_SYS01, controlCompaniesCombo.getValue());
    map.put(ApplicationConsts.FUNCTION_CODE_SYS06, "ACC05");
    map.put(ApplicationConsts.EXPORT_PARAMS, params);
    Response res = ClientUtils.getData("getJasperReport", map);
    if (!res.isError()) {
      JasperPrint print = (JasperPrint) ((VOResponse) res).getVo();
      JRViewer viewer = new JRViewer(print);
      JFrame frame = new JFrame();
      frame.setSize(MDIFrame.getInstance().getSize());
      frame.setContentPane(viewer);
      frame.setTitle(this.getTitle());
      frame.setIconImage(MDIFrame.getInstance().getIconImage());
      frame.setVisible(true);
    } else
      JOptionPane.showMessageDialog(
          ClientUtils.getParentFrame(this),
          res.getErrorMessage(),
          ClientSettings.getInstance().getResources().getResource("print journal"),
          JOptionPane.ERROR_MESSAGE);
  }
}
Esempio n. 2
0
/**
 * Title: OpenSwing Framework
 *
 * <p>Description: Navigator bar: contains first, previous, next and last buttons. This class must
 * be used inside a GridControl.
 *
 * <p>Copyright: Copyright (C) 2006 Mauro Carniel
 *
 * <p>This file is part of OpenSwing Framework. This library is free software; you can redistribute
 * it and/or modify it under the terms of the (LGPL) Lesser General Public License as published by
 * the Free Software Foundation;
 *
 * <p>GNU LESSER GENERAL PUBLIC LICENSE Version 2.1, February 1999
 *
 * <p>This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU Library General Public License for more details.
 *
 * <p>You should have received a copy of the GNU Library General Public License along with this
 * library; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139,
 * USA.
 *
 * <p>The author may be contacted at: [email protected]
 *
 * @author Mauro Carniel
 * @version 1.0
 */
public class NavigatorBar extends JPanel {

  /** load the first block of records into the grid */
  private JButton firstButton = new GenericButton(new ImageIcon(ClientUtils.getImage("first.gif")));

  /** select the previous row in the grid */
  private JButton prevButton = new GenericButton(new ImageIcon(ClientUtils.getImage("prev.gif")));

  /** select the next row in the grid */
  private JButton nextButton = new GenericButton(new ImageIcon(ClientUtils.getImage("next.gif")));

  /** load the last block of records into the grid */
  private JButton lastButton = new GenericButton(new ImageIcon(ClientUtils.getImage("last.gif")));

  /** load the next block of records from the grid */
  private JButton nextPgButton =
      new GenericButton(new ImageIcon(ClientUtils.getImage("nextpg.gif")));

  /** load the previous block of records from the grid */
  private JButton prevPgButton =
      new GenericButton(new ImageIcon(ClientUtils.getImage("prevpg.gif")));

  /** grid control */
  private NavigatorBarController resultSetController = null;

  /**
   * list of ActionListeners registered to this navigator bar; these listeners will be called AFTER
   * a navigator button has been pressed (AFTER selecting row event)
   */
  private ArrayList afterActionListeners = new ArrayList();

  /**
   * list of ActionListeners registered to this navigator bar; these listeners will be called as the
   * first instruction when a navigator button is being pressed (BEFORE selecting row event)
   */
  private ArrayList beforeActionListeners = new ArrayList();

  public static final String FIRST_BUTTON = "FIRST_BUTTON";
  public static final String PREV_BUTTON = "PREV_BUTTON";
  public static final String NEXT_BUTTON = "NEXT_BUTTON";
  public static final String LAST_BUTTON = "LAST_BUTTON";
  public static final String NEXT_PG_BUTTON = "NEXT_PG_BUTTON";
  public static final String PREV_PG_BUTTON = "PREV_PG_BUTTON";
  public static final String UP_KEY = "UP_KEY";
  public static final String DOWN_KEY = "DOWN_KEY";
  public static final String LEFT_MOUSE_BUTTON = "LEFT_MOUSE_BUTTON";

  /**
   * optional input field used to specify the page number to load; only in case of loading one page
   * per time
   */
  private NumericControl controlPageNr = new NumericControl();

  /** current page number */
  private int currentPageNr = -1;

  /** panel that contains page number field */
  private JPanel pageNrPanel = new JPanel();

  /**
   * <code>true</code> to show pagination buttons in navigator bar; <code>false</code> to do not
   * show them; default value: <code>ClientSettings.SHOW_PAGINATION_BUTTONS_ON_NAVBAR</code>
   */
  private boolean showPaginationButtons = ClientSettings.SHOW_PAGINATION_BUTTONS_ON_NAVBAR;

  /**
   * <code>true</code> to show page number input field in navigator bar (note: it is automatically
   * hided if result set is fully loaded in grid, independently from this setting); <code>false
   * </code> to do not show it; default value: <code>true</code>
   */
  private boolean showPageNumber = true;

  public NavigatorBar() {
    try {
      jbInit();
      controlPageNr.setColumns(3);
      controlPageNr.setValue(new Integer(1));
      controlPageNr.addActionListener(
          new ActionListener() {
            public void actionPerformed(ActionEvent e) {
              if (controlPageNr.getDouble() == null) controlPageNr.setValue(new Integer(1));
              if (!checkValidPage()) return;
              currentPageNr = controlPageNr.getDouble().intValue();
              gotoPage();
            }
          });
      controlPageNr.addFocusListener(
          new FocusAdapter() {

            public void focusGained(FocusEvent e) {
              if (controlPageNr.getDouble() == null) controlPageNr.setValue(new Integer(1));
              currentPageNr = controlPageNr.getDouble().intValue();
            }

            public void focusLost(FocusEvent e) {
              if (controlPageNr.getDouble() == null) controlPageNr.setValue(new Integer(1));
              if (!checkValidPage()) return;
              int lastValue = currentPageNr;
              currentPageNr = controlPageNr.getDouble().intValue();
              if (lastValue != currentPageNr) gotoPage();
            }
          });

      firstButton.setToolTipText(
          ClientSettings.getInstance()
              .getResources()
              .getResource("Load the first block of records"));
      firstButton.setPreferredSize(new Dimension(32, 32));
      prevPgButton.setToolTipText(
          ClientSettings.getInstance()
              .getResources()
              .getResource("Load the previous block of records"));
      prevPgButton.setPreferredSize(new Dimension(32, 32));
      prevButton.setToolTipText(
          ClientSettings.getInstance()
              .getResources()
              .getResource("Select the previous row in grid"));
      prevButton.setPreferredSize(new Dimension(32, 32));
      nextButton.setToolTipText(
          ClientSettings.getInstance().getResources().getResource("Select the next row in grid"));
      nextButton.setPreferredSize(new Dimension(32, 32));
      nextPgButton.setToolTipText(
          ClientSettings.getInstance()
              .getResources()
              .getResource("Load the next block of records"));
      nextPgButton.setPreferredSize(new Dimension(32, 32));
      lastButton.setToolTipText(
          ClientSettings.getInstance()
              .getResources()
              .getResource("Load the last block of records"));
      lastButton.setPreferredSize(new Dimension(32, 32));
    } catch (Exception e) {
      e.printStackTrace();
    }
  }

  private boolean checkValidPage() {
    if (resultSetController != null
        && resultSetController.getTotalResultSetLength() != -1
        && resultSetController.getBlockSize() != -1
        && controlPageNr.getDouble().intValue()
            > resultSetController.getTotalResultSetLength() / resultSetController.getBlockSize()) {
      controlPageNr.setValue(new Integer(currentPageNr));
      return false;
    }
    return true;
  }

  /** Reload grid, starting from the specified page. */
  private void gotoPage() {
    if (currentPageNr > 0 && resultSetController != null)
      resultSetController.loadPage(currentPageNr);
  }

  /** Show/update/hide page number field, according to loading policy and current data length. */
  public final void updatePageNumber(int pageNr) {
    controlPageNr.setValue(new Integer(pageNr));
    pageNrPanel.removeAll();
    if (pageNr > 0 && showPageNumber) pageNrPanel.add(controlPageNr);
    pageNrPanel.revalidate();
    this.repaint();
  }

  private void jbInit() throws Exception {
    pageNrPanel.setLayout(new FlowLayout(FlowLayout.LEFT, 0, 0));
    firstButton.addActionListener(
        new java.awt.event.ActionListener() {
          public void actionPerformed(ActionEvent e) {
            firstButton_actionPerformed(e);
          }
        });
    prevButton.setActionCommand(PREV_BUTTON);
    prevButton.addActionListener(
        new java.awt.event.ActionListener() {
          public void actionPerformed(ActionEvent e) {
            prevButton_actionPerformed(e);
          }
        });
    prevPgButton.addActionListener(
        new java.awt.event.ActionListener() {
          public void actionPerformed(ActionEvent e) {
            prevPgButton_actionPerformed(e);
          }
        });
    nextPgButton.addActionListener(
        new java.awt.event.ActionListener() {
          public void actionPerformed(ActionEvent e) {
            nextPgButton_actionPerformed(e);
          }
        });
    nextButton.setActionCommand(NEXT_BUTTON);
    nextButton.addActionListener(
        new java.awt.event.ActionListener() {
          public void actionPerformed(ActionEvent e) {
            nextButton_actionPerformed(e);
          }
        });
    lastButton.addActionListener(
        new java.awt.event.ActionListener() {
          public void actionPerformed(ActionEvent e) {
            lastButton_actionPerformed(e);
          }
        });

    this.setLayout(new FlowLayout(FlowLayout.LEFT, 0, 0));
    this.add(firstButton, null);
    if (showPaginationButtons) this.add(prevPgButton, null);
    this.add(prevButton, null);
    this.add(pageNrPanel, null);
    this.add(nextButton, null);
    if (showPaginationButtons) this.add(nextPgButton, null);
    this.add(lastButton, null);
  }

  public void firstButton_actionPerformed(ActionEvent e) {
    if (resultSetController != null) {
      for (int i = 0; i < beforeActionListeners.size(); i++)
        ((ActionListener) beforeActionListeners.get(i))
            .actionPerformed(new ActionEvent(this, ActionEvent.ACTION_PERFORMED, FIRST_BUTTON));
      resultSetController.firstRow(this);
    }
  }

  public void prevPgButton_actionPerformed(ActionEvent e) {
    if (resultSetController != null) {
      for (int i = 0; i < beforeActionListeners.size(); i++)
        ((ActionListener) beforeActionListeners.get(i))
            .actionPerformed(new ActionEvent(this, ActionEvent.ACTION_PERFORMED, PREV_PG_BUTTON));
      resultSetController.previousPage(this);
    }
  }

  public void prevButton_actionPerformed(ActionEvent e) {
    if (resultSetController != null) {
      for (int i = 0; i < beforeActionListeners.size(); i++)
        ((ActionListener) beforeActionListeners.get(i))
            .actionPerformed(
                new ActionEvent(this, ActionEvent.ACTION_PERFORMED, e.getActionCommand()));

      resultSetController.previousRow(this, e);
    }
  }

  public void nextButton_actionPerformed(ActionEvent e) {
    if (resultSetController != null) {
      for (int i = 0; i < beforeActionListeners.size(); i++)
        ((ActionListener) beforeActionListeners.get(i))
            .actionPerformed(
                new ActionEvent(this, ActionEvent.ACTION_PERFORMED, e.getActionCommand()));

      resultSetController.nextRow(this, e);
    }
  }

  public void nextPgButton_actionPerformed(ActionEvent e) {
    if (resultSetController != null) {
      for (int i = 0; i < beforeActionListeners.size(); i++)
        ((ActionListener) beforeActionListeners.get(i))
            .actionPerformed(new ActionEvent(this, ActionEvent.ACTION_PERFORMED, NEXT_PG_BUTTON));

      resultSetController.nextPage(this);
    }
  }

  public void lastButton_actionPerformed(ActionEvent e) {
    if (resultSetController != null) {
      for (int i = 0; i < beforeActionListeners.size(); i++)
        ((ActionListener) beforeActionListeners.get(i))
            .actionPerformed(new ActionEvent(this, ActionEvent.ACTION_PERFORMED, LAST_BUTTON));

      resultSetController.lastRow(this);
    }
  }

  /** Method called by grid component each time a row is selected. */
  public void setFirstRow(boolean isFirstRecord) {
    firstButton.setEnabled(!isFirstRecord);
    prevPgButton.setEnabled(!isFirstRecord);
    prevButton.setEnabled(!isFirstRecord);
    controlPageNr.setEnabled(true);
    //    controlPageNr.setEnabled(resultSetController.getTotalResultSetLength()!=-1);
  }

  /** Method called by grid component each time a row is selected. */
  public void setLastRow(boolean isLastRecord) {
    lastButton.setEnabled(!isLastRecord);
    nextButton.setEnabled(!isLastRecord);
    nextPgButton.setEnabled(!isLastRecord);
    controlPageNr.setEnabled(true);
    //    controlPageNr.setEnabled(resultSetController.getTotalResultSetLength()!=-1);
  }

  public void setEnabled(boolean enabled) {
    controlPageNr.setEnabled(enabled);
    //    if (!enabled)
    //      controlPageNr.setEnabled(false);
    //    else
    //      controlPageNr.setEnabled(resultSetController.getTotalResultSetLength()!=-1);
    firstButton.setEnabled(enabled);
    prevPgButton.setEnabled(enabled);
    prevButton.setEnabled(enabled);
    nextButton.setEnabled(enabled);
    nextPgButton.setEnabled(enabled);
    lastButton.setEnabled(enabled);
  }

  public void initNavigator(NavigatorBarController resultSetController) {
    this.resultSetController = resultSetController;
  }

  public boolean isFirstButtonEnabled() {
    return firstButton.isEnabled();
  }

  public boolean isPrevButtonEnabled() {
    return prevButton.isEnabled();
  }

  public boolean isNextButtonEnabled() {
    return nextButton.isEnabled();
  }

  public boolean isLastButtonEnabled() {
    return lastButton.isEnabled();
  }

  /**
   * Add an ActionListener that will be called AFTER a navigator button has been pressed (AFTER
   * selecting row event).
   *
   * @param listener ActionListener to register.
   */
  public final void addAfterActionListener(ActionListener listener) {
    afterActionListeners.add(listener);
  }

  /**
   * Remove the specified ActionListener.
   *
   * @param listener ActionListener to remove.
   */
  public final void removeAfterActionListener(ActionListener listener) {
    afterActionListeners.remove(listener);
  }

  /**
   * Method invoked by the grid control when pressing a navigator button.
   *
   * @param buttonType possible values: NavigatorBar.xxx_BUTTON
   */
  public final void fireButtonPressedEvent(String buttonType) {
    for (int i = 0; i < afterActionListeners.size(); i++)
      ((ActionListener) afterActionListeners.get(i))
          .actionPerformed(new ActionEvent(this, ActionEvent.ACTION_PERFORMED, buttonType));
  }

  /**
   * Add an ActionListener that will be called as the first instruction when a navigator button is
   * being pressed (BEFORE selecting row event).
   *
   * @param listener ActionListener to register.
   */
  public final void addBeforeActionListener(ActionListener listener) {
    beforeActionListeners.add(listener);
  }

  /**
   * Remove the specified ActionListener.
   *
   * @param listener ActionListener to remove.
   */
  public final void removeBeforerActionListener(ActionListener listener) {
    beforeActionListeners.remove(listener);
  }

  /**
   * @return <code>true</code> to show pagination buttons in navigator bar; <code>false</code> to do
   *     not show them
   */
  public final boolean isShowPaginationButtons() {
    return showPaginationButtons;
  }

  /**
   * Show/hide pagination buttons in navigator bar; <code>false</code> to do not show them.
   *
   * @param showPaginationButtons <code>true</code> to show pagination buttons in navigator bar;
   *     <code>false</code> to do not show them
   */
  public final void setShowPaginationButtons(boolean showPaginationButtons) {
    if (!this.showPaginationButtons && showPaginationButtons) {
      this.add(prevPgButton, null);
      this.add(nextPgButton, null);
      this.revalidate();
      this.repaint();
    } else if (this.showPaginationButtons && !showPaginationButtons) {
      this.remove(prevPgButton);
      this.remove(nextPgButton);
      this.revalidate();
      this.repaint();
    }
    this.showPaginationButtons = showPaginationButtons;
  }

  /**
   * @return boolean <code>true</code> to show page number input field in navigator bar; <code>false
   *     </code> to do not show it; default value: <code>true</code>
   */
  public final boolean isShowPageNumber() {
    return showPageNumber;
  }

  /**
   * <code>true</code> to show page number input field in navigator bar; <code>false</code> to do
   * not show it. Note: it is automatically hided if result set is fully loaded in grid,
   * independently from this setting.
   *
   * @param showPageNumber <code>true</code> to show page number input field in navigator bar;
   *     <code>false</code> to do not show it
   */
  public final void setShowPageNumber(boolean showPageNumber) {
    this.showPageNumber = showPageNumber;
  }
}
/**
 * Title: JAllInOne ERP/CRM application
 *
 * <p>Description: Detail Frame used for a sale credit note, manually created.
 *
 * <p>Copyright: Copyright (C) 2006 Mauro Carniel
 *
 * <p>This file is part of JAllInOne ERP/CRM application. This application is free software; you can
 * redistribute it and/or modify it under the terms of the (LGPL) Lesser General Public License as
 * published by the Free Software Foundation;
 *
 * <p>GNU LESSER GENERAL PUBLIC LICENSE Version 2.1, February 1999
 *
 * <p>This application is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU Library General Public License for more details.
 *
 * <p>You should have received a copy of the GNU Library General Public License along with this
 * library; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139,
 * USA.
 *
 * <p>The author may be contacted at: [email protected]
 *
 * @author Mauro Carniel
 * @version 1.0
 */
public class SaleCreditDocFrame extends InternalFrame implements InvoiceDocument {

  /** detail form controller */
  private SaleCreditDocController controller = null;

  BorderLayout borderLayout1 = new BorderLayout();
  JPanel mainPanel = new JPanel();
  BorderLayout borderLayout2 = new BorderLayout();
  JTabbedPane tabbedPane = new JTabbedPane();
  JPanel headerPanel = new JPanel();
  FlowLayout flowLayout1 = new FlowLayout();
  JPanel headerButtonsPanel = new JPanel();
  BorderLayout borderLayout3 = new BorderLayout();
  JPanel linesPanel = new JPanel();
  BorderLayout borderLayout4 = new BorderLayout();
  Form headerFormPanel = new Form();
  InsertButton insertButton1 = new InsertButton();
  EditButton editButton1 = new EditButton();
  SaveButton saveButton1 = new SaveButton();
  ReloadButton reloadButton1 = new ReloadButton();
  DeleteButton deleteButton1 = new DeleteButton();
  GridBagLayout gridBagLayout1 = new GridBagLayout();
  SaleIdHeadPanel saleIdHeadPanel1 = new SaleIdHeadPanel(headerFormPanel, false, true);
  SaleCustomerHeadPanel saleCustomerHeadPanel1 = new SaleCustomerHeadPanel(false, headerFormPanel);
  SaleAgentPanel saleAgentPanel = new SaleAgentPanel(headerFormPanel);
  SaleNotesPanel saleNotesPanel = new SaleNotesPanel();
  SaleTotalsPanel saleTotalsPanel1 = new SaleTotalsPanel(headerFormPanel);
  SaleInvoiceDocRowsGridPanel rowsPanel =
      new SaleInvoiceDocRowsGridPanel(this, headerFormPanel, true, true);
  SaleWarehousePanel warePanel = new SaleWarehousePanel(headerFormPanel);
  JPanel addPanel = new JPanel();
  BorderLayout borderLayout5 = new BorderLayout();
  private SaleDocDiscountsPanel discPanel = new SaleDocDiscountsPanel(this, true);
  private SaleDocChargesPanel chargePanel = new SaleDocChargesPanel(this, true);
  private SaleDocActivitiesPanel actPanel = new SaleDocActivitiesPanel(this, true);
  GenericButton confirmButton =
      new GenericButton(new ImageIcon(ClientUtils.getImage("workflow.gif")));
  GenericButton printButton = new GenericButton(new ImageIcon(ClientUtils.getImage("printer.gif")));

  public SaleCreditDocFrame(SaleCreditDocController controller) {
    this.controller = controller;
    try {
      jbInit();
      setSize(750, 630);
      setMinimumSize(new Dimension(750, 630));
      setTitle(ClientSettings.getInstance().getResources().getResource("credit note"));

      //      CustomizedControls customizedControls = new
      // CustomizedControls(tabbedPane,headerFormPanel,ApplicationConsts.ID_SALE_ESTIMATE);

      //
      // saleCustomerHeadPanel1.getCustomerDataLocator().getLookupFrameParams().put(ApplicationConsts.SUBJECT_TYPE,ApplicationConsts.SUBJECT_PEOPLE_CUSTOMER);
      //
      // saleCustomerHeadPanel1.getCustomerDataLocator().getLookupValidationParameters().put(ApplicationConsts.SUBJECT_TYPE,ApplicationConsts.SUBJECT_PEOPLE_CUSTOMER);

      init();

    } catch (Exception e) {
      e.printStackTrace();
    }
  }

  /** Define input controls editable settings according to the document state. */
  private void init() {
    // disable discounts and charges when the no lines are not yet to added...
    HashSet attributeNameToDisable = new HashSet();
    attributeNameToDisable.add("allowanceDOC01");
    attributeNameToDisable.add("depositDOC01");
    headerFormPanel.addInputControlAttributesNotEditableOnState(
        attributeNameToDisable, "docStateDOC01", ApplicationConsts.OPENED);

    // disable customer and pricelist when the at least one line is added...
    attributeNameToDisable = new HashSet();
    attributeNameToDisable.add("customerCodeSAL07");
    attributeNameToDisable.add("pricelistCodeSal01DOC01");
    attributeNameToDisable.add("docDateDOC01");
    attributeNameToDisable.add("paymentCodeReg10DOC01");
    headerFormPanel.addInputControlAttributesNotEditableOnState(
        attributeNameToDisable, "docStateDOC01", ApplicationConsts.HEADER_BLOCKED);

    // disable all editable fields when the order is confimed (closed)...
    attributeNameToDisable = new HashSet();
    attributeNameToDisable.add("allowanceDOC01");
    attributeNameToDisable.add("depositDOC01");
    attributeNameToDisable.add("customerCodeSAL07");
    attributeNameToDisable.add("pricelistCodeSal01DOC01");
    attributeNameToDisable.add("docDateDOC01");
    attributeNameToDisable.add("paymentCodeReg10DOC01");
    attributeNameToDisable.add("destinationCodeReg18DOC01");
    attributeNameToDisable.add("noteDOC01");
    attributeNameToDisable.add("headingNoteDOC01");
    attributeNameToDisable.add("footerNoteDOC01");
    attributeNameToDisable.add("deliveryNoteDOC01");
    attributeNameToDisable.add("warehouseCodeWar01DOC01");
    headerFormPanel.addInputControlAttributesNotEditableOnState(
        attributeNameToDisable, "docStateDOC01", ApplicationConsts.CLOSED);

    HashSet buttonsToDisable = new HashSet();
    buttonsToDisable.add(editButton1);
    buttonsToDisable.add(deleteButton1);
    headerFormPanel.addButtonsNotEnabled(buttonsToDisable, this);
  }

  private void jbInit() throws Exception {
    printButton.setToolTipText(
        ClientSettings.getInstance().getResources().getResource("print document"));
    printButton.addActionListener(new SaleCreditDocFrame_printButton_actionAdapter(this));

    addPanel.setLayout(borderLayout5);
    confirmButton.addActionListener(new SaleCreditDocFrame_confirmButton_actionAdapter(this));

    headerFormPanel.setFunctionId("DOC01_CREDITNOTES");
    headerFormPanel.setFormController(controller);
    headerFormPanel.setVOClassName("org.jallinone.sales.documents.java.DetailSaleDocVO");

    headerPanel.setLayout(borderLayout3);
    headerButtonsPanel.setLayout(flowLayout1);
    flowLayout1.setAlignment(FlowLayout.LEFT);
    mainPanel.setLayout(borderLayout2);
    this.getContentPane().setLayout(borderLayout1);
    linesPanel.setLayout(borderLayout4);
    insertButton1.setText("insertButton1");
    reloadButton1.setText("reloadButton1");
    deleteButton1.setText("deleteButton1");
    headerFormPanel.setLayout(gridBagLayout1);
    headerFormPanel.setInsertButton(insertButton1);
    headerFormPanel.setEditButton(editButton1);
    headerFormPanel.setReloadButton(reloadButton1);
    headerFormPanel.setDeleteButton(deleteButton1);
    headerFormPanel.setSaveButton(saveButton1);
    this.getContentPane().add(mainPanel, BorderLayout.CENTER);
    mainPanel.add(tabbedPane, BorderLayout.CENTER);
    tabbedPane.add(headerPanel, "header");
    headerPanel.add(headerButtonsPanel, BorderLayout.NORTH);
    headerButtonsPanel.add(insertButton1, null);
    headerButtonsPanel.add(editButton1, null);
    headerButtonsPanel.add(saveButton1, null);
    headerButtonsPanel.add(reloadButton1, null);
    headerButtonsPanel.add(deleteButton1, null);
    headerButtonsPanel.add(confirmButton, null);
    printButton.setEnabled(false);
    headerButtonsPanel.add(printButton, null);
    linesPanel.add(rowsPanel, BorderLayout.CENTER);
    headerPanel.add(headerFormPanel, BorderLayout.CENTER);
    headerFormPanel.add(
        saleIdHeadPanel1,
        new GridBagConstraints(
            0,
            0,
            1,
            1,
            1.0,
            0.0,
            GridBagConstraints.NORTHWEST,
            GridBagConstraints.HORIZONTAL,
            new Insets(0, 0, 0, 0),
            0,
            0));
    headerFormPanel.add(
        saleCustomerHeadPanel1,
        new GridBagConstraints(
            0,
            1,
            1,
            1,
            1.0,
            0.0,
            GridBagConstraints.NORTHWEST,
            GridBagConstraints.BOTH,
            new Insets(0, 0, 0, 0),
            0,
            0));
    headerFormPanel.add(
        warePanel,
        new GridBagConstraints(
            0,
            2,
            1,
            1,
            1.0,
            0.0,
            GridBagConstraints.NORTHWEST,
            GridBagConstraints.HORIZONTAL,
            new Insets(0, 0, 0, 0),
            0,
            0));
    headerFormPanel.add(
        saleTotalsPanel1,
        new GridBagConstraints(
            0,
            3,
            1,
            1,
            1.0,
            1.0,
            GridBagConstraints.NORTHWEST,
            GridBagConstraints.HORIZONTAL,
            new Insets(0, 0, 0, 0),
            0,
            0));

    confirmButton.setToolTipText(
        ClientSettings.getInstance().getResources().getResource("credit note closing"));
    confirmButton.setEnabled(false);

    addPanel.add(saleAgentPanel, BorderLayout.NORTH);
    addPanel.add(saleNotesPanel, BorderLayout.CENTER);

    tabbedPane.add(addPanel, "notes");
    tabbedPane.add(linesPanel, "items");
    tabbedPane.add(discPanel, "customer discounts");
    tabbedPane.add(chargePanel, "charges");
    tabbedPane.add(actPanel, "activities");

    headerFormPanel.addLinkedPanel(addPanel);

    tabbedPane.setTitleAt(0, ClientSettings.getInstance().getResources().getResource("header"));
    tabbedPane.setTitleAt(1, ClientSettings.getInstance().getResources().getResource("notes"));
    tabbedPane.setTitleAt(2, ClientSettings.getInstance().getResources().getResource("items"));
    tabbedPane.setTitleAt(
        3, ClientSettings.getInstance().getResources().getResource("customer discounts"));
    tabbedPane.setTitleAt(4, ClientSettings.getInstance().getResources().getResource("charges"));
    tabbedPane.setTitleAt(
        5, ClientSettings.getInstance().getResources().getResource("sale activities"));
  }

  public Form getHeaderFormPanel() {
    return headerFormPanel;
  }

  public void setButtonsEnabled(boolean enabled) {
    rowsPanel.setButtonsEnabled(enabled);
    discPanel.setEnabled(enabled);
    chargePanel.setEnabled(enabled);
    actPanel.setEnabled(enabled);
  }

  public void loadDataCompleted(boolean error, SaleDocPK pk) {
    DetailSaleDocVO vo = (DetailSaleDocVO) headerFormPanel.getVOModel().getValueObject();

    this.setTitle(
        ClientSettings.getInstance().getResources().getResource("credit note")
            + (vo.getDocSequenceDOC01() != null
                ? " - " + vo.getDocYearDOC01() + "/" + vo.getDocSequenceDOC01()
                : "")
            + " - "
            + vo.getName_1REG04()
            + " "
            + (vo.getName_2REG04() == null ? "" : vo.getName_2REG04()));

    saleTotalsPanel1.getControlTaxableIncome().setDecimals(vo.getDecimalsREG03().intValue());
    saleTotalsPanel1.getControlTaxableIncome().setCurrencySymbol(vo.getCurrencySymbolREG03());
    saleTotalsPanel1
        .getControlTaxableIncome()
        .setDecimalSymbol(vo.getDecimalSymbolREG03().charAt(0));
    saleTotalsPanel1
        .getControlTaxableIncome()
        .setGroupingSymbol(vo.getThousandSymbolREG03().charAt(0));

    saleTotalsPanel1.getControlTotal().setDecimals(vo.getDecimalsREG03().intValue());
    saleTotalsPanel1.getControlTotal().setCurrencySymbol(vo.getCurrencySymbolREG03());
    saleTotalsPanel1.getControlTotal().setDecimalSymbol(vo.getDecimalSymbolREG03().charAt(0));
    saleTotalsPanel1.getControlTotal().setGroupingSymbol(vo.getThousandSymbolREG03().charAt(0));

    saleTotalsPanel1.getControlTotalVat().setDecimals(vo.getDecimalsREG03().intValue());
    saleTotalsPanel1.getControlTotalVat().setCurrencySymbol(vo.getCurrencySymbolREG03());
    saleTotalsPanel1.getControlTotalVat().setDecimalSymbol(vo.getDecimalSymbolREG03().charAt(0));
    saleTotalsPanel1.getControlTotalVat().setGroupingSymbol(vo.getThousandSymbolREG03().charAt(0));

    saleTotalsPanel1.getControlAllowance().setDecimals(vo.getDecimalsREG03().intValue());
    saleTotalsPanel1.getControlAllowance().setCurrencySymbol(vo.getCurrencySymbolREG03());
    saleTotalsPanel1.getControlAllowance().setDecimalSymbol(vo.getDecimalSymbolREG03().charAt(0));
    saleTotalsPanel1.getControlAllowance().setGroupingSymbol(vo.getThousandSymbolREG03().charAt(0));

    saleTotalsPanel1.getControlDeposit().setDecimals(vo.getDecimalsREG03().intValue());
    saleTotalsPanel1.getControlDeposit().setCurrencySymbol(vo.getCurrencySymbolREG03());
    saleTotalsPanel1.getControlDeposit().setDecimalSymbol(vo.getDecimalSymbolREG03().charAt(0));
    saleTotalsPanel1.getControlDeposit().setGroupingSymbol(vo.getThousandSymbolREG03().charAt(0));

    rowsPanel.setParentVO(vo);
    rowsPanel.getGrid().getOtherGridParams().put(ApplicationConsts.SALE_DOC_PK, pk);
    rowsPanel.getGrid().reloadData();

    discPanel.setParentVO(vo);
    discPanel.getGrid().getOtherGridParams().put(ApplicationConsts.SALE_DOC_PK, pk);
    discPanel.getGrid().reloadData();

    chargePanel.setParentVO(vo);
    chargePanel.getGrid().getOtherGridParams().put(ApplicationConsts.SALE_DOC_PK, pk);
    chargePanel.getGrid().reloadData();

    actPanel.setParentVO(vo);
    actPanel.getGrid().getOtherGridParams().put(ApplicationConsts.SALE_DOC_PK, pk);
    actPanel.getGrid().reloadData();

    if (vo.getDocStateDOC01().equals(ApplicationConsts.CONFIRMED)
        || vo.getDocStateDOC01().equals(ApplicationConsts.CLOSED)) {
      confirmButton.setEnabled(false);
      setButtonsEnabled(false);
      rowsPanel.setButtonsEnabled(false);
    }
    if (!vo.getDocStateDOC01().equals(ApplicationConsts.HEADER_BLOCKED)) {
      confirmButton.setEnabled(false);
    }
    if (vo.getDocStateDOC01().equals(ApplicationConsts.HEADER_BLOCKED)) {
      confirmButton.setEnabled(true);
    }

    if (vo.getDocStateDOC01().equals(ApplicationConsts.CONFIRMED)
        || vo.getDocStateDOC01().equals(ApplicationConsts.CLOSED)
        || vo.getDocStateDOC01().equals(ApplicationConsts.HEADER_BLOCKED)) {
      printButton.setEnabled(true);
    } else {
      printButton.setEnabled(false);
    }
  }

  /**
   * Method called by GenericButton.setEnabled method to check if the button must be disabled.
   *
   * @param button button whose abilitation must be checked
   * @return <code>true</code> if no policy is defined in the form/grid for the specified button,
   *     <code>false</code> if there exists a disabilitation policy for the specified button
   *     (through addButtonsNotEnabledOnState form/grid method)
   */
  public boolean isButtonDisabled(GenericButton button) {
    if (headerFormPanel.getVOModel() == null) return false;
    DetailSaleDocVO vo = (DetailSaleDocVO) headerFormPanel.getVOModel().getValueObject();
    if (vo != null
        && vo.getDocStateDOC01() != null
        && vo.getDocStateDOC01().equals(ApplicationConsts.CLOSED)) return true;
    else return false;
  }

  public SaleInvoiceDocRowsGridPanel getRowsPanel() {
    return rowsPanel;
  }

  public GridControl getInvoices() {
    if (controller.getParentFrame() != null) return controller.getParentFrame().getGrid();
    else return null;
  }

  void confirmButton_actionPerformed(ActionEvent e) {
    // view close dialog...
    if (JOptionPane.showConfirmDialog(
            ClientUtils.getParentFrame(this),
            ClientSettings.getInstance().getResources().getResource("close credit note?"),
            ClientSettings.getInstance().getResources().getResource("credit note closing"),
            JOptionPane.YES_NO_OPTION)
        == JOptionPane.YES_OPTION) {

      Response res = ClientUtils.getData("closeSaleDoc", controller.getPk());
      if (!res.isError()) {
        confirmButton.setEnabled(false);
        headerFormPanel.setMode(Consts.READONLY);
        headerFormPanel.executeReload();
        if (getInvoices() != null) getInvoices().reloadCurrentBlockOfData();
      } else
        JOptionPane.showMessageDialog(
            ClientUtils.getParentFrame(this),
            res.getErrorMessage(),
            ClientSettings.getInstance().getResources().getResource("credit note closing"),
            JOptionPane.ERROR_MESSAGE);
    }
  }

  public SaleDocDiscountsPanel getDiscPanel() {
    return discPanel;
  }

  public SaleDocChargesPanel getChargePanel() {
    return chargePanel;
  }

  public SaleDocActivitiesPanel getActPanel() {
    return actPanel;
  }

  public DetailSaleDocVO getParentVO() {
    return (DetailSaleDocVO) headerFormPanel.getVOModel().getValueObject();
  }

  public SaleCustomerHeadPanel getSaleCustomerHeadPanel1() {
    return saleCustomerHeadPanel1;
  }

  public SaleWarehousePanel getWarePanel() {
    return warePanel;
  }

  public String getFunctionId() {
    return "DOC01_CREDITNOTES";
  }

  public void enabledConfirmButton() {
    confirmButton.setEnabled(true);
  }

  void printButton_actionPerformed(ActionEvent e) {
    DetailSaleDocVO vo = (DetailSaleDocVO) headerFormPanel.getVOModel().getValueObject();

    HashMap params = new HashMap();
    params.put("COMPANY_CODE", vo.getCompanyCodeSys01DOC01());
    params.put("DOC_TYPE", vo.getDocTypeDOC01());
    params.put("DOC_YEAR", vo.getDocYearDOC01());
    params.put("DOC_NUMBER", vo.getDocNumberDOC01());

    HashMap map = new HashMap();
    map.put(ApplicationConsts.COMPANY_CODE_SYS01, vo.getCompanyCodeSys01DOC01());
    map.put(ApplicationConsts.FUNCTION_CODE_SYS06, headerFormPanel.getFunctionId());
    map.put(ApplicationConsts.EXPORT_PARAMS, params);
    Response res = ClientUtils.getData("getJasperReport", map);
    if (!res.isError()) {
      JasperPrint print = (JasperPrint) ((VOResponse) res).getVo();
      JRViewer viewer = new JRViewer(print);
      JFrame frame = new JFrame();
      frame.setSize(MDIFrame.getInstance().getSize());
      frame.setContentPane(viewer);
      frame.setTitle(this.getTitle());
      frame.setIconImage(MDIFrame.getInstance().getIconImage());
      frame.setVisible(true);
    } else
      JOptionPane.showMessageDialog(
          ClientUtils.getParentFrame(this),
          res.getErrorMessage(),
          ClientSettings.getInstance().getResources().getResource("print document"),
          JOptionPane.ERROR_MESSAGE);
  }
}
/**
 * Title: JAllInOne ERP/CRM application
 *
 * <p>Description: Detail frame related to a supplier.
 *
 * <p>Copyright: Copyright (C) 2006 Mauro Carniel
 *
 * <p>This file is part of JAllInOne ERP/CRM application. This application is free software; you can
 * redistribute it and/or modify it under the terms of the (LGPL) Lesser General Public License as
 * published by the Free Software Foundation;
 *
 * <p>GNU LESSER GENERAL PUBLIC LICENSE Version 2.1, February 1999
 *
 * <p>This application is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU Library General Public License for more details.
 *
 * <p>You should have received a copy of the GNU Library General Public License along with this
 * library; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139,
 * USA.
 *
 * <p>The author may be contacted at: [email protected]
 *
 * @author Mauro Carniel
 * @version 1.0
 */
public class SupplierDetailFrame extends InternalFrame {
  JPanel buttonsPanel = new JPanel();
  FlowLayout flowLayout1 = new FlowLayout();
  InsertButton insertButton = new InsertButton();
  EditButton editButton = new EditButton();
  SaveButton saveButton = new SaveButton();
  ReloadButton reloadButton = new ReloadButton();
  DeleteButton deleteButton = new DeleteButton();
  OrganizationPanel organizationPanel = new OrganizationPanel(false);
  LabelControl labelCompanyCode = new LabelControl();
  CompaniesComboControl controlCompanyCode = new CompaniesComboControl();
  JTabbedPane tabbedPane = new JTabbedPane();
  Form supplierPanel = new Form();
  JPanel subjectPanel = new JPanel();
  GridBagLayout gridBagLayout1 = new GridBagLayout();
  TitledBorder titledBorder1;
  TitledBorder titledBorder2;
  GridBagLayout gridBagLayout2 = new GridBagLayout();
  LabelControl labelSupplierCode = new LabelControl();
  TextControl controlSupplierCode = new TextControl();
  LabelControl labelPay = new LabelControl();
  CodLookupControl controlPayment = new CodLookupControl();
  TextControl controlPayDescr = new TextControl();
  LabelControl labelPricelist = new LabelControl();
  LabelControl labelBank = new LabelControl();
  CodLookupControl controlBank = new CodLookupControl();
  TextControl controlBankDescr = new TextControl();

  LookupController bankController = new LookupController();
  LookupServerDataLocator bankDataLocator = new LookupServerDataLocator();

  LookupController payController = new LookupController();
  LookupServerDataLocator payDataLocator = new LookupServerDataLocator();
  private java.util.List list = null;

  JPanel refPanel = new JPanel();
  BorderLayout borderLayout1 = new BorderLayout();
  BorderLayout borderLayout2 = new BorderLayout();
  BorderLayout borderLayout4 = new BorderLayout();
  ReferencesPanel referencesPanel = new ReferencesPanel();
  JPanel hierarPanel = new JPanel();
  SubjectHierarchyLevelsPanel hierarchiesPanel = new SubjectHierarchyLevelsPanel();
  JPanel treeGridItemsPanel = new JPanel();
  BorderLayout borderLayout3 = new BorderLayout();
  JSplitPane itemsSplitPane = new JSplitPane();
  HierarTreePanel treePanel = new HierarTreePanel();
  JPanel itemsPanel = new JPanel();
  BorderLayout borderLayout5 = new BorderLayout();
  JPanel itemButtonsPanel = new JPanel();
  FlowLayout flowLayout2 = new FlowLayout();
  GridControl itemsGrid = new GridControl();
  InsertButton insertButton1 = new InsertButton();
  EditButton editButton1 = new EditButton();
  SaveButton saveButton1 = new SaveButton();
  ReloadButton reloadButton1 = new ReloadButton();
  ExportButton exportButton1 = new ExportButton();
  NavigatorBar navigatorBar1 = new NavigatorBar();
  DeleteButton deleteButton1 = new DeleteButton();
  JPanel itemHierarsPanel = new JPanel();
  LabelControl labelHierar = new LabelControl();
  ComboBoxControl controlHierarchy = new ComboBoxControl();
  GridBagLayout gridBagLayout3 = new GridBagLayout();
  CodLookupColumn colItemCode = new CodLookupColumn();
  TextColumn colItemDescr = new TextColumn();
  TextColumn colSupplierItemCode = new TextColumn();
  CodLookupColumn colUmCode = new CodLookupColumn();
  DecimalColumn colMinQty = new DecimalColumn();
  DecimalColumn colMultipleQty = new DecimalColumn();

  LookupController itemController = new LookupController();
  LookupServerDataLocator itemDataLocator = new LookupServerDataLocator();

  LookupController umController = new LookupController();
  LookupServerDataLocator umDataLocator = new LookupServerDataLocator();

  /** items grid data locator */
  private ServerGridDataLocator itemsGridDataLocator = new ServerGridDataLocator();

  SupplierPricelistPanel supplierPricelistPanel = new SupplierPricelistPanel();

  JPanel detailPanel = new JPanel();
  GridBagLayout gridBagLayout4 = new GridBagLayout();
  GenericButton impAllItemsButton =
      new GenericButton(new ImageIcon(ClientUtils.getImage("doc3.gif")));

  LabelControl labelDebit = new LabelControl();
  LabelControl labelPurchase = new LabelControl();
  CodLookupControl controlDebitsCode = new CodLookupControl();
  TextControl controlDebitsDescr = new TextControl();
  CodLookupControl controlCostsCode = new CodLookupControl();
  TextControl controlCostsDescr = new TextControl();
  LookupController debitController = new LookupController();
  LookupServerDataLocator debitDataLocator = new LookupServerDataLocator();
  LookupController costsController = new LookupController();
  LookupServerDataLocator costsDataLocator = new LookupServerDataLocator();
  NavigatorBar navigatorBar = new NavigatorBar();

  public SupplierDetailFrame(final SupplierController controller) {
    try {
      jbInit();
      setSize(750, 550);
      setMinimumSize(new Dimension(750, 550));

      supplierPanel.setFormController(controller);
      supplierPanel.setInsertButton(insertButton);
      supplierPanel.setEditButton(editButton);
      supplierPanel.setReloadButton(reloadButton);
      supplierPanel.setDeleteButton(deleteButton);
      supplierPanel.setSaveButton(saveButton);
      supplierPanel.setFunctionId("PUR01");
      organizationPanel.setFunctionId("PUR01");

      // link the parent grid to the current Form...
      HashSet pk = new HashSet();
      pk.add("companyCodeSys01REG04");
      pk.add("progressiveREG04");
      supplierPanel.linkGrid(
          controller.getGridFrame().getGrid(), pk, true, true, true, navigatorBar);

      // banks lookup...
      bankDataLocator.setGridMethodName("loadBanks");
      bankDataLocator.setValidationMethodName("validateBankCode");
      controlBank.setLookupController(bankController);
      controlBank.setControllerMethodName("getBanksList");
      bankController.setLookupDataLocator(bankDataLocator);
      bankController.setFrameTitle("banks");
      bankController.setLookupValueObjectClassName("org.jallinone.registers.bank.java.BankVO");
      bankController.addLookup2ParentLink("bankCodeREG12", "bankCodeReg12PUR01");
      bankController.addLookup2ParentLink("descriptionREG12", "descriptionREG12");
      bankController.setAllColumnVisible(false);
      bankController.setVisibleColumn("bankCodeREG12", true);
      bankController.setVisibleColumn("descriptionREG12", true);
      bankController.setPreferredWidthColumn("descriptionREG12", 200);
      new CustomizedColumns(new BigDecimal(232), bankController);

      // payments lookup...
      payDataLocator.setGridMethodName("loadPayments");
      payDataLocator.setValidationMethodName("validatePaymentCode");
      controlPayment.setLookupController(payController);
      controlPayment.setControllerMethodName("getPaymentsList");
      payController.setLookupDataLocator(payDataLocator);
      payController.setFrameTitle("payments");
      payController.setLookupValueObjectClassName(
          "org.jallinone.registers.payments.java.PaymentVO");
      payController.addLookup2ParentLink("paymentCodeREG10", "paymentCodeReg10PUR01");
      payController.addLookup2ParentLink("descriptionSYS10", "paymentDescriptionSYS10");
      payController.setAllColumnVisible(false);
      payController.setVisibleColumn("paymentCodeREG10", true);
      payController.setVisibleColumn("descriptionSYS10", true);
      payController.setPreferredWidthColumn("descriptionSYS10", 200);
      new CustomizedColumns(new BigDecimal(212), payController);
      payController.addLookupListener(
          new LookupListener() {

            public void beforeLookupAction(
                org.openswing.swing.message.receive.java.ValueObject parentVO) {
              DetailSupplierVO vo = (DetailSupplierVO) parentVO;
              payDataLocator
                  .getLookupValidationParameters()
                  .put(ApplicationConsts.COMPANY_CODE_SYS01, vo.getCompanyCodeSys01REG04());
              payDataLocator
                  .getLookupFrameParams()
                  .put(ApplicationConsts.COMPANY_CODE_SYS01, vo.getCompanyCodeSys01REG04());
            }

            public void codeChanged(
                org.openswing.swing.message.receive.java.ValueObject parentVO,
                Collection parentChangedAttributes) {}

            public void codeValidated(boolean validated) {}

            public void forceValidate() {}
          });

      // items lookup...
      itemDataLocator.setGridMethodName("loadItems");
      itemDataLocator.setValidationMethodName("validateItemCode");
      colItemCode.setLookupController(itemController);
      colItemCode.setControllerMethodName("getItemsList");
      itemController.setLookupDataLocator(itemDataLocator);
      itemController.setFrameTitle("items");
      itemController.setLookupValueObjectClassName("org.jallinone.items.java.GridItemVO");
      itemController.addLookup2ParentLink("companyCodeSys01ITM01", "companyCodeSys01PUR02");
      itemController.addLookup2ParentLink("itemCodeITM01", "itemCodeItm01PUR02");
      itemController.addLookup2ParentLink("descriptionSYS10", "descriptionSYS10");
      itemController.setAllColumnVisible(false);
      itemController.setVisibleColumn("itemCodeITM01", true);
      itemController.setVisibleColumn("descriptionSYS10", true);
      itemController.setPreferredWidthColumn("descriptionSYS10", 200);
      new CustomizedColumns(ApplicationConsts.ID_ITEMS_GRID, itemController);
      itemController.addLookupListener(
          new LookupListener() {

            public void codeValidated(boolean validated) {}

            public void codeChanged(ValueObject parentVO, Collection parentChangedAttributes) {
              GridItemVO vo = (GridItemVO) itemController.getLookupVO();
              if (vo.getItemCodeITM01() != null) {
                SupplierItemVO supplierVO = (SupplierItemVO) parentVO;
                supplierVO.setSupplierItemCodePUR02(vo.getItemCodeITM01());
              }
            }

            public void beforeLookupAction(ValueObject parentVO) {}

            public void forceValidate() {}
          });

      // purchase um lookup...
      umDataLocator.setGridMethodName("loadMeasures");
      umDataLocator.setValidationMethodName("validateMeasureCode");
      colUmCode.setLookupController(umController);
      colUmCode.setControllerMethodName("getMeasureUnitsList");
      umController.setLookupDataLocator(umDataLocator);
      umController.setFrameTitle("measures");
      umController.setLookupValueObjectClassName("org.jallinone.registers.measure.java.MeasureVO");
      umController.addLookup2ParentLink("umCodeREG02", "umCodeReg02PUR02");
      umController.addLookup2ParentLink("decimalsREG02", "decimalsREG02");
      umController.setAllColumnVisible(false);
      umController.setVisibleColumn("umCodeREG02", true);
      umController.setVisibleColumn("decimalsREG02", true);
      new CustomizedColumns(ApplicationConsts.ID_UM_GRID, umController);
      umController.addLookupListener(
          new LookupListener() {

            public void codeValidated(boolean validated) {}

            public void codeChanged(ValueObject parentVO, Collection parentChangedAttributes) {
              MeasureVO vo = (MeasureVO) umController.getLookupVO();
              if (vo.getUmCodeREG02() != null) {
                colMinQty.setDecimals(vo.getDecimalsREG02().intValue());
                colMultipleQty.setDecimals(vo.getDecimalsREG02().intValue());
                SupplierItemVO supplierVO = (SupplierItemVO) parentVO;
                if (supplierVO.getMinPurchaseQtyPUR02() != null)
                  supplierVO.setMinPurchaseQtyPUR02(
                      supplierVO
                          .getMinPurchaseQtyPUR02()
                          .setScale(vo.getDecimalsREG02().intValue(), BigDecimal.ROUND_HALF_UP));
                if (supplierVO.getMultipleQtyPUR02() != null)
                  supplierVO.setMultipleQtyPUR02(
                      supplierVO
                          .getMultipleQtyPUR02()
                          .setScale(vo.getDecimalsREG02().intValue(), BigDecimal.ROUND_HALF_UP));
              }
            }

            public void beforeLookupAction(ValueObject parentVO) {}

            public void forceValidate() {}
          });

      itemsGrid.setController(new SupplierItemsController(this));
      itemsGrid.setGridDataLocator(itemsGridDataLocator);
      itemsGridDataLocator.setServerMethodName("loadSupplierItems");

      treePanel.addHierarTreeListener(
          new HierarTreeListener() {

            public void loadDataCompleted(boolean error) {
              if (treePanel.getTree().getRowCount() > 0) treePanel.getTree().setSelectionRow(0);
              if (treePanel.getTree().getSelectionPath() != null)
                controller.leftClick(
                    (DefaultMutableTreeNode)
                        treePanel.getTree().getSelectionPath().getLastPathComponent());
            }
          });

      treePanel.setTreeController(controller);
      treePanel.setFunctionId("PUR01");

      init();

      itemsGrid.enableDrag(ApplicationConsts.ID_SUPPLIER_ITEMS_GRID.toString());

      // debit account code lookup...
      controlDebitsCode.setLookupController(debitController);
      controlDebitsCode.setControllerMethodName("getAccounts");
      debitController.setLookupDataLocator(debitDataLocator);
      debitDataLocator.setGridMethodName("loadAccounts");
      debitDataLocator.setValidationMethodName("validateAccountCode");
      debitController.setFrameTitle("accounts");
      debitController.setAllowTreeLeafSelectionOnly(false);
      debitController.setLookupValueObjectClassName(
          "org.jallinone.accounting.accounts.java.AccountVO");
      debitController.addLookup2ParentLink("accountCodeACC02", "debitAccountCodeAcc02PUR01");
      debitController.addLookup2ParentLink("descriptionSYS10", "debitAccountDescrPUR01");
      debitController.setFramePreferedSize(new Dimension(400, 400));
      debitController.setAllColumnVisible(false);
      debitController.setVisibleColumn("accountCodeACC02", true);
      debitController.setVisibleColumn("descriptionSYS10", true);
      debitController.setFilterableColumn("accountCodeACC02", true);
      debitController.setFilterableColumn("descriptionSYS10", true);
      debitController.setSortedColumn("accountCodeACC02", "ASC", 1);
      debitController.setSortableColumn("accountCodeACC02", true);
      debitController.setSortableColumn("descriptionSYS10", true);
      debitController.setPreferredWidthColumn("accountCodeACC02", 100);
      debitController.setPreferredWidthColumn("descriptionSYS10", 290);
      debitController.addLookupListener(
          new LookupListener() {

            public void codeValidated(boolean validated) {}

            public void codeChanged(ValueObject parentVO, Collection parentChangedAttributes) {}

            public void beforeLookupAction(ValueObject parentVO) {
              debitDataLocator
                  .getLookupFrameParams()
                  .put(ApplicationConsts.COMPANY_CODE_SYS01, controlCompanyCode.getValue());
              debitDataLocator
                  .getLookupValidationParameters()
                  .put(ApplicationConsts.COMPANY_CODE_SYS01, controlCompanyCode.getValue());
            }

            public void forceValidate() {}
          });

      // costs account code lookup...
      controlCostsCode.setLookupController(costsController);
      controlCostsCode.setControllerMethodName("getAccounts");
      costsController.setLookupDataLocator(costsDataLocator);
      costsDataLocator.setGridMethodName("loadAccounts");
      costsDataLocator.setValidationMethodName("validateAccountCode");
      costsController.setFrameTitle("accounts");
      costsController.setAllowTreeLeafSelectionOnly(false);
      costsController.setLookupValueObjectClassName(
          "org.jallinone.accounting.accounts.java.AccountVO");
      costsController.addLookup2ParentLink("accountCodeACC02", "costsAccountCodeAcc02PUR01");
      costsController.addLookup2ParentLink("descriptionSYS10", "costsAccountDescrPUR01");
      costsController.setFramePreferedSize(new Dimension(400, 400));
      costsController.setAllColumnVisible(false);
      costsController.setVisibleColumn("accountCodeACC02", true);
      costsController.setVisibleColumn("descriptionSYS10", true);
      costsController.setFilterableColumn("accountCodeACC02", true);
      costsController.setFilterableColumn("descriptionSYS10", true);
      costsController.setSortedColumn("accountCodeACC02", "ASC", 1);
      costsController.setSortableColumn("accountCodeACC02", true);
      costsController.setSortableColumn("descriptionSYS10", true);
      costsController.setPreferredWidthColumn("accountCodeACC02", 100);
      costsController.setPreferredWidthColumn("descriptionSYS10", 290);
      costsController.addLookupListener(
          new LookupListener() {

            public void codeValidated(boolean validated) {}

            public void codeChanged(ValueObject parentVO, Collection parentChangedAttributes) {}

            public void beforeLookupAction(ValueObject parentVO) {
              costsDataLocator
                  .getLookupFrameParams()
                  .put(ApplicationConsts.COMPANY_CODE_SYS01, controlCompanyCode.getValue());
              costsDataLocator
                  .getLookupValidationParameters()
                  .put(ApplicationConsts.COMPANY_CODE_SYS01, controlCompanyCode.getValue());
            }

            public void forceValidate() {}
          });

      CustomizedControls customizedControls =
          new CustomizedControls(tabbedPane, supplierPanel, ApplicationConsts.ID_SUPPLIER_GRID);
    } catch (Exception e) {
      e.printStackTrace();
    }
  }

  /** Retrieve item types and fill in the item types combo box. */
  private void init() {
    Response res = ClientUtils.getData("loadItemTypes", new GridParams());
    Domain d = new Domain("ITEM_TYPES");
    if (!res.isError()) {
      ItemTypeVO vo = null;
      list = ((VOListResponse) res).getRows();
      for (int i = 0; i < list.size(); i++) {
        vo = (ItemTypeVO) list.get(i);
        d.addDomainPair(vo.getProgressiveHie02ITM02(), vo.getDescriptionSYS10());
      }
    }
    controlHierarchy.setDomain(d);
    controlHierarchy
        .getComboBox()
        .addItemListener(
            new ItemListener() {
              public void itemStateChanged(ItemEvent e) {
                if (e.getStateChange() == e.SELECTED) {
                  ItemTypeVO typeVO = (ItemTypeVO) list.get(controlHierarchy.getSelectedIndex());
                  treePanel.setCompanyCode(typeVO.getCompanyCodeSys01ITM02());
                  treePanel.setProgressiveHIE02((BigDecimal) controlHierarchy.getValue());
                  DetailSupplierVO vo =
                      (DetailSupplierVO) supplierPanel.getVOModel().getValueObject();
                  treePanel.setCompanyCode(vo.getCompanyCodeSys01REG04());
                  treePanel.reloadTree();
                  itemsGrid.clearData();
                }
              }
            });
    if (d.getDomainPairList().length == 1) controlHierarchy.getComboBox().setSelectedIndex(0);
    else controlHierarchy.getComboBox().setSelectedIndex(-1);
  }

  private void jbInit() throws Exception {
    itemsGrid.setMaxNumberOfRowsOnInsert(50);
    impAllItemsButton.setToolTipText(
        ClientSettings.getInstance().getResources().getResource("import all items"));
    impAllItemsButton.addActionListener(
        new SupplierDetailFrame_impAllItemsButton_actionAdapter(this));

    detailPanel.setLayout(gridBagLayout4);
    itemsGrid.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
    supplierPanel.setVOClassName("org.jallinone.purchases.suppliers.java.DetailSupplierVO");
    supplierPanel.addLinkedPanel(organizationPanel);
    titledBorder1 = new TitledBorder("");
    titledBorder2 = new TitledBorder("");
    subjectPanel.setLayout(gridBagLayout1);
    supplierPanel.setBorder(titledBorder1);
    supplierPanel.setLayout(gridBagLayout2);
    titledBorder1.setTitle(ClientSettings.getInstance().getResources().getResource("supplier"));
    titledBorder1.setTitleColor(Color.blue);
    labelSupplierCode.setText("supplierCodePUR01");
    labelPay.setText("payment terms");
    labelBank.setText("bank");
    controlSupplierCode.setAttributeName("supplierCodePUR01");
    controlSupplierCode.setCanCopy(false);
    controlSupplierCode.setLinkLabel(labelSupplierCode);
    controlSupplierCode.setMaxCharacters(20);
    //    controlSupplierCode.setRequired(true);
    controlSupplierCode.setTrimText(true);
    controlSupplierCode.setUpperCase(true);
    controlSupplierCode.setEnabledOnEdit(false);
    controlPayment.setAttributeName("paymentCodeReg10PUR01");
    controlPayment.setCanCopy(true);
    controlPayment.setLinkLabel(labelPay);
    controlPayment.setMaxCharacters(20);
    controlPayment.setRequired(true);
    controlPayDescr.setAttributeName("paymentDescriptionSYS10");
    controlPayDescr.setCanCopy(true);
    controlPayDescr.setEnabledOnInsert(false);
    controlPayDescr.setEnabledOnEdit(false);
    controlBank.setAttributeName("bankCodeReg12PUR01");
    controlBank.setCanCopy(true);
    controlBank.setLinkLabel(labelBank);
    controlBank.setMaxCharacters(20);
    controlBankDescr.setAttributeName("descriptionREG12");
    controlBankDescr.setCanCopy(true);
    controlBankDescr.setEnabledOnInsert(false);
    controlBankDescr.setEnabledOnEdit(false);
    refPanel.setLayout(borderLayout1);
    hierarPanel.setLayout(borderLayout4);
    treeGridItemsPanel.setLayout(borderLayout3);
    itemsSplitPane.setOrientation(JSplitPane.HORIZONTAL_SPLIT);
    itemsSplitPane.setDividerSize(5);
    itemsPanel.setLayout(borderLayout5);
    itemButtonsPanel.setLayout(flowLayout2);
    flowLayout2.setAlignment(FlowLayout.LEFT);
    itemsGrid.setAutoLoadData(false);
    itemsGrid.setDeleteButton(deleteButton1);
    itemsGrid.setEditButton(editButton1);
    itemsGrid.setExportButton(exportButton1);
    itemsGrid.setFunctionId("PUR01");
    itemsGrid.setMaxSortedColumns(3);
    itemsGrid.setInsertButton(insertButton1);
    itemsGrid.setNavBar(navigatorBar1);
    itemsGrid.setReloadButton(reloadButton1);
    itemsGrid.setSaveButton(saveButton1);
    itemsGrid.setValueObjectClassName("org.jallinone.purchases.items.java.SupplierItemVO");
    insertButton1.setText("insertButton1");
    editButton1.setText("editButton1");
    saveButton1.setText("saveButton1");
    reloadButton1.setText("reloadButton1");
    deleteButton1.setText("deleteButton1");
    itemHierarsPanel.setLayout(gridBagLayout3);
    labelHierar.setText("item hierarchies");
    colItemCode.setColumnFilterable(true);
    colItemCode.setColumnName("itemCodeItm01PUR02");
    colItemCode.setColumnSortable(true);
    colItemCode.setEditableOnInsert(true);
    colItemCode.setHeaderColumnName("itemCodeITM01");
    colItemCode.setPreferredWidth(90);
    colItemCode.setSortVersus(org.openswing.swing.util.java.Consts.ASC_SORTED);
    colItemCode.setMaxCharacters(20);
    colItemDescr.setColumnFilterable(true);
    colItemDescr.setColumnName("descriptionSYS10");
    colItemDescr.setColumnSortable(true);
    colItemDescr.setHeaderColumnName("itemDescriptionSYS10");
    colItemDescr.setPreferredWidth(200);
    colSupplierItemCode.setMaxCharacters(20);
    colSupplierItemCode.setTrimText(true);
    colSupplierItemCode.setUpperCase(true);
    colSupplierItemCode.setColumnFilterable(true);
    colSupplierItemCode.setColumnName("supplierItemCodePUR02");
    colSupplierItemCode.setColumnSortable(true);
    colSupplierItemCode.setEditableOnEdit(true);
    colSupplierItemCode.setEditableOnInsert(true);
    colSupplierItemCode.setHeaderColumnName("supplierItemCodePUR02");
    colSupplierItemCode.setPreferredWidth(120);
    colUmCode.setColumnDuplicable(true);
    colUmCode.setColumnFilterable(true);
    colUmCode.setColumnName("umCodeReg02PUR02");
    colUmCode.setEditableOnEdit(true);
    colUmCode.setEditableOnInsert(true);
    colUmCode.setHeaderColumnName("umCodeReg02PUR02");
    colUmCode.setMaxCharacters(20);
    colMinQty.setDecimals(2);
    colMinQty.setGrouping(false);
    colMinQty.setColumnDuplicable(true);
    colMinQty.setColumnFilterable(true);
    colMinQty.setColumnSortable(true);
    colMinQty.setEditableOnEdit(true);
    colMinQty.setEditableOnInsert(true);
    colMinQty.setPreferredWidth(80);
    colMinQty.setColumnName("minPurchaseQtyPUR02");
    colMultipleQty.setGrouping(false);
    colMultipleQty.setColumnDuplicable(true);
    colMultipleQty.setColumnFilterable(true);
    colMultipleQty.setColumnSortable(true);
    colMultipleQty.setEditableOnEdit(true);
    colMultipleQty.setEditableOnInsert(true);
    colMultipleQty.setPreferredWidth(80);
    colMultipleQty.setColumnName("multipleQtyPUR02");
    subjectPanel.add(
        organizationPanel,
        new GridBagConstraints(
            0,
            1,
            1,
            1,
            1.0,
            1.0,
            GridBagConstraints.NORTHWEST,
            GridBagConstraints.BOTH,
            new Insets(0, 0, 0, 0),
            0,
            0));
    this.setTitle(ClientSettings.getInstance().getResources().getResource("supplier detail"));
    buttonsPanel.setLayout(flowLayout1);
    flowLayout1.setAlignment(FlowLayout.LEFT);
    insertButton.setText("insertButton1");
    editButton.setText("editButton1");
    saveButton.setEnabled(false);
    saveButton.setText("saveButton1");
    reloadButton.setText("reloadButton1");
    deleteButton.setText("deleteButton1");

    labelCompanyCode.setText("companyCodeSys01REG04");
    controlCompanyCode.setAttributeName("companyCodeSys01REG04");
    controlCompanyCode.setLinkLabel(labelCompanyCode);
    controlCompanyCode.setRequired(true);
    controlCompanyCode.setEnabledOnEdit(false);

    this.getContentPane().add(buttonsPanel, BorderLayout.NORTH);
    buttonsPanel.add(insertButton, null);
    buttonsPanel.add(editButton, null);
    buttonsPanel.add(saveButton, null);
    buttonsPanel.add(reloadButton, null);
    buttonsPanel.add(deleteButton, null);
    buttonsPanel.add(navigatorBar, null);
    //    tabbedPane.add(subjectPanel,   "generic data");
    this.getContentPane().add(tabbedPane, BorderLayout.CENTER);
    supplierPanel.add(
        labelCompanyCode,
        new GridBagConstraints(
            0,
            0,
            1,
            1,
            0.0,
            0.0,
            GridBagConstraints.WEST,
            GridBagConstraints.NONE,
            new Insets(5, 5, 5, 5),
            0,
            0));
    supplierPanel.add(
        controlCompanyCode,
        new GridBagConstraints(
            1,
            0,
            1,
            1,
            0.0,
            0.0,
            GridBagConstraints.WEST,
            GridBagConstraints.HORIZONTAL,
            new Insets(5, 5, 5, 5),
            0,
            0));

    //    tabbedPane.add(supplierPanel,    "supplierPanel");
    supplierPanel.add(
        labelSupplierCode,
        new GridBagConstraints(
            0,
            1,
            1,
            1,
            0.0,
            0.0,
            GridBagConstraints.WEST,
            GridBagConstraints.NONE,
            new Insets(0, 5, 5, 5),
            0,
            0));
    supplierPanel.add(
        controlSupplierCode,
        new GridBagConstraints(
            1,
            1,
            1,
            1,
            0.0,
            0.0,
            GridBagConstraints.WEST,
            GridBagConstraints.HORIZONTAL,
            new Insets(5, 5, 5, 5),
            0,
            0));
    supplierPanel.add(
        labelPay,
        new GridBagConstraints(
            0,
            2,
            1,
            1,
            0.0,
            0.0,
            GridBagConstraints.WEST,
            GridBagConstraints.NONE,
            new Insets(5, 5, 5, 5),
            0,
            0));
    supplierPanel.add(
        controlPayment,
        new GridBagConstraints(
            1,
            2,
            1,
            1,
            0.0,
            0.0,
            GridBagConstraints.WEST,
            GridBagConstraints.HORIZONTAL,
            new Insets(5, 5, 5, 5),
            40,
            0));
    supplierPanel.add(
        controlPayDescr,
        new GridBagConstraints(
            2,
            2,
            2,
            1,
            1.0,
            0.0,
            GridBagConstraints.WEST,
            GridBagConstraints.HORIZONTAL,
            new Insets(5, 5, 5, 5),
            0,
            0));
    supplierPanel.add(
        labelPricelist,
        new GridBagConstraints(
            0,
            3,
            1,
            1,
            0.0,
            0.0,
            GridBagConstraints.WEST,
            GridBagConstraints.NONE,
            new Insets(5, 5, 5, 5),
            0,
            0));
    supplierPanel.add(
        labelBank,
        new GridBagConstraints(
            0,
            4,
            1,
            1,
            0.0,
            0.0,
            GridBagConstraints.WEST,
            GridBagConstraints.NONE,
            new Insets(5, 5, 0, 5),
            0,
            0));
    supplierPanel.add(
        controlBank,
        new GridBagConstraints(
            1,
            4,
            1,
            1,
            0.0,
            0.0,
            GridBagConstraints.WEST,
            GridBagConstraints.HORIZONTAL,
            new Insets(5, 5, 5, 5),
            40,
            0));
    supplierPanel.add(
        controlBankDescr,
        new GridBagConstraints(
            2,
            4,
            2,
            3,
            1.0,
            1.0,
            GridBagConstraints.NORTHWEST,
            GridBagConstraints.HORIZONTAL,
            new Insets(5, 5, 0, 5),
            0,
            0));

    supplierPanel.add(
        labelDebit,
        new GridBagConstraints(
            0,
            5,
            1,
            1,
            0.0,
            0.0,
            GridBagConstraints.WEST,
            GridBagConstraints.HORIZONTAL,
            new Insets(5, 5, 5, 5),
            0,
            0));
    supplierPanel.add(
        labelPurchase,
        new GridBagConstraints(
            0,
            6,
            1,
            1,
            0.0,
            1.0,
            GridBagConstraints.WEST,
            GridBagConstraints.HORIZONTAL,
            new Insets(5, 5, 15, 5),
            0,
            0));
    supplierPanel.add(
        controlDebitsCode,
        new GridBagConstraints(
            1,
            5,
            1,
            1,
            0.0,
            0.0,
            GridBagConstraints.WEST,
            GridBagConstraints.HORIZONTAL,
            new Insets(5, 5, 5, 5),
            40,
            0));
    supplierPanel.add(
        controlDebitsDescr,
        new GridBagConstraints(
            2,
            5,
            2,
            1,
            0.0,
            0.0,
            GridBagConstraints.WEST,
            GridBagConstraints.HORIZONTAL,
            new Insets(5, 5, 0, 5),
            0,
            0));
    supplierPanel.add(
        controlCostsCode,
        new GridBagConstraints(
            1,
            6,
            1,
            1,
            0.0,
            0.0,
            GridBagConstraints.WEST,
            GridBagConstraints.NONE,
            new Insets(5, 5, 5, 5),
            40,
            0));
    supplierPanel.add(
        controlCostsDescr,
        new GridBagConstraints(
            2,
            6,
            2,
            3,
            1.0,
            1.0,
            GridBagConstraints.NORTHWEST,
            GridBagConstraints.HORIZONTAL,
            new Insets(5, 5, 0, 5),
            0,
            0));

    labelDebit.setText("debits account");
    labelPurchase.setText("purchase costs account");
    controlDebitsCode.setAttributeName("debitAccountCodeAcc02PUR01");
    controlDebitsDescr.setAttributeName("debitAccountDescrPUR01");
    controlCostsCode.setAttributeName("costsAccountCodeAcc02PUR01");
    controlCostsDescr.setAttributeName("costsAccountDescrPUR01");

    detailPanel.add(
        subjectPanel,
        new GridBagConstraints(
            0,
            0,
            1,
            1,
            1.0,
            1.0,
            GridBagConstraints.WEST,
            GridBagConstraints.BOTH,
            new Insets(5, 5, 5, 5),
            0,
            0));
    detailPanel.add(
        supplierPanel,
        new GridBagConstraints(
            0,
            1,
            1,
            1,
            1.0,
            0.0,
            GridBagConstraints.WEST,
            GridBagConstraints.HORIZONTAL,
            new Insets(5, 5, 5, 5),
            0,
            0));
    tabbedPane.add(detailPanel, "supplier data");

    tabbedPane.add(refPanel, "references");
    refPanel.add(referencesPanel, BorderLayout.CENTER);
    tabbedPane.add(hierarPanel, "hierarchies");
    hierarPanel.add(hierarchiesPanel, BorderLayout.CENTER);
    tabbedPane.add(treeGridItemsPanel, "supplierItems");
    treeGridItemsPanel.add(itemsSplitPane, BorderLayout.CENTER);
    itemsSplitPane.add(treePanel, JSplitPane.LEFT);
    itemsSplitPane.add(itemsPanel, JSplitPane.RIGHT);
    itemsPanel.add(itemButtonsPanel, BorderLayout.NORTH);
    itemsPanel.add(itemsGrid, BorderLayout.CENTER);
    itemsGrid.getColumnContainer().add(colItemCode, null);
    itemButtonsPanel.add(insertButton1, null);
    itemButtonsPanel.add(editButton1, null);
    itemButtonsPanel.add(saveButton1, null);
    itemButtonsPanel.add(reloadButton1, null);
    itemButtonsPanel.add(deleteButton1, null);
    itemButtonsPanel.add(exportButton1, null);
    itemButtonsPanel.add(navigatorBar1, null);
    itemButtonsPanel.add(impAllItemsButton, null);

    controlDebitsCode.setLinkLabel(labelDebit);
    controlDebitsCode.setMaxCharacters(20);
    controlDebitsCode.setRequired(true);
    controlDebitsDescr.setEnabledOnInsert(false);
    controlDebitsDescr.setEnabledOnEdit(false);
    controlCostsCode.setLinkLabel(labelPurchase);
    controlCostsCode.setMaxCharacters(20);
    controlCostsCode.setRequired(true);
    controlCostsDescr.setEnabledOnInsert(false);
    controlCostsDescr.setEnabledOnEdit(false);

    treeGridItemsPanel.add(itemHierarsPanel, BorderLayout.NORTH);
    itemHierarsPanel.add(
        labelHierar,
        new GridBagConstraints(
            0,
            0,
            1,
            1,
            0.0,
            0.0,
            GridBagConstraints.WEST,
            GridBagConstraints.NONE,
            new Insets(5, 5, 5, 0),
            0,
            0));
    itemHierarsPanel.add(
        controlHierarchy,
        new GridBagConstraints(
            1,
            0,
            1,
            1,
            1.0,
            0.0,
            GridBagConstraints.WEST,
            GridBagConstraints.NONE,
            new Insets(5, 5, 5, 5),
            100,
            0));
    tabbedPane.add(supplierPricelistPanel, "supplierPricelistPanel");
    itemsGrid.getColumnContainer().add(colItemDescr, null);
    itemsGrid.getColumnContainer().add(colSupplierItemCode, null);
    itemsGrid.getColumnContainer().add(colUmCode, null);
    itemsGrid.getColumnContainer().add(colMinQty, null);
    itemsGrid.getColumnContainer().add(colMultipleQty, null);

    tabbedPane.setTitleAt(
        0, ClientSettings.getInstance().getResources().getResource("supplier data"));
    tabbedPane.setTitleAt(1, ClientSettings.getInstance().getResources().getResource("references"));
    tabbedPane.setTitleAt(
        2, ClientSettings.getInstance().getResources().getResource("hierarchies"));
    tabbedPane.setTitleAt(
        3, ClientSettings.getInstance().getResources().getResource("supplierItems"));
    tabbedPane.setTitleAt(
        4, ClientSettings.getInstance().getResources().getResource("supplierPricelists"));
    itemsSplitPane.setDividerLocation(200);
  }

  public Form getCurrentForm() {
    return supplierPanel;
  }

  public ReferencesPanel getReferencesPanel() {
    return referencesPanel;
  }

  public SubjectHierarchyLevelsPanel getHierarchiesPanel() {
    return hierarchiesPanel;
  }

  public final void setButtonsEnabled(boolean enabled) {
    referencesPanel.setButtonsEnabled(enabled);
    hierarchiesPanel.setButtonsEnabled(enabled);
    supplierPricelistPanel.setButtonsEnabled(enabled);

    insertButton1.setEnabled(enabled);
    editButton1.setEnabled(enabled);
    deleteButton1.setEnabled(enabled);
    exportButton1.setEnabled(enabled);

    treePanel.setEnabled(enabled);
  }

  public GridControl getItemsGrid() {
    return itemsGrid;
  }

  public HierarTreePanel getTreePanel() {
    return treePanel;
  }

  public LookupController getItemController() {
    return itemController;
  }

  public LookupServerDataLocator getItemDataLocator() {
    return itemDataLocator;
  }

  public SupplierPricelistPanel getSupplierPricelistPanel() {
    return supplierPricelistPanel;
  }

  /**
   * Method invoked when pressing import all items button: it add all items to the supplier items
   * collection.
   */
  void impAllItemsButton_actionPerformed(ActionEvent e) {
    DetailSupplierVO vo = (DetailSupplierVO) supplierPanel.getVOModel().getValueObject();
    SupplierItemVO itemVO = new SupplierItemVO();
    itemVO.setCompanyCodeSys01PUR02(vo.getCompanyCodeSys01REG04());
    itemVO.setProgressiveReg04PUR02(vo.getProgressiveREG04());
    itemVO.setProgressiveHie02PUR02((BigDecimal) controlHierarchy.getValue());
    Response res = ClientUtils.getData("importAllItemsToSupplier", itemVO);
    if (!res.isError()) itemsGrid.reloadData();
  }

  public CodLookupControl getControlDebitsCode() {
    return controlDebitsCode;
  }

  public CodLookupControl getControlCostsCode() {
    return controlCostsCode;
  }
}