Skip to content

Instantly share code, notes, and snippets.

@cristianmiranda
Created January 22, 2021 23:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cristianmiranda/7f0a222727af07babcb2550a3c40d8ef to your computer and use it in GitHub Desktop.
Save cristianmiranda/7f0a222727af07babcb2550a3c40d8ef to your computer and use it in GitHub Desktop.
CustomDataViewColumn.java
package com.escribehost.client.admin.application.sandbox.widgets;
import com.google.gwt.core.client.JavaScriptObject;
import com.googlecode.gwt.charts.client.ColumnFunction;
import com.googlecode.gwt.charts.client.ColumnType;
import com.googlecode.gwt.charts.client.Properties;
import com.googlecode.gwt.charts.client.RoleType;
/**
* Represents a calculated column. A calculated column creates a value on the fly for each row and adds it to the view.
*/
public class CustomDataViewColumn extends JavaScriptObject {
/**
* Default constructor.
*
* @param columnFunction a function for calculating each row value
* @param type data type of the data in the column.
*
* @return the new column
*/
public static CustomDataViewColumn create(ColumnFunction columnFunction, ColumnType type) {
CustomDataViewColumn dataColumn = createObject().cast();
dataColumn.setCalc(columnFunction);
dataColumn.setType(type);
return dataColumn;
}
/**
* Creates a new column
* This is similar to passing in a number instead of an object, but enables you to specify a role and properties for
* the new column.
*
* @param sourceColumn
* @return the new column
*/
public static CustomDataViewColumn create(int sourceColumn) {
CustomDataViewColumn dataColumn = createObject().cast();
dataColumn.setSourceColumn(sourceColumn);
return dataColumn;
}
protected CustomDataViewColumn() {
}
/**
* Sets a function that will be called for each row in the column to calculate a value for that cell.
*
* @param columnFunction a function for calculating each row value
*/
public final native void setCalc(ColumnFunction columnFunction) /*-{
this.calc = function(dataTable, row) {
return columnFunction.@com.googlecode.gwt.charts.client.ColumnFunction::calc(Lcom/googlecode/gwt/charts/client/DataTable;I) (dataTable, row);
};
}-*/;
/**
* Sets an id for the column.
*
* @param id an id for the column
*/
public final native void setId(String id) /*-{
this.id = id;
}-*/;
/**
* Sets a label for the column.
*
* @param label a label for the column
*/
public final native void setLabel(String label) /*-{
this.label = label;
}-*/;
/**
* Sets a pattern specifying how to display the column value.
*
* @param pattern number (or date) format string specifying how to display the column value
*/
public final native void setPattern(String pattern) /*-{
this.pattern = pattern;
}-*/;
/**
* Sets an object containing any arbitrary properties to assign to this column. If not specified, the view column
* will have no properties.
*
* @param properties a map of custom values applied to the cell.
*/
public final native void setProperties(Properties properties) /*-{
this.properties = properties;
}-*/;
/**
* Sets a role for the column.
* If not specified, the existing role will not be imported.
*
* @param role a role for the column
*/
public final void setRole(RoleType role) {
setRole(role.getName());
}
/**
* Sets the source column to use as a value; if specified, do not specify the calc or the type property. This is
* similar to passing in a number instead of an object, but enables you to specify a role and properties for the new
* column.
*
* @param sourceColumn a source column to use as a value
*/
public final native void setSourceColumn(int sourceColumn) /*-{
this.sourceColumn = sourceColumn;
}-*/;
/**
* Sets a type for the column.
* Used as type of the value that the calc function returns
*
* @param type a type for the column
*/
public final void setType(ColumnType type) {
setType(type.getName());
}
private final native void setRole(String role) /*-{
this.role = role;
}-*/;
private final native void setType(String type) /*-{
this.type = type;
}-*/;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment