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 240ac7f31cc3b60a84912be85f6eb9af0680cce5..301e872985a4306fe2db05f4b5b7e9ac10a971ba 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 @@ -42,6 +42,8 @@ public abstract class AbstractPropertyColRenderer<T> implements IColumnDefinitio { case HYPERLINK: return new HyperlinkPropertyColRenderer<S>(colDef); + case MULTILINE_VARCHAR: + return new MultilineVarcharPropertyColRenderer<S>(colDef); default: return new DefaultPropertyColRenderer<S>(colDef); } diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/model/renderer/MultilineVarcharPropertyColRenderer.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/model/renderer/MultilineVarcharPropertyColRenderer.java new file mode 100644 index 0000000000000000000000000000000000000000..00a0798aac71163f5b107ce151c77934e94f17fc --- /dev/null +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/model/renderer/MultilineVarcharPropertyColRenderer.java @@ -0,0 +1,41 @@ +/* + * 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.model.renderer; + +import ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.columns.framework.AbstractPropertyColDef; +import ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.widget.MultilineHTML; + +/** + * An {@link AbstractPropertyColRenderer} which renders value preserving newlines. + * + * @author Piotr Buczek + */ +class MultilineVarcharPropertyColRenderer<T> extends AbstractPropertyColRenderer<T> +{ + + public MultilineVarcharPropertyColRenderer(AbstractPropertyColDef<T> colDef) + { + super(colDef); + } + + @Override + protected String renderValue(String value) + { + return (new MultilineHTML(value)).toString(); + } + +} diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/PropertyValueRenderers.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/PropertyValueRenderers.java index 3520487a142fd6f36a79da59bb1922afb21fd7af..365ee5537b058abc3008210602c3118aacd60170 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/PropertyValueRenderers.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/PropertyValueRenderers.java @@ -32,6 +32,7 @@ import ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.propert import ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.property.AbstractSimplePropertyValueRenderer; import ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.property.IPropertyValueRenderer; import ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.widget.ExternalHyperlink; +import ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.widget.MultilineHTML; import ch.systemsx.cisd.openbis.generic.client.web.client.application.util.IMessageProvider; import ch.systemsx.cisd.openbis.generic.client.web.client.dto.Experiment; import ch.systemsx.cisd.openbis.generic.client.web.client.dto.IEntityInformationHolder; @@ -289,6 +290,8 @@ public final class PropertyValueRenderers return createLinkToMaterial(object); case HYPERLINK: return createHyperlink(object); + case MULTILINE_VARCHAR: + return createMultilineHtmlWidget(object); default: return createHtmlWidget(object); } @@ -327,6 +330,11 @@ public final class PropertyValueRenderers return panel; } + private Widget createMultilineHtmlWidget(T object) + { + return new MultilineHTML(object.getValue()); + } + private Widget createHtmlWidget(T object) { return new InlineHTML(object.getValue()); diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/field/MultilineVarcharField.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/field/MultilineVarcharField.java new file mode 100644 index 0000000000000000000000000000000000000000..cc616c175d5eb363cff6787aff33bc3f14e30a7a --- /dev/null +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/field/MultilineVarcharField.java @@ -0,0 +1,57 @@ +/* + * 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.field; + +import com.extjs.gxt.ui.client.widget.form.TextArea; + +import ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.widget.FieldUtil; + +/** + * A {@link TextArea} extension for registering multiline text with adjustable height. + * + * @author Piotr Buczek + */ +public class MultilineVarcharField extends TextArea +{ + + private static final double DEFAULT_LINE_HEIGHT = 1.6; + + private static final int DEFAULT_LINES = 5; + + /** Constructor for default sized field (5 lines). */ + public MultilineVarcharField(final String label, final boolean mandatory) + { + this(label, mandatory, DEFAULT_LINES); + } + + /** Constructor for multiline field with given number of lines. */ + public MultilineVarcharField(final String label, final boolean mandatory, int lines) + { + this.setFieldLabel(label); + this.setValidateOnBlur(true); + this.setAutoValidate(true); + FieldUtil.setMandatoryFlag(this, mandatory); + + this.setHeightInLines(lines); + } + + public void setHeightInLines(int lines) + { + setHeight(lines * DEFAULT_LINE_HEIGHT + "em"); + } + +} \ No newline at end of file diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/field/PropertyFieldFactory.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/field/PropertyFieldFactory.java index fa9f177abaa6bee42fb9d9d876a73f9462439a43..40541ed12d3c542e58da22dd0fcd987be04efb01 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/field/PropertyFieldFactory.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/field/PropertyFieldFactory.java @@ -72,7 +72,9 @@ public class PropertyFieldFactory return wrapUnaware(MaterialChooserField.create(label, isMandatory, pt .getMaterialType(), originalRawValue, viewContext)); case HYPERLINK: - return wrapUnaware(new HyperlinkField(label, isMandatory)); + return wrapUnaware(new HyperlinkField(label, isMandatory)); + case MULTILINE_VARCHAR: + return wrapUnaware(new MultilineVarcharField(label, isMandatory)); } throw new IllegalStateException("unknown enum " + dataType); } diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/widget/MultilineHTML.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/widget/MultilineHTML.java new file mode 100644 index 0000000000000000000000000000000000000000..0ba5a851d40bc3e900732484f6ca26e772e3a9e8 --- /dev/null +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/widget/MultilineHTML.java @@ -0,0 +1,52 @@ +/* + * 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.widget; + +import com.google.gwt.user.client.ui.HTML; + +/** + * A {@link HTML} widget extension that preserves newlines in multiline text. + * + * @author Piotr Buczek + */ +public final class MultilineHTML extends HTML +{ + /** + * Creates a MultilineHtml widget with the specified HTML contents. + * + * @param html the new widget's HTML contents + */ + public MultilineHTML(String html) + { + // Another way to implement this would be to preserve white-space: + // getElement().getStyle().setProperty("whiteSpace", "pre"); + // but then to long lines would not fit in property grid with no word wrapping. + // So the only option is to replace newlines with <br/> + super(replaceNewlinesWithBRs(html)); + } + + private static final String BR = "<br\\>"; + + private static String replaceNewlinesWithBRs(String html) + { + String result = html; + // to be independent of regexp implementation we have to replace newlines in two steps + result = result.replaceAll("\n\r", BR); + result = result.replaceAll("[\n\r]", BR); + return result; + } +} diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/server/util/TSVRenderer.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/server/util/TSVRenderer.java index 80ff3d918490edfee23ee001549197d4619ec4dc..ff4a87c950ba011ba8a25e7ce7e843fb77668b80 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/server/util/TSVRenderer.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/server/util/TSVRenderer.java @@ -18,6 +18,8 @@ package ch.systemsx.cisd.openbis.generic.client.web.server.util; import java.util.List; +import org.apache.commons.lang.StringUtils; + import ch.systemsx.cisd.openbis.generic.client.web.client.dto.IColumnDefinition; /** @@ -71,11 +73,22 @@ public class TSVRenderer { isFirst = false; } - sb.append(column.getValue(entity)); + sb.append(cleanWhitespaces(column.getValue(entity))); } sb.append(lineSeparator); } + /** + * @return <var>value</var> with white-spaces cleaned in the same way that HTML works (all + * contiguous white-spaces are replaced with single space) + */ + private String cleanWhitespaces(String value) + { + String[] tokens = StringUtils.split(value); + String result = StringUtils.join(tokens, " "); + return result; + } + private <T> void appendHeader(List<IColumnDefinition<T>> columnDefs, StringBuffer sb) { boolean isFirst = true; diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/PropertyValidator.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/PropertyValidator.java index 2f097e5ae5cdece1cb86e2ea1c30158a496f8ba3..ff5ad6909de759ea1c777919924fc9027a6cbd56 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/PropertyValidator.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/PropertyValidator.java @@ -72,6 +72,7 @@ public final class PropertyValidator implements IPropertyValueValidator map.put(EntityDataType.CONTROLLEDVOCABULARY, new ControlledVocabularyValidator()); map.put(EntityDataType.MATERIAL, new MaterialValidator()); map.put(EntityDataType.HYPERLINK, new HyperlinkValidator()); + map.put(EntityDataType.MULTILINE_VARCHAR, new VarcharValidator()); return map; }