From 513bfc920b2e7f067baa7a97902bbbc26c33b1ed Mon Sep 17 00:00:00 2001 From: Giancarlo Panichi Date: Wed, 14 May 2014 16:19:48 +0000 Subject: [PATCH] Added getSelectedRowAsRaw() git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/user/tabular-data-widgetx@95692 82a268e6-3cf1-43bd-a215-b396298e98cf --- .../tdwx/client/TabularDataXGridPanel.java | 82 +++++++++++++++++-- 1 file changed, 75 insertions(+), 7 deletions(-) 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 a8a1a3e..9843853 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 @@ -12,6 +12,7 @@ import java.util.Map; import org.gcube.portlets.user.td.widgetcommonevent.client.event.GridHeaderColumnMenuItemEvent; import org.gcube.portlets.user.td.widgetcommonevent.client.type.GridHeaderColumnMenuItemType; import org.gcube.portlets.user.td.widgetcommonevent.shared.CellData; +import org.gcube.portlets.user.td.widgetcommonevent.shared.grid.model.RowRaw; import org.gcube.portlets.user.tdwx.client.config.GridAndCellSelectionModel; import org.gcube.portlets.user.tdwx.client.config.Row; import org.gcube.portlets.user.tdwx.client.config.TableViewConfig; @@ -101,6 +102,7 @@ public class TabularDataXGridPanel extends ContentPanel { protected ToolBar toolBar; // protected GridInlineEditing editing; protected TableDefinition tableDefinition; + protected VerticalLayoutContainer container; protected ExtendedLiveGridView liveGridView; @@ -172,6 +174,15 @@ public class TabularDataXGridPanel extends ContentPanel { this.contextMenu = contextMenu; } + /** + * Return table definition + * + * @return + */ + public TableDefinition getTableDefinition() { + return tableDefinition; + } + /** * Returns the selected row. * @@ -228,6 +239,65 @@ public class TabularDataXGridPanel extends ContentPanel { return null; } + + + /** + * + * + * @return Selected Row as RowRaw + */ + public RowRaw getSelectedRowAsRaw() { + if (grid != null && grid.getSelectionModel() != null) { + List dataRows = grid.getSelectionModel() + .getSelectedItems(); + List rows = new ArrayList(); + for (DataRow dataRow : dataRows) { + if (dataRow != null) { + rows.add(new Row(dataRow, keys)); + } + } + + RowRaw r = null; + + if (rows.size() > 0) { + HashMap map = new HashMap(); + ColumnModel columnModel = grid.getColumnModel(); + List> columns = columnModel + .getColumns(); + Row rowFirst = rows.get(0); + DataRowColumnConfig columnDataRow = null; + String rowId=null; + for (ColumnConfig col : columns) { + columnDataRow = (DataRowColumnConfig) col; + ColumnDefinition colDef = columnDataRow.getDefinition(); + if (colDef != null) { + String value; + if (colDef.getColumnDataType() + .compareTo("Date") == 0) { + value = rowFirst.getFieldAsDate(colDef + .getColumnLocalId()); + } else { + value = rowFirst.getFieldAsText(colDef + .getColumnLocalId()); + } + map.put(colDef.getColumnLocalId(), value); + ColumnType ctype = colDef.getType(); + if (ctype == ColumnType.COLUMNID) { + rowId=value; + } + + } + } + if(rowId!=null && !rowId.isEmpty() && map.size()>0){ + r=new RowRaw(rowId,map); + } + + } + return r; + } + + return null; + } /** * Retrieve selected cell value @@ -268,16 +338,16 @@ public class TabularDataXGridPanel extends ContentPanel { .getCell()); DataRowColumnConfig cSelected = (DataRowColumnConfig) colSelected; ColumnDefinition cdSelected = cSelected.getDefinition(); - + String cellValue; - if(cdSelected.getColumnDataType().compareTo("Date")==0){ + if (cdSelected.getColumnDataType().compareTo("Date") == 0) { cellValue = row.getFieldAsDate(cdSelected .getColumnLocalId()); } else { cellValue = row.getFieldAsText(cdSelected - .getColumnLocalId()); + .getColumnLocalId()); } - + String columnIdValue = row.getFieldAsText(columnIdSelected .getColumnLocalId()); @@ -703,7 +773,7 @@ public class TabularDataXGridPanel extends ContentPanel { // TODO workaround: the loader is called only if the scroll bar is // in the middle - //if (loader.getOffset() == 0) + // if (loader.getOffset() == 0) // loader.load(); loader.load(0, liveGridView.getCacheSize()); } @@ -816,8 +886,6 @@ public class TabularDataXGridPanel extends ContentPanel { return columnId; } - - /** * * @param rows