2406 lines
64 KiB
Java
2406 lines
64 KiB
Java
package org.gcube.portlets.user.databasesmanager.client.panels;
|
|
|
|
import java.util.ArrayList;
|
|
import java.util.LinkedHashMap;
|
|
import java.util.List;
|
|
import java.util.Set;
|
|
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;
|
|
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.SelectedTableEvent;
|
|
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;
|
|
import org.gcube.portlets.user.databasesmanager.client.events.interfaces.ShowCreateTableEventHandler;
|
|
import org.gcube.portlets.user.databasesmanager.client.events.interfaces.SmartSamplingEventHandler;
|
|
import org.gcube.portlets.user.databasesmanager.client.events.interfaces.SubmitQueryEventHandler;
|
|
import org.gcube.portlets.user.databasesmanager.client.resources.Images;
|
|
import org.gcube.portlets.user.databasesmanager.client.toolbar.GxtToolbarFunctionality;
|
|
import org.gcube.portlets.user.databasesmanager.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.Style.SelectionMode;
|
|
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.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;
|
|
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.EditorGrid.ClicksToEdit;
|
|
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.extjs.gxt.ui.client.widget.toolbar.PagingToolBar;
|
|
import com.extjs.gxt.ui.client.widget.toolbar.ToolBar;
|
|
import com.google.gwt.event.dom.client.KeyCodes;
|
|
import com.google.gwt.event.shared.HandlerManager;
|
|
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.ButtonEvent;
|
|
import com.extjs.gxt.ui.client.event.ComponentEvent;
|
|
import com.extjs.gxt.ui.client.event.Events;
|
|
import com.extjs.gxt.ui.client.event.GridEvent;
|
|
import com.extjs.gxt.ui.client.event.KeyListener;
|
|
import com.extjs.gxt.ui.client.event.Listener;
|
|
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;
|
|
|
|
//class that represents the container of all components
|
|
public class GxtBorderLayoutPanel extends ContentPanel {
|
|
|
|
/* 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;
|
|
// top toolbar that contains the buttons
|
|
private GxtToolbarFunctionality toolbar;
|
|
|
|
private List<String> listAttributes;
|
|
|
|
// bus to manage events
|
|
private HandlerManager eventBus = null;
|
|
|
|
// RPC service
|
|
private GWTdbManagerServiceAsync RPCservice = null;
|
|
|
|
// variable that keeps track of the "submitquery" managed event
|
|
// private boolean submitQueryEventManaged = false;
|
|
|
|
// to keep track that the tables list is not null
|
|
// private boolean tablesListNotNull = false;
|
|
|
|
// dialog used to display the tables list
|
|
private Dialog tablesLoaded = null;
|
|
|
|
// to keep track of selected table in the tables list
|
|
private String selectedTable = null;
|
|
private FileModel table = new FileModel("");
|
|
|
|
// variables to perform the table search
|
|
private String keyword = "";
|
|
private boolean startSearchTable = false;
|
|
|
|
// toolbar for table search functionality
|
|
private ToolBar toolBarTop = null;
|
|
|
|
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);
|
|
|
|
this.setHeaderVisible(false);
|
|
|
|
initLayout();
|
|
createLayouts();
|
|
|
|
addHandler();
|
|
|
|
}
|
|
|
|
private void initLayout() {
|
|
|
|
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);
|
|
|
|
// centerUpper.setBottomComponent(toolBar);
|
|
// toolBar.hide();
|
|
|
|
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);
|
|
|
|
// CENTER BOTTOM
|
|
centerBottom = new ContentPanel();
|
|
centerBottom.setLayout(new FitLayout());
|
|
centerBottom.setHeading("Information Details");
|
|
centerBottom.setScrollMode(Scroll.NONE);
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
// to add handlers
|
|
private void addHandler() {
|
|
|
|
eventBus.addHandler(SelectedItemEvent.TYPE,
|
|
new SelectedItemEventHandler() {
|
|
|
|
public void onSelectedItem(
|
|
SelectedItemEvent selectedItemEvent) {
|
|
|
|
// force the clean of the content panel
|
|
centerBottom.removeAll();
|
|
centerBottom.layout(true);
|
|
|
|
// print check
|
|
// System.out
|
|
// .println("GxtBorderLayoutPanel: Event received");
|
|
|
|
// rootLogger.log(Level.SEVERE,
|
|
// "SelectedItemEvent management");
|
|
|
|
// to get the selected item with its depth
|
|
List<FileModel> data = treePanel.getTreePanel()
|
|
.getSelectionModel().getSelectedItems();
|
|
|
|
FileModel selectedItem = data.get(0);
|
|
|
|
int DepthSelectedItem = treePanel.getTreeStore()
|
|
.getDepth(selectedItem);
|
|
|
|
String text = selectedItem.getName();
|
|
|
|
// print check
|
|
// System.out
|
|
// .println("GxtBorderLayoutPanel--> selected item: "
|
|
// + text);
|
|
|
|
rootLogger.log(Level.INFO, "selected item: " + text);
|
|
|
|
// toolbar.disableButtonOnToolbar(DepthSelectedItem,
|
|
// treePanel.getSelectedItemIsSchema());
|
|
|
|
// disable table details and sampling buttons
|
|
toolbar.disableButtonsOperationsOnTable();
|
|
|
|
// enable appropriate buttons according the selected
|
|
// item
|
|
toolbar.enableButtonOnToolbar(DepthSelectedItem,
|
|
selectedItem.isSchema(),
|
|
selectedItem.getDatabaseType());
|
|
|
|
// clean variable at each item selection event
|
|
table = new FileModel("");
|
|
|
|
if (DepthSelectedItem != 3) {
|
|
|
|
centerUpper.removeAll();
|
|
|
|
centerUpper.layout(true);
|
|
|
|
}
|
|
|
|
if (DepthSelectedItem == 3) { // the item selected is a
|
|
// database.
|
|
|
|
// show database information in the panel
|
|
|
|
// display information about the selected database
|
|
displayDBInfo(data.get(0));
|
|
|
|
}
|
|
|
|
// // display the table name in the right panel when a
|
|
// // table is selected
|
|
//
|
|
// if (DepthSelectedItem == 5) {
|
|
// centerUpper.removeAll();
|
|
// centerUpper.addText(data.get(0).getName());
|
|
// centerUpper.layout(true);
|
|
// }
|
|
//
|
|
// if ((DepthSelectedItem == 4)
|
|
// && (data.get(0).isSchema() == false)) {
|
|
// centerUpper.removeAll();
|
|
// centerUpper.addText(data.get(0).getName());
|
|
// centerUpper.layout(true);
|
|
// }
|
|
|
|
// print check
|
|
// System.out
|
|
// .println("GxtBorderLayoutPanel: Event finished");
|
|
|
|
// rootLogger.log(Level.SEVERE, "Event finished");
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
eventBus.addHandler(LoadTablesEvent.TYPE, new LoadTablesEventHandler() {
|
|
|
|
@Override
|
|
public void onLoadTables(LoadTablesEvent loadTablesEvent) {
|
|
// TODO Auto-generated method stub
|
|
|
|
loadTables();
|
|
|
|
}
|
|
});
|
|
|
|
eventBus.addHandler(SubmitQueryEvent.TYPE,
|
|
new SubmitQueryEventHandler() {
|
|
|
|
@Override
|
|
public void onSubmitQuery(SubmitQueryEvent submitQueryEvent) {
|
|
// TODO Auto-generated method stub
|
|
|
|
// Integer dialogID = toolbar.getDialogID();
|
|
|
|
Integer dialogID = new Integer(submitQueryEvent
|
|
.getDialogID());
|
|
|
|
rootLogger.log(Level.INFO, "dialogID: " + dialogID);
|
|
|
|
submitQuery(dialogID);
|
|
|
|
}
|
|
});
|
|
|
|
eventBus.addHandler(SamplingEvent.TYPE, new SamplingEventHandler() {
|
|
|
|
@Override
|
|
public void onSampling(SamplingEvent samplingEvent) {
|
|
// TODO Auto-generated method stub
|
|
|
|
sample();
|
|
|
|
}
|
|
});
|
|
|
|
eventBus.addHandler(SmartSamplingEvent.TYPE,
|
|
new SmartSamplingEventHandler() {
|
|
|
|
@Override
|
|
public void onSmartSampling(
|
|
SmartSamplingEvent smartSamplingEvent) {
|
|
// TODO Auto-generated method stub
|
|
|
|
smartSample();
|
|
|
|
}
|
|
});
|
|
|
|
eventBus.addHandler(RandomSamplingEvent.TYPE,
|
|
new RandomSamplingEventHandler() {
|
|
|
|
@Override
|
|
public void onRandomSampling(
|
|
RandomSamplingEvent randomSamplingEvent) {
|
|
// TODO Auto-generated method stub
|
|
|
|
randomSample();
|
|
|
|
}
|
|
});
|
|
|
|
eventBus.addHandler(ShowCreateTableEvent.TYPE,
|
|
new ShowCreateTableEventHandler() {
|
|
|
|
@Override
|
|
public void onShowCreateTable(
|
|
ShowCreateTableEvent showCreateTableEvent) {
|
|
// TODO Auto-generated method stub
|
|
|
|
// get the selected item in the tree
|
|
|
|
List<FileModel> data = treePanel.getTreePanel()
|
|
.getSelectionModel().getSelectedItems();
|
|
|
|
// if the selected table is equal to the previous table
|
|
// keep track that table details have been just
|
|
// displayed
|
|
if (!(table.getName().equals(selectedTable))) {
|
|
|
|
table.setName(selectedTable);
|
|
table.setTableDetailsDisplayed(false);
|
|
}
|
|
|
|
// print check
|
|
// System.out
|
|
// .println("GxtBorderLayoutPanel--> selected table: "
|
|
// + table.getName());
|
|
|
|
rootLogger.log(Level.INFO,
|
|
"selected table: " + table.getName());
|
|
|
|
// get table details
|
|
getTableDetails(table);
|
|
|
|
// }
|
|
|
|
}
|
|
});
|
|
|
|
}
|
|
|
|
// method to load the tables list
|
|
private void loadTables() {
|
|
|
|
// clean variable
|
|
selectedTable = null;
|
|
|
|
// disable table details and sampling buttons
|
|
toolbar.disableButtonsOperationsOnTable();
|
|
|
|
// clean the panel
|
|
centerBottom.removeAll();
|
|
centerBottom.layout(true);
|
|
|
|
// get the selected item
|
|
List<FileModel> data = treePanel.getTreePanel().getSelectionModel()
|
|
.getSelectedItems();
|
|
|
|
FileModel element = data.get(0);
|
|
|
|
// recover data inputs
|
|
final LinkedHashMap<String, String> dataInput = new LinkedHashMap<String, String>();
|
|
|
|
// 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, "selected element is a database ");
|
|
|
|
database = element.getName();
|
|
resource = treePanel.getTreeStore().getParent(element).getName();
|
|
|
|
// add data
|
|
dataInput.put("ResourceName", resource);
|
|
dataInput.put("DatabaseName", database);
|
|
dataInput.put("SchemaName", "");
|
|
|
|
} else { // the selected item is a schema
|
|
|
|
rootLogger.log(Level.INFO, "selected element is a schema ");
|
|
|
|
FileModel db = treePanel.getTreeStore().getParent(element);
|
|
database = db.getName();
|
|
|
|
resource = treePanel.getTreeStore().getParent(db).getName();
|
|
schema = element.getName();
|
|
|
|
// add data
|
|
dataInput.put("ResourceName", resource);
|
|
dataInput.put("DatabaseName", database);
|
|
dataInput.put("SchemaName", schema);
|
|
|
|
}
|
|
|
|
rootLogger.log(Level.INFO, "ResourceName: " + resource);
|
|
rootLogger.log(Level.INFO, "DatabaseName: " + database);
|
|
rootLogger.log(Level.INFO, "SchemaName: " + schema);
|
|
|
|
// tablesListNotNull = false;
|
|
|
|
// create RpcProxy object to use the load configuration
|
|
RpcProxy<PagingLoadResult<Result>> proxy = new RpcProxy<PagingLoadResult<Result>>() {
|
|
|
|
@Override
|
|
protected void load(Object loadConfig,
|
|
final AsyncCallback<PagingLoadResult<Result>> callback) {
|
|
// 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);
|
|
|
|
// remote rpc
|
|
RPCservice.LoadTables((PagingLoadConfig) loadConfig, dataInput,
|
|
startSearchTable, keyword,
|
|
new AsyncCallback<PagingLoadResult<Result>>() {
|
|
|
|
@Override
|
|
public void onFailure(Throwable caught) {
|
|
// TODO Auto-generated method stub
|
|
|
|
// print check
|
|
// System.out
|
|
// .println("GxtBorderLayoutPanel--> FAILURE RPC LoadTables");
|
|
|
|
rootLogger.log(Level.SEVERE,
|
|
"FAILURE RPC LoadTables");
|
|
|
|
// caught.printStackTrace();
|
|
|
|
callback.onFailure(caught);
|
|
|
|
// tablesListNotNull = false;
|
|
|
|
// hide the dialog
|
|
tablesLoaded.hide();
|
|
|
|
if (caught
|
|
.getMessage()
|
|
.equals("java.lang.Exception: Result not available")) {
|
|
|
|
MessageBox.alert("Error ", "<br/>Message:"
|
|
+ "no tables available", null);
|
|
|
|
} else {
|
|
|
|
MessageBox.alert("Error ", "<br/>Message:"
|
|
+ caught.getMessage(), null);
|
|
|
|
}
|
|
|
|
if (keyword == null) {
|
|
startSearchTable = false;
|
|
}
|
|
|
|
}
|
|
|
|
@Override
|
|
public void onSuccess(
|
|
PagingLoadResult<Result> result) {
|
|
// TODO Auto-generated method stub
|
|
|
|
// print check
|
|
// System.out
|
|
// .println("GxtBorderLayoutPanel--> SUCCESS RPC LoadTables");
|
|
|
|
rootLogger.log(Level.SEVERE,
|
|
"SUCCESS RPC LoadTables");
|
|
|
|
callback.onSuccess(result);
|
|
|
|
if (keyword == null) {
|
|
startSearchTable = false;
|
|
}
|
|
|
|
// enable toolbar in the dialog
|
|
toolBarTop.enable();
|
|
|
|
}
|
|
});
|
|
|
|
rootLogger.log(Level.SEVERE, "End RPC LoadTables");
|
|
|
|
}
|
|
};
|
|
|
|
// loader to load page enabled set of data
|
|
|
|
final PagingLoader<PagingLoadResult<Result>> loader = new BasePagingLoader<PagingLoadResult<Result>>(
|
|
proxy);
|
|
|
|
// loader.addListener(Loader.BeforeLoad, new Listener<LoadEvent>() {
|
|
// public void handleEvent(LoadEvent be) {
|
|
// BasePagingLoadConfig m = be.<BasePagingLoadConfig> getConfig();
|
|
// m.set("start", m.get("offset"));
|
|
// // m.set("ext", "js");
|
|
// // m.set("lightWeight", true);
|
|
// // m.set("sort", (m.get("sortField") == null) ? "" :
|
|
// m.get("sortField"));
|
|
// // m.set("dir", (m.get("sortDir") == null || (m.get("sortDir") !=
|
|
// null && m.<SortDir> get("sortDir").equals(
|
|
// // SortDir.NONE))) ? "" : m.get("sortDir"));
|
|
//
|
|
// }
|
|
// });
|
|
// loader.setRemoteSort(true);
|
|
|
|
// to create the liststore using the loader
|
|
final ListStore<Result> result = new ListStore<Result>(loader);
|
|
|
|
// bind the loader with a PagingToolBar.
|
|
final PagingToolBar toolBar = new PagingToolBar(100);
|
|
toolBar.bind(loader);
|
|
|
|
// create the column configuration
|
|
ColumnModel cm = createColumnModelForTables();
|
|
|
|
// create the grid with a result list and the column model
|
|
final EditorGrid<Result> grid = new EditorGrid<Result>(result, cm);
|
|
|
|
// set the double click for row edit
|
|
grid.setClicksToEdit(ClicksToEdit.TWO);
|
|
|
|
// grid.setStateId("TablesList");
|
|
// grid.setStateful(true);
|
|
|
|
grid.setLoadMask(true);
|
|
grid.setBorders(true);
|
|
// grid.setAutoExpandColumn("comments");
|
|
// grid.setStyleAttribute("borderTop", "none");
|
|
grid.setStripeRows(true);
|
|
|
|
// to manage the table selection in the grid
|
|
grid.getSelectionModel().setSelectionMode(SelectionMode.SINGLE);
|
|
|
|
// 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();
|
|
|
|
// The offset for the first record to retrieve.
|
|
config.setOffset(0);
|
|
// The number of records being requested.
|
|
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
|
|
|
|
// clear variables
|
|
keyword = null;
|
|
startSearchTable = false;
|
|
// clear the textfield
|
|
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
|
|
grid.getSelectionModel().addSelectionChangedListener(
|
|
new SelectionChangedListener<Result>() {
|
|
|
|
@Override
|
|
public void selectionChanged(
|
|
SelectionChangedEvent<Result> se) {
|
|
// TODO Auto-generated method stub
|
|
|
|
selectedTable = grid.getSelectionModel()
|
|
.getSelectedItems().get(0).getValue();
|
|
|
|
rootLogger.log(Level.INFO, "table selected: "
|
|
+ selectedTable);
|
|
|
|
}
|
|
});
|
|
|
|
// grid.getSeaddListener(Events.SelectionChange,
|
|
// new Listener<SelectionChangedEvent<Result>>() {
|
|
//
|
|
// @Override
|
|
// public void handleEvent(SelectionChangedEvent<Result> be) {
|
|
// // TODO Auto-generated method stub
|
|
//
|
|
// rootLogger.log(Level.INFO, "table selected1: "
|
|
// + be.getSelectedItem().getValue());
|
|
//
|
|
// selectedTable = be.getSelectedItem().getValue();
|
|
//
|
|
//
|
|
// }
|
|
// });
|
|
|
|
// listener to manage the table selection in the grid
|
|
grid.addListener(Events.RowClick, new Listener<GridEvent<Result>>() {
|
|
|
|
@Override
|
|
public void handleEvent(final GridEvent<Result> be) {
|
|
// TODO Auto-generated method stub
|
|
|
|
rootLogger.log(Level.INFO, "table clicked: "
|
|
+ grid.getSelectionModel().getSelectedItems().get(0)
|
|
.getValue());
|
|
|
|
// select the item
|
|
grid.getSelectionModel().select(
|
|
grid.getSelectionModel().getSelectedItems().get(0),
|
|
true);
|
|
|
|
// tablesLoaded.addListener(Events.Hide, new
|
|
// Listener<WindowEvent>() {
|
|
//
|
|
// @Override
|
|
// public void handleEvent(WindowEvent be) {
|
|
// // TODO Auto-generated method stub
|
|
//
|
|
// System.out.println("closing the window");
|
|
//
|
|
// }
|
|
// });
|
|
|
|
}
|
|
});
|
|
|
|
grid.addListener(Events.BeforeEdit, new Listener<GridEvent<Result>>() {
|
|
|
|
@Override
|
|
public void handleEvent(final GridEvent<Result> be) {
|
|
|
|
rootLogger.log(Level.INFO, "table edited: "
|
|
+ be.getValue().toString());
|
|
|
|
// selectedTable = be.getValue().toString();
|
|
|
|
}
|
|
});
|
|
|
|
// this listener catch the Attach event.It fires when
|
|
// the Tables List button is selected.
|
|
// 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>>() {
|
|
public void handleEvent(GridEvent<Result> be) {
|
|
|
|
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();
|
|
|
|
// The offset for the first record to retrieve.
|
|
config.setOffset(0);
|
|
|
|
// The number of records being requested.
|
|
config.setLimit(100);
|
|
|
|
// Map<String, Object> state = grid.getState();
|
|
|
|
// if (state.containsKey("offset")) {
|
|
//
|
|
// // rootLogger.log(Level.INFO, "state contains offset");
|
|
//
|
|
// int offset = (Integer) state.get("offset");
|
|
// rootLogger.log(Level.INFO, "offset: " + offset);
|
|
//
|
|
// int limit = (Integer) state.get("limit");
|
|
// rootLogger.log(Level.INFO, "limit: " + 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);
|
|
}
|
|
});
|
|
|
|
// dialog to display tables list
|
|
// Dialog tablesLoaded = new Dialog();
|
|
tablesLoaded = new Dialog();
|
|
tablesLoaded.setLayout(new FitLayout());
|
|
// ADD CANCEL BUTTON
|
|
tablesLoaded.addButton(new Button("CANCEL"));
|
|
tablesLoaded.setHeading("Tables");
|
|
tablesLoaded.setResizable(false);
|
|
tablesLoaded.setModal(true);
|
|
tablesLoaded.setBlinkModal(true);
|
|
tablesLoaded.setSize(600, 400);
|
|
tablesLoaded.setScrollMode(Scroll.NONE);
|
|
tablesLoaded.setHideOnButtonClick(true);
|
|
tablesLoaded.setMaximizable(true);
|
|
tablesLoaded.setClosable(false);
|
|
tablesLoaded.setBottomComponent(toolBar);
|
|
|
|
// toolBarTop.getAriaSupport().setLabel("Table Search");
|
|
|
|
// enter event in the search
|
|
|
|
// TextField<String> searchTable = new TextField<String>();
|
|
// searchTable.setFieldLabel("Search: ");
|
|
|
|
// searchTable.addListener(Events.KeyPress, new Listener<FieldEvent>() {
|
|
//
|
|
// @Override
|
|
// public void handleEvent(FieldEvent be) {
|
|
// // 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);
|
|
//
|
|
// loader.load(config);
|
|
//
|
|
// }
|
|
// });
|
|
|
|
tablesLoaded.setTopComponent(toolBarTop);
|
|
|
|
// listener to manage the table selection in the grid
|
|
Button ok = (Button) tablesLoaded.getButtonBar().getWidget(0);
|
|
rootLogger.log(Level.INFO, "button: " + ok.getText());
|
|
|
|
Button canc = (Button) tablesLoaded.getButtonBar().getWidget(1);
|
|
rootLogger.log(Level.INFO, "button: " + canc.getText());
|
|
|
|
// listener for buttons
|
|
ok.addSelectionListener(new SelectionListener<ButtonEvent>() {
|
|
|
|
@Override
|
|
public void componentSelected(ButtonEvent ce) {
|
|
// TODO Auto-generated method stub
|
|
|
|
keyword = null;
|
|
startSearchTable = false;
|
|
|
|
if (selectedTable != null) {
|
|
|
|
// display the table in the panel "Database Information"
|
|
displayTableName(selectedTable);
|
|
|
|
// fire event
|
|
eventBus.fireEvent(new SelectedTableEvent());
|
|
|
|
}
|
|
|
|
// 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);
|
|
//
|
|
// }
|
|
|
|
}
|
|
});
|
|
|
|
canc.addSelectionListener(new SelectionListener<ButtonEvent>() {
|
|
|
|
@Override
|
|
public void componentSelected(ButtonEvent ce) {
|
|
// TODO Auto-generated method stub
|
|
|
|
keyword = null;
|
|
startSearchTable = false;
|
|
|
|
//refresh the database information panel
|
|
centerUpper.removeAll();
|
|
centerUpper.layout(true);
|
|
|
|
tablesLoaded.hide();
|
|
|
|
}
|
|
});
|
|
|
|
// 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.add(grid);
|
|
tablesLoaded.show();
|
|
|
|
}
|
|
|
|
// method to submit a query
|
|
private void submitQuery(final Integer dialogID) {
|
|
|
|
// clear variable that keeps track of the managed event
|
|
// boolean submitQueryEventManaged = false;
|
|
|
|
// get the selected item
|
|
List<FileModel> data = treePanel.getTreePanel().getSelectionModel()
|
|
.getSelectedItems();
|
|
FileModel selectedItem = data.get(0);
|
|
|
|
// get information related to the selected item
|
|
// recover input data
|
|
LinkedHashMap<String, String> dataForSubmitQuery = new LinkedHashMap<String, String>();
|
|
|
|
dataForSubmitQuery.put("ResourceName", selectedItem.getResourceName());
|
|
dataForSubmitQuery.put("DatabaseName", selectedItem.getDatabaseName());
|
|
|
|
// print check
|
|
// System.out.println("ResourceName" + selectedItem.getResourceName());
|
|
// System.out.println("DatabaseName" + selectedItem.getDatabaseName());
|
|
|
|
// get data inserted in the form
|
|
// final SubmitQueryData dataQuery = toolbar.getSubmitQueryData();
|
|
|
|
// get data list (inserted in the form)
|
|
LinkedHashMap<Integer, SubmitQueryData> submitQueryDataList = toolbar
|
|
.getSubmitQueryDataList();
|
|
|
|
// get dialog list
|
|
LinkedHashMap<Integer, Dialog> dialogList = toolbar.getDialogFormList();
|
|
|
|
// get the dialog related to the ID
|
|
final Dialog form = dialogList.get(dialogID);
|
|
// get the data form related to the ID
|
|
final SubmitQueryData dataQuery = submitQueryDataList.get(dialogID);
|
|
|
|
// rootLogger.log(Level.INFO, "query: "+ dataQuery.getQuery() +
|
|
// "submitquery->dialogID: "
|
|
// + dialogID);
|
|
|
|
// determine the language
|
|
String dialect;
|
|
|
|
if (selectedItem.isDatabase()) { // the selected item is a database
|
|
|
|
// System.out.println("the selected item is a database");
|
|
rootLogger.log(Level.INFO, "the selected item is a database");
|
|
|
|
// determine the dialect recovering the dialect
|
|
dialect = selectedItem.getDBInfo().get(2).getValue();
|
|
|
|
rootLogger.log(Level.INFO,
|
|
"determined Dialect for smart correction: " + dialect);
|
|
|
|
} else {
|
|
FileModel parent1 = treePanel.getTreeStore()
|
|
.getParent(selectedItem);
|
|
|
|
if (parent1.isDatabase()) { // the selected item is a schema
|
|
|
|
// System.out.println("the selected item is a schema");
|
|
|
|
rootLogger.log(Level.INFO, "the selected item is a schema");
|
|
|
|
// determine the dialect recovering the dialect
|
|
dialect = parent1.getDBInfo().get(2).getValue();
|
|
|
|
rootLogger.log(Level.INFO,
|
|
"determined Dialect for smart correction: " + dialect);
|
|
|
|
}
|
|
|
|
else { // the selected item is a table
|
|
|
|
// System.out.println("the selected item is a table");
|
|
|
|
rootLogger.log(Level.INFO, "the selected item is a table");
|
|
|
|
FileModel parent2 = treePanel.getTreeStore().getParent(parent1);
|
|
|
|
// determine the dialect recovering the dialect
|
|
dialect = parent2.getDBInfo().get(2).getValue();
|
|
|
|
rootLogger.log(Level.INFO,
|
|
"determined Dialect for smart correction: " + dialect);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
String language = ConstantsPortlet.NONE;
|
|
|
|
if (dialect.toUpperCase().contains(ConstantsPortlet.POSTGRES)) {
|
|
|
|
language = ConstantsPortlet.POSTGRES;
|
|
}
|
|
|
|
if (dialect.toUpperCase().contains(ConstantsPortlet.MYSQL)) {
|
|
|
|
language = ConstantsPortlet.MYSQL;
|
|
}
|
|
|
|
rootLogger.log(Level.INFO, "Dialect used for smart correction: "
|
|
+ language);
|
|
|
|
// remote rpc
|
|
RPCservice.submitQuery(dataForSubmitQuery, dataQuery.getQuery(), true,
|
|
dataQuery.getSmartCorrection(), language,
|
|
new AsyncCallback<List<Result>>() {
|
|
|
|
// TO REMOVE data "true" as input if you manage the
|
|
// read-only query in the form
|
|
|
|
@Override
|
|
public void onFailure(Throwable caught) {
|
|
|
|
// Window.alert(caught.getMessage());
|
|
|
|
// print check
|
|
// System.out
|
|
// .println("GxtBorderLayoutPanel--> FAILURE RPC submitQuery");
|
|
|
|
rootLogger.log(Level.SEVERE, "FAILURE RPC submitQuery");
|
|
|
|
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.getBody().isMasked())
|
|
form.getBody().unmask();
|
|
|
|
}
|
|
};
|
|
|
|
// MessageBox.alert("Error "," <br/>Cause:"+caught.getCause()+"<br/>Message:"+caught.getMessage(),
|
|
// l);
|
|
MessageBox.alert("Error ",
|
|
"<br/>Message:" + caught.getMessage(), l);
|
|
|
|
}
|
|
|
|
@Override
|
|
public void onSuccess(List<Result> result) {
|
|
// TODO Auto-generated method stub
|
|
|
|
// print check
|
|
// System.out
|
|
// .println("GxtBorderLayoutPanel--> SUCCESS RPC submitQuery");
|
|
|
|
rootLogger.log(Level.SEVERE, "SUCCESS RPC submitQuery");
|
|
|
|
// System.out.println("result size: " + result.size());
|
|
|
|
rootLogger.log(Level.SEVERE,
|
|
"output size: " + result.size());
|
|
|
|
// 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);
|
|
|
|
// variable that keeps track of the managed event
|
|
// submitQueryEventManaged = true;
|
|
|
|
// parse the result in order to obtain a table
|
|
boolean submitQueryEventManaged = true;
|
|
parseResult(result, form, dialogID,
|
|
submitQueryEventManaged);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
// method to perform the sample table
|
|
|
|
private void sample() {
|
|
|
|
final GxtBorderLayoutPanel obj = this;
|
|
|
|
rootLogger.log(Level.SEVERE, "Start RPC - sample");
|
|
|
|
// get the selected table
|
|
List<FileModel> data = treePanel.getTreePanel().getSelectionModel()
|
|
.getSelectedItems();
|
|
|
|
// the selected item
|
|
FileModel selectedItem = data.get(0);
|
|
|
|
// recover data inputs
|
|
final LinkedHashMap<String, String> dataInput = new LinkedHashMap<String, String>();
|
|
|
|
// check if the table has an associated schema
|
|
FileModel schema;
|
|
FileModel database;
|
|
FileModel resource;
|
|
|
|
if (selectedItem.isDatabase()) {
|
|
|
|
// the table has not a schema because the selected item is a
|
|
// database
|
|
|
|
database = selectedItem;
|
|
resource = treePanel.getTreeStore().getParent(database);
|
|
|
|
dataInput.put("ResourceName", resource.getName());
|
|
dataInput.put("DatabaseName", database.getName());
|
|
dataInput.put("SchemaName", "");
|
|
dataInput.put("TableName", selectedTable);
|
|
|
|
rootLogger.log(Level.INFO, "ResourceName: " + resource.getName());
|
|
rootLogger.log(Level.INFO, "DatabaseName: " + database.getName());
|
|
rootLogger.log(Level.INFO, "SchemaName: " + "");
|
|
rootLogger.log(Level.INFO, "TableName: " + selectedTable);
|
|
|
|
} else {
|
|
// the table has a schema because the selected item is a schema
|
|
|
|
schema = 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", selectedTable);
|
|
|
|
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, "TableName: " + selectedTable);
|
|
|
|
}
|
|
|
|
// 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>>() {
|
|
|
|
@Override
|
|
public void onFailure(Throwable caught) {
|
|
|
|
// Window.alert(caught.getMessage());
|
|
|
|
// print check
|
|
// System.out
|
|
// .println("GxtBorderLayoutPanel--> FAILURE RPC sample");
|
|
|
|
rootLogger.log(Level.SEVERE, "FAILURE RPC sample");
|
|
|
|
MessageBox.alert("Error ",
|
|
"<br/>Message:" + caught.getMessage(), null);
|
|
|
|
if (obj.isMasked()) {
|
|
obj.unmask();
|
|
}
|
|
|
|
}
|
|
|
|
@Override
|
|
public void onSuccess(List<Result> result) {
|
|
|
|
// print check
|
|
// System.out
|
|
// .println("GxtBorderLayoutPanel--> SUCCESS RPC sample");
|
|
|
|
rootLogger.log(Level.SEVERE, "SUCCESS RPC sample");
|
|
|
|
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, null, 0, false);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
// }
|
|
//
|
|
// }
|
|
//
|
|
// };
|
|
|
|
// MessageBox.confirm("Confirm", "Are you sure you want to sample the "
|
|
// + selectedTable + " table?", l);
|
|
|
|
}
|
|
|
|
// method that performs the smart sample
|
|
private void smartSample() {
|
|
|
|
final GxtBorderLayoutPanel obj = this;
|
|
|
|
rootLogger.log(Level.SEVERE, "Start RPC - smartSample");
|
|
|
|
// get the selected table
|
|
List<FileModel> data = treePanel.getTreePanel().getSelectionModel()
|
|
.getSelectedItems();
|
|
|
|
// the selected item
|
|
FileModel selectedItem = data.get(0);
|
|
|
|
// recover data inputs for the algorithm
|
|
|
|
final LinkedHashMap<String, String> dataInput = new LinkedHashMap<String, String>();
|
|
|
|
// check if the table has an associated schema
|
|
FileModel schema;
|
|
FileModel database;
|
|
FileModel resource;
|
|
|
|
if (selectedItem.isDatabase()) {
|
|
|
|
// the table has not a schema
|
|
|
|
database = selectedItem;
|
|
resource = treePanel.getTreeStore().getParent(database);
|
|
|
|
dataInput.put("ResourceName", resource.getName());
|
|
dataInput.put("DatabaseName", database.getName());
|
|
dataInput.put("SchemaName", "");
|
|
dataInput.put("TableName", selectedTable);
|
|
|
|
rootLogger.log(Level.INFO, "ResourceName: " + resource.getName());
|
|
rootLogger.log(Level.INFO, "DatabaseName: " + database.getName());
|
|
rootLogger.log(Level.INFO, "SchemaName: " + "");
|
|
rootLogger.log(Level.INFO, "TableName: " + selectedTable);
|
|
|
|
} else {
|
|
// the table has a schema
|
|
|
|
schema = 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", selectedTable);
|
|
|
|
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, "TableName: " + selectedTable);
|
|
|
|
}
|
|
|
|
// 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>>() {
|
|
|
|
@Override
|
|
public void onFailure(Throwable caught) {
|
|
|
|
// Window.alert(caught.getMessage());
|
|
// System.out.println("FAILURE");
|
|
|
|
// print check
|
|
// System.out
|
|
// .println("GxtBorderLayoutPanel--> FAILURE RPC smartSample");
|
|
|
|
rootLogger.log(Level.SEVERE, "FAILURE RPC smartSample");
|
|
|
|
MessageBox.alert("Error ",
|
|
"<br/>Message:" + caught.getMessage(), null);
|
|
|
|
if (obj.isMasked()) {
|
|
obj.unmask();
|
|
}
|
|
|
|
}
|
|
|
|
@Override
|
|
public void onSuccess(List<Result> result) {
|
|
|
|
// print check
|
|
// print check
|
|
// System.out
|
|
// .println("GxtBorderLayoutPanel--> SUCCESS RPC smartSample");
|
|
|
|
rootLogger.log(Level.SEVERE, "SUCCESS RPC smartSample");
|
|
|
|
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, null, 0, false);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
// }
|
|
//
|
|
// }
|
|
//
|
|
// };
|
|
//
|
|
// MessageBox.confirm("Confirm", "Are you sure you want to sample the "
|
|
// + selectedTable + " table?", l);
|
|
|
|
}
|
|
|
|
// method to perform the random sample
|
|
private void randomSample() {
|
|
|
|
final GxtBorderLayoutPanel obj = this;
|
|
|
|
rootLogger.log(Level.SEVERE, "Start RPC - randomSample");
|
|
|
|
// get the selected table
|
|
List<FileModel> data = treePanel.getTreePanel().getSelectionModel()
|
|
.getSelectedItems();
|
|
|
|
// the selected item
|
|
FileModel selectedItem = data.get(0);
|
|
|
|
// recover data inputs for the algorithm
|
|
|
|
final LinkedHashMap<String, String> dataInput = new LinkedHashMap<String, String>();
|
|
|
|
// check if the table has an associated schema
|
|
FileModel schema;
|
|
FileModel database;
|
|
FileModel resource;
|
|
|
|
if (selectedItem.isDatabase()) {
|
|
|
|
// the table has not a schema
|
|
|
|
database = selectedItem;
|
|
resource = treePanel.getTreeStore().getParent(database);
|
|
|
|
dataInput.put("ResourceName", resource.getName());
|
|
dataInput.put("DatabaseName", database.getName());
|
|
dataInput.put("SchemaName", "");
|
|
dataInput.put("TableName", selectedTable);
|
|
|
|
rootLogger.log(Level.INFO, "ResourceName: " + resource.getName());
|
|
rootLogger.log(Level.INFO, "DatabaseName: " + database.getName());
|
|
rootLogger.log(Level.INFO, "SchemaName: " + "");
|
|
rootLogger.log(Level.INFO, "TableName: " + selectedTable);
|
|
|
|
} else {
|
|
// the table has a schema
|
|
|
|
schema = 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", selectedTable);
|
|
|
|
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, "TableName: " + selectedTable);
|
|
|
|
}
|
|
|
|
// 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>>() {
|
|
|
|
@Override
|
|
public void onFailure(Throwable caught) {
|
|
|
|
// Window.alert(caught.getMessage());
|
|
// System.out.println("FAILURE");
|
|
|
|
// print check
|
|
// System.out
|
|
// .println("GxtBorderLayoutPanel--> FAILURE RPC randomSample");
|
|
|
|
rootLogger.log(Level.SEVERE, "FAILURE RPC randomSample");
|
|
|
|
MessageBox.alert("Error ",
|
|
"<br/>Message:" + caught.getMessage(), null);
|
|
|
|
if (obj.isMasked()) {
|
|
obj.unmask();
|
|
}
|
|
|
|
}
|
|
|
|
@Override
|
|
public void onSuccess(List<Result> result) {
|
|
|
|
// print check
|
|
// System.out
|
|
// .println("GxtBorderLayoutPanel--> SUCCESS RPC randomSample");
|
|
|
|
rootLogger.log(Level.SEVERE, "SUCCESS RPC randomSample");
|
|
|
|
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, null, 0, false);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
// }
|
|
//
|
|
// }
|
|
//
|
|
// };
|
|
|
|
// 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, Dialog dialog,
|
|
final int dialogID, final boolean submitQueryEventManaged) {
|
|
|
|
// to unmask the entire content panel
|
|
final GxtBorderLayoutPanel obj = this;
|
|
|
|
final Dialog form = dialog;
|
|
|
|
RPCservice.parseCVSString(result, listAttributes,
|
|
new AsyncCallback<List<Row>>() {
|
|
|
|
@Override
|
|
public void onFailure(Throwable caught) {
|
|
// TODO Auto-generated method stub
|
|
|
|
// Window.alert(caught.getMessage());
|
|
// System.out.println("FAILURE StartParse");
|
|
|
|
// print check
|
|
// System.out
|
|
// .println("GxtBorderLayoutPanel--> FAILURE RPC parseResult");
|
|
|
|
rootLogger.log(Level.SEVERE, "FAILURE RPC parseResult");
|
|
|
|
MessageBox.alert("Error ",
|
|
"<br/>Message:" + caught.getMessage(), null);
|
|
|
|
// if the submit query event has been performed the
|
|
// dialog form is unmasked otherwise if a sampling
|
|
// operation is performed the entire panel is masked.
|
|
if (submitQueryEventManaged == true) {
|
|
|
|
// submitQueryEventManaged = false;
|
|
|
|
// Dialog form = toolbar.getDialogForm();
|
|
//
|
|
if (form.getBody().isMasked())
|
|
form.getBody().unmask();
|
|
|
|
// form.hide();
|
|
|
|
} else {
|
|
if (obj.isMasked()) {
|
|
obj.unmask();
|
|
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
@Override
|
|
public void onSuccess(List<Row> rows) {
|
|
|
|
// print check
|
|
// System.out
|
|
// .println("GxtBorderLayoutPanel--> SUCCESS RPC parseResult");
|
|
|
|
rootLogger.log(Level.SEVERE, "SUCCESS RPC parseResult");
|
|
|
|
if (rows != null) {
|
|
|
|
// Display the submit query result as a table
|
|
Dialog submitResult = new Dialog() {
|
|
// override the maximize event modifying it with
|
|
// a different behaviour if the mimimize event
|
|
// occurs
|
|
public void maximize() {
|
|
if (isCollapsed()) {
|
|
expand();
|
|
} else {
|
|
super.maximize();
|
|
}
|
|
}
|
|
};
|
|
submitResult.setLayout(new FitLayout());
|
|
|
|
if (submitQueryEventManaged == true) {
|
|
submitResult.setHeading("Result Query "
|
|
+ dialogID);
|
|
} else {
|
|
submitResult.setHeading("Result");
|
|
}
|
|
|
|
submitResult.setResizable(false);
|
|
// submitResult.setHeading("Submit Query");
|
|
// submitResult.setWidth(290);
|
|
// submitResult.setHeight(250);
|
|
// submitResult.setModal(true);
|
|
// submitResult.setBlinkModal(true);
|
|
// submitResult.setBodyStyle("padding:9px;");
|
|
submitResult.setSize(600, 400);
|
|
// submitResult.setScrollMode(Scroll.AUTO);
|
|
submitResult.setScrollMode(Scroll.NONE);
|
|
submitResult.setHideOnButtonClick(true);
|
|
submitResult.setMaximizable(true);
|
|
submitResult.setMinimizable(true);
|
|
// submitResult.addText("Result Table");
|
|
|
|
ListStore<Row> store = new ListStore<Row>();
|
|
store.add(rows);
|
|
|
|
Grid<Row> grid;
|
|
grid = new Grid<Row>(store, createColumnModel());
|
|
|
|
// grid.setAutoExpandColumn("value");
|
|
grid.setBorders(true);
|
|
// grid.setAutoWidth(true);
|
|
|
|
RowData data = new RowData(.5, 1);
|
|
data.setMargins(new Margins(6));
|
|
|
|
// mimimize event handled
|
|
submitResult.addListener(Events.Minimize,
|
|
new Listener<WindowEvent>() {
|
|
|
|
@Override
|
|
public void handleEvent(WindowEvent be) {
|
|
// TODO Auto-generated method stub
|
|
// collpse the dialog
|
|
be.getWindow().collapse();
|
|
|
|
}
|
|
});
|
|
// maximize event handled
|
|
submitResult.addListener(Events.Maximize,
|
|
new Listener<WindowEvent>() {
|
|
|
|
@Override
|
|
public void handleEvent(WindowEvent be) {
|
|
// TODO Auto-generated method stub
|
|
|
|
// expand the dialog
|
|
if (be.getWindow().isCollapsed()) {
|
|
|
|
be.getWindow().expand();
|
|
|
|
}
|
|
|
|
}
|
|
});
|
|
|
|
submitResult.add(grid, data);
|
|
submitResult.show();
|
|
|
|
// if the submit query event has been performed the
|
|
// dialog form is unmasked otherwise if a sampling
|
|
// operation is performed the entire panel is
|
|
// masked.
|
|
|
|
if (submitQueryEventManaged == true) {
|
|
// clear variable
|
|
// submitQueryEventManaged = false;
|
|
|
|
// Dialog form = toolbar.getDialogForm();
|
|
//
|
|
if (form.getBody().isMasked())
|
|
form.getBody().unmask();
|
|
//
|
|
// form.hide();
|
|
|
|
} else {
|
|
if (obj.isMasked()) {
|
|
obj.unmask();
|
|
}
|
|
}
|
|
} else {
|
|
|
|
if (submitQueryEventManaged == true) {
|
|
|
|
// submitQueryEventManaged = false;
|
|
|
|
// Dialog form = toolbar.getDialogForm();
|
|
if (form.getBody().isMasked())
|
|
form.getBody().unmask();
|
|
//
|
|
// form.hide();
|
|
} else {
|
|
if (obj.isMasked()) {
|
|
obj.unmask();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
});
|
|
}
|
|
|
|
// get attributes list for display the result in a table
|
|
private void getListAttributes(String value) {
|
|
|
|
// recover attribute fields for the result table
|
|
String headers = value;
|
|
|
|
// System.out.println("headers: " + headers);
|
|
|
|
rootLogger.log(Level.INFO, "Headers fields table: " + headers);
|
|
|
|
listAttributes = parseAttributesTableResult(headers);
|
|
|
|
// System.out.println("attributes number: " + listAttributes.size());
|
|
|
|
rootLogger.log(Level.INFO,
|
|
"attributes number: " + listAttributes.size());
|
|
|
|
rootLogger.log(Level.INFO, "attributes list: ");
|
|
|
|
for (int i = 0; i < listAttributes.size(); i++) {
|
|
|
|
// System.out.println(listAttributes.get(i));
|
|
|
|
rootLogger.log(Level.INFO, "attribute: " + listAttributes.get(i));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// create column configuration for the grid
|
|
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++) {
|
|
|
|
// System.out.println("attribute: " + listAttributes.get(i));
|
|
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 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;
|
|
|
|
}
|
|
|
|
// create column configuration for the grid
|
|
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);
|
|
// column1.setSortable(false);
|
|
|
|
TextField<String> textProperty = new TextField<String>();
|
|
// text.setAllowBlank(false);
|
|
column.setEditor(new CellEditor(textProperty));
|
|
|
|
configs.add(column);
|
|
|
|
column = new ColumnConfig();
|
|
column.setId("value");
|
|
column.setHeader("Value");
|
|
column.setWidth(600);
|
|
|
|
// column2.setSortable(false);
|
|
|
|
TextField<String> textValue = new TextField<String>();
|
|
// text.setAllowBlank(false);
|
|
column.setEditor(new CellEditor(textValue));
|
|
|
|
configs.add(column);
|
|
|
|
ListStore<Result> store = new ListStore<Result>();
|
|
store.add(result);
|
|
|
|
return new ColumnModel(configs);
|
|
}
|
|
|
|
// create column configuration for the grid
|
|
private ColumnModel createColumnModelForTables() {
|
|
|
|
List<ColumnConfig> configs = new ArrayList<ColumnConfig>();
|
|
|
|
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<String> textValue = new TextField<String>();
|
|
// text.setAllowBlank(false);
|
|
column.setEditor(new CellEditor(textValue));
|
|
|
|
configs.add(column);
|
|
|
|
// ListStore<Result> store = new ListStore<Result>();
|
|
// store.add(result);
|
|
|
|
return new ColumnModel(configs);
|
|
|
|
}
|
|
|
|
private void displayDBInfo(FileModel element) {
|
|
|
|
// System.out.println("GxtBorderLayout->displaying info");
|
|
|
|
rootLogger.log(Level.INFO, "displaying info");
|
|
|
|
List<Result> dataDB = element.getDBInfo();
|
|
|
|
if (dataDB != null) {
|
|
|
|
// System.out.println("GxtBorderLayout->size info: " +
|
|
// dataDB.size());
|
|
|
|
rootLogger.log(Level.INFO, "info size: " + dataDB.size());
|
|
|
|
ListStore<Result> store = new ListStore<Result>();
|
|
store.add(dataDB);
|
|
|
|
EditorGrid<Result> grid = new EditorGrid<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.add(grid);
|
|
centerUpper.layout(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// method to get the table details
|
|
private void getTableDetails(final FileModel Table) {
|
|
|
|
// to unmask the entire content panel
|
|
final GxtBorderLayoutPanel obj = this;
|
|
|
|
rootLogger.log(Level.SEVERE, "Start RPC - getTableDetails");
|
|
|
|
// get the selected table
|
|
List<FileModel> data = treePanel.getTreePanel().getSelectionModel()
|
|
.getSelectedItems();
|
|
|
|
// the selected item
|
|
FileModel selectedItem = data.get(0);
|
|
|
|
// recover data inputs fo the algorithm
|
|
final LinkedHashMap<String, String> dataInput = new LinkedHashMap<String, String>();
|
|
|
|
// check if the table has an associated schema
|
|
FileModel schema;
|
|
FileModel database;
|
|
FileModel resource;
|
|
|
|
if (selectedItem.isDatabase()) {
|
|
|
|
// the table has not a schema
|
|
|
|
database = selectedItem;
|
|
resource = treePanel.getTreeStore().getParent(database);
|
|
|
|
dataInput.put("ResourceName", resource.getName());
|
|
dataInput.put("DatabaseName", database.getName());
|
|
dataInput.put("SchemaName", "");
|
|
dataInput.put("TableName", selectedTable);
|
|
|
|
rootLogger.log(Level.INFO, "ResourceName: " + resource.getName());
|
|
rootLogger.log(Level.INFO, "DatabaseName: " + database.getName());
|
|
rootLogger.log(Level.INFO, "SchemaName: " + "");
|
|
rootLogger.log(Level.INFO, "TableName: " + selectedTable);
|
|
|
|
} else {
|
|
// the table has a schema
|
|
|
|
schema = 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", selectedTable);
|
|
|
|
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, "TableName: " + selectedTable);
|
|
|
|
}
|
|
|
|
// details for the table are displayed if they have not been displayed
|
|
// yet
|
|
if (Table.isTableDetailsDisplayed()) {
|
|
|
|
displayTableDetails(Table);
|
|
|
|
} 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,
|
|
new AsyncCallback<LinkedHashMap<String, FileModel>>() {
|
|
|
|
@Override
|
|
public void onFailure(Throwable caught) {
|
|
// TODO Auto-generated method
|
|
// stub
|
|
|
|
// print check
|
|
// System.out
|
|
// .println("GxtBorderLayoutPanel--> FAILURE RPC getTableDetails");
|
|
|
|
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
|
|
|
|
// print check
|
|
// System.out
|
|
// .println("GxtBorderLayoutPanel--> SUCCESS RPC getTableDetails");
|
|
|
|
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(
|
|
"Create statement", 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(
|
|
"Number of rows", result.get(
|
|
array[i].toString())
|
|
.getName());
|
|
|
|
TableDetails.add(row);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Table.setTableDetails(TableDetails);
|
|
displayTableDetails(Table);
|
|
Table.setTableDetailsDisplayed(true);
|
|
}
|
|
|
|
// if (obj.isMasked()) {
|
|
// obj.unmask();
|
|
// }
|
|
|
|
}
|
|
});
|
|
|
|
// }
|
|
//
|
|
// }
|
|
//
|
|
// };
|
|
|
|
// 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");
|
|
|
|
List<Result> tableDetails = table.getTableDetails();
|
|
|
|
// System.out.println("GxtBorderLayout->size info: " + dataDB.size());
|
|
|
|
rootLogger.log(Level.INFO, "details size: " + tableDetails.size());
|
|
|
|
ListStore<Result> store = new ListStore<Result>();
|
|
|
|
store.add(tableDetails);
|
|
|
|
EditorGrid<Result> grid = new EditorGrid<Result>(store,
|
|
createColumnModelForDBInfo(tableDetails));
|
|
|
|
// grid.setAutoExpandColumn("name");
|
|
grid.setBorders(true);
|
|
|
|
// grid.setAutoWidth(true);
|
|
// RowData data = new RowData(.5, .1);
|
|
// data.setMargins(new Margins(6));
|
|
|
|
centerBottom.removeAll();
|
|
// centerBottom.add(grid, data);
|
|
centerBottom.add(grid);
|
|
centerBottom.layout(true);
|
|
|
|
// to unmask the entire content panel
|
|
if (this.isMasked()) {
|
|
this.unmask();
|
|
}
|
|
|
|
}
|
|
|
|
private void displayTableName(String tableName) {
|
|
|
|
rootLogger.log(Level.INFO, "displaying table name" + tableName
|
|
+ " in the panel");
|
|
|
|
Result table = new Result("Selected table", tableName);
|
|
// create column configuration
|
|
List<ColumnConfig> configs = new ArrayList<ColumnConfig>();
|
|
|
|
ColumnConfig column = new ColumnConfig();
|
|
column.setId("index");
|
|
column.setHeader("Description");
|
|
column.setWidth(100);
|
|
|
|
configs.add(column);
|
|
|
|
column = new ColumnConfig();
|
|
column.setId("value");
|
|
column.setHeader("Value");
|
|
column.setWidth(600);
|
|
|
|
TextField<String> textValue = new TextField<String>();
|
|
// text.setAllowBlank(false);
|
|
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
|
|
centerUpper.removeAll();
|
|
centerUpper.add(grid);
|
|
centerUpper.layout(true);
|
|
|
|
}
|
|
|
|
}
|