Search in sources :

Example 1 with LookupAction

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);
    }
}
Also used : LookupAction(com.haulmont.cuba.gui.actions.picker.LookupAction) LookupAction(com.haulmont.cuba.gui.actions.picker.LookupAction) Action(com.haulmont.cuba.gui.components.Action) MetaClass(com.haulmont.chile.core.model.MetaClass) PickerField(com.haulmont.cuba.gui.components.PickerField) MetaClass(com.haulmont.chile.core.model.MetaClass)

Example 2 with LookupAction

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;
    }
}
Also used : ContainerOptions(com.haulmont.cuba.gui.components.data.options.ContainerOptions) LookupAction(com.haulmont.cuba.gui.actions.picker.LookupAction) ClearAction(com.haulmont.cuba.gui.actions.picker.ClearAction) InputDialogAction(com.haulmont.cuba.gui.components.inputdialog.InputDialogAction) CollectionLoader(com.haulmont.cuba.gui.model.CollectionLoader) MetaClass(com.haulmont.chile.core.model.MetaClass) CollectionContainer(com.haulmont.cuba.gui.model.CollectionContainer)

Example 3 with LookupAction

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));
    }
}
Also used : LookupAction(com.haulmont.cuba.gui.actions.picker.LookupAction) MapScreenOptions(com.haulmont.cuba.gui.screen.MapScreenOptions)

Aggregations

LookupAction (com.haulmont.cuba.gui.actions.picker.LookupAction)3 MetaClass (com.haulmont.chile.core.model.MetaClass)2 ClearAction (com.haulmont.cuba.gui.actions.picker.ClearAction)1 Action (com.haulmont.cuba.gui.components.Action)1 PickerField (com.haulmont.cuba.gui.components.PickerField)1 ContainerOptions (com.haulmont.cuba.gui.components.data.options.ContainerOptions)1 InputDialogAction (com.haulmont.cuba.gui.components.inputdialog.InputDialogAction)1 CollectionContainer (com.haulmont.cuba.gui.model.CollectionContainer)1 CollectionLoader (com.haulmont.cuba.gui.model.CollectionLoader)1 MapScreenOptions (com.haulmont.cuba.gui.screen.MapScreenOptions)1