1 package com.explosion.datastream.exql.gui.table;
2
3 import java.awt.event.MouseAdapter;
4 import java.awt.event.MouseEvent;
5
6 import javax.swing.JOptionPane;
7 import javax.swing.table.JTableHeader;
8 import javax.swing.table.TableColumnModel;
9
10 import org.apache.log4j.LogManager;
11 import org.apache.log4j.Logger;
12
13 import com.explosion.datastream.exql.gui.dbbrowser.DBDataViewer;
14 import com.explosion.expf.Application;
15 import com.explosion.expfmodules.rdbmsconn.dbom.DBEntity;
16 import com.explosion.expfmodules.rdbmsconn.dbom.DBEntityBuffer;
17 import com.explosion.expfmodules.rdbmsconn.dbom.DBEntityColumn;
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39 /***
40 * @author Stephen Cowx
41 * Created on Apr 20, 2004
42 */
43 public class Sort_MouseListener extends MouseAdapter
44 {
45 private static Logger log = LogManager.getLogger(Sort_MouseListener.class);
46 DBEntityBuffer buffer;
47 DBDataViewer view;
48 DBEntity entity = null;
49 private int count = 0;
50
51 public Sort_MouseListener(DBDataViewer view)
52 {
53 log.debug("Sort_MouseListener");
54 this.view = view;
55 }
56
57
58
59 /***
60 * Handle events generated within the table header. Cycles the sorting status
61 * in the DBEntityBuffer
62 * @see java.awt.event.MouseListener#mouseClicked(java.awt.event.MouseEvent)
63 * @param e
64 */
65 public void mouseClicked(MouseEvent e)
66 {
67 count++;
68 if (e.getClickCount() > 1)
69 {
70 JTableHeader h = (JTableHeader) e.getSource();
71 TableColumnModel columnModel = h.getColumnModel();
72 int viewColumn = columnModel.getColumnIndexAtX(e.getX());
73
74 int column = viewColumn;
75
76 String name = columnModel.getColumn(column).getIdentifier().toString();
77 if (column != -1)
78 {
79 DBEntityColumn col = entity.getColumn(name);
80 if (col != null && !col.isSortable())
81 {
82 JOptionPane.showMessageDialog(Application.getApplicationFrame(), "Sorting columns of type "+col.getTypeName()+" is not supported.");
83 return;
84 }
85
86 int status = buffer.getSortDirection(name);
87 if (e.isControlDown())
88 {
89 buffer.removeFromSort(name);
90 }
91
92
93
94
95
96 status = status + (e.isShiftDown() ? -1 : 1);
97 status = (status + 1) % 3 - 1;
98 buffer.setSortingStatus(name, status);
99 view.update();
100 Application.getApplicationFrame().repaint();
101 }
102 }
103 }
104 /***
105 * @return Returns the entity.
106 */
107 public DBEntity getEntity()
108 {
109 return entity;
110 }
111 /***
112 * @param entity The entity to set.
113 */
114 public void setEntity(DBEntity entity)
115 {
116 this.entity = entity;
117 this.buffer = entity.getDBEntityBuffer();
118 }
119 }