001: /*
002: * Copyright 2000,2005 wingS development team.
003: *
004: * This file is part of wingS (http://wingsframework.org).
005: *
006: * wingS is free software; you can redistribute it and/or modify
007: * it under the terms of the GNU Lesser General Public License
008: * as published by the Free Software Foundation; either version 2.1
009: * of the License, or (at your option) any later version.
010: *
011: * Please see COPYING for the complete licence.
012: */
013: package org.wings.plaf;
014:
015: import org.wings.plaf.css.Utils;
016: import org.wings.*;
017: import org.wings.table.STableCellRenderer;
018: import org.wings.io.Device;
019: import org.wings.macro.MacroContext;
020: import org.wings.macro.MacroContainer;
021: import org.wings.macro.MacroTag;
022:
023: import java.io.IOException;
024: import java.util.List;
025: import java.awt.*;
026:
027: /**
028: * <code>CmsTableCG<code>.
029: * <p/>
030: * User: raedler
031: * Date: 10.08.2007
032: * Time: 13:23:45
033: *
034: * @author raedler
035: * @version $Id
036: */
037: public class CmsTableCG implements TableCG, CmsCG {
038:
039: private MacroContainer macros;
040:
041: /**
042: * {@inheritDoc}
043: */
044: public void setMacros(MacroContainer macros) {
045: this .macros = macros;
046: }
047:
048: /**
049: * {@inheritDoc}
050: */
051: public Update getTableCellUpdate(STable table, int row, int col) {
052: // can be ignored at the moment
053: return null;
054: }
055:
056: /**
057: * {@inheritDoc}
058: */
059: public void installCG(SComponent c) {
060: // ignore
061: }
062:
063: /**
064: * {@inheritDoc}
065: */
066: public void uninstallCG(SComponent c) {
067: // ignore
068: }
069:
070: /**
071: * {@inheritDoc}
072: */
073: public void componentChanged(SComponent c) {
074: // can be ignored at the moment
075: }
076:
077: /**
078: * {@inheritDoc}
079: */
080: public void write(Device device, SComponent component)
081: throws IOException {
082: macros.execute();
083: }
084:
085: public void writeTableEvent(Device device, SComponent component)
086: throws IOException {
087: System.out.println("CmsTableCG.writeTableEvent");
088:
089: Utils.writeEvents(device, component, null);
090: }
091:
092: public void writeCellEvent(Device device, SComponent _c,
093: Integer row, Integer col) throws IOException {
094: System.out.println("CmsTableCG.writeCellEvent");
095:
096: STable table = (STable) _c;
097:
098: final boolean isEditingCell = table.isEditing()
099: && row == table.getEditingRow()
100: && col == table.getEditingColumn();
101: final boolean editableCell = table.isCellEditable(row, col);
102: final boolean selectableCell = table.getSelectionMode() != SListSelectionModel.NO_SELECTION
103: && !table.isEditable() && table.isSelectable();
104:
105: final SComponent component;
106: if (isEditingCell) {
107: component = table.getEditorComponent();
108: } else {
109: STableCellRenderer renderer = table.getCellRenderer(row
110: .intValue(), col.intValue());
111: if (renderer != null) {
112: component = table.prepareRenderer(renderer, row
113: .intValue(), col.intValue());
114: } else {
115: device.print(table.getValueAt(row.intValue(), col
116: .intValue()));
117: return;
118: }
119: }
120:
121: final boolean isClickable = component instanceof SClickable;
122:
123: String parameter = null;
124: if (table.isEditable() && !isEditingCell && editableCell)
125: parameter = table.getEditParameter(row.intValue(), col
126: .intValue());
127: else if (selectableCell)
128: parameter = table.getToggleSelectionParameter(row
129: .intValue(), col.intValue());
130:
131: if (parameter != null && !isEditingCell
132: && (selectableCell || editableCell) && !isClickable) {
133: Utils.printClickability(device, table, parameter, true,
134: table.getShowAsFormComponent());
135: }
136: }
137:
138: /**
139: * {@inheritDoc}
140: */
141: public Update getComponentUpdate(SComponent component) {
142: // can be ignored at the moment
143: return null;
144: }
145:
146: public Update getTableScrollUpdate(STable table,
147: Rectangle newViewport, Rectangle oldViewport) {
148: return null;
149: }
150:
151: public Update getSelectionUpdate(STable table,
152: List deselectedIndices, List selectedIndices) {
153: return null;
154: }
155:
156: public Update getEditCellUpdate(STable sTable, int row, int column) {
157: return null;
158: }
159:
160: public Update getRenderCellUpdate(STable sTable, int row, int column) {
161: return null;
162: }
163:
164: @MacroTag
165: public void id(MacroContext context) throws IOException {
166: context.getDevice().print(
167: "id=\"" + context.getComponent().getName() + "\"");
168: }
169:
170: @MacroTag
171: public void toggleSelection(MacroContext context, int row)
172: throws IOException {
173: context
174: .getDevice()
175: .print(
176: "wingS.request.sendEvent(event,true,true,'c','t"
177: + row
178: + ":0;shiftKey='+event.shiftKey+';ctrlKey='+event.ctrlKey+''); return false;");
179: }
180:
181: @MacroTag
182: public void cell(MacroContext context, int row, int col)
183: throws IOException {
184: throw new UnsupportedOperationException(
185: "Currently not supported.");
186: /*
187: Device device = context.getDevice();
188: SComponent component = context.getComponent();
189:
190: RenderHelper.getInstance(component).forbidCaching();
191:
192: STable table = (STable) component;
193: STableCellRenderer renderer = table.getCellRenderer(row, col);
194:
195: if (renderer != null) {
196: SComponent cellComponent = table.prepareRenderer(renderer, row, col);
197: SCellRendererPane rendererPane = table.getCellRendererPane();
198: rendererPane.writeComponent(device, cellComponent, table);
199: } else {
200: device.print(table.getValueAt(row, col));
201: }
202: RenderHelper.getInstance(component).allowCaching();
203: */
204: }
205: }
|