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.DataRowPagingReader;
|
||||
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.PagingLoadUrlEncoder;
|
||||
import org.gcube.portlets.user.tdwx.shared.ServletParameters;
|
||||
|
@ -779,13 +780,21 @@ public class TabularDataXGridPanel extends ContentPanel {
|
|||
}
|
||||
|
||||
if (tableViewConfig != null) {
|
||||
Log.debug("Use specific grid View");
|
||||
if (tableViewConfig.getRowStyleProvider() != null) {
|
||||
grid.getView().setViewConfig(
|
||||
new TabularDataGridViewConfig(tableViewConfig,
|
||||
tableDefinition));
|
||||
}
|
||||
} 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();
|
||||
|
@ -798,6 +807,10 @@ public class TabularDataXGridPanel extends ContentPanel {
|
|||
});
|
||||
|
||||
eventBus.fireEvent(new GridReadyEvent());
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -3,18 +3,38 @@
|
|||
*/
|
||||
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.
|
||||
* @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 {
|
||||
|
||||
|
||||
/**
|
||||
* 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.
|
||||
* @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,47 +3,58 @@
|
|||
*/
|
||||
package org.gcube.portlets.user.tdwx.client.config;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
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.ColumnType;
|
||||
import org.gcube.portlets.user.tdwx.shared.model.DataRow;
|
||||
import org.gcube.portlets.user.tdwx.shared.model.TableDefinition;
|
||||
|
||||
import com.sencha.gxt.core.client.ValueProvider;
|
||||
import com.sencha.gxt.widget.core.client.grid.GridViewConfig;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @author "Giancarlo Panichi"
|
||||
* <a href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
|
||||
*
|
||||
* A bridge between the GridViewConfig and the TableViewConfig.
|
||||
*/
|
||||
/**
|
||||
*
|
||||
* @author "Giancarlo Panichi" <a
|
||||
* href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
|
||||
*
|
||||
* A bridge between the GridViewConfig and the TableViewConfig.
|
||||
*/
|
||||
public class TabularDataGridViewConfig implements GridViewConfig<DataRow> {
|
||||
|
||||
|
||||
protected RowStyleProvider rowStyleProvider;
|
||||
protected Row row;
|
||||
protected TableDefinition definition;
|
||||
|
||||
public TabularDataGridViewConfig(TableViewConfig config, TableDefinition definition)
|
||||
{
|
||||
protected TableDefinition tableDefinition;
|
||||
protected ArrayList<ColumnDefinition> validationColumns;
|
||||
|
||||
public TabularDataGridViewConfig(TableViewConfig config,
|
||||
TableDefinition definition) {
|
||||
this.rowStyleProvider = config.getRowStyleProvider();
|
||||
this.definition=definition;
|
||||
|
||||
this.tableDefinition = definition;
|
||||
validationColumns=new ArrayList<ColumnDefinition>();
|
||||
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);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public String getColStyle(DataRow model, ValueProvider<? super DataRow, ?> valueProvider, int rowIndex, int colIndex) {
|
||||
return "";
|
||||
public String getColStyle(DataRow model,
|
||||
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) {
|
||||
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 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.safecss.shared.SafeStyles;
|
||||
import com.google.gwt.safecss.shared.SafeStylesBuilder;
|
||||
|
@ -41,16 +42,20 @@ public class ColumnConfigGenerator {
|
|||
columnConfig = ColumnConfigGenerator
|
||||
.<Boolean> create(columnDefinition);
|
||||
if (columnDefinition.getType() == ColumnType.VALIDATION) {
|
||||
|
||||
columnConfig.setCell(new AbstractCell<Boolean>(){
|
||||
|
||||
@Override
|
||||
public void render(Context context, Boolean value,
|
||||
SafeHtmlBuilder sb) {
|
||||
//int rowIndex = context.getIndex();
|
||||
//store.get(rowIndex);
|
||||
|
||||
String style = "style='color: " + (value ? "green" : "red")
|
||||
+ "'";
|
||||
String v = String.valueOf(value);
|
||||
sb.appendHtmlConstant("<span " + style
|
||||
+ " qtitle='Change' qtip='" + v + "'>" + v
|
||||
+ " title='"+v+"'>" + v
|
||||
+ "</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