use of com.haulmont.cuba.gui.components.PickerField in project cuba by cuba-platform.
the class PickerFieldDsTest method testUnsubscribeWithComponentListener.
@Test
public void testUnsubscribeWithComponentListener() {
PickerField pickerField = (PickerField) factory.createComponent(PickerField.NAME);
Datasource<User> userDs = getTestUserDatasource();
Group group = metadata.create(Group.class);
group.setName("Test group");
userDs.getItem().setGroup(group);
pickerField.setDatasource(userDs, "group");
// unbind
pickerField.setDatasource(null, null);
Component.ValueChangeListener listener = e -> {
throw new RuntimeException("Value was changed externally");
};
pickerField.addValueChangeListener(listener);
userDs.getItem().setGroup(metadata.create(Group.class));
}
use of com.haulmont.cuba.gui.components.PickerField in project cuba by cuba-platform.
the class PickerFieldDsTest method testValueChangeListener.
@Test
public void testValueChangeListener() {
PickerField pickerField = (PickerField) factory.createComponent(PickerField.NAME);
Datasource<User> userDs = getTestUserDatasource();
User user = userDs.getItem();
Group group = metadata.create(Group.class);
group.setName("Test group");
user.setGroup(group);
// datasource before listener
boolean[] valueWasChanged = { false };
Component.ValueChangeListener listener = e -> valueWasChanged[0] = true;
pickerField.addValueChangeListener(listener);
pickerField.setDatasource(userDs, "group");
assertEquals(true, valueWasChanged[0]);
// reset state
pickerField.setDatasource(null, null);
pickerField.removeValueChangeListener(listener);
valueWasChanged[0] = false;
pickerField.setValue(null);
// listener before datasource
pickerField.addValueChangeListener(listener);
pickerField.setDatasource(userDs, "group");
assertEquals(true, valueWasChanged[0]);
}
use of com.haulmont.cuba.gui.components.PickerField in project cuba by cuba-platform.
the class DynamicAttributesGuiTools method initEntityPickerField.
/**
* Initializes the pickerField for selecting the dynamic attribute value. If the CategoryAttribute has "where" or
* "join" clauses then the data in lookup screens will be filtered with these clauses
*
* @param pickerField PickerField component whose lookup action must be initialized
* @param categoryAttribute CategoryAttribute that is represented by the pickerField
*/
public void initEntityPickerField(PickerField pickerField, CategoryAttribute categoryAttribute) {
Class javaClass = categoryAttribute.getJavaClassForEntity();
if (javaClass == null) {
throw new IllegalArgumentException("Entity type is not specified in category attribute");
}
MetaClass metaClass = metadata.getClassNN(javaClass);
PickerField.LookupAction lookupAction = (PickerField.LookupAction) pickerField.getAction(PickerField.LookupAction.NAME);
if (!Strings.isNullOrEmpty(categoryAttribute.getJoinClause()) || !Strings.isNullOrEmpty(categoryAttribute.getWhereClause())) {
lookupAction = createLookupAction(pickerField, categoryAttribute.getJoinClause(), categoryAttribute.getWhereClause());
pickerField.addAction(lookupAction);
}
if (lookupAction == null) {
lookupAction = pickerField.addLookupAction();
}
String screen = categoryAttribute.getScreen();
if (StringUtils.isNotBlank(screen)) {
lookupAction.setLookupScreen(screen);
} else {
screen = windowConfig.getBrowseScreenId(metaClass);
if (windowConfig.findWindowInfo(screen) != null) {
lookupAction.setLookupScreen(screen);
lookupAction.setLookupScreenOpenType(OpenType.THIS_TAB);
} else {
lookupAction.setLookupScreen(CommonLookupController.SCREEN_ID);
lookupAction.setLookupScreenParams(ParamsMap.of(CommonLookupController.CLASS_PARAMETER, metaClass));
lookupAction.setLookupScreenOpenType(OpenType.DIALOG);
}
}
}
use of com.haulmont.cuba.gui.components.PickerField in project cuba by cuba-platform.
the class PickerFieldDsTest method testUnsubscribeSubscribeDsListener.
@Test
public void testUnsubscribeSubscribeDsListener() {
PickerField pickerField = (PickerField) factory.createComponent(PickerField.NAME);
Datasource<User> userDs = getTestUserDatasource();
Group group = metadata.create(Group.class);
group.setName("Test group");
userDs.getItem().setGroup(group);
pickerField.setDatasource(userDs, "group");
// unbind
pickerField.setDatasource(null, null);
// setup
boolean[] valueWasChanged = { false };
Datasource.ItemPropertyChangeListener<User> listener = e -> valueWasChanged[0] = true;
userDs.addItemPropertyChangeListener(listener);
pickerField.setDatasource(userDs, "group");
pickerField.setValue(null);
assertEquals(true, valueWasChanged[0]);
}
use of com.haulmont.cuba.gui.components.PickerField in project cuba by cuba-platform.
the class PickerFieldDsTest method testDatasourceRepeatableAssign.
@Test
public void testDatasourceRepeatableAssign() {
PickerField pickerField = (PickerField) factory.createComponent(PickerField.NAME);
pickerField.setDatasource(null, null);
pickerField.setDatasource(null, null);
Datasource<User> userDs1 = getTestUserDatasource();
boolean exceptionWasThrown = false;
try {
pickerField.setDatasource(userDs1, null);
} catch (Exception e) {
exceptionWasThrown = true;
}
assertTrue(exceptionWasThrown);
exceptionWasThrown = false;
try {
pickerField.setDatasource(null, "group");
} catch (Exception e) {
exceptionWasThrown = true;
}
assertTrue(exceptionWasThrown);
pickerField.setDatasource(userDs1, "group");
pickerField.setDatasource(userDs1, "group");
userDs1.getItem().setGroup(metadata.create(Group.class));
pickerField.setDatasource(userDs1, "group");
Datasource<User> userDs2 = getTestUserDatasource();
pickerField.setDatasource(userDs2, "group");
pickerField.setValue(null);
assertNotNull(userDs1.getItem().getGroup());
}
Aggregations