/** Creates new form SwitchboardView */
  public SwitchboardView() {
    initComponents();

    btnSalesReport.addActionListener(this);
    btnBackOffice.addActionListener(this);
    btnClockOut.addActionListener(this);
    btnEditTicket.addActionListener(this);

    if (!"false".equals(AppConfig.getFeatureGroupTicketFlag())) {
      btnGroupSettle.addActionListener(this);
    }

    btnLogout.addActionListener(this);

    if (!"false".equals(AppConfig.getManagerMenuFlag())) {
      btnManager.addActionListener(this);
    }

    btnNewTicket.addActionListener(this);

    if (!"false".equals(AppConfig.getFeaturePenarikanFlag())) {
      btnPayout.addActionListener(this);
    }

    btnOrderInfo.addActionListener(this);
    btnReopenTicket.addActionListener(this);
    btnSettleTicket.addActionListener(this);
    btnShutdown.addActionListener(this);

    if (!"false".equals(AppConfig.getFeatureSplitTicketFlag())) {
      btnSplitTicket.addActionListener(this);
    }

    btnTakeout.addActionListener(this);
    btnVoidTicket.addActionListener(this);

    orderServiceExtension = Application.getPluginManager().getPlugin(OrderServiceExtension.class);

    if (orderServiceExtension == null) {
      //            btnHomeDelivery.setEnabled(false);
      //            btnPickup.setEnabled(false);
      //            btnDriveThrough.setEnabled(false);
      //            btnAssignDriver.setEnabled(false);
      //            btnCloseOrder.setEnabled(false);

      orderServiceExtension = new DefaultOrderServiceExtension();
    }
    //		ticketListUpdater = new Timer(30 * 1000, new TicketListUpdaterTask());

    applyComponentOrientation(ComponentOrientation.getOrientation(Locale.getDefault()));

    instance = this;
  }
  public void updateView() {
    User user = Application.getCurrentUser();
    UserType userType = user.getNewUserType();
    if (userType != null) {
      Set<UserPermission> permissions = userType.getPermissions();
      if (permissions != null) {
        btnNewTicket.setEnabled(false);
        btnBackOffice.setEnabled(false);
        btnEditTicket.setEnabled(false);

        if (!"false".equalsIgnoreCase(AppConfig.getFeatureGroupTicketFlag())) {
          btnGroupSettle.setEnabled(false);
        }

        if (!"false".equalsIgnoreCase(AppConfig.getManagerMenuFlag())) {
          btnManager.setEnabled(false);
        }

        if (!"false".equalsIgnoreCase(AppConfig.getFeaturePenarikanFlag())) {
          btnPayout.setEnabled(false);
        }

        btnReopenTicket.setEnabled(false);
        btnSettleTicket.setEnabled(false);

        if (!"false".equalsIgnoreCase(AppConfig.getFeatureSplitTicketFlag())) {
          btnSplitTicket.setEnabled(false);
        }

        btnTakeout.setEnabled(false);
        btnVoidTicket.setEnabled(false);

        for (UserPermission permission : permissions) {
          if (permission.equals(UserPermission.VOID_TICKET)) {
            btnVoidTicket.setEnabled(true);
          } else if (permission.equals(UserPermission.PAY_OUT)) {
            if (!"false".equalsIgnoreCase(AppConfig.getFeaturePenarikanFlag())) {
              btnPayout.setEnabled(true);
            }
          } else if (permission.equals(UserPermission.SETTLE_TICKET)) {
            btnSettleTicket.setEnabled(true);
            if (!"false".equalsIgnoreCase(AppConfig.getFeatureGroupTicketFlag())) {
              btnGroupSettle.setEnabled(true);
            }
          } else if (permission.equals(UserPermission.REOPEN_TICKET)) {
            btnReopenTicket.setEnabled(true);
          } else if (permission.equals(UserPermission.PERFORM_MANAGER_TASK)) {
            if (!"false".equalsIgnoreCase(AppConfig.getManagerMenuFlag())) {
              btnManager.setEnabled(true);
            }
          } else if (permission.equals(UserPermission.SPLIT_TICKET)) {
            if (!"false".equalsIgnoreCase(AppConfig.getFeatureSplitTicketFlag())) {
              btnSplitTicket.setEnabled(true);
            }
          } else if (permission.equals(UserPermission.TAKE_OUT)) {
            btnTakeout.setEnabled(true);
          } else if (permission.equals(UserPermission.VIEW_BACK_OFFICE)) {
            btnBackOffice.setEnabled(true);
          }
          //                    else if (permission.equals(UserPermission.PAY_OUT)) {
          //                        btnPayout.setEnabled(true);
          //                    }
          else if (permission.equals(UserPermission.EDIT_TICKET)) {
            btnEditTicket.setEnabled(true);
          } else if (permission.equals(UserPermission.CREATE_NEW_TICKET)) {
            btnNewTicket.setEnabled(true);
          }
        }
      }
    }

    updateTicketList();
  }
  // <editor-fold defaultstate="collapsed" desc=" Generated Code
  // <editor-fold defaultstate="collapsed"
  // desc=" Generated Code ">//GEN-BEGIN:initComponents
  private void initComponents() {

    javax.swing.JPanel statusPanel = new javax.swing.JPanel();
    lblUserName = new javax.swing.JLabel();
    javax.swing.JPanel bottomPanel = new javax.swing.JPanel();
    javax.swing.JPanel bottomLeftPanel = new javax.swing.JPanel();
    openTicketList = new com.floreantpos.ui.TicketListView();
    javax.swing.JPanel activityPanel = new javax.swing.JPanel();
    btnNewTicket = new com.floreantpos.swing.PosButton();
    btnEditTicket = new com.floreantpos.swing.PosButton();
    btnVoidTicket = new com.floreantpos.swing.PosButton();
    btnPayout = new com.floreantpos.swing.PosButton();
    btnOrderInfo = new com.floreantpos.swing.PosButton();
    javax.swing.JPanel bottomRightPanel = new javax.swing.JPanel();
    btnShutdown = new com.floreantpos.swing.PosButton();
    btnLogout = new com.floreantpos.swing.PosButton();
    btnBackOffice = new com.floreantpos.swing.PosButton();
    btnSalesReport = new com.floreantpos.swing.PosButton();
    btnManager = new com.floreantpos.swing.PosButton();
    btnClockOut = new com.floreantpos.swing.PosButton();

    setLayout(new java.awt.BorderLayout(10, 10));

    lblUserName.setFont(new java.awt.Font("Tahoma", 1, 18));
    lblUserName.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
    statusPanel.add(lblUserName, java.awt.BorderLayout.PAGE_START);

    add(statusPanel, java.awt.BorderLayout.NORTH);

    bottomPanel.setLayout(new java.awt.BorderLayout(5, 5));

    bottomLeftPanel.setBorder(
        javax.swing.BorderFactory.createTitledBorder(
            null,
            POSConstants.OPEN_TICKETS_AND_ACTIVITY,
            javax.swing.border.TitledBorder.CENTER,
            javax.swing.border.TitledBorder.DEFAULT_POSITION));
    bottomLeftPanel.setLayout(new java.awt.BorderLayout(5, 5));
    bottomLeftPanel.add(openTicketList, java.awt.BorderLayout.CENTER);

    activityPanel.setPreferredSize(new java.awt.Dimension(655, 150));
    activityPanel.setLayout(new java.awt.GridLayout(3, 0, 5, 5));

    btnNewTicket.setIcon(
        new javax.swing.ImageIcon(getClass().getResource("/images/new_ticket_32.png")));
    btnNewTicket.setText(POSConstants.DINE_IN);
    activityPanel.add(btnNewTicket);
    btnTakeout = new com.floreantpos.swing.PosButton();

    btnTakeout.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/take_away.png")));
    btnTakeout.setText(POSConstants.CAPITAL_TAKE_OUT);
    activityPanel.add(btnTakeout);

    //        btnPickup = new PosButton();
    //        btnPickup.addActionListener(new ActionListener() {
    //            public void actionPerformed(ActionEvent e) {
    //                doHomeDelivery(Ticket.PICKUP);
    //            }
    //        });
    //        btnPickup.setText(POSConstants.PICKUP);
    //        activityPanel.add(btnPickup);

    //        btnHomeDelivery = new PosButton();
    //        btnHomeDelivery.addActionListener(new ActionListener() {
    //            public void actionPerformed(ActionEvent e) {
    //                doHomeDelivery(Ticket.HOME_DELIVERY);
    //            }
    //        });
    //        btnHomeDelivery.setText(POSConstants.HOME_DELIVERY);
    //        activityPanel.add(btnHomeDelivery);

    /*
            btnDriveThrough = new PosButton();
            btnDriveThrough.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    doTakeout(Ticket.DRIVE_THROUGH);
                }
            });
            btnDriveThrough.setText(POSConstants.DRIVE_THRU);
            activityPanel.add(btnDriveThrough);
    */

    btnEditTicket.setIcon(
        new javax.swing.ImageIcon(getClass().getResource("/images/edit_ticket_32.png")));
    btnEditTicket.setText(POSConstants.CAPITAL_EDIT);
    activityPanel.add(btnEditTicket);
    btnSettleTicket = new com.floreantpos.swing.PosButton();

    btnSettleTicket.setIcon(
        new javax.swing.ImageIcon(getClass().getResource("/images/settle_ticket_32.png")));
    btnSettleTicket.setText(POSConstants.CAPITAL_SETTLE);
    activityPanel.add(btnSettleTicket);

    if (!"false".equals(AppConfig.getFeatureGroupTicketFlag())) {
      btnGroupSettle = new com.floreantpos.swing.PosButton();
      btnGroupSettle.setIcon(
          new javax.swing.ImageIcon(getClass().getResource("/images/settle_ticket_32.png")));
      btnGroupSettle.setText(
          "<html><body>"
              + POSConstants.CAPITAL_SETTLE
              + "<br>"
              + POSConstants.CAPITAL_GROUP
              + "</body></html>");
      activityPanel.add(btnGroupSettle);
    }

    if (!"false".equals(AppConfig.getFeatureSplitTicketFlag())) {
      btnSplitTicket = new com.floreantpos.swing.PosButton();
      btnSplitTicket.setIcon(
          new javax.swing.ImageIcon(getClass().getResource("/images/split_32.png")));
      btnSplitTicket.setText(POSConstants.CAPITAL_SPLIT);
      activityPanel.add(btnSplitTicket);
    }

    btnReopenTicket = new com.floreantpos.swing.PosButton();

    btnReopenTicket.setIcon(
        new javax.swing.ImageIcon(getClass().getResource("/images/edit_ticket_32.png")));
    btnReopenTicket.setText(POSConstants.CAPITAL_RE_OPEN);
    activityPanel.add(btnReopenTicket);

    btnVoidTicket.setIcon(
        new javax.swing.ImageIcon(getClass().getResource("/images/void_ticket_32.png")));
    btnVoidTicket.setText(POSConstants.CAPITAL_VOID);
    activityPanel.add(btnVoidTicket);

    if (!"false".equals(AppConfig.getFeaturePenarikanFlag())) {
      btnPayout.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/pay_32.png")));
      btnPayout.setText(POSConstants.CAPITAL_PAY_OUT);
      activityPanel.add(btnPayout);
    }

    btnOrderInfo.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/search.png")));
    btnOrderInfo.setText(POSConstants.ORDER_INFO);
    activityPanel.add(btnOrderInfo);

    bottomLeftPanel.add(activityPanel, java.awt.BorderLayout.SOUTH);

    //        btnAssignDriver = new PosButton();
    //        btnAssignDriver.addActionListener(new ActionListener() {
    //            public void actionPerformed(ActionEvent e) {
    //                doAssignDriver();
    //            }
    //        });
    //        btnAssignDriver.setText("<html>PILIH<br/>PENGANTAR</html>");
    //        activityPanel.add(btnAssignDriver);
    //
    //        btnCloseOrder = new PosButton();
    //        btnCloseOrder.addActionListener(new ActionListener() {
    //            public void actionPerformed(ActionEvent e) {
    //                doCloseOrder();
    //            }
    //        });
    //        btnCloseOrder.setText(POSConstants.CLOSE_ORDER);
    //        activityPanel.add(btnCloseOrder);

    bottomPanel.add(bottomLeftPanel, java.awt.BorderLayout.CENTER);

    bottomRightPanel.setBorder(
        javax.swing.BorderFactory.createTitledBorder(
            null,
            "LAIN-LAIN",
            javax.swing.border.TitledBorder.CENTER,
            javax.swing.border.TitledBorder.DEFAULT_POSITION));
    bottomRightPanel.setPreferredSize(new java.awt.Dimension(180, 10));

    btnShutdown.setIcon(
        new javax.swing.ImageIcon(getClass().getResource("/images/shut_down_32.png")));
    btnShutdown.setText(POSConstants.CAPITAL_SHUTDOWN);

    btnLogout.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/log_out_32.png")));
    btnLogout.setText(POSConstants.CAPITAL_LOGOUT);

    btnBackOffice.setIcon(
        new javax.swing.ImageIcon(getClass().getResource("/images/back_office.png")));
    btnBackOffice.setText(POSConstants.CAPITAL_BACK_OFFICE);

    btnSalesReport.setIcon(
        new javax.swing.ImageIcon(getClass().getResource("/images/salesreport.png")));
    btnSalesReport.setText(POSConstants.CAPITAL_SALES_REPORT);

    if (!"false".equalsIgnoreCase(AppConfig.getManagerMenuFlag())) {
      btnManager.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/user_32.png")));
      btnManager.setText(POSConstants.CAPITAL_MANAGER);
    }

    btnClockOut.setIcon(
        new javax.swing.ImageIcon(getClass().getResource("/images/log_out_32.png")));
    btnClockOut.setText(POSConstants.CAPITAL_CLOCK_OUT);

    bottomPanel.add(bottomRightPanel, java.awt.BorderLayout.EAST);
    bottomRightPanel.setLayout(
        new MigLayout("aligny bottom, insets 1 2 1 2, gapy 10", "[170px]", "[][][][][]"));
    bottomRightPanel.add(btnShutdown, "cell 0 5,grow");
    bottomRightPanel.add(btnLogout, "cell 0 4,grow");
    bottomRightPanel.add(btnSalesReport, "cell 0 3,grow");
    bottomRightPanel.add(btnClockOut, "cell 0 2,grow");
    bottomRightPanel.add(btnBackOffice, "cell 0 1,grow");

    if (!"false".equalsIgnoreCase(AppConfig.getManagerMenuFlag())) {
      bottomRightPanel.add(btnManager, "cell 0 0,grow");
    }

    add(bottomPanel, java.awt.BorderLayout.CENTER);
  } // </editor-fold>//GEN-END:initComponents