From f3f2e4bd30eb22e2b642163ba6e32435a1c5287f Mon Sep 17 00:00:00 2001 From: kaloyane <kaloyane> Date: Mon, 17 Jan 2011 13:46:10 +0000 Subject: [PATCH] minor: use radio buttons instead of combobox when choosing the script type in PropertyAssignmentForm SVN: 19448 --- .../PropertyTypeAssignmentForm.java | 62 +++++++++++++------ .../ScriptTypeSelectionWidget.java | 10 --- 2 files changed, 43 insertions(+), 29 deletions(-) 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 d80b00d580d..c95c693815f 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 @@ -21,6 +21,7 @@ import java.util.List; import java.util.Set; import com.extjs.gxt.ui.client.Style.HorizontalAlignment; +import com.extjs.gxt.ui.client.Style.Orientation; import com.extjs.gxt.ui.client.Style.Scroll; import com.extjs.gxt.ui.client.event.BaseEvent; import com.extjs.gxt.ui.client.event.ButtonEvent; @@ -32,6 +33,8 @@ import com.extjs.gxt.ui.client.widget.button.Button; import com.extjs.gxt.ui.client.widget.form.CheckBox; import com.extjs.gxt.ui.client.widget.form.Field; import com.extjs.gxt.ui.client.widget.form.FormPanel; +import com.extjs.gxt.ui.client.widget.form.Radio; +import com.extjs.gxt.ui.client.widget.form.RadioGroup; import com.extjs.gxt.ui.client.widget.layout.FlowLayout; import com.google.gwt.user.client.Element; @@ -137,7 +140,11 @@ public final class PropertyTypeAssignmentForm extends LayoutContainer implements private final ScriptChooserField scriptChooser; - private final ScriptTypeSelectionWidget scriptTypeChooser; + private Radio scriptTypeManaged; + + private Radio scriptTypeDynamic; + + private final RadioGroup scriptTypeRadioGroup; public static DatabaseModificationAwareComponent create( final IViewContext<ICommonClientServiceAsync> viewContext, EntityKind entityKind) @@ -157,7 +164,7 @@ public final class PropertyTypeAssignmentForm extends LayoutContainer implements setScrollMode(Scroll.AUTO); add(infoBox = createInfoBox()); add(formPanel = createFormPanel()); - scriptTypeChooser = createScriptTypeChooserField(viewContext); + scriptTypeRadioGroup = createScriptTypeRadioGroup(); scriptChooser = createScriptChooserField(viewContext, createScriptTypeProvider(), entityKind); } @@ -168,21 +175,11 @@ public final class PropertyTypeAssignmentForm extends LayoutContainer implements { public ScriptType tryGetScriptType() { - return scriptTypeChooser.getSimpleValue(); + return isManaged() ? ScriptType.MANAGED_PROPERTY : ScriptType.DYNAMIC_PROPERTY; } }; } - private static ScriptTypeSelectionWidget createScriptTypeChooserField( - IViewContext<ICommonClientServiceAsync> viewContext) - { - ScriptTypeSelectionWidget field = - ScriptTypeSelectionWidget.createPropertyScriptTypes(viewContext); - FieldUtil.setVisibility(false, field); - FieldUtil.markAsMandatory(field); - return field; - } - private static ScriptChooserField createScriptChooserField( final IViewContext<ICommonClientServiceAsync> viewContext, IScriptTypeProvider scriptTypeProvider, EntityKind entityKindOrNull) @@ -210,6 +207,35 @@ public final class PropertyTypeAssignmentForm extends LayoutContainer implements return infoBox; } + private final RadioGroup createScriptTypeRadioGroup() + { + final RadioGroup result = new RadioGroup(); + result.setSelectionRequired(true); + result.setVisible(false); + result.setOrientation(Orientation.HORIZONTAL); + scriptTypeManaged = createRadio(ScriptType.MANAGED_PROPERTY.getDescription()); + scriptTypeDynamic = createRadio(ScriptType.DYNAMIC_PROPERTY.getDescription()); + result.add(scriptTypeManaged); + result.add(scriptTypeDynamic); + FieldUtil.setValueWithoutEvents(result, scriptTypeManaged); + result.setLabelSeparator(""); + result.addListener(Events.Change, new Listener<BaseEvent>() + { + public void handleEvent(BaseEvent be) + { + scriptChooser.setValue(""); + } + }); + return result; + } + + private final Radio createRadio(final String label) + { + Radio result = new Radio(); + result.setBoxLabel(label); + return result; + } + private PropertyTypeSelectionWidget getPropertyTypeWidget() { if (propertyTypeSelectionWidget == null) @@ -299,7 +325,7 @@ public final class PropertyTypeAssignmentForm extends LayoutContainer implements private void updateVisibilityOfScriptRelatedFields() { boolean scriptable = isScriptable(); - FieldUtil.setVisibility(scriptable, scriptTypeChooser, scriptChooser); + FieldUtil.setVisibility(scriptable, scriptTypeRadioGroup, scriptChooser); if (defaultValueField != null) { FieldUtil.setVisibility(scriptable == false, defaultValueField.get()); @@ -434,7 +460,7 @@ public final class PropertyTypeAssignmentForm extends LayoutContainer implements formPanel.add(propertyTypeWidget); formPanel.add(typeSelectionWidget); formPanel.add(getScriptableCheckbox()); - formPanel.add(scriptTypeChooser); + formPanel.add(scriptTypeRadioGroup); formPanel.add(scriptChooser); formPanel.add(getMandatoryCheckbox()); updatePropertyTypeRelatedFields(); @@ -576,14 +602,12 @@ public final class PropertyTypeAssignmentForm extends LayoutContainer implements boolean isDynamic() { - ScriptType scriptTypeOrNull = scriptTypeChooser.getSimpleValue(); - return scriptTypeOrNull != null && scriptTypeOrNull == ScriptType.DYNAMIC_PROPERTY; + return isScriptable() && scriptTypeDynamic.getValue(); } boolean isManaged() { - ScriptType scriptTypeOrNull = scriptTypeChooser.getSimpleValue(); - return scriptTypeOrNull != null && scriptTypeOrNull == ScriptType.MANAGED_PROPERTY; + return isScriptable() && scriptTypeManaged.getValue(); } // diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/property_type/ScriptTypeSelectionWidget.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/property_type/ScriptTypeSelectionWidget.java index 6883ca9c376..dcc80f6b444 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/property_type/ScriptTypeSelectionWidget.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/property_type/ScriptTypeSelectionWidget.java @@ -44,16 +44,6 @@ public final class ScriptTypeSelectionWidget extends SimpleComboBox<ScriptType> Dict.COMBO_BOX_CHOOSE, "script type"), Arrays.asList(ScriptType.values())); } - /** creates a combo box with script types related with property types */ - public static ScriptTypeSelectionWidget createPropertyScriptTypes( - final IViewContext<ICommonClientServiceAsync> viewContext) - { - return new ScriptTypeSelectionWidget(viewContext.getMessage(Dict.SCRIPT_TYPE), - viewContext.getMessage(Dict.SCRIPT_TYPE), viewContext.getMessage( - Dict.COMBO_BOX_CHOOSE, "script type"), Arrays.asList( - ScriptType.DYNAMIC_PROPERTY, ScriptType.MANAGED_PROPERTY)); - } - private ScriptTypeSelectionWidget(final String fieldLabel, final String toolTip, final String chooseText, final List<ScriptType> scriptTypes) { -- GitLab