From 4894259fae712833d1d91d779d4a198474a35a5c Mon Sep 17 00:00:00 2001 From: cramakri <cramakri> Date: Tue, 10 May 2011 13:12:50 +0000 Subject: [PATCH] LMS-2210 Added an archive menu to the experiment browser. SVN: 21206 --- .../web/client/ICommonClientService.java | 28 ++ .../web/client/ICommonClientServiceAsync.java | 25 ++ .../ui/experiment/ExperimentBrowserGrid.java | 27 ++ .../ExperimentDataSetArchivingMenu.java | 401 ++++++++++++++++++ ...SelectedOrAllExperimentsRadioProvider.java | 82 ++++ ...splayedCriteriaOrSelectedEntityHolder.java | 1 + .../web/server/CommonClientService.java | 96 +++++ 7 files changed, 660 insertions(+) create mode 100644 openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/experiment/ExperimentDataSetArchivingMenu.java create mode 100644 openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/experiment/SelectedOrAllExperimentsRadioProvider.java create mode 100644 openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/dto/DisplayedCriteriaOrSelectedEntityHolder.java diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/ICommonClientService.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/ICommonClientService.java index 1e78b91ba28..98d1c9dd7c4 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/ICommonClientService.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/ICommonClientService.java @@ -22,6 +22,7 @@ import java.util.List; import ch.systemsx.cisd.openbis.generic.client.web.client.dto.ArchivingResult; import ch.systemsx.cisd.openbis.generic.client.web.client.dto.DataSetUploadParameters; import ch.systemsx.cisd.openbis.generic.client.web.client.dto.DefaultResultSetConfig; +import ch.systemsx.cisd.openbis.generic.client.web.client.dto.DisplayedCriteriaOrSelectedEntityHolder; import ch.systemsx.cisd.openbis.generic.client.web.client.dto.DisplayedOrSelectedDatasetCriteria; import ch.systemsx.cisd.openbis.generic.client.web.client.dto.DisplayedOrSelectedIdHolderCriteria; import ch.systemsx.cisd.openbis.generic.client.web.client.dto.IResultSetConfig; @@ -851,6 +852,20 @@ public interface ICommonClientService extends IClientService public ArchivingResult unarchiveDatasets(DisplayedOrSelectedDatasetCriteria criteria) throws UserFailureException; + /** + * Schedules archiving of the datasets connected to the specified experiments. + */ + public ArchivingResult archiveDatasets( + DisplayedCriteriaOrSelectedEntityHolder<Experiment> criteria) + throws UserFailureException; + + /** + * Schedules unarchiving of the datasets connected to the specified experiments. + */ + public ArchivingResult unarchiveDatasets( + DisplayedCriteriaOrSelectedEntityHolder<Experiment> criteria) + throws UserFailureException; + /** * Deletes selected authorization groups. */ @@ -992,6 +1007,19 @@ public interface ICommonClientService extends IClientService public ArchivingResult unlockDatasets(DisplayedOrSelectedDatasetCriteria criteria) throws UserFailureException; + /** + * Locks the datasets connected to the specified experiments. + */ + public ArchivingResult lockDatasets(DisplayedCriteriaOrSelectedEntityHolder<Experiment> criteria) + throws UserFailureException; + + /** + * Unlocks the datasets connected to the specified experiments. + */ + public ArchivingResult unlockDatasets( + DisplayedCriteriaOrSelectedEntityHolder<Experiment> criteria) + throws UserFailureException; + /** * Gets the link from a service that supports the IReportingPluginTask#createLink method. */ diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/ICommonClientServiceAsync.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/ICommonClientServiceAsync.java index 4e06d804084..a045e84d5d3 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/ICommonClientServiceAsync.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/ICommonClientServiceAsync.java @@ -24,6 +24,7 @@ import com.google.gwt.user.client.rpc.AsyncCallback; import ch.systemsx.cisd.openbis.generic.client.web.client.dto.ArchivingResult; import ch.systemsx.cisd.openbis.generic.client.web.client.dto.DataSetUploadParameters; import ch.systemsx.cisd.openbis.generic.client.web.client.dto.DefaultResultSetConfig; +import ch.systemsx.cisd.openbis.generic.client.web.client.dto.DisplayedCriteriaOrSelectedEntityHolder; import ch.systemsx.cisd.openbis.generic.client.web.client.dto.DisplayedOrSelectedDatasetCriteria; import ch.systemsx.cisd.openbis.generic.client.web.client.dto.DisplayedOrSelectedIdHolderCriteria; import ch.systemsx.cisd.openbis.generic.client.web.client.dto.IResultSetConfig; @@ -747,6 +748,18 @@ public interface ICommonClientServiceAsync extends IClientServiceAsync public void unarchiveDatasets(DisplayedOrSelectedDatasetCriteria criteria, AsyncCallback<ArchivingResult> callback); + /** + * @see ICommonClientService#archiveDatasets(DisplayedCriteriaOrSelectedEntityHolder) + */ + public void archiveDatasets(DisplayedCriteriaOrSelectedEntityHolder<Experiment> criteria, + AsyncCallback<ArchivingResult> callback); + + /** + * @see ICommonClientService#unarchiveDatasets(DisplayedCriteriaOrSelectedEntityHolder) + */ + public void unarchiveDatasets(DisplayedCriteriaOrSelectedEntityHolder<Experiment> criteria, + AsyncCallback<ArchivingResult> callback); + /** * @see ICommonClientService#deleteAuthorizationGroups(List, String) */ @@ -881,6 +894,18 @@ public interface ICommonClientServiceAsync extends IClientServiceAsync public void unlockDatasets(DisplayedOrSelectedDatasetCriteria criteria, AsyncCallback<ArchivingResult> callback); + /** + * @see ICommonClientService#lockDatasets(DisplayedCriteriaOrSelectedEntityHolder) + */ + public void lockDatasets(DisplayedCriteriaOrSelectedEntityHolder<Experiment> criteria, + AsyncCallback<ArchivingResult> callback); + + /** + * @see ICommonClientService#unlockDatasets(DisplayedCriteriaOrSelectedEntityHolder) + */ + public void unlockDatasets(DisplayedCriteriaOrSelectedEntityHolder<Experiment> criteria, + AsyncCallback<ArchivingResult> callback); + /** * @see ICommonClientService#retrieveLinkFromDataSet(DatastoreServiceDescription, String) */ diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/experiment/ExperimentBrowserGrid.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/experiment/ExperimentBrowserGrid.java index d7189727691..25c90f7d0c0 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/experiment/ExperimentBrowserGrid.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/experiment/ExperimentBrowserGrid.java @@ -41,6 +41,7 @@ import ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.Display import ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.columns.framework.IColumnDefinitionKind; import ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.columns.framework.LinkExtractor; import ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.columns.specific.experiment.CommonExperimentColDefKind; +import ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.experiment.ExperimentDataSetArchivingMenu.SelectedAndDisplayedItems; import ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.grid.AbstractEntityBrowserGrid; import ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.grid.ColumnDefsAndConfigs; import ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.grid.DisposableEntityChooser; @@ -49,6 +50,7 @@ import ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.grid.IC import ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.listener.OpenEntityDetailsTabHelper; import ch.systemsx.cisd.openbis.generic.client.web.client.application.util.IDelegatedActionWithResult; import ch.systemsx.cisd.openbis.generic.client.web.client.application.util.IMessageProvider; +import ch.systemsx.cisd.openbis.generic.client.web.client.application.util.TextToolItem; import ch.systemsx.cisd.openbis.generic.client.web.client.dto.DefaultResultSetConfig; import ch.systemsx.cisd.openbis.generic.client.web.client.dto.ListExperimentsCriteria; import ch.systemsx.cisd.openbis.generic.client.web.client.dto.ResultSet; @@ -213,11 +215,36 @@ public class ExperimentBrowserGrid extends }); changeButtonTitleOnSelectedItems(deleteButton, deleteAllTitle, deleteTitle); addButton(deleteButton); + + if (viewContext.getModel().getApplicationInfo().isArchivingConfigured() + && viewContext.isSimpleOrEmbeddedMode() == false) + { + addButton(createArchivingMenu()); + } + allowMultipleSelection(); // we allow deletion of multiple samples addEntityOperationsSeparator(); } + private final TextToolItem createArchivingMenu() + { + return new ExperimentDataSetArchivingMenu(viewContext, + getSelectedAndDisplayedItemsAction(), createRefreshGridAction()); + } + + private final IDelegatedActionWithResult<SelectedAndDisplayedItems> getSelectedAndDisplayedItemsAction() + { + return new IDelegatedActionWithResult<SelectedAndDisplayedItems>() + { + public SelectedAndDisplayedItems execute() + { + return new SelectedAndDisplayedItems(getSelectedBaseObjects(), + createTableExportCriteria(), getTotalCount()); + } + }; + } + private void openExperimentRegistrationTab() { final ActionContext context = new ActionContext(); diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/experiment/ExperimentDataSetArchivingMenu.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/experiment/ExperimentDataSetArchivingMenu.java new file mode 100644 index 00000000000..32294a0f00b --- /dev/null +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/experiment/ExperimentDataSetArchivingMenu.java @@ -0,0 +1,401 @@ +/* + * Copyright 2010 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.ui.experiment; + +import java.util.List; + +import com.extjs.gxt.ui.client.widget.Dialog; +import com.extjs.gxt.ui.client.widget.MessageBox; +import com.extjs.gxt.ui.client.widget.Window; +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.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; +import ch.systemsx.cisd.openbis.generic.client.web.client.application.menu.IActionMenuItem; +import ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.ColumnConfigFactory; +import ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.data.DataSetArchivingMenu; +import ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.data.IComputationAction; +import ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.experiment.SelectedOrAllExperimentsRadioProvider.ISelectedExperimentsProvider; +import ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.widget.AbstractDataConfirmationDialog; +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; +import ch.systemsx.cisd.openbis.generic.client.web.client.application.util.TextToolItem; +import ch.systemsx.cisd.openbis.generic.client.web.client.dto.ArchivingResult; +import ch.systemsx.cisd.openbis.generic.client.web.client.dto.DisplayedCriteriaOrSelectedEntityHolder; +import ch.systemsx.cisd.openbis.generic.client.web.client.dto.TableExportCriteria; +import ch.systemsx.cisd.openbis.generic.shared.basic.dto.ArchivingServiceKind; +import ch.systemsx.cisd.openbis.generic.shared.basic.dto.DataSetArchivingStatus; +import ch.systemsx.cisd.openbis.generic.shared.basic.dto.DatastoreServiceDescription; +import ch.systemsx.cisd.openbis.generic.shared.basic.dto.Experiment; + +/** + * 'Archiving' menu for data sets connected to experiments. Here, experiments are the central + * entity, as opposed to {@link DataSetArchivingMenu}, where data sets are the central entity. + * + * @author Piotr Buczek + * @author Chandrasekhar Ramakrishnan + */ +public class ExperimentDataSetArchivingMenu extends TextToolItem +{ + private final IViewContext<ICommonClientServiceAsync> viewContext; + + private final IDelegatedActionWithResult<SelectedAndDisplayedItems> selectedDataSetsGetter; + + private final IDelegatedAction postArchivingAction; + + public ExperimentDataSetArchivingMenu(IViewContext<ICommonClientServiceAsync> viewContext, + IDelegatedActionWithResult<SelectedAndDisplayedItems> selectedDataSetsGetter, + IDelegatedAction postArchivingAction) + { + super(viewContext.getMessage(Dict.MENU_ARCHIVING)); + this.viewContext = viewContext; + this.postArchivingAction = postArchivingAction; + this.selectedDataSetsGetter = selectedDataSetsGetter; + + Menu submenu = new Menu(); + addMenuItem(submenu, ArchivingActionMenuKind.ARCHIVING_MENU_ARCHIVE); + addMenuItem(submenu, ArchivingActionMenuKind.ARCHIVING_MENU_UNARCHIVE); + addMenuItem(submenu, ArchivingActionMenuKind.ARCHIVING_MENU_LOCK); + addMenuItem(submenu, ArchivingActionMenuKind.ARCHIVING_MENU_UNLOCK); + setMenu(submenu); + } + + /** {@link ActionMenu} kind enum with names matching dictionary keys */ + private static enum ArchivingActionMenuKind implements IActionMenuItem + { + ARCHIVING_MENU_ARCHIVE(ArchivingServiceKind.ARCHIVE), ARCHIVING_MENU_UNARCHIVE( + ArchivingServiceKind.UNARCHIVE), ARCHIVING_MENU_LOCK(ArchivingServiceKind.LOCK), + ARCHIVING_MENU_UNLOCK(ArchivingServiceKind.UNLOCK); + + private final ArchivingServiceKind taskKind; + + ArchivingActionMenuKind(ArchivingServiceKind taskKind) + { + this.taskKind = taskKind; + } + + public ArchivingServiceKind getDssTaskKind() + { + return taskKind; + } + + public String getMenuId() + { + return this.name(); + } + + public String getMenuText(IMessageProvider messageProvider) + { + return messageProvider.getMessage(this.name()); + } + } + + private final void addMenuItem(Menu submenu, ArchivingActionMenuKind menuItemKind) + { + final IDelegatedAction menuItemAction = + createArchivingMenuAction(menuItemKind.getDssTaskKind()); + submenu.add(new ActionMenu(menuItemKind, viewContext, menuItemAction)); + } + + // + + private IDelegatedAction createArchivingMenuAction(final ArchivingServiceKind taskKind) + { + return new IDelegatedAction() + { + public void execute() + { + final SelectedAndDisplayedItems selectedAndDisplayedItems = + selectedDataSetsGetter.execute(); + final IComputationAction computationAction = + createComputationAction(selectedAndDisplayedItems, taskKind); + final ComputationData data = + new ComputationData(taskKind, computationAction, + selectedAndDisplayedItems); + createPerformComputationDialog(data).show(); + } + + private Window createPerformComputationDialog(ComputationData data) + { + final String title = "Perform " + taskKind.getDescription(); + return new PerformArchivingDialog(viewContext, data, title); + } + }; + } + + private static class ComputationData implements ISelectedExperimentsProvider + { + private final ArchivingServiceKind taskKind; + + private final IComputationAction computationAction; + + private final SelectedAndDisplayedItems selectedAndDisplayedItems; + + public ComputationData(ArchivingServiceKind taskKind, IComputationAction computationAction, + SelectedAndDisplayedItems selectedAndDisplayedItems) + { + super(); + this.taskKind = taskKind; + this.computationAction = computationAction; + this.selectedAndDisplayedItems = selectedAndDisplayedItems; + } + + public ArchivingServiceKind getTaskKind() + { + return taskKind; + } + + public IComputationAction getComputationAction() + { + return computationAction; + } + + public List<Experiment> getSelectedExperiments() + { + return selectedAndDisplayedItems.getSelectedItems(); + } + } + + private IComputationAction createComputationAction( + final SelectedAndDisplayedItems selectedAndDisplayedItems, + final ArchivingServiceKind taskKind) + { + return new IComputationAction() + { + public void execute(DatastoreServiceDescription service, boolean computeOnSelected) + { + DisplayedCriteriaOrSelectedEntityHolder<Experiment> criteria = + selectedAndDisplayedItems.createCriteria(computeOnSelected); + switch (taskKind) + { + case ARCHIVE: + viewContext.getService().archiveDatasets( + criteria, + createArchivingDisplayCallback(taskKind.getDescription(), + computeOnSelected)); + break; + case UNARCHIVE: + viewContext.getService().unarchiveDatasets( + criteria, + createArchivingDisplayCallback(taskKind.getDescription(), + computeOnSelected)); + break; + case LOCK: + viewContext.getService().lockDatasets( + criteria, + createArchivingDisplayCallback(taskKind.getDescription(), + computeOnSelected)); + break; + case UNLOCK: + viewContext.getService().unlockDatasets( + criteria, + createArchivingDisplayCallback(taskKind.getDescription(), + computeOnSelected)); + break; + } + } + }; + } + + private AsyncCallback<ArchivingResult> createArchivingDisplayCallback(String actionName, + boolean computeOnSelected) + { + return AsyncCallbackWithProgressBar.decorate(new ArchivingDisplayCallback(viewContext, + actionName, computeOnSelected), "Scheduling " + actionName + "..."); + } + + private final class ArchivingDisplayCallback extends AbstractAsyncCallback<ArchivingResult> + { + private final String actionName; + + private final boolean computeOnSelected; + + private ArchivingDisplayCallback(IViewContext<?> viewContext, String actionName, + boolean computeOnSelected) + { + super(viewContext); + this.actionName = actionName; + this.computeOnSelected = computeOnSelected; + } + + @Override + public final void process(final ArchivingResult result) + { + final String source = computeOnSelected ? "selected" : "provided"; + if (result.getScheduled() == 0) + { + MessageBox.info(actionName, actionName + " coulndn't be performed on " + source + + " data set(s).", null); + } else + { + boolean subset = result.getProvided() > result.getScheduled(); + MessageBox.info(actionName, actionName + " has been scheduled on " + + (subset ? "a subset of " : "all ") + source + " data set(s).", null); + postArchivingAction.execute(); + } + } + + } + + private static class PerformArchivingDialog extends + AbstractDataConfirmationDialog<ComputationData> + { + private static final int LABEL_WIDTH = ColumnConfigFactory.DEFAULT_COLUMN_WIDTH - 20; + + private static final int FIELD_WIDTH = 2 * ColumnConfigFactory.DEFAULT_COLUMN_WIDTH - 20; + + private static final int DIALOG_WIDTH = 4 * ColumnConfigFactory.DEFAULT_COLUMN_WIDTH + 30; + + private final IViewContext<ICommonClientServiceAsync> viewContext; + + private final SelectedOrAllExperimentsRadioProvider radioProvider; + + protected PerformArchivingDialog(IViewContext<ICommonClientServiceAsync> viewContext, + ComputationData data, String title) + { + super(viewContext, data, title); + this.viewContext = viewContext; + this.radioProvider = new SelectedOrAllExperimentsRadioProvider(data); + + setWidth(DIALOG_WIDTH); + } + + @Override + protected String createMessage() + { + int size = data.getSelectedExperiments().size(); + String computationName = data.getTaskKind().getDescription(); + String requiredStatusName = getRequiredStatus(data.getTaskKind()).getDescription(); + if (size == 0) + { + final String msgIntroduction = viewContext.getMessage(Dict.NO_DATASETS_SELECTED); + String dictKey = Dict.PERFORM_ARCHIVING_ON_ALL_DATASETS_MSG_TEMPLATE; + return viewContext.getMessage(dictKey, msgIntroduction, computationName, + requiredStatusName); + } else + { + String dictKey = Dict.PERFORM_ARCHIVING_ON_SELECTED_OR_ALL_DATASETS_MSG_TEMPLATE; + return viewContext.getMessage(dictKey, computationName, size, requiredStatusName); + } + } + + private DataSetArchivingStatus getRequiredStatus(ArchivingServiceKind taskKind) + { + switch (taskKind) + { + case ARCHIVE: + return DataSetArchivingStatus.AVAILABLE; + case UNARCHIVE: + return DataSetArchivingStatus.ARCHIVED; + case LOCK: + return DataSetArchivingStatus.AVAILABLE; + case UNLOCK: + return DataSetArchivingStatus.LOCKED; + default: + return null; // not possible + } + } + + @Override + protected void executeConfirmedAction() + { + final IComputationAction computationAction = data.getComputationAction(); + final boolean computeOnSelected = getComputeOnSelected(); + computationAction.execute(null, computeOnSelected); + } + + @Override + protected void extendForm() + { + formPanel.setLabelWidth(LABEL_WIDTH); + formPanel.setFieldWidth(FIELD_WIDTH); + + if (data.getSelectedExperiments().size() > 0) + { + formPanel.add(createComputationDataSetsRadio()); + } + Button confirmButton = getButtonById(Dialog.OK); + confirmButton.setText("Run"); + } + + private final RadioGroup createComputationDataSetsRadio() + { + return radioProvider.createComputationDataSetsRadio(); + } + + private boolean getComputeOnSelected() + { + return radioProvider.getComputeOnSelected(); + } + } + + public final static class SelectedAndDisplayedItems + { + // describes all items which are displayed in the grid (including all grid pages) + private final TableExportCriteria<Experiment> displayedItemsConfig; + + // currently selected items + private final List<Experiment> selectedItems; + + private final int displayedItemsCount; + + public SelectedAndDisplayedItems(List<Experiment> selectedItems, + TableExportCriteria<Experiment> displayedItemsConfig, int displayedItemsCount) + { + this.displayedItemsConfig = displayedItemsConfig; + this.selectedItems = selectedItems; + this.displayedItemsCount = displayedItemsCount; + } + + public TableExportCriteria<Experiment> getDisplayedItemsConfig() + { + return displayedItemsConfig; + } + + public int getDisplayedItemsCount() + { + return displayedItemsCount; + } + + public List<Experiment> getSelectedItems() + { + return selectedItems; + } + + public DisplayedCriteriaOrSelectedEntityHolder<Experiment> createCriteria(boolean selected) + { + if (selected) + { + List<Experiment> items = getSelectedItems(); + return DisplayedCriteriaOrSelectedEntityHolder.createSelectedItems(items); + } else + { + return DisplayedCriteriaOrSelectedEntityHolder + .createDisplayedItems(getDisplayedItemsConfig()); + } + } + } + +} diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/experiment/SelectedOrAllExperimentsRadioProvider.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/experiment/SelectedOrAllExperimentsRadioProvider.java new file mode 100644 index 00000000000..4aac7c2b939 --- /dev/null +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/experiment/SelectedOrAllExperimentsRadioProvider.java @@ -0,0 +1,82 @@ +/* + * Copyright 2010 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.ui.experiment; + +import java.util.List; + +import com.extjs.gxt.ui.client.Style.Orientation; +import com.extjs.gxt.ui.client.widget.form.Radio; +import com.extjs.gxt.ui.client.widget.form.RadioGroup; + +import ch.systemsx.cisd.openbis.generic.shared.basic.dto.Experiment; + +/** + * @author Piotr Buczek + */ +public class SelectedOrAllExperimentsRadioProvider +{ + private Radio computeOnSelectedRadio; + + private Radio computeOnAllRadio; + + private final ISelectedExperimentsProvider data; + + public SelectedOrAllExperimentsRadioProvider(ISelectedExperimentsProvider data) + { + this.data = data; + } + + public boolean getComputeOnSelected() + { + if (computeOnSelectedRadio == null) + { + return false; + } else + { + return computeOnSelectedRadio.getValue(); + } + } + + public final RadioGroup createComputationDataSetsRadio() + { + final RadioGroup result = new RadioGroup(); + result.setFieldLabel("Data Sets"); + result.setSelectionRequired(true); + result.setOrientation(Orientation.HORIZONTAL); + computeOnAllRadio = createRadio("all"); + computeOnSelectedRadio = + createRadio("selected (" + data.getSelectedExperiments().size() + ")"); + result.add(computeOnSelectedRadio); + result.add(computeOnAllRadio); + result.setValue(computeOnSelectedRadio); + result.setAutoHeight(true); + return result; + } + + private final Radio createRadio(final String label) + { + Radio result = new Radio(); + result.setBoxLabel(label); + return result; + } + + public interface ISelectedExperimentsProvider + { + public List<Experiment> getSelectedExperiments(); + } + +} \ No newline at end of file diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/dto/DisplayedCriteriaOrSelectedEntityHolder.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/dto/DisplayedCriteriaOrSelectedEntityHolder.java new file mode 100644 index 00000000000..50cc9d61f6b --- /dev/null +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/dto/DisplayedCriteriaOrSelectedEntityHolder.java @@ -0,0 +1 @@ +/* * Copyright 2009 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.dto; import java.util.List; import com.google.gwt.user.client.rpc.IsSerializable; import ch.systemsx.cisd.openbis.generic.shared.basic.IIdHolder; /** * Contains either a collection of entities or a the criteria to get those entities from the cache. * * @author Izabela Adamczyk * @author Chandrasekhar Ramakrishnan */ public final class DisplayedCriteriaOrSelectedEntityHolder<T extends IIdHolder> implements IsSerializable { private TableExportCriteria<T> displayedItemsOrNull; private List<T> selectedItemsOrNull; public static <T extends IIdHolder> DisplayedCriteriaOrSelectedEntityHolder<T> createSelectedItems( List<T> selectedItems) { return new DisplayedCriteriaOrSelectedEntityHolder<T>(null, selectedItems); } public static <T extends IIdHolder> DisplayedCriteriaOrSelectedEntityHolder<T> createDisplayedItems( TableExportCriteria<T> tableExportCriteria) { return new DisplayedCriteriaOrSelectedEntityHolder<T>(tableExportCriteria, null); } private DisplayedCriteriaOrSelectedEntityHolder(TableExportCriteria<T> displayedItemsOrNull, List<T> selectedItemsOrNull) { this.displayedItemsOrNull = displayedItemsOrNull; this.selectedItemsOrNull = selectedItemsOrNull; } public List<T> tryGetSelectedItems() { return selectedItemsOrNull; } public TableExportCriteria<T> tryGetDisplayedItems() { return displayedItemsOrNull; } /** * Call this to test if you should get the selected items or the displayed items. * * @return True if I have selected items; false if I have the criteria to get the displayed * items. */ public boolean hasSelectedItems() { return selectedItemsOrNull != null; } // GWT only @Deprecated private DisplayedCriteriaOrSelectedEntityHolder() { } } \ No newline at end of file diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/server/CommonClientService.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/server/CommonClientService.java index a97e2dcf14b..d2a66bb7456 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/server/CommonClientService.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/server/CommonClientService.java @@ -44,6 +44,7 @@ import ch.systemsx.cisd.openbis.generic.client.web.client.ICommonClientService; import ch.systemsx.cisd.openbis.generic.client.web.client.dto.ArchivingResult; import ch.systemsx.cisd.openbis.generic.client.web.client.dto.DataSetUploadParameters; import ch.systemsx.cisd.openbis.generic.client.web.client.dto.DefaultResultSetConfig; +import ch.systemsx.cisd.openbis.generic.client.web.client.dto.DisplayedCriteriaOrSelectedEntityHolder; import ch.systemsx.cisd.openbis.generic.client.web.client.dto.DisplayedOrSelectedDatasetCriteria; import ch.systemsx.cisd.openbis.generic.client.web.client.dto.DisplayedOrSelectedIdHolderCriteria; import ch.systemsx.cisd.openbis.generic.client.web.client.dto.GridRowModels; @@ -2151,6 +2152,40 @@ public final class CommonClientService extends AbstractClientService implements return prepareExportEntities(criteria); } + private List<String> extractDatasetCodes( + DisplayedCriteriaOrSelectedEntityHolder<Experiment> experimentCriteria) + { + // Get the referenced experiments + List<Experiment> experiments = getReferencedExperiments(experimentCriteria); + if (null == experiments) + { + return new ArrayList<String>(); + } + + DataSetRelatedEntities dataSetRelatedExperiments = new DataSetRelatedEntities(experiments); + List<ExternalData> relatedDataSets = + commonServer.listRelatedDataSets(getSessionToken(), dataSetRelatedExperiments); + return Code.extractCodes(relatedDataSets); + + } + + private List<Experiment> getReferencedExperiments( + DisplayedCriteriaOrSelectedEntityHolder<Experiment> experimentCriteria) + { + if (experimentCriteria.hasSelectedItems()) + { + return experimentCriteria.tryGetSelectedItems(); + } else + { + TableExportCriteria<Experiment> displayedItemsCriteria = + experimentCriteria.tryGetDisplayedItems(); + assert displayedItemsCriteria != null : "displayedItemsCriteria is null"; + List<Experiment> experiments = + fetchCachedEntities(displayedItemsCriteria).extractOriginalObjects(); + return experiments; + } + } + private List<String> extractDatasetCodes( DisplayedOrSelectedDatasetCriteria displayedOrSelectedDatasetCriteria) { @@ -2674,4 +2709,65 @@ public final class CommonClientService extends AbstractClientService implements throw UserFailureExceptionTranslator.translate(e); } } + public ArchivingResult archiveDatasets( + DisplayedCriteriaOrSelectedEntityHolder<Experiment> criteria) + { + try + { + final String sessionToken = getSessionToken(); + List<String> datasetCodes = extractDatasetCodes(criteria); + int result = commonServer.archiveDatasets(sessionToken, datasetCodes, true); + return new ArchivingResult(datasetCodes.size(), result); + } catch (final UserFailureException e) + { + throw UserFailureExceptionTranslator.translate(e); + } + } + + public ArchivingResult unarchiveDatasets( + DisplayedCriteriaOrSelectedEntityHolder<Experiment> criteria) + { + try + { + final String sessionToken = getSessionToken(); + List<String> datasetCodes = extractDatasetCodes(criteria); + int result = commonServer.unarchiveDatasets(sessionToken, datasetCodes); + return new ArchivingResult(datasetCodes.size(), result); + } catch (final UserFailureException e) + { + throw UserFailureExceptionTranslator.translate(e); + } + } + + public ArchivingResult lockDatasets(DisplayedCriteriaOrSelectedEntityHolder<Experiment> criteria) + throws ch.systemsx.cisd.openbis.generic.client.web.client.exception.UserFailureException + { + try + { + final String sessionToken = getSessionToken(); + List<String> datasetCodes = extractDatasetCodes(criteria); + int result = commonServer.lockDatasets(sessionToken, datasetCodes); + return new ArchivingResult(datasetCodes.size(), result); + } catch (final UserFailureException e) + { + throw UserFailureExceptionTranslator.translate(e); + } + } + + public ArchivingResult unlockDatasets( + DisplayedCriteriaOrSelectedEntityHolder<Experiment> criteria) + throws ch.systemsx.cisd.openbis.generic.client.web.client.exception.UserFailureException + { + try + { + final String sessionToken = getSessionToken(); + List<String> datasetCodes = extractDatasetCodes(criteria); + int result = commonServer.unlockDatasets(sessionToken, datasetCodes); + return new ArchivingResult(datasetCodes.size(), result); + } catch (final UserFailureException e) + { + throw UserFailureExceptionTranslator.translate(e); + } + } + } -- GitLab