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 2008-2012 Sergey Skladchikov
*
* 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 org.gwt.advanced.client.ui.widget;
import com.google.gwt.dom.client.Style;
import com.google.gwt.user.client.DOM;
import com.google.gwt.user.client.Element;
import com.google.gwt.user.client.ui.HTMLTable;
import com.google.gwt.user.client.ui.Widget;
import org.gwt.advanced.client.datamodel.*;
import org.gwt.advanced.client.ui.ExpandCellEventProducer;
import org.gwt.advanced.client.ui.ExpandableCellListener;
import org.gwt.advanced.client.ui.widget.cell.*;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
/**
* This class is a tree grid widget implentation that is able to display composite data models
* as a tree of rows.
* Remarkable feature of this grid is that it can render pageable subtrees.
*
* @author Sergey Skladchikov
* @since 1.4.0
*/
public class TreeGrid extends EditableGrid implements ExpandCellEventProducer {
/**
* expandable cell listeners
*/
private List expandableCellListeners;
/**
* Creates a tree grid with resizable columns by default.
*
* @param headers is a list of header names.
* @param columnWidgetClasses is a list of appropriate cell classes.
*/
public TreeGrid(String[] headers, Class[] columnWidgetClasses) {
this(headers, columnWidgetClasses, true);
}
/**
* Creates a tree grid with resizable columns.
*
* @param headers is a list of header names.
* @param columnWidgetClasses is a list of appropriate cell classes.
* @param resizable is a resizability flag. if it's true th grid will allow resize columns
* by a mouse otherwise it won't.
*/
public TreeGrid(String[] headers, Class[] columnWidgetClasses, boolean resizable) {
super(headers, columnWidgetClasses, resizable);
setGridRenderer(new TreeGridRenderer(this));
setGridCellfactory(new TreeCellFactory(this));
}
/**
* {@inheritDoc}
*/
public void addExpandableCellListener(ExpandableCellListener listener) {
getExpandableCellListeners().add(listener);
}
/**
* {@inheritDoc}
*/
public void removeExpandableCellListener(ExpandableCellListener listener) {
getExpandableCellListeners().remove(listener);
}
/**
* {@inheritDoc}
*/
public void fireExpandCell(ExpandableCell cell) {
if (cell.isExpanded())
expandCell((TreeCell) cell);
else
collapseCell((TreeCell) cell);
for (Object o : getExpandableCellListeners()) {
ExpandableCellListener expandableCellListener = (ExpandableCellListener) o;
expandableCellListener.onCellClick(cell);
}
}
/**
* This method returns a widget placed in the cell.
* If the widget is an expandable cell it returns cell child widget.
*
* @param row is a row number.
* @param column is a column number.
* @return is a cell widget.
*/
public Widget getWidget(int row, int column) {
Widget widget = super.getWidget(row, column);
if (widget instanceof ExpandableCell)
widget = (Widget) ((ExpandableCell) widget).getValue();
return widget;
}
/**
* Gets a tree grid row by parent and child row indexes.
*
* @param parentIndex is a parent row index.
* @param rowIndex is a row index.
* @return a tree grid row instance.
*/
public TreeGridRow getGridRow(int parentIndex, int rowIndex) {
if (getModel() instanceof Composite) {
TreeGridRow parent = (TreeGridRow) getGridRow(parentIndex);
if (parent != null && getGridRows(parentIndex).length > rowIndex)
return ((Composite) getModel()).getRow(parent, rowIndex);
}
return null;
}
/**
* Gets a list of tree grid rows by the parent index.
*
* @param parentIndex is a parent row index.
* @return a list of tree grid rows.
*/
public TreeGridRow[] getGridRows(int parentIndex) {
if (getModel() instanceof Composite) {
TreeGridRow parent = (TreeGridRow) getGridRow(parentIndex);
if (parent != null)
return ((Composite) getModel()).getRows(parent);
}
return new TreeGridRow[0];
}
/**
* {@inheritDoc}
*/
public GridRow getGridRowByRowNumber(int row) {
Map mapping = ((TreeGridRenderer) getGridRenderer()).getRowMapping();
return (GridRow) mapping.get(row);
}
/**
* {@inheritDoc}
*/
public void addRow() {
Editable dataModel = getModel();
if (dataModel instanceof Composite) {
Object[] emptyCells = new Object[getHeaders().length];
TreeCell cell = getTreeCell(getCurrentRow());
TreeGridRow parent = cell != null ? cell.getGridRow().getParent() : null;
Composite model = (Composite) dataModel;
model.addRow(parent, emptyCells);
} else
super.addRow();
}
/** {@inheritDoc} */
protected void drawCell(EditableModelEvent event) {
Composite source = (Composite)event.getSource();
if (source == getModel()) {
Object data = source.getRow(((CompositeModelEvent)event).getParent(),
event.getRow()).getData()[event.getColumn()];
getGridRenderer().drawCell(data, getRowByModelRow(event), event.getColumn(), false);
}
}
/**
* {@inheritDoc}
*/
protected void drawColumn(int column) {
int modelColumn = getModelColumn(column);
if (getModel() != null && getModel().getColumns().length > modelColumn) {
Object[] data = getModel().getColumns()[modelColumn].getData();
List