/fin_val/src/production/artem/finance/gui/VipiskaSearch.java
Java | 718 lines | 528 code | 94 blank | 96 comment | 67 complexity | 5a9492246b4b8c1a85172ff06fd94927 MD5 | raw file
Possible License(s): MPL-2.0-no-copyleft-exception, IPL-1.0, Apache-2.0, LGPL-2.1, LGPL-2.0, BSD-3-Clause
- package artem.finance.gui;
-
- import artem.finance.gui.db.BeansFactory;
- import artem.finance.gui.utils.GuiUtils;
- import artem.finance.gui.verifier.DateFormattedTextFieldVerifier;
- import artem.finance.server.persist.Bank;
- import artem.finance.server.persist.Contract;
- import artem.finance.server.persist.Organization;
- import artem.finance.server.persist.Schet;
- import artem.finance.server.persist.Valuta;
- import artem.finance.server.persist.Vipiska;
- import artem.finance.server.persist.beans.BankBean;
- import artem.finance.server.persist.beans.VipiskaBean;
-
- import javax.swing.JPanel;
-
- import java.awt.ContainerOrderFocusTraversalPolicy;
- import java.awt.Dimension;
- import javax.swing.JLabel;
- import java.awt.Rectangle;
- import java.util.ArrayList;
- import java.util.List;
- import java.util.Properties;
-
- import javax.swing.JButton;
- import javax.swing.JDesktopPane;
- import javax.swing.JFormattedTextField;
- import javax.swing.JInternalFrame;
- import javax.swing.JOptionPane;
- import javax.swing.JTextField;
- import javax.swing.JComboBox;
- import javax.swing.JScrollPane;
- import javax.swing.JTable;
- import javax.swing.ListSelectionModel;
- import javax.swing.SwingUtilities;
- import javax.swing.table.JTableHeader;
-
- import java.awt.Point;
- import java.awt.event.ActionEvent;
- import java.awt.event.ActionListener;
- import java.awt.event.ItemEvent;
- import java.awt.event.ItemListener;
- import java.awt.event.MouseEvent;
- import java.awt.event.MouseListener;
- import java.beans.PropertyVetoException;
-
- import javax.swing.DefaultComboBoxModel;
- import javax.swing.JCheckBox;
- import java.rmi.RemoteException;
- import java.sql.Date;
-
- /**
- *
- * @author Burtsev Ivan
- *
- */
- public class VipiskaSearch extends JInternalFrame
- {
-
- private static final long serialVersionUID = 1L;
- private JPanel jContentPane = null;
- private JButton searchButton = null;
- private JButton cleanButton = null;
- private JScrollPane tableScrollPane = null;
- private JTable vipiskaTable = null;
- private JLabel dateLabel = null;
- private JFormattedTextField dateFromFormattedTextField = null;
- private JLabel bankLabel = null;
- private JComboBox bankComboBox = null;
- private BeansFactory factory;
- private JLabel countLabel = null;
- private JComboBox countComboBox = null;
- private JLabel orgLabel = null;
- private JComboBox orgComboBox = null;
- private JLabel dogovorLabel = null;
- private JComboBox dogovorComboBox = null;
- private JCheckBox srokCheckBox = null;
- private JCheckBox allCheckBox = null;
- private JLabel valLabel = null;
- private JTextField valTextField = null;
- private JLabel dateLabel1 = null;
- private JFormattedTextField dateToFormattedTextField = null;
- private Vipiska vipiska = null;
- private Properties properties;
-
- /**
- * This is the default constructor
- */
- public VipiskaSearch(Properties properties)
- {
- super("",
- false, //resizable
- true, //closable
- false, //maximizable
- true);//iconifiable
- this.properties = properties;
- factory = BeansFactory.getInstance();
- initialize();
- }
-
- public Properties getLanguageLabelsProperties()
- {
- return properties;
- }
- /**
- * This method initializes this
- *
- * @return void
- */
- private void initialize()
- {
- this.setSize(975, 653);
- this.setContentPane(getJContentPane());
- this.setTitle(properties.getProperty("vipiskaSearchTitle"));
-
- //InternalFrame always becomes focus first.
- ContainerOrderFocusTraversalPolicy policy = new ContainerOrderFocusTraversalPolicy();
- this.setFocusTraversalPolicy(policy);
-
- }
-
- /**
- * This method initializes jContentPane
- *
- * @return javax.swing.JPanel
- */
- private JPanel getJContentPane()
- {
- if (jContentPane == null)
- {
-
- dateLabel1 = new JLabel();
- dateLabel1.setFocusable(false);
- dateLabel1.setBounds(new Rectangle(11, 43, 32, 18));
- dateLabel1.setText(properties.getProperty("dateEnd"));
- valLabel = new JLabel();
- valLabel.setFocusable(false);
- valLabel.setBounds(new Rectangle(400, 45, 50, 16));
- valLabel.setText(properties.getProperty("currency"));
- dogovorLabel = new JLabel();
- dogovorLabel.setFocusable(false);
- dogovorLabel.setBounds(new Rectangle(510, 45, 50, 16));
- dogovorLabel.setText(properties.getProperty("dogovor"));
- orgLabel = new JLabel();
- orgLabel.setFocusable(false);
- orgLabel.setBounds(new Rectangle(400, 15, 80, 16));
- orgLabel.setText(properties.getProperty("organization"));
- countLabel = new JLabel();
- countLabel.setFocusable(false);
- countLabel.setBounds(new Rectangle(180, 45, 35, 16));
- countLabel.setText(properties.getProperty("count"));
- bankLabel = new JLabel();
- bankLabel.setFocusable(false);
- bankLabel.setBounds(new Rectangle(180, 15, 35, 16));
- bankLabel.setText(properties.getProperty("bank"));
- dateLabel = new JLabel();
- dateLabel.setFocusable(false);
- dateLabel.setBounds(new Rectangle(10, 15, 70, 16));
- dateLabel.setText(properties.getProperty("dateStart"));
- jContentPane = new JPanel();
-
- jContentPane.setLayout(null);
-
- jContentPane.add(getDateFromFormattedTextField(), null);
- jContentPane.add(getDateToFormattedTextField(), null);
- jContentPane.add(getBankComboBox(), null);
- jContentPane.add(getCountComboBox(), null);
- jContentPane.add(getOrgComboBox(), null);
- jContentPane.add(getDogovorComboBox(), null);
- jContentPane.add(getSrokCheckBox(), null);
- jContentPane.add(getAllCheckBox(), null);
-
- jContentPane.add(getSearchButton(), null);
- jContentPane.add(getCleanButton(), null);
-
- jContentPane.add(getTableScrollPane(), null);
-
- jContentPane.add(dateLabel, null);
- jContentPane.add(bankLabel, null);
- jContentPane.add(countLabel, null);
- jContentPane.add(orgLabel, null);
- jContentPane.add(dogovorLabel, null);
- jContentPane.add(valLabel, null);
- jContentPane.add(getValTextField(), null);
- jContentPane.add(dateLabel1, null);
- }
- return jContentPane;
- }
-
- /**
- * This method initializes searchButton
- *
- * @return javax.swing.JButton
- */
- private JButton getSearchButton()
- {
- if (searchButton == null)
- {
- searchButton = new JButton();
- searchButton.setPreferredSize(new Dimension(120, 25)); // Generated
- searchButton.setLocation(new Point(835, 11)); // Generated
- searchButton.setSize(new Dimension(120, 25)); // Generated
- searchButton.setText(properties.getProperty("find")); // Generated
-
- searchButton.addActionListener(new SearchListener());
- }
- return searchButton;
- }
-
- /**
- * This method initializes cleanButton
- *
- * @return javax.swing.JButton
- */
- private JButton getCleanButton() {
- if (cleanButton == null) {
- cleanButton = new JButton();
- cleanButton.setPreferredSize(new Dimension(120, 25)); // Generated
- cleanButton.setLocation(new Point(835, 40)); // Generated
- cleanButton.setSize(new Dimension(120, 25)); // Generated
- cleanButton.setText(properties.getProperty("clear")); // Generated
-
- cleanButton.addActionListener(new ActionListener(){
-
- @Override
- public void actionPerformed(ActionEvent e) {
- clear();
- }
-
- });
- }
- return cleanButton;
- }
-
- private void clear()
- {
- GuiUtils.clear(getJContentPane());
- refreshTheDateFormattedFields();
-
- vipiska = null;
- //Clear table model by setting an empty list.
- List<Object> vipiski = new ArrayList<Object>();
- ((VipiskaTableModel)getVipiskaTable().getModel()).setDataSourceFromVipiskaAL(vipiski);
- }
-
- class SearchListener implements ActionListener{
- @Override
- public void actionPerformed(ActionEvent e)
- {
-
- vipiska = new Vipiska();
-
- Date dateFrom = null;
- Date dateTo = null;
- boolean shouldFindAll = false;
-
- boolean wasSet = false;
-
- if( !"".equals(getDateToFormattedTextField().getText())
- && getDateToFormattedTextField().getText() != null
- && !getDateToFormattedTextField().getText().contains("_") )
- {
- dateTo = GuiUtils.getDateFromFTF( getDateToFormattedTextField() );
- wasSet = true;
- }
-
- if( !"".equals(getDateFromFormattedTextField().getText())
- && getDateFromFormattedTextField().getText() != null
- && !getDateFromFormattedTextField().getText().contains("_") )
- {
- dateFrom = GuiUtils.getDateFromFTF( getDateFromFormattedTextField() );
- wasSet = true;
- }
-
- if( getOrgComboBox().getSelectedIndex() > 0 )
- {
- vipiska.setOrganization((Organization)getOrgComboBox().getSelectedItem());
- wasSet = true;
- }
-
- if( getBankComboBox().getSelectedIndex() > 0 )
- {
- vipiska.setBank( (Bank)getBankComboBox().getSelectedItem() );
- wasSet = true;
- }
-
- if( getCountComboBox().getSelectedIndex() > 0 )
- {
- vipiska.setSchet( (Schet)getCountComboBox().getSelectedItem() );
- wasSet = true;
- }
-
- if( getDogovorComboBox().getSelectedIndex() > 0 )
- {
- vipiska.setContract( (Contract)getDogovorComboBox().getSelectedItem() );
- wasSet = true;
- }
-
- if( getSrokCheckBox().isSelected() )
- {
- vipiska.setSrok( getSrokCheckBox().isSelected() );
- wasSet = true;
- }
-
- if( getAllCheckBox().isSelected() )
- {
- shouldFindAll = true;
- //wasSet = true;
- }
-
- if(wasSet || shouldFindAll)
- {
- final boolean shouldFindAllForThread = shouldFindAll;
- final Date dateFromForThread = dateFrom;
- final Date dateToForThread = dateTo;
-
- SwingUtilities.invokeLater( new Runnable()
- {
- public void run()
- {
- try
- {
- List<Object> vipiski = factory.getVipiskaServiceSLSB().findByExample( new VipiskaBean(vipiska), dateFromForThread, dateToForThread, shouldFindAllForThread );
-
- ((VipiskaTableModel)getVipiskaTable().getModel()).setDataSourceFromVipiskaAL(vipiski);
- vipiska = null;
- }
- catch (RemoteException e1)
- {
- e1.printStackTrace();
- JOptionPane.showMessageDialog(null, "Can not find any document, because of remote problems.");
- }
- }
- });
-
- wasSet = false;
- }
- }
- }
-
- /**
- * This method initializes tableScrollPane
- *
- * @return javax.swing.JScrollPane
- */
- private JScrollPane getTableScrollPane()
- {
- if (tableScrollPane == null)
- {
- tableScrollPane = new JScrollPane();
- tableScrollPane.setBounds(new Rectangle(10, 78, 945, 535)); // Generated
- tableScrollPane.setViewportView(getVipiskaTable());
- }
- return tableScrollPane;
- }
-
- /**
- * This method initializes vipiskaTable
- *
- * @return javax.swing.JTable
- */
- private JTable getVipiskaTable()
- {
- if (vipiskaTable == null)
- {
- VipiskaTableModel dtmodel = new VipiskaTableModel(true);
-
- List<Object> vipiski = new ArrayList<Object>();
-
- dtmodel.setDataSourceFromVipiskaAL(vipiski);
-
- vipiskaTable = new JTable(dtmodel);
- vipiskaTable.setRowHeight(102);
- //dogTable.setColumnSelectionAllowed(true);
-
-
- VipiskaTableCellRenderer vipiskaRenderer = new VipiskaTableCellRenderer();
- vipiskaRenderer.setProperties(properties);
- vipiskaTable.getColumnModel().getColumn(0).setCellRenderer(vipiskaRenderer);
-
- vipiskaTable.getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
-
- VipiskaCellEditor vipiskaEditor = new VipiskaCellEditor();
- vipiskaTable.getColumnModel().getColumn(0).setCellEditor(vipiskaEditor);
-
- vipiskaTable.addMouseListener(new MouseListener()
- {
-
- @Override
- public void mouseClicked(MouseEvent me)
- {
- if(me.getClickCount() == 2)
- {
- Vipiska vipiska = (Vipiska)vipiskaTable.getModel()
- .getValueAt(vipiskaTable.getSelectedRow(), 0);
-
- VipiskaInput frameVipiskaInput = FinanceCurrencyFrame.getFrameVipiskaInput();
- frameVipiskaInput.setSelectedVipiska( vipiska );
-
- JDesktopPane desktop = FinanceCurrencyFrame.getDesktpPane();
-
- if (frameVipiskaInput.isClosed())
- {
- try{
- desktop.add(frameVipiskaInput);
- }catch(IllegalArgumentException ie)
- {
- JOptionPane.showMessageDialog(null, "This vipiska is already opened.");
- }
- }
- else
- {
- if (frameVipiskaInput.isIcon())
- try
- {
- frameVipiskaInput.setIcon(false);
- }
- catch (PropertyVetoException e2)
- {
- e2.printStackTrace();
- }
- if ( !frameVipiskaInput.isSelected() )
- try
- {
- frameVipiskaInput.setSelected(true);
- }
- catch (PropertyVetoException e1)
- {
- e1.printStackTrace();
- }
- }
-
- frameVipiskaInput.setVisible(true);
-
- }
- }
-
- @Override
- public void mouseEntered(MouseEvent arg0){}
-
- @Override
- public void mouseExited(MouseEvent arg0){}
-
- @Override
- public void mousePressed(MouseEvent arg0){}
-
- @Override
- public void mouseReleased(MouseEvent arg0){}
- });
-
- //setting specific tables header
- VipiskaHeaderRenderer hrenderer = new VipiskaHeaderRenderer();
- hrenderer.setProperties(properties);
- JTableHeader theader = vipiskaTable.getTableHeader();//new JTableHeader();
- theader.setDefaultRenderer(hrenderer);
- vipiskaTable.setTableHeader(theader);
- }
- return vipiskaTable;
- }
-
- /**
- * This method initializes dateFromFormattedTextField
- *
- * @return javax.swing.JFormattedTextField
- */
- private JFormattedTextField getDateFromFormattedTextField()
- {
-
- if (dateFromFormattedTextField == null)
- {
- dateFromFormattedTextField = new JFormattedTextField(GuiUtils.getMformatter());
- dateFromFormattedTextField.setColumns(10);
- dateFromFormattedTextField.setInputVerifier( new DateFormattedTextFieldVerifier() );
- dateFromFormattedTextField.setBounds(new Rectangle(90, 10, 71, 23));
- }
-
- return dateFromFormattedTextField;
- }
-
- /**
- * This method initializes dateToFormattedTextField
- *
- * @return javax.swing.JFormattedTextField
- */
- private JFormattedTextField getDateToFormattedTextField()
- {
-
- if (dateToFormattedTextField == null)
- {
- dateToFormattedTextField = new JFormattedTextField(GuiUtils.getMformatter());
- dateToFormattedTextField.setColumns(10);
- dateToFormattedTextField.setInputVerifier( new DateFormattedTextFieldVerifier() );
- dateToFormattedTextField.setBounds(new Rectangle(90, 39, 71, 22));
- }
-
- return dateToFormattedTextField;
- }
-
- /**
- * This method initializes bankComboBox
- *
- * @return javax.swing.JComboBox
- */
- private JComboBox getBankComboBox()
- {
- if (bankComboBox == null)
- {
- bankComboBox = GuiUtils.createBankComboBox(factory, bankComboBox, new Rectangle(220, 10, 160, 20));
-
- bankComboBox.addItemListener( new ItemListener(){
-
- @Override
- public void itemStateChanged( ItemEvent e )
- {
- if( e.getStateChange() == ItemEvent.SELECTED )
- {
- //Without this if ClassCastException appears during auto searching
- if( !(e.getItem() instanceof Bank ))
- {
- return;
- }
-
- Bank item = ( Bank )e.getItem();
-
- try {
- if(item.getId() != null)
- {
- //List contains Schet objects for given bank.
- List<Object> beans = factory.getSchetServiceSLSB().findAllCountsForBank( new BankBean(item) );
-
- beans.add( 0, new Schet() );
-
- Object[] countsWithFirstEmptyValue = beans.toArray();
- DefaultComboBoxModel model = new DefaultComboBoxModel( countsWithFirstEmptyValue );
- countComboBox.setModel( model );
-
- getCountComboBox().setEnabled( true );
- }
- else{
- getCountComboBox().setModel(new DefaultComboBoxModel(new Object[0]));
- getCountComboBox().setEnabled( false );
- }
- getValTextField().setText( "" );
- } catch (RemoteException e1) {
- JOptionPane.showMessageDialog(null, "Can not get counts for selected bank from the database.");
- e1.printStackTrace();
- }
- }
- }
-
- });
- }
- return bankComboBox;
- }
-
- /**
- * This method initializes countComboBox
- *
- * @return javax.swing.JComboBox
- */
- private JComboBox getCountComboBox()
- {
- if (countComboBox == null)
- {
- countComboBox = new JComboBox();
- countComboBox.setBounds(new Rectangle(219, 41, 171, 20));
- countComboBox.setEnabled( false );
- countComboBox.setFocusable(true);
-
- GuiUtils.makeComboBoxAutoSearchible(countComboBox, GuiUtils.getCountCellRenderer());
-
- countComboBox.addItemListener( new ItemListener(){
-
- @Override
- public void itemStateChanged( ItemEvent e )
- {
- if( e.getStateChange() == ItemEvent.SELECTED )
- {
- //Without this if ClassCastException appears during auto searching
- if( !(e.getItem() instanceof Schet ))
- {
- return;
- }
- Schet item = ( Schet )e.getItem();
- if( item.getValuta() != null )
- {
- getValTextField().setText( item.getValuta().getName() );
-
- }
- else
- {
- getValTextField().setText( "" );
- }
- if( item.getBank() != null )
- {
- //Change lead selected bank
- getBankComboBox().setSelectedItem( item.getBank() );
- }
- else
- {
- getBankComboBox().setSelectedIndex( 0 );
- }
- }
- }
-
- });
- }
- return countComboBox;
- }
-
- /**
- * This method initializes orgComboBox
- *
- * @return javax.swing.JComboBox
- */
- private JComboBox getOrgComboBox()
- {
- if (orgComboBox == null)
- {
- orgComboBox = GuiUtils.createOrganizationComboBox(factory, new Rectangle(500, 10, 192, 20));
- }
- return orgComboBox;
- }
-
- /**
- * This method initializes dogovorComboBox
- *
- * @return javax.swing.JComboBox
- */
- private JComboBox getDogovorComboBox()
- {
- if (dogovorComboBox == null)
- {
- dogovorComboBox = GuiUtils.createContractComboBox(factory, dogovorComboBox, new Rectangle(569, 41, 210, 20));
- }
- return dogovorComboBox;
- }
-
- /**
- * This method initializes srokCheckBox
- *
- * @return javax.swing.JCheckBox
- */
- private JCheckBox getSrokCheckBox()
- {
- if (srokCheckBox == null)
- {
- srokCheckBox = new JCheckBox();
- srokCheckBox.setBounds(new Rectangle(699, 7, 121, 24));
- srokCheckBox.setText(properties.getProperty("period90"));
- }
- return srokCheckBox;
- }
-
- /**
- * This method initializes allCheckBox
- *
- * @return javax.swing.JCheckBox
- */
- private JCheckBox getAllCheckBox()
- {
- if (allCheckBox == null)
- {
- allCheckBox = new JCheckBox();
- allCheckBox.setBounds(new Rectangle(785, 37, 50, 24));
- allCheckBox.setText("???");//properties.getProperty("getAll"));
- }
- return allCheckBox;
- }
-
- /**
- * This method initializes valTextField
- *
- * @return javax.swing.JTextField
- */
- private JTextField getValTextField()
- {
- if (valTextField == null)
- {
- valTextField = new JTextField();
- valTextField.setBounds(new Rectangle(454, 41, 46, 20));
- valTextField.setEditable(false);
- valTextField.setFocusable(false);
-
- //Show currency of selected account.
- if(getCountComboBox().getSelectedItem() != null )
- {
- Valuta currency = ((Schet)getCountComboBox().getSelectedItem()).getValuta();
- if( currency != null )
- {
- valTextField.setText( currency.toString() );
- }
- }
- if( getCountComboBox().getSelectedIndex() == 0 )
- {
- valTextField.setText( "" );
- }
-
- }
- return valTextField;
- }
-
- @Override
- public void doDefaultCloseAction()
- {
- super.doDefaultCloseAction();
- clear();
- }
-
- /**
- * Refreshes the XXXDateFormattedTextFields with default values.
- */
- public void refreshTheDateFormattedFields()
- {
- getDateToFormattedTextField().setValue(null);
- getDateFromFormattedTextField().setValue(null);
- }
- }