Source code: cor/gui/evt/JspmEvtListPanel.java
1 /*-----------------------------------------------------------------------------------------------------*/
2 /* */
3 /* Copyright (C) */
4 /* */
5 /* This program is free software; you can redistribute it and/or modify it under the terms of the GNU */
6 /* General Public License as published by the Free Software Foundation; either version 2 of the */
7 /* License, or (at your option) any later version. */
8 /* */
9 /* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; */
10 /* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR */
11 /* PURPOSE. See the GNU General Public License for more details. */
12 /* */
13 /* You should have received a copy of the GNU General Public License along with this program; if */
14 /* not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA */
15 /* 02111-1307 USA */
16 /* */
17 /*-----------------------------------------------------------------------------------------------------*/
18 /* $Author: strand01 $ $Revision: 1.5 $ $Date: 2001/12/20 14:23:02 $ */
19 /*-----------------------------------------------------------------------------------------------------*/
20
21 package cor.gui.evt;
22
23 // Java classes
24 import java.awt.*;
25 import java.awt.event.*;
26 import java.util.*;
27
28 // Swing classes
29 import javax.swing.JTable;
30 import javax.swing.JLabel;
31 import javax.swing.JPanel;
32 import javax.swing.JScrollPane;
33 import javax.swing.tree.DefaultMutableTreeNode;
34 import javax.swing.table.DefaultTableModel;
35 import javax.swing.border.BevelBorder;
36
37 // Jspm classes
38 import com.jdk.*;
39 import cor.gui.*;
40
41 /**
42 * Event management list panel
43 *
44 * This panel is divided into two parts. The upper part shows the message records from the JSPM event
45 * management database table and the lower part the actions corresponding to a selected message in the
46 * upper table.
47 *
48 * By selecting a row in either lists a dialog box will be displayed in which the user can change the
49 * values for the selected message or action.
50 *
51 * @author Steve Randall (strand012001@yahoo.com)
52 * @version 0.0.11
53 * @date 31/10/2001
54 */
55 public class JspmEvtListPanel extends JPanel implements MouseListener
56 {
57 /**
58 * Jspm Core database connection.
59 */
60 private JspmCoreDb jspmCoreDb = null;
61
62 /**
63 * Message table
64 */
65 private JTable msgTable;
66
67 /**
68 * Action table
69 */
70 private JTable actTable;
71
72 /**
73 * Message table model
74 */
75 private DefaultTableModel msgTableModel = null;
76
77 /**
78 * Action table model
79 */
80 private DefaultTableModel actTableModel = null;
81
82 /**
83 * Table panel
84 */
85 private JspmVSplitPane msgSplitPanel = null;
86
87 /**
88 * Table font
89 */
90 private Font font = new Font("Ariel", Font.PLAIN, 11);
91
92 /**
93 * Constructor
94 */
95 public JspmEvtListPanel( JspmCore jspmCore )
96 {
97 jspmCoreDb = jspmCore.getDbConnection();
98
99 setLayout(new BorderLayout());
100 setPreferredSize( new Dimension( 700, JspmConstants.JGE.maxY ) );
101
102 JspmVSplitPane splitPane = new JspmVSplitPane( createMessagePanel(), createActionPanel() );
103 add( splitPane );
104 }
105
106 /**
107 * Creates the message list
108 */
109 private JPanel createMessagePanel()
110 {
111 JspmTableCellRenderer tableRenderer = null;
112
113 final String[] names = { "MsgID", "Token", "Owner", "Source", "Node" };
114 final Object[][] data = {};
115
116 // Create a model of the data.
117 msgTableModel = new DefaultTableModel(data, (Object[])names) {
118
119 // All cells are not editable
120 public boolean isCellEditable(int row, int col) {
121 return false;
122 }
123 };
124
125 msgTable = new JTable( msgTableModel);
126 msgTable.setFont( font );
127 msgTable.addMouseListener( this );
128
129 tableRenderer = new JspmTableCellRenderer( 5, font );
130 tableRenderer.setHorizontalAlignment(JLabel.RIGHT);
131 msgTable.setDefaultRenderer( msgTable.getColumnClass(0), tableRenderer );
132
133 JScrollPane msgTablePanel = new JScrollPane( msgTable );
134 msgTablePanel.setMinimumSize( new Dimension(700, 200) );
135
136 JPanel msgMainPanel = new JPanel();
137 msgMainPanel.setLayout( new BorderLayout() );
138
139 JLabel label = new JLabel( " Messages:" );
140
141 msgMainPanel.add( label, BorderLayout.NORTH );
142 msgMainPanel.add( msgTablePanel, BorderLayout.CENTER );
143
144 return msgMainPanel;
145 }
146
147 /**
148 * Creates the action list
149 */
150 private JPanel createActionPanel()
151 {
152 JspmTableCellRenderer tableRenderer = null;
153
154 final String[] names = { "ActID", "MsgID", "Sequence", "Command", "Source", "Node" };
155 final Object[][] data = {};
156
157 // Create a model of the data.
158 actTableModel = new DefaultTableModel( data, (Object[])names) {
159
160 // All cells are not editable
161 public boolean isCellEditable(int row, int col) {
162 return false;
163 }
164 };
165
166 actTable = new JTable(actTableModel);
167 actTable.setFont(new Font("Ariel", Font.PLAIN, 11));
168 actTable.addMouseListener( this );
169
170 tableRenderer = new JspmTableCellRenderer( 6, font );
171 tableRenderer.setHorizontalAlignment(JLabel.RIGHT);
172
173 actTable.setDefaultRenderer(actTable.getColumnClass(0), tableRenderer);
174
175 JScrollPane actTablePanel = new JScrollPane( actTable );
176 actTablePanel.setMinimumSize( new Dimension(700, 200) );
177
178 JPanel actMainPanel = new JPanel();
179 actMainPanel.setLayout( new BorderLayout() );
180
181 JLabel label = new JLabel( " Actions:" );
182
183 actMainPanel.add( label, BorderLayout.NORTH );
184 actMainPanel.add( actTablePanel, BorderLayout.CENTER );
185
186 return actMainPanel;
187 }
188
189 /**
190 * Clears the message table
191 */
192 private void clearMessageTable()
193 {
194 int rows = 0;
195
196 if((rows = msgTableModel.getRowCount()) > 0) {
197 for(int i = 0; i < rows; i++)
198 msgTableModel.removeRow(0);
199 }
200 }
201
202 /**
203 * Clears the action table
204 */
205 private void clearActionTable()
206 {
207 int rows = 0;
208
209 if((rows = actTableModel.getRowCount()) > 0) {
210 for(int i = 0; i < rows; i++)
211 actTableModel.removeRow(0);
212 }
213 }
214
215 /**
216 * Adds a row to the object info table
217 */
218 public void addMessages( Vector messages )
219 {
220 for( int i = 0; i < messages.size(); i++ ) {
221 Object row[] = new Object[5];
222 row[0] = ( ( Hashtable ) messages.elementAt(i) ).get( "msgid" );
223 row[1] = ( ( Hashtable ) messages.elementAt(i) ).get( "token" );
224 row[2] = ( ( Hashtable ) messages.elementAt(i) ).get( "owner" );
225 row[3] = ( ( Hashtable ) messages.elementAt(i) ).get( "source" );
226 row[4] = ( ( Hashtable ) messages.elementAt(i) ).get( "node" );
227 msgTableModel.addRow((Object[]) row);
228 }
229 }
230
231 /**
232 * Adds a row to the object info table
233 */
234 public void addActions( Vector actions )
235 {
236 Vector actionDef = jspmCoreDb.getActionDefinitions();
237
238 for( int i = 0; i < actions.size(); i++ ) {
239
240 Object row[] = new Object[6];
241
242 row[0] = ( ( Hashtable ) actions.elementAt(i) ).get( "actid" );
243 row[1] = ( ( Hashtable ) actions.elementAt(i) ).get( "msgid" );
244 row[2] = ( ( Hashtable ) actions.elementAt(i) ).get( "sequence" );
245 int actcmd = ( (Integer) ( ( Hashtable ) actions.elementAt(i) ).get( "actcmd" ) ).intValue();
246 row[3] = ( ( (String) ( (Hashtable)actionDef.elementAt( actcmd - 1) ).get( "name" ) ) );
247 row[4] = ( ( Hashtable ) actions.elementAt(i) ).get( "source" );
248 row[5] = ( ( Hashtable ) actions.elementAt(i) ).get( "node" );
249
250 actTableModel.addRow((Object[]) row);
251
252 }
253 }
254
255 /**
256 * Removes all objects from the table.
257 */
258 public void removeAllObjects() {
259
260 clearMessageTable();
261 clearActionTable();
262
263 }
264
265 /**
266 * Process single/double click mouse events.
267 *
268 * This method will process single and double clicks on one of the rows in either the message
269 * or the action table. The processing is as follows:
270 *
271 * - single click on message table will display the actions belonging to this message
272 * in the action list.
273 * - double click on a message table row will display the message dialog box.
274 * - single click on a action in the action list won't do anything.
275 * - double click on a action in the action list will just select (hilite) the corresponding
276 * action.
277 *
278 * @param event (MouseEvent) mouse event.
279 */
280 public void mouseClicked( MouseEvent event )
281 {
282 if( event.getClickCount() == 1 && event.getComponent() == msgTable ) {
283
284 clearActionTable();
285 int row = msgTable.getSelectedRow();
286 int msgid = ((Integer)msgTableModel.getValueAt( row, 0 )).intValue();
287 addActions( jspmCoreDb.getActions( msgid ) );
288
289 } else if( event.getClickCount() == 2 && event.getComponent() == msgTable ) {
290
291 int row = msgTable.getSelectedRow();
292 Integer imsgid = (Integer)msgTableModel.getValueAt( row, 0 );
293 int msgid = imsgid.intValue();
294
295 JspmEvtMessageDialog msgDialog = new JspmEvtMessageDialog( msgid, jspmCoreDb );
296
297 } else if( event.getClickCount() == 2 && event.getComponent() == actTable ) {
298
299 int row = actTable.getSelectedRow();
300 int actid = ((Integer)actTableModel.getValueAt( row, 0 )).intValue();
301
302 JspmEvtActionDialog actDialog = new JspmEvtActionDialog( actid, jspmCoreDb );
303
304 }
305 }
306
307 /**
308 * Process mouse pressed events.
309 *
310 * Nothing has to be done here.
311 *
312 * @param event (MouseEvent) mouse event.
313 */
314 public void mousePressed( MouseEvent event )
315 {
316 }
317
318 /**
319 * Process mouse released events.
320 *
321 * Nothing has to be done here.
322 *
323 * @param event (MouseEvent) mouse event.
324 */
325 public void mouseReleased( MouseEvent event )
326 {
327 }
328
329 /**
330 * Process mouse entered events.
331 *
332 * Nothing has to be done here.
333 *
334 * @param event (MouseEvent) mouse event.
335 */
336 public void mouseEntered( MouseEvent event )
337 {
338 }
339
340 /**
341 * Process mouse exited events.
342 *
343 * Nothing has to be done here.
344 *
345 * @param event (MouseEvent) mouse event.
346 */
347 public void mouseExited( MouseEvent event )
348 {
349 }
350 }
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365