From 5e3fa607646227aa7be3cb90ba8c7354c5732116 Mon Sep 17 00:00:00 2001 From: Giancarlo Panichi Date: Fri, 16 May 2014 13:54:39 +0000 Subject: [PATCH] Added SessionExpiredShow git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/user/tabular-data-sdmx-export-widget@95788 82a268e6-3cf1-43bd-a215-b396298e98cf --- .../client/AgenciesSelectionPanel.java | 170 ++++++++++-------- .../client/CodelistSelectionPanel.java | 23 ++- .../client/DatasetSelectionPanel.java | 22 ++- .../client/SDMXAgenciesSelectionCard.java | 2 +- .../client/SDMXCodelistSelectionCard.java | 2 +- .../client/SDMXDatasetSelectionCard.java | 2 +- .../client/SDMXOperationInProgressCard.java | 47 +++-- .../client/SDMXRegistrySelectionCard.java | 10 ++ 8 files changed, 183 insertions(+), 95 deletions(-) diff --git a/src/main/java/org/gcube/portlets/user/td/sdmxexportwidget/client/AgenciesSelectionPanel.java b/src/main/java/org/gcube/portlets/user/td/sdmxexportwidget/client/AgenciesSelectionPanel.java index 7750d01..4131247 100644 --- a/src/main/java/org/gcube/portlets/user/td/sdmxexportwidget/client/AgenciesSelectionPanel.java +++ b/src/main/java/org/gcube/portlets/user/td/sdmxexportwidget/client/AgenciesSelectionPanel.java @@ -8,7 +8,11 @@ import java.util.Arrays; import java.util.List; import org.gcube.portlets.user.td.gwtservice.client.rpc.TDGWTServiceAsync; +import org.gcube.portlets.user.td.gwtservice.shared.exception.TDGWTSessionExpiredException; import org.gcube.portlets.user.td.gwtservice.shared.tr.type.Agencies; +import org.gcube.portlets.user.td.widgetcommonevent.client.event.SessionExpiredEvent; +import org.gcube.portlets.user.td.widgetcommonevent.client.type.SessionExpiredType; +import org.gcube.portlets.user.td.wizardwidget.client.WizardCard; import org.gcube.portlets.user.td.wizardwidget.client.dataresource.ResourceBundle; import com.allen_sauer.gwt.log.client.Log; @@ -51,85 +55,95 @@ import com.sencha.gxt.widget.core.client.toolbar.ToolBar; /** * - * @author "Giancarlo Panichi" - * g.panichi@isti.cnr.it - * + * @author "Giancarlo Panichi" g.panichi@isti.cnr.it + * */ -public class AgenciesSelectionPanel extends ContentPanel implements HasSelectionHandlers { +public class AgenciesSelectionPanel extends ContentPanel implements + HasSelectionHandlers { - private static final AgenciesProperties properties = GWT.create(AgenciesProperties.class); - - protected static final ColumnConfig nameColumn = new ColumnConfig(properties.name(), 50, "Name"); - protected static final ColumnConfig descriptionColumn = new ColumnConfig(properties.description(), 50, "Description"); + private static final AgenciesProperties properties = GWT + .create(AgenciesProperties.class); + + protected static final ColumnConfig nameColumn = new ColumnConfig( + properties.name(), 50, "Name"); + protected static final ColumnConfig descriptionColumn = new ColumnConfig( + properties.description(), 50, "Description"); protected Grid grid; protected ResourceBundle res; - - - public AgenciesSelectionPanel(ResourceBundle res) - { - this.res=res; + + private WizardCard parent; + + public AgenciesSelectionPanel(WizardCard parent, ResourceBundle res) { + this.parent = parent; + this.res = res; setHeaderVisible(false); new Resizable(this, Dir.E, Dir.SE, Dir.S); - buildPanel(properties.key(), Arrays.>asList(nameColumn, descriptionColumn), nameColumn); + buildPanel(properties.key(), Arrays.> asList( + nameColumn, descriptionColumn), nameColumn); } - - - protected void buildPanel(ModelKeyProvider keyProvider, List> columns, ColumnConfig autoexpandColumn) - { + + protected void buildPanel(ModelKeyProvider keyProvider, + List> columns, + ColumnConfig autoexpandColumn) { ToolBar toolBar = new ToolBar(); toolBar.add(new LabelToolItem("Search: ")); final TextField searchField = new TextField(); toolBar.add(searchField); - + TextButton btnReload = new TextButton(); - //btnReload.setText("Reload"); + // btnReload.setText("Reload"); btnReload.setIcon(res.refresh16()); btnReload.setToolTip("Reload"); toolBar.add(btnReload); - - + IdentityValueProvider identity = new IdentityValueProvider(); - final CheckBoxSelectionModel sm = new CheckBoxSelectionModel(identity); - + final CheckBoxSelectionModel sm = new CheckBoxSelectionModel( + identity); + ColumnModel cm = new ColumnModel(columns); - final ExtendedListStore store = new ExtendedListStore(keyProvider); + final ExtendedListStore store = new ExtendedListStore( + keyProvider); searchField.addKeyUpHandler(new KeyUpHandler() { - public void onKeyUp(KeyUpEvent event) { - Log.trace("searchTerm: "+searchField.getCurrentValue()); - store.applyFilters(); + Log.trace("searchTerm: " + searchField.getCurrentValue()); + store.applyFilters(); } }); - + store.addFilter(new StoreFilter() { - public boolean select(Store store, Agencies parent, Agencies item) { + public boolean select(Store store, Agencies parent, + Agencies item) { String searchTerm = searchField.getCurrentValue(); - if (searchTerm == null) return true; + if (searchTerm == null) + return true; return AgenciesSelectionPanel.this.select(item, searchTerm); } }); store.setEnableFilters(true); - RpcProxy> proxy = new RpcProxy>() { + RpcProxy> proxy = new RpcProxy>() { - - public void load(ListLoadConfig loadConfig, final AsyncCallback> callback) { + public void load(ListLoadConfig loadConfig, + final AsyncCallback> callback) { loadData(loadConfig, callback); - } + } }; - final ListLoader> loader = new ListLoader>(proxy); + final ListLoader> loader = new ListLoader>( + proxy); loader.setRemoteSort(false); - loader.addLoadHandler(new LoadResultListStoreBinding>(store)); + loader.addLoadHandler(new LoadResultListStoreBinding>( + store)); - grid = new Grid(store, cm){ + grid = new Grid(store, cm) { @Override protected void onAfterFirstAttach() { super.onAfterFirstAttach(); @@ -140,8 +154,8 @@ public class AgenciesSelectionPanel extends ContentPanel implements HasSelection }); } }; - - sm.setSelectionMode(SelectionMode.SINGLE); + + sm.setSelectionMode(SelectionMode.SINGLE); grid.setLoader(loader); grid.setSelectionModel(sm); grid.getView().setAutoExpandColumn(autoexpandColumn); @@ -151,72 +165,86 @@ public class AgenciesSelectionPanel extends ContentPanel implements HasSelection grid.setBorders(false); grid.setLoadMask(true); grid.setColumnReordering(true); - + SelectHandler sh = new SelectHandler() { public void onSelect(SelectEvent event) { loader.load(); } }; - + btnReload.addSelectHandler(sh); - + VerticalLayoutContainer con = new VerticalLayoutContainer(); con.add(toolBar, new VerticalLayoutData(1, -1)); con.add(grid, new VerticalLayoutData(1, 1)); setWidget(con); } - - - + protected boolean select(Agencies item, String searchTerm) { - if (item.getName()!=null && item.getName().toLowerCase().contains(searchTerm.toLowerCase())) return true; - if (item.getDescription()!=null && item.getDescription().toLowerCase().contains(searchTerm.toLowerCase())) return true; - if (item.getId()!=null &&item.getId().toLowerCase().contains(searchTerm.toLowerCase())) return true; + if (item.getName() != null + && item.getName().toLowerCase() + .contains(searchTerm.toLowerCase())) + return true; + if (item.getDescription() != null + && item.getDescription().toLowerCase() + .contains(searchTerm.toLowerCase())) + return true; + if (item.getId() != null + && item.getId().toLowerCase() + .contains(searchTerm.toLowerCase())) + return true; return false; } - - protected void loadData(ListLoadConfig loadConfig, final AsyncCallback> callback) { - TDGWTServiceAsync.INSTANCE.getAgencies(new AsyncCallback>() { + protected void loadData(ListLoadConfig loadConfig, + final AsyncCallback> callback) { + TDGWTServiceAsync.INSTANCE + .getAgencies(new AsyncCallback>() { - public void onFailure(Throwable caught) { - - callback.onFailure(caught); - } + public void onFailure(Throwable caught) { + if (caught instanceof TDGWTSessionExpiredException) { + parent.getEventBus() + .fireEvent( + new SessionExpiredEvent( + SessionExpiredType.EXPIREDONSERVER)); + } else { + Log.error("No agencies retrieved"); + } + callback.onFailure(caught); + } - public void onSuccess(ArrayList result) { - Log.trace("loaded "+result.size()+" agencies"); - callback.onSuccess(new ListLoadResultBean(result)); - } - }); + public void onSuccess(ArrayList result) { + Log.trace("loaded " + result.size() + " agencies"); + callback.onSuccess(new ListLoadResultBean( + result)); + } + }); } - - public HandlerRegistration addSelectionHandler(SelectionHandler handler) { + public HandlerRegistration addSelectionHandler( + SelectionHandler handler) { return grid.getSelectionModel().addSelectionHandler(handler); } - - /*public List getSelectedItems() { - return grid.getSelectionModel().getSelectedItems(); - }*/ + /* + * public List getSelectedItems() { return + * grid.getSelectionModel().getSelectedItems(); } + */ public Agencies getSelectedItem() { return grid.getSelectionModel().getSelectedItem(); } - + protected class ExtendedListStore extends ListStore { public ExtendedListStore(ModelKeyProvider keyProvider) { super(keyProvider); } - public void applyFilters() - { + public void applyFilters() { super.applyFilters(); } } - } diff --git a/src/main/java/org/gcube/portlets/user/td/sdmxexportwidget/client/CodelistSelectionPanel.java b/src/main/java/org/gcube/portlets/user/td/sdmxexportwidget/client/CodelistSelectionPanel.java index 15565da..037c6f8 100644 --- a/src/main/java/org/gcube/portlets/user/td/sdmxexportwidget/client/CodelistSelectionPanel.java +++ b/src/main/java/org/gcube/portlets/user/td/sdmxexportwidget/client/CodelistSelectionPanel.java @@ -8,7 +8,11 @@ import java.util.Arrays; import java.util.List; import org.gcube.portlets.user.td.gwtservice.client.rpc.TDGWTServiceAsync; +import org.gcube.portlets.user.td.gwtservice.shared.exception.TDGWTSessionExpiredException; import org.gcube.portlets.user.td.gwtservice.shared.tr.type.Codelist; +import org.gcube.portlets.user.td.widgetcommonevent.client.event.SessionExpiredEvent; +import org.gcube.portlets.user.td.widgetcommonevent.client.type.SessionExpiredType; +import org.gcube.portlets.user.td.wizardwidget.client.WizardCard; import org.gcube.portlets.user.td.wizardwidget.client.dataresource.ResourceBundle; import com.allen_sauer.gwt.log.client.Log; @@ -66,10 +70,13 @@ public class CodelistSelectionPanel extends ContentPanel implements HasSelection protected Grid grid; protected ResourceBundle res; + + private WizardCard parent; - public CodelistSelectionPanel(ResourceBundle res) + public CodelistSelectionPanel(WizardCard parent,ResourceBundle res) { + this.parent=parent; this.res=res; setHeaderVisible(false); new Resizable(this, Dir.E, Dir.SE, Dir.S); @@ -183,7 +190,15 @@ public class CodelistSelectionPanel extends ContentPanel implements HasSelection TDGWTServiceAsync.INSTANCE.getCodelists(new AsyncCallback>() { public void onFailure(Throwable caught) { - callback.onFailure(caught); + if (caught instanceof TDGWTSessionExpiredException) { + parent.getEventBus() + .fireEvent( + new SessionExpiredEvent( + SessionExpiredType.EXPIREDONSERVER)); + } else { + Log.error("No codelists retrieved"); + } + callback.onFailure(caught); } public void onSuccess(ArrayList result) { @@ -199,10 +214,6 @@ public class CodelistSelectionPanel extends ContentPanel implements HasSelection } - /*public List getSelectedItems() { - return grid.getSelectionModel().getSelectedItems(); - }*/ - public Codelist getSelectedItem() { return grid.getSelectionModel().getSelectedItem(); } diff --git a/src/main/java/org/gcube/portlets/user/td/sdmxexportwidget/client/DatasetSelectionPanel.java b/src/main/java/org/gcube/portlets/user/td/sdmxexportwidget/client/DatasetSelectionPanel.java index bef1bee..3dab992 100644 --- a/src/main/java/org/gcube/portlets/user/td/sdmxexportwidget/client/DatasetSelectionPanel.java +++ b/src/main/java/org/gcube/portlets/user/td/sdmxexportwidget/client/DatasetSelectionPanel.java @@ -8,7 +8,12 @@ import java.util.Arrays; import java.util.List; import org.gcube.portlets.user.td.gwtservice.client.rpc.TDGWTServiceAsync; +import org.gcube.portlets.user.td.gwtservice.shared.exception.TDGWTSessionExpiredException; import org.gcube.portlets.user.td.gwtservice.shared.tr.type.Dataset; +import org.gcube.portlets.user.td.widgetcommonevent.client.event.SessionExpiredEvent; +import org.gcube.portlets.user.td.widgetcommonevent.client.type.SessionExpiredType; +import org.gcube.portlets.user.td.wizardwidget.client.WizardCard; +import org.gcube.portlets.user.td.wizardwidget.client.dataresource.ResourceBundle; import com.allen_sauer.gwt.log.client.Log; import com.google.gwt.core.client.GWT; @@ -61,8 +66,14 @@ public class DatasetSelectionPanel extends ContentPanel implements HasSelectionH protected Grid grid; - public DatasetSelectionPanel() + protected ResourceBundle res; + + private WizardCard parent; + + public DatasetSelectionPanel(WizardCard parent, ResourceBundle res) { + this.parent=parent; + this.res=res; setHeaderVisible(false); new Resizable(this, Dir.E, Dir.SE, Dir.S); buildPanel(properties.key(), Arrays.>asList(nameColumn, agencyIdColumn, versionColumn, descriptionColumn), nameColumn); @@ -159,6 +170,15 @@ public class DatasetSelectionPanel extends ContentPanel implements HasSelectionH TDGWTServiceAsync.INSTANCE.getDatasets(new AsyncCallback>() { public void onFailure(Throwable caught) { + if (caught instanceof TDGWTSessionExpiredException) { + parent.getEventBus() + .fireEvent( + new SessionExpiredEvent( + SessionExpiredType.EXPIREDONSERVER)); + } else { + Log.error("No datasets retrieved"); + } + callback.onFailure(caught); } diff --git a/src/main/java/org/gcube/portlets/user/td/sdmxexportwidget/client/SDMXAgenciesSelectionCard.java b/src/main/java/org/gcube/portlets/user/td/sdmxexportwidget/client/SDMXAgenciesSelectionCard.java index a61c144..d7a58cf 100644 --- a/src/main/java/org/gcube/portlets/user/td/sdmxexportwidget/client/SDMXAgenciesSelectionCard.java +++ b/src/main/java/org/gcube/portlets/user/td/sdmxexportwidget/client/SDMXAgenciesSelectionCard.java @@ -31,7 +31,7 @@ public class SDMXAgenciesSelectionCard extends WizardCard { this.exportSession = exportSession; thisCard=this; - this.agenciesSelectionPanel=new AgenciesSelectionPanel(res); + this.agenciesSelectionPanel=new AgenciesSelectionPanel(thisCard,res); agenciesSelectionPanel.addSelectionHandler(new SelectionHandler(){ diff --git a/src/main/java/org/gcube/portlets/user/td/sdmxexportwidget/client/SDMXCodelistSelectionCard.java b/src/main/java/org/gcube/portlets/user/td/sdmxexportwidget/client/SDMXCodelistSelectionCard.java index 0a3182d..518b15d 100644 --- a/src/main/java/org/gcube/portlets/user/td/sdmxexportwidget/client/SDMXCodelistSelectionCard.java +++ b/src/main/java/org/gcube/portlets/user/td/sdmxexportwidget/client/SDMXCodelistSelectionCard.java @@ -31,7 +31,7 @@ public class SDMXCodelistSelectionCard extends WizardCard { this.exportSession = exportSession; thisCard=this; - this.codelistSelectionPanel=new CodelistSelectionPanel(res); + this.codelistSelectionPanel=new CodelistSelectionPanel(thisCard,res); codelistSelectionPanel.addSelectionHandler(new SelectionHandler() { diff --git a/src/main/java/org/gcube/portlets/user/td/sdmxexportwidget/client/SDMXDatasetSelectionCard.java b/src/main/java/org/gcube/portlets/user/td/sdmxexportwidget/client/SDMXDatasetSelectionCard.java index 303005f..2479c46 100644 --- a/src/main/java/org/gcube/portlets/user/td/sdmxexportwidget/client/SDMXDatasetSelectionCard.java +++ b/src/main/java/org/gcube/portlets/user/td/sdmxexportwidget/client/SDMXDatasetSelectionCard.java @@ -28,7 +28,7 @@ public class SDMXDatasetSelectionCard extends WizardCard { thisCard=this; - this.datasetSelectionPanel=new DatasetSelectionPanel(); + this.datasetSelectionPanel=new DatasetSelectionPanel(thisCard,res); setContent(datasetSelectionPanel); diff --git a/src/main/java/org/gcube/portlets/user/td/sdmxexportwidget/client/SDMXOperationInProgressCard.java b/src/main/java/org/gcube/portlets/user/td/sdmxexportwidget/client/SDMXOperationInProgressCard.java index 7e3f4c7..aee2529 100644 --- a/src/main/java/org/gcube/portlets/user/td/sdmxexportwidget/client/SDMXOperationInProgressCard.java +++ b/src/main/java/org/gcube/portlets/user/td/sdmxexportwidget/client/SDMXOperationInProgressCard.java @@ -4,10 +4,13 @@ package org.gcube.portlets.user.td.sdmxexportwidget.client; import org.gcube.portlets.user.td.gwtservice.client.rpc.TDGWTServiceAsync; +import org.gcube.portlets.user.td.gwtservice.shared.exception.TDGWTSessionExpiredException; import org.gcube.portlets.user.td.gwtservice.shared.sdmx.SDMXExportSession; import org.gcube.portlets.user.td.sdmxexportwidget.client.progress.SDMXExportProgressBarUpdater; import org.gcube.portlets.user.td.sdmxexportwidget.client.progress.SDMXExportProgressListener; import org.gcube.portlets.user.td.sdmxexportwidget.client.progress.SDMXExportProgressUpdater; +import org.gcube.portlets.user.td.widgetcommonevent.client.event.SessionExpiredEvent; +import org.gcube.portlets.user.td.widgetcommonevent.client.type.SessionExpiredType; import org.gcube.portlets.user.td.widgetcommonevent.shared.TRId; import org.gcube.portlets.user.td.wizardwidget.client.WizardCard; @@ -114,11 +117,19 @@ public class SDMXOperationInProgressCard extends WizardCard implements } public void onFailure(Throwable caught) { - showErrorAndHide( - "Error in exportSDMX", - "An error occured in exportSDMX: " - + caught.getLocalizedMessage(), caught - .getStackTrace().toString(), caught); + if (caught instanceof TDGWTSessionExpiredException) { + getEventBus() + .fireEvent( + new SessionExpiredEvent( + SessionExpiredType.EXPIREDONSERVER)); + } else { + + showErrorAndHide( + "Error in exportSDMX", + "An error occured in exportSDMX: " + + caught.getLocalizedMessage(), + caught.getStackTrace().toString(), caught); + } } }); } @@ -132,7 +143,7 @@ public class SDMXOperationInProgressCard extends WizardCard implements getWizardWindow().setNextButtonToFinish(); exportSDMX(); } - + @Override public void operationInitializing() { @@ -167,13 +178,21 @@ public class SDMXOperationInProgressCard extends WizardCard implements public void operationFailed(Throwable caught, String reason, String failureDetails) { - AlertMessageBox d = new AlertMessageBox("Error in SDMX Export", reason); - d.addHideHandler(new HideHandler() { - public void onHide(HideEvent event) { - } + if (caught instanceof TDGWTSessionExpiredException) { + getEventBus() + .fireEvent( + new SessionExpiredEvent( + SessionExpiredType.EXPIREDONSERVER)); + } else { + AlertMessageBox d = new AlertMessageBox("Error in SDMX Export", + reason); + d.addHideHandler(new HideHandler() { + public void onHide(HideEvent event) { + } - }); - d.show(); + }); + d.show(); + } } @Override @@ -203,13 +222,13 @@ public class SDMXOperationInProgressCard extends WizardCard implements @Override public void operationGeneratingView() { // TODO Auto-generated method stub - + } @Override public void operationValidate(float elaborated) { // TODO Auto-generated method stub - + } } diff --git a/src/main/java/org/gcube/portlets/user/td/sdmxexportwidget/client/SDMXRegistrySelectionCard.java b/src/main/java/org/gcube/portlets/user/td/sdmxexportwidget/client/SDMXRegistrySelectionCard.java index f895cd9..fb12855 100644 --- a/src/main/java/org/gcube/portlets/user/td/sdmxexportwidget/client/SDMXRegistrySelectionCard.java +++ b/src/main/java/org/gcube/portlets/user/td/sdmxexportwidget/client/SDMXRegistrySelectionCard.java @@ -4,8 +4,11 @@ package org.gcube.portlets.user.td.sdmxexportwidget.client; import org.gcube.portlets.user.td.gwtservice.client.rpc.TDGWTServiceAsync; +import org.gcube.portlets.user.td.gwtservice.shared.exception.TDGWTSessionExpiredException; import org.gcube.portlets.user.td.gwtservice.shared.sdmx.SDMXExportSession; import org.gcube.portlets.user.td.gwtservice.shared.source.SDMXRegistrySource; +import org.gcube.portlets.user.td.widgetcommonevent.client.event.SessionExpiredEvent; +import org.gcube.portlets.user.td.widgetcommonevent.client.type.SessionExpiredType; import org.gcube.portlets.user.td.wizardwidget.client.WizardCard; import com.allen_sauer.gwt.log.client.Log; @@ -147,8 +150,15 @@ public class SDMXRegistrySelectionCard extends WizardCard { ((SDMXRegistrySource)exportSession.getSource()), new AsyncCallback() { public void onFailure(Throwable caught) { + if (caught instanceof TDGWTSessionExpiredException) { + getEventBus() + .fireEvent( + new SessionExpiredEvent( + SessionExpiredType.EXPIREDONSERVER)); + } else { Log.error("SDMXRegistrySource do not stored " + caught.getLocalizedMessage()); + } } public void onSuccess(Void result) {