package realcix20.guis.views;
import java.awt.Color;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.FlowLayout;
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.text.DecimalFormat;
import java.util.Iterator;
import java.util.Vector;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JLabel;
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.table.DefaultTableModel;
import org.jdesktop.swingx.JXTable;
import org.jdesktop.swingx.decorator.AlternateRowHighlighter;
import org.jdesktop.swingx.decorator.Highlighter;
import org.jdesktop.swingx.decorator.HighlighterPipeline;
import org.jdesktop.swingx.decorator.RolloverHighlighter;
import realcix20.classes.FamilyClass;
import realcix20.classes.RegClass;
import realcix20.classes.TaxClass;
import realcix20.classes.XRClass;
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.classes.plugins.CurrencyPlugin;
import realcix20.guis.utils.DialogManager;
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;
import com.jgoodies.forms.factories.FormFactory;
import com.jgoodies.forms.layout.CellConstraints;
import com.jgoodies.forms.layout.ColumnSpec;
import com.jgoodies.forms.layout.FormLayout;
import com.jgoodies.forms.layout.RowSpec;
public class TaxRegsDialog extends JDialog implements ActionListener,
MouseListener {
private ObjectEdit container;
private BaseClass object;
private Row selectedRow;
private String stat;
private double baseAMT1;
private double baseAMT2;
private double taxAMT;
private int n;
private JXTable sourceTable;
private JXTable addedTaxRegsTable;
private JXTable subedTaxRegsTable;
private JPopupMenu sourceTableMenu;
private JPopupMenu addedTaxRegsTableMenu;
private JPopupMenu subedTaxRegsTableMenu;
private JButton taxRegsStatButton;
private JLabel baseAMTLabel;
public TaxRegsDialog(ObjectEdit container, BaseClass object, Row selectedRow) {
super(container);
this.container = container;
this.object = object;
this.selectedRow = selectedRow;
stat = "Display no taxed regs";// "Display no taxed regs"
initMenuBar();
initSourceTablePopupMenu();
initAddedTaxRegsTablePopupMenu();
initSubedTaxRegsTablePopupMenu();
initComponents();
initTablesModel();
n = 0;
calculatorBaseAMT();
n++;
}
private void initSourceTablePopupMenu() {
sourceTableMenu = new JPopupMenu();
JMenuItem addToPositiveMenuItem = new JMenuItem();
addToPositiveMenuItem.setText(MnemonicGenerator.generateMnemonicString(
TxtManager.getTxt("VIEW.OBJECTEDIT.TAX.TAX"), KeyEvent.VK_T));
addToPositiveMenuItem.setMnemonic(KeyEvent.VK_T);
addToPositiveMenuItem.setIcon(ImageManager
.getImage(ImageManager.ADD_IMAGE));
addToPositiveMenuItem.setActionCommand("Add To Positive");
addToPositiveMenuItem.addActionListener(this);
sourceTableMenu.add(addToPositiveMenuItem);
JMenuItem addToNegativeMenuItem = new JMenuItem();
addToNegativeMenuItem.setText(MnemonicGenerator.generateMnemonicString(
TxtManager.getTxt("VIEW.OBJECTEDIT.TAX.TAXEXEMPTION"),
KeyEvent.VK_E));
addToNegativeMenuItem.setMnemonic(KeyEvent.VK_E);
addToNegativeMenuItem.setIcon(ImageManager
.getImage(ImageManager.SUB_IMAGE));
addToNegativeMenuItem.setActionCommand("Add To Negative");
addToNegativeMenuItem.addActionListener(this);
sourceTableMenu.add(addToNegativeMenuItem);
}
private void initAddedTaxRegsTablePopupMenu() {
addedTaxRegsTableMenu = new JPopupMenu();
JMenuItem deleteFromPositiveMenuItem = new JMenuItem();
deleteFromPositiveMenuItem
.setText(MnemonicGenerator
.generateMnemonicString(TxtManager
.getTxt("VIEW.OBJECTEDIT.TAX.DELETETAX"),
KeyEvent.VK_D));
deleteFromPositiveMenuItem.setMnemonic(KeyEvent.VK_D);
deleteFromPositiveMenuItem.setIcon(ImageManager
.getImage(ImageManager.CANCEL_IMAGE));
deleteFromPositiveMenuItem.setActionCommand("Delete From Positive");
deleteFromPositiveMenuItem.addActionListener(this);
addedTaxRegsTableMenu.add(deleteFromPositiveMenuItem);
}
private void initSubedTaxRegsTablePopupMenu() {
subedTaxRegsTableMenu = new JPopupMenu();
JMenuItem deleteFromNegativeMenuItem = new JMenuItem();
deleteFromNegativeMenuItem.setText(MnemonicGenerator
.generateMnemonicString(TxtManager
.getTxt("VIEW.OBJECTEDIT.TAX.DELETETAXEXEMPTION"),
KeyEvent.VK_D));
deleteFromNegativeMenuItem.setMnemonic(KeyEvent.VK_D);
deleteFromNegativeMenuItem.setIcon(ImageManager
.getImage(ImageManager.CANCEL_IMAGE));
deleteFromNegativeMenuItem.setActionCommand("Delete From Negative");
deleteFromNegativeMenuItem.addActionListener(this);
subedTaxRegsTableMenu.add(deleteFromNegativeMenuItem);
}
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 initComponents() {
CellConstraints cc = new CellConstraints();
// ======== this ========
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
TaxRegsDialog thisWindow = (TaxRegsDialog) e.getSource();
thisWindow.container.setEnabled(true);
thisWindow.dispose();
}
});
Container contentPane = getContentPane();
contentPane.setLayout(new FormLayout(new ColumnSpec[] {
new ColumnSpec("10px"),
FormFactory.LABEL_COMPONENT_GAP_COLSPEC,
new ColumnSpec("300px"),
FormFactory.LABEL_COMPONENT_GAP_COLSPEC,
new ColumnSpec("20px"),
FormFactory.LABEL_COMPONENT_GAP_COLSPEC,
new ColumnSpec("300px"),
FormFactory.LABEL_COMPONENT_GAP_COLSPEC,
FormFactory.DEFAULT_COLSPEC }, new RowSpec[] {
new RowSpec("10px"), FormFactory.LINE_GAP_ROWSPEC,
FormFactory.DEFAULT_ROWSPEC, FormFactory.LINE_GAP_ROWSPEC,
new RowSpec("150px"), FormFactory.LINE_GAP_ROWSPEC,
new RowSpec("150px"), FormFactory.LINE_GAP_ROWSPEC,
FormFactory.DEFAULT_ROWSPEC }));
JPanel panel = new JPanel();
{
panel.setLayout(new FlowLayout(FlowLayout.RIGHT));
baseAMTLabel = new JLabel();
panel.add(baseAMTLabel);
JButton calculatorBaseAMTButton = new JButton();
calculatorBaseAMTButton.setIcon(ImageManager
.getImage(ImageManager.CALCULATOR_IMAGE));
calculatorBaseAMTButton.setActionCommand("Calculator BaseAMT");
calculatorBaseAMTButton.addActionListener(this);
panel.add(calculatorBaseAMTButton);
}
contentPane.add(panel, cc.xywh(3, 3, 5, 1));
JScrollPane scrollPane = new JScrollPane();
{
sourceTable = new JXTable();
sourceTable.setHorizontalScrollEnabled(true);
sourceTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
sourceTable
.setHighlighters(new HighlighterPipeline(
new Highlighter[] { AlternateRowHighlighter.classicLinePrinter }));
sourceTable.setHighlighters(new HighlighterPipeline(
new Highlighter[] { AlternateRowHighlighter.genericGrey }));
sourceTable.getHighlighters().addHighlighter(
new RolloverHighlighter(Color.BLACK, Color.WHITE));
sourceTable
.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
sourceTable.setComponentPopupMenu(sourceTableMenu);
sourceTable.addMouseListener(this);
scrollPane.setViewportView(sourceTable);
}
contentPane.add(scrollPane, cc.xywh(3, 5, 1, 3));
JButton button = new JButton();
button.setText(null);
button.setIcon(ImageManager.getImage(ImageManager.ADD_IMAGE));
button.setActionCommand("Add To Positive");
button.addActionListener(this);
contentPane.add(button, cc.xy(5, 5));
scrollPane = new JScrollPane();
{
addedTaxRegsTable = new JXTable();
addedTaxRegsTable.setHorizontalScrollEnabled(true);
addedTaxRegsTable
.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
addedTaxRegsTable
.setHighlighters(new HighlighterPipeline(
new Highlighter[] { AlternateRowHighlighter.classicLinePrinter }));
addedTaxRegsTable.setHighlighters(new HighlighterPipeline(
new Highlighter[] { AlternateRowHighlighter.genericGrey }));
addedTaxRegsTable.getHighlighters().addHighlighter(
new RolloverHighlighter(Color.BLACK, Color.WHITE));
addedTaxRegsTable
.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
addedTaxRegsTable.setComponentPopupMenu(addedTaxRegsTableMenu);
addedTaxRegsTable.addMouseListener(this);
scrollPane.setViewportView(addedTaxRegsTable);
}
contentPane.add(scrollPane, cc.xy(7, 5));
button = new JButton();
button.setText(null);
button.setIcon(ImageManager.getImage(ImageManager.SUB_IMAGE));
button.setActionCommand("Add To Negative");
button.addActionListener(this);
contentPane.add(button, cc.xy(5, 7));
scrollPane = new JScrollPane();
{
subedTaxRegsTable = new JXTable();
subedTaxRegsTable.setHorizontalScrollEnabled(true);
subedTaxRegsTable
.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
subedTaxRegsTable
.setHighlighters(new HighlighterPipeline(
new Highlighter[] { AlternateRowHighlighter.classicLinePrinter }));
subedTaxRegsTable.setHighlighters(new HighlighterPipeline(
new Highlighter[] { AlternateRowHighlighter.genericGrey }));
subedTaxRegsTable.getHighlighters().addHighlighter(
new RolloverHighlighter(Color.BLACK, Color.WHITE));
subedTaxRegsTable
.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
subedTaxRegsTable.setComponentPopupMenu(subedTaxRegsTableMenu);
subedTaxRegsTable.addMouseListener(this);
scrollPane.setViewportView(subedTaxRegsTable);
}
contentPane.add(scrollPane, cc.xy(7, 7));
panel = new JPanel();
{
panel.setLayout(new FlowLayout(FlowLayout.LEFT));
taxRegsStatButton = new JButton();
taxRegsStatButton
.setText(MnemonicGenerator
.generateMnemonicString(
TxtManager
.getTxt("VIEW.OBJECTEDIT.TAX.NOTTAXEDORALLTAXABLEREGS"),
KeyEvent.VK_T));
taxRegsStatButton.setMnemonic(KeyEvent.VK_T);
taxRegsStatButton.setIcon(ImageManager
.getImage(ImageManager.TAXED_REGS_IMAGE));
taxRegsStatButton.setPreferredSize(new Dimension(220, 20));
taxRegsStatButton.setActionCommand("Tax Regs Stat Change");
taxRegsStatButton.addActionListener(this);
panel.add(taxRegsStatButton);
}
contentPane.add(panel, cc.xy(3, 9));
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);
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);
panel.add(cancelButton);
}
contentPane.add(panel, cc.xy(7, 9));
pack();
setTitle(TxtManager.getTxt("VIEW.OBJECTEDIT.TAX.TAXABLEREGS"));
setVisible(true);
setLocationRelativeTo(null);
setResizable(false);
}
private void initTablesModel() {
initTablesStructure();
if (isNewRow()) {
initTablesData();
} else {
Iterator taxsIter = ((ObjectEdit) container).getTaxs().iterator();
while (taxsIter.hasNext()) {
Vector taxDatas = (Vector) taxsIter.next();
Row row = (Row) taxDatas.get(0);
if (row == selectedRow) {
stat = (String) taxDatas.get(1);
Vector sourceData = (Vector) taxDatas.get(2);
Vector addData = (Vector) taxDatas.get(3);
Vector subData = (Vector) taxDatas.get(4);
initTablesData(sourceData, addData, subData);
break;
}
}
}
}
private void initTablesStructure() {
DefaultTableModel model = new DefaultTableModel();
Vector columnNames = new Vector();
RegClass regObject = (RegClass) ClassManager.createClass(510);
Column column = ObjectUtil.findColumn(regObject, "RI", "R");
columnNames.add(column.toString());
column = ObjectUtil.findColumn(regObject, "RI", "RI");
columnNames.add(column.toString());
column = ObjectUtil.findColumn(regObject, "RI", "TXT256");
columnNames.add(column.toString());
column = ObjectUtil.findColumn(regObject, "RI", "LD");
columnNames.add(column.toString());
column = ObjectUtil.findColumn(regObject, "RI", "LC");
columnNames.add(column.toString());
column = ObjectUtil.findColumn(regObject, "RI", "LAMT");
columnNames.add(column.toString());
column = ObjectUtil.findColumn(regObject, "RI", "TC");
columnNames.add(column.toString());
column = ObjectUtil.findColumn(regObject, "RI", "TAMT");
columnNames.add(column.toString());
columnNames.add("");
model.setDataVector(new Vector(), columnNames);
DefaultTableModel cloneModel = new DefaultTableModel();
cloneModel.setDataVector(new Vector(), columnNames);
DefaultTableModel cloneModel1 = new DefaultTableModel();
cloneModel1.setDataVector(new Vector(), columnNames);
sourceTable.setModel(model);
addedTaxRegsTable.setModel(cloneModel);
subedTaxRegsTable.setModel(cloneModel1);
sourceTable.getColumn(0).setPreferredWidth(75);
sourceTable.getColumn(1).setPreferredWidth(75);
sourceTable.getColumn(2).setPreferredWidth(100);
sourceTable.getColumn(3).setPreferredWidth(50);
sourceTable.getColumn(4).setPreferredWidth(50);
sourceTable.getColumn(5).setPreferredWidth(75);
sourceTable.getColumn(6).setPreferredWidth(50);
sourceTable.getColumn(7).setPreferredWidth(75);
sourceTable.getColumnExt(8).setVisible(false);
addedTaxRegsTable.getColumn(0).setPreferredWidth(75);
addedTaxRegsTable.getColumn(1).setPreferredWidth(75);
addedTaxRegsTable.getColumn(2).setPreferredWidth(100);
addedTaxRegsTable.getColumn(3).setPreferredWidth(50);
addedTaxRegsTable.getColumn(4).setPreferredWidth(50);
addedTaxRegsTable.getColumn(5).setPreferredWidth(75);
addedTaxRegsTable.getColumn(6).setPreferredWidth(50);
addedTaxRegsTable.getColumn(7).setPreferredWidth(75);
addedTaxRegsTable.getColumnExt(8).setVisible(false);
subedTaxRegsTable.getColumn(0).setPreferredWidth(75);
subedTaxRegsTable.getColumn(1).setPreferredWidth(75);
subedTaxRegsTable.getColumn(2).setPreferredWidth(100);
subedTaxRegsTable.getColumn(3).setPreferredWidth(50);
subedTaxRegsTable.getColumn(4).setPreferredWidth(50);
subedTaxRegsTable.getColumn(5).setPreferredWidth(75);
subedTaxRegsTable.getColumn(6).setPreferredWidth(50);
subedTaxRegsTable.getColumn(7).setPreferredWidth(75);
subedTaxRegsTable.getColumnExt(8).setVisible(false);
}
private void initTablesData(Vector sourceData, Vector addData,
Vector subData) {
DefaultTableModel sourceModel = (DefaultTableModel) sourceTable.getModel();
DefaultTableModel addModel = (DefaultTableModel) addedTaxRegsTable.getModel();
DefaultTableModel subModel = (DefaultTableModel) subedTaxRegsTable.getModel();
Iterator sourceDataIter = sourceData.iterator();
while (sourceDataIter.hasNext()) {
Vector rowData = (Vector) sourceDataIter.next();
sourceModel.addRow(rowData);
}
Iterator addDataIter = addData.iterator();
while (addDataIter.hasNext()) {
Vector rowData = (Vector) addDataIter.next();
addModel.addRow(rowData);
}
Iterator subDataIter = subData.iterator();
while (subDataIter.hasNext()) {
Vector rowData = (Vector) subDataIter.next();
subModel.addRow(rowData);
}
}
private void changeTaxRegsStat() {
if (stat.equals("Display no taxed regs"))
stat = "Display all taxed regs";
else if (stat.equals("Display all taxed regs"))
stat = "Display no taxed regs";
}
private void initTablesData() {
RegClass regObject = (RegClass) ClassManager.createClass(510);
Vector taxableRows = null;
if (stat.equals("Display no taxed regs")){
taxableRows = regObject.findAllNotTaxedByOtherTaxsRegs(selectedRow);
}
else if (stat.equals("Display all taxed regs"))
taxableRows = regObject.findAllTaxableRegs(selectedRow);
Iterator taxableRowsIter = taxableRows.iterator();
while (taxableRowsIter.hasNext()) {
Row row = (Row) taxableRowsIter.next();
Vector rowData = new Vector();
Cell cell = ObjectUtil.findNewCell(row, "RI", "R");
rowData.add(cell.getColumnValue());
cell = ObjectUtil.findNewCell(row, "RI", "RI");
rowData.add(cell.getColumnValue());
cell = ObjectUtil.findNewCell(row, "RI", "TXT256");
rowData.add(cell.getColumnValue());
cell = ObjectUtil.findNewCell(row, "RI", "LD");
rowData.add(cell.getColumnValue());
cell = ObjectUtil.findNewCell(row, "RI", "LC");
rowData.add(cell.getColumnValue());
cell = ObjectUtil.findNewCell(row, "RI", "LAMT");
rowData.add(cell.getColumnValue());
cell = ObjectUtil.findNewCell(row, "RI", "TC");
rowData.add(cell.getColumnValue());
cell = ObjectUtil.findNewCell(row, "RI", "TAMT");
rowData.add(cell.getColumnValue());
rowData.add(row);
cell = ObjectUtil.findNewCell(selectedRow, "TAXI", "TAXT");
String taxt = (String) cell.getColumnValue();
cell = ObjectUtil.findNewCell(selectedRow, "TAXI", "TAX");
String tax = (String) cell.getColumnValue();
cell = ObjectUtil.findNewCell(selectedRow, "TAXI", "TAXI");
String taxi = (String) cell.getColumnValue();
if (regObject.isRowTaxedBySpecifyTax(row, taxt, tax, taxi)) {
if (regObject.getRowSignBySpecifyTax(row, taxt, tax, taxi) == 1) {
DefaultTableModel model = (DefaultTableModel) addedTaxRegsTable
.getModel();
model.addRow(rowData);
} else if (regObject.getRowSignBySpecifyTax(row, taxt, tax,
taxi) == -1) {
DefaultTableModel model = (DefaultTableModel) subedTaxRegsTable
.getModel();
model.addRow(rowData);
}
} else {
DefaultTableModel model = (DefaultTableModel) sourceTable.getModel();
model.addRow(rowData);
}
}
}
private void updateTablesModel() {
DefaultTableModel sourceModel = (DefaultTableModel) sourceTable
.getModel();
DefaultTableModel addModel = (DefaultTableModel) addedTaxRegsTable
.getModel();
DefaultTableModel subModel = (DefaultTableModel) subedTaxRegsTable
.getModel();
RegClass regObject = (RegClass) ClassManager.createClass(510);
Vector taxableRows = null;
if (stat.equals("Display no taxed regs"))
taxableRows = regObject.findAllNotTaxedByOtherTaxsRegs(selectedRow);
else if (stat.equals("Display all taxed regs"))
taxableRows = regObject.findAllTaxableRegs(selectedRow);
Vector needRemovedRows = new Vector();
Iterator taxableRowsIter = taxableRows.iterator();
while (taxableRowsIter.hasNext()) {
Row regRow = (Row) taxableRowsIter.next();
Iterator rowsIter = addModel.getDataVector().iterator();
while (rowsIter.hasNext()) {
Vector rowData = (Vector) rowsIter.next();
Row addRegRow = (Row) rowData.get(rowData.size() - 1);
if (regObject.isEqual(regRow, addRegRow))
needRemovedRows.add(regRow);
}
rowsIter = subModel.getDataVector().iterator();
while (rowsIter.hasNext()) {
Vector rowData = (Vector) rowsIter.next();
Row subRegRow = (Row) rowData.get(rowData.size() - 1);
if (regObject.isEqual(regRow, subRegRow))
needRemovedRows.add(regRow);
}
}
Iterator needRemovedRowsIter = needRemovedRows.iterator();
while (needRemovedRowsIter.hasNext()) {
Row row = (Row) needRemovedRowsIter.next();
taxableRowsIter = taxableRows.iterator();
while (taxableRowsIter.hasNext()) {
Row regRow = (Row) taxableRowsIter.next();
if (row.equals(regRow)) {
taxableRows.remove(regRow);
break;
}
}
}
int rowCount = sourceModel.getRowCount();
for (int i = 0; i < rowCount; i++)
sourceModel.removeRow(0);
taxableRowsIter = taxableRows.iterator();
while (taxableRowsIter.hasNext()) {
Row row = (Row) taxableRowsIter.next();
Vector rowData = new Vector();
Cell cell = ObjectUtil.findNewCell(row, "RI", "R");
rowData.add(cell.getColumnValue());
cell = ObjectUtil.findNewCell(row, "RI", "RI");
rowData.add(cell.getColumnValue());
cell = ObjectUtil.findNewCell(row, "RI", "TXT256");
rowData.add(cell.getColumnValue());
cell = ObjectUtil.findNewCell(row, "RI", "LD");
rowData.add(cell.getColumnValue());
cell = ObjectUtil.findNewCell(row, "RI", "LC");
rowData.add(cell.getColumnValue());
cell = ObjectUtil.findNewCell(row, "RI", "LAMT");
rowData.add(cell.getColumnValue());
cell = ObjectUtil.findNewCell(row, "RI", "TC");
rowData.add(cell.getColumnValue());
cell = ObjectUtil.findNewCell(row, "RI", "TAMT");
rowData.add(cell.getColumnValue());
rowData.add(row);
sourceModel.addRow(rowData);
}
}
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("Calculator BaseAMT")) {
calculatorBaseAMT();
} else if (e.getActionCommand().equals("Cancel")) {
container.setEnabled(true);
dispose();
} else if (e.getActionCommand().equals("Add To Positive")) {
addToPOrNTables("Add To Positive");
} else if (e.getActionCommand().equals("Add To Negative")) {
addToPOrNTables("Add To Negative");
} else if (e.getActionCommand().equals("Delete From Positive")) {
removeFromPOrNTables("Delete From Positive");
} else if (e.getActionCommand().equals("Delete From Negative")) {
removeFromPOrNTables("Delete From Negative");
} else if (e.getActionCommand().equals("Tax Regs Stat Change")) {
changeTaxRegsStat();
updateTablesModel();
} else if (e.getActionCommand().equals("Confirm")) {
confirm();
}
}
private void confirm() {
boolean result = calculatorBaseAMT1AndTaxAMTUseOldBaseAMT2();
if (result) {
DefaultTableModel sourceModel = (DefaultTableModel) sourceTable
.getModel();
DefaultTableModel addModel = (DefaultTableModel) addedTaxRegsTable
.getModel();
DefaultTableModel subModel = (DefaultTableModel) subedTaxRegsTable
.getModel();
boolean isNewRow = true;
Iterator taxsIter = ((ObjectEdit) container).getTaxs().iterator();
while (taxsIter.hasNext()) {
Vector taxDatas = (Vector) taxsIter.next();
Row row = (Row) taxDatas.get(0);
if (row == selectedRow) {
isNewRow = false;
taxDatas.set(1, stat);
taxDatas.set(2, sourceModel.getDataVector());
taxDatas.set(3, addModel.getDataVector());
taxDatas.set(4, subModel.getDataVector());
break;
}
}
if (isNewRow) {
Vector taxDatas = new Vector();
taxDatas.add(selectedRow);
taxDatas.add(stat);
taxDatas.add(sourceModel.getDataVector());
taxDatas.add(addModel.getDataVector());
taxDatas.add(subModel.getDataVector());
((ObjectEdit) container).getTaxs().add(taxDatas);
}
Cell cell = ObjectUtil.findNewCell(selectedRow, "TAXI",
"TAXBASEAMT1");
cell.setColumnValue(baseAMT1);
cell = ObjectUtil.findNewCell(selectedRow, "TAXI", "TAXBASEAMT2");
cell.setColumnValue(baseAMT2);
cell = ObjectUtil.findNewCell(selectedRow, "TAXI", "TAMT");
cell.setColumnValue(taxAMT);
selectedRow.setModify(true);
((ObjectEdit) container).updateTable();
container.setEnabled(true);
dispose();
}
}
private void removeFromPOrNTables(String action) {
JXTable table = null;
if (action.equals("Delete From Positive")) {
table = addedTaxRegsTable;
} else if (action.equals("Delete From Negative")) {
table = subedTaxRegsTable;
}
int[] selectedRows = table.getSelectedRows();
int[] sorteredRows = new int[selectedRows.length];
Vector selectedRowsVector = new Vector();
if (selectedRows.length > 0) {
DefaultTableModel model = (DefaultTableModel) table.getModel();
// sort
for (int i = 0; i < selectedRows.length; i++) {
sorteredRows[i] = table.convertRowIndexToModel(selectedRows[i]);
}
for (int i = 0; i < sorteredRows.length - 1; i++) {
for (int j = i + 1; j < sorteredRows.length; j++) {
if (sorteredRows[i] > sorteredRows[j]) {
int temp = sorteredRows[i];
sorteredRows[i] = sorteredRows[j];
sorteredRows[j] = temp;
}
}
}
DefaultTableModel model1 = (DefaultTableModel) sourceTable
.getModel();
for (int i = 0; i < sorteredRows.length; i++) {
Vector datas = (Vector) model.getDataVector().elementAt(
sorteredRows[i] - i);
if (stat.equals("Display all taxed regs")) {
model1.addRow(datas);
} else if (stat.equals("Display no taxed regs")) {
Row regRow = (Row) datas.get(datas.size() - 1);
if ((RegClass.isRowTaxable(regRow))
&& (!RegClass.isRowTaxByOtherTaxs(selectedRow,
regRow)))
model1.addRow(datas);
}
model.removeRow(sorteredRows[i] - i);
}
}
}
private void addToPOrNTables(String action) {
JXTable ordinaryTable = null;
if (action.equals("Add To Negative")) {
ordinaryTable = subedTaxRegsTable;
} else if (action.equals("Add To Positive")) {
ordinaryTable = addedTaxRegsTable;
}
int[] selectedRows = sourceTable.getSelectedRows();
int[] sorteredRows = new int[selectedRows.length];
Vector selectedRowsVector = new Vector();
if (selectedRows.length > 0) {
DefaultTableModel model = (DefaultTableModel) sourceTable
.getModel();
// sort
for (int i = 0; i < selectedRows.length; i++) {
sorteredRows[i] = sourceTable
.convertRowIndexToModel(selectedRows[i]);
}
for (int i = 0; i < sorteredRows.length - 1; i++) {
for (int j = i + 1; j < sorteredRows.length; j++) {
if (sorteredRows[i] > sorteredRows[j]) {
int temp = sorteredRows[i];
sorteredRows[i] = sorteredRows[j];
sorteredRows[j] = temp;
}
}
}
DefaultTableModel model1 = (DefaultTableModel) ordinaryTable
.getModel();
for (int i = 0; i < sorteredRows.length; i++) {
Vector datas = (Vector) model.getDataVector().elementAt(
sorteredRows[i] - i);
model1.addRow(datas);
model.removeRow(sorteredRows[i] - i);
}
}
}
private boolean calculatorBaseAMT1AndTaxAMTUseOldBaseAMT2() {
boolean result = true;
baseAMT1 = 0.0;
baseAMT2 = 0.0;
taxAMT = 0.0;
DefaultTableModel model = (DefaultTableModel) addedTaxRegsTable
.getModel();
Vector dataVector = model.getDataVector();
Iterator dataIter = dataVector.iterator();
while (dataIter.hasNext()) {
Vector rowData = (Vector) dataIter.next();
Row row = (Row) rowData.get(rowData.size() - 1);
Cell cell = ObjectUtil.findNewCell(row, "RI", "LAMT");
double lamt = getDouble(cell.getColumnValue());
baseAMT1 += Math.abs(lamt);
}
model = (DefaultTableModel) subedTaxRegsTable.getModel();
dataVector = model.getDataVector();
dataIter = dataVector.iterator();
while (dataIter.hasNext()) {
Vector rowData = (Vector) dataIter.next();
Row row = (Row) rowData.get(rowData.size() - 1);
Cell cell = ObjectUtil.findNewCell(row, "RI", "LAMT");
double lamt = getDouble(cell.getColumnValue());
baseAMT1 -= Math.abs(lamt);
}
String tc = ObjectUtil.findNewCell(selectedRow, "TAXI", "TC")
.getColumnValue().toString();
String tdate = ObjectUtil.findNewCell(selectedRow, "TAX", "TDATE")
.getColumnValue().toString();
result = XRClass.hasExchangeRate(FamilyClass.getLocalCurrency(), tc,
tdate);
if (!result) {
StringBuffer sb = new StringBuffer(TxtManager
.getTxt("INFORMATION.XRNOTFOUND"));
sb.append(tdate);
sb.append(TxtManager.getTxt("INFORMATION.XRNOTFOUND1"));
sb.append(tc);
sb.append(TxtManager.getTxt("INFORMATION.XRNOTFOUND2"));
sb.append(FamilyClass.getLocalCurrency() + ". ");
DialogManager.showMessageDialog(this, sb.toString());
} else {
double xr = XRClass.getExchangeRate(FamilyClass.getLocalCurrency(),
tc, tdate);
baseAMT1 = baseAMT1 / xr;
baseAMT2 = baseAMT2 / xr;
taxAMT = ((TaxClass) container.getObject()).calculatorTax(
selectedRow, baseAMT1, baseAMT2);
}
return result;
}
private void calculatorBaseAMT() {
baseAMT1 = 0.0;
baseAMT2 = 0.0;
taxAMT = 0.0;
DefaultTableModel model = (DefaultTableModel) addedTaxRegsTable
.getModel();
Vector dataVector = model.getDataVector();
Iterator dataIter = dataVector.iterator();
while (dataIter.hasNext()) {
Vector rowData = (Vector) dataIter.next();
Row row = (Row) rowData.get(rowData.size() - 1);
Cell cell = ObjectUtil.findNewCell(row, "RI", "LAMT");
double lamt = getDouble(cell.getColumnValue());
// System.err.println("lamt = " + lamt);
baseAMT1 += Math.abs(lamt);
}
model = (DefaultTableModel) subedTaxRegsTable.getModel();
dataVector = model.getDataVector();
dataIter = dataVector.iterator();
while (dataIter.hasNext()) {
Vector rowData = (Vector) dataIter.next();
Row row = (Row) rowData.get(rowData.size() - 1);
Cell cell = ObjectUtil.findNewCell(row, "RI", "LAMT");
double lamt = getDouble(cell.getColumnValue());
baseAMT1 -= Math.abs(lamt);
}
String tc = ObjectUtil.findNewCell(selectedRow, "TAXI", "TC")
.getColumnValue().toString();
String tdate = ObjectUtil.findNewCell(selectedRow, "TAX", "TDATE")
.getColumnValue().toString();
boolean result = XRClass.hasExchangeRate(
FamilyClass.getLocalCurrency(), tc, tdate);
if (!result) {
StringBuffer sb = new StringBuffer(TxtManager
.getTxt("INFORMATION.XRNOTFOUND"));
sb.append(tdate);
sb.append(TxtManager.getTxt("INFORMATION.XRNOTFOUND1"));
sb.append(tc);
sb.append(TxtManager.getTxt("INFORMATION.XRNOTFOUND2"));
sb.append(FamilyClass.getLocalCurrency() + ". ");
DialogManager.showMessageDialog(this, sb.toString());
return;
}
double xr = XRClass.getExchangeRate(FamilyClass.getLocalCurrency(), tc,
tdate);
// System.err.println("xr = " + xr);
baseAMT1 = baseAMT1 / xr;
baseAMT2 = baseAMT2 / xr;
StringBuffer sb = new StringBuffer("###");
sb.append(CurrencyPlugin.getInstance().getSepor() + "###");
int fraction = CurrencyPlugin.getInstance().getLcFraction();
if (fraction > 0) {
sb.append(CurrencyPlugin.getInstance().getFpoint());
}
for (int i = 1; i <= fraction; i++) {
sb.append("0");
}
DecimalFormat df = new DecimalFormat(sb.toString());
sb = new StringBuffer(TxtManager
.getTxt("VIEW.OBJECTEDIT.TAX.TAXBASEAMT1")
+ " : ");
sb.append(df.format(baseAMT1) + " , ");
if (n > 0) {
if (needBaseAMT2()) {
String s = (String) JOptionPane
.showInputDialog(
this,
TxtManager
.getTxt("VIEW.OBJECTEDIT.TAX.TAXBASEAMT2"),
TxtManager
.getTxt("VIEW.OBJECTEDIT.TAX.INPUTTAXBASEAMT2"),
JOptionPane.PLAIN_MESSAGE, ImageManager
.getImage(ImageManager.TAX_IMAGE),
null, baseAMT2);
try {
baseAMT2 = Double.parseDouble(s);
} catch (Exception e) {
}
}
}
sb.append(TxtManager.getTxt("VIEW.OBJECTEDIT.TAX.TAXBASEAMT2") + " : ");
sb.append(df.format(baseAMT2) + " , ");
//sb.append(TxtManager.getTxt("VIEW.OBJECTEDIT.TAX.TAXAMT") + " : ");
taxAMT = ((TaxClass) container.getObject()).calculatorTax(selectedRow,
baseAMT1, baseAMT2);
sb.append(TxtManager.getTxt("VIEW.OBJECTEDIT.TAX.TAXAMT") + " : ");
sb.append(df.format(taxAMT) + " . ");
baseAMTLabel.setText(sb.toString());
}
private boolean needBaseAMT2() {
boolean result = false;
Cell newCell = ObjectUtil.findNewCell(selectedRow, "TAX", "TAXT");
String taxt = (String) newCell.getColumnValue();
DAO dao = DAO.getInstance();
dao.query(Resources.SELECT_FROM_TAXT_SQL);
dao.setString(1, taxt);
ResultSet rs = dao.executeQuery();
try {
if (rs.next()) {
String formula = rs.getString("FORMULA");
result = (formula.indexOf("[B2]") != -1);
}
rs.close();
} catch (Exception e) {
e.printStackTrace();
}
return result;
}
private double getDouble(Object value) {
double d = 0.0;
if (value != null) {
if (value instanceof Number)
d = ((Number) value).doubleValue();
else if (((String) value).trim().equals(""))
d = 0.0;
else
d = Double.parseDouble((String) value);
}
return d;
}
private boolean isNewRow() {
boolean result = true;
Iterator taxsIter = ((ObjectEdit) container).getTaxs().iterator();
while (taxsIter.hasNext()) {
Vector taxDatas = (Vector) taxsIter.next();
Row row = (Row) taxDatas.get(0);
if (row == selectedRow) {
result = false;
break;
}
}
return result;
}
}