01: /*
02: * Beryl - A web platform based on XML, XSLT and Java
03: * This file is part of the Beryl XML GUI
04: *
05: * Copyright (C) 2004 Wenzel Jakob <wazlaf@tigris.org>
06: *
07: * This program is free software; you can redistribute it and/or
08: * modify it under the terms of the GNU Lesser General Public
09: * License as published by the Free Software Foundation; either
10: * version 2.1 of the License, or (at your option) any later version.
11:
12: * This program is distributed in the hope that it will be useful,
13: * but WITHOUT ANY WARRANTY; without even the implied warranty of
14: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15: * Lesser General Public License for more details.
16: *
17: * You should have received a copy of the GNU Lesser General Public
18: * License along with this program; if not, write to the Free Software
19: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-3107 USA
20: */
21:
22: package org.beryl.gui.builder;
23:
24: import org.beryl.gui.Controller;
25: import org.beryl.gui.GUIEvent;
26: import org.beryl.gui.GUIException;
27: import org.beryl.gui.MessageDialog;
28: import org.beryl.gui.model.MapDataModel;
29: import org.beryl.gui.model.ModelChangeEvent;
30: import org.beryl.gui.model.ModelChangeListener;
31: import org.beryl.gui.model.TableRow;
32: import org.beryl.gui.widgets.Button;
33: import org.beryl.gui.widgets.Dialog;
34: import org.beryl.gui.widgets.Frame;
35: import org.beryl.gui.widgets.Table;
36: import org.w3c.dom.Element;
37:
38: public class EventDialog extends Controller {
39: private WidgetTree tree = null;
40: private WidgetUserObject object = null;
41: private Button deleteButton = null;
42: private Dialog dialog = null;
43: private MapDataModel dataModel = null;
44:
45: public EventDialog(WidgetTree tree, Frame frame,
46: WidgetUserObject object) throws GUIException {
47: this .tree = tree;
48: this .object = object;
49:
50: dataModel = new MapDataModel();
51: dialog = (Dialog) constructDialog("EventDialog", dataModel);
52: deleteButton = (Button) dialog.getWidget("DeleteButton");
53:
54: ((Table) dialog.getWidget("EventTable"))
55: .setTableDataModel(object.eventModel);
56:
57: dataModel.setValue("event", new TableRow[] {});
58:
59: dataModel.addModelChangeListener(new ModelChangeListener() {
60: public void modelChanged(ModelChangeEvent e)
61: throws GUIException {
62: deleteButton.setEnabled(((TableRow[]) dataModel
63: .getValue("event")).length > 0);
64: }
65: });
66: dialog.initDialog(frame);
67: dialog.show();
68: }
69:
70: public void eventOccured(GUIEvent event) {
71: try {
72: String name = event.getName();
73:
74: if (name.equals("close")) {
75: dialog.dispose();
76: } else if (name.equals("add")) {
77: new AddEventDialog(tree, dialog, object);
78: } else if (name.equals("delete")) {
79: TableRow rows[] = (TableRow[]) dataModel
80: .getValue("event");
81:
82: for (int i = 0; i < rows.length; i++) {
83: object.eventModel.removeRow(rows[i]);
84:
85: Element element = (Element) rows[i]
86: .getValue("node");
87: element.getParentNode().removeChild(element);
88:
89: Builder.markModified();
90: }
91: }
92: } catch (GUIException e) {
93: new MessageDialog(e);
94: }
95: }
96: }
|