001: package org.osbl.client.wings.devtools;
002:
003: import org.wings.session.SessionManager;
004: import org.wings.*;
005: import org.wings.script.ScriptListener;
006: import org.wings.script.JavaScriptListener;
007: import org.wings.externalizer.ExternalizeManager;
008: import org.wings.resource.FileResource;
009:
010: import javax.swing.*;
011: import java.awt.event.ActionEvent;
012: import java.util.Map;
013: import java.util.HashMap;
014: import java.io.*;
015:
016: /**
017: * TODO: document me!!!
018: * <p/>
019: * <code>GUIMapGeneratorDevTool</code>.
020: * User: rro
021: * Date: 31.07.2006
022: * Time: 09:08:45
023: *
024: * @author Roman Rädle
025: * @version $Revision$
026: */
027: public class GUIMapGeneratorDevTool extends AbstractAction {
028:
029: private StringBuilder builder;
030:
031: /**
032: * Defines an <code>Action</code> object with a default
033: * description string and default icon.
034: */
035: public GUIMapGeneratorDevTool() {
036: putValue(Action.NAME, "GUIMap Generator");
037: //putValue(Action.SMALL_ICON, org.osbl.client.wings.XIcons.REPLACE);
038: }
039:
040: /**
041: * Invoked when an action occurs.
042: */
043: public void actionPerformed(ActionEvent e) {
044:
045: builder = new StringBuilder();
046: builder
047: .append("<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n");
048: builder
049: .append("<GUIMap KtxInfo=\"Wilken Anmeldung\" Name=\"HTML_MOZ_NACHR\" ScreenType=\"HTML\" LongName=\"Wilken erste Anmeldung\">\n");
050:
051: ComponentTreeWalker treeWalker = new ToscaComponentTreeWalker();
052: treeWalker.walk(SessionManager.getSession().getRootFrame());
053:
054: builder.append("</GUIMap>");
055:
056: File file = null;
057: try {
058: file = File.createTempFile("tosca", ".xml");
059: } catch (IOException ioe) {
060: ioe.printStackTrace();
061: }
062:
063: BufferedWriter out;
064: try {
065: out = new BufferedWriter(new FileWriter(file));
066: out.write(builder.toString());
067: out.flush();
068: out.close();
069: } catch (FileNotFoundException e1) {
070: e1.printStackTrace();
071: } catch (IOException ioe) {
072: ioe.printStackTrace();
073: }
074:
075: FileResource resource = new FileResource(file);
076: resource.setExternalizerFlags(resource.getExternalizerFlags()
077: | ExternalizeManager.REQUEST);
078:
079: Map headers = new HashMap();
080: headers.put("Content-Disposition", "attachment; filename="
081: + file.getName());
082: resource.setHeaders(headers.entrySet());
083:
084: final ScriptListener listener = new JavaScriptListener(null,
085: null, "location.href='" + resource.getURL() + "'");
086: SessionManager.getSession().getScriptManager()
087: .addScriptListener(listener);
088: }
089:
090: class ToscaComponentTreeWalker implements ComponentTreeWalker {
091:
092: public boolean walk(SComponent c) {
093:
094: int level = 0;
095: for (SContainer parent = c.getParent(); parent != null; parent = parent
096: .getParent()) {
097: level++;
098: }
099:
100: if (c instanceof SContainer) {
101:
102: SContainer container = (SContainer) c;
103:
104: if (container.getComponentCount() > 0) {
105:
106: for (SComponent child : container.getComponents()) {
107:
108: if (child instanceof SAbstractButton) {
109:
110: if (child instanceof SRadioButton) {
111: builder
112: .append(" <Control Name=\""
113: + child.getName()
114: + "\" TypeInfo=\"HTMLRadioButton\" Desc=\"id="
115: + child.getName()
116: + "\" />\n");
117: } else if (child instanceof SCheckBox) {
118: builder
119: .append(" <Control Name=\""
120: + child.getName()
121: + "\" TypeInfo=\"HTMLCheckbox\" Desc=\"id="
122: + child.getName()
123: + "\" />\n");
124: } else {
125: builder
126: .append(" <Control Name=\""
127: + child.getName()
128: + "\" TypeInfo=\"HTMLButton\" Desc=\"id="
129: + child.getName()
130: + "\" />\n");
131: }
132: } else if (child instanceof STextComponent) {
133: builder
134: .append(" <Control Name=\""
135: + child.getName()
136: + "\" TypeInfo=\"HTMLEditbox\" Desc=\"id="
137: + child.getName()
138: + "\" />\n");
139: } else if (child instanceof SComboBox) {
140: builder
141: .append(" <Control Name=\""
142: + child.getName()
143: + "\" TypeInfo=\"HTMLComboBox\" Desc=\"id="
144: + child.getName()
145: + "\" />\n");
146: }
147:
148: String tab = "";
149: for (int i = 0; i < level; i++) {
150: tab += " ";
151: }
152:
153: if (child instanceof LowLevelEventListener) {
154: System.out.println(tab + "==> [LLEL] "
155: + child.getName() + " "
156: + child.getClass());
157: } else {
158: System.out.println(tab + "==> "
159: + child.getName() + " "
160: + child.getClass());
161: }
162:
163: walk(child);
164: }
165: }
166: }
167:
168: return false;
169: }
170: }
171: }
|