Added Columns Reordering

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/user/tabular-data-widgetx@101717 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Giancarlo Panichi 2014-11-26 18:02:18 +00:00 committed by Giancarlo Panichi
parent b373c9f7d8
commit 097759a53a
9 changed files with 382 additions and 176 deletions

View File

@ -3,8 +3,6 @@
*/ */
package org.gcube.portlets.user.tdwx.client; package org.gcube.portlets.user.tdwx.client;
import java.util.ArrayList;
import org.gcube.portlets.user.tdwx.client.event.CloseTableEvent; 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.FailureEvent;
import org.gcube.portlets.user.tdwx.client.event.FailureEventHandler; import org.gcube.portlets.user.tdwx.client.event.FailureEventHandler;
@ -22,41 +20,42 @@ import com.google.gwt.user.client.rpc.AsyncCallback;
/** /**
* *
* @author "Giancarlo Panichi" * @author "Giancarlo Panichi" <a
* <a href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a> * href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
* *
* Master class that contains controller and grid * Master class that contains controller and grid
*/ */
public class TabularDataX { public class TabularDataX {
protected static int seed = 0; private static int seed = 0;
protected int tdSessionId; private int tdSessionId;
protected String defaultDataSourceFactoryName; private String defaultDataSourceFactoryName;
protected EventBus eventBus; private EventBus eventBus;
protected TabularDataXController controller; private TabularDataXController controller;
protected TabularDataXGridPanel gridPanel; private TabularDataXGridPanel gridPanel;
/** /**
* Creates a new {@link TabularDataX object setting the default {@link DataSourceXFactory} name. * Creates a new {@link TabularDataX object setting the default {
* @param defaultDataSourceFactoryName the default {@link DataSourceXFactory} name. * @link DataSourceXFactory} name.
*
* @param defaultDataSourceFactoryName
* the default {@link DataSourceXFactory} name.
*/ */
public TabularDataX(String defaultDataSourceFactoryName) public TabularDataX(String defaultDataSourceFactoryName) {
{
this.tdSessionId = seed++; this.tdSessionId = seed++;
this.defaultDataSourceFactoryName = defaultDataSourceFactoryName; this.defaultDataSourceFactoryName = defaultDataSourceFactoryName;
eventBus = new SimpleEventBus(); eventBus = new SimpleEventBus();
controller = new TabularDataXController(tdSessionId, eventBus); controller = new TabularDataXController(tdSessionId, eventBus);
} }
/** /**
* Creates a new {@link TabularDataX} object. * Creates a new {@link TabularDataX} object.
*/ */
public TabularDataX() public TabularDataX() {
{
this(null); this(null);
} }
/** /**
* @return the defaultDataSourceFactoryName * @return the defaultDataSourceFactoryName
*/ */
@ -65,129 +64,137 @@ public class TabularDataX {
} }
/** /**
* @param defaultDataSourceFactoryName the defaultDataSourceFactoryName to set * @param defaultDataSourceFactoryName
* the defaultDataSourceFactoryName to set
*/ */
public void setDefaultDataSourceFactoryName(String defaultDataSourceFactoryName) { public void setDefaultDataSourceFactoryName(
String defaultDataSourceFactoryName) {
this.defaultDataSourceFactoryName = defaultDataSourceFactoryName; this.defaultDataSourceFactoryName = defaultDataSourceFactoryName;
} }
public TabularDataXGridPanel getGridPanel() public TabularDataXGridPanel getGridPanel() {
{
if (gridPanel == null) { if (gridPanel == null) {
gridPanel = new TabularDataXGridPanel(tdSessionId, eventBus); gridPanel = new TabularDataXGridPanel(tdSessionId, eventBus);
} }
return gridPanel; return gridPanel;
} }
/** /**
* Add a new {@link FailureEventHandler}. * Add a new {@link FailureEventHandler}.
*
* @param handler * @param handler
*/ */
public void addFailureHandler(FailureEventHandler handler) public void addFailureHandler(FailureEventHandler handler) {
{
eventBus.addHandler(FailureEvent.TYPE, handler); eventBus.addHandler(FailureEvent.TYPE, handler);
} }
/** /**
* Add a new {@link FailureEventHandler}. * Add a new {@link FailureEventHandler}.
*
* @param handler * @param handler
*/ */
public void addGridReadyHandler(GridReadyEventHandler handler) public void addGridReadyHandler(GridReadyEventHandler handler) {
{
eventBus.addHandler(GridReadyEvent.TYPE, handler); eventBus.addHandler(GridReadyEvent.TYPE, handler);
} }
/** /**
* Opens a new table. * Opens a new table.
* @param id the table id. *
* @param id
* the table id.
*/ */
public void openTable(TableId id) public void openTable(TableId id) {
{ Log.trace("openTable id: " + id);
Log.trace("openTable id: "+id);
eventBus.fireEvent(new OpenTableEvent(id)); eventBus.fireEvent(new OpenTableEvent(id));
} }
/** /**
* Opens a new table. The default {@link DataSourceXFactory} name is used. * Opens a new table. The default {@link DataSourceXFactory} name is used.
* @param tableKey the table key. *
* @param tableKey
* the table key.
*/ */
public void openTable(String tableKey) public void openTable(String tableKey) {
{ Log.trace("openTable tableKey: " + tableKey);
Log.trace("openTable tableKey: "+tableKey);
TableId tableId = getTableId(tableKey); TableId tableId = getTableId(tableKey);
eventBus.fireEvent(new OpenTableEvent(tableId)); eventBus.fireEvent(new OpenTableEvent(tableId));
} }
/** /**
* Returns the current table definition. * Returns the current table definition.
*
* @return the table description, <code>null</code> if no table is open. * @return the table description, <code>null</code> if no table is open.
*/ */
public TableDefinition getCurrentTable() public TableDefinition getCurrentTable() {
{
return controller.getCurrentTable(); return controller.getCurrentTable();
} }
/** /**
* Returns the {@link TableDefinition} for the specified {@link TableId}. * Returns the {@link TableDefinition} for the specified {@link TableId}.
* @param tableId the table id. *
* @param callback the {@link AsyncCallback} called when the {@link TableDefinition} is retrieved. * @param tableId
* the table id.
* @param callback
* the {@link AsyncCallback} called when the
* {@link TableDefinition} is retrieved.
*/ */
public void getTableDefinition(TableId tableId, AsyncCallback<TableDefinition> callback) public void getTableDefinition(TableId tableId,
{ AsyncCallback<TableDefinition> callback) {
controller.getTableDefinition(tableId, callback); controller.getTableDefinition(tableId, callback);
} }
public void getTableDefinition(String tableKey, AsyncCallback<TableDefinition> callback) public void getTableDefinition(String tableKey,
{ AsyncCallback<TableDefinition> callback) {
TableId tableId = getTableId(tableKey); TableId tableId = getTableId(tableKey);
controller.getTableDefinition(tableId, callback); controller.getTableDefinition(tableId, callback);
} }
public void closeTable() public void closeTable() {
{
Log.trace("closeTable"); Log.trace("closeTable");
eventBus.fireEvent(new CloseTableEvent()); eventBus.fireEvent(new CloseTableEvent());
} }
protected TableId getTableId(String tableKey) protected TableId getTableId(String tableKey) {
{
if (defaultDataSourceFactoryName == null) { if (defaultDataSourceFactoryName == null) {
Log.error("No default DataSourceFactoryName specified"); Log.error("No default DataSourceFactoryName specified");
throw new IllegalArgumentException("No default DataSourceFactoryName specified"); throw new IllegalArgumentException(
"No default DataSourceFactoryName specified");
} }
return new TableId(defaultDataSourceFactoryName, tableKey); return new TableId(defaultDataSourceFactoryName, tableKey);
} }
public void addRow(ArrayList<String> rows){ /*
if(gridPanel!=null){ *
gridPanel.addRow(rows); * Disabled direct grid Add Rows on Tabular Resources
} *
} * public void addRow(ArrayList<String> rows) { if (gridPanel != null) {
* gridPanel.addRow(rows); } }
*/
/** /**
* *
* @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 * @return id of column and equals to column name on service
*/ */
public String getColumnName(int i){ public String getColumnName(int i) {
String columnId=null; String columnId = null;
if(gridPanel!=null){ if (gridPanel != null) {
columnId=gridPanel.getColumnName(i); columnId = gridPanel.getColumnName(i);
} }
return columnId; return columnId;
} }
/** /**
* *
* @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 * @return id of column and equals to column name on service
*/ */
public String getColumnLocalId(int i){ public String getColumnLocalId(int i) {
String columnLocalId=null; String columnLocalId = null;
if(gridPanel!=null){ if (gridPanel != null) {
columnLocalId=gridPanel.getColumnLocalId(i); columnLocalId = gridPanel.getColumnLocalId(i);
} }
return columnLocalId; return columnLocalId;
} }

View File

@ -5,12 +5,14 @@ package org.gcube.portlets.user.tdwx.client;
import org.gcube.portlets.user.tdwx.client.event.CloseTableEvent; 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.CloseTableEventHandler;
import org.gcube.portlets.user.tdwx.client.event.ColumnsReorderingEvent;
import org.gcube.portlets.user.tdwx.client.event.FailureEvent; import org.gcube.portlets.user.tdwx.client.event.FailureEvent;
import org.gcube.portlets.user.tdwx.client.event.OpenTableEvent; 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.OpenTableEventHandler;
import org.gcube.portlets.user.tdwx.client.event.TableReadyEvent; import org.gcube.portlets.user.tdwx.client.event.TableReadyEvent;
import org.gcube.portlets.user.tdwx.client.rpc.TabularDataXService; import org.gcube.portlets.user.tdwx.client.rpc.TabularDataXService;
import org.gcube.portlets.user.tdwx.client.rpc.TabularDataXServiceAsync; import org.gcube.portlets.user.tdwx.client.rpc.TabularDataXServiceAsync;
import org.gcube.portlets.user.tdwx.shared.ColumnsReorderingConfig;
import org.gcube.portlets.user.tdwx.shared.model.TableDefinition; import org.gcube.portlets.user.tdwx.shared.model.TableDefinition;
import org.gcube.portlets.user.tdwx.shared.model.TableId; import org.gcube.portlets.user.tdwx.shared.model.TableId;
@ -28,11 +30,11 @@ import com.google.gwt.user.client.rpc.AsyncCallback;
*/ */
public class TabularDataXController { public class TabularDataXController {
protected int tdSessionId; private int tdSessionId;
protected EventBus eventBus; private EventBus eventBus;
protected TabularDataXServiceAsync service; private TabularDataXServiceAsync service;
protected TableDefinition currentTable; private TableDefinition currentTable;
/** /**
* @param eventBus * @param eventBus
@ -59,6 +61,15 @@ public class TabularDataXController {
doCloseTable(); doCloseTable();
} }
}); });
eventBus.addHandler(ColumnsReorderingEvent.TYPE, new ColumnsReorderingEvent.ColumnsReorderingEventHandler() {
@Override
public void onColumnsReordering(ColumnsReorderingEvent event) {
doSetCurrentTableColumnsReordering(event);
}
});
} }
protected void doOpenTable(TableId tableId) protected void doOpenTable(TableId tableId)
@ -92,6 +103,26 @@ public class TabularDataXController {
}); });
} }
protected void doSetCurrentTableColumnsReordering(ColumnsReorderingEvent event)
{
ColumnsReorderingConfig columnReorderingConfig=event.getColumnsReorderingConfig();
service.setCurrentTableColumnsReordering(tdSessionId, columnReorderingConfig, new AsyncCallback<TableDefinition>() {
public void onSuccess(TableDefinition result) {
Log.trace("table definition: "+result);
currentTable = result;
eventBus.fireEvent(new TableReadyEvent(result));
}
public void onFailure(Throwable caught) {
eventBus.fireEvent(new FailureEvent(caught, "Column Reordering failed."));
}
});
}
protected TableDefinition getCurrentTable() protected TableDefinition getCurrentTable()
{ {
return currentTable; return currentTable;
@ -102,6 +133,4 @@ public class TabularDataXController {
service.getTableDefinition(tableId, callback); service.getTableDefinition(tableId, callback);
} }
} }

View File

@ -20,6 +20,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.config.TabularDataGridViewConfig;
import org.gcube.portlets.user.tdwx.client.event.CloseTableEvent; 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.CloseTableEventHandler;
import org.gcube.portlets.user.tdwx.client.event.ColumnsReorderingEvent;
import org.gcube.portlets.user.tdwx.client.event.GridReadyEvent; 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.OpenTableEvent;
import org.gcube.portlets.user.tdwx.client.event.OpenTableEventHandler; import org.gcube.portlets.user.tdwx.client.event.OpenTableEventHandler;
@ -34,6 +35,7 @@ import org.gcube.portlets.user.tdwx.client.model.util.ColumnConfigGenerator;
import org.gcube.portlets.user.tdwx.client.style.DefaultRowStyle; import org.gcube.portlets.user.tdwx.client.style.DefaultRowStyle;
import org.gcube.portlets.user.tdwx.client.util.ColumnPositionComparator; import org.gcube.portlets.user.tdwx.client.util.ColumnPositionComparator;
import org.gcube.portlets.user.tdwx.client.util.PagingLoadUrlEncoder; import org.gcube.portlets.user.tdwx.client.util.PagingLoadUrlEncoder;
import org.gcube.portlets.user.tdwx.shared.ColumnsReorderingConfig;
import org.gcube.portlets.user.tdwx.shared.ServletParameters; import org.gcube.portlets.user.tdwx.shared.ServletParameters;
import org.gcube.portlets.user.tdwx.shared.StaticFilterInformation; import org.gcube.portlets.user.tdwx.shared.StaticFilterInformation;
import org.gcube.portlets.user.tdwx.shared.model.ColumnDefinition; import org.gcube.portlets.user.tdwx.shared.model.ColumnDefinition;
@ -66,6 +68,7 @@ import com.sencha.gxt.widget.core.client.ContentPanel;
import com.sencha.gxt.widget.core.client.container.MarginData; import com.sencha.gxt.widget.core.client.container.MarginData;
import com.sencha.gxt.widget.core.client.container.VerticalLayoutContainer; 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.container.VerticalLayoutContainer.VerticalLayoutData;
import com.sencha.gxt.widget.core.client.event.ColumnMoveEvent;
import com.sencha.gxt.widget.core.client.event.HeaderContextMenuEvent; 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.HeaderContextMenuEvent.HeaderContextMenuHandler;
import com.sencha.gxt.widget.core.client.event.HeaderMouseDownEvent; import com.sencha.gxt.widget.core.client.event.HeaderMouseDownEvent;
@ -75,6 +78,7 @@ import com.sencha.gxt.widget.core.client.grid.ColumnModel;
import com.sencha.gxt.widget.core.client.grid.Grid; import com.sencha.gxt.widget.core.client.grid.Grid;
import com.sencha.gxt.widget.core.client.grid.LiveToolItem; import com.sencha.gxt.widget.core.client.grid.LiveToolItem;
import com.sencha.gxt.widget.core.client.grid.filters.Filter; import com.sencha.gxt.widget.core.client.grid.filters.Filter;
import com.sencha.gxt.widget.core.client.info.Info;
import com.sencha.gxt.widget.core.client.menu.Item; 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.Menu;
import com.sencha.gxt.widget.core.client.menu.MenuItem; import com.sencha.gxt.widget.core.client.menu.MenuItem;
@ -92,44 +96,42 @@ import com.sencha.gxt.widget.core.client.toolbar.ToolBar;
*/ */
public class TabularDataXGridPanel extends ContentPanel { public class TabularDataXGridPanel extends ContentPanel {
protected int tdSessionId; private int tdSessionId;
protected EventBus eventBus; private EventBus eventBus;
protected List<MenuItem> headerColumnMenuItems; private List<MenuItem> headerColumnMenuItems;
protected com.google.web.bindery.event.shared.EventBus externalBus; private com.google.web.bindery.event.shared.EventBus externalBus;
protected ListStore<DataRow> store; private ListStore<DataRow> store;
protected Grid<DataRow> grid; private Grid<DataRow> grid;
protected ToolBar toolBar; private ToolBar toolBar;
// protected GridInlineEditing<DataRow> editing; // protected GridInlineEditing<DataRow> editing;
protected TableDefinition tableDefinition;
protected VerticalLayoutContainer container;
protected ExtendedLiveGridView<DataRow> liveGridView; private TableDefinition tableDefinition;
protected DataRowPagingReader reader; private VerticalLayoutContainer container;
protected PagingLoader<FilterPagingLoadConfig, PagingLoadResult<DataRow>> loader; private ExtendedLiveGridView<DataRow> liveGridView;
protected ExtendedGridFilters<DataRow> gridFilters; private DataRowPagingReader reader;
protected ArrayList<StaticFilterInformation> staticFilters;
protected TableViewConfig tableViewConfig; private PagingLoader<FilterPagingLoadConfig, PagingLoadResult<DataRow>> loader;
protected Menu contextMenu; private ExtendedGridFilters<DataRow> gridFilters;
protected TableDefinition currentTableDefinition; private ArrayList<StaticFilterInformation> staticFilters;
protected Map<String, ColumnKey> keys;
private TableViewConfig tableViewConfig;
private Menu contextMenu;
private Map<String, ColumnKey> keys;
private String visibleOnlyColumn; private String visibleOnlyColumn;
protected boolean errorNotColored=false; private boolean errorNotColored = false;
/** /**
* @param eventBus * @param eventBus
@ -141,13 +143,13 @@ public class TabularDataXGridPanel extends ContentPanel {
setBodyBorder(false); setBodyBorder(false);
setBorders(false); setBorders(false);
setHeaderVisible(false); setHeaderVisible(false);
forceLayoutOnResize=true; forceLayoutOnResize = true;
setResize(true); setResize(true);
bindEventBus(); bindEventBus();
container = new VerticalLayoutContainer(); container = new VerticalLayoutContainer();
container.setBorders(false); container.setBorders(false);
add(container,new MarginData(0)); add(container, new MarginData(0));
//setWidget(container); // setWidget(container);
} }
/** /**
@ -212,10 +214,11 @@ public class TabularDataXGridPanel extends ContentPanel {
* *
* @param staticFilters * @param staticFilters
*/ */
public void setStaticFilters(ArrayList<StaticFilterInformation> staticFilters) { public void setStaticFilters(
ArrayList<StaticFilterInformation> staticFilters) {
this.staticFilters = staticFilters; this.staticFilters = staticFilters;
} }
/** /**
* Returns the selected row. * Returns the selected row.
* *
@ -272,8 +275,6 @@ public class TabularDataXGridPanel extends ContentPanel {
return null; return null;
} }
/** /**
* *
@ -292,7 +293,7 @@ public class TabularDataXGridPanel extends ContentPanel {
} }
RowRaw r = null; RowRaw r = null;
if (rows.size() > 0) { if (rows.size() > 0) {
HashMap<String, String> map = new HashMap<String, String>(); HashMap<String, String> map = new HashMap<String, String>();
ColumnModel<DataRow> columnModel = grid.getColumnModel(); ColumnModel<DataRow> columnModel = grid.getColumnModel();
@ -300,14 +301,13 @@ public class TabularDataXGridPanel extends ContentPanel {
.getColumns(); .getColumns();
Row rowFirst = rows.get(0); Row rowFirst = rows.get(0);
DataRowColumnConfig<?> columnDataRow = null; DataRowColumnConfig<?> columnDataRow = null;
String rowId=null; String rowId = null;
for (ColumnConfig<DataRow, ?> col : columns) { for (ColumnConfig<DataRow, ?> col : columns) {
columnDataRow = (DataRowColumnConfig<?>) col; columnDataRow = (DataRowColumnConfig<?>) col;
ColumnDefinition colDef = columnDataRow.getDefinition(); ColumnDefinition colDef = columnDataRow.getDefinition();
if (colDef != null) { if (colDef != null) {
String value; String value;
if (colDef.getColumnDataType() if (colDef.getColumnDataType().compareTo("Date") == 0) {
.compareTo("Date") == 0) {
value = rowFirst.getFieldAsDate(colDef value = rowFirst.getFieldAsDate(colDef
.getColumnLocalId()); .getColumnLocalId());
} else { } else {
@ -317,13 +317,13 @@ public class TabularDataXGridPanel extends ContentPanel {
map.put(colDef.getColumnLocalId(), value); map.put(colDef.getColumnLocalId(), value);
ColumnType ctype = colDef.getType(); ColumnType ctype = colDef.getType();
if (ctype == ColumnType.COLUMNID) { if (ctype == ColumnType.COLUMNID) {
rowId=value; rowId = value;
} }
} }
} }
if(rowId!=null && !rowId.isEmpty() && map.size()>0){ if (rowId != null && !rowId.isEmpty() && map.size() > 0) {
r=new RowRaw(rowId,map); r = new RowRaw(rowId, map);
} }
} }
@ -416,7 +416,7 @@ public class TabularDataXGridPanel extends ContentPanel {
visibleOnlyColumn = columnLocalId; visibleOnlyColumn = columnLocalId;
} }
/** /**
* *
* @return * @return
@ -424,16 +424,16 @@ public class TabularDataXGridPanel extends ContentPanel {
public boolean isErrorNotColored() { public boolean isErrorNotColored() {
return errorNotColored; return errorNotColored;
} }
/** /**
* *
* @param errorNotColored if true set background withe for rows with error * @param errorNotColored
* if true set background withe for rows with error
*/ */
public void setErrorNotColored(boolean errorNotColored) { public void setErrorNotColored(boolean errorNotColored) {
Log.debug("ErrorNotColored set :"+errorNotColored); Log.debug("ErrorNotColored set :" + errorNotColored);
this.errorNotColored = errorNotColored; this.errorNotColored = errorNotColored;
} }
/** /**
* *
@ -610,7 +610,6 @@ public class TabularDataXGridPanel extends ContentPanel {
Log.trace("table ready, setting grid up"); Log.trace("table ready, setting grid up");
mask("Loading table " + definition.getName() + "... "); mask("Loading table " + definition.getName() + "... ");
setupGrid(definition); setupGrid(definition);
this.currentTableDefinition = definition;
keys = new HashMap<String, ColumnKey>(); keys = new HashMap<String, ColumnKey>();
for (ColumnDefinition column : definition.getColumnsAsList()) for (ColumnDefinition column : definition.getColumnsAsList())
keys.put(column.getColumnLocalId(), column.getKey()); keys.put(column.getColumnLocalId(), column.getKey());
@ -620,8 +619,7 @@ public class TabularDataXGridPanel extends ContentPanel {
protected void doCloseTable() { protected void doCloseTable() {
mask(); mask();
grid = null; grid = null;
this.currentTableDefinition = null; keys.clear();
this.keys.clear();
container.clear(); container.clear();
unmask(); unmask();
} }
@ -697,6 +695,29 @@ public class TabularDataXGridPanel extends ContentPanel {
columnsConfig); columnsConfig);
columnModel = checkOnlyColumn(columnModel); columnModel = checkOnlyColumn(columnModel);
columnModel
.addColumnMoveHandler(new ColumnMoveEvent.ColumnMoveHandler() {
@Override
public void onColumnMove(ColumnMoveEvent event) {
int columnIndex = event.getIndex();
@SuppressWarnings("unchecked")
ColumnConfig<DataRow, ?> col = (ColumnConfig<DataRow, ?>) event
.getColumnConfig();
DataRowColumnConfig<?> columnDataRow = (DataRowColumnConfig<?>) col;
ColumnDefinition colDef = columnDataRow.getDefinition();
Info.display("Column Reordering", "Index: "
+ columnIndex + " Label: " + colDef.getLabel()
+ " Position: " + colDef.getPosition()
+ " ColumnId: " + colDef.getColumnLocalId());
ColumnsReorderingConfig columnsReorderingConfig = new ColumnsReorderingConfig(columnIndex, colDef);
ColumnsReorderingEvent columnsReorderingEvent = new ColumnsReorderingEvent(
columnsReorderingConfig);
eventBus.fireEvent(columnsReorderingEvent);
}
});
if (grid == null) { if (grid == null) {
@ -751,7 +772,8 @@ public class TabularDataXGridPanel extends ContentPanel {
grid.setLoader(loader); grid.setLoader(loader);
grid.setView(liveGridView); grid.setView(liveGridView);
grid.setBorders(false); grid.setBorders(false);
grid.setColumnReordering(true);
// TODO disabled editing rows // TODO disabled editing rows
/* /*
* editing = new GridInlineEditing<DataRow>(grid); * editing = new GridInlineEditing<DataRow>(grid);
@ -777,7 +799,7 @@ public class TabularDataXGridPanel extends ContentPanel {
// //
container.add(grid, new VerticalLayoutData(1, 1, new Margins(0))); container.add(grid, new VerticalLayoutData(1, 1, new Margins(0)));
toolBar = new ToolBar(); toolBar = new ToolBar();
toolBar.add(new LiveToolItem(grid)); toolBar.add(new LiveToolItem(grid));
toolBar.addStyleName(ThemeStyles.getStyle().borderTop()); toolBar.addStyleName(ThemeStyles.getStyle().borderTop());
@ -840,15 +862,15 @@ public class TabularDataXGridPanel extends ContentPanel {
} }
} else { } else {
Log.debug("Use default grid View"); Log.debug("Use default grid View");
tableViewConfig= new TableViewConfig(); tableViewConfig = new TableViewConfig();
Log.debug("Error Not Colored: "+errorNotColored); Log.debug("Error Not Colored: " + errorNotColored);
DefaultRowStyle rowStyle=new DefaultRowStyle(errorNotColored); DefaultRowStyle rowStyle = new DefaultRowStyle(errorNotColored);
tableViewConfig.setRowStyleProvider(rowStyle); tableViewConfig.setRowStyleProvider(rowStyle);
grid.getView().setViewConfig( grid.getView().setViewConfig(
new TabularDataGridViewConfig(tableViewConfig, new TabularDataGridViewConfig(tableViewConfig,
tableDefinition)); tableDefinition));
// grid.getView().setViewConfig(null); // grid.getView().setViewConfig(null);
} }
container.forceLayout(); container.forceLayout();
@ -861,10 +883,7 @@ public class TabularDataXGridPanel extends ContentPanel {
}); });
eventBus.fireEvent(new GridReadyEvent()); eventBus.fireEvent(new GridReadyEvent());
} }
/** /**
@ -953,7 +972,6 @@ public class TabularDataXGridPanel extends ContentPanel {
return columnName; return columnName;
} }
/** /**
* *
* @param i * @param i
@ -975,30 +993,21 @@ public class TabularDataXGridPanel extends ContentPanel {
} }
return columnLocalId; return columnLocalId;
} }
/**
*
* @param rows
*/
public void addRow(ArrayList<String> rows) {
// TODO Disabled AddROW
/*
* if (grid != null && editing != null) {
*
* List<ColumnKey> 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)); }
*/
};
/*
* Disabled AddROW by direct editing
*
* public void addRow(ArrayList<String> rows) {
*
* if (grid != null && editing != null) { List<ColumnKey> 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)); }
*
* }
*/
} }

View File

@ -0,0 +1,62 @@
/**
*
*/
package org.gcube.portlets.user.tdwx.client.event;
import org.gcube.portlets.user.tdwx.shared.ColumnsReorderingConfig;
import com.google.gwt.event.shared.EventHandler;
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 ColumnsReorderingEvent extends GwtEvent<ColumnsReorderingEvent.ColumnsReorderingEventHandler> {
public static GwtEvent.Type<ColumnsReorderingEventHandler> TYPE = new Type<ColumnsReorderingEventHandler>();
public interface ColumnsReorderingEventHandler extends EventHandler {
public void onColumnsReordering(ColumnsReorderingEvent event);
}
@Override
public Type<ColumnsReorderingEventHandler> getAssociatedType() {
return TYPE;
}
@Override
protected void dispatch(ColumnsReorderingEventHandler handler) {
handler.onColumnsReordering(this);
}
protected ColumnsReorderingConfig columnsReorderingConfig;
/**
* @param tableId
*/
public ColumnsReorderingEvent(ColumnsReorderingConfig columnsReorderingConfig) {
this.columnsReorderingConfig = columnsReorderingConfig;
}
public ColumnsReorderingConfig getColumnsReorderingConfig() {
return columnsReorderingConfig;
}
public void setColumnsReorderingConfig(
ColumnsReorderingConfig columnsReorderingConfig) {
this.columnsReorderingConfig = columnsReorderingConfig;
}
@Override
public String toString() {
return "ColumnsReorderingEvent [columnsReorderingConfig="
+ columnsReorderingConfig + "]";
}
}

View File

@ -3,6 +3,7 @@
*/ */
package org.gcube.portlets.user.tdwx.client.rpc; package org.gcube.portlets.user.tdwx.client.rpc;
import org.gcube.portlets.user.tdwx.shared.ColumnsReorderingConfig;
import org.gcube.portlets.user.tdwx.shared.Constants; import org.gcube.portlets.user.tdwx.shared.Constants;
import org.gcube.portlets.user.tdwx.shared.model.TableDefinition; import org.gcube.portlets.user.tdwx.shared.model.TableDefinition;
import org.gcube.portlets.user.tdwx.shared.model.TableId; import org.gcube.portlets.user.tdwx.shared.model.TableId;
@ -22,9 +23,12 @@ public interface TabularDataXService extends RemoteService {
public TableDefinition openTable(int tdSessionId, TableId tableId) throws TabularDataXServiceException; public TableDefinition openTable(int tdSessionId, TableId tableId) throws TabularDataXServiceException;
public TableDefinition getCurrentTableDefinition(int tdSessionId) throws TabularDataXServiceException; public TableDefinition getCurrentTableDefinition(int tdSessionId) throws TabularDataXServiceException;
public TableDefinition setCurrentTableColumnsReordering(int tdSessionId, ColumnsReorderingConfig columnReorderingConfig) throws TabularDataXServiceException;
public TableDefinition getTableDefinition(TableId id) throws TabularDataXServiceException; public TableDefinition getTableDefinition(TableId id) throws TabularDataXServiceException;
public void closeTable(int tdSessionId) throws TabularDataXServiceException; public void closeTable(int tdSessionId) throws TabularDataXServiceException;
} }

View File

@ -3,6 +3,7 @@
*/ */
package org.gcube.portlets.user.tdwx.client.rpc; package org.gcube.portlets.user.tdwx.client.rpc;
import org.gcube.portlets.user.tdwx.shared.ColumnsReorderingConfig;
import org.gcube.portlets.user.tdwx.shared.model.TableDefinition; import org.gcube.portlets.user.tdwx.shared.model.TableDefinition;
import org.gcube.portlets.user.tdwx.shared.model.TableId; import org.gcube.portlets.user.tdwx.shared.model.TableId;
@ -21,7 +22,9 @@ public interface TabularDataXServiceAsync {
void openTable(int tdSessionId, TableId tableId, AsyncCallback<TableDefinition> callback); void openTable(int tdSessionId, TableId tableId, AsyncCallback<TableDefinition> callback);
void getTableDefinition(TableId id, AsyncCallback<TableDefinition> callback); void getTableDefinition(TableId id, AsyncCallback<TableDefinition> callback);
void setCurrentTableColumnsReordering(int tdSessionId, ColumnsReorderingConfig columnReorderingConfig, AsyncCallback<TableDefinition> callback);
void closeTable(int tdSessionId, AsyncCallback<Void> callback); void closeTable(int tdSessionId, AsyncCallback<Void> callback);
} }

View File

@ -12,10 +12,10 @@ import org.gcube.portlets.user.tdwx.client.rpc.TabularDataXServiceException;
import org.gcube.portlets.user.tdwx.server.datasource.DataSourceX; import org.gcube.portlets.user.tdwx.server.datasource.DataSourceX;
import org.gcube.portlets.user.tdwx.server.datasource.DataSourceXException; import org.gcube.portlets.user.tdwx.server.datasource.DataSourceXException;
import org.gcube.portlets.user.tdwx.server.util.SessionUtil; import org.gcube.portlets.user.tdwx.server.util.SessionUtil;
import org.gcube.portlets.user.tdwx.shared.ColumnsReorderingConfig;
import org.gcube.portlets.user.tdwx.shared.model.TableDefinition; import org.gcube.portlets.user.tdwx.shared.model.TableDefinition;
import org.gcube.portlets.user.tdwx.shared.model.TableId; import org.gcube.portlets.user.tdwx.shared.model.TableId;
import com.google.gwt.user.server.rpc.RemoteServiceServlet; import com.google.gwt.user.server.rpc.RemoteServiceServlet;
/** /**
@ -39,6 +39,7 @@ public class TabularDataXServiceImpl extends RemoteServiceServlet implements Tab
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */
@Override
public TableDefinition openTable(int tdSessionId, TableId tableId) throws TabularDataXServiceException { public TableDefinition openTable(int tdSessionId, TableId tableId) throws TabularDataXServiceException {
logger.debug("openTable tdSessionId: "+tdSessionId+" tableId: "+tableId); logger.debug("openTable tdSessionId: "+tdSessionId+" tableId: "+tableId);
@ -59,6 +60,7 @@ public class TabularDataXServiceImpl extends RemoteServiceServlet implements Tab
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */
@Override
public TableDefinition getCurrentTableDefinition(int tdSessionId) throws TabularDataXServiceException { public TableDefinition getCurrentTableDefinition(int tdSessionId) throws TabularDataXServiceException {
logger.debug("getCurrentTableDefinition tdSessionId: "+tdSessionId); logger.debug("getCurrentTableDefinition tdSessionId: "+tdSessionId);
@ -72,9 +74,30 @@ public class TabularDataXServiceImpl extends RemoteServiceServlet implements Tab
} }
} }
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */
@Override
public TableDefinition setCurrentTableColumnsReordering(int tdSessionId, ColumnsReorderingConfig columnReorderingConfig) throws TabularDataXServiceException {
logger.debug("setCurrentTableColumnsReordering tdSessionId: "+tdSessionId);
try{
DataSourceX dataSource = getDataSource(tdSessionId);
logger.debug("Service get current table definition");
TableDefinition tableDefinition=dataSource.setColumnReordering(columnReorderingConfig);
return tableDefinition;
}catch (Exception e) {
logger.error("An error occurred setting columns reordering", e);
throw new TabularDataXServiceException("An error occurred setting columns reordering: "+e.getMessage());
}
}
/**
* {@inheritDoc}
*/
@Override
public TableDefinition getTableDefinition(TableId id) throws TabularDataXServiceException { public TableDefinition getTableDefinition(TableId id) throws TabularDataXServiceException {
logger.debug("getTableDefinition TableId: "+id); logger.debug("getTableDefinition TableId: "+id);
@ -92,6 +115,7 @@ public class TabularDataXServiceImpl extends RemoteServiceServlet implements Tab
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */
@Override
public void closeTable(int tdSessionId) throws TabularDataXServiceException { public void closeTable(int tdSessionId) throws TabularDataXServiceException {
try { try {
closeCurrentTable(tdSessionId, false); closeCurrentTable(tdSessionId, false);
@ -101,7 +125,7 @@ public class TabularDataXServiceImpl extends RemoteServiceServlet implements Tab
} }
} }
protected void closeCurrentTable(int tdSessionId, boolean silent) throws DataSourceXException { protected void closeCurrentTable(int tdSessionId, boolean silent) throws DataSourceXException {
try { try {
HttpSession httpSession = this.getThreadLocalRequest().getSession(); HttpSession httpSession = this.getThreadLocalRequest().getSession();

View File

@ -2,6 +2,7 @@ package org.gcube.portlets.user.tdwx.server.datasource;
import java.util.ArrayList; import java.util.ArrayList;
import org.gcube.portlets.user.tdwx.shared.ColumnsReorderingConfig;
import org.gcube.portlets.user.tdwx.shared.FilterInformation; import org.gcube.portlets.user.tdwx.shared.FilterInformation;
import org.gcube.portlets.user.tdwx.shared.StaticFilterInformation; import org.gcube.portlets.user.tdwx.shared.StaticFilterInformation;
import org.gcube.portlets.user.tdwx.shared.model.TableDefinition; import org.gcube.portlets.user.tdwx.shared.model.TableDefinition;
@ -29,7 +30,16 @@ public interface DataSourceX {
* if an error occurred retrieving the table definition. * if an error occurred retrieving the table definition.
*/ */
public TableDefinition getTableDefinition() throws DataSourceXException; public TableDefinition getTableDefinition() throws DataSourceXException;
/**
* Set column reordering on current table
*
* @param columnReorderingConfigure
* @throws DataSourceXException
*/
public TableDefinition setColumnReordering(ColumnsReorderingConfig columnsReorderingConfig)
throws DataSourceXException;
/** /**
* Retrieves the table data as JSON object. * Retrieves the table data as JSON object.

View File

@ -0,0 +1,58 @@
package org.gcube.portlets.user.tdwx.shared;
import java.io.Serializable;
import org.gcube.portlets.user.tdwx.shared.model.ColumnDefinition;
/**
*
* @author giancarlo email: <a
* href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
*
*/
public class ColumnsReorderingConfig implements Serializable {
private static final long serialVersionUID = -5161869285744817591L;
private int columnIndex;
private ColumnDefinition columnDefinition;
public ColumnsReorderingConfig() {
super();
}
/**
*
* @param columnIndex
* @param columnDefinition
*/
public ColumnsReorderingConfig(int columnIndex,
ColumnDefinition columnDefinition) {
this.columnIndex = columnIndex;
this.columnDefinition = columnDefinition;
}
public int getColumnIndex() {
return columnIndex;
}
public void setColumnIndex(int columnIndex) {
this.columnIndex = columnIndex;
}
public ColumnDefinition getColumnDefinition() {
return columnDefinition;
}
public void setColumnDefinition(ColumnDefinition columnDefinition) {
this.columnDefinition = columnDefinition;
}
@Override
public String toString() {
return "ColumnsReorderingConfig [columnIndex=" + columnIndex
+ ", columnDefinition=" + columnDefinition + "]";
}
}