top toolbar made disabled in the dialog that displays the tables list in order to disallow a user the table search.

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/user/databases-manager-portlet@98776 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Loredana Liccardo 2014-07-18 09:42:27 +00:00
parent 38a7e3daa5
commit bc6775ffc5
1 changed files with 154 additions and 135 deletions

View File

@ -128,6 +128,9 @@ public class GxtBorderLayoutPanel extends ContentPanel {
private String keyword = ""; private String keyword = "";
private boolean startSearchTable = false; private boolean startSearchTable = false;
// toolbar for table search functionality
private ToolBar toolBarTop = null;
// private Grid<Result> grid; // private Grid<Result> grid;
// private PagingToolBar toolBar = new PagingToolBar(100); // private PagingToolBar toolBar = new PagingToolBar(100);
@ -675,7 +678,7 @@ public class GxtBorderLayoutPanel extends ContentPanel {
rootLogger.log(Level.SEVERE, rootLogger.log(Level.SEVERE,
"FAILURE RPC getTables"); "FAILURE RPC getTables");
// caught.printStackTrace(); // caught.printStackTrace();
callback.onFailure(caught); callback.onFailure(caught);
@ -725,10 +728,11 @@ public class GxtBorderLayoutPanel extends ContentPanel {
// tablesLoaded.show(); // tablesLoaded.show();
// tablesLoaded.hide(); // tablesLoaded.hide();
// MessageBox.alert("Error ", "<br/>Message:" // MessageBox.alert("Error ",
// + "no tables available", null); // "<br/>Message:"
// + "no tables available", null);
// if // if
// (((EditorGrid<Result>)tablesLoaded.getWidget(0)).isMasked()) // (((EditorGrid<Result>)tablesLoaded.getWidget(0)).isMasked())
@ -750,6 +754,9 @@ public class GxtBorderLayoutPanel extends ContentPanel {
if (keyword == null) { if (keyword == null) {
startSearchTable = false; startSearchTable = false;
} }
toolBarTop.enable();
} }
}); });
@ -803,8 +810,8 @@ public class GxtBorderLayoutPanel extends ContentPanel {
// grid = new Grid<Result>(result, cm); // grid = new Grid<Result>(result, cm);
// grid.setStateId("TablesList"); // grid.setStateId("TablesList");
// grid.setStateful(true); // grid.setStateful(true);
grid.setLoadMask(true); grid.setLoadMask(true);
grid.setBorders(true); grid.setBorders(true);
@ -854,6 +861,104 @@ public class GxtBorderLayoutPanel extends ContentPanel {
// } // }
// }); // });
// add the search functionality
// Top toolbar for search table functionality
// final ToolBar toolBarTop = new ToolBar();
toolBarTop = new ToolBar();
//TextField for specify the table name to search
final TextField<String> searchTable = new TextField<String>();
searchTable.setEmptyText("enter a text");
searchTable.setToolTip("search a table in the database");
searchTable.setAllowBlank(true);
// add the button search
final Button searchButton = new Button("", Images.iconSearch());
searchButton.setToolTip("Search");
// add the button cancel
Button cancel = new Button("", Images.iconCancel());
cancel.setToolTip("Cancel");
// add Buttons and TextField to the toolbar
toolBarTop.add(searchTable);
toolBarTop.add(searchButton);
toolBarTop.add(cancel);
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);
}
});
cancel.addSelectionListener(new SelectionListener<ButtonEvent>() {
@Override
public void componentSelected(ButtonEvent ce) {
// TODO Auto-generated method stub
keyword = null;
startSearchTable = false;
searchTable.clear();
PagingLoadConfig config = new BasePagingLoadConfig();
config.setOffset(0);
config.setLimit(100);
loader.load(config);
}
});
// "Enter" listener for the search table functionality
searchTable.addKeyListener(new KeyListener() {
@Override
public void componentKeyDown(ComponentEvent event) {
super.componentKeyDown(event);
if (event.getKeyCode() == KeyCodes.KEY_ENTER)
searchButton.fireEvent(Events.Select);
}
});
// listener to manage the table selection in the grid // listener to manage the table selection in the grid
grid.getSelectionModel().addSelectionChangedListener( grid.getSelectionModel().addSelectionChangedListener(
@ -952,13 +1057,22 @@ public class GxtBorderLayoutPanel extends ContentPanel {
} }
}); });
// this listener catch the Attach event.It fires when the selection of
// the Tables List button
// it seems to fire when the event source is attached to the browser's
// document or detached from it.
grid.addListener(Events.Attach, new Listener<GridEvent<Result>>() { grid.addListener(Events.Attach, new Listener<GridEvent<Result>>() {
public void handleEvent(GridEvent<Result> be) { public void handleEvent(GridEvent<Result> be) {
rootLogger.log(Level.INFO, "event Attach handled"); rootLogger.log(Level.INFO, "event Attach handled");
// disable the top toolbar at the first tables loading in such a
// way to disallow a user the search. It will be enabled in the
// rpc when the tables are retrieved.
toolBarTop.disable();
// searchTable.disable();
PagingLoadConfig config = new BasePagingLoadConfig(); PagingLoadConfig config = new BasePagingLoadConfig();
// The offset for the first record to retrieve. // The offset for the first record to retrieve.
@ -967,21 +1081,21 @@ public class GxtBorderLayoutPanel extends ContentPanel {
// The number of records being requested. // The number of records being requested.
config.setLimit(100); config.setLimit(100);
// Map<String, Object> state = grid.getState(); // Map<String, Object> state = grid.getState();
// if (state.containsKey("offset")) { // if (state.containsKey("offset")) {
// //
//// rootLogger.log(Level.INFO, "state contains offset"); // // rootLogger.log(Level.INFO, "state contains offset");
// //
// int offset = (Integer) state.get("offset"); // int offset = (Integer) state.get("offset");
// rootLogger.log(Level.INFO, "offset: " + offset); // rootLogger.log(Level.INFO, "offset: " + offset);
// //
// int limit = (Integer) state.get("limit"); // int limit = (Integer) state.get("limit");
// rootLogger.log(Level.INFO, "limit: " + limit); // rootLogger.log(Level.INFO, "limit: " + limit);
// //
// config.setOffset(offset); // config.setOffset(offset);
// config.setLimit(limit); // config.setLimit(limit);
// } // }
// if (state.containsKey("sortField")) { // if (state.containsKey("sortField")) {
// config.setSortField((String) state.get("sortField")); // config.setSortField((String) state.get("sortField"));
// config.setSortDir(SortDir.valueOf((String) state // config.setSortDir(SortDir.valueOf((String) state
@ -1080,7 +1194,7 @@ public class GxtBorderLayoutPanel extends ContentPanel {
// Dialog tablesLoaded = new Dialog(); // Dialog tablesLoaded = new Dialog();
tablesLoaded = new Dialog(); tablesLoaded = new Dialog();
tablesLoaded.setLayout(new FitLayout()); tablesLoaded.setLayout(new FitLayout());
//ADD CANCEL BUTTON // ADD CANCEL BUTTON
tablesLoaded.addButton(new Button("CANCEL")); tablesLoaded.addButton(new Button("CANCEL"));
tablesLoaded.setHeading("Tables"); tablesLoaded.setHeading("Tables");
@ -1123,97 +1237,6 @@ public class GxtBorderLayoutPanel extends ContentPanel {
// TextField<String> searchTable = new TextField<String>(); // TextField<String> searchTable = new TextField<String>();
// searchTable.setFieldLabel("Search: "); // searchTable.setFieldLabel("Search: ");
// Top toolbar
ToolBar toolBarTop = new ToolBar();
// add the search functionality
final TextField<String> searchTable = new TextField<String>();
searchTable.setEmptyText("enter a text");
searchTable.setToolTip("search a table in the database");
searchTable.setAllowBlank(true);
// add the button search
final Button searchButton = new Button("", Images.iconSearch());
searchButton.setToolTip("Search");
// add the button cancel
Button cancel = new Button("", Images.iconCancel());
cancel.setToolTip("Cancel");
// add Buttons and TextField to the toolbar
toolBarTop.add(searchTable);
toolBarTop.add(searchButton);
toolBarTop.add(cancel);
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);
}
});
cancel.addSelectionListener(new SelectionListener<ButtonEvent>() {
@Override
public void componentSelected(ButtonEvent ce) {
// TODO Auto-generated method stub
keyword = null;
startSearchTable = false;
searchTable.clear();
PagingLoadConfig config = new BasePagingLoadConfig();
config.setOffset(0);
config.setLimit(100);
loader.load(config);
}
});
searchTable.addKeyListener(new KeyListener() {
@Override
public void componentKeyDown(ComponentEvent event) {
super.componentKeyDown(event);
if (event.getKeyCode() == KeyCodes.KEY_ENTER)
searchButton.fireEvent(Events.Select);
}
});
// searchTable.addListener(Events.KeyPress, new Listener<FieldEvent>() { // searchTable.addListener(Events.KeyPress, new Listener<FieldEvent>() {
// //
// @Override // @Override
@ -1246,8 +1269,6 @@ public class GxtBorderLayoutPanel extends ContentPanel {
// tablesLoaded.add(toolBarTop); // tablesLoaded.add(toolBarTop);
// listener to manage the table selection in the grid // listener to manage the table selection in the grid
Button ok = (Button) tablesLoaded.getButtonBar().getWidget(0); Button ok = (Button) tablesLoaded.getButtonBar().getWidget(0);
@ -1267,18 +1288,16 @@ public class GxtBorderLayoutPanel extends ContentPanel {
keyword = null; keyword = null;
startSearchTable = false; startSearchTable = false;
// if ((grid.getState().containsKey("offset"))){
// rootLogger.log(Level.INFO, "setting the state");
// if ((grid.getState().containsKey("offset"))){ //
// rootLogger.log(Level.INFO, "setting the state"); // grid.getState().remove("offset");
// // grid.getState().remove("limit");
// grid.getState().remove("offset"); //
// grid.getState().remove("limit"); //
// // }
// //
// } // grid.getState().clear();
//
// grid.getState().clear();
if (selectedTable != null) { if (selectedTable != null) {
@ -1340,8 +1359,8 @@ public class GxtBorderLayoutPanel extends ContentPanel {
keyword = null; keyword = null;
startSearchTable = false; startSearchTable = false;
// rootLogger.log(Level.INFO, "setting the state"); // rootLogger.log(Level.INFO, "setting the state");
// grid.getState().clear(); // grid.getState().clear();
tablesLoaded.hide(); tablesLoaded.hide();