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 85203fae2f1607b10bec41b13a501f8beccc7c00..bdfe12ebaadf86775a80718a85ba16220ab39a5d 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 @@ -142,11 +142,6 @@ public interface ICommonClientService extends IClientService public String prepareExportMatchingEntities(final TableExportCriteria<MatchingEntity> criteria) throws UserFailureException; - /** - * Returns a list of all property types. - */ - public List<PropertyType> listPropertyTypes() throws UserFailureException; - /** * Returns a chunk of the property types list. */ @@ -184,6 +179,21 @@ public interface ICommonClientService extends IClientService public String prepareExportProjects(final TableExportCriteria<Project> criteria) throws UserFailureException; + /** + * Returns a list of all vocabularies. + * <p> + * Note that the vocabulary terms are included/loaded. + * </p> + */ + public ResultSet<Vocabulary> listVocabularies(boolean withTerms, boolean excludeInternal, + DefaultResultSetConfig<String, Vocabulary> criteria) throws UserFailureException; + + /** + * Like {@link #prepareExportSamples(TableExportCriteria)}, but for Vocabularies. + */ + public String prepareExportVocabularies(final TableExportCriteria<Vocabulary> criteria) + throws UserFailureException; + /** * Assumes that preparation of the export ({@link #prepareExportSamples(TableExportCriteria)} * or {@link #prepareExportExperiments(TableExportCriteria)} has been invoked before and @@ -220,15 +230,6 @@ public interface ICommonClientService extends IClientService */ public List<DataType> listDataTypes() throws UserFailureException; - /** - * Returns a list of all vocabularies. - * <p> - * Note that the vocabulary terms are included/loaded. - * </p> - */ - public List<Vocabulary> listVocabularies(boolean withTerms, boolean excludeInternal) - throws UserFailureException; - /** * Assigns property type to entity type. */ 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 09b0337bf296464532f24a9fab2a6c52a08a7150..cfa27611fb6901f8555cb03157c8a8cca708313f 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 @@ -132,9 +132,6 @@ public interface ICommonClientServiceAsync extends IClientServiceAsync public void prepareExportPropertyTypes(final TableExportCriteria<PropertyType> criteria, AsyncCallback<String> asyncCallback); - /** @see ICommonClientService#listPropertyTypes() */ - public void listPropertyTypes(final AsyncCallback<List<PropertyType>> asyncCallback); - /** * @see ICommonClientService#listMatchingEntities(SearchableEntity, String, IResultSetConfig) */ @@ -154,6 +151,15 @@ public interface ICommonClientServiceAsync extends IClientServiceAsync public void prepareExportProjects(TableExportCriteria<Project> exportCriteria, AsyncCallback<String> callback); + /** @see ICommonClientService#listVocabularies(boolean, boolean, DefaultResultSetConfig) */ + public void listVocabularies(final boolean withTerms, boolean excludeInternal, + DefaultResultSetConfig<String, Vocabulary> criteria, + final AsyncCallback<ResultSet<Vocabulary>> asyncCallback); + + /** @see ICommonClientService#prepareExportVocabularies(TableExportCriteria) */ + public void prepareExportVocabularies(TableExportCriteria<Vocabulary> exportCriteria, + AsyncCallback<String> callback); + /** * @see ICommonClientService#getExportTable(String) */ @@ -188,10 +194,6 @@ public interface ICommonClientServiceAsync extends IClientServiceAsync /** @see ICommonClientService#listDataTypes() */ public void listDataTypes(final AsyncCallback<List<DataType>> asyncCallback); - /** @see ICommonClientService#listVocabularies(boolean,boolean) */ - public void listVocabularies(final boolean withTerms, boolean excludeInternal, - final AsyncCallback<List<Vocabulary>> asyncCallback); - /** @see ICommonClientService#assignPropertyType(EntityKind, String, String, boolean, String) */ public void assignPropertyType(EntityKind entityKind, String propertyTypeCode, String entityTypeCode, boolean isMandatory, String defaultValue, diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/framework/ComponentProvider.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/framework/ComponentProvider.java index 33e9ff03f822f9699ed46d9cba835a6d415d9089..34229c3feb81a700acfe8c4a44362a39ee993dab 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/framework/ComponentProvider.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/framework/ComponentProvider.java @@ -35,7 +35,7 @@ import ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.propert import ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.sample.SampleBatchRegistrationPanel; import ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.sample.SampleBrowserGrid; import ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.sample.SampleRegistrationPanel; -import ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.vocabulary.VocabularyBrowser; +import ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.vocabulary.VocabularyGrid; import ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.vocabulary.VocabularyRegistrationForm; import ch.systemsx.cisd.openbis.generic.client.web.client.dto.EntityKind; @@ -238,13 +238,14 @@ final class ComponentProvider { public ITabItem create() { - Component component = new VocabularyBrowser(viewContext); - return new DefaultTabItem(getMessage(Dict.VOCABULARY_BROWSER), component, true); + DisposableComponent component = VocabularyGrid.create(viewContext); + return DefaultTabItem.create(getMessage(Dict.VOCABULARY_BROWSER), component, + true); } public String getId() { - return VocabularyBrowser.ID; + return VocabularyGrid.GRID_ID; } }; } diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/model/VocabularyModel.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/model/VocabularyModel.java index 44b1f2842e2900173a0668b6a0597a2b0d485757..cba213ca6f22fe6921f7d14fd3c5f1579d278e27 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/model/VocabularyModel.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/model/VocabularyModel.java @@ -16,57 +16,22 @@ package ch.systemsx.cisd.openbis.generic.client.web.client.application.model; -import java.util.ArrayList; -import java.util.List; - import com.extjs.gxt.ui.client.data.BaseModelData; import ch.systemsx.cisd.openbis.generic.client.shared.Vocabulary; +import ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.grid.IColumnDefinitionKind; /** * A {@link BaseModelData} extension suitable for {@link Vocabulary}. * * @author Christian Ribeaud */ -public final class VocabularyModel extends BaseModelData +public final class VocabularyModel extends AbstractEntityModel<Vocabulary> { - public static final String NEW_VOCABULARY_CODE = "(New Vocabulary)"; - private static final long serialVersionUID = 1L; - private VocabularyModel() - { - } - - public VocabularyModel(final Vocabulary vocabulary) - { - assert vocabulary != null : "Unspecified data type."; - set(ModelDataPropertyNames.CODE, vocabulary.getCode()); - set(ModelDataPropertyNames.DESCRIPTION, vocabulary.getDescription()); - set(ModelDataPropertyNames.IS_MANAGED_INTERNALLY, vocabulary.isManagedInternally()); - set(ModelDataPropertyNames.REGISTRATOR, vocabulary.getRegistrator()); - set(ModelDataPropertyNames.REGISTRATION_DATE, vocabulary.getRegistrationDate()); - set(ModelDataPropertyNames.OBJECT, vocabulary); - } - - public final static VocabularyModel createNewVocabularyVocabularyModel() - { - final VocabularyModel model = new VocabularyModel(); - model.set(ModelDataPropertyNames.CODE, NEW_VOCABULARY_CODE); - model.set(ModelDataPropertyNames.OBJECT, null); - return model; - } - - public final static List<VocabularyModel> convert(final List<Vocabulary> vocabularies) + public VocabularyModel(Vocabulary entity, IColumnDefinitionKind<Vocabulary>[] colDefKinds) { - assert vocabularies != null : "Unspecified vocabularies."; - final List<VocabularyModel> vocabularyModels = - new ArrayList<VocabularyModel>(vocabularies.size()); - for (final Vocabulary vocabulary : vocabularies) - { - vocabularyModels.add(new VocabularyModel(vocabulary)); - } - return vocabularyModels; + super(entity, colDefKinds, null); } - } diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/GridWithRPCProxy.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/GridWithRPCProxy.java deleted file mode 100644 index bd2cbb7f768a0a21fc9a2a11799c2bda8fabf006..0000000000000000000000000000000000000000 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/GridWithRPCProxy.java +++ /dev/null @@ -1,107 +0,0 @@ -/* - * 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.application.ui; - -import java.util.List; - -import com.extjs.gxt.ui.client.Style.SelectionMode; -import com.extjs.gxt.ui.client.data.BaseListLoadConfig; -import com.extjs.gxt.ui.client.data.BaseListLoadResult; -import com.extjs.gxt.ui.client.data.BaseListLoader; -import com.extjs.gxt.ui.client.data.ListLoader; -import com.extjs.gxt.ui.client.data.ModelData; -import com.extjs.gxt.ui.client.data.RpcProxy; -import com.extjs.gxt.ui.client.store.ListStore; -import com.extjs.gxt.ui.client.widget.grid.ColumnModel; -import com.extjs.gxt.ui.client.widget.grid.Grid; -import com.extjs.gxt.ui.client.widget.grid.GridView; -import com.google.gwt.user.client.rpc.AsyncCallback; - -import ch.systemsx.cisd.openbis.generic.client.web.client.application.AbstractAsyncCallback; -import ch.systemsx.cisd.openbis.generic.client.web.client.application.IViewContext; - -/** - * Grid with RPCProxy Loader. - * - * @author Izabela Adamczyk - */ -public abstract class GridWithRPCProxy<M, T extends ModelData> extends Grid<T> -{ - abstract protected void loadDataFromService(AsyncCallback<BaseListLoadResult<T>> callback); - - public GridWithRPCProxy(ColumnModel columnModel, String idPrefix) - { - super(null, null); - ListLoader<BaseListLoadConfig> loader = - new BaseListLoader<BaseListLoadConfig, BaseListLoadResult<T>>(createRpcProxy()); - reconfigure(new ListStore<T>(loader), columnModel); - setView(new GridView()); - getView().setForceFit(true); - setLoadMask(true); - getSelectionModel().setSelectionMode(SelectionMode.SINGLE); - setId(createId(idPrefix)); - } - - public static String createId(String idPrefix) - { - return idPrefix + "_grid"; - } - - public void load() - { - getStore().getLoader().load(); - } - - private final RpcProxy<BaseListLoadConfig, BaseListLoadResult<T>> createRpcProxy() - { - return new RpcProxy<BaseListLoadConfig, BaseListLoadResult<T>>() - { - @Override - public final void load(final BaseListLoadConfig loadConfig, - final AsyncCallback<BaseListLoadResult<T>> callback) - { - loadDataFromService(callback); - } - }; - } - - protected abstract class DelegatingAsyncCallback extends AbstractAsyncCallback<List<M>> - { - abstract protected List<T> convert(List<M> result); - - private final AsyncCallback<BaseListLoadResult<T>> delegate; - - public DelegatingAsyncCallback(IViewContext<?> viewContext, - final AsyncCallback<BaseListLoadResult<T>> callback) - { - super(viewContext); - this.delegate = callback; - } - - @Override - protected void finishOnFailure(final Throwable caught) - { - delegate.onFailure(caught); - } - - @Override - protected final void process(final List<M> result) - { - delegate.onSuccess(new BaseListLoadResult<T>(convert(result))); - } - } -} diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/property_type/PropertyTypeRegistrationForm.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/property_type/PropertyTypeRegistrationForm.java index 5112b7add19108ac36245bfc43abb62b50112e70..4c16fa887b6e700c22a4c390e07e8d6343d4188a 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/property_type/PropertyTypeRegistrationForm.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/property_type/PropertyTypeRegistrationForm.java @@ -16,6 +16,7 @@ package ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.property_type; +import com.extjs.gxt.ui.client.data.BaseModelData; import com.extjs.gxt.ui.client.event.SelectionChangedEvent; import com.extjs.gxt.ui.client.event.SelectionChangedListener; import com.extjs.gxt.ui.client.widget.LayoutContainer; @@ -32,7 +33,6 @@ import ch.systemsx.cisd.openbis.generic.client.web.client.application.IViewConte import ch.systemsx.cisd.openbis.generic.client.web.client.application.InfoBoxCallbackListener; import ch.systemsx.cisd.openbis.generic.client.web.client.application.model.DataTypeModel; import ch.systemsx.cisd.openbis.generic.client.web.client.application.model.ModelDataPropertyNames; -import ch.systemsx.cisd.openbis.generic.client.web.client.application.model.VocabularyModel; import ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.AbstractRegistrationForm; import ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.field.CodeField; import ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.field.VarcharField; @@ -155,9 +155,9 @@ public final class PropertyTypeRegistrationForm extends AbstractRegistrationForm propertyType.setDataType(selectedDataType); if (DataTypeCode.CONTROLLEDVOCABULARY.equals(selectedDataType.getCode())) { - final VocabularyModel vocabulary = + final BaseModelData vocabulary = GWTUtils.tryGetSingleSelectedModel(vocabularySelectionWidget); - if (VocabularyModel.NEW_VOCABULARY_CODE.equals(vocabulary + if (VocabularySelectionWidget.NEW_VOCABULARY_CODE.equals(vocabulary .get(ModelDataPropertyNames.CODE))) { propertyType.setVocabulary(vocabularyRegistrationFieldSet.createVocabulary()); diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/property_type/PropertyTypeSelectionWidget.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/property_type/PropertyTypeSelectionWidget.java index 40e727ced2210553150a60fd7992910ab3f4360b..91e84ffb96be896dcc770f0fe519d62b7ac7c787 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/property_type/PropertyTypeSelectionWidget.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/property_type/PropertyTypeSelectionWidget.java @@ -32,6 +32,8 @@ import ch.systemsx.cisd.openbis.generic.client.web.client.application.GenericCon import ch.systemsx.cisd.openbis.generic.client.web.client.application.IViewContext; import ch.systemsx.cisd.openbis.generic.client.web.client.application.model.ModelDataPropertyNames; import ch.systemsx.cisd.openbis.generic.client.web.client.application.util.GWTUtils; +import ch.systemsx.cisd.openbis.generic.client.web.client.dto.DefaultResultSetConfig; +import ch.systemsx.cisd.openbis.generic.client.web.client.dto.ResultSet; /** * {@link ComboBox} containing list of property type codes loaded from the server. @@ -95,14 +97,18 @@ public final class PropertyTypeSelectionWidget extends void refresh() { - viewContext.getService().listPropertyTypes(new ListPropertyTypesCallback(viewContext)); + DefaultResultSetConfig<String, PropertyType> config = + DefaultResultSetConfig.createFetchAll(); + viewContext.getService().listPropertyTypes(config, + new ListPropertyTypesCallback(viewContext)); } // // Helper classes // - public final class ListPropertyTypesCallback extends AbstractAsyncCallback<List<PropertyType>> + public final class ListPropertyTypesCallback extends + AbstractAsyncCallback<ResultSet<PropertyType>> { ListPropertyTypesCallback(final IViewContext<ICommonClientServiceAsync> viewContext) { @@ -110,11 +116,11 @@ public final class PropertyTypeSelectionWidget extends } @Override - protected void process(final List<PropertyType> result) + protected void process(final ResultSet<PropertyType> result) { final ListStore<PropertyTypeComboModel> propertyTypeStore = getStore(); propertyTypeStore.removeAll(); - propertyTypeStore.add(convert(result)); + propertyTypeStore.add(convert(result.getList())); if (propertyTypeStore.getCount() > 0) { setEnabled(true); diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/property_type/VocabularySelectionWidgetForPropertyTypeRegistration.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/property_type/VocabularySelectionWidgetForPropertyTypeRegistration.java index 5af296c8def30d5b0c8cd551ea9c8c0cc7cc2c27..672cf4cc39da6a45dfe6dbad01ee4500f989d0e4 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/property_type/VocabularySelectionWidgetForPropertyTypeRegistration.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/property_type/VocabularySelectionWidgetForPropertyTypeRegistration.java @@ -2,6 +2,7 @@ package ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.proper import java.util.List; +import com.extjs.gxt.ui.client.data.BaseModelData; import com.extjs.gxt.ui.client.event.SelectionChangedEvent; import com.extjs.gxt.ui.client.event.SelectionChangedListener; @@ -9,7 +10,6 @@ import ch.systemsx.cisd.openbis.generic.client.shared.Vocabulary; 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.model.ModelDataPropertyNames; -import ch.systemsx.cisd.openbis.generic.client.web.client.application.model.VocabularyModel; import ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.vocabulary.VocabularyRegistrationFieldSet; import ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.vocabulary.VocabularySelectionWidget; @@ -30,7 +30,7 @@ final class VocabularySelectionWidgetForPropertyTypeRegistration extends Vocabul super(viewContext); assert vocabularyRegistrationFieldSet != null : "Unspecified VocabularyRegistrationFieldSet"; this.vocabularyRegistrationFieldSet = vocabularyRegistrationFieldSet; - addSelectionChangedListener(new SelectionChangedListener<VocabularyModel>() + addSelectionChangedListener(new SelectionChangedListener<BaseModelData>() { // @@ -38,15 +38,15 @@ final class VocabularySelectionWidgetForPropertyTypeRegistration extends Vocabul // @Override - public final void selectionChanged(final SelectionChangedEvent<VocabularyModel> se) + public final void selectionChanged(final SelectionChangedEvent<BaseModelData> se) { - final VocabularyModel selectedItem = se.getSelectedItem(); + final BaseModelData selectedItem = se.getSelectedItem(); final boolean visible; if (selectedItem != null) { visible = selectedItem.get(ModelDataPropertyNames.CODE).equals( - VocabularyModel.NEW_VOCABULARY_CODE); + NEW_VOCABULARY_CODE); } else { visible = false; @@ -75,6 +75,6 @@ final class VocabularySelectionWidgetForPropertyTypeRegistration extends Vocabul protected final void refreshStore(final List<Vocabulary> result) { super.refreshStore(result); - getStore().insert(VocabularyModel.createNewVocabularyVocabularyModel(), 0); + getStore().insert(createNewVocabularyVocabularyModel(), 0); } } \ No newline at end of file diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/vocabulary/VocabularyBrowser.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/vocabulary/VocabularyBrowser.java deleted file mode 100644 index fd407cd08bffbc0060d834e2709c0c5b67218b66..0000000000000000000000000000000000000000 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/vocabulary/VocabularyBrowser.java +++ /dev/null @@ -1,85 +0,0 @@ -/* - * 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.ui.vocabulary; - -import com.extjs.gxt.ui.client.store.Store; -import com.extjs.gxt.ui.client.widget.ContentPanel; -import com.extjs.gxt.ui.client.widget.layout.FitLayout; -import com.extjs.gxt.ui.client.widget.toolbar.AdapterToolItem; -import com.extjs.gxt.ui.client.widget.toolbar.LabelToolItem; -import com.extjs.gxt.ui.client.widget.toolbar.ToolBar; -import com.google.gwt.user.client.Element; - -import ch.systemsx.cisd.openbis.generic.client.web.client.ICommonClientServiceAsync; -import ch.systemsx.cisd.openbis.generic.client.web.client.application.CommonViewContext; -import ch.systemsx.cisd.openbis.generic.client.web.client.application.Dict; -import ch.systemsx.cisd.openbis.generic.client.web.client.application.GenericConstants; -import ch.systemsx.cisd.openbis.generic.client.web.client.application.IViewContext; -import ch.systemsx.cisd.openbis.generic.client.web.client.application.model.ModelDataPropertyNames; -import ch.systemsx.cisd.openbis.generic.client.web.client.application.model.VocabularyModel; -import ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.ColumnFilter; - -/** - * A {@link ContentPanel} extension for browsing the vocabularies. - * - * @author Izabela Adamczyk - */ -public final class VocabularyBrowser extends ContentPanel -{ - private static final String PREFIX = "vocabulary-browser"; - - public static final String ID = GenericConstants.ID_PREFIX + PREFIX; - - private final IViewContext<ICommonClientServiceAsync> viewContext; - - private VocabularyGrid grid; - - private ToolBar toolbar; - - public VocabularyBrowser(final CommonViewContext viewContext) - { - this.viewContext = viewContext; - setLayout(new FitLayout()); - setHeading(viewContext.getMessage(Dict.VOCABULARY_BROWSER)); - setId(ID); - grid = new VocabularyGrid(viewContext, ID); - add(grid); - setBottomComponent(getToolbar()); - } - - private ToolBar getToolbar() - { - if (toolbar == null) - { - toolbar = new ToolBar(); - toolbar.add(new LabelToolItem("Filter:")); - Store<VocabularyModel> store = grid.getStore(); - toolbar.add(new AdapterToolItem(new ColumnFilter<VocabularyModel>(store, - ModelDataPropertyNames.CODE, viewContext.getMessage(Dict.CODE)))); - } - return toolbar; - } - - @Override - protected void onRender(final Element parent, final int pos) - { - super.onRender(parent, pos); - layout(); - grid.load(); - } - -} diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/vocabulary/VocabularyColDefKind.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/vocabulary/VocabularyColDefKind.java new file mode 100644 index 0000000000000000000000000000000000000000..9d993e6c1c9487857abc132f26de1f26e9e2a5e7 --- /dev/null +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/vocabulary/VocabularyColDefKind.java @@ -0,0 +1,107 @@ +/* + * 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.application.ui.vocabulary; + +import ch.systemsx.cisd.openbis.generic.client.shared.Vocabulary; +import ch.systemsx.cisd.openbis.generic.client.web.client.application.Dict; +import ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.grid.AbstractColumnDefinitionKind; +import ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.grid.IColumnDefinitionKind; +import ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.sample.renderer.SimpleYesNoRenderer; + +/** + * @author Tomasz Pylak + */ +public enum VocabularyColDefKind implements IColumnDefinitionKind<Vocabulary> +{ + CODE(new AbstractColumnDefinitionKind<Vocabulary>(Dict.CODE) + { + @Override + public String tryGetValue(Vocabulary entity) + { + return entity.getCode(); + } + }), + + DESCRIPTION(new AbstractColumnDefinitionKind<Vocabulary>(Dict.DESCRIPTION) + { + @Override + public String tryGetValue(Vocabulary entity) + { + return entity.getDescription(); + } + }), + + IS_MANAGED_INTERNALLY(new AbstractColumnDefinitionKind<Vocabulary>(Dict.IS_MANAGED_INTERNALLY) + { + @Override + public String tryGetValue(Vocabulary entity) + { + return SimpleYesNoRenderer.render(entity.isManagedInternally()); + } + }), + + REGISTRATOR(new AbstractColumnDefinitionKind<Vocabulary>(Dict.REGISTRATOR) + { + @Override + public String tryGetValue(Vocabulary entity) + { + return renderRegistrator(entity); + } + }), + + REGISTRATION_DATE(new AbstractColumnDefinitionKind<Vocabulary>(Dict.REGISTRATION_DATE, + AbstractColumnDefinitionKind.DATE_COLUMN_WIDTH, false) + { + @Override + public String tryGetValue(Vocabulary entity) + { + return renderRegistrationDate(entity); + } + }); + + private final AbstractColumnDefinitionKind<Vocabulary> columnDefinitionKind; + + private VocabularyColDefKind(AbstractColumnDefinitionKind<Vocabulary> columnDefinitionKind) + { + this.columnDefinitionKind = columnDefinitionKind; + } + + public String getHeaderMsgKey() + { + return columnDefinitionKind.getHeaderMsgKey(); + } + + public int getWidth() + { + return columnDefinitionKind.getWidth(); + } + + public String id() + { + return name(); + } + + public boolean isHidden() + { + return columnDefinitionKind.isHidden(); + } + + public String tryGetValue(Vocabulary entity) + { + return columnDefinitionKind.tryGetValue(entity); + } +} diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/vocabulary/VocabularyGrid.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/vocabulary/VocabularyGrid.java index c74d63afddc860d1ca0b33b79fafe24bca93b044..d395b5061f598cecc11c4da42c44ba35cd244f9a 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/vocabulary/VocabularyGrid.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/vocabulary/VocabularyGrid.java @@ -16,87 +16,65 @@ package ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.vocabulary; -import java.util.ArrayList; -import java.util.List; - -import com.extjs.gxt.ui.client.data.BaseListLoadResult; -import com.extjs.gxt.ui.client.widget.grid.ColumnConfig; -import com.extjs.gxt.ui.client.widget.grid.ColumnModel; -import com.google.gwt.user.client.rpc.AsyncCallback; - import ch.systemsx.cisd.openbis.generic.client.shared.Vocabulary; -import ch.systemsx.cisd.openbis.generic.client.web.client.application.CommonViewContext; -import ch.systemsx.cisd.openbis.generic.client.web.client.application.Dict; +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.GenericConstants; import ch.systemsx.cisd.openbis.generic.client.web.client.application.IViewContext; -import ch.systemsx.cisd.openbis.generic.client.web.client.application.model.ModelDataPropertyNames; import ch.systemsx.cisd.openbis.generic.client.web.client.application.model.VocabularyModel; -import ch.systemsx.cisd.openbis.generic.client.web.client.application.renderer.DateRenderer; -import ch.systemsx.cisd.openbis.generic.client.web.client.application.renderer.YesNoRenderer; -import ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.ColumnConfigFactory; -import ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.GridWithRPCProxy; +import ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.grid.AbstractSimpleBrowserGrid; +import ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.grid.DisposableComponent; +import ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.grid.IColumnDefinitionKind; +import ch.systemsx.cisd.openbis.generic.client.web.client.dto.DefaultResultSetConfig; +import ch.systemsx.cisd.openbis.generic.client.web.client.dto.ResultSet; +import ch.systemsx.cisd.openbis.generic.client.web.client.dto.TableExportCriteria; /** - * {@link GridWithRPCProxy} displaying vocabularies. + * Grid displaying vocabularies. * - * @author Izabela Adamczyk + * @author Tomasz Pylak */ -public class VocabularyGrid extends GridWithRPCProxy<Vocabulary, VocabularyModel> +public class VocabularyGrid extends AbstractSimpleBrowserGrid<Vocabulary, VocabularyModel> { - private final CommonViewContext viewContext; + // browser consists of the grid and the paging toolbar + public static final String BROWSER_ID = GenericConstants.ID_PREFIX + "vocabulary-browser"; + + public static final String GRID_ID = BROWSER_ID + "_grid"; - public VocabularyGrid(final CommonViewContext viewContext, String idPrefix) + public static DisposableComponent create( + final IViewContext<ICommonClientServiceAsync> viewContext) { - super(createColumnModel(viewContext), idPrefix); - this.viewContext = viewContext; + return new VocabularyGrid(viewContext).asDisposableWithoutToolbar(); } - private static ColumnModel createColumnModel(IViewContext<?> context) + private VocabularyGrid(IViewContext<ICommonClientServiceAsync> viewContext) { - final ArrayList<ColumnConfig> configs = new ArrayList<ColumnConfig>(); - configs.add(ColumnConfigFactory.createCodeColumnConfig(context)); - configs.add(ColumnConfigFactory.createDefaultColumnConfig(context - .getMessage(Dict.DESCRIPTION), ModelDataPropertyNames.DESCRIPTION)); - final ColumnConfig internallyManaged = - ColumnConfigFactory.createDefaultColumnConfig(context - .getMessage(Dict.IS_MANAGED_INTERNALLY), - ModelDataPropertyNames.IS_MANAGED_INTERNALLY); - internallyManaged.setRenderer(new YesNoRenderer()); - configs.add(internallyManaged); - - final ColumnConfig registratorColumnConfig = - ColumnConfigFactory.createDefaultColumnConfig(context.getMessage(Dict.REGISTRATOR), - ModelDataPropertyNames.REGISTRATOR); - configs.add(registratorColumnConfig); - - final ColumnConfig registrationDateColumnConfig = - ColumnConfigFactory.createDefaultColumnConfig(context - .getMessage(Dict.REGISTRATION_DATE), - ModelDataPropertyNames.REGISTRATION_DATE); - registrationDateColumnConfig.setDateTimeFormat(DateRenderer.DEFAULT_DATE_TIME_FORMAT); - configs.add(registrationDateColumnConfig); + super(viewContext, BROWSER_ID, GRID_ID); + } - return new ColumnModel(configs); + @Override + protected IColumnDefinitionKind<Vocabulary>[] getStaticColumnsDefinition() + { + return VocabularyColDefKind.values(); } @Override - protected void loadDataFromService(AsyncCallback<BaseListLoadResult<VocabularyModel>> callback) + protected VocabularyModel createModel(Vocabulary entity) { - viewContext.getService().listVocabularies(true, false, - new ListVocabulariesCallback(viewContext, callback)); + return new VocabularyModel(entity, getStaticColumnsDefinition()); } - class ListVocabulariesCallback extends DelegatingAsyncCallback + @Override + protected void listEntities(DefaultResultSetConfig<String, Vocabulary> resultSetConfig, + AbstractAsyncCallback<ResultSet<Vocabulary>> callback) { - public ListVocabulariesCallback(IViewContext<?> context, - AsyncCallback<BaseListLoadResult<VocabularyModel>> callback) - { - super(context, callback); - } + viewContext.getService().listVocabularies(true, false, resultSetConfig, callback); + } - @Override - protected List<VocabularyModel> convert(List<Vocabulary> result) - { - return VocabularyModel.convert(result); - } + @Override + protected void prepareExportEntities(TableExportCriteria<Vocabulary> exportCriteria, + AbstractAsyncCallback<String> callback) + { + viewContext.getService().prepareExportVocabularies(exportCriteria, callback); } } \ No newline at end of file diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/vocabulary/VocabularySelectionWidget.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/vocabulary/VocabularySelectionWidget.java index fc0afa0ca485151c301daf9b44451aa44979a27d..e03c4475534f4a2f7371b692e5281fc106ace4df 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/vocabulary/VocabularySelectionWidget.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/vocabulary/VocabularySelectionWidget.java @@ -16,8 +16,10 @@ package ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.vocabulary; +import java.util.ArrayList; import java.util.List; +import com.extjs.gxt.ui.client.data.BaseModelData; import com.extjs.gxt.ui.client.store.ListStore; import com.extjs.gxt.ui.client.widget.form.ComboBox; @@ -28,16 +30,19 @@ import ch.systemsx.cisd.openbis.generic.client.web.client.application.Dict; import ch.systemsx.cisd.openbis.generic.client.web.client.application.GenericConstants; import ch.systemsx.cisd.openbis.generic.client.web.client.application.IViewContext; import ch.systemsx.cisd.openbis.generic.client.web.client.application.model.ModelDataPropertyNames; -import ch.systemsx.cisd.openbis.generic.client.web.client.application.model.VocabularyModel; import ch.systemsx.cisd.openbis.generic.client.web.client.application.util.GWTUtils; +import ch.systemsx.cisd.openbis.generic.client.web.client.dto.DefaultResultSetConfig; +import ch.systemsx.cisd.openbis.generic.client.web.client.dto.ResultSet; /** * A {@link ComboBox} extension for selecting a {@link Vocabulary}. * * @author Christian Ribeaud */ -public class VocabularySelectionWidget extends ComboBox<VocabularyModel> +public class VocabularySelectionWidget extends ComboBox<BaseModelData> { + public static final String NEW_VOCABULARY_CODE = "(New Vocabulary)"; + private static final String PREFIX = "vocabulary-select"; public static final String ID = GenericConstants.ID_PREFIX + PREFIX; @@ -53,7 +58,7 @@ public class VocabularySelectionWidget extends ComboBox<VocabularyModel> setEditable(false); setWidth(100); setFieldLabel(viewContext.getMessage(Dict.VOCABULARY)); - setStore(new ListStore<VocabularyModel>()); + setStore(new ListStore<BaseModelData>()); } /** @@ -68,7 +73,9 @@ public class VocabularySelectionWidget extends ComboBox<VocabularyModel> private final void loadVocabularies() { - viewContext.getService().listVocabularies(false, true, + DefaultResultSetConfig<String, Vocabulary> criteria = + DefaultResultSetConfig.createFetchAll(); + viewContext.getService().listVocabularies(false, true, criteria, new ListVocabulariesCallback(viewContext)); } @@ -77,9 +84,9 @@ public class VocabularySelectionWidget extends ComboBox<VocabularyModel> */ protected void refreshStore(final List<Vocabulary> result) { - final ListStore<VocabularyModel> vocabularyStore = getStore(); + final ListStore<BaseModelData> vocabularyStore = getStore(); vocabularyStore.removeAll(); - vocabularyStore.add(VocabularyModel.convert(result)); + vocabularyStore.add(convert(result)); setEnabled(true); if (vocabularyStore.getCount() > 0) { @@ -95,6 +102,34 @@ public class VocabularySelectionWidget extends ComboBox<VocabularyModel> // ComboBox // + private static List<BaseModelData> convert(List<Vocabulary> list) + { + final List<BaseModelData> result = new ArrayList<BaseModelData>(); + for (final Vocabulary vocabulary : list) + { + result.add(createModel(vocabulary)); + } + return result; + } + + private static BaseModelData createModel(Vocabulary vocabulary) + { + return createModel(vocabulary, vocabulary.getCode()); + } + + protected final static BaseModelData createNewVocabularyVocabularyModel() + { + return createModel(null, NEW_VOCABULARY_CODE); + } + + private static BaseModelData createModel(Object object, String code) + { + final BaseModelData model = new BaseModelData(); + model.set(ModelDataPropertyNames.CODE, code); + model.set(ModelDataPropertyNames.OBJECT, object); + return model; + } + @Override protected final void afterRender() { @@ -106,7 +141,8 @@ public class VocabularySelectionWidget extends ComboBox<VocabularyModel> // Helper classes // - public final class ListVocabulariesCallback extends AbstractAsyncCallback<List<Vocabulary>> + public final class ListVocabulariesCallback extends + AbstractAsyncCallback<ResultSet<Vocabulary>> { ListVocabulariesCallback(final IViewContext<ICommonClientServiceAsync> viewContext) { @@ -118,9 +154,9 @@ public class VocabularySelectionWidget extends ComboBox<VocabularyModel> // @Override - protected final void process(final List<Vocabulary> result) + protected final void process(final ResultSet<Vocabulary> result) { - refreshStore(result); + refreshStore(result.getList()); } } diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/dto/IResultSetConfig.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/dto/IResultSetConfig.java index 25d68941dfec78b2f634cbb8714108685dd63038..5f5d708100323f20286e9227bf741cc037ccd27a 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/dto/IResultSetConfig.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/dto/IResultSetConfig.java @@ -30,9 +30,6 @@ public interface IResultSetConfig<K, T> extends IResultSetKeyHolder<K> { public static final int NO_LIMIT = -1; - /** offset which should be used to start fetching from the first element */ - public static final int FIRST_ELEM_OFFSET = 0; - /** * The offset for the first record to retrieve. */ 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 007342046c13e7b140a8da74f2493c74cf70c168..e8dc7cbf35c33916b7893cf6f8a34841fbec4f22 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 @@ -161,9 +161,7 @@ public final class CommonClientService extends AbstractClientService implements private static <T> IResultSetConfig<String, T> createExportListCriteria( final TableExportCriteria<T> exportCriteria) { - final DefaultResultSetConfig<String, T> criteria = new DefaultResultSetConfig<String, T>(); - criteria.setLimit(IResultSetConfig.NO_LIMIT); - criteria.setOffset(IResultSetConfig.FIRST_ELEM_OFFSET); + final DefaultResultSetConfig<String, T> criteria = DefaultResultSetConfig.createFetchAll(); criteria.setSortInfo(exportCriteria.getSortInfo()); criteria.setResultSetKey(exportCriteria.getResultSetKey()); return criteria; @@ -452,6 +450,12 @@ public final class CommonClientService extends AbstractClientService implements return prepareExportEntities(criteria); } + public String prepareExportVocabularies(final TableExportCriteria<Vocabulary> criteria) + throws UserFailureException + { + return prepareExportEntities(criteria); + } + // ---------------- methods which list entities using cache public final ResultSet<Sample> listSamples(final ListSampleCriteria listCriteria) @@ -562,6 +566,35 @@ public final class CommonClientService extends AbstractClientService implements } } + public ResultSet<Vocabulary> listVocabularies(final boolean withTerms, + final boolean excludeInternal, DefaultResultSetConfig<String, Vocabulary> criteria) + throws UserFailureException + { + return listEntities(criteria, new IOriginalDataProvider<Vocabulary>() + { + public List<Vocabulary> getOriginalData() throws UserFailureException + { + return listVocabularies(withTerms, excludeInternal); + } + }); + } + + private List<Vocabulary> listVocabularies(final boolean withTerms, boolean excludeInternal) + throws ch.systemsx.cisd.openbis.generic.client.web.client.exception.UserFailureException + { + try + { + final String sessionToken = getSessionToken(); + final List<VocabularyPE> vocabularies = + commonServer.listVocabularies(sessionToken, withTerms, excludeInternal); + return BeanUtils.createBeanList(Vocabulary.class, vocabularies, DtoConverters + .getVocabularyConverter()); + } catch (final UserFailureException e) + { + throw UserFailureExceptionTranslator.translate(e); + } + } + // ---------------- end list using cache ---------- public final List<ExternalData> listExternalData(final String sampleIdentifier) @@ -635,7 +668,7 @@ public final class CommonClientService extends AbstractClientService implements } } - public List<PropertyType> listPropertyTypes() + private List<PropertyType> listPropertyTypes() throws ch.systemsx.cisd.openbis.generic.client.web.client.exception.UserFailureException { try @@ -664,22 +697,6 @@ public final class CommonClientService extends AbstractClientService implements } } - public final List<Vocabulary> listVocabularies(final boolean withTerms, boolean excludeInternal) - throws ch.systemsx.cisd.openbis.generic.client.web.client.exception.UserFailureException - { - try - { - final String sessionToken = getSessionToken(); - final List<VocabularyPE> vocabularies = - commonServer.listVocabularies(sessionToken, withTerms, excludeInternal); - return BeanUtils.createBeanList(Vocabulary.class, vocabularies, DtoConverters - .getVocabularyConverter()); - } catch (final UserFailureException e) - { - throw UserFailureExceptionTranslator.translate(e); - } - } - public String assignPropertyType(final EntityKind entityKind, final String propertyTypeCode, final String entityTypeCode, final boolean isMandatory, final String defaultValue) throws ch.systemsx.cisd.openbis.generic.client.web.client.exception.UserFailureException diff --git a/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/client/web/server/CommonClientServiceTest.java b/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/client/web/server/CommonClientServiceTest.java index fa4463c938ce79592551cddfd1a3e582a8431739..7c93132e419e629d7e1342229ce4bfd402ba4d14 100644 --- a/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/client/web/server/CommonClientServiceTest.java +++ b/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/client/web/server/CommonClientServiceTest.java @@ -29,6 +29,7 @@ import ch.systemsx.cisd.openbis.generic.client.shared.PropertyType; import ch.systemsx.cisd.openbis.generic.client.shared.SampleType; import ch.systemsx.cisd.openbis.generic.client.shared.Vocabulary; import ch.systemsx.cisd.openbis.generic.client.shared.VocabularyTerm; +import ch.systemsx.cisd.openbis.generic.client.web.client.dto.DefaultResultSetConfig; import ch.systemsx.cisd.openbis.generic.client.web.client.dto.ExternalData; import ch.systemsx.cisd.openbis.generic.client.web.client.dto.ListSampleCriteria; import ch.systemsx.cisd.openbis.generic.client.web.client.dto.ResultSet; @@ -278,8 +279,10 @@ public final class CommonClientServiceTest extends AbstractClientServiceTest will(returnValue(Collections.singletonList(vocabularyPE))); } }); + DefaultResultSetConfig<String, Vocabulary> criteria = + DefaultResultSetConfig.createFetchAll(); final List<Vocabulary> vocabularies = - commonClientService.listVocabularies(false, excludeInternals); + commonClientService.listVocabularies(false, excludeInternals, criteria).getList(); assertEquals(1, vocabularies.size()); assertVocabularyEquals(vocabularyPE, vocabularies.get(0)); context.assertIsSatisfied();