Package realcix20.guis.views

Source Code of realcix20.guis.views.AssignBudgetDialog

package realcix20.guis.views;

import java.awt.Color;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.sql.ResultSet;
import java.util.Calendar;
import java.util.Iterator;
import java.util.Vector;

import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JPopupMenu;
import javax.swing.JScrollPane;
import javax.swing.KeyStroke;
import javax.swing.ListSelectionModel;
import javax.swing.border.TitledBorder;
import javax.swing.table.DefaultTableModel;

import org.jdesktop.swingx.JXTable;
import org.jdesktop.swingx.decorator.AlternateRowHighlighter;
import org.jdesktop.swingx.decorator.Filter;
import org.jdesktop.swingx.decorator.FilterPipeline;
import org.jdesktop.swingx.decorator.HighlighterPipeline;
import org.jdesktop.swingx.decorator.PatternFilter;
import org.jdesktop.swingx.decorator.RolloverHighlighter;
import org.jdesktop.swingx.table.TableColumnExt;

import realcix20.classes.BudgetSettingClass;
import realcix20.classes.basic.BaseClass;
import realcix20.classes.basic.Cell;
import realcix20.classes.basic.ClassManager;
import realcix20.classes.basic.Column;
import realcix20.classes.basic.Row;
import realcix20.guis.utils.ImageManager;
import realcix20.guis.utils.MnemonicGenerator;
import realcix20.guis.utils.TxtManager;
import realcix20.utils.DAO;
import realcix20.utils.ObjectUtil;
import realcix20.utils.Resources;

public class AssignBudgetDialog extends JDialog implements ActionListener, MouseListener {
   
        private JDialog container;
        private BaseClass object;
        private Row selectedRow;
        private Row mainRow;
       
        private JPopupMenu popupMenu;
        private JXTable notAssignedTable;
        private JXTable assignedTable;
       
        private String stat;//1.Current Month;2.All
        private String currentLt;

        public AssignBudgetDialog(JDialog container, BaseClass object, Row selectedRow, Row mainRow) {
           
                super(container);
           
                this.container = container;
                this.object = object;
                this.selectedRow = selectedRow;
                this.mainRow = mainRow;
                this.stat = "Current Month";
                setCurrentLt();
               
                initMenuBar();
                initTablePopupMenu();
                initComponents();
                initTablesModel();
                filterNotAssignedTable();
               
                notAssignedTable.getColumnExt(4).setVisible(false);
           
        }
       
        private void initMenuBar() {
           
                JMenuBar menuBar = new JMenuBar();
                menuBar.setVisible(true);
               
                JMenu notVisibleMenu = new JMenu();
                notVisibleMenu.setVisible(false);
                menuBar.add(notVisibleMenu);
               
                JMenuItem menuItem = new JMenuItem();
                menuItem.setAccelerator(KeyStroke.getKeyStroke("ESCAPE"));
                menuItem.setActionCommand("Cancel");
                menuItem.addActionListener(this);
                menuItem.setVisible(false);
                notVisibleMenu.add(menuItem);
                              
                setJMenuBar(menuBar);
           
        }
       
        private void setCurrentLt() {
           
                DAO dao = DAO.getInstance();
                dao.query(Resources.SELECT_LT_FROM_LD);
                String ld = ObjectUtil.findNewCell(selectedRow, "RI", "LD").getColumnValue().toString();
                dao.setString(1, ld);
                ResultSet rs = dao.executeQuery();
                try {
                    if (rs.next()) {
                        currentLt = rs.getString("LT");
                    }
                    rs.close();
                } catch (Exception e) {
                    e.printStackTrace();
                }
           
        }

