Skip to content
Snippets Groups Projects
Commit 6a8bff3d authored by buczekp's avatar buczekp
Browse files

[LMS-1194] allow to specify order in property type assignment form

SVN: 13086
parent d1f520f4
No related branches found
No related tags found
No related merge requests found
......@@ -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";
......
......@@ -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();
}
......
/*
* 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);
}
}
......@@ -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()
......
......@@ -12,6 +12,7 @@ var common = {
attachment: "Attachment",
code: "Code",
ordinal: "Ordinal",
position_after: "Position After",
section: "Section",
file: "File",
perm_id: "PermID",
......
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