diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/TypedTableGrid.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/TypedTableGrid.java index e1bbb7d4294f7fd794894436cca38ff5124860c1..7f5cceb472b0c8767d52a59c187f192affbbb9e3 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/TypedTableGrid.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/TypedTableGrid.java @@ -122,6 +122,8 @@ import ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.grid.IC import ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.grid.IColumnDefinitionProvider; import ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.grid.IDisplayTypeIDProvider; import ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.grid.IDisposableComponent; +import ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.grid.IModification; +import ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.grid.ITableModificationsManager; import ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.grid.PendingFetchManager; import ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.grid.TableExportType; import ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.grid.expressions.filter.FilterToolbar; @@ -307,36 +309,6 @@ public abstract class TypedTableGrid<T extends Serializable> extends LayoutConta } } - /** Manager of table modifications */ - public interface ITableModificationsManager<M extends ModelData> - { - /** @return <code>true</code> iff there are any uncommitted modifications */ - boolean isTableDirty(); - - /** save all modifications made in the table to the DB */ - void saveModifications(); - - /** save all modifications made in the table to the DB and call the after save action */ - void saveModifications(IDelegatedAction afterSaveAction); - - /** cancel all modifications made in the table */ - void cancelModifications(); - - /** handle cell editing event */ - void handleEditingEvent(M model, String columnID, String stringOrNull); - - /** @return callback for given modifications made to specified model. */ - AsyncCallback<EntityPropertyUpdatesResult> createApplyModificationsCallback(final M model, - final List<IModification> modifications); - } - - protected interface IModification - { - String getColumnID(); - - String tryGetNewValue(); - } - private static class Modification implements IModification { private final String columnID; @@ -1040,22 +1012,12 @@ public abstract class TypedTableGrid<T extends Serializable> extends LayoutConta { if (me.getButtonClicked().getItemId().equals(Dialog.YES)) { - tableModificationsManager.saveModifications(new IDelegatedAction() - { - @Override - public void execute() - { - // ignore this callback and refresh the table - ignore(); - reenableAfterFailure(); - refresh(); - } - }); + tableModificationsManager.saveModifications(); } else { tableModificationsManager.cancelModifications(); - successAction.execute(); } + successAction.execute(); } }; final String title = @@ -2395,7 +2357,29 @@ public abstract class TypedTableGrid<T extends Serializable> extends LayoutConta @Override public void saveModifications() { - saveModifications(null); + saveModifications(new IDelegatedAction() + { + + @Override + public void execute() + { + DefaultResultSetConfig<String, TableModelRowWithObject<T>> config = + createPagingConfig(new BasePagingLoadConfig(), + filterToolbar.getFilters(), getGridDisplayTypeID()); + config.setCacheConfig(ResultSetFetchConfig + .createRecomputeAndCache(resultSetKeyOrNull)); + final int id = TypedTableGrid.this.log("refreshing cache silently"); + listTableRows(config, new AbstractAsyncCallback<TypedTableResultSet<T>>( + viewContext) + { + @Override + protected void process(TypedTableResultSet<T> result) + { + viewContext.logStop(id); + } + }); + } + }); } private void setAfterSaveAction(IDelegatedAction afterSaveAction) diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/grid/IModification.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/grid/IModification.java new file mode 100644 index 0000000000000000000000000000000000000000..6e9f4d9237b9b977a73415474513b7414e525ee3 --- /dev/null +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/grid/IModification.java @@ -0,0 +1,24 @@ +/* + * Copyright 2012 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.grid; + +public interface IModification +{ + public String getColumnID(); + + public String tryGetNewValue(); +} \ No newline at end of file diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/grid/ITableModificationsManager.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/grid/ITableModificationsManager.java new file mode 100644 index 0000000000000000000000000000000000000000..28df2be7a9c24dc9de7f858ecefbdfddf44d24e2 --- /dev/null +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/grid/ITableModificationsManager.java @@ -0,0 +1,48 @@ +/* + * Copyright 2012 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.grid; + +import java.util.List; + +import com.extjs.gxt.ui.client.data.ModelData; +import com.google.gwt.user.client.rpc.AsyncCallback; + +import ch.systemsx.cisd.openbis.generic.client.web.client.application.util.IDelegatedAction; +import ch.systemsx.cisd.openbis.generic.client.web.client.dto.EntityPropertyUpdatesResult; + +/** Manager of table modifications */ +public interface ITableModificationsManager<M extends ModelData> +{ + /** @return <code>true</code> iff there are any uncommitted modifications */ + boolean isTableDirty(); + + /** save all modifications made in the table to the DB */ + void saveModifications(); + + /** save all modifications made in the table to the DB and call the after save action */ + void saveModifications(IDelegatedAction afterSaveAction); + + /** cancel all modifications made in the table */ + void cancelModifications(); + + /** handle cell editing event */ + void handleEditingEvent(M model, String columnID, String stringOrNull); + + /** @return callback for given modifications made to specified model. */ + AsyncCallback<EntityPropertyUpdatesResult> createApplyModificationsCallback(final M model, + final List<IModification> modifications); +} \ No newline at end of file diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/dto/ResultSetFetchConfig.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/dto/ResultSetFetchConfig.java index 838272747a3a434cc2c5e83ae03e9b875be739bc..b5414999caebc10ea8a399329b8f07352e3a1e0d 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/dto/ResultSetFetchConfig.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/dto/ResultSetFetchConfig.java @@ -27,7 +27,7 @@ public class ResultSetFetchConfig<K> implements IsSerializable { public enum ResultSetFetchMode implements IsSerializable { - COMPUTE_AND_CACHE, CLEAR_COMPUTE_AND_CACHE, FETCH_FROM_CACHE, + COMPUTE_AND_CACHE, CLEAR_COMPUTE_AND_CACHE, RECOMPUTE_AND_CACHE, FETCH_FROM_CACHE, FETCH_FROM_CACHE_AND_RECOMPUTE } @@ -58,6 +58,12 @@ public class ResultSetFetchConfig<K> implements IsSerializable return new ResultSetFetchConfig<K>(ResultSetFetchMode.FETCH_FROM_CACHE, resultSetKey); } + /** Instruction to recompute result and to cache it for the specified key. */ + public static <K> ResultSetFetchConfig<K> createRecomputeAndCache(K resultSetKey) + { + return new ResultSetFetchConfig<K>(ResultSetFetchMode.RECOMPUTE_AND_CACHE, resultSetKey); + } + /** * Instruction to fetch the result at the specified key in the cache an then recompute the * custom columns and distinct filter values. Remember that rows are filtered anyway, even diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/server/resultset/CachedResultSetManager.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/server/resultset/CachedResultSetManager.java index 8f07fffafddef29eb31ec9e8c2937c05ebc327c8..9b7954c1c140d8b77be2031c60fd8a3b89c4973f 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/server/resultset/CachedResultSetManager.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/server/resultset/CachedResultSetManager.java @@ -716,15 +716,18 @@ public final class CachedResultSetManager<K> implements IResultSetManager<K>, Se ResultSetFetchMode mode = cacheConfig.getMode(); debug("getResultSet(cache config = " + cacheConfig + ")"); + K dataKey = cacheConfig.tryGetResultSetKey(); switch (mode) { + case RECOMPUTE_AND_CACHE: + return fetchAndCacheResultForSpecifiedKey(sessionToken, resultConfig, dataProvider, + dataKey); case CLEAR_COMPUTE_AND_CACHE: - removeResultSet(cacheConfig.tryGetResultSetKey()); + removeResultSet(dataKey); //$FALL-THROUGH$ - case COMPUTE_AND_CACHE: return fetchAndCacheResult(sessionToken, resultConfig, dataProvider); default: - K dataKey = cacheConfig.tryGetResultSetKey(); TableData<T> tableData = tryGetCachedTableData(dataKey); if (tableData != null) { @@ -742,6 +745,13 @@ public final class CachedResultSetManager<K> implements IResultSetManager<K>, Se final IResultSetConfig<K, T> resultConfig, final IOriginalDataProvider<T> dataProvider) { final K dataKey = resultSetKeyProvider.createKey(); + return fetchAndCacheResultForSpecifiedKey(sessionToken, resultConfig, dataProvider, dataKey); + } + + private <T> IResultSet<K, T> fetchAndCacheResultForSpecifiedKey(final String sessionToken, + final IResultSetConfig<K, T> resultConfig, final IOriginalDataProvider<T> dataProvider, + final K dataKey) + { int limit = resultConfig.getLimit(); if (limit == IResultSetConfig.NO_LIMIT) {