final SCellRendererPane rendererPane, final int row, final int col) throws IOException { final boolean isEditingCell = table.isEditing() && row == table.getEditingRow() && col == table.getEditingColumn(); final boolean editableCell = table.isCellEditable(row, col); final boolean selectableCell = table.getSelectionMode() != SListSelectionModel.NO_SELECTION && !table.isEditable() && table.isSelectable(); component = table.getEditorComponent(); } else { component = table.prepareRenderer(table.getCellRenderer(row, col), row, col); if (table.isEditable() && editableCell) parameter = table.getEditParameter(row, col); else if (selectableCell) parameter = table.getToggleSelectionParameter(row, col); .getShowAsFormComponent()); device.print(isEditingCell ? " editing=\"true\"" : " editing=\"false\""); device.print(isEditingCell ? " class=\"cell\""
protected void writeBody(Device device, STable table, int startX, int endX, int startY, int endY, int emptyIndex) throws IOException { final SListSelectionModel selectionModel = table.getSelectionModel(); String selectedAreaStyle = table.getStyle(STable.SELECTOR_SELECTED); String evenAreaStyle = table.getStyle(STable.SELECTOR_EVEN_ROWS); String oddAreaStyle = table.getStyle(STable.SELECTOR_ODD_ROWS); StringBuilder selectedAreaInline = Utils.inlineStyles(table.getDynamicStyle(STable.SELECTOR_SELECTED)); StringBuilder evenAreaInline = Utils.inlineStyles(table.getDynamicStyle(STable.SELECTOR_EVEN_ROWS)); StringBuilder oddAreaInline = Utils.inlineStyles(table.getDynamicStyle(STable.SELECTOR_ODD_ROWS)); final SCellRendererPane rendererPane = table.getCellRendererPane(); STableColumnModel columnModel = table.getColumnModel(); for (int r = startY; r < endY; ++r) { writeTableRow(device, table, columnModel, selectionModel, rendererPane, r, startX, endX, emptyIndex, selectedAreaInline, oddAreaInline, evenAreaInline, selectedAreaStyle, oddAreaStyle, evenAreaStyle); } }
/** * Set the foreground color. * * @param color the new foreground color */ public void setSelectionBackground(Color color) { Color oldVal = this.getSelectionBackground(); setAttribute(SELECTOR_SELECTED, CSSProperty.BACKGROUND_COLOR, CSSStyleSheet.getAttribute(color)); propertyChangeSupport.firePropertyChange("selectionBackground", oldVal, this.getSelectionBackground()); }
/** * Set the foreground color. * * @param color the new foreground color */ public void setSelectionForeground(Color color) { Color oldVal = this.getSelectionForeground(); setAttribute(SELECTOR_SELECTED, CSSProperty.COLOR, CSSStyleSheet.getAttribute(color)); propertyChangeSupport.firePropertyChange("selectionForeground", oldVal, this.getSelectionForeground()); }
@MacroTag public static void cellEvent(MacroContext context, int row, int col) throws IOException { Device device = context.getDevice(); SComponent _c = context.getComponent(); STable table = (STable) _c; final boolean isEditingCell = table.isEditing() && row == table.getEditingRow() && col == table.getEditingColumn(); final boolean editableCell = table.isCellEditable(row, col); final boolean clickableCell = table instanceof XTable && ((XTable)table).isClickListenerSet(table.convertColumnIndexToModel(col)); final boolean selectableCell = table.getSelectionMode() != SListSelectionModel.NO_SELECTION && !table.isEditable() && table.isSelectable(); final boolean isClickable = _c instanceof SClickable; String parameter = null; if ((table.isEditable() && editableCell) || clickableCell) parameter = STable.getEditParameter(row, col); else if (selectableCell) parameter = STable.getToggleSelectionParameter(row, col) + ";shiftKey='+event.shiftKey+';ctrlKey='+event.ctrlKey+'"; if (parameter != null && (selectableCell || editableCell || clickableCell) && !isClickable) { Utils.printClickability(device, table, parameter, true, table.getShowAsFormComponent()); } }
SComponent component = table.prepareRenderer(table.getCellRenderer(row, column), row, column); table.getCellRendererPane().writeComponent(device, component, table); htmlCode = device.toString(); } catch (Throwable t) { row = table.isHeaderVisible() ? this.row + 1 : this.row; column = columnInView(table, column); column = isSelectionColumnVisible(table) ? column + 1 : column; Rectangle currentViewport = table.getViewportSize(); if (currentViewport != null) { row -= currentViewport.y; handler.addParameter(table.getName()); handler.addParameter(row); handler.addParameter(column);
if (isEditing()) { if (!isCellEditable(row, column)) return false; STableCellEditor editor = getCellEditor(row, column); if (editor != null) { setCellEditor(editor); setEditingRow(row); setEditingColumn(column); editorComp = prepareEditor(editor, row, column); update(((TableCG)getCG()).getEditCellUpdate(this, row, column)); return true; removeEditor();
/** * {@inheritDoc} */ public SComponent getTableCellRendererComponent(STable table, Object value, boolean isSelected, int row, int column) { if (isSelected) { super.setForeground(table.getSelectionForeground()); super.setBackground(table.getSelectionBackground()); } else { super.setForeground(table.getForeground()); WingsUtil.alternateEvenOddBackground(this, table, isSelected, row); } if (value instanceof IValueConnector) { Object connectorValue = ((IValueConnector) value).getConnectorValue(); setSelected((connectorValue != null && ((Boolean) connectorValue) .booleanValue())); } else { setSelected((value != null && ((Boolean) value).booleanValue())); } if (table.isCellEditable(row, column)) { setEnabled(true); } else { setEnabled(false); } return this; }
protected void writeHeader(Device device, STable table, int startX, int endX) throws IOException { if (!table.isHeaderVisible()) return; final SCellRendererPane rendererPane = table.getCellRendererPane(); STableColumnModel columnModel = table.getColumnModel(); String headerAreaStyle = table.getStyle(STable.SELECTOR_HEADER); if (headerAreaStyle != null) device.print("<tr class=\"" + headerAreaStyle + '"'); else device.print("<tr class=\"header\""); StringBuilder headerAreaInline = Utils.inlineStyles(table.getDynamicStyle(STable.SELECTOR_HEADER)); Utils.optAttribute(device, "style", headerAreaInline); device.print(">"); Utils.printNewline(device, table, 1); writeSelectionHeader(device, table); for (int i = startX; i < endX; ++i) { STableColumn column = columnModel.getColumn(i); if (!column.isHidden()) writeHeaderCell(device, table, rendererPane, i); else ++endX; } device.print("</tr>"); Utils.printNewline(device, table); }
SComponent component = table.getEditorComponent(); table.getCellRendererPane().writeComponent(device, component, table); htmlCode = device.toString(); } catch (Throwable t) { row = table.isHeaderVisible() ? this.row + 1 : this.row; column = columnInView(table, column); column = isSelectionColumnVisible(table) ? column + 1 : column; Rectangle currentViewport = table.getViewportSize(); if (currentViewport != null) { row -= currentViewport.y; handler.addParameter(table.getName()); handler.addParameter(row); handler.addParameter(column);
final SCellRendererPane rendererPane, final int row) throws IOException { final STableCellRenderer rowSelectionRenderer = table .getRowSelectionRenderer(); if (isSelectionColumnVisible(table)) { final SComponent comp = rowSelectionRenderer .getTableCellRendererComponent(table, table .getToggleSelectionParameter(row, -1), table.isRowSelected(row), row, -1); final String columnStyle = Utils.joinStyles(comp, "num"); Utils.optAttribute(device, "width", selectionColumnWidth); String value = table.getToggleSelectionParameter(row, -1); if (table.getSelectionMode() != SListSelectionModel.NO_SELECTION) { printClickability(device, table, value, table.getShowAsFormComponent()); device.print(" class=\"clickable "); device.print(columnStyle);
@MacroTag public static void cell(MacroContext context, int row, int col) throws IOException { Device device = context.getDevice(); SComponent component = context.getComponent(); // RenderHelper.getInstance(component).forbidCaching(); STable table = (STable) component; STableCellRenderer renderer = table.getCellRenderer(row, col); if (renderer != null) { SComponent cellComponent = table.prepareRenderer(renderer, row, col); SCellRendererPane rendererPane = table.getCellRendererPane(); rendererPane.writeComponent(device, cellComponent, table); } else { device.print(table.getValueAt(row, col)); } // RenderHelper.getInstance(component).allowCaching(); }
rowConnectorPrototype); STable viewComponent = createSTable(); viewComponent.setBorder(new SLineBorder(Color.LIGHT_GRAY)); if (viewDescriptor.isReadOnly()) { viewComponent.setEditable(false); tableModel.setExceptionHandler(actionHandler); tableModel.setColumnClassesByIds(columnClassesByIds); viewComponent.setModel(tableModel); listSelectionModelBinder.bindSelectionModel(connector, viewComponent .getSelectionModel(), null); int maxColumnSize = computePixelWidth(viewComponent, maxColumnCharacterLength); String propertyName = columnViewDescriptor.getName(); if (!forbiddenColumns.contains(propertyName)) { STableColumn column = viewComponent.getColumnModel().getColumn( columnIndex++); column.setIdentifier(propertyName);
/** * Renders the row sometimes needed to allow row selection. */ protected void writeSelectionBody(final Device device, final STable table, final SCellRendererPane rendererPane, final int row) throws IOException { if (isSelectionColumnVisible(table)) { final SComponent comp = getRowSelectionRenderer(table, row); final String columnStyle = Utils.joinStyles(comp, "num"); device.print("<td valign=\"top\" align=\"right\""); Utils.optAttribute(device, "width", selectionColumnWidth); String value = STable.getToggleSelectionParameter(row, -1) + ";shiftKey='+event.shiftKey+';ctrlKey='+event.ctrlKey+'"; if (table.getSelectionMode() != SListSelectionModel.NO_SELECTION) { printClickability(device, table, value, table.getShowAsFormComponent()); device.print(" class=\"clickable "); device.print(columnStyle); device.print("\""); } else { device.print(" class=\""); device.print(columnStyle); device.print("\""); } device.print(">"); // Renders the content of the row selection row rendererPane.writeComponent(device, comp, table); device.print("</td>"); } }
@Override public SComponent getTableCellRendererComponent(STable table, Object value, boolean selected, int row, int col) { setText(null); setIcon(null); if (value == null) { if (editIcon != null && table.isEditable() && table.isCellEditable(row, col)) setIcon(editIcon); } else if (value instanceof SIcon) setIcon((SIcon)value); else if (value instanceof SComponent) return (SComponent)value; else setText(value.toString()); return this; } }
@Override public void valueChanged(ListSelectionEvent e) { if (isUpdatePossible() && STable.class.isAssignableFrom(STable.this.getClass())) { deselectedIndices = new ArrayList<>(); selectedIndices = new ArrayList<>(); if (getSelectionMode() == SINGLE_SELECTION) { addIndex(e.getFirstIndex()); addIndex(e.getLastIndex()); } else { for (int index = e.getFirstIndex(); index <= e.getLastIndex(); ++index) { addIndex(index); } } update(((TableCG) getCG()).getSelectionUpdate(STable.this, deselectedIndices, selectedIndices)); } else { reload(); } }
public int convertColumnIndexToModel(int viewColumnIndex) { if (viewColumnIndex < 0) { return viewColumnIndex; } return getColumnModel().getColumn(viewColumnIndex).getModelIndex(); }
private void writeColumnWidths(Device device, STable table, int startX, int endX) throws IOException { STableColumnModel columnModel = table.getColumnModel(); // IE-6 crashes if there is a colgroup element but the table body is empty. // That's why, we're writing the colgroup element only if the header is visible OR the model contains at least // one row if (columnModel != null && atLeastOneColumnWidthIsNotNull(columnModel) && (table.isHeaderVisible() || table.getModel().getRowCount() > 0)) { device.print("<colgroup>"); if (isSelectionColumnVisible(table)) writeCol(device, selectionColumnWidth); for (int i = startX; i < endX; ++i) { STableColumn column = columnModel.getColumn(i); if (!column.isHidden()) writeCol(device, column.getWidth()); else ++endX; } device.print("</colgroup>"); Utils.printNewline(device, table); } }
/** * Returns the cell renderer for the given table cell. * @param row Table row * @param col Table column * @return The cell renderer for the given table cell. */ public STableCellRenderer getCellRenderer( int row, int col ) { STableColumnModel columnModel = getColumnModel(); if (columnModel != null) { STableColumn column = columnModel.getColumn(col); if (column != null) { STableCellRenderer renderer = column.getCellRenderer(); if (renderer != null) return renderer; } } return getDefaultRenderer(getColumnClass(col)); }
/** * Return an appropriate editor for the cell specified by this row and * column. If the TableColumn for this column has a non-null editor, return that. * If not, find the class of the data in this column (using getColumnClass()) * and return the default editor for this type of data. * * @param row the row of the cell to edit, where 0 is the first * @param col the column of the cell to edit, where 0 is the first */ public STableCellEditor getCellEditor( int row, int col ) { STableColumnModel columnModel = getColumnModel(); if (columnModel != null) { STableColumn column = columnModel.getColumn(col); if (column != null) { STableCellEditor editor = column.getCellEditor(); if (editor != null) return editor; } } return getDefaultEditor(getColumnClass(col)); }