remote search implemented in the paging for the Tablelist
git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/user/databases-manager-portlet@98692 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
421387df68
commit
550dc39207
|
@ -46,7 +46,8 @@ public interface GWTdbManagerService extends RemoteService {
|
|||
|
||||
LinkedHashMap<String, FileModel> getTableDetails(LinkedHashMap<String, String> dataInput) throws Exception;
|
||||
|
||||
PagingLoadResult<Result> LoadTables(PagingLoadConfig config, LinkedHashMap<String, String> dataInput) throws Exception;
|
||||
PagingLoadResult<Result> LoadTables(PagingLoadConfig config, LinkedHashMap<String, String> dataInput, boolean SearchTable, String keyword) throws Exception;
|
||||
|
||||
// PagingLoadResult<Result> SearchTable(PagingLoadConfig config, LinkedHashMap<String, String> dataInput, String keyword) throws Exception;
|
||||
|
||||
}
|
||||
|
|
|
@ -49,7 +49,10 @@ public interface GWTdbManagerServiceAsync {
|
|||
void randomSample(LinkedHashMap<String, String> dataInput,
|
||||
AsyncCallback<List<Result>> callback);
|
||||
|
||||
void LoadTables(PagingLoadConfig config, LinkedHashMap<String, String> dataInput,
|
||||
void LoadTables(PagingLoadConfig config, LinkedHashMap<String, String> dataInput, boolean SearchTable, String keyword,
|
||||
AsyncCallback<PagingLoadResult<Result>> callback);
|
||||
|
||||
// void SearchTable(PagingLoadConfig config, LinkedHashMap<String, String> dataInput, String keyword,
|
||||
// AsyncCallback<PagingLoadResult<Result>> callback);
|
||||
|
||||
}
|
||||
|
|
|
@ -35,13 +35,16 @@ import com.extjs.gxt.ui.client.Style.Scroll;
|
|||
import com.extjs.gxt.ui.client.Style.SelectionMode;
|
||||
import com.extjs.gxt.ui.client.Style.SortDir;
|
||||
import com.extjs.gxt.ui.client.store.ListStore;
|
||||
import com.extjs.gxt.ui.client.store.Store;
|
||||
import com.extjs.gxt.ui.client.util.Margins;
|
||||
import com.extjs.gxt.ui.client.widget.ContentPanel;
|
||||
import com.extjs.gxt.ui.client.widget.Dialog;
|
||||
import com.extjs.gxt.ui.client.widget.LayoutContainer;
|
||||
import com.extjs.gxt.ui.client.widget.MessageBox;
|
||||
import com.extjs.gxt.ui.client.widget.button.Button;
|
||||
import com.extjs.gxt.ui.client.widget.form.StoreFilterField;
|
||||
import com.extjs.gxt.ui.client.widget.form.TextField;
|
||||
import com.extjs.gxt.ui.client.widget.form.TriggerField;
|
||||
import com.extjs.gxt.ui.client.widget.grid.CellEditor;
|
||||
import com.extjs.gxt.ui.client.widget.grid.ColumnConfig;
|
||||
import com.extjs.gxt.ui.client.widget.grid.ColumnModel;
|
||||
|
@ -54,12 +57,14 @@ 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.LabelToolItem;
|
||||
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.google.gwt.user.client.ui.TabLayoutPanel;
|
||||
import com.extjs.gxt.ui.client.data.BasePagingLoadConfig;
|
||||
import com.extjs.gxt.ui.client.data.BasePagingLoader;
|
||||
import com.extjs.gxt.ui.client.data.LoadEvent;
|
||||
|
@ -78,6 +83,7 @@ import com.extjs.gxt.ui.client.event.SelectionChangedListener;
|
|||
import com.extjs.gxt.ui.client.event.SelectionListener;
|
||||
import com.extjs.gxt.ui.client.event.WindowEvent;
|
||||
import com.extjs.gxt.ui.client.data.BasePagingLoadResult;
|
||||
import com.extjs.gxt.ui.client.widget.form.TwinTriggerField;
|
||||
|
||||
//class that represents the container of all components
|
||||
public class GxtBorderLayoutPanel extends ContentPanel {
|
||||
|
@ -112,6 +118,10 @@ public class GxtBorderLayoutPanel extends ContentPanel {
|
|||
|
||||
private String selectedTable = null;
|
||||
private FileModel table = new FileModel("");
|
||||
|
||||
//variables to perform the table search
|
||||
private String keyword = "";
|
||||
private boolean startSearchTable = false;
|
||||
|
||||
// private Grid<Result> grid;
|
||||
|
||||
|
@ -310,7 +320,7 @@ public class GxtBorderLayoutPanel extends ContentPanel {
|
|||
|
||||
// display information about the selected database
|
||||
displayDBInfo(data.get(0));
|
||||
|
||||
|
||||
}
|
||||
|
||||
// // display the table name in the right panel when a
|
||||
|
@ -644,9 +654,14 @@ public class GxtBorderLayoutPanel extends ContentPanel {
|
|||
// TODO Auto-generated method stub
|
||||
|
||||
rootLogger.log(Level.SEVERE, "Start RPC - getTables");
|
||||
|
||||
rootLogger.log(Level.INFO, "keyword rpc: " + keyword);
|
||||
rootLogger.log(Level.INFO, "Search Table rpc: " + startSearchTable);
|
||||
|
||||
RPCservice.LoadTables((PagingLoadConfig) loadConfig, dataInput,
|
||||
RPCservice.LoadTables((PagingLoadConfig) loadConfig, dataInput, startSearchTable, keyword,
|
||||
new AsyncCallback<PagingLoadResult<Result>>() {
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public void onFailure(Throwable caught) {
|
||||
|
@ -680,7 +695,7 @@ public class GxtBorderLayoutPanel extends ContentPanel {
|
|||
// if
|
||||
// (((EditorGrid<Result>)tablesLoaded.getWidget(0)).isMasked())
|
||||
// {((EditorGrid<Result>)tablesLoaded.getWidget(0)).unmask();}
|
||||
|
||||
startSearchTable = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -720,7 +735,7 @@ public class GxtBorderLayoutPanel extends ContentPanel {
|
|||
// null);
|
||||
//
|
||||
// }
|
||||
|
||||
startSearchTable = false;
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -728,6 +743,8 @@ public class GxtBorderLayoutPanel extends ContentPanel {
|
|||
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
// if (tablesListNotNull == true){
|
||||
|
||||
|
@ -758,6 +775,7 @@ public class GxtBorderLayoutPanel extends ContentPanel {
|
|||
|
||||
// bind the loader with a PagingToolBar.
|
||||
final PagingToolBar toolBar = new PagingToolBar(100);
|
||||
|
||||
toolBar.bind(loader);
|
||||
|
||||
// craete the column configuration
|
||||
|
@ -840,8 +858,6 @@ public class GxtBorderLayoutPanel extends ContentPanel {
|
|||
rootLogger.log(Level.INFO, "table selected: "
|
||||
+ selectedTable);
|
||||
|
||||
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -1054,6 +1070,90 @@ public class GxtBorderLayoutPanel extends ContentPanel {
|
|||
|
||||
tablesLoaded.setBottomComponent(toolBar);
|
||||
|
||||
// toolBarTop.getAriaSupport().setLabel("Table Search");
|
||||
|
||||
// toolBar.add(new LabelToolItem("Search: "));
|
||||
|
||||
// TextField<String> searchTable = new TextField<String>();
|
||||
// searchTable.setFieldLabel("Search: ");
|
||||
|
||||
// StoreFilterField<Result> searchTable = new StoreFilterField<Result>()
|
||||
// {
|
||||
//
|
||||
// @Override
|
||||
// protected boolean doSelect(Store<Result> store, Result parent,
|
||||
// Result record, String property, String filter) {
|
||||
// // TODO Auto-generated method stub
|
||||
// return false;
|
||||
// }
|
||||
// };
|
||||
|
||||
// TwinTriggerField<String> searchTable = new
|
||||
// TwinTriggerField<String>();
|
||||
// searchTable.setFieldLabel("Search: ");
|
||||
|
||||
// TextField<String> searchTable = new TextField<String>();
|
||||
// searchTable.setFieldLabel("Search: ");
|
||||
|
||||
// Top toolbar
|
||||
ToolBar toolBarTop = new ToolBar();
|
||||
|
||||
//add the search functionality
|
||||
final TextField<String> searchTable = new TextField<String>();
|
||||
// searchTable.setFieldLabel("Search: ");
|
||||
toolBarTop.add(searchTable);
|
||||
|
||||
//add the button search
|
||||
Button searchButton = new Button("Search");
|
||||
|
||||
|
||||
|
||||
searchButton.addSelectionListener(new SelectionListener<ButtonEvent>() {
|
||||
|
||||
@Override
|
||||
public void componentSelected(ButtonEvent ce) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
//start search calling the rpc
|
||||
|
||||
//get the keyword
|
||||
keyword = searchTable.getValue();
|
||||
|
||||
startSearchTable = true;
|
||||
|
||||
|
||||
rootLogger.log(Level.INFO, "keyword: " + keyword);
|
||||
rootLogger.log(Level.INFO, "Search Table: " + startSearchTable);
|
||||
|
||||
|
||||
PagingLoadConfig config = new BasePagingLoadConfig();
|
||||
|
||||
config.setOffset(0);
|
||||
config.setLimit(100);
|
||||
|
||||
// Map<String, Object> 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);
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
toolBarTop.add(searchButton);
|
||||
|
||||
tablesLoaded.setTopComponent(toolBarTop);
|
||||
|
||||
// tablesLoaded.add(toolBarTop);
|
||||
|
||||
tablesLoaded.add(grid);
|
||||
|
||||
// listener to manage the table selection in the grid
|
||||
|
@ -1073,7 +1173,7 @@ public class GxtBorderLayoutPanel extends ContentPanel {
|
|||
// TODO Auto-generated method stub
|
||||
|
||||
if (selectedTable != null) {
|
||||
|
||||
|
||||
// display the table in the panel "Database Information"
|
||||
displayTableName(selectedTable);
|
||||
|
||||
|
@ -1290,6 +1390,8 @@ public class GxtBorderLayoutPanel extends ContentPanel {
|
|||
|
||||
}
|
||||
|
||||
|
||||
|
||||
private void submitQuery() {
|
||||
|
||||
// System.out.println("Start RPC - submitQuery");
|
||||
|
@ -3094,8 +3196,7 @@ public class GxtBorderLayoutPanel extends ContentPanel {
|
|||
+ " in the panel");
|
||||
|
||||
Result table = new Result("The selected table is:", tableName);
|
||||
|
||||
|
||||
|
||||
// create column configuration
|
||||
List<ColumnConfig> configs = new ArrayList<ColumnConfig>();
|
||||
|
||||
|
@ -3117,17 +3218,16 @@ public class GxtBorderLayoutPanel extends ContentPanel {
|
|||
column.setEditor(new CellEditor(textValue));
|
||||
|
||||
configs.add(column);
|
||||
|
||||
|
||||
ColumnModel cm = new ColumnModel(configs);
|
||||
|
||||
|
||||
|
||||
ListStore<Result> store = new ListStore<Result>();
|
||||
store.add(table);
|
||||
|
||||
//grid
|
||||
EditorGrid<Result> grid = new EditorGrid<Result>(store,cm);
|
||||
|
||||
//display information in the panel
|
||||
// grid
|
||||
EditorGrid<Result> grid = new EditorGrid<Result>(store, cm);
|
||||
|
||||
// display information in the panel
|
||||
centerUpper.removeAll();
|
||||
centerUpper.add(grid);
|
||||
centerUpper.layout(true);
|
||||
|
|
|
@ -405,18 +405,34 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
|
|||
|
||||
}
|
||||
|
||||
List<Result> result = null;
|
||||
String currentDB = "";
|
||||
String previousDB = "";
|
||||
@Override
|
||||
public PagingLoadResult<Result> LoadTables(PagingLoadConfig config,
|
||||
LinkedHashMap<String, String> dataInput) throws Exception {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
LinkedHashMap<String, String> dataInput, boolean SearchTable,
|
||||
String keyword) throws Exception {
|
||||
|
||||
currentDB = dataInput.get("DatabaseName");
|
||||
if (!currentDB.equals(previousDB)){
|
||||
result = null;
|
||||
System.gc();
|
||||
}
|
||||
|
||||
previousDB = currentDB;
|
||||
// get tables
|
||||
List<Result> result = getTables(dataInput);
|
||||
|
||||
if (result == null)
|
||||
result = getTables(dataInput);
|
||||
|
||||
// Create a sublist and add data to list according
|
||||
// to the limit and offset value of the config
|
||||
|
||||
ArrayList<Result> sublist = new ArrayList<Result>();
|
||||
List<Result> sublist = new ArrayList<Result>();
|
||||
|
||||
BasePagingLoadResult loadResult = null;
|
||||
|
||||
rootLogger.log(Level.INFO, "Searching in the table: "+SearchTable);
|
||||
rootLogger.log(Level.INFO, "Keyword to search: "+keyword);
|
||||
|
||||
int start = config.getOffset();
|
||||
int limit = result.size();
|
||||
|
@ -425,15 +441,83 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
|
|||
limit = Math.min(start + config.getLimit(), limit);
|
||||
}
|
||||
|
||||
for (int i = config.getOffset(); i < limit; i++) {
|
||||
sublist.add(result.get(i));
|
||||
int totalNumber = result.size();
|
||||
if ((SearchTable == false) || keyword==null || keyword.length()==0) {
|
||||
sublist = new ArrayList<Result>(result.subList(start, limit));
|
||||
} else {
|
||||
// search the table
|
||||
for (int i = 0; i < result.size(); i++) {
|
||||
if ((result.get(i).getValue().toLowerCase()).startsWith(keyword
|
||||
.toLowerCase())) {
|
||||
sublist.add(result.get(i));
|
||||
}
|
||||
}
|
||||
|
||||
int sublen = sublist.size();
|
||||
if (start<sublen-1){
|
||||
limit = Math.min(sublen, limit);
|
||||
totalNumber = sublist.size();
|
||||
sublist = new ArrayList<Result>(sublist.subList(start, limit));
|
||||
}
|
||||
}
|
||||
|
||||
return new BasePagingLoadResult<Result>(sublist,
|
||||
config.getOffset(), result.size());
|
||||
loadResult = new BasePagingLoadResult<Result>(sublist,
|
||||
config.getOffset(), totalNumber);
|
||||
|
||||
|
||||
return loadResult;
|
||||
|
||||
}
|
||||
|
||||
// @Override
|
||||
// public PagingLoadResult<Result> SearchTable(PagingLoadConfig config,
|
||||
// LinkedHashMap<String, String> dataInput, String keyword)
|
||||
// throws Exception {
|
||||
// // TODO Auto-generated method stub
|
||||
//
|
||||
// // get tables
|
||||
// List<Result> result = getTables(dataInput);
|
||||
//
|
||||
// // Create a sublist and add data to list according
|
||||
// // to the limit and offset value of the config
|
||||
//
|
||||
// ArrayList<Result> sublist = new ArrayList<Result>();
|
||||
//
|
||||
// // search the table
|
||||
//
|
||||
// for (int i = 0; i < result.size(); i++) {
|
||||
//
|
||||
// if ((result.get(i).getValue().toLowerCase()).startsWith(keyword
|
||||
// .toLowerCase())) {
|
||||
//
|
||||
// sublist.add(result.get(i));
|
||||
//
|
||||
// }
|
||||
//
|
||||
// }
|
||||
//
|
||||
// BasePagingLoadResult loadResult = new
|
||||
// BasePagingLoadResult<Result>(sublist, sublist.size(),
|
||||
// sublist.size());;
|
||||
//
|
||||
// if (sublist.size()!=0){
|
||||
// //if there are tables that start with the specified keyword
|
||||
//
|
||||
// loadResult = new BasePagingLoadResult<Result>(sublist, sublist.size(),
|
||||
// sublist.size());
|
||||
//
|
||||
// }
|
||||
// // else{
|
||||
// // //no tables exist
|
||||
// //
|
||||
// //
|
||||
// // }
|
||||
//
|
||||
//
|
||||
// return loadResult;
|
||||
//
|
||||
// }
|
||||
|
||||
@Override
|
||||
public List<Result> submitQuery(LinkedHashMap<String, String> dataDB,
|
||||
String query, boolean valueReadOnlyQuery,
|
||||
|
@ -1272,7 +1356,7 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
|
|||
// System.out.println("GWTdbManagerServiceImpl-> ResourceType:"
|
||||
// + smsubResType);
|
||||
|
||||
// rootLogger.log(Level.INFO, "ResourceType: " + smsubResType);
|
||||
// rootLogger.log(Level.INFO, "ResourceType: " + smsubResType);
|
||||
|
||||
if (smsubResType == SMResourceType.OBJECT) {
|
||||
SMObject obje = (SMObject) smres;
|
||||
|
@ -1280,15 +1364,13 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
|
|||
|
||||
// System.out.println("key :" + key);
|
||||
|
||||
// rootLogger.log(Level.INFO, "key: " + smsubResType);
|
||||
// rootLogger.log(Level.INFO, "key: " + smsubResType);
|
||||
|
||||
// System.out.println("Object:"
|
||||
// + new String(outstring.getBytes(), "UTF-8"));
|
||||
|
||||
|
||||
// rootLogger.log(Level.INFO,
|
||||
// "Object: " + new String(outstring.getBytes(), "UTF-8"));
|
||||
|
||||
// rootLogger.log(Level.INFO,
|
||||
// "Object: " + new String(outstring.getBytes(), "UTF-8"));
|
||||
|
||||
// outputmap.put(key, outstring);
|
||||
|
||||
|
|
Loading…
Reference in New Issue