From 7567af4ef9b3ee018d695e27a88e937f346bdfbc Mon Sep 17 00:00:00 2001 From: izabel <izabel> Date: Mon, 23 Feb 2009 14:59:10 +0000 Subject: [PATCH] [LMS-717] browsing of materials - missing files SVN: 9930 --- .../application/model/MaterialModel.java | 99 +++++++++++++++++++ .../application/model/MaterialTypeModel.java | 53 ++++++++++ .../ui/material/CheckMaterialTable.java | 35 +++++++ .../ui/material/ListMaterials.java | 65 ++++++++++++ .../application/ui/material/MaterialRow.java | 66 +++++++++++++ 5 files changed, 318 insertions(+) create mode 100644 openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/model/MaterialModel.java create mode 100644 openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/model/MaterialTypeModel.java create mode 100644 openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/material/CheckMaterialTable.java create mode 100644 openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/material/ListMaterials.java create mode 100644 openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/material/MaterialRow.java diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/model/MaterialModel.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/model/MaterialModel.java new file mode 100644 index 00000000000..178132c06e9 --- /dev/null +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/model/MaterialModel.java @@ -0,0 +1,99 @@ +/* + * 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.model; + +import java.util.ArrayList; +import java.util.List; + +import com.extjs.gxt.ui.client.data.ModelData; + +import ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.columns.framework.IColumnDefinitionUI; +import ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.columns.specific.material.CommonMaterialColDefKind; +import ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.columns.specific.material.PropertyMaterialColDef; +import ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.grid.ColumnDefsAndConfigs; +import ch.systemsx.cisd.openbis.generic.client.web.client.application.util.IMessageProvider; +import ch.systemsx.cisd.openbis.generic.client.web.client.dto.Material; +import ch.systemsx.cisd.openbis.generic.shared.basic.dto.MaterialProperty; +import ch.systemsx.cisd.openbis.generic.shared.basic.dto.MaterialType; +import ch.systemsx.cisd.openbis.generic.shared.basic.dto.MaterialTypePropertyType; + +/** + * {@link ModelData} for {@link Material} + * + * @author Izabela Adamczyk + */ +public final class MaterialModel extends BaseEntityModel<Material> +{ + private static final long serialVersionUID = 1L; + + public MaterialModel(final Material entity) + { + super(entity, createColumnsSchema(entity)); + } + + // here we create the columns definition having just one table row. We need them only to render + // column values (headers have been already created), so no message provider is needed. + private static List<IColumnDefinitionUI<Material>> createColumnsSchema(Material entity) + { + List<IColumnDefinitionUI<Material>> list = createCommonColumnsSchema(null); + for (MaterialProperty prop : entity.getProperties()) + { + MaterialTypePropertyType etpt = prop.getEntityTypePropertyType(); + list.add(new PropertyMaterialColDef(etpt.getPropertyType())); + } + return list; + } + + public static ColumnDefsAndConfigs<Material> createColumnsSchema( + IMessageProvider messageProvider, MaterialType selectedTypeOrNull) + { + List<IColumnDefinitionUI<Material>> commonColumnsSchema = + createCommonColumnsSchema(messageProvider); + ColumnDefsAndConfigs<Material> columns = ColumnDefsAndConfigs.create(commonColumnsSchema); + if (selectedTypeOrNull != null) + { + List<IColumnDefinitionUI<Material>> propertyColumnsSchema = + createPropertyColumnsSchema(selectedTypeOrNull); + columns.addColumns(propertyColumnsSchema); + } + return columns; + } + + private static List<IColumnDefinitionUI<Material>> createPropertyColumnsSchema( + MaterialType selectedType) + { + List<MaterialTypePropertyType> entityTypePropertyTypes = + selectedType.getMaterialTypePropertyTypes(); + List<IColumnDefinitionUI<Material>> list = createColDefList(); + for (MaterialTypePropertyType etpt : entityTypePropertyTypes) + { + list.add(new PropertyMaterialColDef(etpt.getPropertyType())); + } + return list; + } + + private static List<IColumnDefinitionUI<Material>> createCommonColumnsSchema( + IMessageProvider msgProviderOrNull) + { + return createColumnsDefinition(CommonMaterialColDefKind.values(), msgProviderOrNull); + } + + private static ArrayList<IColumnDefinitionUI<Material>> createColDefList() + { + return new ArrayList<IColumnDefinitionUI<Material>>(); + } +} diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/model/MaterialTypeModel.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/model/MaterialTypeModel.java new file mode 100644 index 00000000000..96c428f5ff7 --- /dev/null +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/model/MaterialTypeModel.java @@ -0,0 +1,53 @@ +/* + * 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.model; + +import java.util.ArrayList; +import java.util.List; + +import com.extjs.gxt.ui.client.data.BaseModelData; +import com.extjs.gxt.ui.client.data.ModelData; + +import ch.systemsx.cisd.openbis.generic.shared.basic.dto.MaterialType; + +/** + * {@link ModelData} for {@link MaterialType}. + * + * @author Izabela Adamczyk + */ +public class MaterialTypeModel extends BaseModelData +{ + + private static final long serialVersionUID = 1L; + + public MaterialTypeModel(final MaterialType type) + { + set(ModelDataPropertyNames.CODE, type.getCode()); + set(ModelDataPropertyNames.OBJECT, type); + } + + public final static List<MaterialTypeModel> convert(final List<MaterialType> types) + { + final List<MaterialTypeModel> result = new ArrayList<MaterialTypeModel>(); + for (final MaterialType st : types) + { + result.add(new MaterialTypeModel(st)); + } + return result; + } + +} diff --git a/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/material/CheckMaterialTable.java b/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/material/CheckMaterialTable.java new file mode 100644 index 00000000000..5312c1d3bd1 --- /dev/null +++ b/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/material/CheckMaterialTable.java @@ -0,0 +1,35 @@ +/* + * 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.material; + +import ch.systemsx.cisd.openbis.generic.client.web.client.testframework.AbstractDefaultTestCommand; +import ch.systemsx.cisd.openbis.generic.client.web.client.testframework.CheckTableCommand; + +/** + * A {@link AbstractDefaultTestCommand} extension to check whether a list of materials has been + * loaded. + * + * @author Izabela Adamczyk + */ +public class CheckMaterialTable extends CheckTableCommand +{ + public CheckMaterialTable() + { + super(MaterialBrowserGrid.GRID_ID, MaterialBrowserGrid.ListEntitiesCallback.class); + } + +} diff --git a/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/material/ListMaterials.java b/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/material/ListMaterials.java new file mode 100644 index 00000000000..8004c5a2617 --- /dev/null +++ b/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/material/ListMaterials.java @@ -0,0 +1,65 @@ +/* + * 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.material; + +import com.extjs.gxt.ui.client.widget.button.Button; +import com.extjs.gxt.ui.client.widget.form.ComboBox; + +import ch.systemsx.cisd.openbis.generic.client.web.client.application.model.MaterialTypeModel; +import ch.systemsx.cisd.openbis.generic.client.web.client.application.model.ModelDataPropertyNames; +import ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.grid.BrowserGridPagingToolBar; +import ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.material.MaterialTypeSelectionWidget; +import ch.systemsx.cisd.openbis.generic.client.web.client.application.util.GWTUtils; +import ch.systemsx.cisd.openbis.generic.client.web.client.testframework.AbstractDefaultTestCommand; +import ch.systemsx.cisd.openbis.generic.client.web.client.testframework.GWTTestUtil; + +/** + * A {@link AbstractDefaultTestCommand} extension for creating materials list. + * + * @author Izabela Adamczyk + */ +public class ListMaterials extends AbstractDefaultTestCommand +{ + private final String materialTypeName; + + public ListMaterials(final String materialTypeNameOrNull) + { + this.materialTypeName = materialTypeNameOrNull; + addCallbackClass(MaterialTypeSelectionWidget.ListItemsCallback.class); + } + + // + // AbstractDefaultTestCommand + // + + public void execute() + { + + final ComboBox<MaterialTypeModel> typeSelector = + (MaterialTypeSelectionWidget) GWTTestUtil + .getWidgetWithID(MaterialTypeSelectionWidget.ID + + MaterialTypeSelectionWidget.SUFFIX + MaterialBrowserToolbar.ID); + + GWTUtils.setSelectedItem(typeSelector, ModelDataPropertyNames.CODE, + materialTypeName); + + final Button refresh = + (Button) GWTTestUtil.getWidgetWithID(BrowserGridPagingToolBar.REFRESH_BUTTON_ID); + assertTrue(refresh.isEnabled()); + GWTTestUtil.clickButtonWithID(BrowserGridPagingToolBar.REFRESH_BUTTON_ID); + } +} diff --git a/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/material/MaterialRow.java b/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/material/MaterialRow.java new file mode 100644 index 00000000000..7d750642ea3 --- /dev/null +++ b/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/material/MaterialRow.java @@ -0,0 +1,66 @@ +/* + * 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.material; + +import ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.columns.specific.material.CommonMaterialColDefKind; +import ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.columns.specific.material.PropertyMaterialColDef; +import ch.systemsx.cisd.openbis.generic.client.web.client.testframework.Row; +import ch.systemsx.cisd.openbis.generic.shared.basic.dto.PropertyType; + +/** + * Allows to define material table row expectations. + * + * @author Izabela Adamczyk + */ +public class MaterialRow extends Row +{ + + public MaterialRow(final String code) + { + super(); + withCell(CommonMaterialColDefKind.CODE.id(), code); + } + + public final MaterialRow userProperty(final String propertyCode, final Object value) + { + return property(propertyCode, value, false); + } + + public final MaterialRow internalProperty(final String propertyCode, final Object value) + { + return property(propertyCode, value, true); + } + + private final MaterialRow property(final String propertyCode, final Object value, + boolean internalNamespace) + { + final PropertyType propertyType = createPropertyType(propertyCode, internalNamespace); + final String propertyIdentifier = new PropertyMaterialColDef(propertyType).getIdentifier(); + withCell(propertyIdentifier, value); + return this; + } + + private final static PropertyType createPropertyType(final String propertyCode, + boolean internalNamespace) + { + final PropertyType propertyType = new PropertyType(); + propertyType.setInternalNamespace(internalNamespace); + propertyType.setSimpleCode(propertyCode); + return propertyType; + } + +} -- GitLab