use of com.haulmont.cuba.gui.actions.picker.LookupAction 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);
Action lookupAction = pickerField.getAction(LookupAction.ID);
if (lookupAction == null) {
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) {
guiActionSupport.createActionById(pickerField, PickerField.LookupAction.NAME);
}
String screen = categoryAttribute.getScreen();
if (lookupAction instanceof LookupAction) {
initPickerField((LookupAction<?>) lookupAction, screen, metaClass, javaClass);
} else if (lookupAction instanceof PickerField.LookupAction) {
initLegacyPickerField((PickerField.LookupAction) lookupAction, screen, metaClass, javaClass);
}
}
use of com.haulmont.cuba.gui.actions.picker.LookupAction in project cuba by cuba-platform.
the class InputDialog method createEntityField.
@SuppressWarnings("unchecked")
protected Field createEntityField(InputParameter parameter) {
MetaClass metaClass = metadata.getClassNN(parameter.getEntityClass());
Action lookupAction = actions.create(LookupAction.ID);
Action clearAction = actions.create(ClearAction.ID);
if (persistenceManagerService.useLookupScreen(metaClass.getName())) {
PickerField pickerField = uiComponents.create(PickerField.NAME);
pickerField.setMetaClass(metadata.getClass(parameter.getEntityClass()));
pickerField.addAction(lookupAction);
pickerField.addAction(clearAction);
pickerField.setWidthFull();
return pickerField;
} else {
LookupPickerField lookupPickerField = uiComponents.create(LookupPickerField.NAME);
lookupPickerField.addAction(lookupAction);
lookupPickerField.addAction(clearAction);
lookupPickerField.setWidthFull();
CollectionContainer container = dataComponents.createCollectionContainer(parameter.getEntityClass());
CollectionLoader loader = dataComponents.createCollectionLoader();
loader.setQuery("select e from " + metaClass.getName() + " e");
loader.setView(View.MINIMAL);
loader.setContainer(container);
loader.load();
lookupPickerField.setOptions(new ContainerOptions(container));
return lookupPickerField;
}
}
use of com.haulmont.cuba.gui.actions.picker.LookupAction in project cuba by cuba-platform.
the class DataGridEditorComponentGenerationStrategy method setupPickerFieldActions.
protected void setupPickerFieldActions(PickerField<?> pickerField) {
Map<String, Object> lookupScreenParams = ParamsMap.of("dataGridEditor", true);
PickerField.LookupAction legacyLookupAction = (PickerField.LookupAction) pickerField.getAction(PickerField.LookupAction.NAME);
if (legacyLookupAction != null) {
// Opening lookup screen in another mode will close editor
legacyLookupAction.setLookupScreenOpenType(WindowManager.OpenType.DIALOG);
// In case of adding special logic for lookup screen opened from DataGrid editor
legacyLookupAction.setLookupScreenParams(lookupScreenParams);
}
LookupAction<?> lookupAction = (LookupAction<?>) pickerField.getAction(LookupAction.ID);
if (lookupAction != null) {
// Opening lookup screen in another mode will close editor
lookupAction.setOpenMode(OpenMode.DIALOG);
// In case of adding special logic for lookup screen opened from DataGrid editor
lookupAction.setScreenOptionsSupplier(() -> new MapScreenOptions(lookupScreenParams));
}
}
Aggregations