2014-07-02 12:57:14 +02:00
|
|
|
package org.gcube.portlets.user.databasesmanager.client.panels;
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.LinkedHashMap;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.logging.Level;
|
|
|
|
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.datamodel.Row;
|
|
|
|
import org.gcube.portlets.user.databasesmanager.client.datamodel.SubmitQueryData;
|
2014-07-03 14:44:03 +02:00
|
|
|
import org.gcube.portlets.user.databasesmanager.client.events.SamplingEvent;
|
2014-07-02 12:57:14 +02:00
|
|
|
import org.gcube.portlets.user.databasesmanager.client.events.SelectedItemEvent;
|
|
|
|
import org.gcube.portlets.user.databasesmanager.client.events.SubmitQueryEvent;
|
2014-07-03 14:44:03 +02:00
|
|
|
import org.gcube.portlets.user.databasesmanager.client.events.interfaces.SamplingEventHandler;
|
2014-07-02 12:57:14 +02:00
|
|
|
import org.gcube.portlets.user.databasesmanager.client.events.interfaces.SelectedItemEventHandler;
|
|
|
|
import org.gcube.portlets.user.databasesmanager.client.events.interfaces.SubmitQueryEventHandler;
|
|
|
|
import org.gcube.portlets.user.databasesmanager.client.toolbar.GxtToolbarFunctionality;
|
|
|
|
import org.gcube.portlets.user.databasesmanager.client.utils.ConstantsPortlet;
|
|
|
|
|
|
|
|
//import org.gcube.portlets.user.dbmanager.client.GWTdbManagerServiceAsync;
|
|
|
|
//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 org.gcube.portlets.user.dbmanager.client.datamodel.SubmitQueryData;
|
|
|
|
//import org.gcube.portlets.user.dbmanager.client.events.SelectedItemEvent;
|
|
|
|
//import org.gcube.portlets.user.dbmanager.client.events.SubmitQueryEvent;
|
|
|
|
//import org.gcube.portlets.user.dbmanager.client.events.interfaces.SelectedItemEventHandler;
|
|
|
|
//import org.gcube.portlets.user.dbmanager.client.events.interfaces.SubmitQueryEventHandler;
|
|
|
|
//import org.gcube.portlets.user.dbmanager.client.toolbar.GxtToolbarFunctionality;
|
|
|
|
//import org.gcube.portlets.user.dbmanager.client.utils.ConstantsPortlet;
|
|
|
|
|
|
|
|
import com.extjs.gxt.ui.client.Style.LayoutRegion;
|
|
|
|
import com.extjs.gxt.ui.client.Style.Scroll;
|
|
|
|
import com.extjs.gxt.ui.client.store.ListStore;
|
|
|
|
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.grid.ColumnConfig;
|
|
|
|
import com.extjs.gxt.ui.client.widget.grid.ColumnModel;
|
|
|
|
import com.extjs.gxt.ui.client.widget.grid.Grid;
|
|
|
|
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.google.gwt.event.shared.HandlerManager;
|
|
|
|
import com.google.gwt.user.client.Window;
|
|
|
|
import com.google.gwt.user.client.rpc.AsyncCallback;
|
2014-07-03 14:44:03 +02:00
|
|
|
import com.extjs.gxt.ui.client.event.Listener;
|
2014-07-02 12:57:14 +02:00
|
|
|
import com.extjs.gxt.ui.client.event.MessageBoxEvent;
|
2014-07-03 14:44:03 +02:00
|
|
|
import com.extjs.gxt.ui.client.widget.button.Button;
|
2014-07-02 12:57:14 +02:00
|
|
|
|
|
|
|
public class GxtBorderLayoutPanel extends ContentPanel {
|
2014-07-03 14:44:03 +02:00
|
|
|
|
2014-07-02 12:57:14 +02:00
|
|
|
/* Create Root Logger */
|
|
|
|
private static Logger rootLogger = Logger.getLogger("GxtBorderLayoutPanel");
|
|
|
|
|
|
|
|
private ContentPanel north;
|
|
|
|
private ContentPanel west;
|
|
|
|
private LayoutContainer center;
|
|
|
|
private ContentPanel centerUpper;
|
|
|
|
private ContentPanel centerBottom;
|
|
|
|
private GxtTreePanel treePanel;
|
|
|
|
private GxtToolbarFunctionality toolbar;
|
|
|
|
private ArrayList<String> parsedList;
|
|
|
|
|
|
|
|
private List<String> listAttributes;
|
|
|
|
private List<Row> rows;
|
|
|
|
|
|
|
|
private HandlerManager eventBus = null;
|
|
|
|
|
|
|
|
// RPC service
|
|
|
|
private GWTdbManagerServiceAsync RPCservice = null;
|
|
|
|
|
2014-07-03 14:44:03 +02:00
|
|
|
// variable that keeps track of the managed event
|
|
|
|
private boolean submitQueryEventManaged = false;
|
|
|
|
|
2014-07-02 12:57:14 +02:00
|
|
|
public GxtBorderLayoutPanel(HandlerManager eBus,
|
|
|
|
GWTdbManagerServiceAsync service) throws Exception {
|
|
|
|
|
|
|
|
eventBus = eBus;
|
|
|
|
RPCservice = service;
|
|
|
|
|
|
|
|
north = new ContentPanel();
|
|
|
|
west = new ContentPanel();
|
|
|
|
center = new LayoutContainer();
|
|
|
|
treePanel = new GxtTreePanel(eventBus, service);
|
|
|
|
toolbar = new GxtToolbarFunctionality(eventBus, RPCservice);
|
|
|
|
|
|
|
|
initLayout();
|
|
|
|
createLayouts();
|
|
|
|
|
|
|
|
addHandler();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
private void initLayout() {
|
2014-07-03 14:44:03 +02:00
|
|
|
|
|
|
|
|
2014-07-02 12:57:14 +02:00
|
|
|
|
|
|
|
north.setLayout(new FitLayout());
|
|
|
|
north.setTopComponent(toolbar.getToolBar());
|
|
|
|
north.add(toolbar.getToolBar());
|
|
|
|
|
|
|
|
west.setLayout(new FitLayout());
|
|
|
|
west.setHeading("Databases Resources");
|
|
|
|
|
|
|
|
west.add(treePanel);
|
|
|
|
west.setScrollMode(Scroll.AUTO);
|
|
|
|
|
|
|
|
center.setLayout(new BorderLayout());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
public void createLayouts() {
|
|
|
|
|
|
|
|
// Border layout for the external container
|
|
|
|
final BorderLayout borderLayoutNordWest = new BorderLayout();
|
|
|
|
setLayout(borderLayoutNordWest);
|
|
|
|
|
|
|
|
// NORD
|
|
|
|
BorderLayoutData northData = new BorderLayoutData(LayoutRegion.NORTH,
|
|
|
|
55, 55, 70);
|
|
|
|
|
|
|
|
northData.setSplit(false); // Split bar between regions
|
|
|
|
// northData.setFloatable(true);
|
|
|
|
// northData.setCollapsible(true);
|
|
|
|
// northData.setHideCollapseTool(false);
|
|
|
|
// northData.setSplit(true);
|
|
|
|
northData.setMargins(new Margins(0, 0, 1, 0));
|
|
|
|
|
|
|
|
// WEST
|
|
|
|
BorderLayoutData westData = new BorderLayoutData(LayoutRegion.WEST,
|
|
|
|
330, 330, 400);
|
|
|
|
westData.setSplit(true);
|
|
|
|
westData.setCollapsible(true);
|
|
|
|
westData.setMargins(new Margins(0, 1, 0, 0));
|
|
|
|
|
|
|
|
// CENTER
|
|
|
|
|
|
|
|
BorderLayoutData centerData = new BorderLayoutData(LayoutRegion.CENTER);
|
|
|
|
centerData.setMargins(new Margins(0));
|
|
|
|
// center.setHeading("Information");
|
|
|
|
centerData.setSplit(true);
|
|
|
|
centerData.setCollapsible(true);
|
|
|
|
|
|
|
|
// CENTER UPPER
|
|
|
|
|
|
|
|
centerUpper = new ContentPanel();
|
|
|
|
centerUpper.setLayout(new FitLayout());
|
|
|
|
centerUpper.setHeading("Database Information");
|
|
|
|
centerUpper.setScrollMode(Scroll.NONE);
|
|
|
|
|
|
|
|
// CENTER BOTTOM
|
|
|
|
|
|
|
|
centerBottom = new ContentPanel();
|
|
|
|
centerBottom.setLayout(new FitLayout());
|
|
|
|
centerBottom.setHeading("Information Details");
|
|
|
|
centerBottom.setScrollMode(Scroll.AUTO);
|
|
|
|
|
|
|
|
BorderLayoutData centerUpperData = new BorderLayoutData(
|
|
|
|
LayoutRegion.NORTH, 250, 100, 250);
|
|
|
|
|
|
|
|
centerUpperData.setSplit(true); // Split bar between regions
|
|
|
|
// northData.setFloatable(true);
|
|
|
|
centerUpperData.setCollapsible(false);
|
|
|
|
// northData.setHideCollapseTool(false);
|
|
|
|
// northData.setSplit(true);
|
|
|
|
centerUpperData.setMargins(new Margins(0, 0, 1, 0));
|
|
|
|
|
|
|
|
// BorderLayoutData centerBottomData = new
|
|
|
|
// BorderLayoutData(LayoutRegion.CENTER,
|
|
|
|
// 50, 30, 50);
|
|
|
|
|
|
|
|
BorderLayoutData centerBottomData = new BorderLayoutData(
|
|
|
|
LayoutRegion.CENTER);
|
|
|
|
centerBottomData.setSplit(true);
|
|
|
|
centerBottomData.setCollapsible(false);
|
|
|
|
centerBottomData.setMargins(new Margins(0));
|
|
|
|
// centerBottomData.setMargins(new Margins(1, 0, 0, 0));
|
|
|
|
|
|
|
|
// to add the central panels to the second container
|
|
|
|
center.add(centerUpper, centerUpperData);
|
|
|
|
center.add(centerBottom, centerBottomData);
|
|
|
|
|
|
|
|
add(north, northData);
|
|
|
|
add(west, westData);
|
|
|
|
add(center, centerData);
|
|
|
|
// add(east, eastData);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
private void addHandler() {
|
|
|
|
|
|
|
|
eventBus.addHandler(SelectedItemEvent.TYPE,
|
|
|
|
new SelectedItemEventHandler() {
|
|
|
|
|
|
|
|
public void onSelectedItem(
|
|
|
|
SelectedItemEvent selectedItemEvent) {
|
|
|
|
|
2014-07-03 14:44:03 +02:00
|
|
|
// System.out
|
|
|
|
// .println("GxtBorderLayoutPanel: Event received");
|
|
|
|
|
2014-07-02 12:57:14 +02:00
|
|
|
rootLogger.log(Level.SEVERE, "Event received");
|
|
|
|
|
|
|
|
int DepthSelectedItem = treePanel
|
|
|
|
.getTreeDepthSelectedItem();
|
|
|
|
|
2014-07-03 14:44:03 +02:00
|
|
|
// System.out.println("GxtBorderLayoutPanel-> Depth: "
|
|
|
|
// + DepthSelectedItem);
|
2014-07-02 12:57:14 +02:00
|
|
|
|
|
|
|
// element name selected
|
|
|
|
String text = treePanel.getValue();
|
|
|
|
|
2014-07-03 14:44:03 +02:00
|
|
|
// System.out
|
|
|
|
// .println("GxtBorderLayoutPanel-> item selected: "
|
|
|
|
// + text);
|
|
|
|
|
2014-07-02 12:57:14 +02:00
|
|
|
rootLogger.log(Level.INFO, "item selected: " + text);
|
|
|
|
|
|
|
|
toolbar.disableButtonOnToolbar(DepthSelectedItem,
|
|
|
|
treePanel.getSelectedItemIsSchema());
|
|
|
|
|
|
|
|
if (DepthSelectedItem != 3) {
|
|
|
|
|
|
|
|
centerUpper.removeAll();
|
|
|
|
|
|
|
|
centerUpper.layout(true);
|
|
|
|
|
|
|
|
}
|
2014-07-03 14:44:03 +02:00
|
|
|
|
2014-07-02 12:57:14 +02:00
|
|
|
List<FileModel> data = treePanel.getTreePanel()
|
|
|
|
.getSelectionModel().getSelectedItems();
|
2014-07-03 14:44:03 +02:00
|
|
|
|
2014-07-02 12:57:14 +02:00
|
|
|
FileModel selectedItem = data.get(0);
|
|
|
|
|
|
|
|
if (DepthSelectedItem == 3) { // the item selected is a
|
|
|
|
// database.
|
|
|
|
|
|
|
|
// show database information in the panel
|
|
|
|
|
2014-07-03 14:44:03 +02:00
|
|
|
// List<FileModel> data = treePanel.getTreePanel()
|
|
|
|
// .getSelectionModel().getSelectedItems();
|
|
|
|
// FileModel selectedItem = data.get(0);
|
2014-07-02 12:57:14 +02:00
|
|
|
|
|
|
|
FileModel parent = treePanel.getTreeStore()
|
|
|
|
.getParent(selectedItem);
|
|
|
|
|
|
|
|
// displayDBInfo(parent);
|
|
|
|
|
|
|
|
// display information about the selected database
|
|
|
|
displayDBInfo(data.get(0));
|
|
|
|
|
|
|
|
}
|
2014-07-03 14:44:03 +02:00
|
|
|
|
|
|
|
// display the table name in the right panel when a
|
|
|
|
// table is selected
|
|
|
|
|
|
|
|
if (DepthSelectedItem == 5) {
|
|
|
|
|
2014-07-02 12:57:14 +02:00
|
|
|
centerUpper.removeAll();
|
|
|
|
|
|
|
|
centerUpper.addText(data.get(0).getName());
|
2014-07-03 14:44:03 +02:00
|
|
|
|
2014-07-02 12:57:14 +02:00
|
|
|
centerUpper.layout(true);
|
2014-07-03 14:44:03 +02:00
|
|
|
|
2014-07-02 12:57:14 +02:00
|
|
|
}
|
2014-07-03 14:44:03 +02:00
|
|
|
|
|
|
|
if ((DepthSelectedItem == 4)
|
|
|
|
&& (data.get(0).isSchema() == false)) {
|
|
|
|
|
2014-07-02 12:57:14 +02:00
|
|
|
centerUpper.removeAll();
|
|
|
|
|
|
|
|
centerUpper.addText(data.get(0).getName());
|
2014-07-03 14:44:03 +02:00
|
|
|
|
2014-07-02 12:57:14 +02:00
|
|
|
centerUpper.layout(true);
|
2014-07-03 14:44:03 +02:00
|
|
|
|
2014-07-02 12:57:14 +02:00
|
|
|
}
|
|
|
|
|
2014-07-03 14:44:03 +02:00
|
|
|
// System.out
|
|
|
|
// .println("GxtBorderLayoutPanel: Event finished");
|
|
|
|
|
2014-07-02 12:57:14 +02:00
|
|
|
rootLogger.log(Level.SEVERE, "Event finished");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
eventBus.addHandler(SubmitQueryEvent.TYPE,
|
|
|
|
new SubmitQueryEventHandler() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onSubmitQuery(SubmitQueryEvent submitQueryEvent) {
|
|
|
|
// TODO Auto-generated method stub
|
|
|
|
|
2014-07-03 14:44:03 +02:00
|
|
|
// try {
|
|
|
|
// submitQuery();
|
|
|
|
// } catch (Exception e) {
|
|
|
|
// // TODO Auto-generated catch block
|
|
|
|
// e.printStackTrace();
|
|
|
|
// }
|
|
|
|
|
|
|
|
submitQuery();
|
2014-07-02 12:57:14 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2014-07-03 14:44:03 +02:00
|
|
|
eventBus.addHandler(SamplingEvent.TYPE, new SamplingEventHandler() {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onSampling(SamplingEvent samplingEvent) {
|
|
|
|
// TODO Auto-generated method stub
|
|
|
|
|
|
|
|
sample();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2014-07-02 12:57:14 +02:00
|
|
|
}
|
|
|
|
|
2014-07-03 14:44:03 +02:00
|
|
|
private void submitQuery() {
|
|
|
|
|
|
|
|
// System.out.println("Start RPC - submitQuery");
|
2014-07-02 12:57:14 +02:00
|
|
|
|
|
|
|
rootLogger.log(Level.SEVERE, "Start RPC - submitQuery");
|
|
|
|
|
2014-07-03 14:44:03 +02:00
|
|
|
// variable that keeps track of the managed event
|
|
|
|
submitQueryEventManaged = false;
|
|
|
|
|
2014-07-02 12:57:14 +02:00
|
|
|
// recover input data
|
|
|
|
|
|
|
|
LinkedHashMap<String, String> dataDB = treePanel
|
|
|
|
.getInfoOnSelectedItem();
|
|
|
|
|
|
|
|
final SubmitQueryData dataQuery = toolbar.getSubmitQueryData();
|
|
|
|
|
|
|
|
// RPCservice.submitQuery(dataDB, dataQuery.getQuery(),
|
|
|
|
// dataQuery.getReadOnlyQuery(), dataQuery.getSmartCorrection(),
|
|
|
|
// dataQuery.getLanguage(), new AsyncCallback<List<Result>>() {
|
|
|
|
|
|
|
|
// force the "true" value for the readonly input.
|
|
|
|
|
|
|
|
// determine the language
|
|
|
|
List<FileModel> data = treePanel.getTreePanel().getSelectionModel()
|
|
|
|
.getSelectedItems();
|
|
|
|
FileModel selectedItem = data.get(0);
|
|
|
|
|
|
|
|
String dialect;
|
|
|
|
|
|
|
|
if (selectedItem.isDatabase()) { // the selected item is a database
|
2014-07-03 14:44:03 +02:00
|
|
|
|
|
|
|
// System.out.println("the selected item is a database");
|
2014-07-02 12:57:14 +02:00
|
|
|
rootLogger.log(Level.INFO, "the selected item is a database");
|
|
|
|
|
|
|
|
// determine the dialect recovering the dialect
|
|
|
|
dialect = selectedItem.getDBInfo().get(2).getValue();
|
2014-07-03 14:44:03 +02:00
|
|
|
|
|
|
|
rootLogger.log(Level.INFO,
|
|
|
|
"determined Dialect for smart correction: " + dialect);
|
2014-07-02 12:57:14 +02:00
|
|
|
|
|
|
|
} else {
|
|
|
|
FileModel parent1 = treePanel.getTreeStore()
|
|
|
|
.getParent(selectedItem);
|
|
|
|
|
|
|
|
if (parent1.isDatabase()) { // the selected item is a schema
|
2014-07-03 14:44:03 +02:00
|
|
|
|
|
|
|
// System.out.println("the selected item is a schema");
|
|
|
|
|
2014-07-02 12:57:14 +02:00
|
|
|
rootLogger.log(Level.INFO, "the selected item is a schema");
|
|
|
|
|
|
|
|
// determine the dialect recovering the dialect
|
|
|
|
dialect = parent1.getDBInfo().get(2).getValue();
|
2014-07-03 14:44:03 +02:00
|
|
|
|
|
|
|
rootLogger.log(Level.INFO,
|
|
|
|
"determined Dialect for smart correction: " + dialect);
|
2014-07-02 12:57:14 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else { // the selected item is a table
|
|
|
|
|
2014-07-03 14:44:03 +02:00
|
|
|
// System.out.println("the selected item is a table");
|
|
|
|
|
2014-07-02 12:57:14 +02:00
|
|
|
rootLogger.log(Level.INFO, "the selected item is a table");
|
2014-07-03 14:44:03 +02:00
|
|
|
|
2014-07-02 12:57:14 +02:00
|
|
|
FileModel parent2 = treePanel.getTreeStore().getParent(parent1);
|
|
|
|
|
|
|
|
// determine the dialect recovering the dialect
|
|
|
|
dialect = parent2.getDBInfo().get(2).getValue();
|
2014-07-03 14:44:03 +02:00
|
|
|
|
|
|
|
rootLogger.log(Level.INFO,
|
|
|
|
"determined Dialect for smart correction: " + dialect);
|
2014-07-02 12:57:14 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
String language = ConstantsPortlet.NONE;
|
|
|
|
|
|
|
|
if (dialect.toUpperCase().contains(ConstantsPortlet.POSTGRES)) {
|
|
|
|
|
|
|
|
language = ConstantsPortlet.POSTGRES;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (dialect.toUpperCase().contains(ConstantsPortlet.MYSQL)) {
|
|
|
|
|
|
|
|
language = ConstantsPortlet.MYSQL;
|
|
|
|
}
|
2014-07-03 14:44:03 +02:00
|
|
|
|
|
|
|
rootLogger.log(Level.INFO, "Dialect used for smart correction: "
|
|
|
|
+ language);
|
2014-07-02 12:57:14 +02:00
|
|
|
|
|
|
|
RPCservice.submitQuery(dataDB, dataQuery.getQuery(), true,
|
|
|
|
dataQuery.getSmartCorrection(), language,
|
|
|
|
new AsyncCallback<List<Result>>() {
|
|
|
|
|
|
|
|
// // TO REMOVE data "true" and "POSTGRES"
|
|
|
|
// RPCservice.submitQuery(dataDB, dataQuery.getQuery(),
|
|
|
|
// true,
|
|
|
|
// dataQuery.getSmartCorrection(), "POSTGRES",
|
|
|
|
// new AsyncCallback<List<Result>>() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onFailure(Throwable caught) {
|
|
|
|
|
2014-07-03 14:44:03 +02:00
|
|
|
// Window.alert(caught.getMessage());
|
|
|
|
|
|
|
|
// System.out.println("FAILURE submitQuery");
|
|
|
|
|
2014-07-02 12:57:14 +02:00
|
|
|
rootLogger.log(Level.SEVERE, "FAILURE RPC submitQuery");
|
2014-07-03 14:44:03 +02:00
|
|
|
|
|
|
|
Listener<MessageBoxEvent> l = new Listener<MessageBoxEvent>() {
|
|
|
|
public void handleEvent(MessageBoxEvent ce) {
|
|
|
|
// Button btn = ce.getButtonClicked();
|
|
|
|
// Info.display("MessageBox",
|
|
|
|
// "The '{0}' button was pressed",
|
|
|
|
// btn.getHtml());
|
|
|
|
|
|
|
|
// Button btn = ce.getButtonClicked();
|
|
|
|
|
|
|
|
Dialog form = toolbar.getDialogForm();
|
|
|
|
|
|
|
|
if (form.isMasked())
|
|
|
|
form.unmask();
|
|
|
|
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
// MessageBox.alert("Error "," <br/>Cause:"+caught.getCause()+"<br/>Message:"+caught.getMessage(),
|
|
|
|
// l);
|
|
|
|
MessageBox.alert("Error ",
|
|
|
|
"<br/>Message:" + caught.getMessage(), l);
|
2014-07-02 12:57:14 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onSuccess(List<Result> result) {
|
|
|
|
// TODO Auto-generated method stub
|
|
|
|
|
2014-07-03 14:44:03 +02:00
|
|
|
// System.out.println("SUCCESS submitQuery");
|
|
|
|
|
2014-07-02 12:57:14 +02:00
|
|
|
rootLogger.log(Level.SEVERE, "SUCCESS RPC submitQuery");
|
|
|
|
|
|
|
|
rows = new ArrayList<Row>();
|
|
|
|
|
2014-07-03 14:44:03 +02:00
|
|
|
// System.out.println("result size: " + result.size());
|
|
|
|
|
|
|
|
rootLogger.log(Level.SEVERE,
|
|
|
|
"output size: " + result.size());
|
2014-07-02 12:57:14 +02:00
|
|
|
|
|
|
|
// recover query
|
|
|
|
// Result query = result.remove(0);
|
|
|
|
|
|
|
|
// recover converted query
|
|
|
|
Result convertedQuery;
|
|
|
|
|
|
|
|
if (dataQuery.getSmartCorrection() == true) {
|
|
|
|
|
|
|
|
result.remove(0);
|
|
|
|
// convertedQuery = result.get(1);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// get the attributes list for the result table
|
|
|
|
getListAttributes(result.get(0).getValue());
|
|
|
|
|
|
|
|
// remove the header in order to parse only the result
|
|
|
|
result.remove(0);
|
|
|
|
|
2014-07-03 14:44:03 +02:00
|
|
|
// variable that keeps track of the managed event
|
|
|
|
submitQueryEventManaged = true;
|
|
|
|
|
|
|
|
// parse the result in order to obtain a table
|
2014-07-02 12:57:14 +02:00
|
|
|
parseResult(result);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2014-07-03 14:44:03 +02:00
|
|
|
private void sample() {
|
|
|
|
|
|
|
|
// this.mask();
|
|
|
|
|
|
|
|
// System.out.println("Start RPC - submitQuery");
|
|
|
|
|
|
|
|
rootLogger.log(Level.SEVERE, "Start RPC - sample");
|
|
|
|
|
|
|
|
// get the selected table
|
|
|
|
|
|
|
|
List<FileModel> data = treePanel.getTreePanel().getSelectionModel()
|
|
|
|
.getSelectedItems();
|
|
|
|
|
|
|
|
// the selected item is a table
|
|
|
|
FileModel selectedItem = data.get(0);
|
|
|
|
|
|
|
|
rootLogger.log(Level.INFO, "the selected table is: " + selectedItem);
|
|
|
|
|
|
|
|
// recover data inputs
|
|
|
|
|
|
|
|
LinkedHashMap<String, String> dataInput = new LinkedHashMap<String, String>();
|
|
|
|
|
|
|
|
// check if the table has an associated schema
|
|
|
|
FileModel schema;
|
|
|
|
FileModel database;
|
|
|
|
FileModel resource;
|
|
|
|
|
|
|
|
if (treePanel.getTreeStore().getParent(selectedItem).isSchema()) {
|
|
|
|
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 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());
|
|
|
|
}
|
|
|
|
|
|
|
|
// call remote service
|
|
|
|
|
|
|
|
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");
|
|
|
|
|
|
|
|
MessageBox.alert("Error ",
|
|
|
|
"<br/>Message:" + caught.getMessage(), null);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onSuccess(List<Result> result) {
|
|
|
|
|
|
|
|
rootLogger.log(Level.SEVERE, "SUCCESS RPC sample");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
rows = new ArrayList<Row>();
|
|
|
|
|
|
|
|
// System.out.println("result size: " + result.size());
|
|
|
|
|
|
|
|
rootLogger.log(Level.SEVERE, "output size: " + result.size());
|
|
|
|
|
|
|
|
// get the attributes list for the result table
|
|
|
|
getListAttributes(result.get(0).getValue());
|
|
|
|
|
|
|
|
// remove the header in order to parse only the result
|
|
|
|
result.remove(0);
|
|
|
|
|
|
|
|
// parse the result in order to obtain a table
|
|
|
|
parseResult(result);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2014-07-02 12:57:14 +02:00
|
|
|
// start the parsing of the submit result in order to obtain a table
|
|
|
|
private void parseResult(List<Result> result) {
|
2014-07-03 14:44:03 +02:00
|
|
|
|
|
|
|
|
2014-07-02 12:57:14 +02:00
|
|
|
|
|
|
|
RPCservice.parseCVSString(result, listAttributes,
|
|
|
|
new AsyncCallback<List<Row>>() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onFailure(Throwable caught) {
|
|
|
|
// TODO Auto-generated method stub
|
|
|
|
|
|
|
|
Window.alert(caught.getMessage());
|
2014-07-03 14:44:03 +02:00
|
|
|
// System.out.println("FAILURE StartParse");
|
|
|
|
|
2014-07-02 12:57:14 +02:00
|
|
|
rootLogger.log(Level.SEVERE, "FAILURE RPC parseResult");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onSuccess(List<Row> rows) {
|
|
|
|
|
2014-07-03 14:44:03 +02:00
|
|
|
|
|
|
|
|
|
|
|
// System.out.println("Success StartParse");
|
|
|
|
|
2014-07-02 12:57:14 +02:00
|
|
|
rootLogger.log(Level.SEVERE, "SUCCESS RPC parseResult");
|
|
|
|
|
2014-07-03 14:44:03 +02:00
|
|
|
if (submitQueryEventManaged == true) {
|
|
|
|
|
2014-07-02 12:57:14 +02:00
|
|
|
Dialog form = toolbar.getDialogForm();
|
2014-07-03 14:44:03 +02:00
|
|
|
|
2014-07-02 12:57:14 +02:00
|
|
|
if (form.isMasked())
|
|
|
|
form.unmask();
|
2014-07-03 14:44:03 +02:00
|
|
|
|
|
|
|
form.hide();
|
2014-07-02 12:57:14 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
2014-07-03 14:44:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// else {
|
2014-07-02 12:57:14 +02:00
|
|
|
|
2014-07-03 14:44:03 +02:00
|
|
|
if (rows != null) {
|
2014-07-02 12:57:14 +02:00
|
|
|
|
2014-07-03 14:44:03 +02:00
|
|
|
// Dialog form = toolbar.getDialogForm();
|
|
|
|
//
|
|
|
|
// if (form.isMasked())
|
|
|
|
// form.unmask();
|
|
|
|
//
|
|
|
|
// form.hide();
|
2014-07-02 12:57:14 +02:00
|
|
|
|
2014-07-03 14:44:03 +02:00
|
|
|
// Display the submit query result as a table
|
|
|
|
Dialog submitResult = new Dialog();
|
|
|
|
submitResult.setLayout(new FitLayout());
|
|
|
|
submitResult.setHeading("Result");
|
2014-07-02 12:57:14 +02:00
|
|
|
|
2014-07-03 14:44:03 +02:00
|
|
|
submitResult.setResizable(false);
|
|
|
|
// submitResult.setHeading("Submit Query");
|
|
|
|
// submitResult.setWidth(290);
|
|
|
|
// submitResult.setHeight(250);
|
2014-07-02 12:57:14 +02:00
|
|
|
|
2014-07-03 14:44:03 +02:00
|
|
|
submitResult.setModal(true);
|
|
|
|
submitResult.setBlinkModal(true);
|
2014-07-02 12:57:14 +02:00
|
|
|
|
2014-07-03 14:44:03 +02:00
|
|
|
// submitResult.setBodyStyle("padding:9px;");
|
|
|
|
submitResult.setSize(600, 400);
|
|
|
|
// submitResult.setScrollMode(Scroll.AUTO);
|
|
|
|
submitResult.setScrollMode(Scroll.NONE);
|
|
|
|
submitResult.setHideOnButtonClick(true);
|
2014-07-02 12:57:14 +02:00
|
|
|
|
2014-07-03 14:44:03 +02:00
|
|
|
submitResult.setMaximizable(true);
|
|
|
|
// submitResult.addText("Result Table");
|
2014-07-02 12:57:14 +02:00
|
|
|
|
2014-07-03 14:44:03 +02:00
|
|
|
ListStore<Row> store = new ListStore<Row>();
|
|
|
|
store.add(rows);
|
2014-07-02 12:57:14 +02:00
|
|
|
|
2014-07-03 14:44:03 +02:00
|
|
|
Grid<Row> grid;
|
2014-07-02 12:57:14 +02:00
|
|
|
|
2014-07-03 14:44:03 +02:00
|
|
|
grid = new Grid<Row>(store, createColumnModel());
|
2014-07-02 12:57:14 +02:00
|
|
|
|
2014-07-03 14:44:03 +02:00
|
|
|
// grid.setAutoExpandColumn("value");
|
|
|
|
grid.setBorders(true);
|
2014-07-02 12:57:14 +02:00
|
|
|
|
2014-07-03 14:44:03 +02:00
|
|
|
// grid.setAutoWidth(true);
|
2014-07-02 12:57:14 +02:00
|
|
|
|
2014-07-03 14:44:03 +02:00
|
|
|
RowData data = new RowData(.5, 1);
|
|
|
|
data.setMargins(new Margins(6));
|
|
|
|
|
|
|
|
submitResult.add(grid, data);
|
|
|
|
|
|
|
|
submitResult.show();
|
|
|
|
|
|
|
|
}
|
|
|
|
// }
|
|
|
|
|
2014-07-02 12:57:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// private void updateListRow(Row row){
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
// rows.add(row);
|
|
|
|
//
|
|
|
|
// System.out.println("CHECK size2: " + rows.size());
|
|
|
|
//
|
|
|
|
//
|
|
|
|
// }
|
|
|
|
|
|
|
|
// private void returnParsedeList(List<String> result) {
|
|
|
|
//
|
|
|
|
// parsedList = new ArrayList<String>();
|
|
|
|
// for (String s : result) {
|
|
|
|
//
|
|
|
|
// System.out.println("value: " + result);
|
|
|
|
// parsedList.add(s);
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// System.out.println("size row1: " + result.size());
|
|
|
|
//
|
|
|
|
// }
|
|
|
|
|
|
|
|
private void getListAttributes(String value) {
|
|
|
|
|
|
|
|
// recover attribute fields fo the result table
|
|
|
|
String headers = value;
|
|
|
|
|
2014-07-03 14:44:03 +02:00
|
|
|
// System.out.println("headers: " + headers);
|
|
|
|
|
2014-07-02 12:57:14 +02:00
|
|
|
rootLogger.log(Level.INFO, "Headers fields table: " + headers);
|
|
|
|
|
|
|
|
listAttributes = parseAttributesTableResult(headers);
|
|
|
|
|
2014-07-03 14:44:03 +02:00
|
|
|
// System.out.println("attributes number: " + listAttributes.size());
|
|
|
|
|
|
|
|
rootLogger.log(Level.INFO,
|
|
|
|
"attributes number: " + listAttributes.size());
|
2014-07-02 12:57:14 +02:00
|
|
|
|
|
|
|
rootLogger.log(Level.INFO, "attributes list: ");
|
|
|
|
|
|
|
|
for (int i = 0; i < listAttributes.size(); i++) {
|
|
|
|
|
2014-07-03 14:44:03 +02:00
|
|
|
// System.out.println(listAttributes.get(i));
|
|
|
|
|
2014-07-02 12:57:14 +02:00
|
|
|
rootLogger.log(Level.INFO, "attribute: " + listAttributes.get(i));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
private ColumnModel createColumnModel() {
|
|
|
|
|
|
|
|
List<ColumnConfig> configs = new ArrayList<ColumnConfig>();
|
|
|
|
ColumnConfig column;
|
|
|
|
|
|
|
|
column = new ColumnConfig();
|
|
|
|
|
|
|
|
column.setId("index");
|
|
|
|
column.setHeader("Index");
|
|
|
|
column.setWidth(100);
|
|
|
|
column.setSortable(false);
|
|
|
|
|
|
|
|
configs.add(column);
|
|
|
|
|
|
|
|
for (int i = 0; i < listAttributes.size(); i++) {
|
|
|
|
|
2014-07-03 14:44:03 +02:00
|
|
|
// System.out.println("attribute: " + listAttributes.get(i));
|
2014-07-02 12:57:14 +02:00
|
|
|
rootLogger.log(Level.INFO, "attribute: " + listAttributes.get(i));
|
|
|
|
column = new ColumnConfig();
|
|
|
|
column.setId(listAttributes.get(i));
|
|
|
|
// column.setId("\"" + fields.get(i) + "\"");
|
|
|
|
column.setHeader(listAttributes.get(i));
|
|
|
|
column.setWidth(100);
|
|
|
|
column.setSortable(false);
|
|
|
|
|
|
|
|
configs.add(column);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return new ColumnModel(configs);
|
|
|
|
}
|
|
|
|
|
|
|
|
// private String[] parseAttributesTableResult(String value) {
|
|
|
|
//
|
|
|
|
// System.out.println("parsing attributes table");
|
|
|
|
//
|
|
|
|
// String todelete = "[,]";
|
|
|
|
//
|
|
|
|
// value = value.replaceAll(todelete, " ");
|
|
|
|
// value = value.replaceAll("[ ]+", " ");
|
|
|
|
//
|
|
|
|
// String[] tokens = value.split("[ ]");
|
|
|
|
// return tokens;
|
|
|
|
//
|
|
|
|
// }
|
|
|
|
|
|
|
|
private List<String> parseAttributesTableResult(String phrase) {
|
|
|
|
|
|
|
|
String delimiter = ",";
|
|
|
|
List<String> elements = new ArrayList<String>();
|
|
|
|
int idxdelim = -1;
|
|
|
|
phrase = phrase.trim();
|
|
|
|
|
|
|
|
while ((idxdelim = phrase.indexOf(delimiter)) >= 0) {
|
|
|
|
|
|
|
|
elements.add(phrase.substring(0, idxdelim));
|
|
|
|
phrase = phrase.substring(idxdelim + 1).trim();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
elements.add(phrase);
|
|
|
|
return elements;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
private ColumnModel createColumnModelForDBInfo(List<Result> result) {
|
|
|
|
List<ColumnConfig> configs = new ArrayList<ColumnConfig>();
|
|
|
|
|
|
|
|
ColumnConfig column = new ColumnConfig();
|
|
|
|
column.setId("index");
|
|
|
|
column.setHeader("Property");
|
|
|
|
column.setWidth(100);
|
|
|
|
column.setSortable(false);
|
|
|
|
|
|
|
|
configs.add(column);
|
|
|
|
|
|
|
|
column = new ColumnConfig();
|
|
|
|
column.setId("value");
|
|
|
|
column.setHeader("Value");
|
|
|
|
column.setWidth(600);
|
|
|
|
|
|
|
|
column.setSortable(false);
|
|
|
|
|
|
|
|
configs.add(column);
|
|
|
|
|
|
|
|
ListStore<Result> store = new ListStore<Result>();
|
|
|
|
store.add(result);
|
|
|
|
|
|
|
|
return new ColumnModel(configs);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void displayDBInfo(FileModel element) {
|
|
|
|
|
2014-07-03 14:44:03 +02:00
|
|
|
// System.out.println("GxtBorderLayout->displaying info");
|
|
|
|
|
2014-07-02 12:57:14 +02:00
|
|
|
rootLogger.log(Level.INFO, "displaying info");
|
|
|
|
|
|
|
|
// LinkedHashMap<String, FileModel> data = element.getDBInfo();
|
|
|
|
|
|
|
|
List<Result> dataDB = element.getDBInfo();
|
|
|
|
|
2014-07-03 14:44:03 +02:00
|
|
|
// System.out.println("GxtBorderLayout->size info: " + dataDB.size());
|
|
|
|
|
2014-07-02 12:57:14 +02:00
|
|
|
rootLogger.log(Level.INFO, "info size: " + dataDB.size());
|
|
|
|
|
|
|
|
ListStore<Result> store = new ListStore<Result>();
|
|
|
|
store.add(dataDB);
|
|
|
|
|
|
|
|
Grid<Result> grid = new Grid<Result>(store,
|
|
|
|
createColumnModelForDBInfo(dataDB));
|
|
|
|
|
|
|
|
// grid.setAutoExpandColumn("name");
|
|
|
|
grid.setBorders(true);
|
|
|
|
|
|
|
|
// grid.setAutoWidth(true);
|
|
|
|
|
|
|
|
RowData data = new RowData(.5, 1);
|
|
|
|
data.setMargins(new Margins(6));
|
|
|
|
|
|
|
|
centerUpper.removeAll();
|
|
|
|
|
|
|
|
centerUpper.add(grid, data);
|
|
|
|
centerUpper.layout(true);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|