package realcix20.guis.views;
import info.clearthought.layout.TableLayout;
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.FocusListener;
import java.awt.event.KeyEvent;
import java.awt.event.MouseListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.io.File;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.text.DecimalFormat;
import java.util.Arrays;
import java.util.Iterator;
import java.util.StringTokenizer;
import java.util.Vector;
import javax.swing.AbstractAction;
import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JPanel;
import javax.swing.JPopupMenu;
import javax.swing.JScrollPane;
import javax.swing.JTabbedPane;
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.cixfiles.CIXFile;
import realcix20.classes.BudgetClass;
import realcix20.classes.CorrespondenceClass;
import realcix20.classes.PartnerClass;
import realcix20.classes.RegClass;
import realcix20.classes.TaxClass;
import realcix20.classes.TaxTypeClass;
import realcix20.classes.basic.BaseClass;
import realcix20.classes.basic.Cell;
import realcix20.classes.basic.Column;
import realcix20.classes.basic.Row;
import realcix20.classes.plugins.CurrencyPlugin;
import realcix20.guis.listeners.ObjectEditListener;
import realcix20.guis.models.ItemTableModel;
import realcix20.guis.relationships.RelationManager;
import realcix20.guis.utils.ComponentExt;
import realcix20.guis.utils.ComponentManager;
import realcix20.guis.utils.ImageManager;
import realcix20.guis.utils.KeyUtil;
import realcix20.guis.utils.MnemonicGenerator;
import realcix20.guis.utils.TxtManager;
import realcix20.utils.DAO;
import realcix20.utils.ObjectUtil;
import com.jgoodies.forms.factories.DefaultComponentFactory;
import com.jgoodies.forms.layout.CellConstraints;
public class ObjectEdit extends JDialog {
private JTabbedPane propertyPane;
private JPanel controlPanel;
private JXTable table;
private JPopupMenu tablePopupMenu;
private MainView container;
private BaseClass object;
private Row currentRow;
private ObjectEditListener listener;
private Vector headComponentExts;
private Vector headAlertLabels;
private Vector headGroups;
private Vector itemComponentExts;
private String action;
private String type = null;
private CIXFile cixFile;
private File file;
private Vector componentExts;
//specify, used by RegClass
private JLabel regLabel;
private Vector regs;//data strcuture : row, (Vector)notAssigned rowdatas, (Vector)assigned rowdatas
//specify, used by TaxClass
private Vector taxs;//data strcuture : row, String stat, (Vector)sourceTable rowdatas, (Vector)positiveTax rowdatas, (Vector)nagative rowdatas
//specify, used by BudgetClass
private JLabel budgetLabel;
//private Vector banks;//used by PartnerClass
//private Vector address;//used by PartnerClass
private String stat;//used by PartnerClass stat : Add
public Vector address;
public Vector banks;
private RelationManager relationManager;
private JButton confirmButton=new JButton();
public ObjectEdit(MainView container, BaseClass object, Row currentRow, String action) {
super(container);
this.container = container;
this.object = object;
this.currentRow = currentRow;
this.action = action;
listener = new ObjectEditListener(this);
this.stat = "NNNN";
addWindowListener(getListener());
initialHeadAndItemComponentExts();
createRelation();
setAllComponentValue();
initTablePopupMenu();
initComponents();
//specify, used by RegClass
regs = new Vector();
//specify, used by TaxClass
taxs = new Vector();
}
//used by CorrespondenceClass
public ObjectEdit(MainView container, BaseClass object, Row currentRow, String action, String stat) {
super(container);
this.container = container;
this.object = object;
this.currentRow = currentRow;
this.action = action;
this.stat = stat;
listener = new ObjectEditListener(this);
addWindowListener(getListener());
initialHeadAndItemComponentExts();
createRelation();
setAllComponentValue();
initTablePopupMenu();
initComponents();
//specify, used by RegClass
regs = new Vector();
//specify, used by TaxClass
taxs = new Vector();
}
//used by PartnerClass
public ObjectEdit(MainView container, BaseClass object, Row currentRow, String action, String stat, Vector addresses, Vector banks) {
super(container);
this.container = container;
this.object = object;
this.currentRow = currentRow;
this.action = action;
this.stat = stat;
this.address = addresses;
this.banks = banks;
listener = new ObjectEditListener(this);
addWindowListener(getListener());
initialHeadAndItemComponentExts();
createRelation();
setAllComponentValue();
initTablePopupMenu();
initComponents();
//specify, used by RegClass
regs = new Vector();
//specify, used by TaxClass
taxs = new Vector();
}
public ObjectEdit(MainView container, BaseClass object, Row currentRow, String action, String type, File file, CIXFile cixFile) {
super(container);
this.container = container;
this.object = object;
this.currentRow = currentRow;
this.action = action;
this.type = type;
this.cixFile = cixFile;
this.file = file;
listener = new ObjectEditListener(this);
this.addWindowListener(getListener());
initialHeadAndItemComponentExts();
createRelation();
setAllComponentValue();
initTablePopupMenu();
initComponents();
}
private Object getValue(Column column, Row row) {
Object value = null;
Iterator cellIter = row.getNewCells().iterator();
while (cellIter.hasNext()) {
Cell cell = (Cell)cellIter.next();
if ( (cell.getColumnName().equals(column.getColumnName())) && (cell.getTableName().equals(column.getTableName())) ) {
value = cell.getColumnValue();
}
}
return value;
}
public void createRelation() {
componentExts = (Vector)headComponentExts.clone();
getComponentExts().addAll(getItemComponentExts());
relationManager = RelationManager.getInstance(getComponentExts());
}
private void setAllComponentValue() {
Iterator componentExtIter = getComponentExts().iterator();
while (componentExtIter.hasNext()) {
ComponentExt componentExt = (ComponentExt)componentExtIter.next();
Column column = componentExt.getColumn();
Row row = componentExt.getRow();
JComponent component = componentExt.getComponent();
if ( (action.equals("Edit")) || (getStat().equals("Add")) || (getStat().equals("PartnerAdd")) ) {
// System.out.println(column.getTableName() + "." + column.getColumnName());
ComponentManager.setValue(getValue(column, row), component);
} else if (action.equals("Add")) {
Vector parameters = getRelationManager().getParameters_Defvalue(componentExt);
if (parameters != null) {
String sql = getRelationManager().getSQL_Defvalue(componentExt, parameters);
DAO dao = DAO.getInstance();
dao.query(sql);
for (int i = 0; i < parameters.size(); i++) {
String parameter = (String)parameters.get(i);
StringTokenizer st = new StringTokenizer(parameter, ".");
String tableName = (String)st.nextElement();
String columnName = (String)st.nextElement();
ComponentExt tempComponentExt = getRelationManager().findComponentExt(tableName, columnName);
JComponent tempComponent = tempComponentExt.getComponent();
dao.setObject(i+1, ComponentManager.getValue(tempComponent));
}
ResultSet rs = dao.executeQuery();
try {
if (rs.next()) {
ResultSetMetaData rsmd = rs.getMetaData();
for (int i = 1; i <= rsmd.getColumnCount(); i++) {
ComponentExt tempComponentExt = getRelationManager().findComponentExt(column.getTableName(), rsmd.getColumnName(i));
boolean isThisObjectColumn = (tempComponentExt != null);
if (isThisObjectColumn) {
if (rs.getObject(i) != null) {
ComponentManager.setValue(rs.getObject(i), tempComponentExt.getComponent());
}
}
}
}
rs.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
}
private void initialHeadAndItemComponentExts() {
headComponentExts = new Vector();
setItemComponentExts(new Vector());
Iterator columnIter = object.getColumns().iterator();
while (columnIter.hasNext()) {
Column column = (Column)columnIter.next();
if (column.isHeadField()) {
ComponentExt componentExt = new ComponentExt(ComponentManager.getComponent(column), column, currentRow);
headComponentExts.add(componentExt);
}
else if (column.isItemField()) {
ComponentExt componentExt = new ComponentExt(ComponentManager.getComponent(column), column, currentRow);
getItemComponentExts().add(componentExt);
}
}
}
private void initTablePopupMenu() {
tablePopupMenu = new JPopupMenu();
JMenuItem addItem = new JMenuItem();
addItem.setText(MnemonicGenerator.generateMnemonicString(TxtManager.getTxt("VIEW.OBJECTEDIT.GLOBAL.ADD"), KeyEvent.VK_A));
addItem.setMnemonic(KeyEvent.VK_A);
addItem.setIcon(ImageManager.getImage(ImageManager.TABLE_ROW_ADD_IMAGE));
addItem.setActionCommand("Object Add");
addItem.addActionListener(getListener());
tablePopupMenu.add(addItem);
JMenuItem editItem = new JMenuItem();
editItem.setText(MnemonicGenerator.generateMnemonicString(TxtManager.getTxt("VIEW.OBJECTEDIT.GLOBAL.EDIT"), KeyEvent.VK_E));
editItem.setMnemonic(KeyEvent.VK_E);
editItem.setIcon(ImageManager.getImage(ImageManager.TABLE_ROW_EDIT_IMAGE));
editItem.setActionCommand("Object Edit");
editItem.addActionListener(getListener());
tablePopupMenu.add(editItem);
JMenuItem deleteItem = new JMenuItem();
deleteItem.setText(MnemonicGenerator.generateMnemonicString(TxtManager.getTxt("VIEW.OBJECTEDIT.GLOBAL.DELETE"), KeyEvent.VK_D));
deleteItem.setMnemonic(KeyEvent.VK_D);
deleteItem.setIcon(ImageManager.getImage(ImageManager.TABLE_ROW_DELETE_IMAGE));
deleteItem.setActionCommand("Object Delete");
deleteItem.addActionListener(getListener());
tablePopupMenu.add(deleteItem);
if (object instanceof RegClass) {
initRegPopupMenu();
} else if (object instanceof TaxClass) {
initTaxPopupMenu();
}
}
//specify, used by TaxClass
private void initTaxPopupMenu() {
tablePopupMenu.addSeparator();
JMenuItem selectAllCanTaxRegsItem = new JMenuItem();
selectAllCanTaxRegsItem.setText(MnemonicGenerator.generateMnemonicString(TxtManager.getTxt("VIEW.OBJECTEDIT.TAX.TAXABLEREGS"), KeyEvent.VK_T));
selectAllCanTaxRegsItem.setMnemonic(KeyEvent.VK_T);
selectAllCanTaxRegsItem.setIcon(ImageManager.getImage(ImageManager.SELECT_ALL_CAN_TAX_REG_IMAGE));
selectAllCanTaxRegsItem.setActionCommand("Select All Can Tax Regs");
selectAllCanTaxRegsItem.addActionListener(getListener());
tablePopupMenu.add(selectAllCanTaxRegsItem);
JMenuItem calculatorItem = new JMenuItem();
calculatorItem.setText(MnemonicGenerator.generateMnemonicString(TxtManager.getTxt("VIEW.OBJECTEDIT.TAX.CALTAXAMOUNT"), KeyEvent.VK_C));
calculatorItem.setMnemonic(KeyEvent.VK_C);
calculatorItem.setIcon(ImageManager.getImage(ImageManager.CALCULATOR_IMAGE));
calculatorItem.setActionCommand("Calculate Tax");
calculatorItem.addActionListener(getListener());
tablePopupMenu.add(calculatorItem);
JMenuItem calculatorAllItem = new JMenuItem();
calculatorAllItem.setText(MnemonicGenerator.generateMnemonicString(TxtManager.getTxt("VIEW.OBJECTEDIT.TAX.CALALLTAXESAMOUNT"), KeyEvent.VK_F));
calculatorAllItem.setMnemonic(KeyEvent.VK_F);
calculatorAllItem.setIcon(ImageManager.getImage(ImageManager.CALCULATOR_IMAGE));
calculatorAllItem.setActionCommand("Calculate All Items' Tax");
calculatorAllItem.addActionListener(getListener());
tablePopupMenu.add(calculatorAllItem);
}
//specify, used by RegClass
private void initRegPopupMenu() {
tablePopupMenu.addSeparator();
JMenuItem createByRowItem = new JMenuItem();
createByRowItem.setText(MnemonicGenerator.generateMnemonicString(TxtManager.getTxt("VIEW.OBJECTEDIT.GLOBAL.COPYANDADD"), KeyEvent.VK_C));
createByRowItem.setMnemonic(KeyEvent.VK_C);
createByRowItem.setIcon(ImageManager.getImage(ImageManager.CREATE_BY_OBJECT_IMAGE));
createByRowItem.setActionCommand("Create By Item");
createByRowItem.addActionListener(getListener());
tablePopupMenu.add(createByRowItem);
JMenuItem setMinusItem = new JMenuItem();
setMinusItem.setText(MnemonicGenerator.generateMnemonicString(TxtManager.getTxt("VIEW.OBJECTEDIT.REG.SETMINUS"), KeyEvent.VK_S));
setMinusItem.setMnemonic(KeyEvent.VK_S);
setMinusItem.setIcon(ImageManager.getImage(ImageManager.SET_MINUS_IMAGE));
setMinusItem.setActionCommand("Set Minus");
setMinusItem.addActionListener(getListener());
tablePopupMenu.add(setMinusItem);
JMenuItem assignToBudgetItem = new JMenuItem();
assignToBudgetItem.setText(MnemonicGenerator.generateMnemonicString(TxtManager.getTxt("VIEW.OBJECTEDIT.REG.ASSIGNTOBUDGET"), KeyEvent.VK_B));
assignToBudgetItem.setMnemonic(KeyEvent.VK_B);
assignToBudgetItem.setIcon(ImageManager.getImage(ImageManager.ASSIGN_TO_BUDGET_IMAGE));
assignToBudgetItem.setActionCommand("Assign To Budget");
assignToBudgetItem.addActionListener(getListener());
tablePopupMenu.add(assignToBudgetItem);
JMenuItem balanceByItem = new JMenuItem();
balanceByItem.setText(MnemonicGenerator.generateMnemonicString(TxtManager.getTxt("VIEW.OBJECTEDIT.REG.BALANCEBYITEM"), KeyEvent.VK_I));
balanceByItem.setMnemonic(KeyEvent.VK_I);
balanceByItem.setIcon(ImageManager.getImage(ImageManager.BALANCE_IMAGE));
balanceByItem.setActionCommand("Balance by item");
balanceByItem.addActionListener(getListener());
tablePopupMenu.add(balanceByItem);
}
private void initComponents() {
initMenuBar();
headGroups = new Vector();
CellConstraints cc = new CellConstraints();
//specify, used by some specify ui layout
int currentLocation = 0;
//======== this ========
addWindowListener(
new WindowAdapter() {
public void windowClosing(WindowEvent e) {
ObjectEdit thisWindow = (ObjectEdit)e.getSource();
thisWindow.getContainer().setEnabled(true);
thisWindow.dispose();
}
}
);
setTitle(TxtManager.getTxt("CLS." + getObject().getClsId()));
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, 0.0, 0.0, 1.0, 0.0, 1.0E-4};
DefaultComponentFactory compFactory = DefaultComponentFactory.getInstance();
JComponent titleText = compFactory.createSeparator(TxtManager.getTxt("VIEW.OBJECTEDIT.PROPERTIESTITLE"));
contentPane.add(titleText, new GridBagConstraints(0, currentLocation, 1, 1, 0.0, 0.0,
GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL,
new Insets(10, 10, 15, 10), 0, 0));
currentLocation++;
//specify,BudgetClass
if (object instanceof BudgetClass) {
budgetLabel = new JLabel();
setCurrentBudgetTotal();
contentPane.add(budgetLabel, new GridBagConstraints(0, currentLocation, 1, 1, 0.0, 0.0,
GridBagConstraints.CENTER, GridBagConstraints.BOTH,
new Insets(0, 10, 0, 5), 0, 0));
currentLocation++;
}
//======== propertyPane ========
{
propertyPane = new JTabbedPane();
getPropertyPane().setPreferredSize(new Dimension(600, 300));
Iterator headComponentExtIter = headComponentExts.iterator();
headAlertLabels = new Vector();
Iterator headGroupNameIter = object.getHeadGroupnames().iterator();
int n = 0;
while (headGroupNameIter.hasNext()) {
int groupName = ((Integer)headGroupNameIter.next()).intValue();
//======== groupPanel ========
{
JPanel groupPanel = new JPanel();
JScrollPane groupScrollPane = new JScrollPane();
groupScrollPane.setViewportView(groupPanel);
//layout
//columnSpec
// ColumnSpec[] columnSpec = new ColumnSpec[] {
// new ColumnSpec("10px"),
// FormFactory.LABEL_COMPONENT_GAP_COLSPEC,
// new ColumnSpec("150px"),
// FormFactory.LABEL_COMPONENT_GAP_COLSPEC,
// new ColumnSpec("150px"),
// FormFactory.LABEL_COMPONENT_GAP_COLSPEC,
// new ColumnSpec("150px")
// };
//
// //rowSpec
// //get rowCount
// int rowCount = getObject().getGroupHeadFieldCount(groupName);
// RowSpec[] rowSpec = new RowSpec[rowCount * 2 + 1];
// rowSpec[0] = new RowSpec("10px");
// rowSpec[1] = FormFactory.LINE_GAP_ROWSPEC;
// for (int i = 1; i <= rowCount - 1; i++) {
// rowSpec[i * 2] = new RowSpec("20px");
// rowSpec[i * 2 + 1] = FormFactory.LINE_GAP_ROWSPEC;
// }
// rowSpec[rowCount * 2] = new RowSpec("20px");
//
// groupPanel.setLayout(new FormLayout(columnSpec, rowSpec));
//fix ʹ�ö����ı�detailText
double size[][] = {
{ 10,150,150,150,10 },
{ 10} };
TableLayout tableLayout=new TableLayout(size);
groupPanel.setLayout(tableLayout);
tableLayout.setVGap(10);
tableLayout.setHGap(10);
//add components to groupPanel
int currentComponentNumber = 1;
Iterator columnIter = getObject().getColumns().iterator();
while (columnIter.hasNext()) {
Column column = (Column)columnIter.next();
if ( (column.isHeadField()) && (column.getGroupName() == groupName) ) {
tableLayout.insertRow(currentComponentNumber,TableLayout.PREFERRED);
//add label
JLabel label = new JLabel(column.toString());
// groupPanel.add(label, cc.xy(3, currentComponentNumber * 2 + 1));
groupPanel.add(label,"1,"+currentComponentNumber+",f,t");
//add component
ComponentExt componentExt = (ComponentExt)headComponentExtIter.next();
JComponent component = componentExt.getComponent();
//specify, for edit action, the primarykey Component is not allowed to modify
if (action.equals("Edit")) {
if ( (column.isPrimaryKey()) && (column.getTableName().equals(object.getMainTableName())) ) {
component.setEnabled(false);
}
}
// groupPanel.add(component, cc.xy(5, currentComponentNumber * 2 + 1));
groupPanel.add(component,"2,"+currentComponentNumber+",f,f");
//add alert label
JLabel alertLabel = new JLabel();
componentExt.setAlertLabel(alertLabel);
alertLabel.setForeground(Color.RED);
if (column.isPrimaryKey()) {
alertLabel.setIcon(ImageManager.getImage(ImageManager.HELP_IMAGE));
} else {
alertLabel.setVisible(false);
}
// groupPanel.add(alertLabel, cc.xy(7, currentComponentNumber * 2 + 1));
groupPanel.add(alertLabel,"3,"+currentComponentNumber+",f,f");
getHeadAlertLabels().add(alertLabel);
headGroups.add(n);
currentComponentNumber++;
}
}
tableLayout.insertRow(currentComponentNumber,10);
//set groupPanel Title & add groupPanel to propertyPane
String groupNameString = "GRP." + new Integer(groupName).toString();
getPropertyPane().addTab(TxtManager.getTxt(groupNameString), groupScrollPane);
n++;
}
}
}
contentPane.add(getPropertyPane(), new GridBagConstraints(0, currentLocation, 1, 1, 0.0, 0.0,
GridBagConstraints.CENTER, GridBagConstraints.BOTH,
new Insets(10, 10, 10, 10), 0, 0));
currentLocation++;
if (getObject().isSlayerMaster()) {
JComponent childText = compFactory.createSeparator(TxtManager.getTxt("VIEW.OBJECTEDIT.ITEMSTITLE"));
contentPane.add(childText, new GridBagConstraints(0, currentLocation, 1, 1, 0.0, 0.0,
GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL,
new Insets(10, 10, 15, 10), 0, 0));
currentLocation++;
//specify,RegClass
if (object instanceof RegClass) {
JPanel regPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT));
regLabel = new JLabel();
setCurrentLAMTTotal();
regPanel.add(regLabel);
contentPane.add(regPanel, new GridBagConstraints(0, currentLocation, 1, 1, 0.0, 0.0,
GridBagConstraints.CENTER, GridBagConstraints.BOTH,
new Insets(0, 0, 0, 5), 0, 0));
currentLocation++;
}
//======== tableScrollPane ========
JScrollPane tableScrollPane = new JScrollPane();
{
tableScrollPane.setPreferredSize(new Dimension(450, 200));
table = new JXTable();
table.setSortable(true);
table.setComponentPopupMenu(tablePopupMenu);
table.setColumnControlVisible(false);
table.setHorizontalScrollEnabled(true);
table.setHighlighters(new HighlighterPipeline(
new Highlighter[]{ AlternateRowHighlighter.genericGrey }));
table.getHighlighters().addHighlighter(
new RolloverHighlighter(Color.BLACK, Color.WHITE ));
table.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
updateTable();
for (int i = 0; i < getTable().getColumnModel().getColumnCount(); i++) {
table.getColumnModel().getColumn(i).setPreferredWidth(100);
}
tableScrollPane.setViewportView(getTable());
table.addMouseListener(getListener());
}
contentPane.add(tableScrollPane, new GridBagConstraints(0, currentLocation, 1, 1, 0.0, 0.0,
GridBagConstraints.CENTER, GridBagConstraints.BOTH,
new Insets(10, 10, 10, 10), 0, 0));
currentLocation++;
}
//======== controlPanel ========
{
controlPanel = new JPanel();
controlPanel.setLayout(new FlowLayout(FlowLayout.RIGHT));
//specify,used by TaxTypeClass
if (object instanceof TaxTypeClass) {
JButton testFormulaButton = new JButton();
testFormulaButton.setText(MnemonicGenerator.generateMnemonicString(TxtManager.getTxt("VIEW.OBJECTEDIT.TAXTYPE.TESTFORMULA"), KeyEvent.VK_T));
testFormulaButton.setMnemonic(KeyEvent.VK_T);
testFormulaButton.setIcon(ImageManager.getImage(ImageManager.TEST_FORMULA_IMAGE));
testFormulaButton.setPreferredSize(new Dimension(150, 20));
testFormulaButton.setActionCommand("Test Formula");
testFormulaButton.addActionListener(getListener());
controlPanel.add(testFormulaButton);
}
//specify,used by CorresponedenceClass
else if (object instanceof CorrespondenceClass) {
JButton saveAndExportButton = new JButton();
saveAndExportButton.setText(MnemonicGenerator.generateMnemonicString(TxtManager.getTxt("VIEW.OBJECTEDIT.PARTNER.SAVEANDEXPORT"), KeyEvent.VK_E));
saveAndExportButton.setMnemonic(KeyEvent.VK_E);
saveAndExportButton.setIcon(ImageManager.getImage(ImageManager.EXPORT_IMAGE));
saveAndExportButton.setPreferredSize(new Dimension(150, 20));
saveAndExportButton.setActionCommand("Save & Export CorrespondenceClass");
saveAndExportButton.addActionListener(getListener());
controlPanel.add(saveAndExportButton);
JButton confirmAndRegButton = new JButton();
confirmAndRegButton.setText(MnemonicGenerator.generateMnemonicString(TxtManager.getTxt("VIEW.OBJECTEDIT.TAXTYPE.CONFIRMANDREG"), KeyEvent.VK_R));
confirmAndRegButton.setMnemonic(KeyEvent.VK_R);
confirmAndRegButton.setIcon(ImageManager.getImage(ImageManager.REG_IMAGE));
confirmAndRegButton.setActionCommand("Confirm & Register CorrespondenceClass");
confirmAndRegButton.setPreferredSize(new Dimension(150, 20));
confirmAndRegButton.addActionListener(getListener());
controlPanel.add(confirmAndRegButton);
}
//specify,used by TaxClass
else if (object instanceof TaxClass) {
JButton confirmAndRegButton = new JButton();
confirmAndRegButton.setText(MnemonicGenerator.generateMnemonicString(TxtManager.getTxt("VIEW.OBJECTEDIT.TAXTYPE.CONFIRMANDREG"), KeyEvent.VK_R));
confirmAndRegButton.setMnemonic(KeyEvent.VK_R);
confirmAndRegButton.setIcon(ImageManager.getImage(ImageManager.REG_IMAGE));
confirmAndRegButton.setPreferredSize(new Dimension(150, 20));
confirmAndRegButton.setActionCommand("Confirm & Register");
confirmAndRegButton.addActionListener(getListener());
controlPanel.add(confirmAndRegButton);
}
//specify,used by PartnerClass
else if (object instanceof PartnerClass) {
if (this.stat.equals("PartnerAdd")) {
} else if ( ( (action.equals("Edit") && (!ObjectUtil.findNewCell(currentRow, "P", "NS").getColumnValue().toString().equals("ME"))) ) || (action.equals("Add")) ) {
JButton saveAndExportButton = new JButton();
saveAndExportButton.setText(MnemonicGenerator.generateMnemonicString(TxtManager.getTxt("VIEW.OBJECTEDIT.PARTNER.SAVEANDEXPORT"), KeyEvent.VK_E));
saveAndExportButton.setMnemonic(KeyEvent.VK_E);
saveAndExportButton.setIcon(ImageManager.getImage(ImageManager.EXPORT_IMAGE));
saveAndExportButton.setPreferredSize(new Dimension(150, 20));
saveAndExportButton.setActionCommand("Save & Export");
saveAndExportButton.addActionListener(getListener());
controlPanel.add(saveAndExportButton);
}
}
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.setPreferredSize(new Dimension(100, 20));
confirmButton.setActionCommand("Modify");
confirmButton.addActionListener(getListener());
controlPanel.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.setPreferredSize(new Dimension(100, 20));
cancelButton.setActionCommand("Cancel");
cancelButton.addActionListener(getListener());
controlPanel.add(cancelButton);
JButton helpButton = new JButton();
helpButton.setText(MnemonicGenerator.generateMnemonicString(TxtManager.getTxt("VIEW.GLOBAL.HELPBUTTON"), KeyEvent.VK_H));
helpButton.setMnemonic(KeyEvent.VK_H);
helpButton.setIcon(ImageManager.getImage(ImageManager.HELP_IMAGE));
helpButton.setPreferredSize(new Dimension(100, 20));
helpButton.setActionCommand("Help");
helpButton.addActionListener(getListener());
controlPanel.add(helpButton);
}
contentPane.add(controlPanel, new GridBagConstraints(0, currentLocation, 1, 1, 0.0, 0.0,
GridBagConstraints.CENTER, GridBagConstraints.BOTH,
new Insets(0, 0, 0, 5), 0, 0));
currentLocation++;
pack();
setResizable(false);
setVisible(true);
setLocationRelativeTo(null);
}
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(getListener());
menuItem.setVisible(false);
notVisibleMenu.add(menuItem);
menuItem = new JMenuItem();
menuItem.setAccelerator(KeyStroke.getKeyStroke("ENTER"));
menuItem.setActionCommand("Modify");
menuItem.addActionListener(getListener());
menuItem.setVisible(false);
notVisibleMenu.add(menuItem);
menuItem = new JMenuItem();
menuItem.setAccelerator(KeyStroke.getKeyStroke("F1"));
menuItem.setActionCommand("Help");
menuItem.addActionListener(getListener());
menuItem.setVisible(false);
notVisibleMenu.add(menuItem);
menuItem = new JMenuItem();
menuItem.setAccelerator(KeyStroke.getKeyStroke("F4"));
menuItem.setActionCommand("DetailList Show Choices");
menuItem.setVisible(false);
menuItem.addActionListener(getListener());
notVisibleMenu.add(menuItem);
if (getObject().isSlayerMaster()) {
menuItem = new JMenuItem();
menuItem.setAccelerator(KeyStroke.getKeyStroke("F5"));
menuItem.setActionCommand("Object Add");
menuItem.addActionListener(getListener());
menuItem.setVisible(false);
notVisibleMenu.add(menuItem);
menuItem = new JMenuItem();
menuItem.setAccelerator(KeyStroke.getKeyStroke("F6"));
menuItem.setActionCommand("Object Edit");
menuItem.addActionListener(getListener());
menuItem.setVisible(false);
notVisibleMenu.add(menuItem);
menuItem = new JMenuItem();
menuItem.setAccelerator(KeyStroke.getKeyStroke("DELETE"));
menuItem.setActionCommand("Object Delete");
menuItem.addActionListener(getListener());
menuItem.setVisible(false);
notVisibleMenu.add(menuItem);
}
setJMenuBar(menuBar);
//fix
KeyUtil.add("ESCAPE",getRootPane(),new AbstractAction(){
public void actionPerformed(ActionEvent e) {
getListener().actionPerformed(new ActionEvent("no src",ActionEvent.ACTION_PERFORMED,"Cancel"));
}
});
KeyUtil.add("F1",getRootPane(),new AbstractAction(){
public void actionPerformed(ActionEvent e) {
getListener().actionPerformed(new ActionEvent("no src",ActionEvent.ACTION_PERFORMED,"Help"));
}
});
KeyUtil.add("F4",getRootPane(),new AbstractAction(){
public void actionPerformed(ActionEvent e) {
getListener().actionPerformed(new ActionEvent("no src",ActionEvent.ACTION_PERFORMED,"DetailList Show Choices"));
}
});
KeyUtil.add("F5",getRootPane(),new AbstractAction(){
public void actionPerformed(ActionEvent e) {
getListener().actionPerformed(new ActionEvent("no src",ActionEvent.ACTION_PERFORMED,"Object Add"));
}
});
KeyUtil.add("F6",getRootPane(),new AbstractAction(){
public void actionPerformed(ActionEvent e) {
getListener().actionPerformed(new ActionEvent("no src",ActionEvent.ACTION_PERFORMED,"Object Edit"));
}
});
KeyUtil.add("DELETE",getRootPane(),new AbstractAction(){
public void actionPerformed(ActionEvent e) {
getListener().actionPerformed(new ActionEvent("no src",ActionEvent.ACTION_PERFORMED,"Object Delete"));
}
});
getRootPane().setDefaultButton(confirmButton);
}
public void updateTable() {
if (object != null) {
table.setEditable(false);
ItemTableModel tableModel = new ItemTableModel(object, currentRow);
table.setModel(tableModel);
if (table.getRowCount() > 0)
table.removeRowSelectionInterval(0, table.getRowCount() - 1);
table.getColumnExt(table.getColumnCount(true) - 1).setVisible(false);
//specify, Used by RegClass
if (object instanceof RegClass)
setCurrentLAMTTotal();
//specify, Used by BudgetClass
else if (object instanceof BudgetClass)
setCurrentBudgetTotal();
} else {
table.setModel(new DefaultTableModel());
}
}
//specify,Used by RegClasss
public double setCurrentLAMTTotal() {
double sum = 0.0;
Iterator rowIter = currentRow.getRowSet().getRows().iterator();
while (rowIter.hasNext()) {
Row row = (Row)rowIter.next();
if (!row.isDelete()) {
Cell cell = ObjectUtil.findNewCell(row, "RI", "LAMT");
if (cell.getColumnValue() != null) {
Number lamt = (Number)cell.getColumnValue();
sum += lamt.doubleValue();
}
}
}
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());
String numberStr = df.format(sum);
String str = null;
if (Math.abs(sum) <= 0.000001) {
sum = 0.0;
str = TxtManager.getTxt("VIEW.OBJECTEDIT.REG.BALANCELABEL") + " = " + 0.0;
} else {
str = "<html>" + TxtManager.getTxt("VIEW.OBJECTEDIT.REG.BALANCELABEL") + " = " +
"<font color=red>" + numberStr + "</font></html>";
}
regLabel.setText(str);
return sum;
}
//specify, Used by BudgetClass
public double setCurrentBudgetTotal() {
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.BUDGET.BUDGETLABEL"));
sb.append(" : ");
Cell cell = ObjectUtil.findNewCell(currentRow, "B", "LAMT");
double budget = 0.0;
if (cell.getColumnValue() != null)
budget = ((Number)cell.getColumnValue()).doubleValue();
sb.append(df.format(budget) + " , ");
sb.append(TxtManager.getTxt("VIEW.OBJECTEDIT.BUDGET.ACTURALLABEL"));
sb.append(" : ");
Double actural = 0.0;
Iterator rowIter = currentRow.getRowSet().getRows().iterator();
while (rowIter.hasNext()) {
Row row = (Row)rowIter.next();
cell = ObjectUtil.findNewCell(row, "BI", "LAMT");
if (cell.getColumnValue() != null) {
Number oneCost = (Number)cell.getColumnValue();
actural += oneCost.doubleValue();
}
}
sb.append(df.format(actural) + " , ");
sb.append(TxtManager.getTxt("VIEW.OBJECTEDIT.BUDGET.REMAINLABEL"));
sb.append(" : ");
double remain = budget - actural;
sb.append(df.format(remain) + " . ");
budgetLabel.setText(sb.toString());
return remain;
}
public MainView getContainer() {
return container;
}
public Vector getHeadComponentExts() {
return headComponentExts;
}
public Vector getHeadAlertLabels() {
return headAlertLabels;
}
public JTabbedPane getPropertyPane() {
return propertyPane;
}
public Row getCurrentRow() {
return currentRow;
}
public BaseClass getObject() {
return object;
}
public JXTable getTable() {
return table;
}
public Vector getItemComponentExts() {
return itemComponentExts;
}
public String getAction() {
return action;
}
public String getType() {
return type;
}
public CIXFile getCixFile() {
return cixFile;
}
public File getFile() {
return file;
}
public Vector getRegs() {
return regs;
}
public Vector getTaxs() {
return taxs;
}
public void setTaxs(Vector taxs) {
this.taxs = taxs;
}
public ObjectEditListener getListener() {
return listener;
}
public RelationManager getRelationManager() {
return relationManager;
}
public Vector getBanks() {
return banks;
}
public void setBanks(Vector banks) {
this.banks = banks;
}
public Vector getHeadGroups() {
return headGroups;
}
public Vector getComponentExts() {
return componentExts;
}
public void setItemComponentExts(Vector itemComponentExts) {
this.itemComponentExts = itemComponentExts;
}
public String getStat() {
return stat;
}
}