diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/model/ExperimentModel.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/model/ExperimentModel.java index a7eef610594264a97cc6dcd97b1829ed3c105b09..bc0b88d768e71c3f6dff8787974df00b5e59bfd4 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/model/ExperimentModel.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/model/ExperimentModel.java @@ -21,6 +21,8 @@ import java.util.List; import com.extjs.gxt.ui.client.data.ModelData; +import ch.systemsx.cisd.openbis.generic.client.web.client.application.model.renderer.AbstractPropertyColRenderer; +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.columns.framework.IColumnDefinitionUI; import ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.columns.specific.experiment.CommonExperimentColDefKind; import ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.columns.specific.experiment.PropertyExperimentColDef; @@ -42,18 +44,21 @@ public final class ExperimentModel extends BaseEntityModel<Experiment> public ExperimentModel(final Experiment entity) { - super(entity, createColumnsSchema(entity)); + super(entity, createColumnsSchemaForRendering(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<Experiment>> createColumnsSchema(Experiment entity) + private static List<IColumnDefinitionUI<Experiment>> createColumnsSchemaForRendering( + Experiment entity) { List<IColumnDefinitionUI<Experiment>> list = createCommonColumnsSchema(null); for (ExperimentProperty prop : entity.getProperties()) { ExperimentTypePropertyType etpt = prop.getEntityTypePropertyType(); - list.add(new PropertyExperimentColDef(etpt.getPropertyType())); + AbstractPropertyColDef<Experiment> colDef = + new PropertyExperimentColDef(etpt.getPropertyType()); + list.add(AbstractPropertyColRenderer.getPropertyColRenderer(colDef)); } return list; } 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 index 178132c06e9951bfd509cf428e4604eb16de638d..3cbdd3311258214abca9af2547ceac880b30d882 100644 --- 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 @@ -21,6 +21,8 @@ import java.util.List; import com.extjs.gxt.ui.client.data.ModelData; +import ch.systemsx.cisd.openbis.generic.client.web.client.application.model.renderer.AbstractPropertyColRenderer; +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.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; @@ -42,18 +44,21 @@ public final class MaterialModel extends BaseEntityModel<Material> public MaterialModel(final Material entity) { - super(entity, createColumnsSchema(entity)); + super(entity, createColumnsSchemaForRendering(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) + private static List<IColumnDefinitionUI<Material>> createColumnsSchemaForRendering( + Material entity) { List<IColumnDefinitionUI<Material>> list = createCommonColumnsSchema(null); for (MaterialProperty prop : entity.getProperties()) { MaterialTypePropertyType etpt = prop.getEntityTypePropertyType(); - list.add(new PropertyMaterialColDef(etpt.getPropertyType())); + AbstractPropertyColDef<Material> colDef = + new PropertyMaterialColDef(etpt.getPropertyType()); + list.add(AbstractPropertyColRenderer.getPropertyColRenderer(colDef)); } return list; } diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/model/SampleModel.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/model/SampleModel.java index dbcbb186618b67bbb36de72a403272ff9b21a5af..37a5073168a1d1dd78f1d2ef8ab220c590e6f0a6 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/model/SampleModel.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/model/SampleModel.java @@ -22,7 +22,9 @@ import java.util.List; import com.extjs.gxt.ui.client.data.ModelData; import ch.systemsx.cisd.openbis.generic.client.web.client.application.Dict; +import ch.systemsx.cisd.openbis.generic.client.web.client.application.model.renderer.AbstractPropertyColRenderer; import ch.systemsx.cisd.openbis.generic.client.web.client.application.renderer.LinkRenderer; +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.columns.framework.IColumnDefinitionUI; import ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.columns.specific.sample.CommonSampleColDefKind; import ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.columns.specific.sample.ParentContainerSampleColDef; @@ -47,7 +49,7 @@ public final class SampleModel extends BaseEntityModel<Sample> public SampleModel(final Sample entity) { - super(entity, createColumnsSchema(entity)); + super(entity, createColumnsSchemaForRendering(entity)); set(ModelDataPropertyNames.SAMPLE_TYPE, entity.getSampleType() != null ? entity .getSampleType().getCode() : null); // add a link for experiment @@ -81,7 +83,7 @@ public final class SampleModel extends BaseEntityModel<Sample> // 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<Sample>> createColumnsSchema(Sample sample) + private static List<IColumnDefinitionUI<Sample>> createColumnsSchemaForRendering(Sample sample) { List<IColumnDefinitionUI<Sample>> list = createCommonColumnsSchema(null); List<IColumnDefinitionUI<Sample>> parentColumns = @@ -90,7 +92,9 @@ public final class SampleModel extends BaseEntityModel<Sample> for (SampleProperty prop : sample.getProperties()) { SampleTypePropertyType etpt = prop.getEntityTypePropertyType(); - list.add(new PropertySampleColDef(etpt.getPropertyType(), etpt.isDisplayed())); + AbstractPropertyColDef<Sample> colDef = + new PropertySampleColDef(etpt.getPropertyType(), etpt.isDisplayed()); + list.add(AbstractPropertyColRenderer.getPropertyColRenderer(colDef)); } return list; } 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 new file mode 100644 index 0000000000000000000000000000000000000000..240ac7f31cc3b60a84912be85f6eb9af0680cce5 --- /dev/null +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/model/renderer/AbstractPropertyColRenderer.java @@ -0,0 +1,93 @@ +/* + * 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.columns.framework.IColumnDefinitionUI; +import ch.systemsx.cisd.openbis.generic.shared.basic.dto.DataTypeCode; + +/** + * An abstract decorator for {@link AbstractPropertyColDef} to be used in grids for rendering values + * in a different way in grids than in export. <br> + * It changes {@link AbstractPropertyColDef#getValue(Object)} behavior distinguishing certain + * property types so in grid there can be e.g. a link displayed for hyperlink property. Other + * methods are delegated without any change. + * + * @author Piotr Buczek + */ +public abstract class AbstractPropertyColRenderer<T> implements IColumnDefinitionUI<T> +{ + + /** + * @return property renderer for given column of given entity + */ + public static <S> AbstractPropertyColRenderer<S> getPropertyColRenderer( + AbstractPropertyColDef<S> colDef) + { + switch (colDef.getDataTypeCode()) + { + case HYPERLINK: + return new HyperlinkPropertyColRenderer<S>(colDef); + default: + return new DefaultPropertyColRenderer<S>(colDef); + } + } + + protected final AbstractPropertyColDef<T> colDef; + + public AbstractPropertyColRenderer(AbstractPropertyColDef<T> colDef) + { + super(); + this.colDef = colDef; + } + + public String getValue(T entity) + { + return renderValue(colDef.getValue(entity)); + } + + /** @return given <var>value</var> rendered depending on property type */ + protected abstract String renderValue(String value); + + // default delegate methods + + public String getHeader() + { + return colDef.getHeader(); + } + + public String getIdentifier() + { + return colDef.getIdentifier(); + } + + public int getWidth() + { + return colDef.getWidth(); + } + + public boolean isHidden() + { + return colDef.isHidden(); + } + + public DataTypeCode getDataTypeCode() + { + return colDef.getDataTypeCode(); + } + +} diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/model/renderer/DefaultPropertyColRenderer.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/model/renderer/DefaultPropertyColRenderer.java new file mode 100644 index 0000000000000000000000000000000000000000..d9c478619336788655eeb2aef57e78d3c364011a --- /dev/null +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/model/renderer/DefaultPropertyColRenderer.java @@ -0,0 +1,40 @@ +/* + * 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; + +/** + * An {@link AbstractPropertyColRenderer} which renders value in a default way (as a simple String). + * + * @author Piotr Buczek + */ +class DefaultPropertyColRenderer<T> extends AbstractPropertyColRenderer<T> +{ + + public DefaultPropertyColRenderer(AbstractPropertyColDef<T> colDef) + { + super(colDef); + } + + @Override + protected String renderValue(String value) + { + return value; + } + +} diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/model/renderer/HyperlinkPropertyColRenderer.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/model/renderer/HyperlinkPropertyColRenderer.java new file mode 100644 index 0000000000000000000000000000000000000000..a490bb4b4cfb7c3370f1ca6f2d6ce60084a71a84 --- /dev/null +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/model/renderer/HyperlinkPropertyColRenderer.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.ExternalHyperlink; + +/** + * An {@link AbstractPropertyColRenderer} which renders value as an external hyperlink. + * + * @author Piotr Buczek + */ +class HyperlinkPropertyColRenderer<T> extends AbstractPropertyColRenderer<T> +{ + + public HyperlinkPropertyColRenderer(AbstractPropertyColDef<T> colDef) + { + super(colDef); + } + + @Override + protected String renderValue(String value) + { + return ExternalHyperlink.createAnchorString(value, value); + } + +} 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 b1cd7550485584523a27c374ebfb9672ff56c909..3520487a142fd6f36a79da59bb1922afb21fd7af 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 @@ -31,6 +31,7 @@ import ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.listene import ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.property.AbstractPropertyValueRenderer; 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.util.IMessageProvider; import ch.systemsx.cisd.openbis.generic.client.web.client.dto.Experiment; import ch.systemsx.cisd.openbis.generic.client.web.client.dto.IEntityInformationHolder; @@ -282,15 +283,22 @@ public final class PropertyValueRenderers public Widget getAsWidget(T object) { - if (isMaterialProperty(object)) + switch (getDataTypeCode(object)) { - return createLinkToMaterial(object); - } else - { - return new InlineHTML(object.getValue()); + case MATERIAL: + return createLinkToMaterial(object); + case HYPERLINK: + return createHyperlink(object); + default: + return createHtmlWidget(object); } } + private DataTypeCode getDataTypeCode(T property) + { + return getPropertyType(property).getDataType().getCode(); + } + private Widget createLinkToMaterial(T object) { String value = object.getValue(); @@ -319,9 +327,15 @@ public final class PropertyValueRenderers return panel; } - private boolean isMaterialProperty(T property) + private Widget createHtmlWidget(T object) { - return getPropertyType(property).getDataType().getCode().equals(DataTypeCode.MATERIAL); + return new InlineHTML(object.getValue()); + } + + private Widget createHyperlink(T object) + { + String value = object.getValue(); + return new ExternalHyperlink(value, value); } private boolean isAllowedMaterialTypeUnspecified(T property) diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/columns/framework/AbstractPropertyColDef.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/columns/framework/AbstractPropertyColDef.java index b7608ba3471377bd5ff116065112f23f3a7f458b..708e9ddf17eb8107187b56fe1691a12fd755ee20 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/columns/framework/AbstractPropertyColDef.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/columns/framework/AbstractPropertyColDef.java @@ -20,6 +20,7 @@ import java.util.List; import com.google.gwt.user.client.rpc.IsSerializable; +import ch.systemsx.cisd.openbis.generic.shared.basic.dto.DataTypeCode; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.EntityProperty; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.PropertyType; @@ -41,6 +42,8 @@ public abstract class AbstractPropertyColDef<T> extends AbstractColumnDefinition private String simpleCode; + private PropertyType propertyType; + // GWT only public AbstractPropertyColDef() { @@ -55,17 +58,19 @@ public abstract class AbstractPropertyColDef<T> extends AbstractColumnDefinition int width, String propertyTypeLabel, String identifierPrefix) { this(propertyType.getSimpleCode(), isDisplayedByDefault, width, propertyType - .isInternalNamespace(), propertyTypeLabel, identifierPrefix + PROPERTY_PREFIX); + .isInternalNamespace(), propertyTypeLabel, identifierPrefix + PROPERTY_PREFIX, + propertyType); } protected AbstractPropertyColDef(String propertyTypeCode, boolean isDisplayedByDefault, int width, boolean isInternalNamespace, String propertyTypeLabel, - String identifierPrefix) + String identifierPrefix, PropertyType propertyType) { super(propertyTypeLabel, width, isDisplayedByDefault); this.isInternalNamespace = isInternalNamespace; this.simpleCode = propertyTypeCode; this.identifierPrefix = identifierPrefix; + this.propertyType = propertyType; } @Override @@ -88,13 +93,19 @@ public abstract class AbstractPropertyColDef<T> extends AbstractColumnDefinition private boolean isMatching(EntityProperty<?, ?> prop) { - PropertyType propertyType = prop.getEntityTypePropertyType().getPropertyType(); - return propertyType.isInternalNamespace() == isInternalNamespace - && propertyType.getSimpleCode().equals(simpleCode); + PropertyType propType = prop.getEntityTypePropertyType().getPropertyType(); + return propType.isInternalNamespace() == isInternalNamespace + && propType.getSimpleCode().equals(simpleCode); } public String getIdentifier() { return identifierPrefix + isInternalNamespace + simpleCode; } + + public final DataTypeCode getDataTypeCode() + { + return propertyType.getDataType().getCode(); + } + } \ No newline at end of file diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/columns/specific/experiment/PropertyExperimentColDef.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/columns/specific/experiment/PropertyExperimentColDef.java index a6d213ab8d14736250db09f4799c10d0d257fb4e..f28c48e5bcb95a8f021eee4d005c63d731d4c6de 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/columns/specific/experiment/PropertyExperimentColDef.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/columns/specific/experiment/PropertyExperimentColDef.java @@ -34,7 +34,7 @@ public class PropertyExperimentColDef extends AbstractPropertyColDef<Experiment> // GWT only public PropertyExperimentColDef() { - super(null, false, 0, false, null, null); + super(null, false, 0, false, null, null, null); } public PropertyExperimentColDef(PropertyType propertyType) diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/columns/specific/material/PropertyMaterialColDef.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/columns/specific/material/PropertyMaterialColDef.java index 1773bd02300dbd53e1f4764baa327790d6b7c27b..b719c5d54411268f68894dd2f079793e070bc12d 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/columns/specific/material/PropertyMaterialColDef.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/columns/specific/material/PropertyMaterialColDef.java @@ -34,7 +34,7 @@ public class PropertyMaterialColDef extends AbstractPropertyColDef<Material> imp // GWT only public PropertyMaterialColDef() { - super(null, false, 0, false, null, null); + super(null, false, 0, false, null, null, null); } public PropertyMaterialColDef(PropertyType propertyType) diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/columns/specific/sample/PropertySampleColDef.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/columns/specific/sample/PropertySampleColDef.java index e749199636a16697c4879ea50443645e44c6c57a..15f13951f73e65afddf0c1f9c39370c298497a50 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/columns/specific/sample/PropertySampleColDef.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/columns/specific/sample/PropertySampleColDef.java @@ -30,7 +30,7 @@ public class PropertySampleColDef extends AbstractPropertyColDef<Sample> impleme // GWT only public PropertySampleColDef() { - super(null, false, 0, false, null, null); + super(null, false, 0, false, null, null, null); } public PropertySampleColDef(PropertyType propertyType, boolean isDisplayedByDefault) diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/field/HyperlinkField.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/field/HyperlinkField.java new file mode 100644 index 0000000000000000000000000000000000000000..5b3017c6a22480fb7130ad0616243a3cbc8b2c36 --- /dev/null +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/field/HyperlinkField.java @@ -0,0 +1,40 @@ +/* + * 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.TextField; + +import ch.systemsx.cisd.openbis.generic.shared.basic.CommonValidationConstants; + +/** + * A {@link TextField} extension for registering text (<code>String</code>) that will be rendered as + * a link. The text characters are validated. + * + * @author Piotr Buczek + */ +public class HyperlinkField extends VarcharField +{ + public HyperlinkField(final String label, final boolean mandatory) + { + super(label, mandatory); + setRegex(CommonValidationConstants.HYPERLINK_REGEXP); + setEmptyText("Hyperlink"); + getMessages().setBlankText("Hyperlink required"); + getMessages().setRegexText("Hyperlink has improper format"); + } + +} \ 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 ca34e6faef2239c04c3d4f1d226317cf0b0559cf..fa9f177abaa6bee42fb9d9d876a73f9462439a43 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 @@ -71,6 +71,8 @@ public class PropertyFieldFactory case MATERIAL: return wrapUnaware(MaterialChooserField.create(label, isMandatory, pt .getMaterialType(), originalRawValue, viewContext)); + case HYPERLINK: + return wrapUnaware(new HyperlinkField(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/ExternalHyperlink.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/widget/ExternalHyperlink.java new file mode 100644 index 0000000000000000000000000000000000000000..95f8b6090f88f613d5bf77ec06c1860e58513b88 --- /dev/null +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/widget/ExternalHyperlink.java @@ -0,0 +1,46 @@ +/* + * 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.InlineHTML; + +/** + * A {@link InlineHTML} widget extension that renders as an anchor to an external resource. <br> + * The anchor opens in a new window/tab depending on the browser. + * + * @author Piotr Buczek + */ +public final class ExternalHyperlink extends InlineHTML +{ + + /** + * Creates a hyperlink with its text and href specified. + * + * @param text the hyperlink's text + * @param href the hyperlink's href + */ + public ExternalHyperlink(String text, String href) + { + // using DOM.createAnchor() like in Hypelink is another way to implement this + super(createAnchorString(text, href)); + } + + public static String createAnchorString(String text, String href) + { + return "<a href=\"" + href + "\" target=\"_blank\">" + text + "</a>"; + } +} 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 d160d40227ef935349e077431cade2d9ee8992a9..e818093190d12e187edd9de74608caa3af9e77ec 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 @@ -33,6 +33,7 @@ import ch.systemsx.cisd.common.collections.IToStringConverter; import ch.systemsx.cisd.common.exceptions.UserFailureException; import ch.systemsx.cisd.common.utilities.PropertyUtils; import ch.systemsx.cisd.common.utilities.PropertyUtils.Boolean; +import ch.systemsx.cisd.openbis.generic.shared.basic.CommonValidationConstants; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.MaterialIdentifier; import ch.systemsx.cisd.openbis.generic.shared.dto.PropertyTypePE; import ch.systemsx.cisd.openbis.generic.shared.dto.VocabularyPE; @@ -70,6 +71,7 @@ public final class PropertyValidator implements IPropertyValueValidator map.put(EntityDataType.REAL, new RealValidator()); map.put(EntityDataType.CONTROLLEDVOCABULARY, new ControlledVocabularyValidator()); map.put(EntityDataType.MATERIAL, new MaterialValidator()); + map.put(EntityDataType.HYPERLINK, new HyperlinkValidator()); return map; } @@ -288,4 +290,25 @@ public final class PropertyValidator implements IPropertyValueValidator return value; } } + + private final static class HyperlinkValidator implements IDataTypeValidator + { + + // + // IDataTypeValidator + // + + public final String validate(final String value) throws UserFailureException + { + assert value != null : "Unspecified value."; + if (value.matches(CommonValidationConstants.HYPERLINK_REGEXP)) + { + return value; + } else + { + throw UserFailureException.fromTemplate( + "Hyperlink value '%s' has improper format.", value); + } + } + } } diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/basic/CommonValidationConstants.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/basic/CommonValidationConstants.java new file mode 100644 index 0000000000000000000000000000000000000000..5006337b1bae1f6e1108cdb61fa2d402f614f313 --- /dev/null +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/basic/CommonValidationConstants.java @@ -0,0 +1,32 @@ +/* + * 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.shared.basic; + +/** + * Common constants to be used both on client and server side for field validation. + * + * @author Piotr Buczek + */ +public class CommonValidationConstants +{ + + // A complete regexp for hyperlink may be very complex like this one: + // http://internet.ls-la.net/folklore/url-regexpr.html + // We should rather use sth simple for "safe" hyperlink - with no <>()[] + /** a simple regular expression for "safe" hyperlinks */ + public static final String HYPERLINK_REGEXP = "[^<>()\\[\\]]*"; +}