From 097759a53ac9c896800e67e8256b8ed5ee4e0888 Mon Sep 17 00:00:00 2001 From: Giancarlo Panichi Date: Wed, 26 Nov 2014 18:02:18 +0000 Subject: [PATCH] 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 --- .../user/tdwx/client/TabularDataX.java | 167 +++++++++-------- .../tdwx/client/TabularDataXController.java | 41 +++- .../tdwx/client/TabularDataXGridPanel.java | 177 +++++++++--------- .../client/event/ColumnsReorderingEvent.java | 62 ++++++ .../tdwx/client/rpc/TabularDataXService.java | 8 +- .../client/rpc/TabularDataXServiceAsync.java | 5 +- .../tdwx/server/TabularDataXServiceImpl.java | 28 ++- .../tdwx/server/datasource/DataSourceX.java | 12 +- .../tdwx/shared/ColumnsReorderingConfig.java | 58 ++++++ 9 files changed, 382 insertions(+), 176 deletions(-) create mode 100644 src/main/java/org/gcube/portlets/user/tdwx/client/event/ColumnsReorderingEvent.java create mode 100644 src/main/java/org/gcube/portlets/user/tdwx/shared/ColumnsReorderingConfig.java 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 90bdb14..ffc5af0 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 @@ -3,8 +3,6 @@ */ 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.FailureEvent; import org.gcube.portlets.user.tdwx.client.event.FailureEventHandler; @@ -22,41 +20,42 @@ import com.google.gwt.user.client.rpc.AsyncCallback; /** * - * @author "Giancarlo Panichi" - * g.panichi@isti.cnr.it + * @author "Giancarlo Panichi" g.panichi@isti.cnr.it * - * Master class that contains controller and grid + * Master class that contains controller and grid */ public class TabularDataX { - - protected static int seed = 0; - - protected int tdSessionId; - protected String defaultDataSourceFactoryName; - protected EventBus eventBus; - protected TabularDataXController controller; - protected TabularDataXGridPanel gridPanel; - + + private static int seed = 0; + + private int tdSessionId; + private String defaultDataSourceFactoryName; + private EventBus eventBus; + private TabularDataXController controller; + private TabularDataXGridPanel gridPanel; + /** - * Creates a new {@link TabularDataX object setting the default {@link DataSourceXFactory} name. - * @param defaultDataSourceFactoryName the default {@link DataSourceXFactory} name. + * Creates a new {@link TabularDataX object setting the default { + * @link DataSourceXFactory} name. + * + * @param defaultDataSourceFactoryName + * the default {@link DataSourceXFactory} name. */ - public TabularDataX(String defaultDataSourceFactoryName) - { + public TabularDataX(String defaultDataSourceFactoryName) { this.tdSessionId = seed++; this.defaultDataSourceFactoryName = defaultDataSourceFactoryName; eventBus = new SimpleEventBus(); controller = new TabularDataXController(tdSessionId, eventBus); } - + /** * Creates a new {@link TabularDataX} object. */ - public TabularDataX() - { + public TabularDataX() { this(null); } - + /** * @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; } - public TabularDataXGridPanel getGridPanel() - { + public TabularDataXGridPanel getGridPanel() { if (gridPanel == null) { gridPanel = new TabularDataXGridPanel(tdSessionId, eventBus); } return gridPanel; } - + /** * Add a new {@link FailureEventHandler}. + * * @param handler */ - public void addFailureHandler(FailureEventHandler handler) - { + public void addFailureHandler(FailureEventHandler handler) { eventBus.addHandler(FailureEvent.TYPE, handler); } - - + /** * Add a new {@link FailureEventHandler}. + * * @param handler */ - public void addGridReadyHandler(GridReadyEventHandler handler) - { + public void addGridReadyHandler(GridReadyEventHandler handler) { eventBus.addHandler(GridReadyEvent.TYPE, handler); } - - + /** * Opens a new table. - * @param id the table id. + * + * @param id + * the table id. */ - public void openTable(TableId id) - { - Log.trace("openTable id: "+id); + public void openTable(TableId id) { + Log.trace("openTable id: " + id); eventBus.fireEvent(new OpenTableEvent(id)); } - + /** * 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) - { - Log.trace("openTable tableKey: "+tableKey); + public void openTable(String tableKey) { + Log.trace("openTable tableKey: " + tableKey); TableId tableId = getTableId(tableKey); eventBus.fireEvent(new OpenTableEvent(tableId)); } - + /** * Returns the current table definition. + * * @return the table description, null if no table is open. */ - public TableDefinition getCurrentTable() - { + public TableDefinition getCurrentTable() { return controller.getCurrentTable(); } - + /** * 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 callback) - { + public void getTableDefinition(TableId tableId, + AsyncCallback callback) { controller.getTableDefinition(tableId, callback); } - - public void getTableDefinition(String tableKey, AsyncCallback callback) - { + + public void getTableDefinition(String tableKey, + AsyncCallback callback) { TableId tableId = getTableId(tableKey); controller.getTableDefinition(tableId, callback); } - - public void closeTable() - { + + public void closeTable() { Log.trace("closeTable"); eventBus.fireEvent(new CloseTableEvent()); } - - protected TableId getTableId(String tableKey) - { + + protected TableId getTableId(String tableKey) { if (defaultDataSourceFactoryName == null) { 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); } - - public void addRow(ArrayList rows){ - if(gridPanel!=null){ - gridPanel.addRow(rows); - } - } - + + /* + * + * Disabled direct grid Add Rows on Tabular Resources + * + * public void addRow(ArrayList 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 */ - public String getColumnName(int i){ - String columnId=null; - if(gridPanel!=null){ - columnId=gridPanel.getColumnName(i); + public String getColumnName(int i) { + String columnId = null; + if (gridPanel != null) { + columnId = gridPanel.getColumnName(i); } 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 */ - public String getColumnLocalId(int i){ - String columnLocalId=null; - if(gridPanel!=null){ - columnLocalId=gridPanel.getColumnLocalId(i); + public String getColumnLocalId(int i) { + String columnLocalId = null; + if (gridPanel != null) { + columnLocalId = gridPanel.getColumnLocalId(i); } return columnLocalId; } diff --git a/src/main/java/org/gcube/portlets/user/tdwx/client/TabularDataXController.java b/src/main/java/org/gcube/portlets/user/tdwx/client/TabularDataXController.java index 55b688a..90781b0 100644 --- a/src/main/java/org/gcube/portlets/user/tdwx/client/TabularDataXController.java +++ b/src/main/java/org/gcube/portlets/user/tdwx/client/TabularDataXController.java @@ -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.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.OpenTableEvent; 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.rpc.TabularDataXService; 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.TableId; @@ -28,11 +30,11 @@ import com.google.gwt.user.client.rpc.AsyncCallback; */ public class TabularDataXController { - protected int tdSessionId; - protected EventBus eventBus; - protected TabularDataXServiceAsync service; + private int tdSessionId; + private EventBus eventBus; + private TabularDataXServiceAsync service; - protected TableDefinition currentTable; + private TableDefinition currentTable; /** * @param eventBus @@ -59,6 +61,15 @@ public class TabularDataXController { doCloseTable(); } }); + + eventBus.addHandler(ColumnsReorderingEvent.TYPE, new ColumnsReorderingEvent.ColumnsReorderingEventHandler() { + + @Override + public void onColumnsReordering(ColumnsReorderingEvent event) { + doSetCurrentTableColumnsReordering(event); + + } + }); } 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() { + + 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() { return currentTable; @@ -102,6 +133,4 @@ public class TabularDataXController { service.getTableDefinition(tableId, callback); } - - } 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 43d3f35..ba3aee2 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 @@ -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.event.CloseTableEvent; 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.OpenTableEvent; 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.util.ColumnPositionComparator; 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.StaticFilterInformation; 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.VerticalLayoutContainer; 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.HeaderContextMenuHandler; 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.LiveToolItem; 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.Menu; 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 { - protected int tdSessionId; + private int tdSessionId; - protected EventBus eventBus; + private EventBus eventBus; - protected List headerColumnMenuItems; + private List headerColumnMenuItems; - protected com.google.web.bindery.event.shared.EventBus externalBus; + private com.google.web.bindery.event.shared.EventBus externalBus; - protected ListStore store; - protected Grid grid; - protected ToolBar toolBar; + private ListStore store; + private Grid grid; + private ToolBar toolBar; // protected GridInlineEditing editing; - protected TableDefinition tableDefinition; - - protected VerticalLayoutContainer container; - protected ExtendedLiveGridView liveGridView; + private TableDefinition tableDefinition; - protected DataRowPagingReader reader; + private VerticalLayoutContainer container; - protected PagingLoader> loader; + private ExtendedLiveGridView liveGridView; - protected ExtendedGridFilters gridFilters; - - protected ArrayList staticFilters; + private DataRowPagingReader reader; - protected TableViewConfig tableViewConfig; + private PagingLoader> loader; - protected Menu contextMenu; + private ExtendedGridFilters gridFilters; - protected TableDefinition currentTableDefinition; - protected Map keys; + private ArrayList staticFilters; + + private TableViewConfig tableViewConfig; + + private Menu contextMenu; + + private Map keys; private String visibleOnlyColumn; - - protected boolean errorNotColored=false; - - + + private boolean errorNotColored = false; /** * @param eventBus @@ -141,13 +143,13 @@ public class TabularDataXGridPanel extends ContentPanel { setBodyBorder(false); setBorders(false); setHeaderVisible(false); - forceLayoutOnResize=true; + forceLayoutOnResize = true; setResize(true); bindEventBus(); container = new VerticalLayoutContainer(); container.setBorders(false); - add(container,new MarginData(0)); - //setWidget(container); + add(container, new MarginData(0)); + // setWidget(container); } /** @@ -212,10 +214,11 @@ public class TabularDataXGridPanel extends ContentPanel { * * @param staticFilters */ - public void setStaticFilters(ArrayList staticFilters) { + public void setStaticFilters( + ArrayList staticFilters) { this.staticFilters = staticFilters; } - + /** * Returns the selected row. * @@ -272,8 +275,6 @@ public class TabularDataXGridPanel extends ContentPanel { return null; } - - /** * @@ -292,7 +293,7 @@ public class TabularDataXGridPanel extends ContentPanel { } RowRaw r = null; - + if (rows.size() > 0) { HashMap map = new HashMap(); ColumnModel columnModel = grid.getColumnModel(); @@ -300,14 +301,13 @@ public class TabularDataXGridPanel extends ContentPanel { .getColumns(); Row rowFirst = rows.get(0); DataRowColumnConfig columnDataRow = null; - String rowId=null; + String rowId = null; for (ColumnConfig col : columns) { columnDataRow = (DataRowColumnConfig) col; ColumnDefinition colDef = columnDataRow.getDefinition(); if (colDef != null) { String value; - if (colDef.getColumnDataType() - .compareTo("Date") == 0) { + if (colDef.getColumnDataType().compareTo("Date") == 0) { value = rowFirst.getFieldAsDate(colDef .getColumnLocalId()); } else { @@ -317,13 +317,13 @@ public class TabularDataXGridPanel extends ContentPanel { map.put(colDef.getColumnLocalId(), value); ColumnType ctype = colDef.getType(); if (ctype == ColumnType.COLUMNID) { - rowId=value; + rowId = value; } - + } } - if(rowId!=null && !rowId.isEmpty() && map.size()>0){ - r=new RowRaw(rowId,map); + if (rowId != null && !rowId.isEmpty() && map.size() > 0) { + r = new RowRaw(rowId, map); } } @@ -416,7 +416,7 @@ public class TabularDataXGridPanel extends ContentPanel { visibleOnlyColumn = columnLocalId; } - + /** * * @return @@ -424,16 +424,16 @@ public class TabularDataXGridPanel extends ContentPanel { public boolean isErrorNotColored() { 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) { - Log.debug("ErrorNotColored set :"+errorNotColored); + Log.debug("ErrorNotColored set :" + errorNotColored); this.errorNotColored = errorNotColored; } - /** * @@ -610,7 +610,6 @@ public class TabularDataXGridPanel extends ContentPanel { Log.trace("table ready, setting grid up"); mask("Loading table " + definition.getName() + "... "); setupGrid(definition); - this.currentTableDefinition = definition; keys = new HashMap(); for (ColumnDefinition column : definition.getColumnsAsList()) keys.put(column.getColumnLocalId(), column.getKey()); @@ -620,8 +619,7 @@ public class TabularDataXGridPanel extends ContentPanel { protected void doCloseTable() { mask(); grid = null; - this.currentTableDefinition = null; - this.keys.clear(); + keys.clear(); container.clear(); unmask(); } @@ -697,6 +695,29 @@ public class TabularDataXGridPanel extends ContentPanel { columnsConfig); columnModel = checkOnlyColumn(columnModel); + columnModel + .addColumnMoveHandler(new ColumnMoveEvent.ColumnMoveHandler() { + + @Override + public void onColumnMove(ColumnMoveEvent event) { + int columnIndex = event.getIndex(); + @SuppressWarnings("unchecked") + ColumnConfig col = (ColumnConfig) 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) { @@ -751,7 +772,8 @@ public class TabularDataXGridPanel extends ContentPanel { grid.setLoader(loader); grid.setView(liveGridView); grid.setBorders(false); - + grid.setColumnReordering(true); + // TODO disabled editing rows /* * editing = new GridInlineEditing(grid); @@ -777,7 +799,7 @@ public class TabularDataXGridPanel extends ContentPanel { // container.add(grid, new VerticalLayoutData(1, 1, new Margins(0))); - + toolBar = new ToolBar(); toolBar.add(new LiveToolItem(grid)); toolBar.addStyleName(ThemeStyles.getStyle().borderTop()); @@ -840,15 +862,15 @@ public class TabularDataXGridPanel extends ContentPanel { } } else { Log.debug("Use default grid View"); - tableViewConfig= new TableViewConfig(); - Log.debug("Error Not Colored: "+errorNotColored); - DefaultRowStyle rowStyle=new DefaultRowStyle(errorNotColored); - + tableViewConfig = new TableViewConfig(); + Log.debug("Error Not Colored: " + errorNotColored); + DefaultRowStyle rowStyle = new DefaultRowStyle(errorNotColored); + tableViewConfig.setRowStyleProvider(rowStyle); grid.getView().setViewConfig( new TabularDataGridViewConfig(tableViewConfig, tableDefinition)); - // grid.getView().setViewConfig(null); + // grid.getView().setViewConfig(null); } container.forceLayout(); @@ -861,10 +883,7 @@ public class TabularDataXGridPanel extends ContentPanel { }); eventBus.fireEvent(new GridReadyEvent()); - - - - + } /** @@ -953,7 +972,6 @@ public class TabularDataXGridPanel extends ContentPanel { return columnName; } - /** * * @param i @@ -975,30 +993,21 @@ public class TabularDataXGridPanel extends ContentPanel { } return columnLocalId; } - - - /** - * - * @param rows - */ - public void addRow(ArrayList rows) { - // TODO Disabled AddROW - /* - * 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)); } - */ - }; + /* + * Disabled AddROW by direct editing + * + * 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)); } + * + * } + */ } diff --git a/src/main/java/org/gcube/portlets/user/tdwx/client/event/ColumnsReorderingEvent.java b/src/main/java/org/gcube/portlets/user/tdwx/client/event/ColumnsReorderingEvent.java new file mode 100644 index 0000000..eb3913e --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/tdwx/client/event/ColumnsReorderingEvent.java @@ -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" + * g.panichi@isti.cnr.it + * + */ +public class ColumnsReorderingEvent extends GwtEvent { + + public static GwtEvent.Type TYPE = new Type(); + + public interface ColumnsReorderingEventHandler extends EventHandler { + + public void onColumnsReordering(ColumnsReorderingEvent event); + + } + + @Override + public Type 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 + "]"; + } + + +} diff --git a/src/main/java/org/gcube/portlets/user/tdwx/client/rpc/TabularDataXService.java b/src/main/java/org/gcube/portlets/user/tdwx/client/rpc/TabularDataXService.java index 23a3a3f..3173b8f 100644 --- a/src/main/java/org/gcube/portlets/user/tdwx/client/rpc/TabularDataXService.java +++ b/src/main/java/org/gcube/portlets/user/tdwx/client/rpc/TabularDataXService.java @@ -3,6 +3,7 @@ */ 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.model.TableDefinition; 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 getCurrentTableDefinition(int tdSessionId) throws TabularDataXServiceException; - + + public TableDefinition setCurrentTableColumnsReordering(int tdSessionId, ColumnsReorderingConfig columnReorderingConfig) throws TabularDataXServiceException; + public TableDefinition getTableDefinition(TableId id) throws TabularDataXServiceException; public void closeTable(int tdSessionId) throws TabularDataXServiceException; - + + } diff --git a/src/main/java/org/gcube/portlets/user/tdwx/client/rpc/TabularDataXServiceAsync.java b/src/main/java/org/gcube/portlets/user/tdwx/client/rpc/TabularDataXServiceAsync.java index c51050e..9249451 100644 --- a/src/main/java/org/gcube/portlets/user/tdwx/client/rpc/TabularDataXServiceAsync.java +++ b/src/main/java/org/gcube/portlets/user/tdwx/client/rpc/TabularDataXServiceAsync.java @@ -3,6 +3,7 @@ */ 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.TableId; @@ -21,7 +22,9 @@ public interface TabularDataXServiceAsync { void openTable(int tdSessionId, TableId tableId, AsyncCallback callback); void getTableDefinition(TableId id, AsyncCallback callback); - + + void setCurrentTableColumnsReordering(int tdSessionId, ColumnsReorderingConfig columnReorderingConfig, AsyncCallback callback); + void closeTable(int tdSessionId, AsyncCallback callback); } diff --git a/src/main/java/org/gcube/portlets/user/tdwx/server/TabularDataXServiceImpl.java b/src/main/java/org/gcube/portlets/user/tdwx/server/TabularDataXServiceImpl.java index 384626e..fb5ace7 100644 --- a/src/main/java/org/gcube/portlets/user/tdwx/server/TabularDataXServiceImpl.java +++ b/src/main/java/org/gcube/portlets/user/tdwx/server/TabularDataXServiceImpl.java @@ -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.DataSourceXException; 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.TableId; - import com.google.gwt.user.server.rpc.RemoteServiceServlet; /** @@ -39,6 +39,7 @@ public class TabularDataXServiceImpl extends RemoteServiceServlet implements Tab /** * {@inheritDoc} */ + @Override public TableDefinition openTable(int tdSessionId, TableId tableId) throws TabularDataXServiceException { logger.debug("openTable tdSessionId: "+tdSessionId+" tableId: "+tableId); @@ -59,6 +60,7 @@ public class TabularDataXServiceImpl extends RemoteServiceServlet implements Tab /** * {@inheritDoc} */ + @Override public TableDefinition getCurrentTableDefinition(int tdSessionId) throws TabularDataXServiceException { logger.debug("getCurrentTableDefinition tdSessionId: "+tdSessionId); @@ -72,9 +74,30 @@ public class TabularDataXServiceImpl extends RemoteServiceServlet implements Tab } } + + /** * {@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 { logger.debug("getTableDefinition TableId: "+id); @@ -92,6 +115,7 @@ public class TabularDataXServiceImpl extends RemoteServiceServlet implements Tab /** * {@inheritDoc} */ + @Override public void closeTable(int tdSessionId) throws TabularDataXServiceException { try { closeCurrentTable(tdSessionId, false); @@ -101,7 +125,7 @@ public class TabularDataXServiceImpl extends RemoteServiceServlet implements Tab } } - + protected void closeCurrentTable(int tdSessionId, boolean silent) throws DataSourceXException { try { HttpSession httpSession = this.getThreadLocalRequest().getSession(); diff --git a/src/main/java/org/gcube/portlets/user/tdwx/server/datasource/DataSourceX.java b/src/main/java/org/gcube/portlets/user/tdwx/server/datasource/DataSourceX.java index d1e9a09..7548f0a 100644 --- a/src/main/java/org/gcube/portlets/user/tdwx/server/datasource/DataSourceX.java +++ b/src/main/java/org/gcube/portlets/user/tdwx/server/datasource/DataSourceX.java @@ -2,6 +2,7 @@ package org.gcube.portlets.user.tdwx.server.datasource; 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.StaticFilterInformation; import org.gcube.portlets.user.tdwx.shared.model.TableDefinition; @@ -29,7 +30,16 @@ public interface DataSourceX { * if an error occurred retrieving the table definition. */ 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. diff --git a/src/main/java/org/gcube/portlets/user/tdwx/shared/ColumnsReorderingConfig.java b/src/main/java/org/gcube/portlets/user/tdwx/shared/ColumnsReorderingConfig.java new file mode 100644 index 0000000..af054ad --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/tdwx/shared/ColumnsReorderingConfig.java @@ -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: g.panichi@isti.cnr.it + * + */ +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 + "]"; + } + +}