Added delete option for tabular resource without table

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/user/tabular-data-open-widget@93992 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Giancarlo Panichi 2014-04-01 14:21:02 +00:00 committed by Giancarlo Panichi
parent 12a91b9740
commit 26084460f9
2 changed files with 91 additions and 36 deletions

View File

@ -4,9 +4,9 @@
package org.gcube.portlets.user.td.openwidget.client;
import org.gcube.portlets.user.td.gwtservice.client.rpc.TDGWTServiceAsync;
import org.gcube.portlets.user.td.gwtservice.shared.tr.open.TDOpenSession;
import org.gcube.portlets.user.td.gwtservice.shared.tr.TabResource;
import org.gcube.portlets.user.td.gwtservice.shared.tr.TableData;
import org.gcube.portlets.user.td.gwtservice.shared.tr.open.TDOpenSession;
import org.gcube.portlets.user.td.widgetcommonevent.shared.TRId;
import org.gcube.portlets.user.td.wizardwidget.client.WizardCard;
@ -15,7 +15,9 @@ import com.google.gwt.event.logical.shared.SelectionEvent;
import com.google.gwt.event.logical.shared.SelectionHandler;
import com.google.gwt.user.client.Command;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.sencha.gxt.widget.core.client.Dialog.PredefinedButton;
import com.sencha.gxt.widget.core.client.box.AlertMessageBox;
import com.sencha.gxt.widget.core.client.box.ConfirmMessageBox;
import com.sencha.gxt.widget.core.client.event.HideEvent;
import com.sencha.gxt.widget.core.client.event.HideEvent.HideHandler;
@ -28,7 +30,7 @@ import com.sencha.gxt.widget.core.client.event.HideEvent.HideHandler;
public class TabResourcesSelectionCard extends WizardCard {
protected final String GRIDWIDTH = "538px";
protected final String GRIDHEIGHT = "430px";
protected TabResourcesSelectionCard thisCard;
protected TDOpenSession tdOpenSession;
protected TabResourcesSelectionPanel tabResourcesSelectionPanel;
@ -42,13 +44,12 @@ public class TabResourcesSelectionCard extends WizardCard {
tabResourcesSelectionPanel = new TabResourcesSelectionPanel(res);
//tabResourcesSelectionPanel.setResize(false);
//tabResourcesSelectionPanel.setSize(GRIDWIDTH, GRIDHEIGHT);
// tabResourcesSelectionPanel.setResize(false);
// tabResourcesSelectionPanel.setSize(GRIDWIDTH, GRIDHEIGHT);
tabResourcesSelectionPanel
.addSelectionHandler(new SelectionHandler<TabResource>() {
public void onSelection(SelectionEvent<TabResource> event) {
tdOpenSession
.setSelectedTabResource(tabResourcesSelectionPanel
@ -73,19 +74,71 @@ public class TabResourcesSelectionCard extends WizardCard {
};
getWizardWindow().setNextButtonCommand(sayFinish);
//getWizardWindow().setFinishCommand(sayFinish);
// getWizardWindow().setFinishCommand(sayFinish);
}
protected void retrieveLastTable(){
protected void retrieveLastTable() {
TDGWTServiceAsync.INSTANCE.getLastTable(tdOpenSession
.getSelectedTabResource().getTrId(), new AsyncCallback<TableData>(){
.getSelectedTabResource().getTrId(),
new AsyncCallback<TableData>() {
@Override
public void onFailure(Throwable caught) {
Log.debug("Attention", "This tabular resource does not have a valid table");
AlertMessageBox d = new AlertMessageBox(
"Attention", "This tabular resource does not have a valid table"
Log.debug("Attention",
"This tabular resource does not have a valid table");
AlertMessageBox d = new AlertMessageBox("Attention",
"This tabular resource does not have a valid table");
d.addHideHandler(new HideHandler() {
public void onHide(HideEvent event) {
removeTRWithLastTableNull();
}
});
d.show();
}
@Override
public void onSuccess(TableData result) {
Log.debug("Retrieve last table: " + result);
updateTDOpenSessionInfo(result);
}
});
}
protected void removeTRWithLastTableNull() {
final ConfirmMessageBox mb = new ConfirmMessageBox("Remove",
"Would you like to remove this tabular resource without table?");
mb.addHideHandler(new HideHandler() {
public void onHide(HideEvent event) {
if (mb.getHideButton() == mb.getButtonById(PredefinedButton.YES
.name())) {
callRemoveLastTable();
} else if (mb.getHideButton() == mb
.getButtonById(PredefinedButton.NO.name())) {
// perform NO action
}
}
});
mb.setWidth(300);
mb.show();
}
protected void callRemoveLastTable(){
Log.debug("Remove TR:" + tdOpenSession
.getSelectedTabResource().getTrId());
TDGWTServiceAsync.INSTANCE.removeTabularResource(tdOpenSession
.getSelectedTabResource().getTrId(),
new AsyncCallback<Void>() {
public void onFailure(Throwable caught) {
AlertMessageBox d = new AlertMessageBox("Error",
"Error on remove TabResource: "
+ caught.getLocalizedMessage());
d.addHideHandler(new HideHandler() {
@ -98,35 +151,32 @@ public class TabResourcesSelectionCard extends WizardCard {
}
@Override
public void onSuccess(TableData result) {
Log.debug("Retrieve last table: "+result);
updateTDOpenSessionInfo(result);
public void onSuccess(Void result) {
tabResourcesSelectionPanel.gridReload();
}
});
});
}
protected void updateTDOpenSessionInfo(TableData table){
TabResource tabResource=tdOpenSession.getSelectedTabResource();
TRId trId=tabResource.getTrId();
protected void updateTDOpenSessionInfo(TableData table) {
TabResource tabResource = tdOpenSession.getSelectedTabResource();
TRId trId = tabResource.getTrId();
trId.setTableId(table.getTrId().getTableId());
trId.setTableType(table.getTrId().getTableType());
tabResource.setTrId(trId);
tdOpenSession.setSelectedTabResource(tabResource);
Log.debug("TdOpenSession: "+tdOpenSession);
Log.debug("TdOpenSession: " + tdOpenSession);
setTabularResource();
}
protected void setTabularResource(){
TDGWTServiceAsync.INSTANCE.setTabResource(tdOpenSession
.getSelectedTabResource(),
protected void setTabularResource() {
TDGWTServiceAsync.INSTANCE.setTabResource(
tdOpenSession.getSelectedTabResource(),
new AsyncCallback<Void>() {
public void onFailure(Throwable caught) {
AlertMessageBox d = new AlertMessageBox(
"Error", "Error on set TabResource: "
AlertMessageBox d = new AlertMessageBox("Error",
"Error on set TabResource: "
+ caught.getLocalizedMessage());
d.addHideHandler(new HideHandler() {
@ -141,16 +191,16 @@ public class TabResourcesSelectionCard extends WizardCard {
}
public void onSuccess(Void result) {
getWizardWindow().fireCompleted(tdOpenSession
.getSelectedTabResource().getTrId());
getWizardWindow().fireCompleted(
tdOpenSession.getSelectedTabResource()
.getTrId());
getWizardWindow().close(false);
Log.info("OpenTD Tabular Resource selected :" + tdOpenSession
.getSelectedTabResource());
Log.info("OpenTD Tabular Resource selected :"
+ tdOpenSession.getSelectedTabResource());
}
});
}
}

View File

@ -236,5 +236,10 @@ public class TabResourcesSelectionPanel extends ContentPanel implements HasSelec
}
public void gridReload(){
grid.getLoader().load();
}
}