01: package jimm.datavision.gui;
02:
03: import jimm.datavision.*;
04: import jimm.datavision.gui.cmd.GroupEditCommand;
05: import jimm.util.I18N;
06: import java.awt.event.*;
07: import java.util.*;
08:
09: /**
10: * This dialog is used for editing report groups.
11: *
12: * @author Jim Menard, <a href="mailto:jimm@io.com">jimm@io.com</a>
13: */
14: public class GroupWin extends TwoListWin {
15:
16: /**
17: * Constructor.
18: *
19: * @param designer the window to which this dialog belongs
20: * @param report the...um...I forgot
21: */
22: public GroupWin(Designer designer, Report report) {
23: super (designer, I18N.get("GroupWin.title"),
24: "GroupChangeCommand.name", "GroupWin.right_box_title",
25: report);
26: }
27:
28: protected void fillListModels() {
29: Iterator iter;
30:
31: // First find and add groups in order.
32: for (iter = report.groups(); iter.hasNext();) {
33: Group group = (Group) iter.next();
34: rightModel.addElement(new GroupWinListItem(group
35: .getSelectable(), group));
36: }
37:
38: // Now iterate through all user cols and columns in tables used by the
39: // report, adding to the left list those that are not already grouped
40: // to the left list.
41: for (iter = report.userColumns(); iter.hasNext();)
42: addToModel((Selectable) iter.next());
43: for (iter = report.getDataSource()
44: .columnsInTablesUsedInReport(); iter.hasNext();)
45: addToModel((Selectable) iter.next());
46: }
47:
48: protected void addToModel(Selectable s) {
49: Group group = report.findGroup(s);
50: if (group == null)
51: leftModel.add(new GroupWinListItem(s, group));
52: }
53:
54: /**
55: * Handles ascending and descending sort order buttons.
56: */
57: public void actionPerformed(ActionEvent e) {
58: String cmd = e.getActionCommand();
59: if (cmd.equals(I18N.get("GUI.ascending")))
60: ((GroupWinListItem) rightList.getSelectedValue()).sortOrder = Group.SORT_ASCENDING;
61: else if (cmd.equals(I18N.get("GUI.descending")))
62: ((GroupWinListItem) rightList.getSelectedValue()).sortOrder = 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,
74: items);
75: cmd.perform();
76: commands.add(cmd);
77: }
78:
79: protected void doRevert() {
80: // Rebuild list models
81: leftModel.removeAllElements();
82: rightModel.removeAllElements();
83: fillListModels();
84: adjustButtons();
85: }
86:
87: }
|