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 281653f..69a2fd1 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 @@ -115,7 +115,7 @@ public class TabularDataXGridPanel extends ContentPanel { this.eventBus = eventBus; bindEventBus(); container = new VerticalLayoutContainer(); - + setWidget(container); } @@ -214,6 +214,60 @@ public class TabularDataXGridPanel extends ContentPanel { return null; } + + /** + * getSelectedRowsId + * + * @return List list of identifiers of the selected rows + */ + public ArrayList getSelectedRowsId() { + if (grid != null) { + ColumnModel columnModel = grid + .getColumnModel(); + + List> columns = columnModel + .getColumns(); + DataRowColumnConfig c = null; + boolean columnIdRetrieved = false; + for (ColumnConfig col : columns) { + c = (DataRowColumnConfig) col; + ColumnType ctype = c.getDefinition().getType(); + if (ctype == ColumnType.COLUMNID) { + columnIdRetrieved = true; + break; + } + } + + if (columnIdRetrieved) { + ColumnDefinition cd = c.getDefinition(); + Log.debug("CD - Definition:" + cd.getId() + + " ColumnLocalId:" + cd.getColumnLocalId() + + " Label:" + cd.getLabel() + " Key:" + + cd.getKey()); + List rowsSelected = getSelectedRows(); + Log.debug("Retriving rows selected"); + String rowS = ""; + ArrayList rows = new ArrayList(); + if (rowsSelected != null) { + for (Row row : rowsSelected) { + rowS = row.getFieldAsText(cd.getLabel()); + Log.debug("Selected Row:" + rowS); + rows.add(rowS); + } + } else { + Log.debug("no selected rows retrived"); + } + return rows; + } else { + Log.debug("no COLUMNID retrived"); + return null; + } + + } else { + return null; + } + + } protected void bindEventBus() { eventBus.addHandler(OpenTableEvent.TYPE, new OpenTableEventHandler() { @@ -262,14 +316,13 @@ public class TabularDataXGridPanel extends ContentPanel { unmask(); } - protected void setupGrid(TableDefinition tableDefinition) { - this.tableDefinition=tableDefinition; - + this.tableDefinition = tableDefinition; + ColumnDefinition modelKeyColumn = tableDefinition.getModelKeyColumn(); - store = new ListStore( - new DataRowModelKeyProvider(modelKeyColumn.getKey())); - + store = new ListStore(new DataRowModelKeyProvider( + modelKeyColumn.getKey())); + store.addStoreUpdateHandler(new StoreUpdateEvent.StoreUpdateHandler() { @Override @@ -317,31 +370,30 @@ public class TabularDataXGridPanel extends ContentPanel { liveGridView = new ExtendedLiveGridView(); liveGridView.setRowHeight(21); - + grid = new Grid(store, columnModel); grid.setLoadMask(true); grid.setLoader(loader); grid.setView(liveGridView); - + editing = new GridInlineEditing(grid); editing.setClicksToEdit(ClicksToEdit.TWO); - - for(ColumnConfig c:columnsConfig){ - ColumnConfigGenerator.setEditor(editing, c); + + for (ColumnConfig c : columnsConfig) { + ColumnConfigGenerator.setEditor(editing, c); } - + // numberer.initPlugin(grid); - container.add(grid, new VerticalLayoutData(1, 1, new Margins(0))); - + ToolBar toolBar = new ToolBar(); toolBar.add(new LiveToolItem(grid)); toolBar.addStyleName(ThemeStyles.getStyle().borderTop()); toolBar.getElement().getStyle().setProperty("borderBottom", "none"); - - container.add(toolBar, new VerticalLayoutData(1, 25, new Margins(0))); - + + container.add(toolBar, + new VerticalLayoutData(1, 25, new Margins(0))); container.forceLayout(); @@ -353,7 +405,7 @@ public class TabularDataXGridPanel extends ContentPanel { }); loader.load(0, liveGridView.getCacheSize()); - + if (contextMenu != null) { grid.setContextMenu(contextMenu); } else @@ -362,9 +414,7 @@ public class TabularDataXGridPanel extends ContentPanel { if (headerColumnMenuItems != null) { setHeaderContextMenuHandler(); } - - - + } else { // TODO we need to manually reset the sort loader.clearSortInfo(); @@ -372,11 +422,11 @@ public class TabularDataXGridPanel extends ContentPanel { grid.reconfigure(store, columnModel); editing = new GridInlineEditing(grid); editing.setClicksToEdit(ClicksToEdit.TWO); - - for(ColumnConfig c:columnsConfig){ - ColumnConfigGenerator.setEditor(editing, c); + + for (ColumnConfig c : columnsConfig) { + ColumnConfigGenerator.setEditor(editing, c); } - + // TODO workaround: the loader is called only if the scroll bar is // in the middle if (loader.getOffset() == 0) @@ -394,8 +444,6 @@ public class TabularDataXGridPanel extends ContentPanel { grid.getView().setViewConfig(null); } - - } /** @@ -462,7 +510,8 @@ public class TabularDataXGridPanel extends ContentPanel { /** * - * @param i index of column in ColumnModel + * @param i + * index of column in ColumnModel * @return id of column and equals to column name on service */ public String getColumnId(int i) { @@ -482,38 +531,38 @@ public class TabularDataXGridPanel extends ContentPanel { } - - public void addRow(ArrayList rows){ - if(grid!=null && editing!=null){ - List keys=tableDefinition.getKeys(); - - DataRow dataRow=new DataRow(keys.size()); - for(ColumnKey key:keys){ + /** + * + * @param rows + */ + public void addRow(ArrayList rows) { + if (grid != null && editing != null) { + List keys = tableDefinition.getKeys(); + + DataRow dataRow = new DataRow(keys.size()); + for (ColumnKey key : keys) { dataRow.set(key, null); } - - editing.cancelEditing(); - int pos=0; - if(rows!=null && rows.size()>0){ - pos=new Integer(rows.get(0)); - } - - store.add(pos, dataRow); - - int row = store.indexOf(dataRow); - editing.startEditing(new GridCell(row, pos)); + + editing.cancelEditing(); + int pos = 0; + if (rows != null && rows.size() > 0) { + pos = new Integer(rows.get(0)); + } + + store.add(pos, dataRow); + + int row = store.indexOf(dataRow); + editing.startEditing(new GridCell(row, pos)); } } - - + protected class ExtendedLiveGridView extends LiveGridView { - //TODO bug in gxt3 3.0.0 fixed in future - /*@Override - public void refresh(boolean headerToo) { - preventScrollToTopOnRefresh = true; - super.refresh(headerToo); - }*/ + // TODO bug in gxt3 3.0.0 fixed in future + /* + * @Override public void refresh(boolean headerToo) { + * preventScrollToTopOnRefresh = true; super.refresh(headerToo); } + */ }; - }