diff --git a/src/main/java/org/gcube/portlets/user/tdwx/client/TabularDataX.java b/src/main/java/org/gcube/portlets/user/tdwx/client/TabularDataX.java index eb220ec..1774f8e 100644 --- a/src/main/java/org/gcube/portlets/user/tdwx/client/TabularDataX.java +++ b/src/main/java/org/gcube/portlets/user/tdwx/client/TabularDataX.java @@ -8,6 +8,8 @@ import java.util.ArrayList; import org.gcube.portlets.user.tdwx.client.event.CloseTableEvent; import org.gcube.portlets.user.tdwx.client.event.FailureEvent; import org.gcube.portlets.user.tdwx.client.event.FailureEventHandler; +import org.gcube.portlets.user.tdwx.client.event.GridReadyEvent; +import org.gcube.portlets.user.tdwx.client.event.GridReadyEventHandler; import org.gcube.portlets.user.tdwx.client.event.OpenTableEvent; import org.gcube.portlets.user.tdwx.server.datasource.DataSourceXFactory; import org.gcube.portlets.user.tdwx.shared.model.TableDefinition; @@ -86,6 +88,17 @@ public class TabularDataX { eventBus.addHandler(FailureEvent.TYPE, handler); } + + /** + * Add a new {@link FailureEventHandler}. + * @param handler + */ + public void addGridReadyHandler(GridReadyEventHandler handler) + { + eventBus.addHandler(GridReadyEvent.TYPE, handler); + } + + /** * Opens a new table. * @param id the table id. 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 a26f2b6..b652764 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 @@ -18,6 +18,7 @@ import org.gcube.portlets.user.tdwx.client.config.TableViewConfig; import org.gcube.portlets.user.tdwx.client.config.TabularDataGridViewConfig; import org.gcube.portlets.user.tdwx.client.event.CloseTableEvent; import org.gcube.portlets.user.tdwx.client.event.CloseTableEventHandler; +import org.gcube.portlets.user.tdwx.client.event.GridReadyEvent; import org.gcube.portlets.user.tdwx.client.event.OpenTableEvent; import org.gcube.portlets.user.tdwx.client.event.OpenTableEventHandler; import org.gcube.portlets.user.tdwx.client.event.TableReadyEvent; @@ -39,6 +40,7 @@ import com.allen_sauer.gwt.log.client.Log; import com.google.gwt.core.client.GWT; import com.google.gwt.core.client.Scheduler; import com.google.gwt.core.client.Scheduler.ScheduledCommand; +import com.google.gwt.dom.client.NativeEvent; import com.google.gwt.event.logical.shared.SelectionEvent; import com.google.gwt.event.logical.shared.SelectionHandler; import com.google.gwt.event.shared.EventBus; @@ -58,6 +60,8 @@ import com.sencha.gxt.widget.core.client.container.VerticalLayoutContainer; import com.sencha.gxt.widget.core.client.container.VerticalLayoutContainer.VerticalLayoutData; import com.sencha.gxt.widget.core.client.event.HeaderContextMenuEvent; import com.sencha.gxt.widget.core.client.event.HeaderContextMenuEvent.HeaderContextMenuHandler; +import com.sencha.gxt.widget.core.client.event.HeaderMouseDownEvent; +import com.sencha.gxt.widget.core.client.event.HeaderMouseDownEvent.HeaderMouseDownHandler; 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.grid.Grid; @@ -106,6 +110,8 @@ public class TabularDataXGridPanel extends ContentPanel { protected TableDefinition currentTableDefinition; protected Map keys; + private String visibleOnlyColumn; + /** * @param eventBus */ @@ -247,7 +253,8 @@ public class TabularDataXGridPanel extends ContentPanel { } if (columnIdRetrieved) { Log.debug("ColumnId Retrieved"); - ColumnDefinition columnIdSelected = columnId.getDefinition(); + ColumnDefinition columnIdSelected = columnId + .getDefinition(); // Retrive ColumnSelected ColumnConfig colSelected = columns.get(cell .getCell()); @@ -255,14 +262,16 @@ public class TabularDataXGridPanel extends ContentPanel { ColumnDefinition cdSelected = cSelected.getDefinition(); String cellValue = row .getFieldAsText(cdSelected.getLabel()); - - String columnIdValue = row - .getFieldAsText(columnIdSelected.getLabel()); - - CellData tdCell=new CellData(cellValue, cdSelected.getId(), cdSelected.getColumnLocalId(), - cdSelected.getLabel(), columnIdValue, cell.getRow(),cell.getCell()); - - Log.debug("Selected Cell: "+tdCell); + + String columnIdValue = row.getFieldAsText(columnIdSelected + .getLabel()); + + CellData tdCell = new CellData(cellValue, + cdSelected.getId(), cdSelected.getColumnLocalId(), + cdSelected.getLabel(), columnIdValue, + cell.getRow(), cell.getCell()); + + Log.debug("Selected Cell: " + tdCell); return tdCell; } else { Log.debug("No ColumnId Retrieved"); @@ -277,32 +286,82 @@ public class TabularDataXGridPanel extends ContentPanel { return null; } + + /** + * Set one and only one visible column + * + * @param columnLocalId + */ + public void setVisibleOnlyColumn(String columnLocalId) { + Log.debug("setVisibleOnlyColumn: "+columnLocalId); + visibleOnlyColumn=columnLocalId; + + } + /** + * + * @param columnModel + * @return + */ + protected ColumnModel checkOnlyColumn(ColumnModel columnModel){ + if (visibleOnlyColumn!=null && !visibleOnlyColumn.isEmpty()) { + Log.debug("setVisibleOnlyColumn: Grid not null"); + + + List> columns = columnModel.getColumns(); + + List> columnsNew = new ArrayList>(); + // Retrive Column with conlumnLocalId + DataRowColumnConfig columnTarget = null; + // boolean columnTargetRetrieved = false; + for (ColumnConfig col : columns) { + columnTarget = (DataRowColumnConfig) col; + String columnLocal = columnTarget.getDefinition() + .getColumnLocalId(); + if (visibleOnlyColumn.compareTo(columnLocal) == 0) { + // columnTargetRetrieved = true; + columnTarget.setHidden(false); + columnsNew.add(columnTarget); + } else { + columnTarget.setHidden(true); + columnsNew.add(columnTarget); + } + } + columnModel = new ColumnModel(columnsNew); + + } else { + Log.debug("visibleOnlyColumn null"); + } + return columnModel; + + } + /** * Retrieve selected cell value * * @param columnLocalId * @return */ - public ArrayList getCellValue(String columnLocalId){ - ArrayList value=null; + public ArrayList getCellValue(String columnLocalId) { + ArrayList value = null; if (grid != null) { ColumnModel columnModel = grid.getColumnModel(); List> columns = columnModel.getColumns(); - - // Retrive Column with conlumnName + + // Retrive Column with conlumnLocalId DataRowColumnConfig columnTarget = null; boolean columnTargetRetrieved = false; for (ColumnConfig col : columns) { columnTarget = (DataRowColumnConfig) col; - String columnLocal = columnTarget.getDefinition().getColumnLocalId(); - if (columnLocalId.compareTo(columnLocal)==0) { + String columnLocal = columnTarget.getDefinition() + .getColumnLocalId(); + if (columnLocalId.compareTo(columnLocal) == 0) { columnTargetRetrieved = true; break; } } - + if (columnTargetRetrieved) { ColumnDefinition cd = columnTarget.getDefinition(); Log.debug("CD - Definition:" + cd.getId() + " ColumnLocalId:" @@ -328,7 +387,7 @@ public class TabularDataXGridPanel extends ContentPanel { } return value; } - + /** * getSelectedRowsId * @@ -429,7 +488,39 @@ public class TabularDataXGridPanel extends ContentPanel { container.clear(); unmask(); } + + /** + * + * @param handler + */ + protected void addHeaderMouseDownHandler(HeaderMouseDownHandler handler) { + if (grid != null) { + + if (handler == null) { + handler = new HeaderMouseDownHandler() { + @Override + public void onHeaderMouseDown(HeaderMouseDownEvent event) { + Log.debug("HeaderMouseDownEvent :"+event.toDebugString()); + if (event.getEvent().getButton() == NativeEvent.BUTTON_RIGHT) { + event.getEvent().stopPropagation(); + } else { + + } + + } + }; + }; + grid.addHeaderMouseDownHandler(handler); + } + } + + /** + * Define the grid + * + * + * @param tableDefinition + */ protected void setupGrid(TableDefinition tableDefinition) { this.tableDefinition = tableDefinition; @@ -465,7 +556,9 @@ public class TabularDataXGridPanel extends ContentPanel { ColumnModel columnModel = new ColumnModel( columnsConfig); - + + columnModel =checkOnlyColumn(columnModel); + if (grid == null) { reader = new DataRowPagingReader(tableDefinition); @@ -492,7 +585,9 @@ public class TabularDataXGridPanel extends ContentPanel { grid.setLoadMask(true); grid.setLoader(loader); grid.setView(liveGridView); - + + + // TODO disabled editing rows /* * editing = new GridInlineEditing(grid); @@ -565,7 +660,8 @@ public class TabularDataXGridPanel extends ContentPanel { } else { grid.getView().setViewConfig(null); } - + + eventBus.fireEvent(new GridReadyEvent()); } /** diff --git a/src/main/java/org/gcube/portlets/user/tdwx/client/event/GridReadyEvent.java b/src/main/java/org/gcube/portlets/user/tdwx/client/event/GridReadyEvent.java new file mode 100644 index 0000000..65cb954 --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/tdwx/client/event/GridReadyEvent.java @@ -0,0 +1,45 @@ +/** + * + */ +package org.gcube.portlets.user.tdwx.client.event; + +import com.google.gwt.event.shared.GwtEvent; + +/** + * + * @author "Giancarlo Panichi" + * g.panichi@isti.cnr.it + * + */ +public class GridReadyEvent extends GwtEvent { + + public static GwtEvent.Type TYPE = new Type(); + + @Override + public Type getAssociatedType() { + return TYPE; + } + + @Override + protected void dispatch(GridReadyEventHandler handler) { + handler.onGridReady(this); + } + + + /** + * @param tableDefinition + */ + public GridReadyEvent() { + + } + + /** + * {@inheritDoc} + */ + @Override + public String toString() { + StringBuilder builder = new StringBuilder(); + builder.append("TableReadyEvent "); + return builder.toString(); + } +} diff --git a/src/main/java/org/gcube/portlets/user/tdwx/client/event/GridReadyEventHandler.java b/src/main/java/org/gcube/portlets/user/tdwx/client/event/GridReadyEventHandler.java new file mode 100644 index 0000000..9274f02 --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/tdwx/client/event/GridReadyEventHandler.java @@ -0,0 +1,18 @@ +/** + * + */ +package org.gcube.portlets.user.tdwx.client.event; + +import com.google.gwt.event.shared.EventHandler; + +/** + * + * @author "Giancarlo Panichi" + * g.panichi@isti.cnr.it + * + */ +public interface GridReadyEventHandler extends EventHandler { + + public void onGridReady(GridReadyEvent event); + +}