KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > jimm > datavision > gui > SortWin


1 package jimm.datavision.gui;
2 import jimm.datavision.Report;
3 import jimm.datavision.UserColumn;
4 import jimm.datavision.Selectable;
5 import jimm.datavision.source.*;
6 import jimm.datavision.gui.cmd.SortEditCommand;
7 import jimm.util.I18N;
8 import java.awt.event.*;
9 import java.util.*;
10
11 /**
12  * This dialog is used for editing the report query's list of sort
13  * orders.
14  *
15  * @author Jim Menard, <a HREF="mailto:jimm@io.com">jimm@io.com</a>
16  */

17 public class SortWin extends TwoListWin {
18
19 protected Query query;
20
21 /**
22  * Constructor.
23  *
24  * @param designer the window to which this dialog belongs
25  * @param report the...um...I forgot
26  */

27 public SortWin(Designer designer, Report report) {
28     super(designer, I18N.get("SortWin.title"), "SortChangeCommand.name",
29       "SortWin.right_box_title", report);
30 }
31
32 /**
33  * Fills the unsorted and sorted columns lists. Excludes colums that are
34  * used in report groups.
35  */

36 protected void fillListModels() {
37     // Since this method is called from within our superclass ctor, before
38
// the query gets initialized, we have to grab it here.
39
DataSource ds = report.getDataSource();
40     query = ds.getQuery();
41
42     // Add user cols used in report that are not used by a group.
43
Iterator iter;
44     for (iter = report.userColumns(); iter.hasNext(); ) {
45     UserColumn uc = (UserColumn)iter.next();
46     if (!report.isUsedBySomeGroup(uc)) // Ignore group user groups
47
addToModel(uc);
48     }
49
50     // Add columns used in report that are not used by a group.
51
for (iter = ds.columnsInTablesUsedInReport(); iter.hasNext(); ) {
52     Column col = (Column)iter.next();
53     if (!report.isUsedBySomeGroup(col)) // Ignore group columns
54
addToModel(col);
55     }
56 }
57
58 protected void addToModel(Selectable g) {
59     int order = query.sortOrderOf(g);
60     SortWinListItem item = new SortWinListItem(g, order);
61     if (order == Query.SORT_UNDEFINED)
62     leftModel.add(item);
63     else
64     rightModel.addElement(item);
65 }
66
67 /**
68  * Handles ascending and descending sort order buttons.
69  */

70 public void actionPerformed(ActionEvent e) {
71     String JavaDoc cmd = e.getActionCommand();
72     if (cmd.equals(I18N.get("GUI.ascending")))
73     ((SortWinListItem)rightList.getSelectedValue()).sortOrder = 'a';
74     else if (cmd.equals(I18N.get("GUI.descending")))
75     ((SortWinListItem)rightList.getSelectedValue()).sortOrder = 'd';
76     else
77     super.actionPerformed(e);
78 }
79
80 protected void doSave() {
81     // Turn the model's vector into a collection
82
ArrayList items = new ArrayList();
83     for (Enumeration e = rightModel.elements(); e.hasMoreElements(); )
84     items.add(e.nextElement());
85
86     SortEditCommand cmd = new SortEditCommand(query, items);
87     cmd.perform();
88     commands.add(cmd);
89 }
90
91 protected void doRevert() {
92     // Rebuild list models
93
leftModel.removeAllElements();
94     rightModel.removeAllElements();
95     fillListModels();
96     adjustButtons();
97 }
98
99 }
100
Popular Tags