some bugs fixed and messagebox added for get details and sampling operations

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/user/databases-manager-portlet@98589 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Loredana Liccardo 2014-07-14 12:20:18 +00:00
parent 1adb58e887
commit 8b53e63c90
1 changed files with 576 additions and 245 deletions

View File

@ -40,6 +40,7 @@ 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.TextField;
import com.extjs.gxt.ui.client.widget.grid.CellEditor;
import com.extjs.gxt.ui.client.widget.grid.ColumnConfig;
@ -74,6 +75,7 @@ import com.extjs.gxt.ui.client.event.MessageBoxEvent;
import com.extjs.gxt.ui.client.event.SelectionChangedEvent;
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;
//class that represents the container of all components
@ -425,7 +427,8 @@ public class GxtBorderLayoutPanel extends ContentPanel {
List<FileModel> data = treePanel.getTreePanel()
.getSelectionModel().getSelectedItems();
// if ((data.get(0).isDatabase())&&(data.get(0).getDatabaseType().equals(ConstantsPortlet.MYSQL))){
// if
// ((data.get(0).isDatabase())&&(data.get(0).getDatabaseType().equals(ConstantsPortlet.MYSQL))){
if (!(table.getName().equals(selectedTable))) {
@ -456,8 +459,6 @@ public class GxtBorderLayoutPanel extends ContentPanel {
rootLogger.log(Level.SEVERE, "Start RPC - loadTables");
// to mask the entire content panel
// this.mask("Loading", "x-mask-loading");
@ -810,34 +811,39 @@ public class GxtBorderLayoutPanel extends ContentPanel {
// }
// });
// listener to manage the table selection in the grid
grid.addListener(Events.BeforeEdit, new Listener<GridEvent<Result>>() {
@Override
public void handleEvent(final GridEvent<Result> be) {
// TODO Auto-generated method stub
be.getValue().toString();
// be.getValue().toString();
// System.out.println("table selected: " +
// be.getValue().toString());
rootLogger.log(Level.INFO, "table selected: " + be.getValue().toString());
// Fire event
eventBus.fireEvent(new SelectedTableEvent());
tablesLoaded.getButtonById(Dialog.OK)
.addSelectionListener(
new SelectionListener<ButtonEvent>() {
@Override
public void componentSelected(
ButtonEvent ce) {
rootLogger.log(Level.INFO, "table selected: "
+ be.getValue().toString());
selectedTable = be.getValue().toString();
}
});
// tablesLoaded.addListener(Events.Hide, new
// Listener<WindowEvent>() {
//
// @Override
// public void handleEvent(WindowEvent be) {
// // TODO Auto-generated method stub
//
// System.out.println("closing the window");
//
// }
// });
// if (selectedTable!=null){
// // Fire event
// eventBus.fireEvent(new SelectedTableEvent());
//
// }
}
});
@ -955,6 +961,8 @@ public class GxtBorderLayoutPanel extends ContentPanel {
// Dialog tablesLoaded = new Dialog();
tablesLoaded = new Dialog();
tablesLoaded.setLayout(new FitLayout());
tablesLoaded.addButton(new Button("CANCEL"));
tablesLoaded.setHeading("Tables");
tablesLoaded.setResizable(false);
@ -966,10 +974,72 @@ public class GxtBorderLayoutPanel extends ContentPanel {
tablesLoaded.setHideOnButtonClick(true);
tablesLoaded.setMaximizable(true);
tablesLoaded.setClosable(false);
tablesLoaded.setBottomComponent(toolBar);
tablesLoaded.add(grid);
// listener to manage the table selection in the grid
tablesLoaded.getButtonById(Dialog.OK).addSelectionListener(
new SelectionListener<ButtonEvent>() {
@Override
public void componentSelected(ButtonEvent ce) {
// selectedTable = be.getValue().toString();
Listener<MessageBoxEvent> l = new Listener<MessageBoxEvent>() {
@Override
public void handleEvent(MessageBoxEvent be) {
// TODO Auto-generated method stub
rootLogger.log(Level.INFO, "button clicked");
eventBus.fireEvent(new SelectedTableEvent());
}
};
if (selectedTable != null) {
// MessageBox.alert("Information",
// "The table "+selectedTable+ " was selected",
// null);
MessageBox.info("Information", "The table "
+ selectedTable + " was selected", l);
// eventBus.fireEvent(new SelectedTableEvent());
} else {
// MessageBox.alert("Warning",
// "No table "+selectedTable+ " was selected",
// null);
MessageBox.info("Information",
"No table was selected", null);
}
}
});
// tablesLoaded.getButtonById("CANCEL").addSelectionListener(
// new SelectionListener<ButtonEvent>() {
//
// @Override
// public void componentSelected(ButtonEvent ce) {
// // TODO Auto-generated method stub
//
// tablesLoaded.hide();
//
// }
// });
tablesLoaded.show();
// ToolBar toolBar = new ToolBar();
@ -1263,7 +1333,9 @@ public class GxtBorderLayoutPanel extends ContentPanel {
// to mask the entire content panel
this.mask("Sampling the " + selectedTable + " table", "x-mask-loading");
// this.mask("Sampling the " + selectedTable + " table",
// "x-mask-loading");
// this.mask("Sampling the table", "x-mask-loading");
// System.out.println("Start RPC - submitQuery");
@ -1290,7 +1362,7 @@ public class GxtBorderLayoutPanel extends ContentPanel {
// recover data inputs
LinkedHashMap<String, String> dataInput = new LinkedHashMap<String, String>();
final LinkedHashMap<String, String> dataInput = new LinkedHashMap<String, String>();
// check if the table has an associated schema
FileModel schema;
@ -1435,19 +1507,34 @@ public class GxtBorderLayoutPanel extends ContentPanel {
// // selectedItem.getName());
// }
Listener<MessageBoxEvent> l = new Listener<MessageBoxEvent>() {
@Override
public void handleEvent(MessageBoxEvent be) {
// TODO Auto-generated method stub
Button btn = be.getButtonClicked();
if (btn.getText().equals("Yes")) {
// to mask the entire content panel
obj.mask("Sampling the table", "x-mask-loading");
// call remote service
RPCservice.sample(dataInput, new AsyncCallback<List<Result>>() {
RPCservice.sample(dataInput,
new AsyncCallback<List<Result>>() {
@Override
public void onFailure(Throwable caught) {
// Window.alert(caught.getMessage());
// System.out.println("FAILURE");
rootLogger.log(Level.SEVERE, "FAILURE RPC sample");
rootLogger.log(Level.SEVERE,
"FAILURE RPC sample");
MessageBox.alert("Error ",
"<br/>Message:" + caught.getMessage(), null);
MessageBox.alert("Error ", "<br/>Message:"
+ caught.getMessage(), null);
if (obj.isMasked()) {
obj.unmask();
@ -1458,21 +1545,27 @@ public class GxtBorderLayoutPanel extends ContentPanel {
@Override
public void onSuccess(List<Result> result) {
rootLogger.log(Level.SEVERE, "SUCCESS RPC sample");
rootLogger.log(Level.SEVERE,
"SUCCESS RPC sample");
// rows = new ArrayList<Row>();
// System.out.println("result size: " + result.size());
// System.out.println("result size: " +
// result.size());
rootLogger.log(Level.SEVERE, "output size: " + result.size());
rootLogger.log(Level.SEVERE,
"output size: " + result.size());
// get the attributes list for the result table
// get the attributes list for the result
// table
getListAttributes(result.get(0).getValue());
// remove the header in order to parse only the result
// remove the header in order to parse only
// the result
result.remove(0);
// parse the result in order to obtain a table
// parse the result in order to obtain a
// table
parseResult(result);
}
@ -1481,11 +1574,21 @@ public class GxtBorderLayoutPanel extends ContentPanel {
}
}
};
MessageBox.confirm("Confirm", "Are you sure you want to sample the "
+ selectedTable + " table?", l);
}
private void smartSample() {
// to mask the entire content panel
this.mask("Sampling the " + selectedTable + " table", "x-mask-loading");
// this.mask("Sampling the " + selectedTable + " table",
// "x-mask-loading");
final GxtBorderLayoutPanel obj = this;
@ -1511,7 +1614,7 @@ public class GxtBorderLayoutPanel extends ContentPanel {
// recover data inputs for the algorithm
LinkedHashMap<String, String> dataInput = new LinkedHashMap<String, String>();
final LinkedHashMap<String, String> dataInput = new LinkedHashMap<String, String>();
// check if the table has an associated schema
FileModel schema;
@ -1659,19 +1762,33 @@ public class GxtBorderLayoutPanel extends ContentPanel {
// // selectedItem.getName());
// }
Listener<MessageBoxEvent> l = new Listener<MessageBoxEvent>() {
@Override
public void handleEvent(MessageBoxEvent be) {
// TODO Auto-generated method stub
Button btn = be.getButtonClicked();
if (btn.getText().equals("Yes")) {
// to mask the entire content panel
obj.mask("Sampling the table", "x-mask-loading");
// call remote service
RPCservice.smartSample(dataInput, new AsyncCallback<List<Result>>() {
RPCservice.smartSample(dataInput,
new AsyncCallback<List<Result>>() {
@Override
public void onFailure(Throwable caught) {
// Window.alert(caught.getMessage());
// System.out.println("FAILURE");
rootLogger.log(Level.SEVERE, "FAILURE RPC smartSample");
rootLogger.log(Level.SEVERE,
"FAILURE RPC smartSample");
MessageBox.alert("Error ",
"<br/>Message:" + caught.getMessage(), null);
MessageBox.alert("Error ", "<br/>Message:"
+ caught.getMessage(), null);
if (obj.isMasked()) {
obj.unmask();
@ -1682,21 +1799,27 @@ public class GxtBorderLayoutPanel extends ContentPanel {
@Override
public void onSuccess(List<Result> result) {
rootLogger.log(Level.SEVERE, "SUCCESS RPC smartSample");
rootLogger.log(Level.SEVERE,
"SUCCESS RPC smartSample");
// rows = new ArrayList<Row>();
// System.out.println("result size: " + result.size());
// System.out.println("result size: " +
// result.size());
rootLogger.log(Level.SEVERE, "output size: " + result.size());
rootLogger.log(Level.SEVERE,
"output size: " + result.size());
// get the attributes list for the result table
// get the attributes list for the result
// table
getListAttributes(result.get(0).getValue());
// remove the header in order to parse only the result
// remove the header in order to parse only
// the result
result.remove(0);
// parse the result in order to obtain a table
// parse the result in order to obtain a
// table
parseResult(result);
}
@ -1705,10 +1828,20 @@ public class GxtBorderLayoutPanel extends ContentPanel {
}
}
};
MessageBox.confirm("Confirm", "Are you sure you want to sample the "
+ selectedTable + " table?", l);
}
private void randomSample() {
// to mask the entire content panel
this.mask("Sampling the " + selectedTable + " table", "x-mask-loading");
// this.mask("Sampling the " + selectedTable + " table",
// "x-mask-loading");
final GxtBorderLayoutPanel obj = this;
@ -1734,7 +1867,7 @@ public class GxtBorderLayoutPanel extends ContentPanel {
// recover data inputs for the algorithm
LinkedHashMap<String, String> dataInput = new LinkedHashMap<String, String>();
final LinkedHashMap<String, String> dataInput = new LinkedHashMap<String, String>();
// check if the table has an associated schema
FileModel schema;
@ -1883,19 +2016,34 @@ public class GxtBorderLayoutPanel extends ContentPanel {
// // selectedItem.getName());
// }
Listener<MessageBoxEvent> l = new Listener<MessageBoxEvent>() {
@Override
public void handleEvent(MessageBoxEvent be) {
// TODO Auto-generated method stub
Button btn = be.getButtonClicked();
if (btn.getText().equals("Yes")) {
// to mask the entire content panel
obj.mask("Sampling the table", "x-mask-loading");
// call remote service
RPCservice.randomSample(dataInput, new AsyncCallback<List<Result>>() {
RPCservice.randomSample(dataInput,
new AsyncCallback<List<Result>>() {
@Override
public void onFailure(Throwable caught) {
// Window.alert(caught.getMessage());
// System.out.println("FAILURE");
rootLogger.log(Level.SEVERE, "FAILURE RPC randomSample");
rootLogger.log(Level.SEVERE,
"FAILURE RPC randomSample");
MessageBox.alert("Error ",
"<br/>Message:" + caught.getMessage(), null);
MessageBox.alert("Error ", "<br/>Message:"
+ caught.getMessage(), null);
if (obj.isMasked()) {
obj.unmask();
@ -1906,21 +2054,27 @@ public class GxtBorderLayoutPanel extends ContentPanel {
@Override
public void onSuccess(List<Result> result) {
rootLogger.log(Level.SEVERE, "SUCCESS RPC randomSample");
rootLogger.log(Level.SEVERE,
"SUCCESS RPC randomSample");
// rows = new ArrayList<Row>();
// System.out.println("result size: " + result.size());
// System.out.println("result size: " +
// result.size());
rootLogger.log(Level.SEVERE, "output size: " + result.size());
rootLogger.log(Level.SEVERE,
"output size: " + result.size());
// get the attributes list for the result table
// get the attributes list for the result
// table
getListAttributes(result.get(0).getValue());
// remove the header in order to parse only the result
// remove the header in order to parse only
// the result
result.remove(0);
// parse the result in order to obtain a table
// parse the result in order to obtain a
// table
parseResult(result);
}
@ -1929,6 +2083,15 @@ public class GxtBorderLayoutPanel extends ContentPanel {
}
}
};
MessageBox.confirm("Confirm", "Are you sure you want to sample the "
+ selectedTable + " table?", l);
}
// start the parsing of the submit result in order to obtain a table
private void parseResult(List<Result> result) {
@ -1956,6 +2119,8 @@ public class GxtBorderLayoutPanel extends ContentPanel {
if (submitQueryEventManaged == true) {
submitQueryEventManaged = false;
Dialog form = toolbar.getDialogForm();
if (form.isMasked())
@ -2033,6 +2198,8 @@ public class GxtBorderLayoutPanel extends ContentPanel {
if (submitQueryEventManaged == true) {
submitQueryEventManaged = false;
Dialog form = toolbar.getDialogForm();
if (form.isMasked())
@ -2051,6 +2218,8 @@ public class GxtBorderLayoutPanel extends ContentPanel {
if (submitQueryEventManaged == true) {
submitQueryEventManaged = false;
Dialog form = toolbar.getDialogForm();
if (form.isMasked())
@ -2306,8 +2475,8 @@ public class GxtBorderLayoutPanel extends ContentPanel {
// to mask the entire content panel
this.mask("Loading details for " + selectedTable + " table",
"x-mask-loading");
// this.mask("Loading details for " + selectedTable + " table",
// "x-mask-loading");
// to unmask the entire content panel
final GxtBorderLayoutPanel obj = this;
@ -2340,7 +2509,7 @@ public class GxtBorderLayoutPanel extends ContentPanel {
// recover data inputs
LinkedHashMap<String, String> dataInput = new LinkedHashMap<String, String>();
final LinkedHashMap<String, String> dataInput = new LinkedHashMap<String, String>();
// check if the table has an associated schema
FileModel schema;
@ -2493,19 +2662,41 @@ public class GxtBorderLayoutPanel extends ContentPanel {
} else {
Listener<MessageBoxEvent> l = new Listener<MessageBoxEvent>() {
@Override
public void handleEvent(MessageBoxEvent be) {
// TODO Auto-generated method stub
Button btn = be.getButtonClicked();
if (btn.getText().equals("Yes")) {
// to mask the entire content panel
obj.mask("Loading details", "x-mask-loading");
// call remote service
RPCservice.getTableDetails(dataInput,
RPCservice
.getTableDetails(
dataInput,
new AsyncCallback<LinkedHashMap<String, FileModel>>() {
@Override
public void onFailure(Throwable caught) {
// TODO Auto-generated method stub
public void onFailure(
Throwable caught) {
// TODO Auto-generated method
// stub
rootLogger.log(Level.SEVERE,
rootLogger
.log(Level.SEVERE,
"FAILURE RPC getTableDetails");
MessageBox.alert("Error ",
"<br/>Message:" + caught.getMessage(), null);
MessageBox
.alert("Error ",
"<br/>Message:"
+ caught.getMessage(),
null);
if (obj.isMasked()) {
obj.unmask();
@ -2516,66 +2707,93 @@ public class GxtBorderLayoutPanel extends ContentPanel {
@Override
public void onSuccess(
LinkedHashMap<String, FileModel> result) {
// TODO Auto-generated method stub
// TODO Auto-generated method
// stub
rootLogger.log(Level.SEVERE,
rootLogger
.log(Level.SEVERE,
"SUCCESS RPC getTableDetails");
// details are recovered about the selected table
// details are recovered about
// the selected table
if (result.size() != 0) {
// recover keys from the result
// recover keys from the
// result
Set<String> keys = result.keySet();
Set<String> keys = result
.keySet();
Object[] array = keys.toArray();
Object[] array = keys
.toArray();
// System.out.println("array size: " +
// System.out.println("array size: "
// +
// array.length);
// recover details
List<Result> TableDetails = new ArrayList<Result>();
for (int i = 0; i < result.size(); i++) {
for (int i = 0; i < result
.size(); i++) {
if (array[i].toString().contains(
if (array[i]
.toString()
.contains(
"CreateTable")) {
// recover the showCreateTable statement
// recover the
// showCreateTable
// statement
Result row = new Result("CreateTable",
result.get(array[i].toString())
Result row = new Result(
"CreateTable",
result.get(
array[i].toString())
.getName());
TableDetails.add(row);
TableDetails
.add(row);
}
if (array[i].toString().contains(
if (array[i]
.toString()
.contains(
"Column Names")) {
// recover the column names
// recover the
// column names
Result row = new Result("Column Names",
result.get(array[i].toString())
Result row = new Result(
"Column Names",
result.get(
array[i].toString())
.getName());
TableDetails.add(row);
TableDetails
.add(row);
}
if (array[i].toString().contains(
if (array[i]
.toString()
.contains(
"NumberRows")) {
// recover the column names
// recover the
// column names
Result row = new Result("NumberRows",
result.get(array[i].toString())
Result row = new Result(
"NumberRows",
result.get(
array[i].toString())
.getName());
TableDetails.add(row);
TableDetails
.add(row);
}
@ -2600,6 +2818,119 @@ public class GxtBorderLayoutPanel extends ContentPanel {
}
};
MessageBox.confirm("Confirm",
"Are you sure you want to get details for " + selectedTable
+ " table?", l);
// // call remote service
// RPCservice.getTableDetails(dataInput,
// new AsyncCallback<LinkedHashMap<String, FileModel>>() {
//
// @Override
// public void onFailure(Throwable caught) {
// // TODO Auto-generated method stub
//
// rootLogger.log(Level.SEVERE,
// "FAILURE RPC getTableDetails");
//
// MessageBox.alert("Error ",
// "<br/>Message:" + caught.getMessage(), null);
//
// if (obj.isMasked()) {
// obj.unmask();
// }
//
// }
//
// @Override
// public void onSuccess(
// LinkedHashMap<String, FileModel> result) {
// // TODO Auto-generated method stub
//
// rootLogger.log(Level.SEVERE,
// "SUCCESS RPC getTableDetails");
//
// // details are recovered about the selected table
//
// if (result.size() != 0) {
//
// // recover keys from the result
//
// Set<String> keys = result.keySet();
//
// Object[] array = keys.toArray();
//
// // System.out.println("array size: " +
// // array.length);
//
// // recover details
//
// List<Result> TableDetails = new ArrayList<Result>();
//
// for (int i = 0; i < result.size(); i++) {
//
// if (array[i].toString().contains(
// "CreateTable")) {
//
// // recover the showCreateTable statement
//
// Result row = new Result("CreateTable",
// result.get(array[i].toString())
// .getName());
//
// TableDetails.add(row);
//
// }
//
// if (array[i].toString().contains(
// "Column Names")) {
//
// // recover the column names
//
// Result row = new Result("Column Names",
// result.get(array[i].toString())
// .getName());
//
// TableDetails.add(row);
//
// }
//
// if (array[i].toString().contains(
// "NumberRows")) {
//
// // recover the column names
//
// Result row = new Result("NumberRows",
// result.get(array[i].toString())
// .getName());
//
// TableDetails.add(row);
//
// }
//
// }
//
// Table.setTableDetails(TableDetails);
//
// displayTableDetails(Table);
//
// Table.setTableDetailsDisplayed(true);
//
// }
//
// // if (obj.isMasked()) {
// // obj.unmask();
// // }
//
// }
// });
}
}
private void displayTableDetails(FileModel table) {
rootLogger.log(Level.INFO, "displaying table details");