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; 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.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.TabResource;
import org.gcube.portlets.user.td.gwtservice.shared.tr.TableData; 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.widgetcommonevent.shared.TRId;
import org.gcube.portlets.user.td.wizardwidget.client.WizardCard; 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.event.logical.shared.SelectionHandler;
import com.google.gwt.user.client.Command; import com.google.gwt.user.client.Command;
import com.google.gwt.user.client.rpc.AsyncCallback; 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.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;
import com.sencha.gxt.widget.core.client.event.HideEvent.HideHandler; 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 { public class TabResourcesSelectionCard extends WizardCard {
protected final String GRIDWIDTH = "538px"; protected final String GRIDWIDTH = "538px";
protected final String GRIDHEIGHT = "430px"; protected final String GRIDHEIGHT = "430px";
protected TabResourcesSelectionCard thisCard; protected TabResourcesSelectionCard thisCard;
protected TDOpenSession tdOpenSession; protected TDOpenSession tdOpenSession;
protected TabResourcesSelectionPanel tabResourcesSelectionPanel; protected TabResourcesSelectionPanel tabResourcesSelectionPanel;
@ -42,13 +44,12 @@ public class TabResourcesSelectionCard extends WizardCard {
tabResourcesSelectionPanel = new TabResourcesSelectionPanel(res); tabResourcesSelectionPanel = new TabResourcesSelectionPanel(res);
//tabResourcesSelectionPanel.setResize(false); // tabResourcesSelectionPanel.setResize(false);
//tabResourcesSelectionPanel.setSize(GRIDWIDTH, GRIDHEIGHT); // tabResourcesSelectionPanel.setSize(GRIDWIDTH, GRIDHEIGHT);
tabResourcesSelectionPanel tabResourcesSelectionPanel
.addSelectionHandler(new SelectionHandler<TabResource>() { .addSelectionHandler(new SelectionHandler<TabResource>() {
public void onSelection(SelectionEvent<TabResource> event) { public void onSelection(SelectionEvent<TabResource> event) {
tdOpenSession tdOpenSession
.setSelectedTabResource(tabResourcesSelectionPanel .setSelectedTabResource(tabResourcesSelectionPanel
@ -73,19 +74,71 @@ public class TabResourcesSelectionCard extends WizardCard {
}; };
getWizardWindow().setNextButtonCommand(sayFinish); getWizardWindow().setNextButtonCommand(sayFinish);
//getWizardWindow().setFinishCommand(sayFinish); // getWizardWindow().setFinishCommand(sayFinish);
} }
protected void retrieveLastTable(){ protected void retrieveLastTable() {
TDGWTServiceAsync.INSTANCE.getLastTable(tdOpenSession TDGWTServiceAsync.INSTANCE.getLastTable(tdOpenSession
.getSelectedTabResource().getTrId(), new AsyncCallback<TableData>(){ .getSelectedTabResource().getTrId(),
new AsyncCallback<TableData>() {
@Override @Override
public void onFailure(Throwable caught) { public void onFailure(Throwable caught) {
Log.debug("Attention", "This tabular resource does not have a valid table"); Log.debug("Attention",
AlertMessageBox d = new AlertMessageBox( "This tabular resource does not have a valid table");
"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()); + caught.getLocalizedMessage());
d.addHideHandler(new HideHandler() { d.addHideHandler(new HideHandler() {
@ -98,35 +151,32 @@ public class TabResourcesSelectionCard extends WizardCard {
} }
@Override public void onSuccess(Void result) {
public void onSuccess(TableData result) { tabResourcesSelectionPanel.gridReload();
Log.debug("Retrieve last table: "+result);
updateTDOpenSessionInfo(result);
} }
});
});
} }
protected void updateTDOpenSessionInfo(TableData table){
TabResource tabResource=tdOpenSession.getSelectedTabResource(); protected void updateTDOpenSessionInfo(TableData table) {
TRId trId=tabResource.getTrId(); TabResource tabResource = tdOpenSession.getSelectedTabResource();
TRId trId = tabResource.getTrId();
trId.setTableId(table.getTrId().getTableId()); trId.setTableId(table.getTrId().getTableId());
trId.setTableType(table.getTrId().getTableType()); trId.setTableType(table.getTrId().getTableType());
tabResource.setTrId(trId); tabResource.setTrId(trId);
tdOpenSession.setSelectedTabResource(tabResource); tdOpenSession.setSelectedTabResource(tabResource);
Log.debug("TdOpenSession: "+tdOpenSession); Log.debug("TdOpenSession: " + tdOpenSession);
setTabularResource(); setTabularResource();
} }
protected void setTabularResource() {
protected void setTabularResource(){ TDGWTServiceAsync.INSTANCE.setTabResource(
TDGWTServiceAsync.INSTANCE.setTabResource(tdOpenSession tdOpenSession.getSelectedTabResource(),
.getSelectedTabResource(),
new AsyncCallback<Void>() { new AsyncCallback<Void>() {
public void onFailure(Throwable caught) { public void onFailure(Throwable caught) {
AlertMessageBox d = new AlertMessageBox( AlertMessageBox d = new AlertMessageBox("Error",
"Error", "Error on set TabResource: " "Error on set TabResource: "
+ caught.getLocalizedMessage()); + caught.getLocalizedMessage());
d.addHideHandler(new HideHandler() { d.addHideHandler(new HideHandler() {
@ -141,16 +191,16 @@ public class TabResourcesSelectionCard extends WizardCard {
} }
public void onSuccess(Void result) { public void onSuccess(Void result) {
getWizardWindow().fireCompleted(tdOpenSession getWizardWindow().fireCompleted(
.getSelectedTabResource().getTrId()); tdOpenSession.getSelectedTabResource()
.getTrId());
getWizardWindow().close(false); getWizardWindow().close(false);
Log.info("OpenTD Tabular Resource selected :" + tdOpenSession Log.info("OpenTD Tabular Resource selected :"
.getSelectedTabResource()); + tdOpenSession.getSelectedTabResource());
} }
}); });
} }
} }

View File

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