001: /*
002: * Beryl - A web platform based on XML, XSLT and Java
003: * This file is part of the Beryl XML GUI
004: *
005: * Copyright (C) 2004 Wenzel Jakob <wazlaf@tigris.org>
006: *
007: * This program is free software; you can redistribute it and/or
008: * modify it under the terms of the GNU Lesser General Public
009: * License as published by the Free Software Foundation; either
010: * version 2.1 of the License, or (at your option) any later version.
011:
012: * This program is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015: * Lesser General Public License for more details.
016: *
017: * You should have received a copy of the GNU Lesser General Public
018: * License along with this program; if not, write to the Free Software
019: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-3107 USA
020: */
021:
022: package org.beryl.gui.builder;
023:
024: import java.util.List;
025:
026: import org.beryl.gui.Controller;
027: import org.beryl.gui.GUIEvent;
028: import org.beryl.gui.GUIException;
029: import org.beryl.gui.MessageDialog;
030: import org.beryl.gui.WidgetInfo;
031: import org.beryl.gui.WidgetInfo.EventEntry;
032: import org.beryl.gui.model.ListDataModel;
033: import org.beryl.gui.model.MapDataModel;
034: import org.beryl.gui.model.ModelChangeEvent;
035: import org.beryl.gui.model.ModelChangeListener;
036: import org.beryl.gui.model.TableRow;
037: import org.beryl.gui.widgets.Button;
038: import org.beryl.gui.widgets.ComboBox;
039: import org.beryl.gui.widgets.Dialog;
040: import org.w3c.dom.Element;
041:
042: public class AddEventDialog extends Controller {
043: private WidgetTree tree = null;
044: private Dialog dialog = null;
045: private MapDataModel dataModel = null;
046: private WidgetUserObject object = null;
047:
048: public AddEventDialog(WidgetTree tree, Dialog parent,
049: WidgetUserObject object) throws GUIException {
050: this .tree = tree;
051: this .object = object;
052:
053: dataModel = new MapDataModel();
054: dialog = constructDialog("AddEventDialog", dataModel);
055: final Button okButton = (Button) dialog.getWidget("OKButton");
056:
057: dataModel.addModelChangeListener(new ModelChangeListener() {
058: public void modelChanged(ModelChangeEvent e)
059: throws GUIException {
060: okButton.setEnabled(dataModel.getValue("event") != null
061: && dataModel.getValue("name") != null
062: && !((String) dataModel.getValue("name"))
063: .trim().equals(""));
064: }
065: });
066:
067: ListDataModel events = new ListDataModel();
068: List list = object.widget.getWidgetInfo().getEventEntries();
069:
070: for (int i = 0; i < list.size(); i++) {
071: events.addValue(list.get(i));
072: }
073:
074: ((ComboBox) dialog.getWidget("EventCombo"))
075: .setListDataModel(events);
076:
077: if (list.size() > 0) {
078: dataModel.setValue("event", list.get(0));
079: }
080:
081: dialog.initDialog(parent);
082: dialog.show();
083: }
084:
085: public void eventOccured(GUIEvent e) {
086: String eventName = e.getName();
087:
088: try {
089: if (eventName.equals("cancel")) {
090: dialog.dispose();
091: } else if (eventName.equals("ok")) {
092: WidgetInfo.EventEntry event = (EventEntry) dataModel
093: .getValue("event");
094: String name = (String) dataModel.getValue("name");
095:
096: Element emitNode = object.element.getOwnerDocument()
097: .createElement("emit");
098:
099: emitNode.setAttribute("event", event.eventName);
100: emitNode.setAttribute("name", name);
101:
102: object.element.appendChild(emitNode);
103:
104: TableRow row = new TableRow();
105: row.setValue("event", event.eventName);
106: row.setValue("name", name);
107: row.setValue("description", event.getDescription());
108: row.setValue("node", emitNode);
109:
110: object.eventModel.addRow(row);
111:
112: Builder.markModified();
113:
114: dialog.dispose();
115: }
116: } catch (Exception ex) {
117: new MessageDialog(ex);
118: }
119: }
120: }
|