        private void initComponents() {                             

                addWindowListener(
                        new WindowAdapter() {
                   
                            public void windowClosing(WindowEvent e) {
                                AssignBudgetDialog thisWindow = (AssignBudgetDialog)e.getSource();
                                thisWindow.container.setEnabled(true);
                                thisWindow.dispose();
                            }
                   
                        }
                );
    Container contentPane = getContentPane();
    contentPane.setLayout(new GridBagLayout());
    ((GridBagLayout)contentPane.getLayout()).columnWidths = new int[] {0, 0};
    ((GridBagLayout)contentPane.getLayout()).rowHeights = new int[] {0, 0, 0, 0, 0, 0};
    ((GridBagLayout)contentPane.getLayout()).columnWeights = new double[] {1.0, 1.0E-4};
    ((GridBagLayout)contentPane.getLayout()).rowWeights = new double[] {0.0, 1.0, 0.0, 1.0, 0.0, 1.0E-4};
               
                JPanel tPanel = new JPanel();
                tPanel.setLayout(new FlowLayout(FlowLayout.RIGHT));
                JButton thisMonthOrAllButton = new JButton();
                thisMonthOrAllButton.setText(MnemonicGenerator.generateMnemonicString(TxtManager.getTxt("VIEW.OBJECTEDIT.REG.THISMONTHORALL"), KeyEvent.VK_T));
                thisMonthOrAllButton.setMnemonic(KeyEvent.VK_T);
                thisMonthOrAllButton.setIcon(ImageManager.getImage(ImageManager.CALENDAR_VIEW_MONTH_IMAGE));
                thisMonthOrAllButton.setActionCommand("Current Month / All");
                thisMonthOrAllButton.addActionListener(this);
                tPanel.add(thisMonthOrAllButton);              
    contentPane.add(tPanel, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0,
      GridBagConstraints.CENTER, GridBagConstraints.BOTH,
      new Insets(10, 10, 15, 10), 0, 0));
   
