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 java.util.Iterator;
25:
26: import org.beryl.gui.Controller;
27: import org.beryl.gui.GUIEvent;
28: import org.beryl.gui.GUIException;
29: import org.beryl.gui.MessageDialog;
30: import org.beryl.gui.WidgetInfo;
31: import org.beryl.gui.model.ListDataModel;
32: import org.beryl.gui.model.MapDataModel;
33: import org.beryl.gui.widgets.Button;
34: import org.beryl.gui.widgets.ComboBox;
35: import org.beryl.gui.widgets.Dialog;
36: import org.w3c.dom.Element;
37:
38: public class InsertDialog extends Controller {
39: private Dialog dialog = null;
40: private WidgetTree tree = null;
41: private Element anchorElement = null;
42: private MapDataModel dataModel = null;
43: private String className = null;
44: private String nonePreset = new String("none");
45:
46: public InsertDialog(WidgetTree tree, String className,
47: WidgetInfo info, Element anchorElement) throws GUIException {
48: this .tree = tree;
49: this .className = className;
50: this .anchorElement = anchorElement;
51:
52: dataModel = new MapDataModel();
53: dataModel.setValue("preset", nonePreset);
54: dataModel.setValue("widget", className);
55:
56: ListDataModel presetModel = new ListDataModel();
57: presetModel.addValue(nonePreset);
58:
59: for (Iterator i = info.getPresetEntries().iterator(); i
60: .hasNext();) {
61: presetModel.addValue(i.next());
62: }
63:
64: dialog = constructDialog("InsertDialog", dataModel);
65: ((ComboBox) dialog.getWidget("PresetBox"))
66: .setListDataModel(presetModel);
67: ((Button) dialog.getWidget("AnchorButton")).setEnabled(info
68: .getSupportsAnchor());
69: dialog.initDialog(tree.getFrame());
70: dialog.show();
71: }
72:
73: public void eventOccured(GUIEvent event) {
74: String name = event.getName();
75:
76: try {
77: if (name.equals("cancel")) {
78: dialog.dispose();
79: } else if (name.equals("add")) {
80: dialog.dispose();
81:
82: String preset = (dataModel.getValue("preset") instanceof String) ? null
83: : ((WidgetInfo.PresetEntry) dataModel
84: .getValue("preset")).presetName;
85:
86: if (anchorElement.getAttribute("type").equals(""))
87: anchorElement = null;
88: tree.doInsert(className, preset, anchorElement);
89: } else if (name.equals("anchor")) {
90: AnchorEditor anchorEditor = new AnchorEditor(dialog,
91: anchorElement, null);
92: anchorEditor.show();
93: }
94: } catch (Exception e) {
95: new MessageDialog(e);
96: }
97: }
98: }
|