Skip to content
Snippets Groups Projects
Commit 4c27960c authored by buczekp's avatar buczekp
Browse files

[LMS-827] added multiline fields and handling multiline text in browsers and export

SVN: 10615
parent d57fa51f
No related branches found
No related tags found
No related merge requests found
Showing
with 178 additions and 2 deletions
......@@ -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);
}
......
/*
* 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();
}
}
......@@ -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());
......
/*
* 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
......@@ -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);
}
......
/*
* 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;
}
}
......@@ -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;
......
......@@ -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;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment