diff --git a/src/main/java/org/gcube/portlets/user/td/client/TabularDataController.java b/src/main/java/org/gcube/portlets/user/td/client/TabularDataController.java index 2831d89..3d901de 100644 --- a/src/main/java/org/gcube/portlets/user/td/client/TabularDataController.java +++ b/src/main/java/org/gcube/portlets/user/td/client/TabularDataController.java @@ -33,7 +33,6 @@ import org.gcube.portlets.user.td.widgetcommonevent.shared.GridOperationId; import org.gcube.portlets.user.td.widgetcommonevent.shared.TRId; import org.gcube.portlets.user.td.wizardwidget.client.WizardListener; import org.gcube.portlets.user.tdtemplate.client.TdTemplateController; -//import org.gcube.portlets.user.tdtemplate.client.TdTemplateController; import org.gcube.portlets.user.tdwx.client.TabularDataX; import org.gcube.portlets.user.tdwx.shared.model.TableId; @@ -52,6 +51,7 @@ import com.sencha.gxt.widget.core.client.container.BorderLayoutContainer.BorderL import com.sencha.gxt.widget.core.client.event.HideEvent; import com.sencha.gxt.widget.core.client.event.HideEvent.HideHandler; import com.sencha.gxt.widget.core.client.info.Info; +//import org.gcube.portlets.user.tdtemplate.client.TdTemplateController; /** * @@ -390,8 +390,10 @@ public class TabularDataController { case TABLEAGGREAGETE: break; case ROWADD: + doRowsAdd(); break; case ROWDELETE: + doRowsDelete(); break; case DUPLICATEDELETE: openDuplicatesRows(); @@ -779,31 +781,45 @@ public class TabularDataController { Log.debug("Change Table Request to " + event.getTrId()); openTable(event.getTrId()); }; + + + protected void doRowsAdd(){ + ArrayList rows = tabularData.getGridPanel().getSelectedRowsId(); + onRowsAdd(rows); + } + + protected void doRowsDelete(){ + ArrayList rows = tabularData.getGridPanel().getSelectedRowsId(); + onRowsDelete(rows); + } + + private void onRowsDelete(ArrayList rows){ + if(rows==null || rows.size()==0){ + alertMessage("No rows selected", "No rows selected"); + return; + } + DeleteRows deleteRows=new DeleteRows(trId, rows,eventBus); + deleteRows.delete(); + } + + private void onRowsAdd(ArrayList rows){ + tabularData.addRow(rows); + } protected void doGridContextMenuCommand(GridContextMenuItemEvent event) { Log.debug("GridContextMenu Fire Event", "OperationId: " + event.getGridOperationId()); GridOperationId gridOperationId = event.getGridOperationId(); ArrayList rows = event.getRows(); - - - + switch (gridOperationId) { case ROWADD: - if(rows==null){ - rows=new ArrayList(); - } - tabularData.addRow(rows); + onRowsAdd(rows); break; case ROWEDIT: break; case ROWDELETE: - if(rows==null || rows.size()==0){ - alertMessage("No rows selected", "No rows selected"); - return; - } - DeleteRows deleteRows=new DeleteRows(trId, rows,eventBus); - deleteRows.delete(); + onRowsDelete(rows); break; default: break; diff --git a/src/main/java/org/gcube/portlets/user/td/client/grid/GridContextMenu.java b/src/main/java/org/gcube/portlets/user/td/client/grid/GridContextMenu.java index 71c429f..c491da9 100644 --- a/src/main/java/org/gcube/portlets/user/td/client/grid/GridContextMenu.java +++ b/src/main/java/org/gcube/portlets/user/td/client/grid/GridContextMenu.java @@ -1,24 +1,16 @@ package org.gcube.portlets.user.td.client.grid; import java.util.ArrayList; -import java.util.List; import org.gcube.portlets.user.td.client.resource.TabularDataResources; import org.gcube.portlets.user.td.widgetcommonevent.client.event.GridContextMenuItemEvent; import org.gcube.portlets.user.td.widgetcommonevent.shared.GridOperationId; import org.gcube.portlets.user.tdwx.client.TabularDataXGridPanel; -import org.gcube.portlets.user.tdwx.client.config.Row; -import org.gcube.portlets.user.tdwx.client.model.grid.DataRowColumnConfig; -import org.gcube.portlets.user.tdwx.shared.model.ColumnDefinition; -import org.gcube.portlets.user.tdwx.shared.model.ColumnType; -import org.gcube.portlets.user.tdwx.shared.model.DataRow; import com.allen_sauer.gwt.log.client.Log; import com.google.gwt.event.logical.shared.SelectionEvent; import com.google.gwt.event.logical.shared.SelectionHandler; import com.google.web.bindery.event.shared.EventBus; -import com.sencha.gxt.widget.core.client.grid.ColumnConfig; -import com.sencha.gxt.widget.core.client.grid.ColumnModel; import com.sencha.gxt.widget.core.client.menu.Item; import com.sencha.gxt.widget.core.client.menu.Menu; import com.sencha.gxt.widget.core.client.menu.MenuItem; @@ -50,47 +42,10 @@ public class GridContextMenu { public void onSelection(SelectionEvent event) { Log.debug("gridPanel is: " + gridPanel); if (gridPanel != null) { - ColumnModel columnModel = gridPanel.getGrid() - .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 = gridPanel.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"); - } - GridContextMenuItemEvent eventGridContextMenu = new GridContextMenuItemEvent( + ArrayList rows=gridPanel.getSelectedRowsId(); + GridContextMenuItemEvent eventGridContextMenu = new GridContextMenuItemEvent( GridOperationId.ROWADD, rows); - eventBus.fireEvent(eventGridContextMenu); - } else { - Log.debug("no COLUMNID retrived"); - } + eventBus.fireEvent(eventGridContextMenu); } @@ -99,7 +54,7 @@ public class GridContextMenu { tableContextMenu.add(addRowItem); - MenuItem editRowItem = new MenuItem("Edit Row"); + /*MenuItem editRowItem = new MenuItem("Edit Row"); editRowItem.setId(GridOperationId.ROWEDIT.toString()); editRowItem.setIcon(TabularDataResources.INSTANCE.rowEdit()); editRowItem.addSelectionHandler(new SelectionHandler() { @@ -108,54 +63,18 @@ public class GridContextMenu { public void onSelection(SelectionEvent event) { Log.debug("gridPanel is: " + gridPanel); if (gridPanel != null) { - ColumnModel columnModel = gridPanel.getGrid() - .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 = gridPanel.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"); - } - GridContextMenuItemEvent eventGridContextMenu = new GridContextMenuItemEvent( + if (gridPanel != null) { + ArrayList rows=gridPanel.getSelectedRowsId(); + GridContextMenuItemEvent eventGridContextMenu = new GridContextMenuItemEvent( GridOperationId.ROWEDIT, rows); - eventBus.fireEvent(eventGridContextMenu); - } else { - Log.debug("no COLUMNID retrived"); - } + eventBus.fireEvent(eventGridContextMenu); } - } }); tableContextMenu.add(editRowItem); - + */ + MenuItem deleteRowItem = new MenuItem("Delete Row"); deleteRowItem.setId(GridOperationId.ROWDELETE.toString()); deleteRowItem.setIcon(TabularDataResources.INSTANCE.rowRemove()); @@ -165,49 +84,11 @@ public class GridContextMenu { public void onSelection(SelectionEvent event) { Log.debug("gridPanel is: " + gridPanel); if (gridPanel != null) { - ColumnModel columnModel = gridPanel.getGrid() - .getColumnModel(); - - List> columns = columnModel - .getColumns(); - Log.debug("Columns Config: "+columns); - DataRowColumnConfig c = null; - boolean columnIdRetrieved = false; - for (ColumnConfig col : columns) { - c = (DataRowColumnConfig) col; - Log.debug("Column "+c.getDefinition().getLabel()+" type:"+ - c.getDefinition().getType()); - 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 = gridPanel.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"); - } + if (gridPanel != null) { + ArrayList rows=gridPanel.getSelectedRowsId(); GridContextMenuItemEvent eventGridContextMenu = new GridContextMenuItemEvent( - GridOperationId.ROWDELETE, rows); + GridOperationId.ROWDELETE, rows); eventBus.fireEvent(eventGridContextMenu); - } else { - Log.debug("no COLUMNID retrived"); } } diff --git a/src/main/java/org/gcube/portlets/user/td/client/ribbon/ModifyToolBar.java b/src/main/java/org/gcube/portlets/user/td/client/ribbon/ModifyToolBar.java index e7ee959..a5a6c74 100644 --- a/src/main/java/org/gcube/portlets/user/td/client/ribbon/ModifyToolBar.java +++ b/src/main/java/org/gcube/portlets/user/td/client/ribbon/ModifyToolBar.java @@ -138,8 +138,7 @@ public class ModifyToolBar { aggregateButton.addSelectHandler(new SelectHandler() { public void onSelect(SelectEvent event) { - // eventBus.fireEvent(new - // ImportTableEvent(ImportTableType.JSON)); + //eventBus.fireEvent(new RibbonEvent(RibbonType.AGGREGATE)); } }); @@ -156,8 +155,7 @@ public class ModifyToolBar { addRowButton.addSelectHandler(new SelectHandler() { public void onSelect(SelectEvent event) { - // eventBus.fireEvent(new - // ImportTableEvent(ImportTableType.JSON)); + eventBus.fireEvent(new RibbonEvent(RibbonType.ROWADD)); } }); @@ -174,8 +172,7 @@ public class ModifyToolBar { deleteRowButton.addSelectHandler(new SelectHandler() { public void onSelect(SelectEvent event) { - // eventBus.fireEvent(new - // ImportTableEvent(ImportTableType.JSON)); + eventBus.fireEvent(new RibbonEvent(RibbonType.ROWDELETE)); } }); @@ -337,8 +334,8 @@ public class ModifyToolBar { unionButton.disable(); groupbyButton.disable(); aggregateButton.disable(); - addRowButton.disable(); - deleteRowButton.disable(); + addRowButton.enable(); + deleteRowButton.enable(); deleteDuplicateButton.enable(); annotationButton.disable(); // Column