From 26084460f98500b4d86d3cf0be81e0c271660dbc Mon Sep 17 00:00:00 2001 From: Giancarlo Panichi Date: Tue, 1 Apr 2014 14:21:02 +0000 Subject: [PATCH] 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 --- .../client/TabResourcesSelectionCard.java | 122 ++++++++++++------ .../client/TabResourcesSelectionPanel.java | 5 + 2 files changed, 91 insertions(+), 36 deletions(-) diff --git a/src/main/java/org/gcube/portlets/user/td/openwidget/client/TabResourcesSelectionCard.java b/src/main/java/org/gcube/portlets/user/td/openwidget/client/TabResourcesSelectionCard.java index 59e1f7a..d376a35 100644 --- a/src/main/java/org/gcube/portlets/user/td/openwidget/client/TabResourcesSelectionCard.java +++ b/src/main/java/org/gcube/portlets/user/td/openwidget/client/TabResourcesSelectionCard.java @@ -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() { - public void onSelection(SelectionEvent 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(){ + .getSelectedTabResource().getTrId(), + new AsyncCallback() { @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() { + + 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() { 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()); } }); - - + } } diff --git a/src/main/java/org/gcube/portlets/user/td/openwidget/client/TabResourcesSelectionPanel.java b/src/main/java/org/gcube/portlets/user/td/openwidget/client/TabResourcesSelectionPanel.java index 70b7524..ffefd21 100644 --- a/src/main/java/org/gcube/portlets/user/td/openwidget/client/TabResourcesSelectionPanel.java +++ b/src/main/java/org/gcube/portlets/user/td/openwidget/client/TabResourcesSelectionPanel.java @@ -236,5 +236,10 @@ public class TabResourcesSelectionPanel extends ContentPanel implements HasSelec } + public void gridReload(){ + grid.getLoader().load(); + } + + }