Skip to content
Snippets Groups Projects
Commit 82a44fc7 authored by tpylak's avatar tpylak
Browse files

LMS-749 possibility of pretty printing the description of the user query

SVN: 9778
parent 92e8ea80
No related branches found
No related tags found
No related merge requests found
......@@ -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.
......
......@@ -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
......@@ -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);
}
......
......@@ -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
......@@ -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;
......
......@@ -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}.
......
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