                JPanel panel = new JPanel();
    {                       
      panel.setBorder(new TitledBorder(TxtManager.getTxt("VIEW.OBJECTEDIT.REG.NOTASSIGNEDBUDGETS")));
      panel.setLayout(new GridBagLayout());
      ((GridBagLayout)panel.getLayout()).columnWidths = new int[] {0, 0};
      ((GridBagLayout)panel.getLayout()).rowHeights = new int[] {0, 0};
      ((GridBagLayout)panel.getLayout()).columnWeights = new double[] {1.0, 1.0E-4};
      ((GridBagLayout)panel.getLayout()).rowWeights = new double[] {1.0, 1.0E-4};
     
                        JScrollPane scrollPane = new JScrollPane();
      {
        scrollPane.setPreferredSize(new Dimension(500, 150));
       
        notAssignedTable = new JXTable();
                                notAssignedTable.setSortable(false);
                                notAssignedTable.setEditable(false);
                                notAssignedTable.setColumnControlVisible(false);
                                notAssignedTable.setHorizontalScrollEnabled(true);
                                HighlighterPipeline highlighters = new HighlighterPipeline();
                                highlighters.addHighlighter(new AlternateRowHighlighter());
                                highlighters.addHighlighter(new RolloverHighlighter(Color.BLACK, Color.WHITE));
                                notAssignedTable.setHighlighters(highlighters);
                                notAssignedTable.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);       
                                notAssignedTable.addMouseListener(this);
        scrollPane.setViewportView(notAssignedTable);
      }
      panel.add(scrollPane, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0,
        GridBagConstraints.CENTER, GridBagConstraints.BOTH,
        new Insets(0, 0, 0, 0), 0, 0));
    }
    contentPane.add(panel, new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0,
      GridBagConstraints.CENTER, GridBagConstraints.BOTH,
      new Insets(0, 0, 5, 0), 0, 0));

    panel = new JPanel();
    {
      panel.setLayout(new FlowLayout());
     
      JButton upButton = new JButton();
                        upButton.setIcon(ImageManager.getImage(ImageManager.ARROW_UP_IMAGE));
                        upButton.setActionCommand("UP");
                        upButton.addActionListener(this);
      panel.add(upButton);
     
      JButton downButton = new JButton();
                        downButton.setIcon(ImageManager.getImage(ImageManager.ARROW_DOWN_IMAGE));
                        downButton.setActionCommand("DOWN");
                        downButton.addActionListener(this);
      panel.add(downButton);
    }
    contentPane.add(panel, new GridBagConstraints(0, 2, 1, 1, 0.0, 0.0,
      GridBagConstraints.CENTER, GridBagConstraints.BOTH,
      new Insets(0, 0, 5, 0), 0, 0));

    panel = new JPanel();
    {
      panel.setBorder(new TitledBorder(TxtManager.getTxt("VIEW.OBJECTEDIT.REG.ASSIGNEDBUDGETS")));
      panel.setLayout(new GridBagLayout());
      ((GridBagLayout)panel.getLayout()).columnWidths = new int[] {0, 0};
      ((GridBagLayout)panel.getLayout()).rowHeights = new int[] {0, 0};
      ((GridBagLayout)panel.getLayout()).columnWeights = new double[] {1.0, 1.0E-4};
      ((GridBagLayout)panel.getLayout()).rowWeights = new double[] {1.0, 1.0E-4};
     
      JScrollPane scrollPane = new JScrollPane();
      {
        scrollPane.setPreferredSize(new Dimension(500, 150));
       
        assignedTable = new JXTable();
                                assignedTable.setSortable(false);
                                assignedTable.setEditable(false);
                                assignedTable.setColumnControlVisible(false);
                                assignedTable.setHorizontalScrollEnabled(true);
                                HighlighterPipeline highlighters = new HighlighterPipeline();
                                highlighters.addHighlighter(new AlternateRowHighlighter());
                                highlighters.addHighlighter(new RolloverHighlighter(Color.BLACK, Color.WHITE));
                                assignedTable.setHighlighters(highlighters);
                                assignedTable.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
                                assignedTable.setComponentPopupMenu(popupMenu)
                                assignedTable.addMouseListener(this);
        scrollPane.setViewportView(assignedTable);
      }
      panel.add(scrollPane, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0,
        GridBagConstraints.CENTER, GridBagConstraints.BOTH,
        new Insets(0, 0, 0, 0), 0, 0));
    }
    contentPane.add(panel, new GridBagConstraints(0, 3, 1, 1, 0.0, 0.0,
      GridBagConstraints.CENTER, GridBagConstraints.BOTH,
      new Insets(0, 0, 5, 0), 0, 0));

    panel = new JPanel();
    {
      panel.setLayout(new FlowLayout(FlowLayout.RIGHT));                             
                       
      JButton confirmButton = new JButton();
                        confirmButton.setText(MnemonicGenerator.generateMnemonicString(TxtManager.getTxt("VIEW.GLOBAL.CONFIRMBUTTON"), KeyEvent.VK_O));
                        confirmButton.setMnemonic(KeyEvent.VK_O);
                        confirmButton.setIcon(ImageManager.getImage(ImageManager.CONFIRM_IMAGE));
                        confirmButton.setActionCommand("Confirm");
                        confirmButton.addActionListener(this);
      confirmButton.setPreferredSize(new Dimension(75, 20));
      panel.add(confirmButton);
     
      JButton cancelButton = new JButton();
                        cancelButton.setText(MnemonicGenerator.generateMnemonicString(TxtManager.getTxt("VIEW.GLOBAL.CANCELBUTTON"), KeyEvent.VK_C));
                        cancelButton.setMnemonic(KeyEvent.VK_C);
                        cancelButton.setIcon(ImageManager.getImage(ImageManager.CANCEL_IMAGE));
                        cancelButton.setActionCommand("Cancel");
                        cancelButton.addActionListener(this);
      cancelButton.setPreferredSize(new Dimension(75, 20));
      panel.add(cancelButton);
    }
    contentPane.add(panel, new GridBagConstraints(0, 4, 1, 1, 0.0, 0.0,
      GridBagConstraints.CENTER, GridBagConstraints.BOTH,
      new Insets(0, 0, 0, 0), 0, 0));
                   
                pack();
                setTitle(TxtManager.getTxt("VIEW.OBJECTEDIT.REG.ASSIGNTOBUDGET"));
                setVisible(true);
                setLocationRelativeTo(null);
                setResizable(false);
               
  }                        
       
        private void initTablesModel() {
           
                initTablesStructure();
               
                if (!isSelectedRowAssigned()) {
                    initTablesData();
                } else {                   
                    Iterator regsIter = ((ObjectEdit)container).getRegs().iterator();
                    while (regsIter.hasNext()) {
                        Vector regDatas = (Vector)regsIter.next();
                        Row row = (Row)regDatas.get(0);
                        if (row == selectedRow) {
                            Vector notAssignedDataVector = (Vector)regDatas.get(1);
                            Vector assignedDataVector = (Vector)regDatas.get(2);
                            initTablesData(notAssignedDataVector, assignedDataVector);
                            break;
                        }
                    }                   
                }
           
        }
       
        private void initTablesStructure() {
           
                DefaultTableModel model = new DefaultTableModel();
                Vector columnNames = new Vector();
                BudgetSettingClass budgetSettingObject = (BudgetSettingClass)ClassManager.createClass(539);
                Iterator columnsIter = budgetSettingObject.getColumns().iterator();
                int n = 0;
                while (columnsIter.hasNext()) {
                    Column column = (Column)columnsIter.next();
                    columnNames.add(column.toString());
                    if (n == 3)
                    columnNames.add(TxtManager.getTxt("VIEW.OBJECTEDIT.REG.ASSIGNEDAMOUNT"));
                    n++;
                }
                columnNames.add("");
                model.setDataVector(new Vector(), columnNames);               
                DefaultTableModel cloneModel = new DefaultTableModel();
                cloneModel.setDataVector(new Vector(), columnNames);
           
                notAssignedTable.setModel(model);
                assignedTable.setModel(cloneModel);
               
                notAssignedTable.getColumn(0).setPreferredWidth(100);
                notAssignedTable.getColumn(1).setPreferredWidth(100);
                notAssignedTable.getColumn(2).setPreferredWidth(50);
                notAssignedTable.getColumn(3).setPreferredWidth(75);               
                notAssignedTable.getColumn(4).setPreferredWidth(75);
                //notAssignedTable.getColumnExt(4).setVisible(false);
                notAssignedTable.getColumn(5).setPreferredWidth(50);
                notAssignedTable.getColumnExt(6).setVisible(false);
               
                assignedTable.getColumn(0).setPreferredWidth(100);
                assignedTable.getColumn(1).setPreferredWidth(100);
                assignedTable.getColumn(2).setPreferredWidth(50);
                assignedTable.getColumn(3).setPreferredWidth(75);
                assignedTable.getColumn(4).setPreferredWidth(75);
                assignedTable.getColumn(5).setPreferredWidth(50);
                assignedTable.getColumnExt(6).setVisible(false);
        }               
       
        private void initTablesData() {
           
                DefaultTableModel aModel = (DefaultTableModel)assignedTable.getModel();
                DefaultTableModel naModel = (DefaultTableModel)notAssignedTable.getModel();                           
               
                Cell cell = ObjectUtil.findNewCell(selectedRow, "RI", "LAMT");
                double r_lamt = 0.0;
                if (cell.getColumnValue() instanceof Number)
                    r_lamt = ((Number)cell.getColumnValue()).doubleValue();
                else
                    r_lamt = Double.parseDouble((String)cell.getColumnValue());
               
                DAO dao = DAO.getInstance();
                dao.query(Resources.SELECT_ALL_B_SQL);
                ResultSet rs = dao.executeQuery();
                try {
                    while (rs.next()) {
                        Vector rowData = new Vector();
                        String b = rs.getString("B");
                        String ruser = rs.getString("RUSER");
                        String rmonth = rs.getString("RMONTH");
                        double lamt = rs.getDouble("LAMT");
                        String lc = rs.getString("LC");
                        BudgetObject budget = new BudgetObject(b, ruser, rmonth, lamt, lc);
                        rowData.add(b);
                        rowData.add(ruser);
                        rowData.add(rmonth);
                        rowData.add(lamt);
                        rowData.add(r_lamt);
                        rowData.add(lc);
                        rowData.add(budget);
                        if (isBudgetAssigned(budget)) {
                           
                            setOldLamt(rowData);
                           
                            aModel.addRow(rowData);
                            budget.assigned = true;
                        } else {
                            naModel.addRow(rowData);
                            budget.assigned = false;
                        }
                    }
                    rs.close();
                } catch (Exception e) {
                    e.printStackTrace();
                }               
           
        }
       
        private void initTablesData(Vector notAssignedDataVector, Vector assignedDataVector) {
           
                DefaultTableModel aModel = (DefaultTableModel)assignedTable.getModel();
                DefaultTableModel naModel = (DefaultTableModel)notAssignedTable.getModel();
               
                Iterator nadIter = notAssignedDataVector.iterator();
                while (nadIter.hasNext()) {
                    Vector rowData = (Vector)nadIter.next();
                    naModel.addRow(rowData);
                }
               
                Iterator adIter = assignedDataVector.iterator();
                while (adIter.hasNext()) {
                    Vector rowData = (Vector)adIter.next();                  
                    aModel.addRow(rowData);
                }
           
        }
       
        private void initTablePopupMenu() {
           
                popupMenu = new JPopupMenu();
               
                JMenuItem modifyRegLamtItem = new JMenuItem();
                modifyRegLamtItem.setText(MnemonicGenerator.generateMnemonicString(TxtManager.getTxt("VIEW.OBJECTEDIT.REG.MODIFYASSIGNAMOUNT"), KeyEvent.VK_M));
                modifyRegLamtItem.setIcon(ImageManager.getImage(ImageManager.MODIFY_LAMT_IMAGE));
                modifyRegLamtItem.setMnemonic(KeyEvent.VK_M);
                modifyRegLamtItem.setActionCommand("Modify Reg Lamt");
                modifyRegLamtItem.addActionListener(this);
                popupMenu.add(modifyRegLamtItem);
               
                JMenuItem averageRegItem = new JMenuItem();
                averageRegItem.setText(MnemonicGenerator.generateMnemonicString(TxtManager.getTxt("VIEW.OBJECTEDIT.REG.AVERAGEREG"), KeyEvent.VK_A));
                averageRegItem.setMnemonic(KeyEvent.VK_A);
                averageRegItem.setIcon(ImageManager.getImage(ImageManager.AVERAGE_IMAGE));
                averageRegItem.setActionCommand("Average");
                averageRegItem.addActionListener(this);
                popupMenu.add(averageRegItem);                               
           
        }               

        private boolean isBudgetAssigned(BudgetObject budget) {
           
                boolean result = false;
           
                Cell cell = ObjectUtil.findNewCell(selectedRow, "RI", "R");
                Integer r = 0;
                if (cell.getColumnValue() instanceof Number)
                    r = ((Number)cell.getColumnValue()).intValue();
                else
                    r = Integer.parseInt((String)cell.getColumnValue());
               
                cell = ObjectUtil.findNewCell(selectedRow, "RI", "RI");
                Integer ri = 0;
                if (cell.getColumnValue() instanceof Number)
                    ri = ((Number)cell.getColumnValue()).intValue();
                else
                    ri = Integer.parseInt((String)cell.getColumnValue());
               
                DAO dao = DAO.getInstance();
                dao.query(Resources.SELECT_BI_BY_ALLPK_SQL);
                dao.setObject(1, r);
                dao.setObject(2, ri);
                dao.setObject(3, budget.b);
                dao.setObject(4, budget.ruser);
                dao.setObject(5, budget.rmonth);
                ResultSet rs = dao.executeQuery();
                try {
                    if (rs.next())
                        result = true;
                    else
                        result = false;
                    rs.close();
                } catch (Exception e) {
                    e.printStackTrace();
                }
               
                return result;
           
        }
       
        public void mousePressed(MouseEvent e) {                                      
           
                if ( (e.getSource() instanceof JXTable) && (e.getButton() == e.BUTTON3) ) {      
                    JXTable table = (JXTable)e.getSource();
                    if ( (table.getRowCount() > 0) && (table.rowAtPoint(e.getPoint()) != -1) ) {
                        if (table.getSelectedRows().length > 0)
                            table.removeRowSelectionInterval(0, table.getRowCount() - 1);
                        table.addRowSelectionInterval(table.rowAtPoint(e.getPoint()), table.rowAtPoint(e.getPoint()));
                    }                   
                }

        }

        public void mouseClicked(MouseEvent e) {           
        }
       
        public void mouseReleased(MouseEvent e) {
        }

        public void mouseEntered(MouseEvent e) {
        }

        public void mouseExited(MouseEvent e) {
        }
       
        public void actionPerformed(ActionEvent e) {
           
                if (e.getActionCommand().equals("Cancel")) {
                    container.setEnabled(true);
                    dispose();
                } else if (e.getActionCommand().equals("Confirm")) {
                    confirm();
                    container.setEnabled(true);
                    dispose();
                } else if (e.getActionCommand().equals("UP")) {
                    upAndDown("UP");
                } else if (e.getActionCommand().equals("DOWN")) {
                    upAndDown("DOWN");
                } else if (e.getActionCommand().equals("Modify Reg Lamt")) {
                    showModifyRegLamtDialog();
                } else if (e.getActionCommand().equals("Average")) {
                    averageRegLamt();
                } else if (e.getActionCommand().equals("Current Month / All")) {
                    if (stat.equals("Current Month"))
                        stat = "All";
                    else if (stat.equals("All"))
                        stat = "Current Month";
                    filterNotAssignedTable();
                }          
           
        }     
       
        private void filterNotAssignedTable() {
           
                if (stat.equals("Current Month")) {
                
                    java.util.Date now = new java.util.Date(System.currentTimeMillis());
                    Calendar cal = Calendar.getInstance();
                    cal.setTime(now);
                    int year = cal.get(Calendar.YEAR);
                    int month = cal.get(Calendar.MONTH) + 1;
                    StringBuffer sb = new StringBuffer(year);
                    if (month < 10)
                        sb.append("0" + month);
                    else
                        sb.append(month);
                    String currentMonth = sb.toString();
                    int columnIndex = -1;
                    for (int i = 0; i < notAssignedTable.getColumnCount(false); i++) {
                        TableColumnExt tce = notAssignedTable.getColumnExt(i);
                        String brmonthTitle = ObjectUtil.findColumnTxt(539, "B", "RMONTH");
                        if (brmonthTitle.equals(tce.getTitle())) {
                            columnIndex = i;
                            break;
                        }
                    }
                    if (columnIndex != -1) {
                        Filter[] filterArray = { new PatternFilter(currentMonth, 0, columnIndex) };
                        FilterPipeline filters = new FilterPipeline(filterArray);
                        notAssignedTable.setFilters(filters);                       
                    }
                   
                } else {
                    Filter[] filterArray = { new PatternFilter(".*", 0, 0) };
                    FilterPipeline filters = new FilterPipeline(filterArray);
                    notAssignedTable.setFilters(filters);
                }                         
           
        }
       
        private boolean isSelectedRowAssigned() {
           
                boolean result = false;
               
                Iterator regsIter = ((ObjectEdit)container).getRegs().iterator();               
                while (regsIter.hasNext()) {
                    Vector regDatas = (Vector)regsIter.next();
                    Row row = (Row)regDatas.get(0);
                    if (row == selectedRow) {
                        result = true;
                        break;
                    }
                }
               
                return result;
           
        }
       
        private void upAndDown(String action) {
           
                JXTable sourceTable = null;
                JXTable ordinaryTable = null;
                if (action.equals("UP")) {
                    sourceTable = assignedTable;
                    ordinaryTable = notAssignedTable;                   
                } else if (action.equals("DOWN")) {
                    sourceTable = notAssignedTable;
                    ordinaryTable = assignedTable;
                }
               
                //Will be modified, add sorter function
                int[] selectedRows = sourceTable.getSelectedRows();
                if (selectedRows.length > 0) {
                    DefaultTableModel sModel = (DefaultTableModel)sourceTable.getModel();
                    DefaultTableModel oModel = (DefaultTableModel)ordinaryTable.getModel();                   
                   
                    for (int i = 0; i < selectedRows.length; i++) {      
                        int row = sourceTable.getFilters().convertRowIndexToModel(selectedRows[i] - i);
                        Vector datas = (Vector)sModel.getDataVector().elementAt(row);
                        //Vector datas = (Vector)sModel.getDataVector().elementAt(selectedRows[i] - i);
                        Double r_lamt = (Double)datas.get(4);
                        if ( (currentLt.equals("X")) || (currentLt.equals("V")) || (currentLt.equals("XVC")) ) {
                            datas.set(4, 0 - r_lamt);
                        }
                        oModel.addRow(datas);
                        BudgetObject budget =(BudgetObject)sModel.getValueAt(row, 6);
                        budget.assigned = !budget.assigned;   
                       
                        sModel.removeRow(row);
                        //sModel.removeRow(selectedRows[i] - i);
                    }
                   
                }
           
        }
       
        private void showModifyRegLamtDialog() {
           
                int selectedRow = assignedTable.getSelectedRow();
                DefaultTableModel aModel = (DefaultTableModel)assignedTable.getModel();
                if (selectedRow != -1) {
                    Number lamt = ((Number)aModel.getValueAt(selectedRow, 4));
                   
                    String s = (String)JOptionPane.showInputDialog(
                                                    this,
                                                    TxtManager.getTxt("VIEW.OBJECTEDIT.REG.ASSIGNAMOUNT"),
                                                    TxtManager.getTxt("VIEW.OBJECTEDIT.REG.MODIFYASSIGNAMOUNT"),                                                   
                                                    JOptionPane.PLAIN_MESSAGE,
                                                    ImageManager.getImage(ImageManager.MODIFY_LAMT_IMAGE),
                                                    null,
                                                    lamt);
                    double newLamt = 0.0;
                    try {
                        newLamt = Double.parseDouble(s);                       
                    } catch (Exception e) {
                        newLamt = lamt.doubleValue();
                    }
                   
                    aModel.setValueAt(newLamt, selectedRow, 4);
                   
                }                           
           
        }
       
        private void averageRegLamt() {
           
                Cell cell = ObjectUtil.findNewCell(selectedRow, "RI", "LAMT");
                double r_lamt = 0.0;
                if (cell.getColumnValue() instanceof Number)
                    r_lamt = ((Number)cell.getColumnValue()).doubleValue();
                else
                    r_lamt = Double.parseDouble((String)cell.getColumnValue());
               
                if ( (currentLt.equals("X")) || (currentLt.equals("V")) || (currentLt.equals("XVC")) ) {
                    r_lamt = 0 - r_lamt;
                }
               
                DefaultTableModel aModel = (DefaultTableModel)assignedTable.getModel();
                double new_lamt = r_lamt / aModel.getRowCount();
                for (int i = 0; i < aModel.getRowCount(); i++) {
                    ((Vector)(aModel.getDataVector().get(i))).set(4, new_lamt);
                }
                aModel.fireTableDataChanged();
               
        }
       
        private void confirm() {
           
                DefaultTableModel aModel = (DefaultTableModel)assignedTable.getModel();
                DefaultTableModel naModel = (DefaultTableModel)notAssignedTable.getModel();
           
                boolean isNewRow = true;
                Iterator regsIter = ((ObjectEdit)container).getRegs().iterator();
                while (regsIter.hasNext()) {
                    Vector regDatas = (Vector)regsIter.next();
                    Row row = (Row)regDatas.get(0);
                    if (row == selectedRow) {
                        isNewRow = false;
                        regDatas.set(1, naModel.getDataVector());
                        regDatas.set(2, aModel.getDataVector());
                        break;
                    }
                }
               
                if (isNewRow) {
                    Vector regDatas = new Vector();
                    regDatas.add(selectedRow);
                    regDatas.add(naModel.getDataVector());
                    regDatas.add(aModel.getDataVector());
                    ((ObjectEdit)container).getRegs().add(regDatas);
                }
           
        }
       
        private void setOldLamt(Vector rowData) {
                           
                int r = 0;
                Cell cell = ObjectUtil.findNewCell(selectedRow, "RI", "R");
                if (cell.getColumnValue() instanceof Number)
                    r = ((Number)cell.getColumnValue()).intValue();
                else
                    r = Integer.parseInt((String)cell.getColumnValue());
               
                int ri = 0;
                cell = ObjectUtil.findNewCell(selectedRow, "RI", "RI");
                if (cell.getColumnValue() instanceof Number)
                    ri = ((Number)cell.getColumnValue()).intValue();
                else
                    ri = Integer.parseInt((String)cell.getColumnValue());
               
                DAO dao = DAO.getInstance();
                dao.query(Resources.SELECT_BI_BY_ALLPK_SQL);
                dao.setObject(1, r);
                dao.setObject(2, ri);
                dao.setObject(3, rowData.get(0));
                dao.setObject(4, rowData.get(1));
                dao.setObject(5, rowData.get(2));
                ResultSet rs = dao.executeQuery();
                try {
                    if (rs.next())
                        rowData.set(4, rs.getDouble("LAMT"));
                    rs.close();
                } catch (Exception e) {
                    e.printStackTrace();
                }
           
        }
       
        class BudgetObject {
           
                public String b;
                public String ruser;
                public String rmonth;
                public double lamt;
                public String lc;
                public boolean assigned;
           
                public BudgetObject(String b, String ruser, String rmonth, double lamt, String lc) {
                   
                        this.b = b;
                        this.ruser = ruser;
                        this.rmonth = rmonth;
                        this.lamt = lamt;
                        this.lc = lc;
                        this.assigned = false;
                }
               
                public boolean equals(Object obj) {
                   
                        boolean result = false;
                   
                        if (obj instanceof BudgetObject) {
                            BudgetObject other = (BudgetObject)obj;
                            if ( (other.b == b&& (other.ruser == ruser) && (other.rmonth == rmonth) ) {
                                result = true;
                            } else {
                                result = false;
                            }
                        } else {
                            result = false;
                        }
                       
                        return result;
                       
                }
           
        }
   
}
TOP

Related Classes of realcix20.guis.views.AssignBudgetDialog

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.