From 33da8115af5055957668c561852abaf175104865 Mon Sep 17 00:00:00 2001 From: Loredana Liccardo Date: Fri, 11 Jul 2014 10:35:26 +0000 Subject: [PATCH] paging implemeneted in a dialog git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/user/databases-manager-portlet@98561 82a268e6-3cf1-43bd-a215-b396298e98cf --- .../client/GWTdbManagerService.java | 7 +- .../client/GWTdbManagerServiceAsync.java | 11 +- .../client/events/EventsTypeEnum.java | 3 +- .../client/events/LoadTablesEvent.java | 33 ++ .../interfaces/LoadTablesEventHandler.java | 9 + .../client/panels/GxtBorderLayoutPanel.java | 418 ++++++++++++++++-- .../client/panels/GxtTreePanel.java | 214 +++++---- .../server/GWTdbManagerServiceImpl.java | 89 ++-- 8 files changed, 628 insertions(+), 156 deletions(-) create mode 100644 src/main/java/org/gcube/portlets/user/databasesmanager/client/events/LoadTablesEvent.java create mode 100644 src/main/java/org/gcube/portlets/user/databasesmanager/client/events/interfaces/LoadTablesEventHandler.java diff --git a/src/main/java/org/gcube/portlets/user/databasesmanager/client/GWTdbManagerService.java b/src/main/java/org/gcube/portlets/user/databasesmanager/client/GWTdbManagerService.java index 1049b26..dcf1e29 100644 --- a/src/main/java/org/gcube/portlets/user/databasesmanager/client/GWTdbManagerService.java +++ b/src/main/java/org/gcube/portlets/user/databasesmanager/client/GWTdbManagerService.java @@ -6,11 +6,13 @@ import java.util.List; import org.gcube.portlets.user.databasesmanager.client.datamodel.FileModel; import org.gcube.portlets.user.databasesmanager.client.datamodel.Result; import org.gcube.portlets.user.databasesmanager.client.datamodel.Row; +import com.extjs.gxt.ui.client.data.PagingLoadConfig; //import org.gcube.portlets.user.dbmanager.client.datamodel.FileModel; //import org.gcube.portlets.user.dbmanager.client.datamodel.Result; //import org.gcube.portlets.user.dbmanager.client.datamodel.Row; +import com.extjs.gxt.ui.client.data.PagingLoadResult; import com.google.gwt.user.client.rpc.RemoteService; import com.google.gwt.user.client.rpc.RemoteServiceRelativePath; @@ -20,8 +22,7 @@ public interface GWTdbManagerService extends RemoteService { List getResource() throws Exception; - List getTables(LinkedHashMap dataInput) - throws Exception; + LinkedHashMap getDBInfo(String resourceName) throws Exception; @@ -44,6 +45,8 @@ public interface GWTdbManagerService extends RemoteService { throws Exception; LinkedHashMap getTableDetails(LinkedHashMap dataInput) throws Exception; + + PagingLoadResult LoadTables(PagingLoadConfig config, LinkedHashMap dataInput) throws Exception; } diff --git a/src/main/java/org/gcube/portlets/user/databasesmanager/client/GWTdbManagerServiceAsync.java b/src/main/java/org/gcube/portlets/user/databasesmanager/client/GWTdbManagerServiceAsync.java index 0f798ab..44b79d6 100644 --- a/src/main/java/org/gcube/portlets/user/databasesmanager/client/GWTdbManagerServiceAsync.java +++ b/src/main/java/org/gcube/portlets/user/databasesmanager/client/GWTdbManagerServiceAsync.java @@ -6,11 +6,13 @@ import java.util.List; import org.gcube.portlets.user.databasesmanager.client.datamodel.FileModel; import org.gcube.portlets.user.databasesmanager.client.datamodel.Result; import org.gcube.portlets.user.databasesmanager.client.datamodel.Row; +import com.extjs.gxt.ui.client.data.PagingLoadConfig; //import org.gcube.portlets.user.dbmanager.client.datamodel.FileModel; //import org.gcube.portlets.user.dbmanager.client.datamodel.Result; //import org.gcube.portlets.user.dbmanager.client.datamodel.Row; +import com.extjs.gxt.ui.client.data.PagingLoadResult; import com.google.gwt.user.client.rpc.AsyncCallback; public interface GWTdbManagerServiceAsync { @@ -20,8 +22,10 @@ public interface GWTdbManagerServiceAsync { void getDBInfo(String resourceName, AsyncCallback> asyncCallback); - void getTables(LinkedHashMap dataInput, - AsyncCallback> callback); +// void getTables(LinkedHashMap dataInput, +// AsyncCallback> callback); + + void getDBSchema(LinkedHashMap dataInput, AsyncCallback> callback); @@ -45,4 +49,7 @@ public interface GWTdbManagerServiceAsync { void randomSample(LinkedHashMap dataInput, AsyncCallback> callback); + void LoadTables(PagingLoadConfig config, LinkedHashMap dataInput, + AsyncCallback> callback); + } diff --git a/src/main/java/org/gcube/portlets/user/databasesmanager/client/events/EventsTypeEnum.java b/src/main/java/org/gcube/portlets/user/databasesmanager/client/events/EventsTypeEnum.java index 6edc01e..81ff8c0 100644 --- a/src/main/java/org/gcube/portlets/user/databasesmanager/client/events/EventsTypeEnum.java +++ b/src/main/java/org/gcube/portlets/user/databasesmanager/client/events/EventsTypeEnum.java @@ -7,6 +7,7 @@ public enum EventsTypeEnum { SHOW_CREATE_TABLE_EVENT, SAMPLING_EVENT, SMART_SAMPLING_EVENT, - RANDOM_SAMPLING_EVENT; + RANDOM_SAMPLING_EVENT, + LOAD_TABLES_EVENT; } \ No newline at end of file diff --git a/src/main/java/org/gcube/portlets/user/databasesmanager/client/events/LoadTablesEvent.java b/src/main/java/org/gcube/portlets/user/databasesmanager/client/events/LoadTablesEvent.java new file mode 100644 index 0000000..dd2946c --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/databasesmanager/client/events/LoadTablesEvent.java @@ -0,0 +1,33 @@ +package org.gcube.portlets.user.databasesmanager.client.events; + +import org.gcube.portlets.user.databasesmanager.client.events.interfaces.LoadTablesEventHandler; +import org.gcube.portlets.user.databasesmanager.client.events.interfaces.RandomSamplingEventHandler; + +import com.google.gwt.event.shared.GwtEvent; +import com.google.gwt.event.shared.GwtEvent.Type; + +public class LoadTablesEvent extends GwtEvent{ + + public static Type TYPE = new Type(); + + @Override + protected void dispatch(LoadTablesEventHandler handler) { + // TODO Auto-generated method stub + + handler.onLoadTables(this); + + } + + @Override + public Type getAssociatedType() { + // TODO Auto-generated method stub + return TYPE; + } + + public EventsTypeEnum getKey() { + + // TODO Auto-generated method stub + return EventsTypeEnum.LOAD_TABLES_EVENT; + } + +} diff --git a/src/main/java/org/gcube/portlets/user/databasesmanager/client/events/interfaces/LoadTablesEventHandler.java b/src/main/java/org/gcube/portlets/user/databasesmanager/client/events/interfaces/LoadTablesEventHandler.java new file mode 100644 index 0000000..553cbdc --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/databasesmanager/client/events/interfaces/LoadTablesEventHandler.java @@ -0,0 +1,9 @@ +package org.gcube.portlets.user.databasesmanager.client.events.interfaces; + +import org.gcube.portlets.user.databasesmanager.client.events.LoadTablesEvent; + +import com.google.gwt.event.shared.EventHandler; + +public interface LoadTablesEventHandler extends EventHandler{ + public void onLoadTables(LoadTablesEvent loadTablesEvent); +} diff --git a/src/main/java/org/gcube/portlets/user/databasesmanager/client/panels/GxtBorderLayoutPanel.java b/src/main/java/org/gcube/portlets/user/databasesmanager/client/panels/GxtBorderLayoutPanel.java index a69d56c..839feeb 100644 --- a/src/main/java/org/gcube/portlets/user/databasesmanager/client/panels/GxtBorderLayoutPanel.java +++ b/src/main/java/org/gcube/portlets/user/databasesmanager/client/panels/GxtBorderLayoutPanel.java @@ -3,6 +3,7 @@ package org.gcube.portlets.user.databasesmanager.client.panels; import java.util.ArrayList; import java.util.LinkedHashMap; import java.util.List; +import java.util.Map; import java.util.Set; import java.util.logging.Level; import java.util.logging.Logger; @@ -12,12 +13,14 @@ import org.gcube.portlets.user.databasesmanager.client.datamodel.FileModel; import org.gcube.portlets.user.databasesmanager.client.datamodel.Result; import org.gcube.portlets.user.databasesmanager.client.datamodel.Row; import org.gcube.portlets.user.databasesmanager.client.datamodel.SubmitQueryData; +import org.gcube.portlets.user.databasesmanager.client.events.LoadTablesEvent; import org.gcube.portlets.user.databasesmanager.client.events.RandomSamplingEvent; import org.gcube.portlets.user.databasesmanager.client.events.SamplingEvent; import org.gcube.portlets.user.databasesmanager.client.events.SelectedItemEvent; import org.gcube.portlets.user.databasesmanager.client.events.ShowCreateTableEvent; import org.gcube.portlets.user.databasesmanager.client.events.SmartSamplingEvent; import org.gcube.portlets.user.databasesmanager.client.events.SubmitQueryEvent; +import org.gcube.portlets.user.databasesmanager.client.events.interfaces.LoadTablesEventHandler; import org.gcube.portlets.user.databasesmanager.client.events.interfaces.RandomSamplingEventHandler; import org.gcube.portlets.user.databasesmanager.client.events.interfaces.SamplingEventHandler; import org.gcube.portlets.user.databasesmanager.client.events.interfaces.SelectedItemEventHandler; @@ -40,15 +43,29 @@ import com.extjs.gxt.ui.client.widget.grid.ColumnConfig; import com.extjs.gxt.ui.client.widget.grid.ColumnModel; import com.extjs.gxt.ui.client.widget.grid.EditorGrid; import com.extjs.gxt.ui.client.widget.grid.Grid; +import com.extjs.gxt.ui.client.widget.grid.LiveGridView; import com.extjs.gxt.ui.client.widget.layout.BorderLayout; import com.extjs.gxt.ui.client.widget.layout.BorderLayoutData; import com.extjs.gxt.ui.client.widget.layout.FitLayout; import com.extjs.gxt.ui.client.widget.layout.RowData; +import com.extjs.gxt.ui.client.widget.toolbar.FillToolItem; +import com.extjs.gxt.ui.client.widget.toolbar.LiveToolItem; +import com.extjs.gxt.ui.client.widget.toolbar.PagingToolBar; +import com.extjs.gxt.ui.client.widget.toolbar.ToolBar; import com.google.gwt.event.shared.HandlerManager; import com.google.gwt.user.client.Window; import com.google.gwt.user.client.rpc.AsyncCallback; +import com.extjs.gxt.ui.client.data.BasePagingLoadConfig; +import com.extjs.gxt.ui.client.data.BasePagingLoader; +import com.extjs.gxt.ui.client.data.PagingLoadConfig; +import com.extjs.gxt.ui.client.data.PagingLoadResult; +import com.extjs.gxt.ui.client.data.PagingLoader; +import com.extjs.gxt.ui.client.data.RpcProxy; +import com.extjs.gxt.ui.client.event.Events; +import com.extjs.gxt.ui.client.event.GridEvent; import com.extjs.gxt.ui.client.event.Listener; import com.extjs.gxt.ui.client.event.MessageBoxEvent; +import com.extjs.gxt.ui.client.data.BasePagingLoadResult; //class that represents the container of all components public class GxtBorderLayoutPanel extends ContentPanel { @@ -76,6 +93,8 @@ public class GxtBorderLayoutPanel extends ContentPanel { // variable that keeps track of the managed event private boolean submitQueryEventManaged = false; + +// private PagingToolBar toolBar = new PagingToolBar(100); public GxtBorderLayoutPanel(HandlerManager eBus, GWTdbManagerServiceAsync service) throws Exception { @@ -150,6 +169,10 @@ public class GxtBorderLayoutPanel extends ContentPanel { centerUpper.setLayout(new FitLayout()); centerUpper.setHeading("Database Information"); centerUpper.setScrollMode(Scroll.NONE); + +// centerUpper.setBottomComponent(toolBar); +// toolBar.hide(); + // CENTER BOTTOM @@ -297,6 +320,17 @@ public class GxtBorderLayoutPanel extends ContentPanel { }); + eventBus.addHandler(LoadTablesEvent.TYPE, new LoadTablesEventHandler() { + + @Override + public void onLoadTables(LoadTablesEvent loadTablesEvent) { + // TODO Auto-generated method stub + + loadTables(); + + } + }); + eventBus.addHandler(SubmitQueryEvent.TYPE, new SubmitQueryEventHandler() { @@ -379,6 +413,306 @@ public class GxtBorderLayoutPanel extends ContentPanel { } + private void loadTables() { + + // System.out.println("Start RPC - loadTables"); + + rootLogger.log(Level.SEVERE, "Start RPC - loadTables"); + + // to mask the entire content panel + + // this.mask("Loading", "x-mask-loading"); + + // get the selected item + + List data = treePanel.getTreePanel().getSelectionModel() + .getSelectedItems(); + + FileModel element = data.get(0); + + // recover data inputs + + final LinkedHashMap dataInput = new LinkedHashMap(); + + // check if the table has an associated schema + + String resource = ""; + String database = ""; + String schema = ""; + + if (element.isDatabase()) { // the selected item is a database + + rootLogger.log(Level.INFO, "element is a database "); + + database = element.getName(); + resource = treePanel.getTreeStore().getParent(element).getName(); + + dataInput.put("ResourceName", resource); + dataInput.put("DatabaseName", database); + dataInput.put("SchemaName", ""); + + } else { // the selected item is a schema + + rootLogger.log(Level.INFO, "element is a schema "); + + FileModel db = treePanel.getTreeStore().getParent(element); + database = db.getName(); + + resource = treePanel.getTreeStore().getParent(db).getName(); + schema = element.getName(); + + dataInput.put("ResourceName", resource); + dataInput.put("DatabaseName", database); + dataInput.put("SchemaName", schema); + + // dataInput.put("ResourceName", resource.getName()); + // dataInput.put("DatabaseName", database.getName()); + // dataInput.put("SchemaName", element.getName()); + + } + + // FileModel database = store.getParent(element); + // FileModel resource = store.getParent(database); + // + // dataInput.put("ResourceName", resource.getName()); + // dataInput.put("DatabaseName", database.getName()); + + // if (element.getDatabaseType().equals(ConstantsPortlet.POSTGRES)){ + // + // + // } + // else{ + // dataInput.put("SchemaName", ""); + // } + + // System.out.println("schema name: " + element.getName()); + + // rootLogger.log(Level.INFO, "ResourceName: " + resource.getName()); + // rootLogger.log(Level.INFO, "DatabaseName: " + database.getName()); + // rootLogger.log(Level.INFO, "SchemaName: " + element.getName()); + + rootLogger.log(Level.INFO, "ResourceName: " + resource); + rootLogger.log(Level.INFO, "DatabaseName: " + database); + rootLogger.log(Level.INFO, "SchemaName: " + schema); + + // FileModel schema; + // FileModel database; + // FileModel resource; + // + // if (treePanel.getTreeStore().getParent(selectedItem).isDatabase()) { + // + // // the table has not a schema + // + // database = treePanel.getTreeStore().getParent(selectedItem); + // resource = treePanel.getTreeStore().getParent(database); + // + // dataInput.put("ResourceName", resource.getName()); + // dataInput.put("DatabaseName", database.getName()); + // dataInput.put("SchemaName", ""); + // // dataInput.put("TableName", selectedItem.getName()); + // + // rootLogger.log(Level.INFO, "ResourceName: " + resource.getName()); + // rootLogger.log(Level.INFO, "DatabaseName: " + database.getName()); + // rootLogger.log(Level.INFO, "SchemaName: " + selectedItem.getName()); + // + // // schema = treePanel.getTreeStore().getParent(selectedItem); + // // database = treePanel.getTreeStore().getParent(schema); + // // resource = treePanel.getTreeStore().getParent(database); + // // + // // dataInput.put("ResourceName", resource.getName()); + // // dataInput.put("DatabaseName", database.getName()); + // // dataInput.put("SchemaName", schema.getName()); + // // dataInput.put("TableName", selectedItem.getName()); + // // + // // rootLogger.log(Level.INFO, "ResourceName: " + + // // resource.getName()); + // // rootLogger.log(Level.INFO, "DatabaseName: " + + // // database.getName()); + // // rootLogger.log(Level.INFO, "SchemaName: " + schema.getName()); + // // rootLogger.log(Level.INFO, "SchemaName: " + + // // selectedItem.getName()); + // + // } else { + // // the table has a schema + // + // schema = treePanel.getTreeStore().getParent(selectedItem); + // database = treePanel.getTreeStore().getParent(schema); + // resource = treePanel.getTreeStore().getParent(database); + // + // dataInput.put("ResourceName", resource.getName()); + // dataInput.put("DatabaseName", database.getName()); + // dataInput.put("SchemaName", schema.getName()); + // // dataInput.put("TableName", selectedItem.getName()); + // + // rootLogger.log(Level.INFO, "ResourceName: " + resource.getName()); + // rootLogger.log(Level.INFO, "DatabaseName: " + database.getName()); + // rootLogger.log(Level.INFO, "SchemaName: " + schema.getName()); + // // rootLogger.log(Level.INFO, "SchemaName: " + + // selectedItem.getName()); + // + // // the table has not a schema + // // database = treePanel.getTreeStore().getParent(selectedItem); + // // resource = treePanel.getTreeStore().getParent(database); + // // + // // dataInput.put("ResourceName", resource.getName()); + // // dataInput.put("DatabaseName", database.getName()); + // // dataInput.put("SchemaName", ""); + // // dataInput.put("TableName", selectedItem.getName()); + // // + // // rootLogger.log(Level.INFO, "ResourceName: " + + // // resource.getName()); + // // rootLogger.log(Level.INFO, "DatabaseName: " + + // // database.getName()); + // // rootLogger.log(Level.INFO, "SchemaName: " + ""); + // // rootLogger.log(Level.INFO, "SchemaName: " + + // // selectedItem.getName()); + // } + + // create RpcProxy object to use the load configuration + + RpcProxy> proxy = new RpcProxy>() { + + @Override + protected void load(Object loadConfig, + AsyncCallback> callback) { + + RPCservice.LoadTables((PagingLoadConfig) loadConfig, dataInput, + callback); + // TODO Auto-generated method stub + + } + }; + + // loader to load page enabled set of data + + final PagingLoader> loader = new BasePagingLoader>( + proxy); + // loader.setRemoteSort(true); + + // to create the lsitstore using the loader + + ListStore result = new ListStore(loader); + + // bind the loader with a PagingToolBar. + final PagingToolBar toolBar = new PagingToolBar(100); + toolBar.bind(loader); + + // craete the column configuration + ColumnModel cm = createColumnModelForTables(); + + // create the grid with a result list and the column model + + final Grid grid = new Grid(result, cm); + + grid.setStateId("pagingGridExample"); + grid.setStateful(true); + grid.addListener(Events.Attach, new Listener>() { + public void handleEvent(GridEvent be) { + PagingLoadConfig config = new BasePagingLoadConfig(); + + config.setOffset(0); + config.setLimit(100); + + Map state = grid.getState(); + if (state.containsKey("offset")) { + int offset = (Integer) state.get("offset"); + int limit = (Integer) state.get("limit"); + config.setOffset(offset); + config.setLimit(limit); + } + // if (state.containsKey("sortField")) { + // config.setSortField((String) state.get("sortField")); + // config.setSortDir(SortDir.valueOf((String) state + // .get("sortDir"))); + // } + loader.load(config); + } + }); +// grid.setLoadMask(true); + grid.setBorders(true); + // grid.setAutoExpandColumn("comments"); + // grid.setStyleAttribute("borderTop", "none"); +// grid.setStripeRows(true); + + Dialog tablesLoaded = new Dialog(); + tablesLoaded.setLayout(new FitLayout()); + tablesLoaded.setHeading("Result"); + tablesLoaded.setResizable(false); + + tablesLoaded.setModal(true); + tablesLoaded.setBlinkModal(true); + + tablesLoaded.setSize(600, 400); + tablesLoaded.setScrollMode(Scroll.NONE); + tablesLoaded.setHideOnButtonClick(true); + tablesLoaded.setMaximizable(true); +// + tablesLoaded.setBottomComponent(toolBar); + + // aggiungere la toolbart + +// centerUpper.setBottomComponent(toolBar); + +// LiveGridView liveView = new LiveGridView(); +// liveView.setEmptyText("No rows available on the server."); +// liveView.setRowHeight(32); +// grid.setView(liveView); +// +// ToolBar toolBar = new ToolBar(); +// toolBar.add(new FillToolItem()); +// +// LiveToolItem item = new LiveToolItem(); +// item.bindGrid(grid); +// +// toolBar.add(item); +// tablesLoaded.setBottomComponent(toolBar); + + +// centerUpper.removeAll(); + + +// centerUpper.setBottomComponent(toolBar); + +// ContentPanel tablesLoaded = new ContentPanel(); +// tablesLoaded.setLayout(new FitLayout()); +// tablesLoaded.setBottomComponent(toolBar); +// tablesLoaded.add(grid); + +// centerUpper.removeAll(); + +// centerUpper.add(tablesLoaded); +// toolBar.show(); +// centerUpper.setBottomComponent(toolBar); +// centerUpper.add(grid); +// centerUpper.layout(true); + + +// centerUpper.show(); + + // RowData d = new RowData(.5, 1); + // d.setMargins(new Margins(6)); + + // tablesLoaded.add(grid, d); + + tablesLoaded.add(grid); + + tablesLoaded.show(); + + // ContentPanel panel = new ContentPanel(); + // panel.setFrame(true); + // panel.setCollapsible(true); + // panel.setAnimCollapse(false); + // + // panel.setHeading("Paging Grid"); + // panel.setLayout(new FitLayout()); + // panel.add(grid); + // panel.setSize(600, 350); + // panel.setBottomComponent(toolBar); + // grid.getAriaSupport().setLabelledBy(panel.getId()); + // add(panel); + + } + private void submitQuery() { // System.out.println("Start RPC - submitQuery"); @@ -577,7 +911,7 @@ public class GxtBorderLayoutPanel extends ContentPanel { this.mask("Loading", "x-mask-loading"); // System.out.println("Start RPC - submitQuery"); - + final GxtBorderLayoutPanel obj = this; rootLogger.log(Level.SEVERE, "Start RPC - sample"); @@ -684,8 +1018,8 @@ public class GxtBorderLayoutPanel extends ContentPanel { MessageBox.alert("Error ", "
Message:" + caught.getMessage(), null); - - if (obj.isMasked()){ + + if (obj.isMasked()) { obj.unmask(); } @@ -722,7 +1056,7 @@ public class GxtBorderLayoutPanel extends ContentPanel { // to mask the entire content panel this.mask("Loading", "x-mask-loading"); - + final GxtBorderLayoutPanel obj = this; // System.out.println("Start RPC - submitQuery"); @@ -832,8 +1166,8 @@ public class GxtBorderLayoutPanel extends ContentPanel { MessageBox.alert("Error ", "
Message:" + caught.getMessage(), null); - - if (obj.isMasked()){ + + if (obj.isMasked()) { obj.unmask(); } @@ -1310,6 +1644,37 @@ public class GxtBorderLayoutPanel extends ContentPanel { return new ColumnModel(configs); } + private ColumnModel createColumnModelForTables() { + + List configs = new ArrayList(); + + ColumnConfig column = new ColumnConfig(); + column.setId("index"); + column.setHeader("Index"); + column.setWidth(100); + + configs.add(column); + + column = new ColumnConfig(); + column.setId("value"); + column.setHeader("Name"); + column.setWidth(600); + + // column2.setSortable(false); + + TextField textValue = new TextField(); + // text.setAllowBlank(false); + column.setEditor(new CellEditor(textValue)); + + configs.add(column); + + // ListStore store = new ListStore(); + // store.add(result); + + return new ColumnModel(configs); + + } + private void displayDBInfo(FileModel element) { // System.out.println("GxtBorderLayout->displaying info"); @@ -1319,37 +1684,38 @@ public class GxtBorderLayoutPanel extends ContentPanel { // LinkedHashMap data = element.getDBInfo(); List dataDB = element.getDBInfo(); - - if (dataDB!=null){ - // System.out.println("GxtBorderLayout->size info: " + dataDB.size()); + if (dataDB != null) { - rootLogger.log(Level.INFO, "info size: " + dataDB.size()); + // System.out.println("GxtBorderLayout->size info: " + + // dataDB.size()); - ListStore store = new ListStore(); - store.add(dataDB); + rootLogger.log(Level.INFO, "info size: " + dataDB.size()); - // Grid grid = new Grid(store, - // createColumnModelForDBInfo(dataDB)); + ListStore store = new ListStore(); + store.add(dataDB); - EditorGrid grid = new EditorGrid(store, - createColumnModelForDBInfo(dataDB)); + // Grid grid = new Grid(store, + // createColumnModelForDBInfo(dataDB)); - // grid.setAutoExpandColumn("name"); - grid.setBorders(true); + EditorGrid grid = new EditorGrid(store, + createColumnModelForDBInfo(dataDB)); - // grid.setAutoWidth(true); + // grid.setAutoExpandColumn("name"); + grid.setBorders(true); - // RowData data = new RowData(.5, 1); - // data.setMargins(new Margins(6)); + // grid.setAutoWidth(true); - centerUpper.removeAll(); + // RowData data = new RowData(.5, 1); + // data.setMargins(new Margins(6)); - // centerUpper.add(grid, data); + centerUpper.removeAll(); + + // centerUpper.add(grid, data); + + centerUpper.add(grid); + centerUpper.layout(true); - centerUpper.add(grid); - centerUpper.layout(true); - } } diff --git a/src/main/java/org/gcube/portlets/user/databasesmanager/client/panels/GxtTreePanel.java b/src/main/java/org/gcube/portlets/user/databasesmanager/client/panels/GxtTreePanel.java index a8c4357..092e950 100644 --- a/src/main/java/org/gcube/portlets/user/databasesmanager/client/panels/GxtTreePanel.java +++ b/src/main/java/org/gcube/portlets/user/databasesmanager/client/panels/GxtTreePanel.java @@ -10,6 +10,7 @@ import java.util.logging.Logger; import org.gcube.portlets.user.databasesmanager.client.GWTdbManagerServiceAsync; import org.gcube.portlets.user.databasesmanager.client.datamodel.FileModel; import org.gcube.portlets.user.databasesmanager.client.datamodel.Result; +import org.gcube.portlets.user.databasesmanager.client.events.LoadTablesEvent; import org.gcube.portlets.user.databasesmanager.client.events.SelectedItemEvent; import org.gcube.portlets.user.databasesmanager.client.utils.ConstantsPortlet; import com.extjs.gxt.ui.client.Style.SelectionMode; @@ -706,6 +707,9 @@ public class GxtTreePanel extends LayoutContainer { } private void loadTables(final FileModel element) { + + if (treePanel.isMasked()) + treePanel.unmask(); // System.out.println("Start RPC - getTables"); @@ -770,6 +774,8 @@ public class GxtTreePanel extends LayoutContainer { String schema = ""; if (element.isDatabase()) { // the selected item is a database + + rootLogger.log(Level.INFO, "element is a database "); database = element.getName(); resource = store.getParent(element).getName(); @@ -779,6 +785,8 @@ public class GxtTreePanel extends LayoutContainer { dataInput.put("SchemaName", ""); } else { // the selected item is a schema + + rootLogger.log(Level.INFO, "element is a schema "); FileModel db = store.getParent(element); database = db.getName(); @@ -824,102 +832,116 @@ public class GxtTreePanel extends LayoutContainer { // System.out.println(parent.getName()); // System.out.println(element.getName()); - // call remote service - - RPCservice.getTables(dataInput, new AsyncCallback>() { - - @Override - public void onFailure(Throwable caught) { - // Window.alert(caught.getMessage()); - // System.out.println("FAILURE"); - rootLogger.log(Level.SEVERE, "FAILURE RPC getTables"); - - // no tables are available (the schema has not table) - if (caught.getMessage().equals( - "java.lang.Exception: Result not available")) { - - element.setIsExpanded(false); - - treePanel.setExpanded(element, false); - - element.setIsLoaded(true); - - if (treePanel.isMasked()) - treePanel.unmask(); - - treePanel.enableEvents(true); - - } - - // MessageBox.alert("Error ","
Message:"+caught.getMessage(), - // null); - - } - - @Override - public void onSuccess(List result) { - - - - // System.out.println("SUCCESS"); - - rootLogger.log(Level.SEVERE, "SUCCESS RPC getTables"); - - if (result.size() == 0) { // the database has not tables - - // System.out.println("the database has not tables"); - - rootLogger.log(Level.SEVERE, "the database has not tables"); - - // loadTables(element); - element.setIsExpanded(false); - - treePanel.setExpanded(element, false); - - } else { - - for (int i = 0; i < result.size(); i++) { - - result.get(i).setIsTable(true); - - result.get(i).setIsExpanded(false); - - result.get(i).setIsLoaded(true); - - // result.get(i).setIsSchema(false); - - // element.setIsLoaded(true); - - // ppritn check - // System.out.println(result.get(i).getName()); - - // rootLogger.log(Level.INFO, "table: " - // + result.get(i).getName()); - - } - - // int numChildrenFolder = store.getChildCount(element); - - // if (numChildrenFolder == 0) { - - addChildren(element, result); - - // } - } - - element.setIsLoaded(true); - - if (treePanel.isMasked()) - treePanel.unmask(); - - treePanel.enableEvents(true); - - } - }); - - // System.out.println("End RPC - getTables"); - - rootLogger.log(Level.SEVERE, "End RPC getTables"); +// // call remote service +// +// RPCservice.getTables(dataInput, new AsyncCallback>() { +// +// @Override +// public void onFailure(Throwable caught) { +// // Window.alert(caught.getMessage()); +// // System.out.println("FAILURE"); +// rootLogger.log(Level.SEVERE, "FAILURE RPC getTables"); +// +// // no tables are available (the schema has not table) +// if (caught.getMessage().equals( +// "java.lang.Exception: Result not available")) { +// +// element.setIsExpanded(false); +// +// treePanel.setExpanded(element, false); +// +// element.setIsLoaded(true); +// +// if (treePanel.isMasked()) +// treePanel.unmask(); +// +// treePanel.enableEvents(true); +// +// } +// +// // MessageBox.alert("Error ","
Message:"+caught.getMessage(), +// // null); +// +// } +// +// @Override +// public void onSuccess(List result) { +// +// +// +// // System.out.println("SUCCESS"); +// +// rootLogger.log(Level.SEVERE, "SUCCESS RPC getTables"); +// +// if (result.size() == 0) { // the database has not tables +// +// // System.out.println("the database has not tables"); +// +// rootLogger.log(Level.SEVERE, "the database has not tables"); +// +// // loadTables(element); +//// element.setIsExpanded(false); +//// +//// treePanel.setExpanded(element, false); +// +// } else { +// +// for (int i = 0; i < result.size(); i++) { +// +// result.get(i).setIsTable(true); +// +//// result.get(i).setIsExpanded(false); +// +// result.get(i).setIsLoaded(true); +// +// // result.get(i).setIsSchema(false); +// +// // element.setIsLoaded(true); +// +// // ppritn check +// // System.out.println(result.get(i).getName()); +// +// // rootLogger.log(Level.INFO, "table: " +// // + result.get(i).getName()); +// +// } +// +// // int numChildrenFolder = store.getChildCount(element); +// +// // if (numChildrenFolder == 0) { +// +// +// //addChildren(element, result); +// +// // +// +// // } +// } +// +// element.setIsLoaded(true); +// +// element.setIsExpanded(false); +// treePanel.setExpanded(element, false); +// +// if (treePanel.isMasked()) +// treePanel.unmask(); +// +// treePanel.enableEvents(true); +// +// //fire event +// eventBus.fireEvent(new LoadTablesEvent()); +// +// +// +// } +// }); +// +// //System.out.println("End RPC - getTables"); +// +// rootLogger.log(Level.SEVERE, "End RPC getTables"); + + //fire event to manage the tables loading + eventBus.fireEvent(new LoadTablesEvent()); } diff --git a/src/main/java/org/gcube/portlets/user/databasesmanager/server/GWTdbManagerServiceImpl.java b/src/main/java/org/gcube/portlets/user/databasesmanager/server/GWTdbManagerServiceImpl.java index 2ad4138..5672c0d 100644 --- a/src/main/java/org/gcube/portlets/user/databasesmanager/server/GWTdbManagerServiceImpl.java +++ b/src/main/java/org/gcube/portlets/user/databasesmanager/server/GWTdbManagerServiceImpl.java @@ -54,6 +54,9 @@ import org.gcube.portlets.user.databasesmanager.server.util.SessionUtil; //import org.gcube.portlets.user.dbmanager.client.datamodel.Row; //import org.gcube.portlets.user.dbmanager.server.util.SessionUtil; +import com.extjs.gxt.ui.client.data.BasePagingLoadResult; +import com.extjs.gxt.ui.client.data.PagingLoadConfig; +import com.extjs.gxt.ui.client.data.PagingLoadResult; import com.google.gwt.user.server.rpc.RemoteServiceServlet; import com.thoughtworks.xstream.XStream; @@ -189,9 +192,8 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements // System.out.println(inputParameters.get(i).getName()); inputParameters.get(i).setValue(resourceName); - - -// rootLogger.log(Level.INFO, "ResourceName: " + resourceName); + + // rootLogger.log(Level.INFO, "ResourceName: " + resourceName); rootLogger.log(Level.INFO, inputParameters.get(i).getName()); } @@ -270,18 +272,17 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements // System.out.println(inputParameters.get(i).getName()); rootLogger.log(Level.INFO, inputParameters.get(i).getName()); - + } inputParameters.get(0).setValue(dataInput.get("ResourceName")); inputParameters.get(1).setValue(dataInput.get("DatabaseName")); - - rootLogger.log(Level.INFO, "ResourceName: " + dataInput.get("ResourceName")); - rootLogger.log(Level.INFO, "DatabaseName: " + dataInput.get("DatabaseName")); + rootLogger.log(Level.INFO, + "ResourceName: " + dataInput.get("ResourceName")); - - + rootLogger.log(Level.INFO, + "DatabaseName: " + dataInput.get("DatabaseName")); String computationId = startComputation(algorithmId, inputParameters); @@ -298,7 +299,7 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements FileModel obj = new FileModel(outputMap.get(String.valueOf(i))); -// obj.setIsSchema(true); + // obj.setIsSchema(true); // obj.setIsLoaded(true); @@ -310,15 +311,14 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements } - @Override - public List getTables(LinkedHashMap dataInput) + private List getTables(LinkedHashMap dataInput) throws Exception { List inputParameters = new ArrayList(); // List outputParameters = new ArrayList(); - List outputParameters = new ArrayList(); + List outputParameters = new ArrayList(); // get list of algorithms @@ -361,12 +361,13 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements inputParameters.get(0).setValue(dataInput.get("ResourceName")); inputParameters.get(1).setValue(dataInput.get("DatabaseName")); inputParameters.get(2).setValue(dataInput.get("SchemaName")); - - rootLogger.log(Level.SEVERE, "ResourceName: " + dataInput.get("ResourceName")); - rootLogger.log(Level.SEVERE, "DatabaseName: " + dataInput.get("DatabaseName")); - rootLogger.log(Level.SEVERE, "SchemaName: " + dataInput.get("SchemaName")); - - + + rootLogger.log(Level.SEVERE, + "ResourceName: " + dataInput.get("ResourceName")); + rootLogger.log(Level.SEVERE, + "DatabaseName: " + dataInput.get("DatabaseName")); + rootLogger.log(Level.SEVERE, + "SchemaName: " + dataInput.get("SchemaName")); // System.out.println("size outputMap pre computation: " // + outputMap.size()); @@ -380,20 +381,23 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements rootLogger.log(Level.SEVERE, "output data retrieved"); rootLogger.log(Level.SEVERE, "output data size: " + outputMap.size()); -// System.out.println("size outputMap: " + outputMap.size()); + // System.out.println("size outputMap: " + outputMap.size()); for (int i = 0; i < outputMap.size(); i++) { // outputParameters.add(outputKey.get(String.valueOf(i)) + " " // + outputMap.get(String.valueOf(i))); - FileModel obj = new FileModel(outputMap.get(String.valueOf(i))); + // FileModel obj = new FileModel(outputMap.get(String.valueOf(i))); // obj.setIsLoaded(true); // obj.setIsTable(true); - outputParameters.add(obj); + Result row = new Result(String.valueOf(i), outputMap.get(String + .valueOf(i))); + + outputParameters.add(row); } @@ -401,6 +405,35 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements } + @Override + public PagingLoadResult LoadTables(PagingLoadConfig config, + LinkedHashMap dataInput) throws Exception { + // TODO Auto-generated method stub + + // get tables + List result = getTables(dataInput); + + // Create a sublist and add data to list according + // to the limit and offset value of the config + + ArrayList sublist = new ArrayList(); + + int start = config.getOffset(); + int limit = result.size(); + + if (config.getLimit() > 0) { + limit = Math.min(start + config.getLimit(), limit); + } + + for (int i = config.getOffset(); i < limit; i++) { + sublist.add(result.get(i)); + } + + return new BasePagingLoadResult(sublist, + config.getOffset(), result.size()); + + } + @Override public List submitQuery(LinkedHashMap dataDB, String query, boolean valueReadOnlyQuery, @@ -465,8 +498,9 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements inputParameters.get(0).setValue(dataDB.get("ResourceName")); inputParameters.get(1).setValue(dataDB.get("DatabaseName")); - - rootLogger.log(Level.INFO, "ResourceName " + dataDB.get("ResourceName")); + + rootLogger + .log(Level.INFO, "ResourceName " + dataDB.get("ResourceName")); rootLogger.log(Level.INFO, "DatabaseName" + dataDB.get("DatabaseName")); inputParameters.get(2).setValue(String.valueOf(valueReadOnlyQuery)); @@ -599,8 +633,7 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements @Override public List smartSample(LinkedHashMap dataInput) throws Exception { - - + List inputParameters = new ArrayList(); // sample result @@ -674,7 +707,7 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements return output; } - + @Override public List randomSample(LinkedHashMap dataInput) throws Exception { @@ -1297,6 +1330,4 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements } - - }