diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/AsyncCallbackWithProgressBar.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/AsyncCallbackWithProgressBar.java new file mode 100644 index 0000000000000000000000000000000000000000..7ba8df47da9ab9ca9de129273c3656c20b5f6492 --- /dev/null +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/AsyncCallbackWithProgressBar.java @@ -0,0 +1,84 @@ +/* + * Copyright 2008 ETH Zuerich, CISD + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package ch.systemsx.cisd.openbis.generic.client.web.client.application; + +import com.extjs.gxt.ui.client.widget.Dialog; +import com.extjs.gxt.ui.client.widget.ProgressBar; +import com.google.gwt.user.client.rpc.AsyncCallback; + +import ch.systemsx.cisd.openbis.generic.client.web.client.application.util.GWTUtils; + +/** + * {@link AsyncCallback} decorator adding a progress bar that is visible until response is received + * from a RPC call. + * + * @author Piotr Buczek + */ +public class AsyncCallbackWithProgressBar<T> implements AsyncCallback<T> +{ + + /** + * Decorates given callback with a progress bar containing given message. + */ + public static <T> AsyncCallbackWithProgressBar<T> decorate(AsyncCallback<T> decoratedCallback, + String progressMessage) + { + return new AsyncCallbackWithProgressBar<T>(decoratedCallback, progressMessage); + } + + private final AsyncCallback<T> decoratedCallback; + + private final Dialog progressBar; + + private AsyncCallbackWithProgressBar(AsyncCallback<T> decoratedCallback, String progressMessage) + { + super(); + this.decoratedCallback = decoratedCallback; + this.progressBar = createAndShowProgressBar(progressMessage); + } + + public void onFailure(Throwable caught) + { + progressBar.hide(); + decoratedCallback.onFailure(caught); + } + + public void onSuccess(T result) + { + progressBar.hide(); + decoratedCallback.onSuccess(result); + } + + private final static Dialog createAndShowProgressBar(final String title) + { + ProgressBar progressBar = new ProgressBar(); + progressBar.auto(); + + Dialog dialog = new Dialog(); + GWTUtils.setToolTip(dialog, title); + + dialog.add(progressBar); + dialog.setButtons(""); + dialog.setAutoHeight(true); + dialog.setClosable(false); + dialog.addText(title); + dialog.setResizable(false); + dialog.show(); + return dialog; + } + +} diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/data/DataSetArchivingMenu.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/data/DataSetArchivingMenu.java index 3b67a7e7b8cd5e71958e0aa6c13567208e33100e..1940faa3f67224ac15f0d716872404a7c146f5b3 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/data/DataSetArchivingMenu.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/data/DataSetArchivingMenu.java @@ -25,9 +25,11 @@ import com.extjs.gxt.ui.client.widget.button.Button; import com.extjs.gxt.ui.client.widget.form.RadioGroup; import com.extjs.gxt.ui.client.widget.menu.Menu; import com.extjs.gxt.ui.client.widget.menu.MenuItem; +import com.google.gwt.user.client.rpc.AsyncCallback; import ch.systemsx.cisd.openbis.generic.client.web.client.ICommonClientServiceAsync; import ch.systemsx.cisd.openbis.generic.client.web.client.application.AbstractAsyncCallback; +import ch.systemsx.cisd.openbis.generic.client.web.client.application.AsyncCallbackWithProgressBar; import ch.systemsx.cisd.openbis.generic.client.web.client.application.Dict; import ch.systemsx.cisd.openbis.generic.client.web.client.application.IViewContext; import ch.systemsx.cisd.openbis.generic.client.web.client.application.menu.ActionMenu; @@ -36,7 +38,6 @@ import ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.ColumnC import ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.data.AbstractExternalDataGrid.SelectedAndDisplayedItems; import ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.data.SelectedOrAllDataSetsRadioProvider.ISelectedDataSetsProvider; import ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.widget.AbstractDataConfirmationDialog; -import ch.systemsx.cisd.openbis.generic.client.web.client.application.util.GWTUtils; import ch.systemsx.cisd.openbis.generic.client.web.client.application.util.IDelegatedAction; import ch.systemsx.cisd.openbis.generic.client.web.client.application.util.IDelegatedActionWithResult; import ch.systemsx.cisd.openbis.generic.client.web.client.application.util.IMessageProvider; @@ -188,58 +189,56 @@ public class DataSetArchivingMenu extends MenuItem case ARCHIVE: viewContext.getService().archiveDatasets( criteria, - new ArchivingDisplayCallback(viewContext, taskKind - .getDescription(), computeOnSelected)); + createArchivingDisplayCallback(taskKind.getDescription(), + computeOnSelected)); break; case UNARCHIVE: viewContext.getService().unarchiveDatasets( criteria, - new ArchivingDisplayCallback(viewContext, taskKind - .getDescription(), computeOnSelected)); + createArchivingDisplayCallback(taskKind.getDescription(), + computeOnSelected)); break; case LOCK: viewContext.getService().lockDatasets( criteria, - new ArchivingDisplayCallback(viewContext, taskKind - .getDescription(), computeOnSelected)); + createArchivingDisplayCallback(taskKind.getDescription(), + computeOnSelected)); break; case UNLOCK: viewContext.getService().unlockDatasets( criteria, - new ArchivingDisplayCallback(viewContext, taskKind - .getDescription(), computeOnSelected)); + createArchivingDisplayCallback(taskKind.getDescription(), + computeOnSelected)); break; } } }; } + private AsyncCallback<ArchivingResult> createArchivingDisplayCallback(String actionName, + boolean computeOnSelected) + { + return AsyncCallbackWithProgressBar.decorate(new ArchivingDisplayCallback(viewContext, + actionName, computeOnSelected), "Schedulling " + actionName + "..."); + } + private final class ArchivingDisplayCallback extends AbstractAsyncCallback<ArchivingResult> { private final String actionName; private final boolean computeOnSelected; - private final Dialog progressBar; - private ArchivingDisplayCallback(IViewContext<?> viewContext, String actionName, boolean computeOnSelected) { super(viewContext); this.actionName = actionName; this.computeOnSelected = computeOnSelected; - this.progressBar = createAndShowProgressBar(); - } - - private Dialog createAndShowProgressBar() - { - return GWTUtils.createAndShowProgressBar("Scheduling " + actionName + "..."); } @Override public final void process(final ArchivingResult result) { - progressBar.hide(); final String source = computeOnSelected ? "selected" : "provided"; if (result.getScheduled() == 0) { @@ -254,12 +253,6 @@ public class DataSetArchivingMenu extends MenuItem } } - @Override - public void finishOnFailure(Throwable caught) - { - progressBar.hide(); - super.finishOnFailure(caught); - } } private static class PerformArchivingDialog extends diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/data/DataSetComputeMenu.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/data/DataSetComputeMenu.java index fe88bd233e3f8bf66ac66f88e4265318a69d7772..e569838bea6f1e8a829d2d614c28e3f28c7108e6 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/data/DataSetComputeMenu.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/data/DataSetComputeMenu.java @@ -36,6 +36,7 @@ import com.extjs.gxt.ui.client.widget.menu.Menu; import ch.systemsx.cisd.openbis.generic.client.web.client.ICommonClientServiceAsync; import ch.systemsx.cisd.openbis.generic.client.web.client.application.AbstractAsyncCallback; +import ch.systemsx.cisd.openbis.generic.client.web.client.application.AsyncCallbackWithProgressBar; import ch.systemsx.cisd.openbis.generic.client.web.client.application.Dict; import ch.systemsx.cisd.openbis.generic.client.web.client.application.IViewContext; import ch.systemsx.cisd.openbis.generic.client.web.client.application.help.HelpPageIdentifier; @@ -167,16 +168,22 @@ public class DataSetComputeMenu extends TextToolItem DataSetReportGenerator.generate(viewContext, service, criteria); break; case PROCESSING: - viewContext.getService().processDatasets(service, criteria, - new ProcessingDisplayCallback(viewContext)); + viewContext.getService().processDatasets( + service, + criteria, + AsyncCallbackWithProgressBar.decorate( + new ProcessingDisplayCallback(viewContext), + "Scheduling processing...")); break; } } + }; } private final class ProcessingDisplayCallback extends AbstractAsyncCallback<Void> { + private ProcessingDisplayCallback(IViewContext<?> viewContext) { super(viewContext); @@ -187,6 +194,12 @@ public class DataSetComputeMenu extends TextToolItem { MessageBox.info("Processing", "Processing has been scheduled successfully.", null); } + + @Override + public void finishOnFailure(Throwable caught) + { + super.finishOnFailure(caught); + } } private static class ComputationData implements ISelectedDataSetsProvider diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/data/DataSetReportGenerator.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/data/DataSetReportGenerator.java index f1f6b6f11a39c40375d133fd86677022e8f62643..75b685e67a570c055a634f76a962b45da6fae5f1 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/data/DataSetReportGenerator.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/data/DataSetReportGenerator.java @@ -16,6 +16,8 @@ package ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.data; +import com.google.gwt.user.client.rpc.AsyncCallback; + import ch.systemsx.cisd.openbis.generic.client.web.client.ICommonClientServiceAsync; import ch.systemsx.cisd.openbis.generic.client.web.client.application.IViewContext; import ch.systemsx.cisd.openbis.generic.client.web.client.application.framework.AbstractTabItemFactory; @@ -30,6 +32,7 @@ import ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.report. import ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.report.ReportGrid; import ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.report.ReportGeneratedCallback.IOnReportComponentGeneratedAction; import ch.systemsx.cisd.openbis.generic.client.web.client.dto.DisplayedOrSelectedDatasetCriteria; +import ch.systemsx.cisd.openbis.generic.client.web.client.dto.TableModelReference; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.DatastoreServiceDescription; /** @@ -57,8 +60,8 @@ public class DataSetReportGenerator DatastoreServiceDescription service, DisplayedOrSelectedDatasetCriteria criteria, IOnReportComponentGeneratedAction action) { - ReportGeneratedCallback callback = - new ReportGeneratedCallback(viewContext, service, action); + AsyncCallback<TableModelReference> callback = + ReportGeneratedCallback.create(viewContext, service, action); viewContext.getService().createReportFromDatasets(service, criteria, callback); } diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/report/ReportGeneratedCallback.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/report/ReportGeneratedCallback.java index ac8e524ef034304a22eb3f1a63cab229a679c72a..5a990cdcb527fbed345969838d7cc48a4da355a2 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/report/ReportGeneratedCallback.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/report/ReportGeneratedCallback.java @@ -16,14 +16,14 @@ package ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.report; -import com.extjs.gxt.ui.client.widget.Dialog; import com.extjs.gxt.ui.client.widget.MessageBox; +import com.google.gwt.user.client.rpc.AsyncCallback; import ch.systemsx.cisd.openbis.generic.client.web.client.ICommonClientServiceAsync; import ch.systemsx.cisd.openbis.generic.client.web.client.application.AbstractAsyncCallback; +import ch.systemsx.cisd.openbis.generic.client.web.client.application.AsyncCallbackWithProgressBar; import ch.systemsx.cisd.openbis.generic.client.web.client.application.IViewContext; import ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.grid.IDisposableComponent; -import ch.systemsx.cisd.openbis.generic.client.web.client.application.util.GWTUtils; import ch.systemsx.cisd.openbis.generic.client.web.client.application.util.StringUtils; import ch.systemsx.cisd.openbis.generic.client.web.client.dto.TableModelReference; import ch.systemsx.cisd.openbis.generic.shared.basic.IReportInformationProvider; @@ -40,13 +40,20 @@ public class ReportGeneratedCallback extends AbstractAsyncCallback<TableModelRef private final IViewContext<ICommonClientServiceAsync> viewContext; - private final Dialog progressBar; - private final IOnReportComponentGeneratedAction action; private final IReportInformationProvider reportInformationProvider; - public ReportGeneratedCallback(IViewContext<ICommonClientServiceAsync> viewContext, + public static AsyncCallback<TableModelReference> create( + IViewContext<ICommonClientServiceAsync> viewContext, + IReportInformationProvider reportInformationProvider, + IOnReportComponentGeneratedAction action) + { + return AsyncCallbackWithProgressBar.decorate(new ReportGeneratedCallback(viewContext, + reportInformationProvider, action), "Generating the report..."); + } + + private ReportGeneratedCallback(IViewContext<ICommonClientServiceAsync> viewContext, IReportInformationProvider reportInformationProvider, IOnReportComponentGeneratedAction action) { @@ -54,18 +61,11 @@ public class ReportGeneratedCallback extends AbstractAsyncCallback<TableModelRef this.viewContext = viewContext; this.reportInformationProvider = reportInformationProvider; this.action = action; - this.progressBar = createAndShowProgressBar(); - } - - private Dialog createAndShowProgressBar() - { - return GWTUtils.createAndShowProgressBar("Generating the report..."); } @Override protected void process(final TableModelReference tableModelReference) { - progressBar.hide(); final IDisposableComponent reportComponent = ReportGrid.create(viewContext, tableModelReference, reportInformationProvider); action.execute(reportComponent); @@ -75,11 +75,4 @@ public class ReportGeneratedCallback extends AbstractAsyncCallback<TableModelRef } } - @Override - public void finishOnFailure(Throwable caught) - { - progressBar.hide(); - super.finishOnFailure(caught); - } - } diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/util/GWTUtils.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/util/GWTUtils.java index e3a761faec0836e3112009b1b7cad9aae2553c38..526cd185570a2280cc87b51365b89c9327f50553 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/util/GWTUtils.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/util/GWTUtils.java @@ -22,8 +22,6 @@ import java.util.List; import com.extjs.gxt.ui.client.data.ModelData; import com.extjs.gxt.ui.client.store.ListStore; import com.extjs.gxt.ui.client.widget.Component; -import com.extjs.gxt.ui.client.widget.Dialog; -import com.extjs.gxt.ui.client.widget.ProgressBar; import com.extjs.gxt.ui.client.widget.form.ComboBox; import com.extjs.gxt.ui.client.widget.form.Field; import com.extjs.gxt.ui.client.widget.grid.GridSelectionModel; @@ -270,24 +268,6 @@ public final class GWTUtils "$", "-DOLLAR-"); } - public final static Dialog createAndShowProgressBar(final String title) - { - ProgressBar progressBar = new ProgressBar(); - progressBar.auto(); - - Dialog dialog = new Dialog(); - GWTUtils.setToolTip(dialog, title); - - dialog.add(progressBar); - dialog.setButtons(""); - dialog.setAutoHeight(true); - dialog.setClosable(false); - dialog.addText(title); - dialog.setResizable(false); - dialog.show(); - return dialog; - } - // // native JavaScript // diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/plugin/query/client/web/client/application/module/QueryEditor.java b/openbis/source/java/ch/systemsx/cisd/openbis/plugin/query/client/web/client/application/module/QueryEditor.java index f8432dd45384728675df47d0fef15d795ee96467..4a6b86a4cff3b63a13c5bb9ad813e7eeadfc1924 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/plugin/query/client/web/client/application/module/QueryEditor.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/plugin/query/client/web/client/application/module/QueryEditor.java @@ -309,7 +309,7 @@ public class QueryEditor extends Dialog viewContext.getService().createQueryResultsReport( sqlStatement, parameterBindings, - new ReportGeneratedCallback(viewContext.getCommonViewContext(), + ReportGeneratedCallback.create(viewContext.getCommonViewContext(), createReportInformationProvider(sqlStatement), createDisplayQueryResultsAction())); } diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/plugin/query/client/web/client/application/module/QueryViewer.java b/openbis/source/java/ch/systemsx/cisd/openbis/plugin/query/client/web/client/application/module/QueryViewer.java index 6d9d45622e87e669dfa81e854f7950c0b9f92267..27dbb34db796e68887bf05fa867f5c01aa99ffd1 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/plugin/query/client/web/client/application/module/QueryViewer.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/plugin/query/client/web/client/application/module/QueryViewer.java @@ -22,6 +22,7 @@ import com.extjs.gxt.ui.client.widget.Component; import com.extjs.gxt.ui.client.widget.ContentPanel; import com.extjs.gxt.ui.client.widget.layout.FitLayout; import com.google.gwt.user.client.Element; +import com.google.gwt.user.client.rpc.AsyncCallback; import ch.systemsx.cisd.openbis.generic.client.web.client.application.IViewContext; import ch.systemsx.cisd.openbis.generic.client.web.client.application.framework.DatabaseModificationAwareComponent; @@ -30,6 +31,7 @@ import ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.grid.ID import ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.report.ReportGeneratedCallback; import ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.report.ReportGeneratedCallback.IOnReportComponentGeneratedAction; import ch.systemsx.cisd.openbis.generic.client.web.client.application.util.IDelegatedAction; +import ch.systemsx.cisd.openbis.generic.client.web.client.dto.TableModelReference; import ch.systemsx.cisd.openbis.generic.shared.basic.IReportInformationProvider; import ch.systemsx.cisd.openbis.generic.shared.basic.TechId; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.DatabaseModificationKind; @@ -94,8 +96,8 @@ public class QueryViewer extends ContentPanel implements IDatabaseModificationOb { return; } - ReportGeneratedCallback callback = - new ReportGeneratedCallback(viewContext.getCommonViewContext(), + AsyncCallback<TableModelReference> callback = + ReportGeneratedCallback.create(viewContext.getCommonViewContext(), createReportInformationProvider(sqlQueryOrNull), createDisplayQueryResultsAction()); if (queryIdOrNull != null)