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;
|
2014-07-04 11:07:19 +02:00
|
|
|
import java.util.Set;
|
2014-07-02 12:57:14 +02:00
|
|
|
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;
|
2014-09-19 17:36:36 +02:00
|
|
|
import org.gcube.portlets.user.databasesmanager.client.datamodel.SamplingResultWithFileFromServlet;
|
2014-07-02 12:57:14 +02:00
|
|
|
import org.gcube.portlets.user.databasesmanager.client.datamodel.Row;
|
|
|
|
import org.gcube.portlets.user.databasesmanager.client.datamodel.SubmitQueryData;
|
2014-09-19 17:36:36 +02:00
|
|
|
import org.gcube.portlets.user.databasesmanager.client.datamodel.SubmitQueryResultWithFileFromServlet;
|
2014-07-11 12:35:26 +02:00
|
|
|
import org.gcube.portlets.user.databasesmanager.client.events.LoadTablesEvent;
|
2014-07-04 12:36:43 +02:00
|
|
|
import org.gcube.portlets.user.databasesmanager.client.events.RandomSamplingEvent;
|
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;
|
2014-07-14 10:06:55 +02:00
|
|
|
import org.gcube.portlets.user.databasesmanager.client.events.SelectedTableEvent;
|
2014-07-04 11:07:19 +02:00
|
|
|
import org.gcube.portlets.user.databasesmanager.client.events.ShowCreateTableEvent;
|
2014-07-04 12:09:47 +02:00
|
|
|
import org.gcube.portlets.user.databasesmanager.client.events.SmartSamplingEvent;
|
2014-07-02 12:57:14 +02:00
|
|
|
import org.gcube.portlets.user.databasesmanager.client.events.SubmitQueryEvent;
|
2014-07-11 12:35:26 +02:00
|
|
|
import org.gcube.portlets.user.databasesmanager.client.events.interfaces.LoadTablesEventHandler;
|
2014-07-04 12:36:43 +02:00
|
|
|
import org.gcube.portlets.user.databasesmanager.client.events.interfaces.RandomSamplingEventHandler;
|
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;
|
2014-07-04 11:07:19 +02:00
|
|
|
import org.gcube.portlets.user.databasesmanager.client.events.interfaces.ShowCreateTableEventHandler;
|
2014-07-04 12:09:47 +02:00
|
|
|
import org.gcube.portlets.user.databasesmanager.client.events.interfaces.SmartSamplingEventHandler;
|
2014-07-02 12:57:14 +02:00
|
|
|
import org.gcube.portlets.user.databasesmanager.client.events.interfaces.SubmitQueryEventHandler;
|
2014-07-17 14:37:55 +02:00
|
|
|
import org.gcube.portlets.user.databasesmanager.client.resources.Images;
|
2014-07-02 12:57:14 +02:00
|
|
|
import org.gcube.portlets.user.databasesmanager.client.toolbar.GxtToolbarFunctionality;
|
2014-10-13 16:34:03 +02:00
|
|
|
import org.gcube.portlets.user.databasesmanager.shared.ConstantsPortlet;
|
2014-09-29 15:13:02 +02:00
|
|
|
import org.gcube.portlets.user.databasesmanager.shared.SessionExpiredException;
|
|
|
|
import org.gcube.portlets.widgets.sessionchecker.client.CheckSession;
|
2014-09-24 11:02:22 +02:00
|
|
|
|
|
|
|
import com.extjs.gxt.ui.client.Style;
|
2014-07-02 12:57:14 +02:00
|
|
|
import com.extjs.gxt.ui.client.Style.LayoutRegion;
|
|
|
|
import com.extjs.gxt.ui.client.Style.Scroll;
|
2014-07-14 10:06:55 +02:00
|
|
|
import com.extjs.gxt.ui.client.Style.SelectionMode;
|
2014-07-02 12:57:14 +02:00
|
|
|
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;
|
2014-07-14 14:20:18 +02:00
|
|
|
import com.extjs.gxt.ui.client.widget.button.Button;
|
2014-09-24 11:02:22 +02:00
|
|
|
import com.extjs.gxt.ui.client.widget.form.TextArea;
|
2014-07-04 11:07:19 +02:00
|
|
|
import com.extjs.gxt.ui.client.widget.form.TextField;
|
|
|
|
import com.extjs.gxt.ui.client.widget.grid.CellEditor;
|
2014-07-02 12:57:14 +02:00
|
|
|
import com.extjs.gxt.ui.client.widget.grid.ColumnConfig;
|
|
|
|
import com.extjs.gxt.ui.client.widget.grid.ColumnModel;
|
2014-07-04 11:07:19 +02:00
|
|
|
import com.extjs.gxt.ui.client.widget.grid.EditorGrid;
|
2014-07-14 16:06:45 +02:00
|
|
|
import com.extjs.gxt.ui.client.widget.grid.EditorGrid.ClicksToEdit;
|
2014-07-02 12:57:14 +02:00
|
|
|
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;
|
2014-09-24 11:02:22 +02:00
|
|
|
import com.extjs.gxt.ui.client.widget.layout.RowLayout;
|
2014-07-11 12:35:26 +02:00
|
|
|
import com.extjs.gxt.ui.client.widget.toolbar.PagingToolBar;
|
|
|
|
import com.extjs.gxt.ui.client.widget.toolbar.ToolBar;
|
2014-07-17 14:37:55 +02:00
|
|
|
import com.google.gwt.event.dom.client.KeyCodes;
|
2014-07-02 12:57:14 +02:00
|
|
|
import com.google.gwt.event.shared.HandlerManager;
|
2014-09-19 17:36:36 +02:00
|
|
|
import com.google.gwt.user.client.Window;
|
2014-07-02 12:57:14 +02:00
|
|
|
import com.google.gwt.user.client.rpc.AsyncCallback;
|
2014-09-19 17:36:36 +02:00
|
|
|
import com.google.gwt.user.client.ui.HTML;
|
2014-07-11 12:35:26 +02:00
|
|
|
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;
|
2014-07-11 20:22:24 +02:00
|
|
|
import com.extjs.gxt.ui.client.event.ButtonEvent;
|
2014-07-17 14:37:55 +02:00
|
|
|
import com.extjs.gxt.ui.client.event.ComponentEvent;
|
2014-07-11 12:35:26 +02:00
|
|
|
import com.extjs.gxt.ui.client.event.Events;
|
|
|
|
import com.extjs.gxt.ui.client.event.GridEvent;
|
2014-07-17 14:37:55 +02:00
|
|
|
import com.extjs.gxt.ui.client.event.KeyListener;
|
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-14 10:06:55 +02:00
|
|
|
import com.extjs.gxt.ui.client.event.SelectionChangedEvent;
|
|
|
|
import com.extjs.gxt.ui.client.event.SelectionChangedListener;
|
2014-07-11 20:22:24 +02:00
|
|
|
import com.extjs.gxt.ui.client.event.SelectionListener;
|
2014-07-30 11:13:17 +02:00
|
|
|
import com.extjs.gxt.ui.client.event.WindowEvent;
|
2014-07-04 12:09:47 +02:00
|
|
|
|
2014-07-09 16:55:19 +02:00
|
|
|
//class that represents the container of all components
|
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;
|
2014-07-18 17:34:26 +02:00
|
|
|
// top toolbar that contains the buttons
|
2014-07-02 12:57:14 +02:00
|
|
|
private GxtToolbarFunctionality toolbar;
|
2014-08-29 15:39:04 +02:00
|
|
|
// private List<String> listAttributes;
|
2014-07-18 17:34:26 +02:00
|
|
|
// bus to manage events
|
2014-07-02 12:57:14 +02:00
|
|
|
private HandlerManager eventBus = null;
|
|
|
|
// RPC service
|
|
|
|
private GWTdbManagerServiceAsync RPCservice = null;
|
2014-07-18 17:34:26 +02:00
|
|
|
// dialog used to display the tables list
|
2014-07-11 20:22:24 +02:00
|
|
|
private Dialog tablesLoaded = null;
|
2014-07-18 17:34:26 +02:00
|
|
|
// to keep track of selected table in the tables list
|
2014-09-22 10:14:48 +02:00
|
|
|
private String selectedTable = "";
|
2014-09-22 11:10:07 +02:00
|
|
|
private String currentselectedTable = "";
|
2014-07-14 10:06:55 +02:00
|
|
|
private FileModel table = new FileModel("");
|
2014-07-17 14:37:55 +02:00
|
|
|
// variables to perform the table search
|
2014-07-16 16:18:09 +02:00
|
|
|
private String keyword = "";
|
|
|
|
private boolean startSearchTable = false;
|
2014-07-18 11:42:27 +02:00
|
|
|
// toolbar for table search functionality
|
|
|
|
private ToolBar toolBarTop = null;
|
|
|
|
|
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);
|
2014-08-29 15:39:04 +02:00
|
|
|
// toolbar = new GxtToolbarFunctionality(eventBus);
|
|
|
|
toolbar = new GxtToolbarFunctionality(eventBus, RPCservice);
|
2014-07-30 16:41:11 +02:00
|
|
|
this.setHeaderVisible(false); // hide the header of the panel
|
2014-07-02 12:57:14 +02:00
|
|
|
|
|
|
|
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);
|
2014-07-11 20:22:24 +02:00
|
|
|
// centerUpper.setBottomComponent(toolBar);
|
|
|
|
// toolBar.hide();
|
2014-07-02 12:57:14 +02:00
|
|
|
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));
|
|
|
|
|
2014-07-18 17:34:26 +02:00
|
|
|
// CENTER BOTTOM
|
|
|
|
centerBottom = new ContentPanel();
|
|
|
|
centerBottom.setLayout(new FitLayout());
|
|
|
|
centerBottom.setHeading("Information Details");
|
|
|
|
centerBottom.setScrollMode(Scroll.NONE);
|
2014-07-02 12:57:14 +02:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2014-07-18 17:34:26 +02:00
|
|
|
// to add handlers
|
2014-07-02 12:57:14 +02:00
|
|
|
private void addHandler() {
|
|
|
|
|
|
|
|
eventBus.addHandler(SelectedItemEvent.TYPE,
|
|
|
|
new SelectedItemEventHandler() {
|
|
|
|
public void onSelectedItem(
|
|
|
|
SelectedItemEvent selectedItemEvent) {
|
2014-07-18 17:34:26 +02:00
|
|
|
// force the clean of the content panel
|
2014-07-04 11:24:13 +02:00
|
|
|
centerBottom.removeAll();
|
|
|
|
centerBottom.layout(true);
|
|
|
|
|
2014-07-18 17:34:26 +02:00
|
|
|
// to get the selected item with its depth
|
2014-07-09 16:55:19 +02:00
|
|
|
List<FileModel> data = treePanel.getTreePanel()
|
|
|
|
.getSelectionModel().getSelectedItems();
|
|
|
|
FileModel selectedItem = data.get(0);
|
2014-07-09 18:12:30 +02:00
|
|
|
int DepthSelectedItem = treePanel.getTreeStore()
|
|
|
|
.getDepth(selectedItem);
|
2014-07-09 16:55:19 +02:00
|
|
|
String text = selectedItem.getName();
|
2014-07-22 11:47:28 +02:00
|
|
|
rootLogger.log(Level.INFO, "selected item: " + text);
|
2014-07-02 12:57:14 +02:00
|
|
|
|
2014-07-14 10:06:55 +02:00
|
|
|
// disable table details and sampling buttons
|
|
|
|
toolbar.disableButtonsOperationsOnTable();
|
2014-07-18 17:34:26 +02:00
|
|
|
// enable appropriate buttons according the selected
|
|
|
|
// item
|
2014-07-14 10:06:55 +02:00
|
|
|
toolbar.enableButtonOnToolbar(DepthSelectedItem,
|
|
|
|
selectedItem.isSchema(),
|
|
|
|
selectedItem.getDatabaseType());
|
2014-07-14 14:20:18 +02:00
|
|
|
|
2014-07-18 17:34:26 +02:00
|
|
|
// clean variable at each item selection event
|
2014-07-14 14:20:18 +02:00
|
|
|
table = new FileModel("");
|
2014-09-22 11:10:07 +02:00
|
|
|
|
2014-09-22 10:14:48 +02:00
|
|
|
// clean variable
|
|
|
|
selectedTable = "";
|
2014-09-22 11:10:07 +02:00
|
|
|
currentselectedTable = "";
|
2014-07-02 12:57:14 +02:00
|
|
|
|
|
|
|
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));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2014-07-11 12:35:26 +02:00
|
|
|
eventBus.addHandler(LoadTablesEvent.TYPE, new LoadTablesEventHandler() {
|
|
|
|
@Override
|
|
|
|
public void onLoadTables(LoadTablesEvent loadTablesEvent) {
|
2014-07-30 16:41:11 +02:00
|
|
|
// load tables
|
2014-07-11 12:35:26 +02:00
|
|
|
loadTables();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2014-07-02 12:57:14 +02:00
|
|
|
eventBus.addHandler(SubmitQueryEvent.TYPE,
|
|
|
|
new SubmitQueryEventHandler() {
|
|
|
|
@Override
|
|
|
|
public void onSubmitQuery(SubmitQueryEvent submitQueryEvent) {
|
2014-07-30 11:13:17 +02:00
|
|
|
Integer dialogID = new Integer(submitQueryEvent
|
|
|
|
.getDialogID());
|
|
|
|
rootLogger.log(Level.INFO, "dialogID: " + dialogID);
|
2014-07-24 17:07:34 +02:00
|
|
|
submitQuery(dialogID);
|
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) {
|
|
|
|
sample();
|
|
|
|
}
|
|
|
|
});
|
2014-07-04 12:36:43 +02:00
|
|
|
|
|
|
|
eventBus.addHandler(SmartSamplingEvent.TYPE,
|
|
|
|
new SmartSamplingEventHandler() {
|
|
|
|
@Override
|
|
|
|
public void onSmartSampling(
|
|
|
|
SmartSamplingEvent smartSamplingEvent) {
|
|
|
|
smartSample();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
eventBus.addHandler(RandomSamplingEvent.TYPE,
|
|
|
|
new RandomSamplingEventHandler() {
|
|
|
|
@Override
|
|
|
|
public void onRandomSampling(
|
|
|
|
RandomSamplingEvent randomSamplingEvent) {
|
|
|
|
randomSample();
|
|
|
|
}
|
|
|
|
});
|
2014-07-03 14:44:03 +02:00
|
|
|
|
2014-07-04 11:07:19 +02:00
|
|
|
eventBus.addHandler(ShowCreateTableEvent.TYPE,
|
|
|
|
new ShowCreateTableEventHandler() {
|
|
|
|
@Override
|
|
|
|
public void onShowCreateTable(
|
|
|
|
ShowCreateTableEvent showCreateTableEvent) {
|
2014-07-18 17:34:26 +02:00
|
|
|
// get the selected item in the tree
|
2014-07-04 11:24:13 +02:00
|
|
|
List<FileModel> data = treePanel.getTreePanel()
|
|
|
|
.getSelectionModel().getSelectedItems();
|
2014-07-14 14:20:18 +02:00
|
|
|
|
2014-07-18 17:34:26 +02:00
|
|
|
// if the selected table is equal to the previous table
|
|
|
|
// keep track that table details have been just
|
|
|
|
// displayed
|
2014-09-22 10:14:48 +02:00
|
|
|
if (!(table.getName().equals(currentselectedTable))) {
|
|
|
|
table.setName(currentselectedTable);
|
2014-07-14 10:06:55 +02:00
|
|
|
table.setTableDetailsDisplayed(false);
|
|
|
|
}
|
2014-07-30 11:13:17 +02:00
|
|
|
rootLogger.log(Level.INFO,
|
|
|
|
"selected table: " + table.getName());
|
2014-07-18 17:34:26 +02:00
|
|
|
// get table details
|
2014-07-14 10:06:55 +02:00
|
|
|
getTableDetails(table);
|
2014-07-04 11:07:19 +02:00
|
|
|
}
|
|
|
|
});
|
2014-10-10 12:53:26 +02:00
|
|
|
|
|
|
|
// eventBus.addHandler(RefreshDataEvent.TYPE,
|
|
|
|
// new RefreshDataEventHandler() {
|
|
|
|
// @Override
|
|
|
|
// public void onRefreshData(RefreshDataEvent refreshDataEvent) {
|
|
|
|
// }
|
|
|
|
// });
|
2014-07-02 12:57:14 +02:00
|
|
|
}
|
|
|
|
|
2014-07-18 17:34:26 +02:00
|
|
|
// method to load the tables list
|
2014-07-11 12:35:26 +02:00
|
|
|
private void loadTables() {
|
2014-07-14 16:06:45 +02:00
|
|
|
// clean variable
|
2014-09-22 11:10:07 +02:00
|
|
|
// selectedTable = null;
|
2014-07-14 16:06:45 +02:00
|
|
|
|
2014-07-14 14:59:12 +02:00
|
|
|
// disable table details and sampling buttons
|
2014-09-22 11:10:07 +02:00
|
|
|
// toolbar.disableButtonsOperationsOnTable();
|
2014-09-15 16:12:50 +02:00
|
|
|
// clear the panel
|
2014-09-19 17:36:36 +02:00
|
|
|
// centerBottom.removeAll();
|
|
|
|
// centerBottom.layout(true);
|
2014-07-11 12:35:26 +02:00
|
|
|
|
|
|
|
// 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 = "";
|
|
|
|
|
2014-09-22 11:10:07 +02:00
|
|
|
final String elementType;
|
|
|
|
|
2014-07-11 12:35:26 +02:00
|
|
|
if (element.isDatabase()) { // the selected item is a database
|
2014-07-18 17:34:26 +02:00
|
|
|
rootLogger.log(Level.INFO, "selected element is a database ");
|
2014-07-11 12:35:26 +02:00
|
|
|
database = element.getName();
|
|
|
|
resource = treePanel.getTreeStore().getParent(element).getName();
|
2014-07-18 17:34:26 +02:00
|
|
|
// add data
|
2014-07-11 12:35:26 +02:00
|
|
|
dataInput.put("ResourceName", resource);
|
|
|
|
dataInput.put("DatabaseName", database);
|
|
|
|
dataInput.put("SchemaName", "");
|
2014-09-22 11:10:07 +02:00
|
|
|
elementType = ConstantsPortlet.DATABASE;
|
2014-07-11 12:35:26 +02:00
|
|
|
} else { // the selected item is a schema
|
2014-07-18 17:34:26 +02:00
|
|
|
rootLogger.log(Level.INFO, "selected element is a schema ");
|
2014-07-11 12:35:26 +02:00
|
|
|
FileModel db = treePanel.getTreeStore().getParent(element);
|
|
|
|
database = db.getName();
|
|
|
|
resource = treePanel.getTreeStore().getParent(db).getName();
|
|
|
|
schema = element.getName();
|
2014-07-18 17:34:26 +02:00
|
|
|
// add data
|
2014-07-11 12:35:26 +02:00
|
|
|
dataInput.put("ResourceName", resource);
|
|
|
|
dataInput.put("DatabaseName", database);
|
|
|
|
dataInput.put("SchemaName", schema);
|
2014-09-22 11:10:07 +02:00
|
|
|
elementType = ConstantsPortlet.SCHEMA;
|
2014-07-11 12:35:26 +02:00
|
|
|
}
|
|
|
|
|
2014-07-30 16:41:11 +02:00
|
|
|
// print check
|
2014-07-11 12:35:26 +02:00
|
|
|
rootLogger.log(Level.INFO, "ResourceName: " + resource);
|
|
|
|
rootLogger.log(Level.INFO, "DatabaseName: " + database);
|
|
|
|
rootLogger.log(Level.INFO, "SchemaName: " + schema);
|
2014-07-15 18:43:38 +02:00
|
|
|
|
2014-07-11 12:35:26 +02:00
|
|
|
// create RpcProxy object to use the load configuration
|
|
|
|
RpcProxy<PagingLoadResult<Result>> proxy = new RpcProxy<PagingLoadResult<Result>>() {
|
|
|
|
@Override
|
|
|
|
protected void load(Object loadConfig,
|
2014-07-11 20:22:24 +02:00
|
|
|
final AsyncCallback<PagingLoadResult<Result>> callback) {
|
|
|
|
rootLogger.log(Level.SEVERE, "Start RPC - getTables");
|
2014-07-17 14:37:55 +02:00
|
|
|
|
2014-07-16 16:18:09 +02:00
|
|
|
rootLogger.log(Level.INFO, "keyword rpc: " + keyword);
|
2014-07-17 14:37:55 +02:00
|
|
|
rootLogger.log(Level.INFO, "Search Table rpc: "
|
|
|
|
+ startSearchTable);
|
2014-07-18 17:34:26 +02:00
|
|
|
// remote rpc
|
2014-07-17 14:37:55 +02:00
|
|
|
RPCservice.LoadTables((PagingLoadConfig) loadConfig, dataInput,
|
2014-09-22 11:10:07 +02:00
|
|
|
elementType, startSearchTable, keyword,
|
2014-07-14 10:06:55 +02:00
|
|
|
new AsyncCallback<PagingLoadResult<Result>>() {
|
2014-07-11 20:22:24 +02:00
|
|
|
@Override
|
|
|
|
public void onFailure(Throwable caught) {
|
2014-07-14 10:06:55 +02:00
|
|
|
rootLogger.log(Level.SEVERE,
|
2014-07-18 17:34:26 +02:00
|
|
|
"FAILURE RPC LoadTables");
|
2014-10-01 15:38:16 +02:00
|
|
|
|
|
|
|
if (caught instanceof SessionExpiredException) {
|
|
|
|
rootLogger.log(Level.INFO,
|
|
|
|
"Session expired");
|
2014-09-29 15:13:02 +02:00
|
|
|
CheckSession.showLogoutDialog();
|
|
|
|
return;
|
|
|
|
}
|
2014-07-18 11:42:27 +02:00
|
|
|
// caught.printStackTrace();
|
2014-07-11 20:22:24 +02:00
|
|
|
callback.onFailure(caught);
|
2014-07-18 17:34:26 +02:00
|
|
|
// hide the dialog
|
2014-07-11 20:22:24 +02:00
|
|
|
tablesLoaded.hide();
|
2014-07-14 10:06:55 +02:00
|
|
|
|
2014-09-19 17:36:36 +02:00
|
|
|
if (caught.getMessage().contains(
|
|
|
|
"Result not available")) {
|
|
|
|
MessageBox.alert("Warning ",
|
|
|
|
"<br/>Message:"
|
|
|
|
+ "no tables available",
|
|
|
|
null);
|
2014-07-18 17:34:26 +02:00
|
|
|
} else {
|
2014-07-14 10:06:55 +02:00
|
|
|
MessageBox.alert("Error ", "<br/>Message:"
|
|
|
|
+ caught.getMessage(), null);
|
2014-07-11 20:22:24 +02:00
|
|
|
}
|
2014-07-17 14:37:55 +02:00
|
|
|
if (keyword == null) {
|
|
|
|
startSearchTable = false;
|
|
|
|
}
|
2014-07-11 20:22:24 +02:00
|
|
|
}
|
2014-09-05 11:30:05 +02:00
|
|
|
|
2014-07-11 20:22:24 +02:00
|
|
|
@Override
|
|
|
|
public void onSuccess(
|
|
|
|
PagingLoadResult<Result> result) {
|
2014-07-14 10:06:55 +02:00
|
|
|
rootLogger.log(Level.SEVERE,
|
2014-07-18 17:34:26 +02:00
|
|
|
"SUCCESS RPC LoadTables");
|
2014-07-11 20:22:24 +02:00
|
|
|
callback.onSuccess(result);
|
2014-09-19 17:36:36 +02:00
|
|
|
|
2014-07-17 14:37:55 +02:00
|
|
|
if (keyword == null) {
|
|
|
|
startSearchTable = false;
|
|
|
|
}
|
2014-07-18 17:34:26 +02:00
|
|
|
// enable toolbar in the dialog
|
2014-07-18 11:42:27 +02:00
|
|
|
toolBarTop.enable();
|
2014-09-19 17:36:36 +02:00
|
|
|
|
2014-10-01 15:38:16 +02:00
|
|
|
// if (result != null) {
|
|
|
|
//
|
|
|
|
// List<Result> data = result.getData();
|
|
|
|
// if (data.size() == 0) {
|
|
|
|
// MessageBox
|
|
|
|
// .alert("Warning ",
|
|
|
|
// "<br/>Message:"
|
|
|
|
// + "no tables availables",
|
|
|
|
// null);
|
|
|
|
// return;
|
|
|
|
// }
|
|
|
|
// }
|
2014-09-19 17:36:36 +02:00
|
|
|
|
2014-07-14 10:06:55 +02:00
|
|
|
}
|
|
|
|
});
|
2014-07-30 16:41:11 +02:00
|
|
|
// rootLogger.log(Level.SEVERE, "End RPC LoadTables");
|
2014-07-11 12:35:26 +02:00
|
|
|
}
|
|
|
|
};
|
2014-07-14 10:06:55 +02:00
|
|
|
|
2014-07-11 12:35:26 +02:00
|
|
|
// loader to load page enabled set of data
|
|
|
|
final PagingLoader<PagingLoadResult<Result>> loader = new BasePagingLoader<PagingLoadResult<Result>>(
|
|
|
|
proxy);
|
2014-07-11 20:22:24 +02:00
|
|
|
// 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"));
|
|
|
|
// }
|
|
|
|
// });
|
2014-07-11 12:35:26 +02:00
|
|
|
// loader.setRemoteSort(true);
|
|
|
|
|
2014-07-30 16:41:11 +02:00
|
|
|
// to create the listStore using the loader
|
2014-07-14 16:06:45 +02:00
|
|
|
final ListStore<Result> result = new ListStore<Result>(loader);
|
2014-07-11 12:35:26 +02:00
|
|
|
|
|
|
|
// bind the loader with a PagingToolBar.
|
2014-07-14 10:06:55 +02:00
|
|
|
final PagingToolBar toolBar = new PagingToolBar(100);
|
|
|
|
toolBar.bind(loader);
|
2014-07-11 12:35:26 +02:00
|
|
|
|
2014-07-18 17:34:26 +02:00
|
|
|
// create the column configuration
|
2014-07-11 12:35:26 +02:00
|
|
|
ColumnModel cm = createColumnModelForTables();
|
|
|
|
|
|
|
|
// create the grid with a result list and the column model
|
2014-07-14 14:20:18 +02:00
|
|
|
final EditorGrid<Result> grid = new EditorGrid<Result>(result, cm);
|
2014-07-18 17:34:26 +02:00
|
|
|
// set the double click for row edit
|
2014-07-14 16:06:45 +02:00
|
|
|
grid.setClicksToEdit(ClicksToEdit.TWO);
|
2014-07-18 11:42:27 +02:00
|
|
|
// grid.setStateId("TablesList");
|
|
|
|
// grid.setStateful(true);
|
2014-07-14 10:06:55 +02:00
|
|
|
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);
|
|
|
|
|
2014-07-18 11:42:27 +02:00
|
|
|
// add the search functionality
|
|
|
|
// Top toolbar for search table functionality
|
|
|
|
toolBarTop = new ToolBar();
|
|
|
|
|
2014-07-18 17:34:26 +02:00
|
|
|
// TextField for specify the table name to search
|
2014-07-18 11:42:27 +02:00
|
|
|
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) {
|
|
|
|
// 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();
|
2014-07-18 17:34:26 +02:00
|
|
|
// The offset for the first record to retrieve.
|
2014-07-18 11:42:27 +02:00
|
|
|
config.setOffset(0);
|
2014-07-18 17:34:26 +02:00
|
|
|
// The number of records being requested.
|
2014-07-18 11:42:27 +02:00
|
|
|
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) {
|
2014-07-18 17:34:26 +02:00
|
|
|
// clear variables
|
2014-07-18 11:42:27 +02:00
|
|
|
keyword = null;
|
|
|
|
startSearchTable = false;
|
2014-07-18 17:34:26 +02:00
|
|
|
// clear the textfield
|
2014-07-18 11:42:27 +02:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
});
|
2014-07-14 14:20:18 +02:00
|
|
|
|
2014-07-14 16:06:45 +02:00
|
|
|
// listener to manage the table selection in the grid
|
|
|
|
grid.addListener(Events.RowClick, new Listener<GridEvent<Result>>() {
|
2014-07-14 10:29:10 +02:00
|
|
|
@Override
|
|
|
|
public void handleEvent(final GridEvent<Result> be) {
|
2014-09-22 10:14:48 +02:00
|
|
|
rootLogger.log(Level.INFO, "RowClick Event->table clicked: "
|
2014-07-14 16:06:45 +02:00
|
|
|
+ grid.getSelectionModel().getSelectedItems().get(0)
|
|
|
|
.getValue());
|
2014-07-18 17:34:26 +02:00
|
|
|
// select the item
|
2014-07-14 16:06:45 +02:00
|
|
|
grid.getSelectionModel().select(
|
|
|
|
grid.getSelectionModel().getSelectedItems().get(0),
|
|
|
|
true);
|
2014-09-22 11:10:07 +02:00
|
|
|
|
2014-07-14 14:20:18 +02:00
|
|
|
// tablesLoaded.addListener(Events.Hide, new
|
|
|
|
// Listener<WindowEvent>() {
|
|
|
|
// @Override
|
|
|
|
// public void handleEvent(WindowEvent be) {
|
|
|
|
// // TODO Auto-generated method stub
|
|
|
|
// System.out.println("closing the window");
|
|
|
|
// }
|
|
|
|
// });
|
2014-07-14 10:29:10 +02:00
|
|
|
}
|
|
|
|
});
|
2014-07-15 18:43:38 +02:00
|
|
|
|
2014-07-14 16:06:45 +02:00
|
|
|
grid.addListener(Events.BeforeEdit, new Listener<GridEvent<Result>>() {
|
|
|
|
@Override
|
|
|
|
public void handleEvent(final GridEvent<Result> be) {
|
2014-07-15 18:43:38 +02:00
|
|
|
rootLogger.log(Level.INFO, "table edited: "
|
|
|
|
+ be.getValue().toString());
|
|
|
|
// selectedTable = be.getValue().toString();
|
2014-07-14 16:06:45 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2014-07-18 17:34:26 +02:00
|
|
|
// this listener catch the Attach event.It fires when
|
|
|
|
// the Tables List button is selected.
|
2014-07-18 11:42:27 +02:00
|
|
|
// it seems to fire when the event source is attached to the browser's
|
|
|
|
// document or detached from it.
|
2014-07-11 12:35:26 +02:00
|
|
|
grid.addListener(Events.Attach, new Listener<GridEvent<Result>>() {
|
|
|
|
public void handleEvent(GridEvent<Result> be) {
|
2014-07-17 17:14:34 +02:00
|
|
|
rootLogger.log(Level.INFO, "event Attach handled");
|
2014-07-18 11:42:27 +02:00
|
|
|
// 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();
|
|
|
|
|
2014-07-11 12:35:26 +02:00
|
|
|
PagingLoadConfig config = new BasePagingLoadConfig();
|
2014-07-17 14:37:55 +02:00
|
|
|
// The offset for the first record to retrieve.
|
2014-07-11 12:35:26 +02:00
|
|
|
config.setOffset(0);
|
2014-07-17 14:37:55 +02:00
|
|
|
// The number of records being requested.
|
2014-07-11 12:35:26 +02:00
|
|
|
config.setLimit(100);
|
|
|
|
|
2014-07-18 11:42:27 +02:00
|
|
|
// 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);
|
|
|
|
// }
|
2014-07-11 12:35:26 +02:00
|
|
|
// if (state.containsKey("sortField")) {
|
|
|
|
// config.setSortField((String) state.get("sortField"));
|
|
|
|
// config.setSortDir(SortDir.valueOf((String) state
|
|
|
|
// .get("sortDir")));
|
|
|
|
// }
|
|
|
|
loader.load(config);
|
|
|
|
}
|
|
|
|
});
|
2014-07-11 20:22:24 +02:00
|
|
|
|
|
|
|
tablesLoaded = new Dialog();
|
|
|
|
tablesLoaded.setLayout(new FitLayout());
|
2014-07-18 11:42:27 +02:00
|
|
|
// ADD CANCEL BUTTON
|
2014-10-16 12:49:08 +02:00
|
|
|
// tablesLoaded.addButton(new Button("CANCEL"));
|
2014-07-11 20:22:24 +02:00
|
|
|
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);
|
2014-10-16 12:49:08 +02:00
|
|
|
tablesLoaded.setMinimizable(false);
|
|
|
|
tablesLoaded.setClosable(true);
|
2014-07-11 20:22:24 +02:00
|
|
|
tablesLoaded.setBottomComponent(toolBar);
|
2014-07-16 16:18:09 +02:00
|
|
|
// toolBarTop.getAriaSupport().setLabel("Table Search");
|
|
|
|
|
2014-07-18 17:34:26 +02:00
|
|
|
// enter event in the search
|
2014-07-16 16:18:09 +02:00
|
|
|
// TextField<String> searchTable = new TextField<String>();
|
|
|
|
// searchTable.setFieldLabel("Search: ");
|
2014-07-17 14:37:55 +02:00
|
|
|
// 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);
|
|
|
|
// }
|
|
|
|
// });
|
2014-07-16 16:18:09 +02:00
|
|
|
tablesLoaded.setTopComponent(toolBarTop);
|
|
|
|
|
2014-07-14 14:20:18 +02:00
|
|
|
// listener to manage the table selection in the grid
|
2014-09-22 10:14:48 +02:00
|
|
|
final Button ok = (Button) tablesLoaded.getButtonBar().getWidget(0);
|
|
|
|
ok.disable();
|
2014-07-14 14:59:12 +02:00
|
|
|
rootLogger.log(Level.INFO, "button: " + ok.getText());
|
2014-10-16 12:49:08 +02:00
|
|
|
|
|
|
|
// Button canc = (Button) tablesLoaded.getButtonBar().getWidget(1);
|
|
|
|
// rootLogger.log(Level.INFO, "button: " + canc.getText());
|
2014-09-22 11:10:07 +02:00
|
|
|
|
2014-07-15 18:43:38 +02:00
|
|
|
// listener for buttons
|
2014-07-14 14:59:12 +02:00
|
|
|
ok.addSelectionListener(new SelectionListener<ButtonEvent>() {
|
|
|
|
@Override
|
|
|
|
public void componentSelected(ButtonEvent ce) {
|
2014-07-17 14:37:55 +02:00
|
|
|
keyword = null;
|
|
|
|
startSearchTable = false;
|
2014-09-22 11:10:07 +02:00
|
|
|
|
|
|
|
// if (selectedTable != null) {
|
|
|
|
if (!currentselectedTable.equals(selectedTable)) {
|
2014-09-22 10:14:48 +02:00
|
|
|
currentselectedTable = selectedTable;
|
2014-09-19 17:36:36 +02:00
|
|
|
// refresh the content in the two panels
|
2014-09-15 16:12:50 +02:00
|
|
|
centerBottom.removeAll();
|
|
|
|
centerBottom.layout(true);
|
|
|
|
centerUpper.removeAll();
|
|
|
|
centerUpper.layout(true);
|
2014-09-19 17:36:36 +02:00
|
|
|
|
2014-07-15 18:43:38 +02:00
|
|
|
// display the table in the panel "Database Information"
|
2014-09-22 10:14:48 +02:00
|
|
|
displayTableName(currentselectedTable);
|
2014-09-19 17:36:36 +02:00
|
|
|
|
2014-09-18 14:10:36 +02:00
|
|
|
// to get the selected item in the tree panel
|
|
|
|
List<FileModel> data = treePanel.getTreePanel()
|
|
|
|
.getSelectionModel().getSelectedItems();
|
|
|
|
FileModel selectedItem = data.get(0);
|
2014-09-19 17:36:36 +02:00
|
|
|
|
2014-07-15 18:43:38 +02:00
|
|
|
// fire event
|
2014-09-19 17:36:36 +02:00
|
|
|
eventBus.fireEvent(new SelectedTableEvent(selectedItem,
|
2014-09-22 10:14:48 +02:00
|
|
|
currentselectedTable));
|
2014-07-15 18:03:38 +02:00
|
|
|
}
|
2014-07-14 14:59:12 +02:00
|
|
|
}
|
|
|
|
});
|
2014-07-14 14:20:18 +02:00
|
|
|
|
2014-10-16 12:49:08 +02:00
|
|
|
//CANC BUTTON that closes the window
|
|
|
|
// canc.addSelectionListener(new SelectionListener<ButtonEvent>() {
|
|
|
|
// @Override
|
|
|
|
// public void componentSelected(ButtonEvent ce) {
|
|
|
|
// keyword = null;
|
|
|
|
// startSearchTable = false;
|
|
|
|
// // refresh the database information panel
|
|
|
|
// // centerUpper.removeAll();
|
|
|
|
// // centerUpper.layout(true);
|
|
|
|
// tablesLoaded.hide();
|
|
|
|
// }
|
|
|
|
// });
|
|
|
|
|
|
|
|
tablesLoaded.addListener(Events.Hide, new Listener<WindowEvent>() {
|
2014-07-14 14:59:12 +02:00
|
|
|
@Override
|
2014-10-16 12:49:08 +02:00
|
|
|
public void handleEvent(WindowEvent be) {
|
|
|
|
|
2014-07-17 14:37:55 +02:00
|
|
|
keyword = null;
|
|
|
|
startSearchTable = false;
|
2014-07-14 14:59:12 +02:00
|
|
|
tablesLoaded.hide();
|
2014-10-16 12:49:08 +02:00
|
|
|
|
|
|
|
rootLogger.log(Level.INFO, "Window Tables closed");
|
|
|
|
|
|
|
|
}});
|
2014-09-22 11:10:07 +02:00
|
|
|
|
|
|
|
// listener to manage the table selection in the grid
|
|
|
|
grid.getSelectionModel().addSelectionChangedListener(
|
|
|
|
new SelectionChangedListener<Result>() {
|
|
|
|
@Override
|
|
|
|
public void selectionChanged(
|
|
|
|
SelectionChangedEvent<Result> se) {
|
|
|
|
selectedTable = grid.getSelectionModel()
|
|
|
|
.getSelectedItems().get(0).getValue();
|
|
|
|
rootLogger.log(Level.INFO,
|
|
|
|
"SelectionChangedListener->table selected: "
|
2014-09-22 10:14:48 +02:00
|
|
|
+ selectedTable);
|
2014-09-22 11:10:07 +02:00
|
|
|
|
|
|
|
ok.enable();
|
|
|
|
}
|
|
|
|
});
|
2014-07-17 14:37:55 +02:00
|
|
|
tablesLoaded.add(grid);
|
2014-07-11 20:22:24 +02:00
|
|
|
tablesLoaded.show();
|
2014-07-11 12:35:26 +02:00
|
|
|
}
|
|
|
|
|
2014-07-18 17:34:26 +02:00
|
|
|
// method to submit a query
|
2014-07-25 20:03:14 +02:00
|
|
|
private void submitQuery(final Integer dialogID) {
|
2014-07-18 17:34:26 +02:00
|
|
|
// get the selected item
|
2014-07-09 16:55:19 +02:00
|
|
|
List<FileModel> data = treePanel.getTreePanel().getSelectionModel()
|
|
|
|
.getSelectedItems();
|
|
|
|
FileModel selectedItem = data.get(0);
|
2014-07-03 14:44:03 +02:00
|
|
|
|
2014-07-18 17:34:26 +02:00
|
|
|
// get information related to the selected item
|
2014-07-02 12:57:14 +02:00
|
|
|
// recover input data
|
2014-07-09 16:55:19 +02:00
|
|
|
LinkedHashMap<String, String> dataForSubmitQuery = new LinkedHashMap<String, String>();
|
|
|
|
dataForSubmitQuery.put("ResourceName", selectedItem.getResourceName());
|
|
|
|
dataForSubmitQuery.put("DatabaseName", selectedItem.getDatabaseName());
|
2014-07-09 18:12:30 +02:00
|
|
|
|
|
|
|
// print check
|
|
|
|
// System.out.println("ResourceName" + selectedItem.getResourceName());
|
|
|
|
// System.out.println("DatabaseName" + selectedItem.getDatabaseName());
|
2014-07-02 12:57:14 +02:00
|
|
|
|
2014-07-30 11:13:17 +02:00
|
|
|
// get data list (inserted in the form)
|
|
|
|
LinkedHashMap<Integer, SubmitQueryData> submitQueryDataList = toolbar
|
|
|
|
.getSubmitQueryDataList();
|
|
|
|
// get dialog list
|
2014-07-24 17:07:34 +02:00
|
|
|
LinkedHashMap<Integer, Dialog> dialogList = toolbar.getDialogFormList();
|
2014-07-30 11:13:17 +02:00
|
|
|
// get the dialog related to the ID
|
2014-07-24 17:07:34 +02:00
|
|
|
final Dialog form = dialogList.get(dialogID);
|
2014-07-30 11:13:17 +02:00
|
|
|
// get the data form related to the ID
|
2014-07-24 17:07:34 +02:00
|
|
|
final SubmitQueryData dataQuery = submitQueryDataList.get(dialogID);
|
2014-08-29 15:39:04 +02:00
|
|
|
// get the UID related to submitQuery operation
|
|
|
|
LinkedHashMap<Integer, String> uidSubmitQueryList = toolbar
|
|
|
|
.getUIDSubmitQueryList();
|
|
|
|
final String UID = uidSubmitQueryList.get(dialogID);
|
2014-07-30 11:13:17 +02:00
|
|
|
|
|
|
|
// rootLogger.log(Level.INFO, "query: "+ dataQuery.getQuery() +
|
|
|
|
// "submitquery->dialogID: "
|
|
|
|
// + dialogID);
|
|
|
|
|
2014-07-02 12:57:14 +02:00
|
|
|
// determine the language
|
|
|
|
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
|
|
|
|
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-09-08 12:36:49 +02:00
|
|
|
} else { // the selected item is a table
|
|
|
|
// 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");
|
|
|
|
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
|
|
|
|
2014-07-18 17:34:26 +02:00
|
|
|
// remote rpc
|
2014-07-09 16:55:19 +02:00
|
|
|
RPCservice.submitQuery(dataForSubmitQuery, dataQuery.getQuery(), true,
|
2014-08-29 15:39:04 +02:00
|
|
|
dataQuery.getSmartCorrection(), language, UID,
|
2014-09-19 17:36:36 +02:00
|
|
|
new AsyncCallback<SubmitQueryResultWithFileFromServlet>() {
|
2014-07-02 12:57:14 +02:00
|
|
|
|
2014-09-08 12:36:49 +02:00
|
|
|
// TODO: TO REMOVE data "true" as input if you manage the
|
2014-07-18 17:34:26 +02:00
|
|
|
// read-only query in the form
|
2014-07-02 12:57:14 +02:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onFailure(Throwable caught) {
|
2014-07-03 14:44:03 +02:00
|
|
|
// Window.alert(caught.getMessage());
|
2014-09-05 11:30:05 +02:00
|
|
|
rootLogger
|
|
|
|
.log(Level.SEVERE, "FAILURE RPC submitQuery ");
|
|
|
|
|
2014-10-01 15:38:16 +02:00
|
|
|
if (caught instanceof SessionExpiredException) {
|
2014-09-29 15:13:02 +02:00
|
|
|
rootLogger.log(Level.INFO, "Session expired");
|
|
|
|
CheckSession.showLogoutDialog();
|
|
|
|
return;
|
|
|
|
}
|
2014-10-01 15:38:16 +02:00
|
|
|
|
2014-09-08 12:36:49 +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();
|
|
|
|
//
|
|
|
|
// if (form.getBody().isMasked())
|
|
|
|
// form.getBody().unmask();
|
|
|
|
// }
|
|
|
|
// };
|
2014-09-05 11:30:05 +02:00
|
|
|
|
|
|
|
if (!(caught.getMessage().equals("ServerException"))) {
|
2014-09-10 16:00:13 +02:00
|
|
|
if (caught.getMessage().contains(
|
|
|
|
"Result not available")) {
|
|
|
|
MessageBox.alert("Warning ", "<br/>Message:"
|
|
|
|
+ "The query returned 0 values", null);
|
2014-09-19 17:36:36 +02:00
|
|
|
} else {
|
|
|
|
MessageBox.alert("Error ", "<br/>Message:"
|
|
|
|
+ caught.getMessage(), null);
|
2014-09-10 16:00:13 +02:00
|
|
|
}
|
2014-09-01 12:58:31 +02:00
|
|
|
}
|
2014-09-05 11:30:05 +02:00
|
|
|
|
|
|
|
// if (!(caught instanceof
|
|
|
|
// javax.xml.ws.soap.SOAPFaultException)){
|
|
|
|
// MessageBox.alert("Error ",
|
|
|
|
// "<br/>Message:" + caught.getMessage(), l);
|
|
|
|
// }
|
2014-09-08 12:36:49 +02:00
|
|
|
|
2014-09-05 11:30:05 +02:00
|
|
|
if (form.getBody().isMasked())
|
|
|
|
form.getBody().unmask();
|
2014-09-08 12:36:49 +02:00
|
|
|
|
|
|
|
if (form.getButtonById(Dialog.OK).isEnabled() == false) {
|
2014-09-05 11:30:05 +02:00
|
|
|
form.getButtonById(Dialog.OK).enable();
|
|
|
|
}
|
2014-07-02 12:57:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2014-09-22 11:10:07 +02:00
|
|
|
public void onSuccess(
|
|
|
|
SubmitQueryResultWithFileFromServlet obj) {
|
2014-09-01 12:58:31 +02:00
|
|
|
rootLogger.log(Level.SEVERE, "SUCCESS RPC submitQuery");
|
2014-09-08 12:36:49 +02:00
|
|
|
|
2014-09-22 11:10:07 +02:00
|
|
|
if (obj != null) {
|
|
|
|
// get list attributes
|
2014-09-19 17:36:36 +02:00
|
|
|
List<String> listAttributes = obj.getListOutput();
|
2014-09-22 11:10:07 +02:00
|
|
|
|
2014-09-19 17:36:36 +02:00
|
|
|
if (form.getBody().isMasked())
|
|
|
|
form.getBody().unmask();
|
2014-09-08 12:36:49 +02:00
|
|
|
|
2014-09-19 17:36:36 +02:00
|
|
|
if (form.getButtonById(Dialog.OK).isEnabled() == false) {
|
|
|
|
form.getButtonById(Dialog.OK).enable();
|
|
|
|
}
|
2014-09-08 12:36:49 +02:00
|
|
|
|
2014-10-01 15:38:16 +02:00
|
|
|
// if listAttributes is null the computation has
|
|
|
|
// been removed from the statisticalManager.In this
|
|
|
|
// case no message is displayed.
|
2014-09-19 17:36:36 +02:00
|
|
|
if (listAttributes == null) {
|
|
|
|
return;
|
|
|
|
}
|
2014-08-29 15:39:04 +02:00
|
|
|
|
2014-09-19 17:36:36 +02:00
|
|
|
if (listAttributes.size() == 0) {
|
|
|
|
// if (form.getBody().isMasked())
|
|
|
|
// form.getBody().unmask();
|
|
|
|
rootLogger.log(Level.SEVERE,
|
|
|
|
"No results have been returned");
|
|
|
|
MessageBox.alert("Warning ", "<br/>Message:"
|
|
|
|
+ "The query returned 0 values", null);
|
|
|
|
return;
|
|
|
|
}
|
2014-10-01 15:38:16 +02:00
|
|
|
|
|
|
|
String query = "";
|
|
|
|
|
|
|
|
if (dataQuery.getSmartCorrection() == false) {
|
|
|
|
query = dataQuery.getQuery();
|
|
|
|
} else {
|
|
|
|
query = obj.getConvertedQuery();
|
|
|
|
}
|
2014-09-19 17:36:36 +02:00
|
|
|
// if ((listAttributes == null)
|
|
|
|
// || (listAttributes.size() == 0)) {
|
|
|
|
//
|
|
|
|
// // if (form.getBody().isMasked())
|
|
|
|
// // form.getBody().unmask();
|
|
|
|
//
|
|
|
|
// rootLogger.log(Level.SEVERE,
|
|
|
|
// "No results have been returned");
|
|
|
|
//
|
|
|
|
// MessageBox.alert("Error ", "<br/>Message:"
|
|
|
|
// + "Result not available", null);
|
|
|
|
// return;
|
|
|
|
// }
|
2014-09-05 11:30:05 +02:00
|
|
|
|
2014-09-22 11:10:07 +02:00
|
|
|
rootLogger.log(Level.SEVERE,
|
|
|
|
"SUCCESS RPC submitQuery");
|
2014-09-19 17:36:36 +02:00
|
|
|
rootLogger.log(Level.SEVERE, "output size: "
|
|
|
|
+ listAttributes.size());
|
2014-07-02 12:57:14 +02:00
|
|
|
|
2014-09-19 17:36:36 +02:00
|
|
|
// recover query
|
|
|
|
// Result query = result.remove(0);
|
|
|
|
// recover converted query
|
|
|
|
// Result convertedQuery;
|
2014-07-02 12:57:14 +02:00
|
|
|
|
2014-09-19 17:36:36 +02:00
|
|
|
// if (dataQuery.getSmartCorrection() == true) {
|
|
|
|
// result.remove(0);
|
|
|
|
// // convertedQuery = result.get(1);
|
|
|
|
// }
|
2014-08-29 15:39:04 +02:00
|
|
|
|
2014-09-19 17:36:36 +02:00
|
|
|
// get the attributes list for the result table
|
|
|
|
// List<String> listAttributes = new
|
|
|
|
// ArrayList<String>();
|
|
|
|
// listAttributes = 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
|
|
|
|
// boolean submitQueryEventManaged = true;
|
|
|
|
// parseResult(result, form, dialogID,
|
|
|
|
// submitQueryEventManaged);
|
|
|
|
|
|
|
|
// parseSubmitQueryResult(result, form, dialogID,
|
|
|
|
// listAttributes, dataQuery.getQuery());
|
|
|
|
|
|
|
|
// get path
|
|
|
|
String fileName = obj.getFileName();
|
2014-09-22 11:10:07 +02:00
|
|
|
parseSubmitQueryResult(form, dialogID,
|
2014-09-24 11:02:22 +02:00
|
|
|
listAttributes, query, fileName, UID);
|
2014-09-22 11:10:07 +02:00
|
|
|
|
2014-09-19 17:36:36 +02:00
|
|
|
}
|
2014-09-22 11:10:07 +02:00
|
|
|
|
2014-07-02 12:57:14 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2014-08-29 15:39:04 +02:00
|
|
|
// start the parsing of the submit result in order to obtain a table
|
|
|
|
private void parseSubmitQueryResult(Dialog dialog, final int dialogID,
|
2014-10-01 15:38:16 +02:00
|
|
|
final List<String> listAttributes, String query, String fileName,
|
|
|
|
final String UID) {
|
2014-08-29 15:39:04 +02:00
|
|
|
|
|
|
|
final Dialog form = dialog;
|
|
|
|
// define the proxy and create the grid to display in the dialog
|
|
|
|
// create RpcProxy object to use the load configuration
|
|
|
|
RpcProxy<PagingLoadResult<Row>> proxy = new RpcProxy<PagingLoadResult<Row>>() {
|
|
|
|
@Override
|
|
|
|
protected void load(Object loadConfig,
|
|
|
|
final AsyncCallback<PagingLoadResult<Row>> callback) {
|
|
|
|
rootLogger.log(Level.SEVERE,
|
|
|
|
"Start RPC - loadSubmitQueryResult");
|
|
|
|
|
|
|
|
// remote rpc
|
|
|
|
RPCservice.loadSubmitResult((PagingLoadConfig) loadConfig,
|
|
|
|
listAttributes, UID,
|
|
|
|
new AsyncCallback<PagingLoadResult<Row>>() {
|
|
|
|
@Override
|
|
|
|
public void onFailure(Throwable caught) {
|
|
|
|
rootLogger.log(Level.SEVERE,
|
|
|
|
"FAILURE RPC loadSubmitQueryResult");
|
2014-10-01 15:38:16 +02:00
|
|
|
|
|
|
|
if (caught instanceof SessionExpiredException) {
|
|
|
|
rootLogger.log(Level.INFO,
|
|
|
|
"Session expired");
|
2014-09-29 15:13:02 +02:00
|
|
|
CheckSession.showLogoutDialog();
|
|
|
|
return;
|
2014-10-01 15:38:16 +02:00
|
|
|
}
|
2014-09-05 11:30:05 +02:00
|
|
|
|
|
|
|
Listener<MessageBoxEvent> l = new Listener<MessageBoxEvent>() {
|
|
|
|
public void handleEvent(MessageBoxEvent ce) {
|
|
|
|
if (form.getBody().isMasked())
|
|
|
|
form.getBody().unmask();
|
2014-09-08 12:36:49 +02:00
|
|
|
|
|
|
|
if (form.getButtonById(Dialog.OK)
|
|
|
|
.isEnabled() == false) {
|
|
|
|
form.getButtonById(Dialog.OK)
|
|
|
|
.enable();
|
2014-09-05 11:30:05 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
2014-09-19 17:36:36 +02:00
|
|
|
|
2014-08-29 15:39:04 +02:00
|
|
|
MessageBox.alert("Error ", "<br/>Message:"
|
2014-09-05 11:30:05 +02:00
|
|
|
+ caught.getMessage(), l);
|
2014-08-29 15:39:04 +02:00
|
|
|
callback.onFailure(caught);
|
|
|
|
}
|
2014-09-05 11:30:05 +02:00
|
|
|
|
2014-08-29 15:39:04 +02:00
|
|
|
@Override
|
|
|
|
public void onSuccess(PagingLoadResult<Row> result) {
|
|
|
|
rootLogger.log(Level.SEVERE,
|
|
|
|
"SUCCESS RPC loadSubmitQueryResult");
|
2014-09-05 11:30:05 +02:00
|
|
|
|
|
|
|
if (result != null) {
|
|
|
|
callback.onSuccess(result);
|
|
|
|
List<Row> rows = result.getData();
|
2014-09-08 12:36:49 +02:00
|
|
|
|
2014-09-05 11:30:05 +02:00
|
|
|
if (form.getBody().isMasked())
|
|
|
|
form.getBody().unmask();
|
2014-09-08 12:36:49 +02:00
|
|
|
|
|
|
|
if (form.getButtonById(Dialog.OK)
|
|
|
|
.isEnabled() == false) {
|
2014-09-05 11:30:05 +02:00
|
|
|
form.getButtonById(Dialog.OK).enable();
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((rows == null) || (rows.size() == 0)) {
|
|
|
|
rootLogger
|
|
|
|
.log(Level.SEVERE,
|
|
|
|
"No results have been returned");
|
2014-09-19 17:36:36 +02:00
|
|
|
|
|
|
|
MessageBox
|
|
|
|
.alert("Warning ",
|
|
|
|
"<br/>Message:"
|
|
|
|
+ "The query returned 0 values",
|
|
|
|
null);
|
|
|
|
|
2014-09-05 11:30:05 +02:00
|
|
|
return;
|
|
|
|
}
|
2014-08-29 15:39:04 +02:00
|
|
|
}
|
|
|
|
// if (result != null) {
|
|
|
|
// rootLogger.log(Level.SEVERE,
|
|
|
|
// "rows not null");
|
|
|
|
// }
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
// loader to load page enabled set of data
|
|
|
|
final PagingLoader<PagingLoadResult<Row>> loader = new BasePagingLoader<PagingLoadResult<Row>>(
|
|
|
|
proxy);
|
|
|
|
|
|
|
|
// to create the listStore using the loader
|
|
|
|
final ListStore<Row> store = new ListStore<Row>(loader);
|
|
|
|
// bind the loader with a PagingToolBar.
|
|
|
|
final PagingToolBar toolBar = new PagingToolBar(100);
|
|
|
|
toolBar.bind(loader);
|
|
|
|
|
|
|
|
// create the grid with a result list and the column model
|
|
|
|
Grid<Row> grid;
|
|
|
|
grid = new Grid<Row>(store, createColumnModel(listAttributes));
|
|
|
|
grid.setLoadMask(true);
|
|
|
|
grid.setBorders(true);
|
|
|
|
grid.setStripeRows(true);
|
|
|
|
// to manage the table selection in the grid
|
|
|
|
grid.getSelectionModel().setSelectionMode(SelectionMode.SINGLE);
|
|
|
|
|
|
|
|
grid.addListener(Events.Attach, new Listener<GridEvent<Row>>() {
|
|
|
|
public void handleEvent(GridEvent<Row> 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();
|
|
|
|
|
|
|
|
PagingLoadConfig config = new BasePagingLoadConfig();
|
|
|
|
// The offset for the first record to retrieve.
|
|
|
|
config.setOffset(0);
|
|
|
|
// The number of records being requested.
|
|
|
|
config.setLimit(100);
|
|
|
|
|
|
|
|
// 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);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
// // Display the submit query result as a table
|
|
|
|
// Dialog submitResult = new Dialog();
|
|
|
|
// submitResult.setLayout(new FitLayout());
|
|
|
|
//
|
|
|
|
// //TODO DA MODIFICARE
|
|
|
|
// submitResult.setHeading("Result");
|
|
|
|
// submitResult.setSize(600, 400);
|
|
|
|
//
|
|
|
|
// submitResult.add(grid);
|
|
|
|
// submitResult.show();
|
|
|
|
|
|
|
|
// 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();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2014-10-01 15:38:16 +02:00
|
|
|
// submitResult.setLayout(new FitLayout());
|
2014-08-29 15:39:04 +02:00
|
|
|
submitResult.setHeading("Result Query " + dialogID);
|
|
|
|
submitResult.setResizable(false);
|
|
|
|
submitResult.setSize(600, 400);
|
|
|
|
submitResult.setScrollMode(Scroll.NONE);
|
|
|
|
submitResult.setHideOnButtonClick(true);
|
|
|
|
submitResult.setMaximizable(true);
|
|
|
|
submitResult.setMinimizable(true);
|
2014-10-01 15:38:16 +02:00
|
|
|
// submitResult.setBottomComponent(toolBar);
|
|
|
|
|
2014-09-24 11:02:22 +02:00
|
|
|
submitResult.setLayout(new RowLayout(Style.Orientation.VERTICAL));
|
2014-10-01 15:38:16 +02:00
|
|
|
// to add the panel of the converted query and the panel that display
|
|
|
|
// the query's result
|
|
|
|
ContentPanel q = new ContentPanel();
|
2014-09-24 11:02:22 +02:00
|
|
|
q.setLayout(new FitLayout());
|
|
|
|
q.setHeaderVisible(false);
|
|
|
|
q.addText(query);
|
|
|
|
submitResult.add(q, new RowData(1, 0.3));
|
2014-10-01 15:38:16 +02:00
|
|
|
|
2014-09-24 11:02:22 +02:00
|
|
|
ContentPanel g = new ContentPanel();
|
|
|
|
g.setLayout(new FitLayout());
|
|
|
|
g.setHeaderVisible(false);
|
|
|
|
g.setBottomComponent(toolBar);
|
|
|
|
g.add(grid);
|
2014-10-01 15:38:16 +02:00
|
|
|
g.layout(true);
|
|
|
|
|
2014-08-29 15:39:04 +02:00
|
|
|
// mimimize event handled
|
|
|
|
submitResult.addListener(Events.Minimize, new Listener<WindowEvent>() {
|
|
|
|
@Override
|
|
|
|
public void handleEvent(WindowEvent be) {
|
|
|
|
// collapse the dialog
|
|
|
|
be.getWindow().collapse();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
// maximize event handled
|
|
|
|
submitResult.addListener(Events.Maximize, new Listener<WindowEvent>() {
|
|
|
|
@Override
|
|
|
|
public void handleEvent(WindowEvent be) {
|
|
|
|
// expand the dialog
|
|
|
|
if (be.getWindow().isCollapsed()) {
|
|
|
|
be.getWindow().expand();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
submitResult.addListener(Events.Hide, new Listener<WindowEvent>() {
|
|
|
|
@Override
|
|
|
|
public void handleEvent(WindowEvent be) {
|
|
|
|
// call rpc to remove the stored result
|
|
|
|
RPCservice.refreshDataOnServer(UID, new AsyncCallback<Void>() {
|
|
|
|
@Override
|
|
|
|
public void onFailure(Throwable caught) {
|
|
|
|
rootLogger.log(Level.SEVERE,
|
|
|
|
"FAILURE RPC refreshDataOnServer");
|
2014-10-01 15:38:16 +02:00
|
|
|
|
|
|
|
if (caught instanceof SessionExpiredException) {
|
2014-09-29 15:13:02 +02:00
|
|
|
rootLogger.log(Level.INFO, "Session expired");
|
|
|
|
CheckSession.showLogoutDialog();
|
|
|
|
return;
|
2014-10-01 15:38:16 +02:00
|
|
|
}
|
2014-08-29 15:39:04 +02:00
|
|
|
}
|
2014-09-10 16:00:13 +02:00
|
|
|
|
2014-08-29 15:39:04 +02:00
|
|
|
@Override
|
|
|
|
public void onSuccess(Void result) {
|
|
|
|
rootLogger.log(Level.SEVERE,
|
|
|
|
"SUCCESS RPC refreshDataOnServer");
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
2014-09-22 11:10:07 +02:00
|
|
|
|
2014-09-19 17:36:36 +02:00
|
|
|
// add the button to download the result
|
2014-09-22 11:10:07 +02:00
|
|
|
final String urlFile = Window.Location.getProtocol() + "//"
|
2014-09-19 17:36:36 +02:00
|
|
|
+ Window.Location.getHost() + fileName;
|
|
|
|
|
|
|
|
Button download = new Button("Download",
|
|
|
|
new SelectionListener<ButtonEvent>() {
|
|
|
|
@Override
|
2014-09-22 11:10:07 +02:00
|
|
|
public void componentSelected(ButtonEvent ce) {
|
|
|
|
Window.open(urlFile, "Result File", "_blank");
|
2014-09-19 17:36:36 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
submitResult.addButton(download);
|
2014-10-01 15:38:16 +02:00
|
|
|
// submitResult.add(grid);
|
|
|
|
submitResult.add(g, new RowData(1, 0.7));
|
2014-08-29 15:39:04 +02:00
|
|
|
submitResult.show();
|
|
|
|
}
|
|
|
|
|
2014-07-18 17:34:26 +02:00
|
|
|
// method to perform the sample table
|
|
|
|
private void sample() {
|
2014-07-09 18:12:30 +02:00
|
|
|
final GxtBorderLayoutPanel obj = this;
|
2014-07-03 14:44:03 +02:00
|
|
|
rootLogger.log(Level.SEVERE, "Start RPC - sample");
|
|
|
|
|
|
|
|
// get the selected table
|
|
|
|
List<FileModel> data = treePanel.getTreePanel().getSelectionModel()
|
|
|
|
.getSelectedItems();
|
2014-07-14 10:06:55 +02:00
|
|
|
// the selected item
|
2014-07-03 14:44:03 +02:00
|
|
|
FileModel selectedItem = data.get(0);
|
|
|
|
// recover data inputs
|
2014-07-14 14:20:18 +02:00
|
|
|
final LinkedHashMap<String, String> dataInput = new LinkedHashMap<String, String>();
|
2014-07-03 14:44:03 +02:00
|
|
|
// check if the table has an associated schema
|
|
|
|
FileModel schema;
|
|
|
|
FileModel database;
|
|
|
|
FileModel resource;
|
|
|
|
|
2014-09-22 11:10:07 +02:00
|
|
|
String elementType;
|
2014-10-01 15:38:16 +02:00
|
|
|
|
2014-07-14 10:06:55 +02:00
|
|
|
if (selectedItem.isDatabase()) {
|
2014-07-18 17:34:26 +02:00
|
|
|
// the table has not a schema because the selected item is a
|
|
|
|
// database
|
2014-07-14 10:06:55 +02:00
|
|
|
database = selectedItem;
|
2014-07-09 18:12:30 +02:00
|
|
|
resource = treePanel.getTreeStore().getParent(database);
|
|
|
|
|
|
|
|
dataInput.put("ResourceName", resource.getName());
|
|
|
|
dataInput.put("DatabaseName", database.getName());
|
|
|
|
dataInput.put("SchemaName", "");
|
2014-09-22 10:14:48 +02:00
|
|
|
dataInput.put("TableName", currentselectedTable);
|
2014-07-09 18:12:30 +02:00
|
|
|
|
|
|
|
rootLogger.log(Level.INFO, "ResourceName: " + resource.getName());
|
|
|
|
rootLogger.log(Level.INFO, "DatabaseName: " + database.getName());
|
|
|
|
rootLogger.log(Level.INFO, "SchemaName: " + "");
|
2014-09-22 10:14:48 +02:00
|
|
|
rootLogger.log(Level.INFO, "TableName: " + currentselectedTable);
|
2014-10-01 15:38:16 +02:00
|
|
|
|
2014-09-22 11:10:07 +02:00
|
|
|
elementType = ConstantsPortlet.DATABASE;
|
2014-07-09 18:12:30 +02:00
|
|
|
} else {
|
2014-07-18 17:34:26 +02:00
|
|
|
// the table has a schema because the selected item is a schema
|
2014-07-14 10:06:55 +02:00
|
|
|
schema = selectedItem;
|
2014-07-03 14:44:03 +02:00
|
|
|
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());
|
2014-09-22 10:14:48 +02:00
|
|
|
dataInput.put("TableName", currentselectedTable);
|
2014-07-03 14:44:03 +02:00
|
|
|
|
|
|
|
rootLogger.log(Level.INFO, "ResourceName: " + resource.getName());
|
|
|
|
rootLogger.log(Level.INFO, "DatabaseName: " + database.getName());
|
|
|
|
rootLogger.log(Level.INFO, "SchemaName: " + schema.getName());
|
2014-09-22 10:14:48 +02:00
|
|
|
rootLogger.log(Level.INFO, "TableName: " + currentselectedTable);
|
2014-10-01 15:38:16 +02:00
|
|
|
|
2014-09-22 11:10:07 +02:00
|
|
|
elementType = ConstantsPortlet.SCHEMA;
|
2014-07-03 14:44:03 +02:00
|
|
|
}
|
|
|
|
|
2014-07-15 18:43:38 +02:00
|
|
|
// to mask the entire content panel
|
|
|
|
obj.mask("Sampling the table", "x-mask-loading");
|
2014-07-03 14:44:03 +02:00
|
|
|
|
2014-07-15 18:43:38 +02:00
|
|
|
// call remote service
|
2014-09-22 11:10:07 +02:00
|
|
|
RPCservice.sample(dataInput, elementType,
|
2014-09-19 17:36:36 +02:00
|
|
|
new AsyncCallback<SamplingResultWithFileFromServlet>() {
|
|
|
|
@Override
|
|
|
|
public void onFailure(Throwable caught) {
|
|
|
|
// Window.alert(caught.getMessage());
|
|
|
|
rootLogger.log(Level.SEVERE, "FAILURE RPC sample");
|
2014-10-01 15:38:16 +02:00
|
|
|
|
|
|
|
if (caught instanceof SessionExpiredException) {
|
2014-09-29 15:13:02 +02:00
|
|
|
rootLogger.log(Level.INFO, "Session expired");
|
|
|
|
CheckSession.showLogoutDialog();
|
|
|
|
return;
|
2014-10-01 15:38:16 +02:00
|
|
|
}
|
|
|
|
|
2014-09-19 17:36:36 +02:00
|
|
|
if (caught.getMessage()
|
|
|
|
.contains("Result not available")) {
|
|
|
|
MessageBox.alert("Warning ", "<br/>Message:"
|
|
|
|
+ "The table has 0 rows", null);
|
|
|
|
} else {
|
|
|
|
MessageBox.alert("Error ",
|
|
|
|
"<br/>Message:" + caught.getMessage(), null);
|
|
|
|
}
|
|
|
|
if (obj.isMasked()) {
|
|
|
|
obj.unmask();
|
|
|
|
}
|
|
|
|
}
|
2014-09-10 16:00:13 +02:00
|
|
|
|
2014-09-19 17:36:36 +02:00
|
|
|
@Override
|
2014-10-01 15:38:16 +02:00
|
|
|
public void onSuccess(
|
|
|
|
SamplingResultWithFileFromServlet samplingResult) {
|
2014-09-19 17:36:36 +02:00
|
|
|
rootLogger.log(Level.SEVERE, "SUCCESS RPC sample");
|
|
|
|
|
2014-09-30 14:32:27 +02:00
|
|
|
if (samplingResult != null) {
|
2014-09-19 17:36:36 +02:00
|
|
|
// get data
|
2014-10-01 15:38:16 +02:00
|
|
|
List<Result> result = samplingResult
|
|
|
|
.getListOutput();
|
2014-09-19 17:36:36 +02:00
|
|
|
// get the attributes list for the result
|
|
|
|
// table
|
|
|
|
List<String> listAttributes = new ArrayList<String>();
|
|
|
|
listAttributes = getListAttributes(result.get(0)
|
|
|
|
.getValue());
|
|
|
|
// remove the header in order to parse only
|
|
|
|
// the result
|
|
|
|
result.remove(0);
|
|
|
|
rootLogger.log(Level.SEVERE, "output size: "
|
|
|
|
+ result.size());
|
|
|
|
|
|
|
|
// get path
|
2014-09-30 14:32:27 +02:00
|
|
|
String fileName = samplingResult.getFileName();
|
2014-09-19 17:36:36 +02:00
|
|
|
// parse the result in order to obtain a
|
|
|
|
// table
|
|
|
|
parseResult(result, listAttributes, fileName);
|
|
|
|
|
2014-10-01 15:38:16 +02:00
|
|
|
} else {
|
|
|
|
MessageBox.alert("Error ", "<br/>Message: "
|
|
|
|
+ "no data available", null);
|
|
|
|
|
2014-09-30 14:32:27 +02:00
|
|
|
if (obj.isMasked()) {
|
|
|
|
obj.unmask();
|
|
|
|
}
|
2014-10-01 15:38:16 +02:00
|
|
|
|
2014-09-19 17:36:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
});
|
2014-10-10 12:53:26 +02:00
|
|
|
|
2014-07-04 12:09:47 +02:00
|
|
|
}
|
2014-07-04 12:36:43 +02:00
|
|
|
|
2014-07-18 17:34:26 +02:00
|
|
|
// method that performs the smart sample
|
2014-07-04 12:36:43 +02:00
|
|
|
private void smartSample() {
|
2014-07-09 18:12:30 +02:00
|
|
|
final GxtBorderLayoutPanel obj = this;
|
2014-07-04 12:36:43 +02:00
|
|
|
rootLogger.log(Level.SEVERE, "Start RPC - smartSample");
|
|
|
|
// get the selected table
|
|
|
|
List<FileModel> data = treePanel.getTreePanel().getSelectionModel()
|
|
|
|
.getSelectedItems();
|
2014-07-14 10:06:55 +02:00
|
|
|
// the selected item
|
2014-07-04 12:36:43 +02:00
|
|
|
FileModel selectedItem = data.get(0);
|
|
|
|
// recover data inputs for the algorithm
|
2014-07-14 14:20:18 +02:00
|
|
|
final LinkedHashMap<String, String> dataInput = new LinkedHashMap<String, String>();
|
2014-07-04 12:36:43 +02:00
|
|
|
// check if the table has an associated schema
|
|
|
|
FileModel schema;
|
|
|
|
FileModel database;
|
|
|
|
FileModel resource;
|
2014-10-01 15:38:16 +02:00
|
|
|
|
2014-09-22 11:10:07 +02:00
|
|
|
String elementType;
|
2014-10-01 15:38:16 +02:00
|
|
|
|
2014-07-14 10:06:55 +02:00
|
|
|
if (selectedItem.isDatabase()) {
|
|
|
|
// the table has not a schema
|
|
|
|
database = selectedItem;
|
2014-07-04 12:36:43 +02:00
|
|
|
resource = treePanel.getTreeStore().getParent(database);
|
|
|
|
|
|
|
|
dataInput.put("ResourceName", resource.getName());
|
|
|
|
dataInput.put("DatabaseName", database.getName());
|
2014-07-09 14:11:19 +02:00
|
|
|
dataInput.put("SchemaName", "");
|
2014-09-22 10:14:48 +02:00
|
|
|
dataInput.put("TableName", currentselectedTable);
|
2014-07-04 12:36:43 +02:00
|
|
|
|
|
|
|
rootLogger.log(Level.INFO, "ResourceName: " + resource.getName());
|
|
|
|
rootLogger.log(Level.INFO, "DatabaseName: " + database.getName());
|
2014-07-09 14:11:19 +02:00
|
|
|
rootLogger.log(Level.INFO, "SchemaName: " + "");
|
2014-09-22 10:14:48 +02:00
|
|
|
rootLogger.log(Level.INFO, "TableName: " + currentselectedTable);
|
2014-10-01 15:38:16 +02:00
|
|
|
elementType = ConstantsPortlet.DATABASE;
|
2014-07-04 12:36:43 +02:00
|
|
|
} else {
|
2014-07-09 14:11:19 +02:00
|
|
|
// the table has a schema
|
2014-07-14 10:06:55 +02:00
|
|
|
schema = selectedItem;
|
2014-07-09 14:11:19 +02:00
|
|
|
database = treePanel.getTreeStore().getParent(schema);
|
2014-07-04 12:36:43 +02:00
|
|
|
resource = treePanel.getTreeStore().getParent(database);
|
|
|
|
|
|
|
|
dataInput.put("ResourceName", resource.getName());
|
|
|
|
dataInput.put("DatabaseName", database.getName());
|
2014-07-09 14:11:19 +02:00
|
|
|
dataInput.put("SchemaName", schema.getName());
|
2014-09-22 10:14:48 +02:00
|
|
|
dataInput.put("TableName", currentselectedTable);
|
2014-07-04 12:36:43 +02:00
|
|
|
|
|
|
|
rootLogger.log(Level.INFO, "ResourceName: " + resource.getName());
|
|
|
|
rootLogger.log(Level.INFO, "DatabaseName: " + database.getName());
|
2014-07-09 14:11:19 +02:00
|
|
|
rootLogger.log(Level.INFO, "SchemaName: " + schema.getName());
|
2014-09-22 10:14:48 +02:00
|
|
|
rootLogger.log(Level.INFO, "TableName: " + currentselectedTable);
|
2014-10-01 15:38:16 +02:00
|
|
|
elementType = ConstantsPortlet.SCHEMA;
|
2014-07-04 12:36:43 +02:00
|
|
|
}
|
2014-07-15 18:43:38 +02:00
|
|
|
// to mask the entire content panel
|
|
|
|
obj.mask("Sampling the table", "x-mask-loading");
|
2014-07-11 12:35:26 +02:00
|
|
|
|
2014-07-15 18:43:38 +02:00
|
|
|
// call remote service
|
2014-09-22 11:10:07 +02:00
|
|
|
RPCservice.smartSample(dataInput, elementType,
|
2014-09-19 17:36:36 +02:00
|
|
|
new AsyncCallback<SamplingResultWithFileFromServlet>() {
|
|
|
|
@Override
|
|
|
|
public void onFailure(Throwable caught) {
|
|
|
|
// Window.alert(caught.getMessage());
|
|
|
|
rootLogger.log(Level.SEVERE, "FAILURE RPC smartSample");
|
2014-10-01 15:38:16 +02:00
|
|
|
|
|
|
|
if (caught instanceof SessionExpiredException) {
|
2014-09-29 15:13:02 +02:00
|
|
|
rootLogger.log(Level.INFO, "Session expired");
|
|
|
|
CheckSession.showLogoutDialog();
|
|
|
|
return;
|
2014-10-01 15:38:16 +02:00
|
|
|
}
|
2014-09-19 17:36:36 +02:00
|
|
|
if (caught.getMessage()
|
|
|
|
.contains("The table has 0 rows")) {
|
|
|
|
MessageBox.alert("Warning ", "<br/>Message:"
|
|
|
|
+ "The table has 0 rows", null);
|
|
|
|
} else {
|
|
|
|
MessageBox.alert("Error ",
|
|
|
|
"<br/>Message:" + caught.getMessage(), null);
|
|
|
|
}
|
|
|
|
if (obj.isMasked()) {
|
|
|
|
obj.unmask();
|
|
|
|
}
|
|
|
|
}
|
2014-07-04 12:36:43 +02:00
|
|
|
|
2014-09-19 17:36:36 +02:00
|
|
|
@Override
|
2014-10-01 15:38:16 +02:00
|
|
|
public void onSuccess(
|
|
|
|
SamplingResultWithFileFromServlet samplingResult) {
|
2014-09-19 17:36:36 +02:00
|
|
|
rootLogger.log(Level.SEVERE, "SUCCESS RPC smartSample");
|
|
|
|
|
2014-09-30 14:32:27 +02:00
|
|
|
if (samplingResult != null) {
|
2014-09-19 17:36:36 +02:00
|
|
|
// get data
|
2014-10-01 15:38:16 +02:00
|
|
|
List<Result> result = samplingResult
|
|
|
|
.getListOutput();
|
2014-09-19 17:36:36 +02:00
|
|
|
// get the attributes list for the result
|
|
|
|
// table
|
|
|
|
List<String> listAttributes = new ArrayList<String>();
|
|
|
|
listAttributes = getListAttributes(result.get(0)
|
|
|
|
.getValue());
|
|
|
|
// remove the header in order to parse only
|
|
|
|
// the result
|
|
|
|
result.remove(0);
|
|
|
|
rootLogger.log(Level.SEVERE, "output size: "
|
|
|
|
+ result.size());
|
|
|
|
// get path
|
2014-09-30 14:32:27 +02:00
|
|
|
String fileName = samplingResult.getFileName();
|
2014-09-19 17:36:36 +02:00
|
|
|
// parse the result in order to obtain a
|
|
|
|
// table
|
|
|
|
parseResult(result, listAttributes, fileName);
|
2014-10-01 15:38:16 +02:00
|
|
|
} else {
|
|
|
|
MessageBox.alert("Error ", "<br/>Message: "
|
|
|
|
+ "no data available", null);
|
|
|
|
|
2014-09-30 14:32:27 +02:00
|
|
|
if (obj.isMasked()) {
|
|
|
|
obj.unmask();
|
|
|
|
}
|
2014-10-01 15:38:16 +02:00
|
|
|
|
2014-09-19 17:36:36 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2014-07-04 12:36:43 +02:00
|
|
|
}
|
|
|
|
|
2014-07-18 17:34:26 +02:00
|
|
|
// method to perform the random sample
|
2014-07-04 12:36:43 +02:00
|
|
|
private void randomSample() {
|
2014-07-09 18:12:30 +02:00
|
|
|
final GxtBorderLayoutPanel obj = this;
|
|
|
|
rootLogger.log(Level.SEVERE, "Start RPC - randomSample");
|
|
|
|
// get the selected table
|
|
|
|
List<FileModel> data = treePanel.getTreePanel().getSelectionModel()
|
|
|
|
.getSelectedItems();
|
2014-07-14 10:06:55 +02:00
|
|
|
// the selected item
|
2014-07-09 18:12:30 +02:00
|
|
|
FileModel selectedItem = data.get(0);
|
|
|
|
// recover data inputs for the algorithm
|
2014-07-14 14:20:18 +02:00
|
|
|
final LinkedHashMap<String, String> dataInput = new LinkedHashMap<String, String>();
|
2014-07-04 12:09:47 +02:00
|
|
|
|
2014-07-09 18:12:30 +02:00
|
|
|
// check if the table has an associated schema
|
|
|
|
FileModel schema;
|
|
|
|
FileModel database;
|
|
|
|
FileModel resource;
|
2014-07-04 12:09:47 +02:00
|
|
|
|
2014-09-22 11:10:07 +02:00
|
|
|
String elementType;
|
2014-10-01 15:38:16 +02:00
|
|
|
|
2014-07-14 10:06:55 +02:00
|
|
|
if (selectedItem.isDatabase()) {
|
|
|
|
// the table has not a schema
|
|
|
|
database = selectedItem;
|
2014-07-09 18:12:30 +02:00
|
|
|
resource = treePanel.getTreeStore().getParent(database);
|
2014-07-04 12:09:47 +02:00
|
|
|
|
2014-07-09 18:12:30 +02:00
|
|
|
dataInput.put("ResourceName", resource.getName());
|
|
|
|
dataInput.put("DatabaseName", database.getName());
|
|
|
|
dataInput.put("SchemaName", "");
|
2014-09-22 10:14:48 +02:00
|
|
|
dataInput.put("TableName", currentselectedTable);
|
2014-07-04 12:09:47 +02:00
|
|
|
|
2014-07-09 18:12:30 +02:00
|
|
|
rootLogger.log(Level.INFO, "ResourceName: " + resource.getName());
|
|
|
|
rootLogger.log(Level.INFO, "DatabaseName: " + database.getName());
|
|
|
|
rootLogger.log(Level.INFO, "SchemaName: " + "");
|
2014-09-22 10:14:48 +02:00
|
|
|
rootLogger.log(Level.INFO, "TableName: " + currentselectedTable);
|
2014-09-22 11:10:07 +02:00
|
|
|
elementType = ConstantsPortlet.DATABASE;
|
2014-07-09 18:12:30 +02:00
|
|
|
} else {
|
|
|
|
// the table has a schema
|
2014-07-14 10:06:55 +02:00
|
|
|
schema = selectedItem;
|
2014-07-09 18:12:30 +02:00
|
|
|
database = treePanel.getTreeStore().getParent(schema);
|
|
|
|
resource = treePanel.getTreeStore().getParent(database);
|
2014-07-04 12:36:43 +02:00
|
|
|
|
2014-07-09 18:12:30 +02:00
|
|
|
dataInput.put("ResourceName", resource.getName());
|
|
|
|
dataInput.put("DatabaseName", database.getName());
|
|
|
|
dataInput.put("SchemaName", schema.getName());
|
2014-09-22 10:14:48 +02:00
|
|
|
dataInput.put("TableName", currentselectedTable);
|
2014-07-09 18:12:30 +02:00
|
|
|
|
|
|
|
rootLogger.log(Level.INFO, "ResourceName: " + resource.getName());
|
|
|
|
rootLogger.log(Level.INFO, "DatabaseName: " + database.getName());
|
|
|
|
rootLogger.log(Level.INFO, "SchemaName: " + schema.getName());
|
2014-09-22 10:14:48 +02:00
|
|
|
rootLogger.log(Level.INFO, "TableName: " + currentselectedTable);
|
2014-09-22 11:10:07 +02:00
|
|
|
elementType = ConstantsPortlet.SCHEMA;
|
2014-07-09 18:12:30 +02:00
|
|
|
}
|
|
|
|
|
2014-07-15 18:43:38 +02:00
|
|
|
// to mask the entire content panel
|
|
|
|
obj.mask("Sampling the table", "x-mask-loading");
|
2014-07-09 18:12:30 +02:00
|
|
|
|
2014-07-15 18:43:38 +02:00
|
|
|
// call remote service
|
2014-09-22 11:10:07 +02:00
|
|
|
RPCservice.randomSample(dataInput, elementType,
|
2014-09-19 17:36:36 +02:00
|
|
|
new AsyncCallback<SamplingResultWithFileFromServlet>() {
|
|
|
|
@Override
|
|
|
|
public void onFailure(Throwable caught) {
|
|
|
|
// Window.alert(caught.getMessage());
|
|
|
|
rootLogger
|
|
|
|
.log(Level.SEVERE, "FAILURE RPC randomSample");
|
2014-10-01 15:38:16 +02:00
|
|
|
|
|
|
|
if (caught instanceof SessionExpiredException) {
|
2014-09-29 15:13:02 +02:00
|
|
|
rootLogger.log(Level.INFO, "Session expired");
|
|
|
|
CheckSession.showLogoutDialog();
|
|
|
|
return;
|
2014-10-01 15:38:16 +02:00
|
|
|
}
|
|
|
|
|
2014-09-19 17:36:36 +02:00
|
|
|
if (caught.getMessage()
|
|
|
|
.contains("Result not available")) {
|
|
|
|
MessageBox.alert("Warning ", "<br/>Message:"
|
|
|
|
+ "The table has 0 rows", null);
|
|
|
|
} else {
|
|
|
|
MessageBox.alert("Error ",
|
|
|
|
"<br/>Message:" + caught.getMessage(), null);
|
|
|
|
}
|
|
|
|
if (obj.isMasked()) {
|
|
|
|
obj.unmask();
|
|
|
|
}
|
|
|
|
}
|
2014-09-05 11:30:05 +02:00
|
|
|
|
2014-09-19 17:36:36 +02:00
|
|
|
@Override
|
2014-10-01 15:38:16 +02:00
|
|
|
public void onSuccess(
|
|
|
|
SamplingResultWithFileFromServlet samplingResult) {
|
2014-09-19 17:36:36 +02:00
|
|
|
rootLogger
|
|
|
|
.log(Level.SEVERE, "SUCCESS RPC randomSample");
|
|
|
|
|
2014-09-30 14:32:27 +02:00
|
|
|
if (samplingResult != null) {
|
2014-09-19 17:36:36 +02:00
|
|
|
// get data
|
2014-10-01 15:38:16 +02:00
|
|
|
List<Result> result = samplingResult
|
|
|
|
.getListOutput();
|
2014-09-19 17:36:36 +02:00
|
|
|
// get the attributes list for the result
|
|
|
|
// table
|
|
|
|
List<String> listAttributes = new ArrayList<String>();
|
|
|
|
listAttributes = getListAttributes(result.get(0)
|
|
|
|
.getValue());
|
|
|
|
// remove the header in order to parse only
|
|
|
|
// the result
|
|
|
|
result.remove(0);
|
|
|
|
rootLogger.log(Level.SEVERE, "output size: "
|
|
|
|
+ result.size());
|
|
|
|
// get path
|
2014-09-30 14:32:27 +02:00
|
|
|
String fileName = samplingResult.getFileName();
|
2014-09-19 17:36:36 +02:00
|
|
|
// parse the result in order to obtain a
|
|
|
|
// table
|
|
|
|
parseResult(result, listAttributes, fileName);
|
2014-10-01 15:38:16 +02:00
|
|
|
} else {
|
|
|
|
MessageBox.alert("Error ", "<br/>Message: "
|
|
|
|
+ "no data available", null);
|
|
|
|
|
2014-09-30 14:32:27 +02:00
|
|
|
if (obj.isMasked()) {
|
|
|
|
obj.unmask();
|
|
|
|
}
|
2014-10-01 15:38:16 +02:00
|
|
|
|
2014-09-19 17:36:36 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2014-07-03 14:44:03 +02:00
|
|
|
}
|
|
|
|
|
2014-07-02 12:57:14 +02:00
|
|
|
// start the parsing of the submit result in order to obtain a table
|
2014-08-29 15:39:04 +02:00
|
|
|
private void parseResult(List<Result> result,
|
2014-09-19 17:36:36 +02:00
|
|
|
final List<String> listAttributes, final String fileName) {
|
2014-07-04 12:09:47 +02:00
|
|
|
// to unmask the entire content panel
|
|
|
|
final GxtBorderLayoutPanel obj = this;
|
2014-08-29 15:39:04 +02:00
|
|
|
// final Dialog form = dialog;
|
2014-07-02 12:57:14 +02:00
|
|
|
|
|
|
|
RPCservice.parseCVSString(result, listAttributes,
|
|
|
|
new AsyncCallback<List<Row>>() {
|
|
|
|
@Override
|
|
|
|
public void onFailure(Throwable caught) {
|
2014-07-09 18:12:30 +02:00
|
|
|
// Window.alert(caught.getMessage());
|
2014-07-30 11:13:17 +02:00
|
|
|
rootLogger.log(Level.SEVERE, "FAILURE RPC parseResult");
|
2014-10-01 15:38:16 +02:00
|
|
|
|
|
|
|
if (caught instanceof SessionExpiredException) {
|
2014-09-29 15:13:02 +02:00
|
|
|
rootLogger.log(Level.INFO, "Session expired");
|
|
|
|
CheckSession.showLogoutDialog();
|
|
|
|
return;
|
2014-10-01 15:38:16 +02:00
|
|
|
}
|
|
|
|
|
2014-07-09 18:12:30 +02:00
|
|
|
MessageBox.alert("Error ",
|
|
|
|
"<br/>Message:" + caught.getMessage(), null);
|
2014-07-03 14:44:03 +02:00
|
|
|
|
2014-07-18 17:34:26 +02:00
|
|
|
// 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.
|
2014-08-29 15:39:04 +02:00
|
|
|
if (obj.isMasked()) {
|
|
|
|
obj.unmask();
|
2014-07-04 11:07:19 +02:00
|
|
|
}
|
2014-08-29 15:39:04 +02:00
|
|
|
// if (submitQueryEventManaged == true) {
|
|
|
|
//
|
|
|
|
// if (form.getBody().isMasked())
|
|
|
|
// form.getBody().unmask();
|
|
|
|
// } else {
|
|
|
|
// if (obj.isMasked()) {
|
|
|
|
// obj.unmask();
|
|
|
|
// }
|
|
|
|
// }
|
2014-07-09 18:12:30 +02:00
|
|
|
}
|
2014-09-05 11:30:05 +02:00
|
|
|
|
2014-07-09 18:12:30 +02:00
|
|
|
@Override
|
|
|
|
public void onSuccess(List<Row> rows) {
|
|
|
|
rootLogger.log(Level.SEVERE, "SUCCESS RPC parseResult");
|
|
|
|
|
2014-07-04 11:07:19 +02:00
|
|
|
if (rows != null) {
|
|
|
|
// Display the submit query result as a table
|
2014-08-29 15:39:04 +02:00
|
|
|
Dialog sampleResult = new Dialog() {
|
2014-09-19 17:36:36 +02:00
|
|
|
|
2014-07-30 11:13:17 +02:00
|
|
|
// override the maximize event modifying it with
|
|
|
|
// a different behaviour if the mimimize event
|
|
|
|
// occurs
|
|
|
|
public void maximize() {
|
|
|
|
if (isCollapsed()) {
|
|
|
|
expand();
|
|
|
|
} else {
|
|
|
|
super.maximize();
|
|
|
|
}
|
|
|
|
}
|
2014-09-19 17:36:36 +02:00
|
|
|
|
2014-07-30 11:13:17 +02:00
|
|
|
};
|
|
|
|
|
2014-08-29 15:39:04 +02:00
|
|
|
// if (submitQueryEventManaged == true) {
|
|
|
|
// submitResult.setHeading("Result Query "
|
|
|
|
// + dialogID);
|
|
|
|
// } else {
|
|
|
|
// submitResult.setHeading("Result");
|
|
|
|
// }
|
2014-07-30 11:13:17 +02:00
|
|
|
|
2014-08-29 15:39:04 +02:00
|
|
|
sampleResult.setLayout(new FitLayout());
|
|
|
|
sampleResult.setHeading("Result");
|
|
|
|
sampleResult.setResizable(false);
|
2014-07-04 11:07:19 +02:00
|
|
|
// submitResult.setHeading("Submit Query");
|
|
|
|
// submitResult.setWidth(290);
|
|
|
|
// submitResult.setHeight(250);
|
2014-07-30 11:13:17 +02:00
|
|
|
// submitResult.setModal(true);
|
|
|
|
// submitResult.setBlinkModal(true);
|
2014-07-04 11:07:19 +02:00
|
|
|
// submitResult.setBodyStyle("padding:9px;");
|
2014-08-29 15:39:04 +02:00
|
|
|
sampleResult.setSize(600, 400);
|
2014-07-04 11:07:19 +02:00
|
|
|
// submitResult.setScrollMode(Scroll.AUTO);
|
2014-08-29 15:39:04 +02:00
|
|
|
sampleResult.setScrollMode(Scroll.NONE);
|
|
|
|
sampleResult.setHideOnButtonClick(true);
|
|
|
|
sampleResult.setMaximizable(true);
|
|
|
|
sampleResult.setMinimizable(true);
|
2014-07-04 11:07:19 +02:00
|
|
|
// submitResult.addText("Result Table");
|
2014-07-02 12:57:14 +02:00
|
|
|
|
2014-07-04 11:07:19 +02:00
|
|
|
ListStore<Row> store = new ListStore<Row>();
|
|
|
|
store.add(rows);
|
2014-07-02 12:57:14 +02:00
|
|
|
|
2014-07-04 11:07:19 +02:00
|
|
|
Grid<Row> grid;
|
2014-08-29 15:39:04 +02:00
|
|
|
grid = new Grid<Row>(store,
|
|
|
|
createColumnModel(listAttributes));
|
2014-07-02 12:57:14 +02:00
|
|
|
|
2014-07-04 11:07:19 +02:00
|
|
|
// grid.setAutoExpandColumn("value");
|
|
|
|
grid.setBorders(true);
|
|
|
|
// grid.setAutoWidth(true);
|
|
|
|
RowData data = new RowData(.5, 1);
|
|
|
|
data.setMargins(new Margins(6));
|
2014-07-03 14:44:03 +02:00
|
|
|
|
2014-07-30 11:13:17 +02:00
|
|
|
// mimimize event handled
|
2014-08-29 15:39:04 +02:00
|
|
|
sampleResult.addListener(Events.Minimize,
|
2014-07-30 11:13:17 +02:00
|
|
|
new Listener<WindowEvent>() {
|
|
|
|
@Override
|
|
|
|
public void handleEvent(WindowEvent be) {
|
2014-07-30 16:41:11 +02:00
|
|
|
// collapse the dialog
|
2014-07-30 11:13:17 +02:00
|
|
|
be.getWindow().collapse();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
// maximize event handled
|
2014-08-29 15:39:04 +02:00
|
|
|
sampleResult.addListener(Events.Maximize,
|
2014-07-30 11:13:17 +02:00
|
|
|
new Listener<WindowEvent>() {
|
|
|
|
@Override
|
|
|
|
public void handleEvent(WindowEvent be) {
|
|
|
|
// expand the dialog
|
|
|
|
if (be.getWindow().isCollapsed()) {
|
|
|
|
be.getWindow().expand();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2014-07-04 11:07:19 +02:00
|
|
|
|
2014-09-19 17:36:36 +02:00
|
|
|
// add the button to download the result
|
|
|
|
final String urlFile = Window.Location
|
|
|
|
.getProtocol()
|
|
|
|
+ "//"
|
|
|
|
+ Window.Location.getHost() + fileName;
|
|
|
|
|
|
|
|
Button download = new Button("Download",
|
|
|
|
new SelectionListener<ButtonEvent>() {
|
|
|
|
@Override
|
|
|
|
public void componentSelected(
|
|
|
|
ButtonEvent ce) {
|
|
|
|
Window.open(urlFile, "Result File",
|
|
|
|
"_blank");
|
|
|
|
}
|
|
|
|
});
|
|
|
|
sampleResult.addButton(download);
|
2014-08-29 15:39:04 +02:00
|
|
|
sampleResult.add(grid, data);
|
|
|
|
sampleResult.show();
|
2014-07-04 11:07:19 +02:00
|
|
|
|
2014-07-18 17:34:26 +02:00
|
|
|
// 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.
|
2014-07-09 18:12:30 +02:00
|
|
|
|
2014-08-29 15:39:04 +02:00
|
|
|
// if (submitQueryEventManaged == true) {
|
|
|
|
// if (form.getBody().isMasked())
|
|
|
|
// form.getBody().unmask();
|
|
|
|
// } else {
|
|
|
|
// if (obj.isMasked()) {
|
|
|
|
// obj.unmask();
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
|
|
|
|
if (obj.isMasked()) {
|
|
|
|
obj.unmask();
|
2014-07-09 18:12:30 +02:00
|
|
|
}
|
|
|
|
} else {
|
2014-08-29 15:39:04 +02:00
|
|
|
// if (submitQueryEventManaged == true) {
|
|
|
|
// if (form.getBody().isMasked())
|
|
|
|
// form.getBody().unmask();
|
|
|
|
// } else {
|
|
|
|
// if (obj.isMasked()) {
|
|
|
|
// obj.unmask();
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
|
|
|
|
if (obj.isMasked()) {
|
|
|
|
obj.unmask();
|
2014-07-09 18:12:30 +02:00
|
|
|
}
|
2014-07-04 12:09:47 +02:00
|
|
|
}
|
2014-07-02 12:57:14 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2014-07-18 17:34:26 +02:00
|
|
|
// get attributes list for display the result in a table
|
2014-08-29 15:39:04 +02:00
|
|
|
private List<String> getListAttributes(String value) {
|
|
|
|
List<String> listAttributes = new ArrayList<String>();
|
2014-07-18 17:34:26 +02:00
|
|
|
// recover attribute fields for the result table
|
2014-07-02 12:57:14 +02:00
|
|
|
String headers = value;
|
2014-08-29 15:39:04 +02:00
|
|
|
// rootLogger.log(Level.INFO, "Headers fields table: " + headers);
|
2014-07-02 12:57:14 +02:00
|
|
|
listAttributes = parseAttributesTableResult(headers);
|
2014-07-03 14:44:03 +02:00
|
|
|
rootLogger.log(Level.INFO,
|
|
|
|
"attributes number: " + listAttributes.size());
|
2014-07-02 12:57:14 +02:00
|
|
|
|
2014-08-29 15:39:04 +02:00
|
|
|
// rootLogger.log(Level.INFO, "attributes list: ");
|
|
|
|
// print check
|
|
|
|
// for (int i = 0; i < listAttributes.size(); i++) {
|
|
|
|
// rootLogger.log(Level.INFO, "attribute: " + listAttributes.get(i));
|
|
|
|
// }
|
|
|
|
return listAttributes;
|
2014-07-02 12:57:14 +02:00
|
|
|
}
|
|
|
|
|
2014-07-18 17:34:26 +02:00
|
|
|
// create column configuration for the grid
|
2014-08-29 15:39:04 +02:00
|
|
|
private ColumnModel createColumnModel(List<String> listAttributes) {
|
2014-07-02 12:57:14 +02:00
|
|
|
List<ColumnConfig> configs = new ArrayList<ColumnConfig>();
|
|
|
|
ColumnConfig column;
|
|
|
|
column = new ColumnConfig();
|
2014-07-30 11:13:17 +02:00
|
|
|
// column.setId("index");
|
|
|
|
// column.setHeader("Index");
|
|
|
|
// column.setWidth(100);
|
|
|
|
// column.setSortable(false);
|
|
|
|
// configs.add(column);
|
2014-07-02 12:57:14 +02:00
|
|
|
|
|
|
|
for (int i = 0; i < listAttributes.size(); i++) {
|
2014-08-29 15:39:04 +02:00
|
|
|
// rootLogger.log(Level.INFO, "attribute: " +
|
|
|
|
// listAttributes.get(i));
|
2014-07-02 12:57:14 +02:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2014-07-18 17:34:26 +02:00
|
|
|
// create column configuration for the grid
|
2014-07-02 12:57:14 +02:00
|
|
|
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);
|
2014-07-30 16:41:11 +02:00
|
|
|
// column.setSortable(false);
|
2014-07-04 11:24:13 +02:00
|
|
|
|
|
|
|
TextField<String> textProperty = new TextField<String>();
|
|
|
|
// text.setAllowBlank(false);
|
2014-07-04 11:07:19 +02:00
|
|
|
column.setEditor(new CellEditor(textProperty));
|
2014-07-02 12:57:14 +02:00
|
|
|
configs.add(column);
|
|
|
|
|
|
|
|
column = new ColumnConfig();
|
|
|
|
column.setId("value");
|
|
|
|
column.setHeader("Value");
|
|
|
|
column.setWidth(600);
|
2014-07-30 16:41:11 +02:00
|
|
|
// column.setSortable(false);
|
2014-07-04 11:24:13 +02:00
|
|
|
|
|
|
|
TextField<String> textValue = new TextField<String>();
|
|
|
|
// text.setAllowBlank(false);
|
2014-07-04 11:07:19 +02:00
|
|
|
column.setEditor(new CellEditor(textValue));
|
2014-07-02 12:57:14 +02:00
|
|
|
configs.add(column);
|
|
|
|
|
|
|
|
ListStore<Result> store = new ListStore<Result>();
|
|
|
|
store.add(result);
|
|
|
|
return new ColumnModel(configs);
|
|
|
|
}
|
|
|
|
|
2014-07-18 17:34:26 +02:00
|
|
|
// create column configuration for the grid
|
2014-07-11 12:35:26 +02:00
|
|
|
private ColumnModel createColumnModelForTables() {
|
|
|
|
List<ColumnConfig> configs = new ArrayList<ColumnConfig>();
|
|
|
|
ColumnConfig column = new ColumnConfig();
|
2014-07-14 10:06:55 +02:00
|
|
|
// column.setId("index");
|
|
|
|
// column.setHeader("Index");
|
|
|
|
// column.setWidth(100);
|
|
|
|
// configs.add(column);
|
2014-07-11 12:35:26 +02:00
|
|
|
|
|
|
|
column = new ColumnConfig();
|
|
|
|
column.setId("value");
|
|
|
|
column.setHeader("Name");
|
|
|
|
column.setWidth(600);
|
2014-07-30 16:41:11 +02:00
|
|
|
// column.setSortable(false);
|
2014-07-11 12:35:26 +02:00
|
|
|
|
2014-07-14 14:20:18 +02:00
|
|
|
TextField<String> textValue = new TextField<String>();
|
|
|
|
// text.setAllowBlank(false);
|
|
|
|
column.setEditor(new CellEditor(textValue));
|
2014-07-11 12:35:26 +02:00
|
|
|
configs.add(column);
|
|
|
|
// ListStore<Result> store = new ListStore<Result>();
|
|
|
|
// store.add(result);
|
|
|
|
return new ColumnModel(configs);
|
|
|
|
}
|
|
|
|
|
2014-07-02 12:57:14 +02:00
|
|
|
private void displayDBInfo(FileModel element) {
|
|
|
|
rootLogger.log(Level.INFO, "displaying info");
|
|
|
|
List<Result> dataDB = element.getDBInfo();
|
|
|
|
|
2014-07-11 12:35:26 +02:00
|
|
|
if (dataDB != null) {
|
|
|
|
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);
|
2014-07-09 18:34:40 +02:00
|
|
|
}
|
2014-07-02 12:57:14 +02:00
|
|
|
}
|
|
|
|
|
2014-07-18 17:34:26 +02:00
|
|
|
// method to get the table details
|
2014-07-14 10:06:55 +02:00
|
|
|
private void getTableDetails(final FileModel Table) {
|
2014-07-09 14:11:19 +02:00
|
|
|
// to unmask the entire content panel
|
|
|
|
final GxtBorderLayoutPanel obj = this;
|
2014-07-04 11:07:19 +02:00
|
|
|
rootLogger.log(Level.SEVERE, "Start RPC - getTableDetails");
|
|
|
|
|
2014-07-14 10:06:55 +02:00
|
|
|
// get the selected table
|
|
|
|
List<FileModel> data = treePanel.getTreePanel().getSelectionModel()
|
|
|
|
.getSelectedItems();
|
|
|
|
// the selected item
|
|
|
|
FileModel selectedItem = data.get(0);
|
2014-07-18 17:34:26 +02:00
|
|
|
// recover data inputs fo the algorithm
|
2014-07-14 14:20:18 +02:00
|
|
|
final LinkedHashMap<String, String> dataInput = new LinkedHashMap<String, String>();
|
2014-07-04 11:07:19 +02:00
|
|
|
// check if the table has an associated schema
|
|
|
|
FileModel schema;
|
|
|
|
FileModel database;
|
|
|
|
FileModel resource;
|
|
|
|
|
2014-07-14 10:06:55 +02:00
|
|
|
if (selectedItem.isDatabase()) {
|
|
|
|
// the table has not a schema
|
|
|
|
database = selectedItem;
|
2014-07-04 11:07:19 +02:00
|
|
|
resource = treePanel.getTreeStore().getParent(database);
|
|
|
|
|
|
|
|
dataInput.put("ResourceName", resource.getName());
|
|
|
|
dataInput.put("DatabaseName", database.getName());
|
2014-07-09 14:11:19 +02:00
|
|
|
dataInput.put("SchemaName", "");
|
2014-09-22 10:14:48 +02:00
|
|
|
dataInput.put("TableName", currentselectedTable);
|
2014-07-04 11:07:19 +02:00
|
|
|
|
|
|
|
rootLogger.log(Level.INFO, "ResourceName: " + resource.getName());
|
|
|
|
rootLogger.log(Level.INFO, "DatabaseName: " + database.getName());
|
2014-07-09 14:11:19 +02:00
|
|
|
rootLogger.log(Level.INFO, "SchemaName: " + "");
|
2014-09-22 10:14:48 +02:00
|
|
|
rootLogger.log(Level.INFO, "TableName: " + currentselectedTable);
|
2014-07-04 11:07:19 +02:00
|
|
|
} else {
|
2014-07-09 14:11:19 +02:00
|
|
|
// the table has a schema
|
2014-07-14 10:06:55 +02:00
|
|
|
schema = selectedItem;
|
2014-07-09 14:11:19 +02:00
|
|
|
database = treePanel.getTreeStore().getParent(schema);
|
2014-07-04 11:07:19 +02:00
|
|
|
resource = treePanel.getTreeStore().getParent(database);
|
|
|
|
|
|
|
|
dataInput.put("ResourceName", resource.getName());
|
|
|
|
dataInput.put("DatabaseName", database.getName());
|
2014-07-09 14:11:19 +02:00
|
|
|
dataInput.put("SchemaName", schema.getName());
|
2014-09-22 10:14:48 +02:00
|
|
|
dataInput.put("TableName", currentselectedTable);
|
2014-07-04 11:07:19 +02:00
|
|
|
|
|
|
|
rootLogger.log(Level.INFO, "ResourceName: " + resource.getName());
|
|
|
|
rootLogger.log(Level.INFO, "DatabaseName: " + database.getName());
|
2014-07-09 14:11:19 +02:00
|
|
|
rootLogger.log(Level.INFO, "SchemaName: " + schema.getName());
|
2014-09-22 10:14:48 +02:00
|
|
|
rootLogger.log(Level.INFO, "TableName: " + currentselectedTable);
|
2014-07-04 11:07:19 +02:00
|
|
|
}
|
|
|
|
|
2014-07-18 17:34:26 +02:00
|
|
|
// details for the table are displayed if they have not been displayed
|
|
|
|
// yet
|
2014-07-14 10:06:55 +02:00
|
|
|
if (Table.isTableDetailsDisplayed()) {
|
|
|
|
displayTableDetails(Table);
|
2014-07-15 18:43:38 +02:00
|
|
|
} else {
|
|
|
|
// to mask the entire content panel
|
|
|
|
obj.mask("Loading details", "x-mask-loading");
|
2014-07-04 11:07:19 +02:00
|
|
|
|
2014-07-15 18:43:38 +02:00
|
|
|
// call remote service
|
|
|
|
RPCservice.getTableDetails(dataInput,
|
|
|
|
new AsyncCallback<LinkedHashMap<String, FileModel>>() {
|
|
|
|
@Override
|
|
|
|
public void onFailure(Throwable caught) {
|
|
|
|
rootLogger.log(Level.SEVERE,
|
|
|
|
"FAILURE RPC getTableDetails");
|
2014-10-01 15:38:16 +02:00
|
|
|
|
|
|
|
if (caught instanceof SessionExpiredException) {
|
2014-09-29 15:13:02 +02:00
|
|
|
rootLogger.log(Level.INFO, "Session expired");
|
|
|
|
CheckSession.showLogoutDialog();
|
|
|
|
return;
|
|
|
|
}
|
2014-10-01 15:38:16 +02:00
|
|
|
|
2014-07-15 18:43:38 +02:00
|
|
|
MessageBox.alert("Error ",
|
|
|
|
"<br/>Message:" + caught.getMessage(), null);
|
2014-07-04 11:07:19 +02:00
|
|
|
|
2014-07-15 18:43:38 +02:00
|
|
|
if (obj.isMasked()) {
|
|
|
|
obj.unmask();
|
|
|
|
}
|
|
|
|
}
|
2014-07-04 11:07:19 +02:00
|
|
|
|
2014-07-15 18:43:38 +02:00
|
|
|
@Override
|
|
|
|
public void onSuccess(
|
|
|
|
LinkedHashMap<String, FileModel> result) {
|
|
|
|
rootLogger.log(Level.SEVERE,
|
|
|
|
"SUCCESS RPC getTableDetails");
|
2014-07-04 11:07:19 +02:00
|
|
|
|
2014-07-15 18:43:38 +02:00
|
|
|
// 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();
|
2014-07-04 11:07:19 +02:00
|
|
|
|
2014-07-15 18:43:38 +02:00
|
|
|
// recover details
|
|
|
|
List<Result> TableDetails = new ArrayList<Result>();
|
2014-07-04 11:07:19 +02:00
|
|
|
|
2014-07-15 18:43:38 +02:00
|
|
|
for (int i = 0; i < result.size(); i++) {
|
|
|
|
if (array[i].toString().contains(
|
|
|
|
"CreateTable")) {
|
|
|
|
// recover the
|
|
|
|
// showCreateTable
|
|
|
|
// statement
|
2014-07-30 11:13:17 +02:00
|
|
|
Result row = new Result(
|
|
|
|
"Create statement", result.get(
|
|
|
|
array[i].toString())
|
2014-07-15 18:43:38 +02:00
|
|
|
.getName());
|
|
|
|
TableDetails.add(row);
|
|
|
|
}
|
2014-07-04 11:07:19 +02:00
|
|
|
|
2014-07-15 18:43:38 +02:00
|
|
|
if (array[i].toString().contains(
|
|
|
|
"Column Names")) {
|
|
|
|
// recover the
|
|
|
|
// column names
|
2014-07-23 14:17:10 +02:00
|
|
|
Result row = new Result("Column names",
|
2014-07-15 18:43:38 +02:00
|
|
|
result.get(array[i].toString())
|
|
|
|
.getName());
|
|
|
|
TableDetails.add(row);
|
|
|
|
}
|
2014-07-04 11:07:19 +02:00
|
|
|
|
2014-07-15 18:43:38 +02:00
|
|
|
if (array[i].toString().contains(
|
|
|
|
"NumberRows")) {
|
|
|
|
// recover the
|
|
|
|
// column names
|
2014-07-30 11:13:17 +02:00
|
|
|
Result row = new Result(
|
|
|
|
"Number of rows", result.get(
|
|
|
|
array[i].toString())
|
2014-07-15 18:43:38 +02:00
|
|
|
.getName());
|
|
|
|
TableDetails.add(row);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Table.setTableDetails(TableDetails);
|
|
|
|
displayTableDetails(Table);
|
|
|
|
Table.setTableDetailsDisplayed(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2014-07-04 11:24:13 +02:00
|
|
|
}
|
2014-07-04 11:07:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
private void displayTableDetails(FileModel table) {
|
|
|
|
rootLogger.log(Level.INFO, "displaying table details");
|
|
|
|
|
|
|
|
List<Result> tableDetails = table.getTableDetails();
|
|
|
|
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));
|
2014-07-04 11:24:13 +02:00
|
|
|
// grid.setAutoExpandColumn("name");
|
2014-07-04 11:07:19 +02:00
|
|
|
grid.setBorders(true);
|
|
|
|
// grid.setAutoWidth(true);
|
2014-07-04 11:24:13 +02:00
|
|
|
// RowData data = new RowData(.5, .1);
|
|
|
|
// data.setMargins(new Margins(6));
|
2014-07-04 11:07:19 +02:00
|
|
|
centerBottom.removeAll();
|
2014-07-04 11:24:13 +02:00
|
|
|
// centerBottom.add(grid, data);
|
2014-07-04 11:07:19 +02:00
|
|
|
centerBottom.add(grid);
|
|
|
|
centerBottom.layout(true);
|
2014-07-04 11:24:13 +02:00
|
|
|
|
2014-07-04 12:09:47 +02:00
|
|
|
// to unmask the entire content panel
|
2014-07-04 11:07:19 +02:00
|
|
|
if (this.isMasked()) {
|
|
|
|
this.unmask();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-07-15 18:43:38 +02:00
|
|
|
private void displayTableName(String tableName) {
|
2014-08-29 15:39:04 +02:00
|
|
|
rootLogger.log(Level.INFO, "displaying table name " + tableName
|
2014-07-15 18:43:38 +02:00
|
|
|
+ " in the panel");
|
2014-09-15 15:59:05 +02:00
|
|
|
final Result table = new Result("Selected table", tableName);
|
|
|
|
final ListStore<Result> store = new ListStore<Result>();
|
|
|
|
store.add(table);
|
2014-09-19 17:36:36 +02:00
|
|
|
|
2014-07-15 18:43:38 +02:00
|
|
|
// create column configuration
|
|
|
|
List<ColumnConfig> configs = new ArrayList<ColumnConfig>();
|
|
|
|
ColumnConfig column = new ColumnConfig();
|
|
|
|
column.setId("index");
|
|
|
|
column.setHeader("Description");
|
2014-07-17 14:37:55 +02:00
|
|
|
column.setWidth(100);
|
2014-07-15 18:43:38 +02:00
|
|
|
configs.add(column);
|
|
|
|
|
|
|
|
column = new ColumnConfig();
|
|
|
|
column.setId("value");
|
|
|
|
column.setHeader("Value");
|
|
|
|
column.setWidth(600);
|
|
|
|
|
|
|
|
TextField<String> textValue = new TextField<String>();
|
|
|
|
// text.setAllowBlank(false);
|
2014-09-19 17:36:36 +02:00
|
|
|
// column.setEditor(new CellEditor(textValue));
|
|
|
|
column.setEditor(new CellEditor(textValue) {
|
|
|
|
// public Object preProcessValue(Object value) {
|
2014-09-24 11:02:22 +02:00
|
|
|
// System.out.println("value preProcess: " +
|
2014-09-19 17:36:36 +02:00
|
|
|
// store.getModels().get(0).getValue());
|
|
|
|
// return store.getModels().get(0).getValue();
|
|
|
|
// }
|
2014-09-15 15:59:05 +02:00
|
|
|
public Object postProcessValue(Object value) {
|
2014-09-24 11:02:22 +02:00
|
|
|
// System.out.println("value postProcess: " +
|
2014-09-19 17:36:36 +02:00
|
|
|
// store.findModel(table).getValue());
|
|
|
|
return store.findModel(table).getValue();
|
2014-09-15 15:59:05 +02:00
|
|
|
}
|
2014-09-19 17:36:36 +02:00
|
|
|
|
2014-09-15 15:59:05 +02:00
|
|
|
});
|
2014-09-19 17:36:36 +02:00
|
|
|
|
2014-07-15 18:43:38 +02:00
|
|
|
configs.add(column);
|
|
|
|
ColumnModel cm = new ColumnModel(configs);
|
2014-07-16 16:18:09 +02:00
|
|
|
|
|
|
|
// grid
|
|
|
|
EditorGrid<Result> grid = new EditorGrid<Result>(store, cm);
|
|
|
|
// display information in the panel
|
2014-07-15 18:43:38 +02:00
|
|
|
centerUpper.removeAll();
|
|
|
|
centerUpper.add(grid);
|
|
|
|
centerUpper.layout(true);
|
|
|
|
}
|
2014-07-02 12:57:14 +02:00
|
|
|
}
|