From 7d0442e07d7320ef47ac89120827f09c4fa89cfc Mon Sep 17 00:00:00 2001 From: buczekp <buczekp> Date: Fri, 17 Dec 2010 10:59:30 +0000 Subject: [PATCH] [LMS-1948] fixed rendering of specific properties SVN: 19190 --- .../renderer/AbstractPropertyColRenderer.java | 1 + .../renderer/TimestampStringCellRenderer.java | 54 ++++++++++++ .../VocabularyTermStringCellRenderer.java | 36 ++++++++ .../client/application/ui/TypedTableGrid.java | 41 +++++++-- .../basic/dto/VocabularyTermTableCell.java | 84 +++++++++++++++++++ .../shared/util/TypedTableModelBuilder.java | 17 ++-- 6 files changed, 221 insertions(+), 12 deletions(-) create mode 100644 openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/renderer/TimestampStringCellRenderer.java create mode 100644 openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/renderer/VocabularyTermStringCellRenderer.java create mode 100644 openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/basic/dto/VocabularyTermTableCell.java diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/model/renderer/AbstractPropertyColRenderer.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/model/renderer/AbstractPropertyColRenderer.java index 19f66a79f2f..7aa09ce3faf 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/model/renderer/AbstractPropertyColRenderer.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/model/renderer/AbstractPropertyColRenderer.java @@ -49,6 +49,7 @@ public abstract class AbstractPropertyColRenderer<T extends IEntityPropertiesHol final IViewContext<?> viewContext, EntityPropertyColDef<S> colDef, RealNumberFormatingParameters realNumberFormatingParameters) { + // NOTE: keep in sync with TypedTableGrid.tryGetSpecificRenderer switch (colDef.getDataTypeCode()) { case REAL: diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/renderer/TimestampStringCellRenderer.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/renderer/TimestampStringCellRenderer.java new file mode 100644 index 00000000000..204a061a29a --- /dev/null +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/renderer/TimestampStringCellRenderer.java @@ -0,0 +1,54 @@ +/* + * 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.renderer; + +import java.util.Date; + +import com.extjs.gxt.ui.client.store.ListStore; +import com.extjs.gxt.ui.client.widget.grid.ColumnData; +import com.extjs.gxt.ui.client.widget.grid.Grid; +import com.extjs.gxt.ui.client.widget.grid.GridCellRenderer; + +import ch.systemsx.cisd.common.shared.basic.utils.StringUtils; +import ch.systemsx.cisd.openbis.generic.client.web.client.application.model.BaseEntityModel; +import ch.systemsx.cisd.openbis.generic.shared.basic.BasicConstant; + +/** + * An {@link GridCellRenderer} which renders date value stored in + * {@link BasicConstant#CANONICAL_DATE_FORMAT_PATTERN} in more readable format (the one used in date + * fields in registration forms). + * + * @author Piotr Buczek + */ +public class TimestampStringCellRenderer implements GridCellRenderer<BaseEntityModel<?>> +{ + + public Object render(BaseEntityModel<?> model, String property, ColumnData config, + int rowIndex, int colIndex, ListStore<BaseEntityModel<?>> store, + Grid<BaseEntityModel<?>> grid) + { + String originalValue = String.valueOf(model.get(property)); + if (StringUtils.isBlank(originalValue)) + { + return originalValue; + } else + { + Date date = DateRenderer.DEFAULT_DATE_TIME_FORMAT.parse(originalValue); + return DateRenderer.renderDate(date); + } + } +} diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/renderer/VocabularyTermStringCellRenderer.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/renderer/VocabularyTermStringCellRenderer.java new file mode 100644 index 00000000000..4f77b61bd9d --- /dev/null +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/renderer/VocabularyTermStringCellRenderer.java @@ -0,0 +1,36 @@ +package ch.systemsx.cisd.openbis.generic.client.web.client.application.renderer; + +import com.extjs.gxt.ui.client.store.ListStore; +import com.extjs.gxt.ui.client.widget.grid.ColumnData; +import com.extjs.gxt.ui.client.widget.grid.Grid; +import com.extjs.gxt.ui.client.widget.grid.GridCellRenderer; + +import ch.systemsx.cisd.common.shared.basic.utils.StringUtils; +import ch.systemsx.cisd.openbis.generic.client.web.client.application.model.BaseEntityModel; +import ch.systemsx.cisd.openbis.generic.client.web.client.application.model.renderer.VocabularyPropertyColRenderer; +import ch.systemsx.cisd.openbis.generic.shared.basic.dto.ISerializableComparable; +import ch.systemsx.cisd.openbis.generic.shared.basic.dto.TableModelRowWithObject; +import ch.systemsx.cisd.openbis.generic.shared.basic.dto.VocabularyTerm; +import ch.systemsx.cisd.openbis.generic.shared.basic.dto.VocabularyTermTableCell; + +public class VocabularyTermStringCellRenderer implements GridCellRenderer<BaseEntityModel<?>> +{ + + public Object render(BaseEntityModel<?> model, String property, ColumnData config, + int rowIndex, int colIndex, ListStore<BaseEntityModel<?>> store, + Grid<BaseEntityModel<?>> grid) + { + String originalValue = String.valueOf(model.get(property)); + if (StringUtils.isBlank(originalValue)) + { + return originalValue; + } else + { + ISerializableComparable cell = + ((TableModelRowWithObject<?>) model.getBaseObject()).getValues().get(colIndex); + VocabularyTermTableCell vocabularyTermTableCell = (VocabularyTermTableCell) cell; + VocabularyTerm vocabularyTerm = vocabularyTermTableCell.getVocabularyTerm(); + return VocabularyPropertyColRenderer.renderTerm(vocabularyTerm); + } + } +} 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 ba7f1a5320f..3b7fe3b87d8 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 @@ -23,6 +23,7 @@ import java.util.List; import java.util.Map; import java.util.Set; +import com.extjs.gxt.ui.client.widget.grid.GridCellRenderer; import com.google.gwt.user.client.rpc.AsyncCallback; import ch.systemsx.cisd.openbis.generic.client.web.client.ICommonClientServiceAsync; @@ -30,7 +31,11 @@ import ch.systemsx.cisd.openbis.generic.client.web.client.application.AbstractAs import ch.systemsx.cisd.openbis.generic.client.web.client.application.IViewContext; import ch.systemsx.cisd.openbis.generic.client.web.client.application.framework.IDisplayTypeIDGenerator; import ch.systemsx.cisd.openbis.generic.client.web.client.application.model.BaseEntityModel; +import ch.systemsx.cisd.openbis.generic.client.web.client.application.renderer.LinkRenderer; +import ch.systemsx.cisd.openbis.generic.client.web.client.application.renderer.MultilineStringCellRenderer; import ch.systemsx.cisd.openbis.generic.client.web.client.application.renderer.RealNumberRenderer; +import ch.systemsx.cisd.openbis.generic.client.web.client.application.renderer.TimestampStringCellRenderer; +import ch.systemsx.cisd.openbis.generic.client.web.client.application.renderer.VocabularyTermStringCellRenderer; 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.framework.LinkExtractor; import ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.grid.AbstractBrowserGrid; @@ -164,25 +169,49 @@ public abstract class TypedTableGrid<T extends ISerializable> } if (headers != null) { - RealNumberRenderer realNumberRenderer = - new RealNumberRenderer(viewContext.getDisplaySettingsManager() - .getRealNumberFormatingParameters()); for (TableModelColumnHeader header : headers) { String id = header.getId(); if (listenerLinkGenerators.containsKey(id)) { definitions.setGridCellRendererFor(id, createInternalLinkCellRenderer()); - } - if (header.getDataType() == DataTypeCode.REAL) + } else { - definitions.setGridCellRendererFor(id, realNumberRenderer); + final GridCellRenderer<BaseEntityModel<?>> specificRendererOrNull = + tryGetSpecificRenderer(header.getDataType()); + if (specificRendererOrNull != null) + { + definitions.setGridCellRendererFor(id, specificRendererOrNull); + } } } } return definitions; } + private GridCellRenderer<BaseEntityModel<?>> tryGetSpecificRenderer(DataTypeCode dataType) + { + // NOTE: keep in sync with AbstractPropertyColRenderer.getPropertyColRenderer + switch (dataType) + { + case CONTROLLEDVOCABULARY: + return new VocabularyTermStringCellRenderer(); + case HYPERLINK: + return LinkRenderer.createExternalLinkRenderer(); + case REAL: + return new RealNumberRenderer(viewContext.getDisplaySettingsManager() + .getRealNumberFormatingParameters()); + case MULTILINE_VARCHAR: + return new MultilineStringCellRenderer(); + case TIMESTAMP: + return new TimestampStringCellRenderer(); + case XML: + return new MultilineStringCellRenderer(); + default: + return null; + } + } + @Override protected BaseEntityModel<TableModelRowWithObject<T>> createModel( GridRowModel<TableModelRowWithObject<T>> entity) diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/basic/dto/VocabularyTermTableCell.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/basic/dto/VocabularyTermTableCell.java new file mode 100644 index 00000000000..d5f5c680b2b --- /dev/null +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/basic/dto/VocabularyTermTableCell.java @@ -0,0 +1,84 @@ +/* + * 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.shared.basic.dto; + +/** + * Table cell for a {@link VocabularyTerm}. + * + * @author Piotr Buczek + */ +public class VocabularyTermTableCell implements ISerializableComparable +{ + private static final long serialVersionUID = ServiceVersionHolder.VERSION; + + private VocabularyTerm vocabularyTerm; + + public VocabularyTermTableCell(VocabularyTerm term) + { + if (term == null) + { + throw new IllegalArgumentException("Unspecified vocabulary term"); + } + + vocabularyTerm = term; + } + + public int compareTo(ISerializableComparable o) + { + return getVocabularyTerm().toString().compareTo(o.toString()); + } + + public VocabularyTerm getVocabularyTerm() + { + return vocabularyTerm; + } + + @Override + public int hashCode() + { + return getVocabularyTerm().hashCode(); + } + + @Override + public boolean equals(Object obj) + { + if (obj == this) + { + return true; + } + if (obj instanceof VocabularyTermTableCell == false) + { + return false; + } + VocabularyTermTableCell other = (VocabularyTermTableCell) obj; + return this.getVocabularyTerm().equals(other.getVocabularyTerm()); + } + + @Override + public String toString() + { + return getVocabularyTerm().toString(); + } + + // --------------------------- + + // GWT only + @SuppressWarnings("unused") + private VocabularyTermTableCell() + { + } +} diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/util/TypedTableModelBuilder.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/util/TypedTableModelBuilder.java index 3ad1eb5922c..5af567ef1ac 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/util/TypedTableModelBuilder.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/util/TypedTableModelBuilder.java @@ -46,6 +46,7 @@ import ch.systemsx.cisd.openbis.generic.shared.basic.dto.StringTableCell; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.TableModelColumnHeader; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.TableModelRowWithObject; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.TypedTableModel; +import ch.systemsx.cisd.openbis.generic.shared.basic.dto.VocabularyTermTableCell; /** * Builder class for creating an instance of {@link TypedTableModel}. @@ -141,13 +142,17 @@ public class TypedTableModelBuilder<T extends ISerializable> IColumn column = column(code).withTitle(label); DataTypeCode dataType = propertyType.getDataType().getCode(); ISerializableComparable value; - if (DataTypeCode.MATERIAL == dataType) + switch (dataType) { - value = new MaterialTableCell(property.getMaterial()); - column.withEntityKind(EntityKind.MATERIAL); - } else - { - value = DataTypeUtils.convertTo(dataType, property.tryGetAsString()); + case MATERIAL: + value = new MaterialTableCell(property.getMaterial()); + column.withEntityKind(EntityKind.MATERIAL); + break; + case CONTROLLEDVOCABULARY: + value = new VocabularyTermTableCell(property.getVocabularyTerm()); + break; + default: + value = DataTypeUtils.convertTo(dataType, property.tryGetAsString()); } column.withDataType(dataType).addValue(value); } -- GitLab