diff --git a/src/main/java/org/gcube/portlets/user/tdwx/client/TabularDataXGridPanel.java b/src/main/java/org/gcube/portlets/user/tdwx/client/TabularDataXGridPanel.java
index 9843853..227a4ae 100644
--- a/src/main/java/org/gcube/portlets/user/tdwx/client/TabularDataXGridPanel.java
+++ b/src/main/java/org/gcube/portlets/user/tdwx/client/TabularDataXGridPanel.java
@@ -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());
+
+
+
+
}
/**
diff --git a/src/main/java/org/gcube/portlets/user/tdwx/client/config/RowStyleProvider.java b/src/main/java/org/gcube/portlets/user/tdwx/client/config/RowStyleProvider.java
index f72279f..152d3ec 100644
--- a/src/main/java/org/gcube/portlets/user/tdwx/client/config/RowStyleProvider.java
+++ b/src/main/java/org/gcube/portlets/user/tdwx/client/config/RowStyleProvider.java
@@ -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: g.panichi@isti.cnr.it
+ *
*/
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 validationColumns);
+
+ /**
+ *
+ * @param row
+ * @param tableDefinition
+ * @return
+ */
+ public String getColStyle(Row row, ArrayList validationColumns,
+ ValueProvider super DataRow, ?> valueProvider, int rowIndex, int colIndex);
}
diff --git a/src/main/java/org/gcube/portlets/user/tdwx/client/config/TabularDataGridViewConfig.java b/src/main/java/org/gcube/portlets/user/tdwx/client/config/TabularDataGridViewConfig.java
index 942c8e6..e237acc 100644
--- a/src/main/java/org/gcube/portlets/user/tdwx/client/config/TabularDataGridViewConfig.java
+++ b/src/main/java/org/gcube/portlets/user/tdwx/client/config/TabularDataGridViewConfig.java
@@ -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"
- * g.panichi@isti.cnr.it
- *
- * A bridge between the GridViewConfig and the TableViewConfig.
- */
+/**
+ *
+ * @author "Giancarlo Panichi" g.panichi@isti.cnr.it
+ *
+ * A bridge between the GridViewConfig and the TableViewConfig.
+ */
public class TabularDataGridViewConfig implements GridViewConfig {
-
+
protected RowStyleProvider rowStyleProvider;
protected Row row;
- protected TableDefinition definition;
-
- public TabularDataGridViewConfig(TableViewConfig config, TableDefinition definition)
- {
+ protected TableDefinition tableDefinition;
+ protected ArrayList validationColumns;
+
+ public TabularDataGridViewConfig(TableViewConfig config,
+ TableDefinition definition) {
this.rowStyleProvider = config.getRowStyleProvider();
- this.definition=definition;
-
+ this.tableDefinition = definition;
+ validationColumns=new ArrayList();
Map keys = new HashMap();
- 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 {
*/
public String getRowStyle(DataRow model, int rowIndex) {
row.setDataRow(model);
- return rowStyleProvider.getRowStyle(row);
+ return rowStyleProvider.getRowStyle(row, validationColumns);
}
}
diff --git a/src/main/java/org/gcube/portlets/user/tdwx/client/config/ValidationRowStyleProvider.java b/src/main/java/org/gcube/portlets/user/tdwx/client/config/ValidationRowStyleProvider.java
deleted file mode 100644
index 11e97e2..0000000
--- a/src/main/java/org/gcube/portlets/user/tdwx/client/config/ValidationRowStyleProvider.java
+++ /dev/null
@@ -1,25 +0,0 @@
-package org.gcube.portlets.user.tdwx.client.config;
-
-/**
- *
- * @author "Giancarlo Panichi"
- * g.panichi@isti.cnr.it
- *
- */
-public class ValidationRowStyleProvider implements RowStyleProvider {
-
- @Override
- public String getRowStyle(Row row) {
- /*
- Collection keys=row.keys.values();
- DataRow r=row.dataRow;
-
- for(ColumnKey k:keys){
- Object b = r.get(k);
- }
- */
-
- return null;
- }
-
-}
diff --git a/src/main/java/org/gcube/portlets/user/tdwx/client/model/util/ColumnConfigGenerator.java b/src/main/java/org/gcube/portlets/user/tdwx/client/model/util/ColumnConfigGenerator.java
index 65ec3e4..7f46733 100644
--- a/src/main/java/org/gcube/portlets/user/tdwx/client/model/util/ColumnConfigGenerator.java
+++ b/src/main/java/org/gcube/portlets/user/tdwx/client/model/util/ColumnConfigGenerator.java
@@ -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
. create(columnDefinition);
if (columnDefinition.getType() == ColumnType.VALIDATION) {
+
columnConfig.setCell(new AbstractCell(){
@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("" + v
+ + " title='"+v+"'>" + v
+ "");
}
});
diff --git a/src/main/java/org/gcube/portlets/user/tdwx/client/resources/ResourceBundle.java b/src/main/java/org/gcube/portlets/user/tdwx/client/resources/ResourceBundle.java
new file mode 100644
index 0000000..cc11aae
--- /dev/null
+++ b/src/main/java/org/gcube/portlets/user/tdwx/client/resources/ResourceBundle.java
@@ -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: g.panichi@isti.cnr.it
+ *
+ */
+public interface ResourceBundle extends ClientBundle {
+
+ public static final ResourceBundle INSTANCE = GWT
+ .create(ResourceBundle.class);
+
+ @Source("TDGrid.css")
+ TDGridCSS tdGridCSS();
+}
\ No newline at end of file
diff --git a/src/main/java/org/gcube/portlets/user/tdwx/client/resources/TDGridCSS.java b/src/main/java/org/gcube/portlets/user/tdwx/client/resources/TDGridCSS.java
new file mode 100644
index 0000000..d842808
--- /dev/null
+++ b/src/main/java/org/gcube/portlets/user/tdwx/client/resources/TDGridCSS.java
@@ -0,0 +1,16 @@
+package org.gcube.portlets.user.tdwx.client.resources;
+
+import com.google.gwt.resources.client.CssResource;
+
+
+/**
+ *
+ * @author "Giancarlo Panichi"
+ * email: g.panichi@isti.cnr.it
+ *
+ */
+public interface TDGridCSS extends CssResource {
+
+ @ClassName("grid-row-red")
+ public String getGridRowRed();
+}
diff --git a/src/main/java/org/gcube/portlets/user/tdwx/client/style/DefaultRowStyle.java b/src/main/java/org/gcube/portlets/user/tdwx/client/style/DefaultRowStyle.java
new file mode 100644
index 0000000..4e4cb29
--- /dev/null
+++ b/src/main/java/org/gcube/portlets/user/tdwx/client/style/DefaultRowStyle.java
@@ -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: g.panichi@isti.cnr.it
+ *
+ */
+public class DefaultRowStyle implements RowStyleProvider {
+
+ ResourceBundle res=ResourceBundle.INSTANCE;
+
+
+
+ @Override
+ public String getRowStyle(Row row,
+ ArrayList 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 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;
+ }
+
+}
diff --git a/src/main/resources/org/gcube/portlets/user/tdwx/client/resources/TDGrid.css b/src/main/resources/org/gcube/portlets/user/tdwx/client/resources/TDGrid.css
new file mode 100644
index 0000000..4311a4e
--- /dev/null
+++ b/src/main/resources/org/gcube/portlets/user/tdwx/client/resources/TDGrid.css
@@ -0,0 +1,6 @@
+@CHARSET "UTF-8";
+
+.grid-row-red {
+ background-color: #FFAFAF !important;
+}
+