diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/Dict.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/Dict.java index 723fccdffa31d66dd52be8b425d519493b097294..1d713ffbc5c22cb57de13861a64eb26885d7dbb4 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/Dict.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/Dict.java @@ -48,6 +48,8 @@ public abstract class Dict public static final String CODE = "code"; + public static final String POSITION_AFTER = "position_after"; + public static final String ORDINAL = "ordinal"; public static final String SECTION = "section"; diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/model/renderer/TooltipRenderer.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/model/renderer/TooltipRenderer.java index 31cb4b984ce6780ebdfd34a92bcbd034c70b43bd..7cdd139bc836d83f6daafceebaa176654cb8ebe2 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/model/renderer/TooltipRenderer.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/model/renderer/TooltipRenderer.java @@ -26,13 +26,19 @@ import ch.systemsx.cisd.openbis.generic.client.web.client.application.util.Strin public class TooltipRenderer { public static final String renderAsTooltip(String code, String descriptionOrNull) + { + return renderAsTooltip(code, "description", descriptionOrNull); + } + + public static final String renderAsTooltip(String code, String additionalLabel, + String additionalValueOrNull) { assert code != null; final StringBuilder sb = new StringBuilder(); sb.append("<b>" + code + "</b>"); - if (StringUtils.isEmpty(descriptionOrNull) == false) + if (StringUtils.isEmpty(additionalValueOrNull) == false) { - sb.append("<br><hr>description: <i>" + descriptionOrNull + "</i>"); + sb.append("<br><hr>" + additionalLabel + ": <i>" + additionalValueOrNull + "</i>"); } return sb.toString(); } diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/property_type/EntityTypePropertyTypeSelectionWidget.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/property_type/EntityTypePropertyTypeSelectionWidget.java new file mode 100644 index 0000000000000000000000000000000000000000..d644a7f080f32c3675188cb71a8a9e1bb17eedb3 --- /dev/null +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/property_type/EntityTypePropertyTypeSelectionWidget.java @@ -0,0 +1,160 @@ +/* + * 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.property_type; + +import java.util.ArrayList; +import java.util.List; + +import com.extjs.gxt.ui.client.data.BaseModelData; +import com.extjs.gxt.ui.client.widget.form.ComboBox; + +import ch.systemsx.cisd.openbis.generic.client.web.client.ICommonClientServiceAsync; +import ch.systemsx.cisd.openbis.generic.client.web.client.application.AbstractAsyncCallback; +import ch.systemsx.cisd.openbis.generic.client.web.client.application.Dict; +import ch.systemsx.cisd.openbis.generic.client.web.client.application.IViewContext; +import ch.systemsx.cisd.openbis.generic.client.web.client.application.model.ModelDataPropertyNames; +import ch.systemsx.cisd.openbis.generic.client.web.client.application.model.renderer.TooltipRenderer; +import ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.widget.DropDownList; +import ch.systemsx.cisd.openbis.generic.client.web.client.application.util.GWTUtils; +import ch.systemsx.cisd.openbis.generic.shared.basic.dto.DatabaseModificationKind; +import ch.systemsx.cisd.openbis.generic.shared.basic.dto.EntityTypePropertyType; +import ch.systemsx.cisd.openbis.generic.shared.basic.dto.DatabaseModificationKind.ObjectKind; + +/** + * {@link ComboBox} containing list of property type codes of specified entity type loaded from the + * server. + * + * @author Piotr Buczek + */ +public final class EntityTypePropertyTypeSelectionWidget + extends + DropDownList<EntityTypePropertyTypeSelectionWidget.EntityTypePropertyTypeComboModel, EntityTypePropertyType<?>> +{ + public static final String TOP_ITEM_CODE = "(top)"; + + private static final String EMPTY_RESULT_SUFFIX = "property types"; + + private static final String CHOOSE_SUFFIX = "property type"; + + private static final String SUFFIX = "entity-type-property-type"; + + private static class EntityTypePropertyTypeComboModel extends BaseModelData + { + private static final long serialVersionUID = 1L; + + private static final String ORDINAL = "ordinal"; + + public EntityTypePropertyTypeComboModel(EntityTypePropertyType<?> entity) + { + set(ModelDataPropertyNames.CODE, entity == null ? TOP_ITEM_CODE : entity + .getPropertyType().getCode()); + set(ModelDataPropertyNames.CODE_WITH_LABEL, entity == null ? TOP_ITEM_CODE + : getDisplayName(entity)); + set(ORDINAL, entity == null ? 0L : entity.getOrdinal()); + set(ModelDataPropertyNames.TOOLTIP, entity == null ? null : getTooltip(entity)); + set(ModelDataPropertyNames.OBJECT, entity); + } + + private Object getTooltip(EntityTypePropertyType<?> entity) + { + return TooltipRenderer.renderAsTooltip(entity.getPropertyType().getCode(), "section", + entity.getSection()); + } + + private String getDisplayName(EntityTypePropertyType<?> entity) + { + return (entity.getSection() != null ? entity.getSection() + ": " : "") + + entity.getPropertyType().getCode(); + } + + public Long getOrdinal() + { + return get(ORDINAL); + } + } + + public EntityTypePropertyTypeSelectionWidget( + final IViewContext<ICommonClientServiceAsync> viewContext, final String idSuffix, + List<EntityTypePropertyType<?>> etpts, String initialValueOrNull) + { + super(viewContext, SUFFIX + idSuffix, Dict.POSITION_AFTER, + ModelDataPropertyNames.CODE_WITH_LABEL, CHOOSE_SUFFIX, EMPTY_RESULT_SUFFIX); + setETPTs(etpts); + selectInitialValue(initialValueOrNull); + setTemplate(GWTUtils.getTooltipTemplate(ModelDataPropertyNames.CODE_WITH_LABEL, + ModelDataPropertyNames.TOOLTIP)); + } + + private void setETPTs(List<EntityTypePropertyType<?>> etpts) + { + final List<EntityTypePropertyTypeComboModel> models = + new ArrayList<EntityTypePropertyTypeComboModel>(); + models.addAll(convertItems(etpts)); + updateStore(models); + getPropertyEditor().setList(store.getModels()); + } + + private void selectInitialValue(String initialValueOrNull) + { + if (initialValueOrNull != null) + { + trySelectByCode(initialValueOrNull); + updateOriginalValue(); + } + } + + public void trySelectByCode(String termCode) + { + GWTUtils.setSelectedItem(this, ModelDataPropertyNames.CODE, termCode); + } + + public void updateOriginalValue() + { + setOriginalValue(getValue()); + } + + public final Long getSelectedEntityTypePropertyTypeOrdinal() + { + final EntityTypePropertyTypeComboModel selectedItem = getValue(); + assert selectedItem != null; + return selectedItem.getOrdinal(); + } + + @Override + protected List<EntityTypePropertyTypeComboModel> convertItems( + List<EntityTypePropertyType<?>> etpts) + { + final List<EntityTypePropertyTypeComboModel> result = + new ArrayList<EntityTypePropertyTypeComboModel>(); + for (final EntityTypePropertyType<?> etpt : etpts) + { + result.add(new EntityTypePropertyTypeComboModel(etpt)); + } + return result; + } + + @Override + protected void loadData(AbstractAsyncCallback<List<EntityTypePropertyType<?>>> callback) + { + // nothing to do - list was injected in constructor + } + + public DatabaseModificationKind[] getRelevantModifications() + { + return DatabaseModificationKind.any(ObjectKind.PROPERTY_TYPE); + } +} diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/property_type/PropertyTypeAssignmentForm.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/property_type/PropertyTypeAssignmentForm.java index c63cc90b1cd197959e94227fabc2c3bed5247e90..e3587f0bb3aef0863267a3dcbb9ca3d48d807f69 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/property_type/PropertyTypeAssignmentForm.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/property_type/PropertyTypeAssignmentForm.java @@ -16,6 +16,7 @@ package ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.property_type; +import java.util.ArrayList; import java.util.List; import java.util.Set; @@ -115,6 +116,8 @@ public final class PropertyTypeAssignmentForm extends LayoutContainer implements // TODO 2009-10-26, Piotr Buczek: use combo box private Field<String> sectionField; + private EntityTypePropertyTypeSelectionWidget etptSelectionWidget; + private Button saveButton; private final InfoBox infoBox; @@ -176,8 +179,7 @@ public final class PropertyTypeAssignmentForm extends LayoutContainer implements { public void handleEvent(BaseEvent be) { - updateDefaultField(); - updateEntityTypePropertyTypeFields(); + updatePropertyTypeRelatedFields(); } }); } @@ -244,7 +246,7 @@ public final class PropertyTypeAssignmentForm extends LayoutContainer implements { public void handleEvent(BaseEvent be) { - updateEntityTypePropertyTypeFields(); + updatePropertyTypeEntityTypeRelatedFields(); } }); return result; @@ -326,10 +328,7 @@ public final class PropertyTypeAssignmentForm extends LayoutContainer implements */ private Long getPreviousETPTOrdinal() { - // development version - append - final List<? extends EntityTypePropertyType<?>> allETPTs = - tryGetSelectedEntityType().getAssignedPropertyTypes(); - return (allETPTs.size() > 0) ? allETPTs.get(allETPTs.size() - 1).getOrdinal() : 0L; + return etptSelectionWidget.getSelectedEntityTypePropertyTypeOrdinal(); } private EntityType tryGetSelectedEntityType() @@ -355,8 +354,7 @@ public final class PropertyTypeAssignmentForm extends LayoutContainer implements formPanel.add(propertyTypeWidget); formPanel.add(typeSelectionWidget); formPanel.add(getMandatoryCheckbox()); - updateDefaultField(); - updateEntityTypePropertyTypeFields(); + updatePropertyTypeRelatedFields(); modificationManager.addObserver(propertyTypeWidget); modificationManager.addObserver(typeSelectionWidget); @@ -397,9 +395,9 @@ public final class PropertyTypeAssignmentForm extends LayoutContainer implements } } - private void updateDefaultField() + private void updatePropertyTypeRelatedFields() { - hideDefaultField(); + hidePropertyTypeRelatedFields(); final PropertyType propertyType = propertyTypeSelectionWidget.tryGetSelectedPropertyType(); if (propertyType != null) { @@ -415,9 +413,10 @@ public final class PropertyTypeAssignmentForm extends LayoutContainer implements formPanel.add(defaultValueField.get()); } layout(); + updatePropertyTypeEntityTypeRelatedFields(); } - private void hideDefaultField() + private void hidePropertyTypeRelatedFields() { if (defaultValueField != null) { @@ -426,44 +425,63 @@ public final class PropertyTypeAssignmentForm extends LayoutContainer implements formPanel.remove(field); defaultValueField = null; } + hideEntityTypePropertyTypeRelatedFields(); } // - private void updateEntityTypePropertyTypeFields() + private void updatePropertyTypeEntityTypeRelatedFields() { - hideEntityTypePropertyTypeFields(); + hideEntityTypePropertyTypeRelatedFields(); final PropertyType propertyType = propertyTypeSelectionWidget.tryGetSelectedPropertyType(); final EntityType entityType = tryGetSelectedEntityType(); if (propertyType != null && entityType != null) { - System.err.println(); - for (EntityTypePropertyType<?> etpt : entityType.getAssignedPropertyTypes()) - { - System.err.println((propertyType.equals(etpt.getPropertyType()) ? "*" : "") - + etpt.getPropertyType().getCode()); - } - sectionField = new VarcharField(viewContext.getMessage(Dict.SECTION), false); - sectionField.setToolTip(viewContext.getMessage(Dict.SECTION_TOOLTIP)); - sectionField.setId(createChildId(SECTION_VALUE_ID_PART - + propertyType.isInternalNamespace() + propertyType.getSimpleCode())); - - sectionField.show(); + sectionField = createSectionField(entityType); formPanel.add(sectionField); + etptSelectionWidget = createETPTSelectionWidget(entityType); + formPanel.add(etptSelectionWidget); } layout(); } - private void hideEntityTypePropertyTypeFields() + private void hideEntityTypePropertyTypeRelatedFields() { - if (sectionField != null) + if (sectionField != null && etptSelectionWidget != null) { sectionField.hide(); + etptSelectionWidget.hide(); formPanel.remove(sectionField); + formPanel.remove(etptSelectionWidget); sectionField = null; + etptSelectionWidget = null; } } + private EntityTypePropertyTypeSelectionWidget createETPTSelectionWidget(EntityType entityType) + { + // by default - append + final List<EntityTypePropertyType<?>> all = + new ArrayList<EntityTypePropertyType<?>>(entityType.getAssignedPropertyTypes()); + all.add(0, null); // null will be transformed into '(top)' + final String lastCode = + (all.size() > 1) ? all.get(all.size() - 1).getPropertyType().getCode() + : EntityTypePropertyTypeSelectionWidget.TOP_ITEM_CODE; + final EntityTypePropertyTypeSelectionWidget result = + new EntityTypePropertyTypeSelectionWidget(viewContext, getId(), all, lastCode); + FieldUtil.setMandatoryFlag(result, true); + return result; + } + + private Field<String> createSectionField(EntityType entityType) + { + Field<String> result = new VarcharField(viewContext.getMessage(Dict.SECTION), false); + result.setToolTip(viewContext.getMessage(Dict.SECTION_TOOLTIP)); + result.setId(createChildId(SECTION_VALUE_ID_PART + entityType.getCode())); + result.show(); + return result; + } + // private final void submitForm() @@ -481,7 +499,9 @@ public final class PropertyTypeAssignmentForm extends LayoutContainer implements private void resetForm() { formPanel.reset(); - updateDefaultField(); + updatePropertyTypeRelatedFields(); + // need to refresh list of assigned property types + getTypeSelectionWidget().refreshStore(); } public DatabaseModificationKind[] getRelevantModifications() diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/public/common-dictionary.js b/openbis/source/java/ch/systemsx/cisd/openbis/public/common-dictionary.js index 0aff066246565c8d0be34158958b3f3c8dfbfded..253d66561248a2f3f3f11bc99a2b2b48086ca3d5 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/public/common-dictionary.js +++ b/openbis/source/java/ch/systemsx/cisd/openbis/public/common-dictionary.js @@ -12,6 +12,7 @@ var common = { attachment: "Attachment", code: "Code", ordinal: "Ordinal", + position_after: "Position After", section: "Section", file: "File", perm_id: "PermID",