1 package ch.ige.edossier.transfer.client;
2
3 import java.util.ArrayList;
4 import java.util.List;
5 import java.awt.*;
6 import java.awt.event.ActionEvent;
7 import java.awt.event.WindowEvent;
8 import javax.swing.*;
9 import javax.swing.table.TableColumn;
10 import ch.ige.edossier.transfer.server.dao.EreignisDAO;
11 import ch.ige.edossier.transfer.vo.EreignisVO;
12 import ch.ige.edossier.web.server.dao.AccountDAO;
13 import ch.ige.edossier.web.vo.AccountVO;
14 import ch.ige.edossier.web.vo.DossierVO;
15
16
17
25 public class TransferFrame extends JFrame
26 {
27 private JPanel contentPane;
28 private BorderLayout borderLayout1 = new BorderLayout();
29 private JTabbedPane tbpInterception = new JTabbedPane();
30 private JPanel pnlInterception = new JPanel();
31 private JPanel pnlAccount = new JPanel();
32 private BorderLayout borderLayout2 = new BorderLayout();
33 private JLabel lblName = new JLabel();
34 private JTextField txfEmail = new JTextField();
35 private JLabel lblEmail = new JLabel();
36 private JPanel pnlData = new JPanel();
37 private JTextField txfName = new JTextField();
38 private JTextField txfTelNr = new JTextField();
39 private GridBagLayout gridBagLayout3 = new GridBagLayout();
40 private JLabel lblTelNr = new JLabel();
41 private JTextField txfPwd = new JTextField();
42 private JLabel lblPwd = new JLabel();
43 private JButton btnSaveAccount = new JButton();
44 private JScrollPane scpInterception = new JScrollPane();
45 private BorderLayout borderLayout3 = new BorderLayout();
46 private JPanel pnlButtons = new JPanel();
47 private JButton btnSelect = new JButton();
48 private GridBagLayout gridBagLayout1 = new GridBagLayout();
49 private JButton btnUnselect = new JButton();
50 private JButton btnSaveInt = new JButton();
51
52 private DtmInterception dtmInterception = new DtmInterception();
54 private JTable tblInterception = new JTable( dtmInterception );
55
56 private DtmAccount dtmAccount = new DtmAccount();
57 private JTable tblAccount = new JTable( dtmAccount );
58 private JScrollPane scpAccount = new JScrollPane();
59 private JComboBox cbxAccount = new JComboBox();
60
61 public TransferFrame()
63 {
64 enableEvents( AWTEvent.WINDOW_EVENT_MASK );
65 try
66 {
67 jbInit();
68 initialWork();
69 }
70 catch( Exception ex )
71 {
72 JOptionPane.showMessageDialog( this, ex.getMessage(), "Fehler bei TransferFrame", JOptionPane.ERROR_MESSAGE );
73 }
74 }
75
76 private void jbInit() throws Exception
78 {
79 contentPane = ( JPanel )this.getContentPane();
80 contentPane.setLayout( borderLayout1 );
81 this.setSize( new Dimension( 527, 361 ) );
82 this.setTitle( "Transfer-Application" );
83 pnlInterception.setLayout( borderLayout3 );
84 pnlAccount.setLayout( borderLayout2 );
85 lblName.setText( "Name:" );
86 lblName.setHorizontalAlignment( SwingConstants.RIGHT );
87 txfEmail.setText( "" );
88 txfEmail.setRequestFocusEnabled( true );
89 txfEmail.setPreferredSize( new Dimension( 200, 20 ) );
90 txfEmail.setMinimumSize( new Dimension( 200, 20 ) );
91 lblEmail.setText( "Email:" );
92 lblEmail.setHorizontalAlignment( SwingConstants.RIGHT );
93 lblEmail.setPreferredSize( new Dimension( 200, 15 ) );
94 pnlData.setLayout( gridBagLayout3 );
95 txfName.setMinimumSize( new Dimension( 200, 20 ) );
96 txfName.setPreferredSize( new Dimension( 200, 20 ) );
97 txfName.setText( "" );
98 txfTelNr.setMinimumSize( new Dimension( 200, 20 ) );
99 txfTelNr.setPreferredSize( new Dimension( 200, 20 ) );
100 txfTelNr.setText( "" );
101 lblTelNr.setHorizontalAlignment( SwingConstants.RIGHT );
102 lblTelNr.setText( "Telefon:" );
103 txfPwd.setMinimumSize( new Dimension( 200, 20 ) );
104 txfPwd.setPreferredSize( new Dimension( 200, 20 ) );
105 txfPwd.setText( "" );
106 lblPwd.setHorizontalAlignment( SwingConstants.RIGHT );
107 lblPwd.setText( "Password:" );
108 btnSaveAccount.setMaximumSize( new Dimension( 101, 30 ) );
109 btnSaveAccount.setMinimumSize( new Dimension( 120, 30 ) );
110 btnSaveAccount.setPreferredSize( new Dimension( 120, 30 ) );
111 btnSaveAccount.setHorizontalAlignment( SwingConstants.CENTER );
112 btnSaveAccount.setHorizontalTextPosition( SwingConstants.RIGHT );
113 btnSaveAccount.setText( "Save Account" );
114 btnSaveAccount.addActionListener( new java.awt.event.ActionListener()
115 {
116 public void actionPerformed( ActionEvent e )
117 {
118 btnSaveAccount_actionPerformed( e );
119 }
120 } );
121 pnlButtons.setLayout( gridBagLayout1 );
122 btnSelect.setMaximumSize( new Dimension( 100, 30 ) );
123 btnSelect.setMinimumSize( new Dimension( 100, 30 ) );
124 btnSelect.setPreferredSize( new Dimension( 100, 30 ) );
125 btnSelect.setText( "Select All" );
126 btnSelect.addActionListener( new java.awt.event.ActionListener()
127 {
128 public void actionPerformed( ActionEvent e )
129 {
130 btnSelect_actionPerformed( e );
131 }
132 } );
133 btnUnselect.setMaximumSize( new Dimension( 89, 23 ) );
134 btnUnselect.setMinimumSize( new Dimension( 100, 30 ) );
135 btnUnselect.setPreferredSize( new Dimension( 100, 30 ) );
136 btnUnselect.setText( "Unselect All" );
137 btnUnselect.addActionListener( new java.awt.event.ActionListener()
138 {
139 public void actionPerformed( ActionEvent e )
140 {
141 btnUnselect_actionPerformed( e );
142 }
143 } );
144 btnSaveInt.setMaximumSize( new Dimension( 100, 30 ) );
145 btnSaveInt.setMinimumSize( new Dimension( 100, 30 ) );
146 btnSaveInt.setPreferredSize( new Dimension( 100, 30 ) );
147 btnSaveInt.setMargin( new Insets( 2, 14, 2, 14 ) );
148 btnSaveInt.setText( "Save" );
149 btnSaveInt.addActionListener( new java.awt.event.ActionListener()
150 {
151 public void actionPerformed( ActionEvent e )
152 {
153 btnSaveInt_actionPerformed( e );
154 }
155 } );
156
157 pnlData.setMinimumSize( new Dimension( 488, 170 ) );
158 pnlData.setPreferredSize( new Dimension( 550, 170 ) );
159 tbpInterception.add( pnlInterception, "Interceptions" );
160 tbpInterception.add( pnlAccount, "Account" );
161
162 pnlAccount.add( pnlData, BorderLayout.NORTH );
163 contentPane.add( tbpInterception, BorderLayout.CENTER );
164 pnlData.add( lblEmail, new GridBagConstraints( 0, 0, 1, 1, 0.0, 0.0
165 , GridBagConstraints.SOUTHEAST, GridBagConstraints.NONE,
166 new Insets( 0, 0, 7, 0 ), 0, 0 ) );
167 pnlData.add( lblPwd, new GridBagConstraints( 0, 1, 1, 1, 0.0, 0.0
168 , GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets( 0, 75, 0, 0 ), 0, 0 ) );
169 pnlData.add( lblName, new GridBagConstraints( 0, 2, 1, 1, 0.0, 0.0
170 , GridBagConstraints.EAST, GridBagConstraints.NONE,
171 new Insets( 0, 0, 0, 0 ), 0, 0 ) );
172 pnlData.add( lblTelNr, new GridBagConstraints( 0, 3, 1, 1, 0.0, 0.0
173 , GridBagConstraints.NORTHEAST, GridBagConstraints.NONE,
174 new Insets( 7, 0, 0, 0 ), 0, 0 ) );
175 pnlData.add( txfEmail, new GridBagConstraints( 1, 0, 3, 1, 0.0, 0.0
176 , GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets( 30, 10, 5, 10 ), 0, 0 ) );
177 pnlData.add( txfPwd, new GridBagConstraints( 1, 1, 3, 1, 0.0, 0.0
178 , GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets( 5, 10, 5, 0 ), 0, 0 ) );
179 pnlData.add( txfName, new GridBagConstraints( 1, 2, 1, 1, 0.0, 0.0
180 , GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets( 5, 10, 5, 0 ), 0, 0 ) );
181 pnlData.add( txfTelNr, new GridBagConstraints( 1, 3, 2, 1, 0.0, 0.0
182 , GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets( 5, 10, 30, 0 ), 0, 0 ) );
183 pnlData.add( btnSaveAccount, new GridBagConstraints( 2, 3, 1, 1, 1.0, 0.0
184 , GridBagConstraints.NORTHEAST, GridBagConstraints.NONE, new Insets( 5, 0, 10, 20 ), 0, 0 ) );
185 pnlButtons.add( btnSelect, new GridBagConstraints( 0, 1, 1, 1, 0.0, 0.0
186 , GridBagConstraints.WEST, GridBagConstraints.NONE,
187 new Insets( 10, 20, 10, 0 ), 0, 0 ) );
188 pnlButtons.add( btnUnselect, new GridBagConstraints( 1, 1, 1, 1, 0.0, 0.0
189 , GridBagConstraints.WEST, GridBagConstraints.NONE,
190 new Insets( 10, 10, 10, 0 ), 0, 0 ) );
191 pnlButtons.add( btnSaveInt, new GridBagConstraints( 2, 1, 1, 1, 1.0, 0.0
192 , GridBagConstraints.EAST, GridBagConstraints.NONE,
193 new Insets( 10, 0, 10, 20 ), 0, 0 ) );
194
195 pnlAccount.add( scpAccount, BorderLayout.CENTER );
196 scpAccount.getViewport().add( tblAccount, null );
197
198 pnlInterception.add( scpInterception, BorderLayout.CENTER );
199 pnlInterception.add( pnlButtons, BorderLayout.SOUTH );
200 scpInterception.getViewport().add( tblInterception, null );
201
202 cbxAccount.setBackground( SystemColor.controlLtHighlight );
203
204 TableColumn tcCheck = tblInterception.getColumnModel().getColumn( 0 );
206 TableColumn accountColumn = tblInterception.getColumnModel().getColumn( 3 );
207 TableColumn voColumn = tblInterception.getColumnModel().getColumn( 4 );
208
209 tblInterception.removeColumn( voColumn );
210 tcCheck.setMaxWidth( 20 );
211 accountColumn.setCellEditor( new DefaultCellEditor( cbxAccount ) );
212 }
213
214
219 private void initialWork()
220 {
221 List alAccountVO = this.readAccounts();
222 dtmAccount.setData( alAccountVO );
223 fillComboBox( alAccountVO );
224
225 readInterceptions();
226 }
227
228
233 private void fillComboBox( List alAccountVO )
234 {
235 AccountVO accountVO = null;
236
237 for( int i = 0; i < alAccountVO.size(); i++ )
238 {
239 accountVO = ( AccountVO )alAccountVO.get( i );
240 cbxAccount.addItem( new ComboBoxObject( String.valueOf( accountVO.getAccountId() ), accountVO.getName() ) );
241 }
242 }
243
244 protected void processWindowEvent( WindowEvent e )
246 {
247 super.processWindowEvent( e );
248 if( e.getID() == WindowEvent.WINDOW_CLOSING )
249 {
250 System.exit( 0 );
251 }
252 }
253
254
258 public void readInterceptions()
259 {
260 try
261 {
262 EreignisDAO ereignisDAO = new EreignisDAO();
263 List listInterceptions = ereignisDAO.selectAllData();
264 dtmInterception.setData( listInterceptions );
265 }
266 catch( Exception ex )
267 {
268 JOptionPane.showMessageDialog( this, ex.getMessage(), "Fehler bei readInterceptions", JOptionPane.ERROR_MESSAGE );
269 }
270 }
271
272
276 public List readAccounts()
277 {
278 List alAccounts = new ArrayList();
279 AccountDAO accountDAO = new AccountDAO();
280
281 try
282 {
283 alAccounts = accountDAO.selectAll();
284 }
285 catch( Exception ex )
286 {
287 JOptionPane.showMessageDialog( this, ex.getMessage(), "Fehler bei readAccounts", JOptionPane.ERROR_MESSAGE );
288 }
289 return alAccounts;
290 }
291
292
296 public void btnSelect_actionPerformed( ActionEvent e )
297 {
298 int row = dtmInterception.getRowCount();
299 for( int i = 0; i < row; i++ )
300 {
301 dtmInterception.setValueAt( new Boolean( true ), i, 0 );
302 }
303 }
304
305
309 public void btnUnselect_actionPerformed( ActionEvent e )
310 {
311 int row = this.dtmInterception.getRowCount();
312 for( int i = 0; i < row; i++ )
313 {
314 dtmInterception.setValueAt( new Boolean( false ), i, 0 );
315 }
316 }
317
318
322 public void btnSaveInt_actionPerformed( ActionEvent e )
323 {
324 List alEreignisVO = new ArrayList();
325 alEreignisVO = dtmInterception.getMarkedData();
326
327 DataDivider dataDivider = new DataDivider();
328 DataInserter dataInserter = new DataInserter();
329 EreignisVO ereignisVO;
330 DossierVO dossierVO;
331
332 for( int i = 0; i < alEreignisVO.size(); i++ )
333 {
334 ereignisVO = ( EreignisVO )alEreignisVO.get( i );
335 dossierVO = dataDivider.divide( ereignisVO );
336 System.out.println( "\nDossierVO\n" + dossierVO.toString() );
337
338 dataInserter.insert( dossierVO );
339 }
340 }
341
342
346 void btnSaveAccount_actionPerformed( ActionEvent e )
347 {
348 AccountDAO accountDAO = new AccountDAO();
349 AccountVO accountVO = getAccountData();
350
351 if( accountVO != null )
352 {
353 try
354 {
355 accountDAO.insert( accountVO );
356 dtmAccount.setData( readAccounts() );
357 }
358 catch( Exception ex )
359 {
360 JOptionPane.showMessageDialog( this, ex.getMessage(), "Fehler bei saveAccount", JOptionPane.ERROR_MESSAGE );
361 }
362 }
363 }
364
365
369 private AccountVO getAccountData()
370 {
371 AccountVO accountVO = null;
372
373 if( !txfName.getText().trim().equals( "" ) &&
374 !txfEmail.getText().trim().equals( "" ) &&
375 !txfPwd.getText().trim().equals( "" ) &&
376 !txfTelNr.getText().trim().equals( "" ) )
377 {
378 accountVO = new AccountVO();
379 accountVO.setName( this.txfName.getText() );
380 accountVO.setEmail( this.txfEmail.getText() );
381 accountVO.setPwd( this.txfPwd.getText() );
382 accountVO.setTelNr( this.txfTelNr.getText() );
383 }
384 else
385 {
386 JOptionPane.showMessageDialog( this, "Alle Felder ausfüllen", "Validierung", JOptionPane.INFORMATION_MESSAGE );
387 }
388
389 return accountVO;
390 }
391 }
392