From 82a44fc753a9c4a70cd61a867fc9d140a2251e52 Mon Sep 17 00:00:00 2001 From: tpylak <tpylak> Date: Tue, 10 Feb 2009 15:46:02 +0000 Subject: [PATCH] LMS-749 possibility of pretty printing the description of the user query SVN: 9778 --- .../application/ui/data/CriteriaWidget.java | 25 +++++++++++++++++++ .../application/ui/data/CriterionWidget.java | 24 +++++++++++++++--- .../DataSetSearchFieldsSelectionWidget.java | 13 ++++++++-- .../ui/data/MatchCriteriaRadio.java | 12 ++++++++- .../PropertyTypeRegistrationForm.java | 12 ++++----- .../web/client/application/util/GWTUtils.java | 20 ++++++++++++++- 6 files changed, 91 insertions(+), 15 deletions(-) diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/data/CriteriaWidget.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/data/CriteriaWidget.java index f20ad9e75f3..c81c34d5bcd 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/data/CriteriaWidget.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/data/CriteriaWidget.java @@ -113,6 +113,31 @@ public class CriteriaWidget extends VerticalPanel } + /** description of the search criteria for the user */ + public String getCriteriaDescription() + { + StringBuffer sb = new StringBuffer(); + sb.append(matchRadios.getSelectedLabel()); + sb.append(": "); + boolean first = true; + for (CriterionWidget cw : criteriaWidgets) + { + String desc = cw.tryGetDescription(); + if (desc != null) + { + if (first == false) + { + sb.append(", "); + } else + { + first = false; + } + sb.append(desc); + } + } + return sb.toString(); + } + /** * Resets "match criteria" radio buttons to initial values, removes unnecessary criteria widgets * and resets the remaining ones. diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/data/CriterionWidget.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/data/CriterionWidget.java index f91b859416f..c15a5c90868 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/data/CriterionWidget.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/data/CriterionWidget.java @@ -60,15 +60,19 @@ public class CriterionWidget extends HorizontalPanel generatedChildren = 0; this.parent = parent; this.idSuffix = idSuffix; + this.nameField = nameField; + this.valueField = new TextField<String>(); + this.removeButton = createRemoveButton(); + final TableData tableData = new TableData(HorizontalAlignment.LEFT, VerticalAlignment.BOTTOM); tableData.setPadding(1); - add(this.nameField = nameField, tableData); - nameField.setWidth(300); - add(valueField = new TextField<String>(), tableData); + add(this.nameField, tableData); + this.nameField.setWidth(300); + add(valueField, tableData); valueField.setWidth(150); add(createAddButton(), tableData); - add(removeButton = createRemoveButton(), tableData); + add(removeButton, tableData); } /** @@ -155,4 +159,16 @@ public class CriterionWidget extends HorizontalPanel return null; } + + public String tryGetDescription() + { + DataSetSearchCriterion criterion = tryGetValue(); + String name = nameField.tryGetSelectedCode(); + if (criterion == null || name == null) + { + return null; + } + + return name + " = " + criterion.getValue(); + } } \ No newline at end of file diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/data/DataSetSearchFieldsSelectionWidget.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/data/DataSetSearchFieldsSelectionWidget.java index 4d97f8f8ecf..5fa7cc77283 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/data/DataSetSearchFieldsSelectionWidget.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/data/DataSetSearchFieldsSelectionWidget.java @@ -86,6 +86,14 @@ public final class DataSetSearchFieldsSelectionWidget extends return (DataSetSearchField) GWTUtils.tryGetSingleSelected(this); } + /** + * Returns code of the selected option, or null - if nothing selected. + */ + public String tryGetSelectedCode() + { + return GWTUtils.tryGetSingleSelectedCode(this); + } + public DataSetSearchFieldsSelectionWidget(DataSetSearchFieldsSelectionWidget source, final String idSuffix) { @@ -181,8 +189,9 @@ public final class DataSetSearchFieldsSelectionWidget extends private DataSetSearchFieldComboModel createComboModel(final PropertyType propertyType, DataSetSearchField searchField, boolean useCode) { - String prefix = getDisplayName(searchField.getKind()) + ": "; - String code = prefix + (useCode ? propertyType.getCode() : propertyType.getLabel()); + String prefix = getDisplayName(searchField.getKind()); + String property = (useCode ? propertyType.getCode() : propertyType.getLabel()); + String code = prefix + " \'" + property + "\'"; return new DataSetSearchFieldComboModel(code, searchField); } diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/data/MatchCriteriaRadio.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/data/MatchCriteriaRadio.java index edc0ece0bfe..a10836aca7e 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/data/MatchCriteriaRadio.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/data/MatchCriteriaRadio.java @@ -62,9 +62,14 @@ public class MatchCriteriaRadio extends HorizontalPanel orRadio.setValue(true); } + String getSelectedLabel() + { + return isAndSelected() ? andRadio.getBoxLabel() : orRadio.getBoxLabel(); + } + SearchCriteria.CriteriaConnection getSelected() { - if (andRadio.getValue() != null && andRadio.getValue().booleanValue() == true) + if (isAndSelected()) { return SearchCriteria.CriteriaConnection.AND; } else @@ -72,4 +77,9 @@ public class MatchCriteriaRadio extends HorizontalPanel return SearchCriteria.CriteriaConnection.OR; } } + + private boolean isAndSelected() + { + return andRadio.getValue() != null && andRadio.getValue().booleanValue() == true; + } } \ No newline at end of file diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/property_type/PropertyTypeRegistrationForm.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/property_type/PropertyTypeRegistrationForm.java index 41c0d1a2bb8..d8f2f47df9d 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/property_type/PropertyTypeRegistrationForm.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/property_type/PropertyTypeRegistrationForm.java @@ -16,7 +16,6 @@ package ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.property_type; -import com.extjs.gxt.ui.client.data.BaseModelData; import com.extjs.gxt.ui.client.event.SelectionChangedEvent; import com.extjs.gxt.ui.client.event.SelectionChangedListener; import com.extjs.gxt.ui.client.widget.LayoutContainer; @@ -155,16 +154,15 @@ public final class PropertyTypeRegistrationForm extends AbstractRegistrationForm propertyType.setDataType(selectedDataType); if (DataTypeCode.CONTROLLEDVOCABULARY.equals(selectedDataType.getCode())) { - final BaseModelData vocabulary = - GWTUtils.tryGetSingleSelectedModel(vocabularySelectionWidget); - if (VocabularySelectionWidget.NEW_VOCABULARY_CODE.equals(vocabulary - .get(ModelDataPropertyNames.CODE))) + final String selectedVocabularyCode = + GWTUtils.tryGetSingleSelectedCode(vocabularySelectionWidget); + if (VocabularySelectionWidget.NEW_VOCABULARY_CODE.equals(selectedVocabularyCode)) { propertyType.setVocabulary(vocabularyRegistrationFieldSet.createVocabulary()); } else { - propertyType.setVocabulary((Vocabulary) vocabulary - .get(ModelDataPropertyNames.OBJECT)); + propertyType.setVocabulary((Vocabulary) GWTUtils + .tryGetSingleSelected(vocabularySelectionWidget)); } } return propertyType; diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/util/GWTUtils.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/util/GWTUtils.java index 334ef4b9596..93e53a5a8ee 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/util/GWTUtils.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/util/GWTUtils.java @@ -139,7 +139,8 @@ public final class GWTUtils * * @returns <code>null</code> if nothing is selected. */ - public final static <T extends ModelData> T tryGetSingleSelectedModel(final ComboBox<T> comboBox) + private final static <T extends ModelData> T tryGetSingleSelectedModel( + final ComboBox<T> comboBox) { assert comboBox != null : "Unspecified combo box."; final List<T> selection = comboBox.getSelection(); @@ -152,6 +153,23 @@ public final class GWTUtils return null; } + /** + * Tries to return the selected object code (saved as {@link ModelDataPropertyNames#CODE} in the + * model) from the given {@link ComboBox}. + * + * @returns <code>null</code> if nothing is selected. + */ + public final static <T extends ModelData, O> String tryGetSingleSelectedCode( + final ComboBox<T> comboBox) + { + T selectedModel = GWTUtils.tryGetSingleSelectedModel(comboBox); + if (selectedModel == null) + { + return null; + } + return selectedModel.get(ModelDataPropertyNames.CODE); + } + /** * Tries to return the selected object (saved as {@link ModelDataPropertyNames#OBJECT} in the * model) from the given {@link ComboBox}. -- GitLab