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

[LMS-1194] added section combo box

SVN: 13099
parent ae3b0beb
No related branches found
No related tags found
No related merge requests found
......@@ -49,7 +49,6 @@ import ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.Abstrac
import ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.data.DataSetTypeSelectionWidget;
import ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.experiment.ExperimentTypeSelectionWidget;
import ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.field.PropertyFieldFactory;
import ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.field.VarcharField;
import ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.material.MaterialTypeSelectionWidget;
import ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.sample.SampleTypeSelectionWidget;
import ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.widget.DropDownList;
......@@ -113,8 +112,7 @@ public final class PropertyTypeAssignmentForm extends LayoutContainer implements
private CheckBox mandatoryCheckbox;
// TODO 2009-10-26, Piotr Buczek: use combo box
private Field<String> sectionField;
private SectionSelectionWidget sectionSelectionWidget;
private EntityTypePropertyTypeSelectionWidget etptSelectionWidget;
......@@ -302,9 +300,9 @@ public final class PropertyTypeAssignmentForm extends LayoutContainer implements
private String getSectionValue()
{
if (sectionField != null)
if (sectionSelectionWidget != null)
{
return sectionField.getValue();
return sectionSelectionWidget.getSimpleValue();
}
return null;
}
......@@ -437,9 +435,11 @@ public final class PropertyTypeAssignmentForm extends LayoutContainer implements
final EntityType entityType = tryGetSelectedEntityType();
if (propertyType != null && entityType != null)
{
sectionField = createSectionField(entityType);
formPanel.add(sectionField);
etptSelectionWidget = createETPTSelectionWidget(entityType);
final List<EntityTypePropertyType<?>> etpts =
new ArrayList<EntityTypePropertyType<?>>(entityType.getAssignedPropertyTypes());
sectionSelectionWidget = createSectionSelectionWidget(etpts);
formPanel.add(sectionSelectionWidget);
etptSelectionWidget = createETPTSelectionWidget(etpts);
formPanel.add(etptSelectionWidget);
}
layout();
......@@ -447,39 +447,35 @@ public final class PropertyTypeAssignmentForm extends LayoutContainer implements
private void hideEntityTypePropertyTypeRelatedFields()
{
if (sectionField != null && etptSelectionWidget != null)
if (sectionSelectionWidget != null && etptSelectionWidget != null)
{
sectionField.hide();
sectionSelectionWidget.hide();
etptSelectionWidget.hide();
formPanel.remove(sectionField);
formPanel.remove(sectionSelectionWidget);
formPanel.remove(etptSelectionWidget);
sectionField = null;
sectionSelectionWidget = null;
etptSelectionWidget = null;
}
}
private EntityTypePropertyTypeSelectionWidget createETPTSelectionWidget(EntityType entityType)
private EntityTypePropertyTypeSelectionWidget createETPTSelectionWidget(
List<EntityTypePropertyType<?>> etpts)
{
// by default - append
final List<EntityTypePropertyType<?>> all =
new ArrayList<EntityTypePropertyType<?>>(entityType.getAssignedPropertyTypes());
all.add(0, null); // null will be transformed into '(top)'
etpts.add(0, null); // null will be transformed into '(top)'
final String lastCode =
(all.size() > 1) ? all.get(all.size() - 1).getPropertyType().getCode()
(etpts.size() > 1) ? etpts.get(etpts.size() - 1).getPropertyType().getCode()
: EntityTypePropertyTypeSelectionWidget.TOP_ITEM_CODE;
final EntityTypePropertyTypeSelectionWidget result =
new EntityTypePropertyTypeSelectionWidget(viewContext, getId(), all, lastCode);
new EntityTypePropertyTypeSelectionWidget(viewContext, getId(), etpts, lastCode);
FieldUtil.setMandatoryFlag(result, true);
return result;
}
private Field<String> createSectionField(EntityType entityType)
private SectionSelectionWidget createSectionSelectionWidget(
List<EntityTypePropertyType<?>> etpts)
{
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;
return SectionSelectionWidget.create(viewContext, etpts);
}
//
......
......@@ -43,7 +43,6 @@ import ch.systemsx.cisd.openbis.generic.client.web.client.application.model.Base
import ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.columns.framework.IColumnDefinitionKind;
import ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.columns.specific.PropertyTypeAssignmentColDefKind;
import ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.field.PropertyFieldFactory;
import ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.field.VarcharField;
import ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.grid.AbstractSimpleBrowserGrid;
import ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.grid.IBrowserGridActionInvoker;
import ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.grid.IDisposableComponent;
......@@ -243,7 +242,7 @@ public class PropertyTypeAssignmentGrid extends
private final boolean originalIsMandatory;
private final Field<String> sectionField;
private final SectionSelectionWidget sectionSelectionWidget;
private final EntityTypePropertyTypeSelectionWidget etptSelectionWidget;
......@@ -283,32 +282,40 @@ public class PropertyTypeAssignmentGrid extends
defaultValueField = null;
}
// TODO 2009-10-26, Piotr Buczek: use combo box
sectionField = new VarcharField(viewContext.getMessage(Dict.SECTION), false);
sectionField.setValue(etpt.getSection());
addField(sectionField);
final List<EntityTypePropertyType<?>> etpts =
getEntityTypePropertyTypes(etpt.getEntityType());
etptSelectionWidget = createETPTSelectionWidget();
sectionSelectionWidget = createSectionSelectionWidget(etpts);
sectionSelectionWidget.setSimpleValue(etpt.getSection());
addField(sectionSelectionWidget);
etptSelectionWidget = createETPTSelectionWidget(etpts);
addField(etptSelectionWidget);
}
private EntityTypePropertyTypeSelectionWidget createETPTSelectionWidget()
private SectionSelectionWidget createSectionSelectionWidget(
List<EntityTypePropertyType<?>> etpts)
{
return SectionSelectionWidget.create(viewContext, etpts);
}
private EntityTypePropertyTypeSelectionWidget createETPTSelectionWidget(
List<EntityTypePropertyType<?>> allETPTs)
{
final EntityType entityType = etpt.getEntityType();
// create a new list of items from all etpts assigned to entity type
final List<EntityTypePropertyType<?>> all =
final List<EntityTypePropertyType<?>> etpts =
new ArrayList<EntityTypePropertyType<?>>();
all.add(null); // null will be transformed into '(top)'
etpts.add(null); // null will be transformed into '(top)'
String initialPropertyTypeCodeOrNull = null;
String previousPropertyTypeCodeOrNull =
EntityTypePropertyTypeSelectionWidget.TOP_ITEM_CODE;
for (EntityTypePropertyType<?> currentETPT : getPropertyTypes(entityType))
for (EntityTypePropertyType<?> currentETPT : allETPTs)
{
final String currentPropertyTypeCode =
currentETPT.getPropertyType().getCode();
if (propertyTypeCode.equals(currentPropertyTypeCode) == false)
{
all.add(currentETPT);
etpts.add(currentETPT);
previousPropertyTypeCodeOrNull = currentPropertyTypeCode;
} else
{
......@@ -316,7 +323,7 @@ public class PropertyTypeAssignmentGrid extends
}
}
final EntityTypePropertyTypeSelectionWidget result =
new EntityTypePropertyTypeSelectionWidget(viewContext, getId(), all,
new EntityTypePropertyTypeSelectionWidget(viewContext, getId(), etpts,
initialPropertyTypeCodeOrNull);
FieldUtil.setMandatoryFlag(result, true);
return result;
......@@ -324,7 +331,7 @@ public class PropertyTypeAssignmentGrid extends
private String getSectionValue()
{
return sectionField.getValue();
return sectionSelectionWidget.getSimpleValue();
}
/**
......@@ -397,7 +404,7 @@ public class PropertyTypeAssignmentGrid extends
PropertyTypeAssignmentColDefKind.ENTITY_KIND });
}
private List<EntityTypePropertyType<?>> getPropertyTypes(EntityType entityType)
private List<EntityTypePropertyType<?>> getEntityTypePropertyTypes(EntityType entityType)
{
return entityTypePropertyTypes.get(entityType);
}
......
/*
* 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.LinkedHashSet;
import java.util.List;
import java.util.Set;
import com.extjs.gxt.ui.client.widget.form.ComboBox;
import com.extjs.gxt.ui.client.widget.form.SimpleComboBox;
import ch.systemsx.cisd.openbis.generic.client.web.client.ICommonClientServiceAsync;
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.shared.basic.dto.EntityTypePropertyType;
/**
* A {@link ComboBox} extension using simple strings for selecting section name of
* {@link EntityTypePropertyType}.
*
* @author Piotr Buczek
*/
public final class SectionSelectionWidget extends SimpleComboBox<String>
{
public static SectionSelectionWidget create(
final IViewContext<ICommonClientServiceAsync> viewContext,
List<EntityTypePropertyType<?>> etpts)
{
final Set<String> sections = new LinkedHashSet<String>(); // linked set preserves order
for (EntityTypePropertyType<?> currentETPT : etpts)
{
final String section = currentETPT.getSection();
if (section != null)
{
sections.add(currentETPT.getSection());
}
}
return new SectionSelectionWidget(viewContext.getMessage(Dict.SECTION), viewContext
.getMessage(Dict.SECTION_TOOLTIP), viewContext.getMessage(Dict.COMBO_BOX_EMPTY,
"sections"), viewContext.getMessage(Dict.COMBO_BOX_CHOOSE, "section"),
new ArrayList<String>(sections));
}
private SectionSelectionWidget(final String fieldLabel, final String toolTip,
final String emptyText, final String chooseText, final List<String> sections)
{
setFieldLabel(fieldLabel);
setToolTip(toolTip);
if (sections.size() == 0)
{
setEmptyText(emptyText);
} else
{
setEmptyText(chooseText);
}
add(sections);
}
}
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