added the query "select * table_name limit 10" in the dialog submitQuery

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/user/databases-manager-portlet@100017 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Loredana Liccardo 2014-09-18 12:10:36 +00:00
parent 1278e1d456
commit d9735e3f44
5 changed files with 140 additions and 20 deletions

View File

@ -1,5 +1,6 @@
package org.gcube.portlets.user.databasesmanager.client.events;
import org.gcube.portlets.user.databasesmanager.client.datamodel.FileModel;
import org.gcube.portlets.user.databasesmanager.client.events.interfaces.SelectedTableEventHandler;
import com.google.gwt.event.shared.GwtEvent;
@ -7,6 +8,14 @@ public class SelectedTableEvent extends GwtEvent<SelectedTableEventHandler> {
public static Type<SelectedTableEventHandler> TYPE = new Type<SelectedTableEventHandler>();
private FileModel tableInfo;
private String selectedTable;
public SelectedTableEvent(FileModel item, String table){
tableInfo = item;
selectedTable = table;
}
@Override
public Type<SelectedTableEventHandler> getAssociatedType() {
return TYPE;
@ -20,4 +29,11 @@ public class SelectedTableEvent extends GwtEvent<SelectedTableEventHandler> {
public EventsTypeEnum getKey() {
return EventsTypeEnum.SELECTED_TABLE_EVENT;
}
public FileModel getTableInfo(){
return tableInfo;
}
public String getSelectedTable(){
return selectedTable;
}
}

View File

@ -16,9 +16,24 @@ public class GxtFormSubmitQuery extends LayoutContainer {
// private VerticalPanel vp;
private FormPanel form;
private FormData formData;
// query for the field TextArea
private String inputQuery;
// GWT logger
private static Logger rootLogger = Logger.getLogger("GxtFormSubmitQuery");
public GxtFormSubmitQuery(String q) {
inputQuery = q;
this.setLayout(new FitLayout());
// this.setSize(600, 400);
formData = new FormData("-20");
// vp = new VerticalPanel();
// vp.setSpacing(10);
createLayout();
// add(vp);
}
public GxtFormSubmitQuery() {
this.setLayout(new FitLayout());
// this.setSize(600, 400);
@ -43,6 +58,9 @@ public class GxtFormSubmitQuery extends LayoutContainer {
query.setHeight(300);
query.setPreventScrollbars(false);
query.setFieldLabel("Query");
if (inputQuery != null) {
query.setValue(inputQuery);
}
// query.setHeight(50);
// query.setWidth(50);
// query.setAllowBlank(false);

View File

@ -698,8 +698,14 @@ public class GxtBorderLayoutPanel extends ContentPanel {
// display the table in the panel "Database Information"
displayTableName(selectedTable);
// to get the selected item in the tree panel
List<FileModel> data = treePanel.getTreePanel()
.getSelectionModel().getSelectedItems();
FileModel selectedItem = data.get(0);
// fire event
eventBus.fireEvent(new SelectedTableEvent());
eventBus.fireEvent(new SelectedTableEvent(selectedItem, selectedTable));
}
}
});

View File

@ -633,9 +633,14 @@ public class GxtTreePanel extends LayoutContainer {
if (DatabaseType
.equals(ConstantsPortlet.MYSQL)) {
child.setDatabaseType(ConstantsPortlet.MYSQL);
child.setIsExpanded(false);
treePanel.setExpanded(child, false);
}
if (DatabaseType
.equals(ConstantsPortlet.POSTGRES)){
child.setDatabaseType(ConstantsPortlet.POSTGRES);
}
children.add(child);
}
}

View File

@ -5,15 +5,18 @@ 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.SubmitQueryData;
import org.gcube.portlets.user.databasesmanager.client.events.LoadTablesEvent;
import org.gcube.portlets.user.databasesmanager.client.events.RandomSamplingEvent;
import org.gcube.portlets.user.databasesmanager.client.events.RefreshDataEvent;
import org.gcube.portlets.user.databasesmanager.client.events.SamplingEvent;
import org.gcube.portlets.user.databasesmanager.client.events.SelectedItemEvent;
import org.gcube.portlets.user.databasesmanager.client.events.SelectedTableEvent;
import org.gcube.portlets.user.databasesmanager.client.events.ShowCreateTableEvent;
import org.gcube.portlets.user.databasesmanager.client.events.SmartSamplingEvent;
import org.gcube.portlets.user.databasesmanager.client.events.SubmitQueryEvent;
import org.gcube.portlets.user.databasesmanager.client.events.interfaces.SelectedItemEventHandler;
import org.gcube.portlets.user.databasesmanager.client.events.interfaces.SelectedTableEventHandler;
import org.gcube.portlets.user.databasesmanager.client.form.GxtFormSubmitQuery;
import org.gcube.portlets.user.databasesmanager.client.utils.ConstantsPortlet;
@ -61,6 +64,13 @@ public class GxtToolbarFunctionality {
.getLogger("GxtToolbarFunctionality");
// RPC service
private GWTdbManagerServiceAsync RPCservice = null;
// selected table
private String selectedTable;
// databse information related to the selected table
private FileModel tableInfo;
// proposed query displayed in the submit query form
private String queryForSubmitOperation = "select * from %1$s limit 10";
private boolean isTableSelected = false;
// Constructor
// public GxtToolbarFunctionality(HandlerManager eBus) {
@ -140,8 +150,7 @@ public class GxtToolbarFunctionality {
btnRefresCachedData = new Button(ConstantsPortlet.REFRESHCACHEDDATA);
btnRefresCachedData.setScale(ButtonScale.SMALL);
btnRefresCachedData.setArrowAlign(ButtonArrowAlign.BOTTOM);
btnRefresCachedData
.setToolTip("refreshes data");
btnRefresCachedData.setToolTip("refreshes data");
toolBar.add(btnRefresCachedData);
// add(toolBar, new FlowData(10));
@ -172,8 +181,31 @@ public class GxtToolbarFunctionality {
btnSimpleSample.enable();
btnSmartSample.enable();
btnRandomSample.enable();
// get selected table name and related database
// information
String tableName = selectedTableEvent
.getSelectedTable();
FileModel tableInfo = selectedTableEvent.getTableInfo();
setInfoOnSelectedTable(tableName, tableInfo);
isTableSelected = true;
// rootLogger.info("table clicked: " + isTableSelected);
}
});
eventBus.addHandler(SelectedItemEvent.TYPE,
new SelectedItemEventHandler() {
@Override
public void onSelectedItem(
SelectedItemEvent selectedItemEvent) {
isTableSelected = false;
// rootLogger.info("item clicked: " + isTableSelected);
}
});
}
private void addSelectionListenersOnToolBar() {
@ -214,9 +246,19 @@ public class GxtToolbarFunctionality {
// dialog.setWidth(290);
// dialog.setHeight(250);
// form to submit a query
final GxtFormSubmitQuery form = new GxtFormSubmitQuery();
// create form to submit a query
final GxtFormSubmitQuery form;
// get query for submit operation
String query = null;
if (isTableSelected == true) {
query = getQueryForSubmitOperation();
}
if ((query != null) && (!query.equals(""))) {
form = new GxtFormSubmitQuery(query);
} else {
form = new GxtFormSubmitQuery();
}
dialog.add(form);
dialog.show();
@ -351,20 +393,19 @@ public class GxtToolbarFunctionality {
eventBus.fireEvent(new LoadTablesEvent());
}
});
btnRefresCachedData.addSelectionListener(new SelectionListener<ButtonEvent>(){
@Override
public void componentSelected(ButtonEvent ce) {
rootLogger
.log(Level.INFO,
"REFRESH BUTTON");
//fire event
eventBus.fireEvent(new RefreshDataEvent());
}
});
btnRefresCachedData
.addSelectionListener(new SelectionListener<ButtonEvent>() {
@Override
public void componentSelected(ButtonEvent ce) {
rootLogger.log(Level.INFO, "REFRESH BUTTON");
// fire event
eventBus.fireEvent(new RefreshDataEvent());
}
});
}
// buttons enable/disable operation depending from the item selected in the
@ -386,7 +427,7 @@ public class GxtToolbarFunctionality {
btnSimpleSample.disable();
btnSmartSample.disable();
btnRandomSample.disable();
break;
case 2:
@ -398,7 +439,7 @@ public class GxtToolbarFunctionality {
btnSimpleSample.disable();
btnSmartSample.disable();
btnRandomSample.disable();
break;
case 3:
@ -525,6 +566,40 @@ public class GxtToolbarFunctionality {
return uidSubmitQueryList;
}
private void setInfoOnSelectedTable(String table, FileModel info) {
selectedTable = table;
tableInfo = info;
}
private String getQueryForSubmitOperation() {
String query = "";
if (tableInfo.isDatabase()) {
if (tableInfo.getDatabaseType().equals(ConstantsPortlet.MYSQL)) {
String dbName = tableInfo.getDatabaseName();
// the full name equal to "dbname.tablename"
String tableName = dbName + "." + selectedTable;
// query = String.format(queryForSubmitOperation, tableName);
query = "select * from " + tableName + " limit 10";
// System.out.println("query mysql: " + query);
}
}
if (tableInfo.isSchema()) { // database postgres
String schemaName = tableInfo.getName();
// the full name equal to "schemaname.tablename"
String tableName = schemaName + "." + "\"" + selectedTable + "\"";
// query = String.format(queryForSubmitOperation, tableName);
query = "select * from " + tableName + " limit 10";
// System.out.println("query postgres: " + query);
}
return query;
}
// public Integer getDialogID() {
// return new Integer(ID);
// }