Minor Update

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/user/tabular-data-widgetx@93795 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Giancarlo Panichi 2014-03-28 17:42:56 +00:00 committed by Giancarlo Panichi
parent 7016d0749c
commit ccab7c3813
4 changed files with 192 additions and 20 deletions

View File

@ -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.

View File

@ -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<String, ColumnKey> 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<DataRow, ?> 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<DataRow> checkOnlyColumn(ColumnModel<DataRow> columnModel){
if (visibleOnlyColumn!=null && !visibleOnlyColumn.isEmpty()) {
Log.debug("setVisibleOnlyColumn: Grid not null");
List<ColumnConfig<DataRow, ?>> columns = columnModel.getColumns();
List<ColumnConfig<DataRow, ?>> columnsNew = new ArrayList<ColumnConfig<DataRow, ?>>();
// Retrive Column with conlumnLocalId
DataRowColumnConfig<?> columnTarget = null;
// boolean columnTargetRetrieved = false;
for (ColumnConfig<DataRow, ?> 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<DataRow>(columnsNew);
} else {
Log.debug("visibleOnlyColumn null");
}
return columnModel;
}
/**
* Retrieve selected cell value
*
* @param columnLocalId
* @return
*/
public ArrayList<String> getCellValue(String columnLocalId){
ArrayList<String> value=null;
public ArrayList<String> getCellValue(String columnLocalId) {
ArrayList<String> value = null;
if (grid != null) {
ColumnModel<DataRow> columnModel = grid.getColumnModel();
List<ColumnConfig<DataRow, ?>> columns = columnModel.getColumns();
// Retrive Column with conlumnName
// Retrive Column with conlumnLocalId
DataRowColumnConfig<?> columnTarget = null;
boolean columnTargetRetrieved = false;
for (ColumnConfig<DataRow, ?> 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<DataRow> columnModel = new ColumnModel<DataRow>(
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<DataRow>(grid);
@ -565,7 +660,8 @@ public class TabularDataXGridPanel extends ContentPanel {
} else {
grid.getView().setViewConfig(null);
}
eventBus.fireEvent(new GridReadyEvent());
}
/**

View File

@ -0,0 +1,45 @@
/**
*
*/
package org.gcube.portlets.user.tdwx.client.event;
import com.google.gwt.event.shared.GwtEvent;
/**
*
* @author "Giancarlo Panichi"
* <a href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
*
*/
public class GridReadyEvent extends GwtEvent<GridReadyEventHandler> {
public static GwtEvent.Type<GridReadyEventHandler> TYPE = new Type<GridReadyEventHandler>();
@Override
public Type<GridReadyEventHandler> 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();
}
}

View File

@ -0,0 +1,18 @@
/**
*
*/
package org.gcube.portlets.user.tdwx.client.event;
import com.google.gwt.event.shared.EventHandler;
/**
*
* @author "Giancarlo Panichi"
* <a href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
*
*/
public interface GridReadyEventHandler extends EventHandler {
public void onGridReady(GridReadyEvent event);
}