KickJava   Java API By Example, From Geeks To Geeks.

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


1 package jimm.datavision.gui;
2 import jimm.datavision.*;
3 import jimm.datavision.gui.cmd.GroupEditCommand;
4 import jimm.util.I18N;
5 import java.awt.event.*;
6 import java.util.*;
7
8 /**
9  * This dialog is used for editing report groups.
10  *
11  * @author Jim Menard, <a HREF="mailto:jimm@io.com">jimm@io.com</a>
12  */

13 public class GroupWin extends TwoListWin {
14
15 /**
16  * Constructor.
17  *
18  * @param designer the window to which this dialog belongs
19  * @param report the...um...I forgot
20  */

21 public GroupWin(Designer designer, Report report) {
22     super(designer, I18N.get("GroupWin.title"), "GroupChangeCommand.name",
23       "GroupWin.right_box_title", report);
24 }
25
26 protected void fillListModels() {
27     Iterator iter;
28
29     // First find and add groups in order.
30
for (iter = report.groups(); iter.hasNext(); ) {
31     Group group = (Group)iter.next();
32     rightModel.addElement(new GroupWinListItem(group.getSelectable(),
33                            group));
34     }
35
36     // Now iterate through all user cols and columns in tables used by the
37
// report, adding to the left list those that are not already grouped
38
// to the left list.
39
for (iter = report.userColumns(); iter.hasNext(); )
40     addToModel((Selectable)iter.next());
41     for (iter = report.getDataSource().columnsInTablesUsedInReport();
42      iter.hasNext(); )
43     addToModel((Selectable)iter.next());
44 }
45
46 protected void addToModel(Selectable s) {
47     Group group = report.findGroup(s);
48     if (group == null)
49     leftModel.add(new GroupWinListItem(s, group));
50 }
51
52 /**
53  * Handles ascending and descending sort order buttons.
54  */

55 public void actionPerformed(ActionEvent e) {
56     String JavaDoc cmd = e.getActionCommand();
57     if (cmd.equals(I18N.get("GUI.ascending")))
58     ((GroupWinListItem)rightList.getSelectedValue()).sortOrder =
59         Group.SORT_ASCENDING;
60     else if (cmd.equals(I18N.get("GUI.descending")))
61     ((GroupWinListItem)rightList.getSelectedValue()).sortOrder =
62         Group.SORT_DESCENDING;
63     else
64     super.actionPerformed(e);
65 }
66
67 protected void doSave() {
68     // Turn the model's vector into a collection
69
ArrayList items = new ArrayList();
70     for (Enumeration e = rightModel.elements(); e.hasMoreElements(); )
71     items.add(e.nextElement());
72
73     GroupEditCommand cmd = new GroupEditCommand(report, designer, items);
74     cmd.perform();
75     commands.add(cmd);
76 }
77
78 protected void doRevert() {
79     // Rebuild list models
80
leftModel.removeAllElements();
81     rightModel.removeAllElements();
82     fillListModels();
83     adjustButtons();
84 }
85
86 }
87
Popular Tags