use of com.haulmont.cuba.gui.components.SearchField in project cuba by cuba-platform.
the class SearchFieldLoader method loadComponent.
@Override
public void loadComponent() {
super.loadComponent();
SearchField searchField = (SearchField) resultComponent;
String minSearchStringLength = element.attributeValue("minSearchStringLength");
if (StringUtils.isNotEmpty(minSearchStringLength)) {
searchField.setMinSearchStringLength(Integer.parseInt(minSearchStringLength));
}
String modeString = element.attributeValue("mode");
if (StringUtils.isNotEmpty(modeString)) {
SearchField.Mode mode;
try {
mode = SearchField.Mode.valueOf(StringUtils.upperCase(modeString));
} catch (IllegalArgumentException e) {
throw new GuiDevelopmentException("Unable to parse mode for search", context.getFullFrameId(), "mode", modeString);
}
searchField.setMode(mode);
}
String escapeValueForLike = element.attributeValue("escapeValueForLike");
if (StringUtils.isNotEmpty(escapeValueForLike)) {
searchField.setEscapeValueForLike(Boolean.parseBoolean(escapeValueForLike));
}
}
use of com.haulmont.cuba.gui.components.SearchField in project cuba by cuba-platform.
the class SearchFieldDsTest method testValueChangeListener.
@Test
public void testValueChangeListener() {
SearchField searchField = factory.createComponent(SearchField.class);
CollectionDatasource<Group, UUID> groupsDs = getTestCollectionDatasource();
searchField.setOptionsDatasource(groupsDs);
List<Group> groups = new ArrayList<>(groupsDs.getItems());
Datasource<User> userDs = getTestUserDatasource();
User user = userDs.getItem();
user.setGroup(groups.get(0));
boolean[] valueWasChanged = { false };
Component.ValueChangeListener listener = e -> valueWasChanged[0] = true;
searchField.addValueChangeListener(listener);
searchField.setDatasource(userDs, "group");
assertEquals(true, valueWasChanged[0]);
}
use of com.haulmont.cuba.gui.components.SearchField in project cuba by cuba-platform.
the class SearchFieldDsTest method testUnsubscribeDsListener.
@Test
public void testUnsubscribeDsListener() {
SearchField searchField = factory.createComponent(SearchField.class);
CollectionDatasource<Group, UUID> groupsDs = getTestCollectionDatasource();
searchField.setOptionsDatasource(groupsDs);
Datasource<User> userDs = getTestUserDatasource();
Group group = groupsDs.getItems().iterator().next();
userDs.getItem().setGroup(group);
searchField.setDatasource(userDs, "group");
// unbind
searchField.setDatasource(null, null);
Datasource.ItemPropertyChangeListener<User> listener = e -> {
throw new RuntimeException("Value was changed externally");
};
userDs.addItemPropertyChangeListener(listener);
searchField.setValue(metadata.create(Group.class));
}
use of com.haulmont.cuba.gui.components.SearchField in project cuba by cuba-platform.
the class SearchFieldDsTest method testDatasourceRepeatableAssign.
@Test
public void testDatasourceRepeatableAssign() {
SearchField searchField = (SearchField) factory.createComponent(SearchField.NAME);
searchField.setDatasource(null, null);
searchField.setDatasource(null, null);
Datasource<User> userDs1 = getTestUserDatasource();
boolean exceptionWasThrown = false;
try {
searchField.setDatasource(userDs1, null);
} catch (Exception e) {
exceptionWasThrown = true;
}
assertTrue(exceptionWasThrown);
exceptionWasThrown = false;
try {
searchField.setDatasource(null, "name");
} catch (Exception e) {
exceptionWasThrown = true;
}
assertTrue(exceptionWasThrown);
searchField.setDatasource(userDs1, "name");
searchField.setDatasource(userDs1, "name");
userDs1.getItem().setName("Test name");
searchField.setDatasource(userDs1, "name");
Datasource<User> userDs2 = getTestUserDatasource();
searchField.setDatasource(userDs2, "name");
searchField.setValue(null);
assertEquals("Test name", userDs1.getItem().getName());
}
use of com.haulmont.cuba.gui.components.SearchField in project cuba by cuba-platform.
the class SearchFieldDsTest method testUnsubscribeSubscribeComponentListener.
@Test
public void testUnsubscribeSubscribeComponentListener() {
SearchField searchField = factory.createComponent(SearchField.class);
CollectionDatasource<Group, UUID> groupsDs = getTestCollectionDatasource();
searchField.setOptionsDatasource(groupsDs);
Datasource<User> userDs = getTestUserDatasource();
Group group = groupsDs.getItems().iterator().next();
User user = userDs.getItem();
user.setGroup(group);
searchField.setDatasource(userDs, "group");
// unbind
searchField.setDatasource(null, null);
// setup
boolean[] valueWasChanged = { false };
Component.ValueChangeListener listener = e -> valueWasChanged[0] = true;
// datasource before listener
searchField.setDatasource(userDs, "group");
searchField.addValueChangeListener(listener);
user.setGroup(metadata.create(Group.class));
assertEquals(true, valueWasChanged[0]);
// reset state
valueWasChanged[0] = false;
searchField.setDatasource(null, null);
searchField.removeValueChangeListener(listener);
searchField.setValue(null);
// listener before datasource
searchField.addValueChangeListener(listener);
searchField.setDatasource(userDs, "group");
assertEquals(true, valueWasChanged[0]);
}
Aggregations