Minor Update
git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/user/tabular-data-widgetx@97394 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
9d1dfcd59e
commit
a5047b2c65
|
@ -30,6 +30,7 @@ import org.gcube.portlets.user.tdwx.client.model.grid.DataRowColumnConfig;
|
||||||
import org.gcube.portlets.user.tdwx.client.model.grid.DataRowModelKeyProvider;
|
import org.gcube.portlets.user.tdwx.client.model.grid.DataRowModelKeyProvider;
|
||||||
import org.gcube.portlets.user.tdwx.client.model.grid.DataRowPagingReader;
|
import org.gcube.portlets.user.tdwx.client.model.grid.DataRowPagingReader;
|
||||||
import org.gcube.portlets.user.tdwx.client.model.util.ColumnConfigGenerator;
|
import org.gcube.portlets.user.tdwx.client.model.util.ColumnConfigGenerator;
|
||||||
|
import org.gcube.portlets.user.tdwx.client.style.DefaultRowStyle;
|
||||||
import org.gcube.portlets.user.tdwx.client.util.ColumnPositionComparator;
|
import org.gcube.portlets.user.tdwx.client.util.ColumnPositionComparator;
|
||||||
import org.gcube.portlets.user.tdwx.client.util.PagingLoadUrlEncoder;
|
import org.gcube.portlets.user.tdwx.client.util.PagingLoadUrlEncoder;
|
||||||
import org.gcube.portlets.user.tdwx.shared.ServletParameters;
|
import org.gcube.portlets.user.tdwx.shared.ServletParameters;
|
||||||
|
@ -779,13 +780,21 @@ public class TabularDataXGridPanel extends ContentPanel {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tableViewConfig != null) {
|
if (tableViewConfig != null) {
|
||||||
|
Log.debug("Use specific grid View");
|
||||||
if (tableViewConfig.getRowStyleProvider() != null) {
|
if (tableViewConfig.getRowStyleProvider() != null) {
|
||||||
grid.getView().setViewConfig(
|
grid.getView().setViewConfig(
|
||||||
new TabularDataGridViewConfig(tableViewConfig,
|
new TabularDataGridViewConfig(tableViewConfig,
|
||||||
tableDefinition));
|
tableDefinition));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
grid.getView().setViewConfig(null);
|
Log.debug("Use default grid View");
|
||||||
|
tableViewConfig= new TableViewConfig();
|
||||||
|
DefaultRowStyle rowStyle=new DefaultRowStyle();
|
||||||
|
tableViewConfig.setRowStyleProvider(rowStyle);
|
||||||
|
grid.getView().setViewConfig(
|
||||||
|
new TabularDataGridViewConfig(tableViewConfig,
|
||||||
|
tableDefinition));
|
||||||
|
// grid.getView().setViewConfig(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
container.forceLayout();
|
container.forceLayout();
|
||||||
|
@ -798,6 +807,10 @@ public class TabularDataXGridPanel extends ContentPanel {
|
||||||
});
|
});
|
||||||
|
|
||||||
eventBus.fireEvent(new GridReadyEvent());
|
eventBus.fireEvent(new GridReadyEvent());
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -3,18 +3,38 @@
|
||||||
*/
|
*/
|
||||||
package org.gcube.portlets.user.tdwx.client.config;
|
package org.gcube.portlets.user.tdwx.client.config;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
import org.gcube.portlets.user.tdwx.shared.model.ColumnDefinition;
|
||||||
|
import org.gcube.portlets.user.tdwx.shared.model.DataRow;
|
||||||
|
|
||||||
|
import com.sencha.gxt.core.client.ValueProvider;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Provides the CSS styles to apply to the provided row.
|
* Provides the CSS styles to apply to the provided row.
|
||||||
* @author "Federico De Faveri defaveri@isti.cnr.it"
|
*
|
||||||
|
* @author "Giancarlo Panichi"
|
||||||
|
* email: <a href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
|
||||||
|
*
|
||||||
*/
|
*/
|
||||||
public interface RowStyleProvider {
|
public interface RowStyleProvider {
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the CSS style for the specified row.
|
*
|
||||||
* Multiple styles can be specified, each separate by space.
|
|
||||||
* @param row the row where to apply the style. Don't store the object, it will be reused in successive calls.
|
* @param row the row where to apply the style. Don't store the object, it will be reused in successive calls.
|
||||||
* @return the style/s to apply, empty {@link String} if no style have to be applied.
|
* @param tableDefinition table definition.
|
||||||
|
* @return the CSS name style for the specified row, multiple names styles can be specified, each separate by space.
|
||||||
*/
|
*/
|
||||||
public String getRowStyle(Row row);
|
public String getRowStyle(Row row, ArrayList<ColumnDefinition> validationColumns);
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param row
|
||||||
|
* @param tableDefinition
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public String getColStyle(Row row, ArrayList<ColumnDefinition> validationColumns,
|
||||||
|
ValueProvider<? super DataRow, ?> valueProvider, int rowIndex, int colIndex);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,23 +3,23 @@
|
||||||
*/
|
*/
|
||||||
package org.gcube.portlets.user.tdwx.client.config;
|
package org.gcube.portlets.user.tdwx.client.config;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import org.gcube.portlets.user.tdwx.shared.model.ColumnDefinition;
|
import org.gcube.portlets.user.tdwx.shared.model.ColumnDefinition;
|
||||||
import org.gcube.portlets.user.tdwx.shared.model.ColumnKey;
|
import org.gcube.portlets.user.tdwx.shared.model.ColumnKey;
|
||||||
|
import org.gcube.portlets.user.tdwx.shared.model.ColumnType;
|
||||||
import org.gcube.portlets.user.tdwx.shared.model.DataRow;
|
import org.gcube.portlets.user.tdwx.shared.model.DataRow;
|
||||||
import org.gcube.portlets.user.tdwx.shared.model.TableDefinition;
|
import org.gcube.portlets.user.tdwx.shared.model.TableDefinition;
|
||||||
|
|
||||||
import com.sencha.gxt.core.client.ValueProvider;
|
import com.sencha.gxt.core.client.ValueProvider;
|
||||||
import com.sencha.gxt.widget.core.client.grid.GridViewConfig;
|
import com.sencha.gxt.widget.core.client.grid.GridViewConfig;
|
||||||
|
|
||||||
|
/**
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
*
|
||||||
* @author "Giancarlo Panichi"
|
* @author "Giancarlo Panichi" <a
|
||||||
* <a href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
|
* href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
|
||||||
*
|
*
|
||||||
* A bridge between the GridViewConfig and the TableViewConfig.
|
* A bridge between the GridViewConfig and the TableViewConfig.
|
||||||
*/
|
*/
|
||||||
|
@ -27,23 +27,34 @@ public class TabularDataGridViewConfig implements GridViewConfig<DataRow> {
|
||||||
|
|
||||||
protected RowStyleProvider rowStyleProvider;
|
protected RowStyleProvider rowStyleProvider;
|
||||||
protected Row row;
|
protected Row row;
|
||||||
protected TableDefinition definition;
|
protected TableDefinition tableDefinition;
|
||||||
|
protected ArrayList<ColumnDefinition> validationColumns;
|
||||||
|
|
||||||
public TabularDataGridViewConfig(TableViewConfig config, TableDefinition definition)
|
public TabularDataGridViewConfig(TableViewConfig config,
|
||||||
{
|
TableDefinition definition) {
|
||||||
this.rowStyleProvider = config.getRowStyleProvider();
|
this.rowStyleProvider = config.getRowStyleProvider();
|
||||||
this.definition=definition;
|
this.tableDefinition = definition;
|
||||||
|
validationColumns=new ArrayList<ColumnDefinition>();
|
||||||
Map<String, ColumnKey> keys = new HashMap<String, ColumnKey>();
|
Map<String, ColumnKey> keys = new HashMap<String, ColumnKey>();
|
||||||
for (ColumnDefinition column:definition.getColumnsAsList()) keys.put(column.getLabel(), column.getKey());
|
|
||||||
|
for (ColumnDefinition column : definition.getColumnsAsList()) {
|
||||||
|
keys.put(column.getLabel(), column.getKey());
|
||||||
|
if (column.getType() == ColumnType.VALIDATION){
|
||||||
|
validationColumns.add(column);
|
||||||
|
}
|
||||||
|
}
|
||||||
row = new Row(keys);
|
row = new Row(keys);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritDoc}
|
* {@inheritDoc}
|
||||||
*/
|
*/
|
||||||
public String getColStyle(DataRow model, ValueProvider<? super DataRow, ?> valueProvider, int rowIndex, int colIndex) {
|
public String getColStyle(DataRow model,
|
||||||
return "";
|
ValueProvider<? super DataRow, ?> valueProvider, int rowIndex,
|
||||||
|
int colIndex) {
|
||||||
|
row.setDataRow(model);
|
||||||
|
return rowStyleProvider.getColStyle(row, validationColumns, valueProvider,
|
||||||
|
rowIndex, colIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -51,7 +62,7 @@ public class TabularDataGridViewConfig implements GridViewConfig<DataRow> {
|
||||||
*/
|
*/
|
||||||
public String getRowStyle(DataRow model, int rowIndex) {
|
public String getRowStyle(DataRow model, int rowIndex) {
|
||||||
row.setDataRow(model);
|
row.setDataRow(model);
|
||||||
return rowStyleProvider.getRowStyle(row);
|
return rowStyleProvider.getRowStyle(row, validationColumns);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,25 +0,0 @@
|
||||||
package org.gcube.portlets.user.tdwx.client.config;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @author "Giancarlo Panichi"
|
|
||||||
* <a href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public class ValidationRowStyleProvider implements RowStyleProvider {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getRowStyle(Row row) {
|
|
||||||
/*
|
|
||||||
Collection<ColumnKey> keys=row.keys.values();
|
|
||||||
DataRow r=row.dataRow;
|
|
||||||
|
|
||||||
for(ColumnKey k:keys){
|
|
||||||
Object b = r.get(k);
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -11,6 +11,7 @@ import org.gcube.portlets.user.tdwx.shared.model.ColumnType;
|
||||||
import org.gcube.portlets.user.tdwx.shared.model.DataRow;
|
import org.gcube.portlets.user.tdwx.shared.model.DataRow;
|
||||||
|
|
||||||
import com.google.gwt.cell.client.AbstractCell;
|
import com.google.gwt.cell.client.AbstractCell;
|
||||||
|
import com.google.gwt.cell.client.Cell.Context;
|
||||||
import com.google.gwt.i18n.client.DateTimeFormat;
|
import com.google.gwt.i18n.client.DateTimeFormat;
|
||||||
import com.google.gwt.safecss.shared.SafeStyles;
|
import com.google.gwt.safecss.shared.SafeStyles;
|
||||||
import com.google.gwt.safecss.shared.SafeStylesBuilder;
|
import com.google.gwt.safecss.shared.SafeStylesBuilder;
|
||||||
|
@ -41,16 +42,20 @@ public class ColumnConfigGenerator {
|
||||||
columnConfig = ColumnConfigGenerator
|
columnConfig = ColumnConfigGenerator
|
||||||
.<Boolean> create(columnDefinition);
|
.<Boolean> create(columnDefinition);
|
||||||
if (columnDefinition.getType() == ColumnType.VALIDATION) {
|
if (columnDefinition.getType() == ColumnType.VALIDATION) {
|
||||||
|
|
||||||
columnConfig.setCell(new AbstractCell<Boolean>(){
|
columnConfig.setCell(new AbstractCell<Boolean>(){
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void render(Context context, Boolean value,
|
public void render(Context context, Boolean value,
|
||||||
SafeHtmlBuilder sb) {
|
SafeHtmlBuilder sb) {
|
||||||
|
//int rowIndex = context.getIndex();
|
||||||
|
//store.get(rowIndex);
|
||||||
|
|
||||||
String style = "style='color: " + (value ? "green" : "red")
|
String style = "style='color: " + (value ? "green" : "red")
|
||||||
+ "'";
|
+ "'";
|
||||||
String v = String.valueOf(value);
|
String v = String.valueOf(value);
|
||||||
sb.appendHtmlConstant("<span " + style
|
sb.appendHtmlConstant("<span " + style
|
||||||
+ " qtitle='Change' qtip='" + v + "'>" + v
|
+ " title='"+v+"'>" + v
|
||||||
+ "</span>");
|
+ "</span>");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -0,0 +1,20 @@
|
||||||
|
package org.gcube.portlets.user.tdwx.client.resources;
|
||||||
|
|
||||||
|
import com.google.gwt.core.client.GWT;
|
||||||
|
import com.google.gwt.resources.client.ClientBundle;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author "Giancarlo Panichi"
|
||||||
|
* email: <a href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public interface ResourceBundle extends ClientBundle {
|
||||||
|
|
||||||
|
public static final ResourceBundle INSTANCE = GWT
|
||||||
|
.create(ResourceBundle.class);
|
||||||
|
|
||||||
|
@Source("TDGrid.css")
|
||||||
|
TDGridCSS tdGridCSS();
|
||||||
|
}
|
|
@ -0,0 +1,16 @@
|
||||||
|
package org.gcube.portlets.user.tdwx.client.resources;
|
||||||
|
|
||||||
|
import com.google.gwt.resources.client.CssResource;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author "Giancarlo Panichi"
|
||||||
|
* email: <a href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public interface TDGridCSS extends CssResource {
|
||||||
|
|
||||||
|
@ClassName("grid-row-red")
|
||||||
|
public String getGridRowRed();
|
||||||
|
}
|
|
@ -0,0 +1,60 @@
|
||||||
|
package org.gcube.portlets.user.tdwx.client.style;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
import org.gcube.portlets.user.tdwx.client.config.Row;
|
||||||
|
import org.gcube.portlets.user.tdwx.client.config.RowStyleProvider;
|
||||||
|
import org.gcube.portlets.user.tdwx.client.resources.ResourceBundle;
|
||||||
|
import org.gcube.portlets.user.tdwx.shared.model.ColumnDefinition;
|
||||||
|
import org.gcube.portlets.user.tdwx.shared.model.DataRow;
|
||||||
|
|
||||||
|
import com.sencha.gxt.core.client.ValueProvider;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author "Giancarlo Panichi" email: <a
|
||||||
|
* href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class DefaultRowStyle implements RowStyleProvider {
|
||||||
|
|
||||||
|
ResourceBundle res=ResourceBundle.INSTANCE;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getRowStyle(Row row,
|
||||||
|
ArrayList<ColumnDefinition> validationColumns) {
|
||||||
|
String style = "";
|
||||||
|
|
||||||
|
|
||||||
|
for (ColumnDefinition c : validationColumns) {
|
||||||
|
Boolean valid = row.getField(c.getColumnLocalId());
|
||||||
|
if (valid != null && valid == false) {
|
||||||
|
style = res.tdGridCSS().getGridRowRed();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return style;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getColStyle(Row row,
|
||||||
|
ArrayList<ColumnDefinition> validationColumns,
|
||||||
|
ValueProvider<? super DataRow, ?> valueProvider, int rowIndex,
|
||||||
|
int colIndex) {
|
||||||
|
String style = "";
|
||||||
|
for (ColumnDefinition c : validationColumns) {
|
||||||
|
Boolean valid = row.getField(c.getColumnLocalId());
|
||||||
|
if (valid != null && valid == false) {
|
||||||
|
style = res.tdGridCSS().getGridRowRed();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
return style;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,6 @@
|
||||||
|
@CHARSET "UTF-8";
|
||||||
|
|
||||||
|
.grid-row-red {
|
||||||
|
background-color: #FFAFAF !important;
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue