001: package org.wings.plaf.css;
002:
003: import org.wings.io.Device;
004: import org.wings.io.StringBuilderDevice;
005: import org.wings.SComponent;
006: import org.wings.header.SessionHeaders;
007: import org.wings.script.ScriptListener;
008: import org.wings.session.ScriptManager;
009: import org.wings.dnd.*;
010: import org.wings.plaf.Update;
011:
012: import java.io.IOException;
013: import java.util.List;
014: import java.util.ArrayList;
015:
016: public class DragAndDropManagerCG implements
017: org.wings.plaf.DragAndDropManagerCG {
018: protected final List headers = new ArrayList();
019:
020: public DragAndDropManagerCG() {
021: }
022:
023: public void write(Device device, final SComponent component)
024: throws IOException {
025: final DragAndDropManager dragAndDropManager = (DragAndDropManager) component;
026:
027: ScriptManager.getInstance().addScriptListener(
028: new ScriptListener() {
029:
030: public String getScript() {
031: StringBuilder builder = AbstractComponentCG.STRING_BUILDER
032: .get();
033: builder.setLength(0);
034:
035: builder.append("wingS.dnd.manager = '");
036: builder.append(dragAndDropManager.getName());
037: builder.append("';");
038:
039: return builder.toString();
040: }
041:
042: public String getEvent() {
043: return null;
044: }
045:
046: public String getCode() {
047: return null;
048: }
049:
050: public int getPriority() {
051: return DEFAULT_PRIORITY;
052: }
053: });
054: }
055:
056: public void installCG(SComponent c) {
057: SessionHeaders.getInstance().registerHeaders(headers);
058: }
059:
060: public void uninstallCG(SComponent c) {
061: SessionHeaders.getInstance().deregisterHeaders(headers);
062: }
063:
064: public void componentChanged(SComponent c) {
065: }
066:
067: public Update getComponentUpdate(SComponent component) {
068: return new ComponentUpdate(component);
069: }
070:
071: protected class ComponentUpdate extends AbstractUpdate {
072:
073: public ComponentUpdate(SComponent component) {
074: super (component);
075: }
076:
077: public int getProperty() {
078: return FULL_REPLACE_UPDATE;
079: }
080:
081: public int getPriority() {
082: return 4;
083: }
084:
085: public Handler getHandler() {
086: String htmlCode = "";
087: String exception = null;
088:
089: try {
090: StringBuilderDevice htmlDevice = new StringBuilderDevice(
091: 1024);
092: write(htmlDevice, component);
093: htmlCode = htmlDevice.toString();
094: } catch (Throwable t) {
095: exception = t.getClass().getName();
096: }
097:
098: UpdateHandler handler = new UpdateHandler("component");
099: handler.addParameter(component.getName());
100: handler.addParameter(htmlCode);
101: if (exception != null) {
102: handler.addParameter(exception);
103: }
104: return handler;
105: }
106: }
107: }
|