Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*******************************************************************************
* Copyright 2015 xWic group (http://www.xwic.de)
*
* Licensed under the Apache License, Version 2.0 (the "License").
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*******************************************************************************/
package de.jwic.controls.tableviewer;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.PrintWriter;
import java.io.Serializable;
import java.util.Iterator;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import de.jwic.base.Control;
import de.jwic.base.Field;
import de.jwic.base.IControlRenderer;
import de.jwic.base.ImageRef;
import de.jwic.base.JWicRuntime;
import de.jwic.base.RenderContext;
import de.jwic.data.IContentProvider;
import de.jwic.data.Range;
/**
* Default implementation of the ITableRenderer interface. The default renderer
* generates HTML "by code", without using templates. The reason for this is
* because its faster, costs less resources and the generated HTML is quite
* complex so that templates would be quite ugly anyway.
*
* @author Florian Lippisch
*/
public class DefaultTableRenderer implements ITableRenderer, Serializable {
/**
*
*/
private static final long serialVersionUID = 1L;
/** default icon used for sort-up image */
public final static ImageRef ICON_SORTUP = new ImageRef("/jwic/gfx/sortup.gif");
/** default icon used for sort-down image */
public final static ImageRef ICON_SORTDOWN = new ImageRef("/jwic/gfx/sortdn.gif");
/** default icon used for expand image */
public final static ImageRef ICON_EXPAND = new ImageRef("/jwic/gfx/expand.png");
/** default icon used for collapse image */
public final static ImageRef ICON_COLLAPSE = new ImageRef("/jwic/gfx/collapse.png");
/** default icon used for indention */
public final static ImageRef ICON_CLEAR = new ImageRef("/jwic/gfx/clear.gif");
protected transient Log log = LogFactory.getLog(getClass());
private boolean expandLinkSpacing = true;
private int expandIconWidth = 19;
private int expandIconHeight = 16;
/*
* (non-Javadoc)
*
* @see de.jwic.ecolib.tableviewer.ITableRenderer#renderTable(de.jwic.base.
* RenderContext, de.jwic.ecolib.tableviewer.TableViewer,
* de.jwic.ecolib.tableviewer.TableModel)
*/
public void renderTable(RenderContext renderContext, TableViewer viewer, TableModel model,
ITableLabelProvider labelProvider) {
// make sure to load the TableViewer library
renderContext.addRequiredJSContent(TableViewer.class.getName().replace('.', '/') + ".static.js");
renderContext.addScript(viewer.getControlID(),
"{ afterUpdate: function(element) {JWic.controls.TableViewer.initialize(element, '"
+ viewer.getControlID() + "', {" + " colResize : " + viewer.isResizeableColumns() + " ,menu : "
+ (viewer.getMenu() != null ? "\'" + viewer.getMenu().getControlID() + "\'" : "null")
+ " ,fitToParent:" + model.isFitToParent() + "});}}");
String tblvGfxPath = JWicRuntime.getJWicRuntime().getContextPath() + "/jwic/gfx/";
PrintWriter writer = renderContext.getWriter();
IContentProvider> contentProvider = model.getContentProvider();
int tblWidth = 0;
for (Iterator it = model.getColumnIterator(); it.hasNext();) {
TableColumn tc = it.next();
if (!tc.isVisible()) {
continue;
}
tblWidth += tc.getWidth();
}
// Add resizer div
// if (viewer.isResizeableColumns()) {
// writer.print("");
// }
// render main table.
writer.print("
");
}
// render HEADER columns
if (viewer.isShowHeader()) {
renderHeader(writer, model, viewer, tblvGfxPath);
}
if (viewer.isScrollable()) {
// if scrollable, seperate the data table from the header
// and render it within its own, scrollable DIV. Will only
// look proper if the columns have a fixed width.
int dataHeight = viewer.getHeight() != 0 ? viewer.getHeight() - (viewer.isShowHeader() ? 20 : 0) : 200;
if (viewer.isShowStatusBar()) {
dataHeight -= 18;
}
int dataWidth = viewer.getWidth() != 0 ? viewer.getWidth() : 300;
if (viewer.isShowHeader()) {
writer.println("
");
}
writer.print("
");
writer.print("
");
}
Range range = model.getRange();
if (range.getMax() == 0) { // = Auto
int max = -1;
int rowSpace = viewer.getHeight() - (35 + 20); // - header height +
// scroll bar height
if (rowSpace != 0) {
if (viewer.isShowStatusBar()) {
rowSpace -= 18;
}
max = rowSpace / viewer.getRowHeightHint(); //
if (max < 1) {
max = 1;
}
model.setLastRenderedPageSize(max);
}
range = new Range(range.getStart(), max);
}
// render table BODY
writer.println("");
try {
int count = renderRows(0, false, writer, contentProvider.getContentIterator(range), viewer, labelProvider);
if (count == 0) {
// if no rows exist, then print an empty row just to preserve
// the scrolling of the header
renderEmptyRow(writer, viewer);
}
model.setLastRowRenderCount(count);
} catch (Exception e) {
writer.println("Error reading data from ContentProvider: " + e);
log.error("Error reading data from ContentProvider", e);
}
writer.println("");
writer.println("
");
if (viewer.isScrollable()) {
writer.println("
");
}
writer.println("
");
// render STATUS BAR
if (viewer.isShowStatusBar()) {
writer.println("
");
for (Iterator itC = model.getColumnIterator(); itC.hasNext();) {
TableColumn column = itC.next();
if (!column.isVisible()) {
continue;
}
if (isResizable && column.getWidth() == 0) {
// must set a default width if resizeable columns is activated
column.setWidth(150);
}
writer.print("
");
if (column.getSortIcon() != TableColumn.SORT_ICON_NONE) {
ImageRef imgSort = null;
switch (column.getSortIcon()) {
case TableColumn.SORT_ICON_UP:
imgSort = ICON_SORTUP;
break;
case TableColumn.SORT_ICON_DOWN:
imgSort = ICON_SORTDOWN;
break;
}
if (imgSort != null) {
writer.print("
");
writer.print("");
writer.print("
");
}
}
if (isResizable) {
writer.print("
");
writer.print("
");
}
writer.print("
");
writer.println("
");
}
// if the width is fixed, we must render an empty column at the end so
// that the
// browser will not adjust the columns width
if (viewer.getWidth() != 0) {
if (viewer.isScrollable()) {
writer.println("