PageRenderTime 48ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/fin_val/src/production/artem/finance/gui/VipiskaSearch.java

http://finval.googlecode.com/
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
  1. package artem.finance.gui;
  2. import artem.finance.gui.db.BeansFactory;
  3. import artem.finance.gui.utils.GuiUtils;
  4. import artem.finance.gui.verifier.DateFormattedTextFieldVerifier;
  5. import artem.finance.server.persist.Bank;
  6. import artem.finance.server.persist.Contract;
  7. import artem.finance.server.persist.Organization;
  8. import artem.finance.server.persist.Schet;
  9. import artem.finance.server.persist.Valuta;
  10. import artem.finance.server.persist.Vipiska;
  11. import artem.finance.server.persist.beans.BankBean;
  12. import artem.finance.server.persist.beans.VipiskaBean;
  13. import javax.swing.JPanel;
  14. import java.awt.ContainerOrderFocusTraversalPolicy;
  15. import java.awt.Dimension;
  16. import javax.swing.JLabel;
  17. import java.awt.Rectangle;
  18. import java.util.ArrayList;
  19. import java.util.List;
  20. import java.util.Properties;
  21. import javax.swing.JButton;
  22. import javax.swing.JDesktopPane;
  23. import javax.swing.JFormattedTextField;
  24. import javax.swing.JInternalFrame;
  25. import javax.swing.JOptionPane;
  26. import javax.swing.JTextField;
  27. import javax.swing.JComboBox;
  28. import javax.swing.JScrollPane;
  29. import javax.swing.JTable;
  30. import javax.swing.ListSelectionModel;
  31. import javax.swing.SwingUtilities;
  32. import javax.swing.table.JTableHeader;
  33. import java.awt.Point;
  34. import java.awt.event.ActionEvent;
  35. import java.awt.event.ActionListener;
  36. import java.awt.event.ItemEvent;
  37. import java.awt.event.ItemListener;
  38. import java.awt.event.MouseEvent;
  39. import java.awt.event.MouseListener;
  40. import java.beans.PropertyVetoException;
  41. import javax.swing.DefaultComboBoxModel;
  42. import javax.swing.JCheckBox;
  43. import java.rmi.RemoteException;
  44. import java.sql.Date;
  45. /**
  46. *
  47. * @author Burtsev Ivan
  48. *
  49. */
  50. public class VipiskaSearch extends JInternalFrame
  51. {
  52. private static final long serialVersionUID = 1L;
  53. private JPanel jContentPane = null;
  54. private JButton searchButton = null;
  55. private JButton cleanButton = null;
  56. private JScrollPane tableScrollPane = null;
  57. private JTable vipiskaTable = null;
  58. private JLabel dateLabel = null;
  59. private JFormattedTextField dateFromFormattedTextField = null;
  60. private JLabel bankLabel = null;
  61. private JComboBox bankComboBox = null;
  62. private BeansFactory factory;
  63. private JLabel countLabel = null;
  64. private JComboBox countComboBox = null;
  65. private JLabel orgLabel = null;
  66. private JComboBox orgComboBox = null;
  67. private JLabel dogovorLabel = null;
  68. private JComboBox dogovorComboBox = null;
  69. private JCheckBox srokCheckBox = null;
  70. private JCheckBox allCheckBox = null;
  71. private JLabel valLabel = null;
  72. private JTextField valTextField = null;
  73. private JLabel dateLabel1 = null;
  74. private JFormattedTextField dateToFormattedTextField = null;
  75. private Vipiska vipiska = null;
  76. private Properties properties;
  77. /**
  78. * This is the default constructor
  79. */
  80. public VipiskaSearch(Properties properties)
  81. {
  82. super("",
  83. false, //resizable
  84. true, //closable
  85. false, //maximizable
  86. true);//iconifiable
  87. this.properties = properties;
  88. factory = BeansFactory.getInstance();
  89. initialize();
  90. }
  91. public Properties getLanguageLabelsProperties()
  92. {
  93. return properties;
  94. }
  95. /**
  96. * This method initializes this
  97. *
  98. * @return void
  99. */
  100. private void initialize()
  101. {
  102. this.setSize(975, 653);
  103. this.setContentPane(getJContentPane());
  104. this.setTitle(properties.getProperty("vipiskaSearchTitle"));
  105. //InternalFrame always becomes focus first.
  106. ContainerOrderFocusTraversalPolicy policy = new ContainerOrderFocusTraversalPolicy();
  107. this.setFocusTraversalPolicy(policy);
  108. }
  109. /**
  110. * This method initializes jContentPane
  111. *
  112. * @return javax.swing.JPanel
  113. */
  114. private JPanel getJContentPane()
  115. {
  116. if (jContentPane == null)
  117. {
  118. dateLabel1 = new JLabel();
  119. dateLabel1.setFocusable(false);
  120. dateLabel1.setBounds(new Rectangle(11, 43, 32, 18));
  121. dateLabel1.setText(properties.getProperty("dateEnd"));
  122. valLabel = new JLabel();
  123. valLabel.setFocusable(false);
  124. valLabel.setBounds(new Rectangle(400, 45, 50, 16));
  125. valLabel.setText(properties.getProperty("currency"));
  126. dogovorLabel = new JLabel();
  127. dogovorLabel.setFocusable(false);
  128. dogovorLabel.setBounds(new Rectangle(510, 45, 50, 16));
  129. dogovorLabel.setText(properties.getProperty("dogovor"));
  130. orgLabel = new JLabel();
  131. orgLabel.setFocusable(false);
  132. orgLabel.setBounds(new Rectangle(400, 15, 80, 16));
  133. orgLabel.setText(properties.getProperty("organization"));
  134. countLabel = new JLabel();
  135. countLabel.setFocusable(false);
  136. countLabel.setBounds(new Rectangle(180, 45, 35, 16));
  137. countLabel.setText(properties.getProperty("count"));
  138. bankLabel = new JLabel();
  139. bankLabel.setFocusable(false);
  140. bankLabel.setBounds(new Rectangle(180, 15, 35, 16));
  141. bankLabel.setText(properties.getProperty("bank"));
  142. dateLabel = new JLabel();
  143. dateLabel.setFocusable(false);
  144. dateLabel.setBounds(new Rectangle(10, 15, 70, 16));
  145. dateLabel.setText(properties.getProperty("dateStart"));
  146. jContentPane = new JPanel();
  147. jContentPane.setLayout(null);
  148. jContentPane.add(getDateFromFormattedTextField(), null);
  149. jContentPane.add(getDateToFormattedTextField(), null);
  150. jContentPane.add(getBankComboBox(), null);
  151. jContentPane.add(getCountComboBox(), null);
  152. jContentPane.add(getOrgComboBox(), null);
  153. jContentPane.add(getDogovorComboBox(), null);
  154. jContentPane.add(getSrokCheckBox(), null);
  155. jContentPane.add(getAllCheckBox(), null);
  156. jContentPane.add(getSearchButton(), null);
  157. jContentPane.add(getCleanButton(), null);
  158. jContentPane.add(getTableScrollPane(), null);
  159. jContentPane.add(dateLabel, null);
  160. jContentPane.add(bankLabel, null);
  161. jContentPane.add(countLabel, null);
  162. jContentPane.add(orgLabel, null);
  163. jContentPane.add(dogovorLabel, null);
  164. jContentPane.add(valLabel, null);
  165. jContentPane.add(getValTextField(), null);
  166. jContentPane.add(dateLabel1, null);
  167. }
  168. return jContentPane;
  169. }
  170. /**
  171. * This method initializes searchButton
  172. *
  173. * @return javax.swing.JButton
  174. */
  175. private JButton getSearchButton()
  176. {
  177. if (searchButton == null)
  178. {
  179. searchButton = new JButton();
  180. searchButton.setPreferredSize(new Dimension(120, 25)); // Generated
  181. searchButton.setLocation(new Point(835, 11)); // Generated
  182. searchButton.setSize(new Dimension(120, 25)); // Generated
  183. searchButton.setText(properties.getProperty("find")); // Generated
  184. searchButton.addActionListener(new SearchListener());
  185. }
  186. return searchButton;
  187. }
  188. /**
  189. * This method initializes cleanButton
  190. *
  191. * @return javax.swing.JButton
  192. */
  193. private JButton getCleanButton() {
  194. if (cleanButton == null) {
  195. cleanButton = new JButton();
  196. cleanButton.setPreferredSize(new Dimension(120, 25)); // Generated
  197. cleanButton.setLocation(new Point(835, 40)); // Generated
  198. cleanButton.setSize(new Dimension(120, 25)); // Generated
  199. cleanButton.setText(properties.getProperty("clear")); // Generated
  200. cleanButton.addActionListener(new ActionListener(){
  201. @Override
  202. public void actionPerformed(ActionEvent e) {
  203. clear();
  204. }
  205. });
  206. }
  207. return cleanButton;
  208. }
  209. private void clear()
  210. {
  211. GuiUtils.clear(getJContentPane());
  212. refreshTheDateFormattedFields();
  213. vipiska = null;
  214. //Clear table model by setting an empty list.
  215. List<Object> vipiski = new ArrayList<Object>();
  216. ((VipiskaTableModel)getVipiskaTable().getModel()).setDataSourceFromVipiskaAL(vipiski);
  217. }
  218. class SearchListener implements ActionListener{
  219. @Override
  220. public void actionPerformed(ActionEvent e)
  221. {
  222. vipiska = new Vipiska();
  223. Date dateFrom = null;
  224. Date dateTo = null;
  225. boolean shouldFindAll = false;
  226. boolean wasSet = false;
  227. if( !"".equals(getDateToFormattedTextField().getText())
  228. && getDateToFormattedTextField().getText() != null
  229. && !getDateToFormattedTextField().getText().contains("_") )
  230. {
  231. dateTo = GuiUtils.getDateFromFTF( getDateToFormattedTextField() );
  232. wasSet = true;
  233. }
  234. if( !"".equals(getDateFromFormattedTextField().getText())
  235. && getDateFromFormattedTextField().getText() != null
  236. && !getDateFromFormattedTextField().getText().contains("_") )
  237. {
  238. dateFrom = GuiUtils.getDateFromFTF( getDateFromFormattedTextField() );
  239. wasSet = true;
  240. }
  241. if( getOrgComboBox().getSelectedIndex() > 0 )
  242. {
  243. vipiska.setOrganization((Organization)getOrgComboBox().getSelectedItem());
  244. wasSet = true;
  245. }
  246. if( getBankComboBox().getSelectedIndex() > 0 )
  247. {
  248. vipiska.setBank( (Bank)getBankComboBox().getSelectedItem() );
  249. wasSet = true;
  250. }
  251. if( getCountComboBox().getSelectedIndex() > 0 )
  252. {
  253. vipiska.setSchet( (Schet)getCountComboBox().getSelectedItem() );
  254. wasSet = true;
  255. }
  256. if( getDogovorComboBox().getSelectedIndex() > 0 )
  257. {
  258. vipiska.setContract( (Contract)getDogovorComboBox().getSelectedItem() );
  259. wasSet = true;
  260. }
  261. if( getSrokCheckBox().isSelected() )
  262. {
  263. vipiska.setSrok( getSrokCheckBox().isSelected() );
  264. wasSet = true;
  265. }
  266. if( getAllCheckBox().isSelected() )
  267. {
  268. shouldFindAll = true;
  269. //wasSet = true;
  270. }
  271. if(wasSet || shouldFindAll)
  272. {
  273. final boolean shouldFindAllForThread = shouldFindAll;
  274. final Date dateFromForThread = dateFrom;
  275. final Date dateToForThread = dateTo;
  276. SwingUtilities.invokeLater( new Runnable()
  277. {
  278. public void run()
  279. {
  280. try
  281. {
  282. List<Object> vipiski = factory.getVipiskaServiceSLSB().findByExample( new VipiskaBean(vipiska), dateFromForThread, dateToForThread, shouldFindAllForThread );
  283. ((VipiskaTableModel)getVipiskaTable().getModel()).setDataSourceFromVipiskaAL(vipiski);
  284. vipiska = null;
  285. }
  286. catch (RemoteException e1)
  287. {
  288. e1.printStackTrace();
  289. JOptionPane.showMessageDialog(null, "Can not find any document, because of remote problems.");
  290. }
  291. }
  292. });
  293. wasSet = false;
  294. }
  295. }
  296. }
  297. /**
  298. * This method initializes tableScrollPane
  299. *
  300. * @return javax.swing.JScrollPane
  301. */
  302. private JScrollPane getTableScrollPane()
  303. {
  304. if (tableScrollPane == null)
  305. {
  306. tableScrollPane = new JScrollPane();
  307. tableScrollPane.setBounds(new Rectangle(10, 78, 945, 535)); // Generated
  308. tableScrollPane.setViewportView(getVipiskaTable());
  309. }
  310. return tableScrollPane;
  311. }
  312. /**
  313. * This method initializes vipiskaTable
  314. *
  315. * @return javax.swing.JTable
  316. */
  317. private JTable getVipiskaTable()
  318. {
  319. if (vipiskaTable == null)
  320. {
  321. VipiskaTableModel dtmodel = new VipiskaTableModel(true);
  322. List<Object> vipiski = new ArrayList<Object>();
  323. dtmodel.setDataSourceFromVipiskaAL(vipiski);
  324. vipiskaTable = new JTable(dtmodel);
  325. vipiskaTable.setRowHeight(102);
  326. //dogTable.setColumnSelectionAllowed(true);
  327. VipiskaTableCellRenderer vipiskaRenderer = new VipiskaTableCellRenderer();
  328. vipiskaRenderer.setProperties(properties);
  329. vipiskaTable.getColumnModel().getColumn(0).setCellRenderer(vipiskaRenderer);
  330. vipiskaTable.getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
  331. VipiskaCellEditor vipiskaEditor = new VipiskaCellEditor();
  332. vipiskaTable.getColumnModel().getColumn(0).setCellEditor(vipiskaEditor);
  333. vipiskaTable.addMouseListener(new MouseListener()
  334. {
  335. @Override
  336. public void mouseClicked(MouseEvent me)
  337. {
  338. if(me.getClickCount() == 2)
  339. {
  340. Vipiska vipiska = (Vipiska)vipiskaTable.getModel()
  341. .getValueAt(vipiskaTable.getSelectedRow(), 0);
  342. VipiskaInput frameVipiskaInput = FinanceCurrencyFrame.getFrameVipiskaInput();
  343. frameVipiskaInput.setSelectedVipiska( vipiska );
  344. JDesktopPane desktop = FinanceCurrencyFrame.getDesktpPane();
  345. if (frameVipiskaInput.isClosed())
  346. {
  347. try{
  348. desktop.add(frameVipiskaInput);
  349. }catch(IllegalArgumentException ie)
  350. {
  351. JOptionPane.showMessageDialog(null, "This vipiska is already opened.");
  352. }
  353. }
  354. else
  355. {
  356. if (frameVipiskaInput.isIcon())
  357. try
  358. {
  359. frameVipiskaInput.setIcon(false);
  360. }
  361. catch (PropertyVetoException e2)
  362. {
  363. e2.printStackTrace();
  364. }
  365. if ( !frameVipiskaInput.isSelected() )
  366. try
  367. {
  368. frameVipiskaInput.setSelected(true);
  369. }
  370. catch (PropertyVetoException e1)
  371. {
  372. e1.printStackTrace();
  373. }
  374. }
  375. frameVipiskaInput.setVisible(true);
  376. }
  377. }
  378. @Override
  379. public void mouseEntered(MouseEvent arg0){}
  380. @Override
  381. public void mouseExited(MouseEvent arg0){}
  382. @Override
  383. public void mousePressed(MouseEvent arg0){}
  384. @Override
  385. public void mouseReleased(MouseEvent arg0){}
  386. });
  387. //setting specific tables header
  388. VipiskaHeaderRenderer hrenderer = new VipiskaHeaderRenderer();
  389. hrenderer.setProperties(properties);
  390. JTableHeader theader = vipiskaTable.getTableHeader();//new JTableHeader();
  391. theader.setDefaultRenderer(hrenderer);
  392. vipiskaTable.setTableHeader(theader);
  393. }
  394. return vipiskaTable;
  395. }
  396. /**
  397. * This method initializes dateFromFormattedTextField
  398. *
  399. * @return javax.swing.JFormattedTextField
  400. */
  401. private JFormattedTextField getDateFromFormattedTextField()
  402. {
  403. if (dateFromFormattedTextField == null)
  404. {
  405. dateFromFormattedTextField = new JFormattedTextField(GuiUtils.getMformatter());
  406. dateFromFormattedTextField.setColumns(10);
  407. dateFromFormattedTextField.setInputVerifier( new DateFormattedTextFieldVerifier() );
  408. dateFromFormattedTextField.setBounds(new Rectangle(90, 10, 71, 23));
  409. }
  410. return dateFromFormattedTextField;
  411. }
  412. /**
  413. * This method initializes dateToFormattedTextField
  414. *
  415. * @return javax.swing.JFormattedTextField
  416. */
  417. private JFormattedTextField getDateToFormattedTextField()
  418. {
  419. if (dateToFormattedTextField == null)
  420. {
  421. dateToFormattedTextField = new JFormattedTextField(GuiUtils.getMformatter());
  422. dateToFormattedTextField.setColumns(10);
  423. dateToFormattedTextField.setInputVerifier( new DateFormattedTextFieldVerifier() );
  424. dateToFormattedTextField.setBounds(new Rectangle(90, 39, 71, 22));
  425. }
  426. return dateToFormattedTextField;
  427. }
  428. /**
  429. * This method initializes bankComboBox
  430. *
  431. * @return javax.swing.JComboBox
  432. */
  433. private JComboBox getBankComboBox()
  434. {
  435. if (bankComboBox == null)
  436. {
  437. bankComboBox = GuiUtils.createBankComboBox(factory, bankComboBox, new Rectangle(220, 10, 160, 20));
  438. bankComboBox.addItemListener( new ItemListener(){
  439. @Override
  440. public void itemStateChanged( ItemEvent e )
  441. {
  442. if( e.getStateChange() == ItemEvent.SELECTED )
  443. {
  444. //Without this if ClassCastException appears during auto searching
  445. if( !(e.getItem() instanceof Bank ))
  446. {
  447. return;
  448. }
  449. Bank item = ( Bank )e.getItem();
  450. try {
  451. if(item.getId() != null)
  452. {
  453. //List contains Schet objects for given bank.
  454. List<Object> beans = factory.getSchetServiceSLSB().findAllCountsForBank( new BankBean(item) );
  455. beans.add( 0, new Schet() );
  456. Object[] countsWithFirstEmptyValue = beans.toArray();
  457. DefaultComboBoxModel model = new DefaultComboBoxModel( countsWithFirstEmptyValue );
  458. countComboBox.setModel( model );
  459. getCountComboBox().setEnabled( true );
  460. }
  461. else{
  462. getCountComboBox().setModel(new DefaultComboBoxModel(new Object[0]));
  463. getCountComboBox().setEnabled( false );
  464. }
  465. getValTextField().setText( "" );
  466. } catch (RemoteException e1) {
  467. JOptionPane.showMessageDialog(null, "Can not get counts for selected bank from the database.");
  468. e1.printStackTrace();
  469. }
  470. }
  471. }
  472. });
  473. }
  474. return bankComboBox;
  475. }
  476. /**
  477. * This method initializes countComboBox
  478. *
  479. * @return javax.swing.JComboBox
  480. */
  481. private JComboBox getCountComboBox()
  482. {
  483. if (countComboBox == null)
  484. {
  485. countComboBox = new JComboBox();
  486. countComboBox.setBounds(new Rectangle(219, 41, 171, 20));
  487. countComboBox.setEnabled( false );
  488. countComboBox.setFocusable(true);
  489. GuiUtils.makeComboBoxAutoSearchible(countComboBox, GuiUtils.getCountCellRenderer());
  490. countComboBox.addItemListener( new ItemListener(){
  491. @Override
  492. public void itemStateChanged( ItemEvent e )
  493. {
  494. if( e.getStateChange() == ItemEvent.SELECTED )
  495. {
  496. //Without this if ClassCastException appears during auto searching
  497. if( !(e.getItem() instanceof Schet ))
  498. {
  499. return;
  500. }
  501. Schet item = ( Schet )e.getItem();
  502. if( item.getValuta() != null )
  503. {
  504. getValTextField().setText( item.getValuta().getName() );
  505. }
  506. else
  507. {
  508. getValTextField().setText( "" );
  509. }
  510. if( item.getBank() != null )
  511. {
  512. //Change lead selected bank
  513. getBankComboBox().setSelectedItem( item.getBank() );
  514. }
  515. else
  516. {
  517. getBankComboBox().setSelectedIndex( 0 );
  518. }
  519. }
  520. }
  521. });
  522. }
  523. return countComboBox;
  524. }
  525. /**
  526. * This method initializes orgComboBox
  527. *
  528. * @return javax.swing.JComboBox
  529. */
  530. private JComboBox getOrgComboBox()
  531. {
  532. if (orgComboBox == null)
  533. {
  534. orgComboBox = GuiUtils.createOrganizationComboBox(factory, new Rectangle(500, 10, 192, 20));
  535. }
  536. return orgComboBox;
  537. }
  538. /**
  539. * This method initializes dogovorComboBox
  540. *
  541. * @return javax.swing.JComboBox
  542. */
  543. private JComboBox getDogovorComboBox()
  544. {
  545. if (dogovorComboBox == null)
  546. {
  547. dogovorComboBox = GuiUtils.createContractComboBox(factory, dogovorComboBox, new Rectangle(569, 41, 210, 20));
  548. }
  549. return dogovorComboBox;
  550. }
  551. /**
  552. * This method initializes srokCheckBox
  553. *
  554. * @return javax.swing.JCheckBox
  555. */
  556. private JCheckBox getSrokCheckBox()
  557. {
  558. if (srokCheckBox == null)
  559. {
  560. srokCheckBox = new JCheckBox();
  561. srokCheckBox.setBounds(new Rectangle(699, 7, 121, 24));
  562. srokCheckBox.setText(properties.getProperty("period90"));
  563. }
  564. return srokCheckBox;
  565. }
  566. /**
  567. * This method initializes allCheckBox
  568. *
  569. * @return javax.swing.JCheckBox
  570. */
  571. private JCheckBox getAllCheckBox()
  572. {
  573. if (allCheckBox == null)
  574. {
  575. allCheckBox = new JCheckBox();
  576. allCheckBox.setBounds(new Rectangle(785, 37, 50, 24));
  577. allCheckBox.setText("???");//properties.getProperty("getAll"));
  578. }
  579. return allCheckBox;
  580. }
  581. /**
  582. * This method initializes valTextField
  583. *
  584. * @return javax.swing.JTextField
  585. */
  586. private JTextField getValTextField()
  587. {
  588. if (valTextField == null)
  589. {
  590. valTextField = new JTextField();
  591. valTextField.setBounds(new Rectangle(454, 41, 46, 20));
  592. valTextField.setEditable(false);
  593. valTextField.setFocusable(false);
  594. //Show currency of selected account.
  595. if(getCountComboBox().getSelectedItem() != null )
  596. {
  597. Valuta currency = ((Schet)getCountComboBox().getSelectedItem()).getValuta();
  598. if( currency != null )
  599. {
  600. valTextField.setText( currency.toString() );
  601. }
  602. }
  603. if( getCountComboBox().getSelectedIndex() == 0 )
  604. {
  605. valTextField.setText( "" );
  606. }
  607. }
  608. return valTextField;
  609. }
  610. @Override
  611. public void doDefaultCloseAction()
  612. {
  613. super.doDefaultCloseAction();
  614. clear();
  615. }
  616. /**
  617. * Refreshes the XXXDateFormattedTextFields with default values.
  618. */
  619. public void refreshTheDateFormattedFields()
  620. {
  621. getDateToFormattedTextField().setValue(null);
  622. getDateFromFormattedTextField().setValue(null);
  623. }
  624. }