Search in sources :

Example 1 with MapScreenOptions

use of io.jmix.ui.screen.MapScreenOptions in project jmix by jmix-framework.

the class RelatedEntitiesBean method openRelatedScreen.

@Override
public void openRelatedScreen(Collection<? extends Entity> selectedEntities, MetaClass metaClass, MetaProperty metaProperty, @Nullable RelatedScreenDescriptor descriptor) {
    checkNotNullArgument(metaClass, "MetaClass can't be null");
    checkNotNullArgument(metaProperty, "MetaProperty can't be null");
    WindowManager windowManager = windowManagerProvider.get();
    if (!selectedEntities.isEmpty()) {
        Map<String, Object> params = new HashMap<>();
        WindowParams.DISABLE_AUTO_REFRESH.set(params, true);
        WindowParams.DISABLE_RESUME_SUSPENDED.set(params, true);
        if (descriptor != null && descriptor.getScreenParams() != null) {
            params.putAll(descriptor.getScreenParams());
        }
        String screenId;
        if (descriptor != null && StringUtils.isNotEmpty(descriptor.getScreenId())) {
            screenId = descriptor.getScreenId();
        } else {
            screenId = windowConfig.getBrowseScreenId(metaProperty.getRange().asClass());
        }
        if (StringUtils.isEmpty(screenId)) {
            String message = String.format("Can't show related entities: passed screenId is null and " + "there is no default browse screen for %s", metaClass.getName());
            throw new IllegalStateException(message);
        }
        WindowManager.OpenType openType = WindowManager.OpenType.THIS_TAB;
        if (descriptor != null) {
            openType = descriptor.getOpenType();
        }
        Screen screen = ((CubaScreens) windowManager).create(screenId, openType.getOpenMode(), new MapScreenOptions(params));
        boolean found = ComponentsHelper.walkComponents(screen.getWindow(), screenComponent -> {
            if (!(screenComponent instanceof Filter)) {
                return false;
            } else {
                MetaClass actualMetaClass = ((FilterImplementation) screenComponent).getEntityMetaClass();
                MetaClass relatedMetaClass = metaProperty.getRange().asClass();
                MetaClass effectiveMetaClass = extendedEntities.getEffectiveMetaClass(relatedMetaClass);
                if (Objects.equals(actualMetaClass, effectiveMetaClass)) {
                    MetaDataDescriptor metaDataDescriptor = new MetaDataDescriptor(metaClass, metaProperty);
                    applyFilter(((Filter) screenComponent), selectedEntities, descriptor, metaDataDescriptor);
                    return true;
                }
                return false;
            }
        });
        screen.show();
        if (!found) {
            windowManager.showNotification(messages.getMainMessage("actions.Related.FilterNotFound"), NotificationType.WARNING);
        }
        if (screen instanceof LegacyFrame) {
            LegacyFrame legacyFrame = (LegacyFrame) screen;
            ((DsContextImplementation) legacyFrame.getDsContext()).resumeSuspended();
        }
    } else {
        windowManager.showNotification(messages.getMainMessage("actions.Related.NotSelected"), NotificationType.HUMANIZED);
    }
}
Also used : DsContextImplementation(com.haulmont.cuba.gui.data.impl.DsContextImplementation) Screen(io.jmix.ui.screen.Screen) LegacyFrame(com.haulmont.cuba.gui.screen.compatibility.LegacyFrame) CubaScreens(com.haulmont.cuba.web.sys.CubaScreens) WindowManager(com.haulmont.cuba.gui.WindowManager) FilterImplementation(io.jmix.ui.component.FilterImplementation) MetaClass(io.jmix.core.metamodel.model.MetaClass) Filter(com.haulmont.cuba.gui.components.Filter) MapScreenOptions(io.jmix.ui.screen.MapScreenOptions)

Example 2 with MapScreenOptions

use of io.jmix.ui.screen.MapScreenOptions in project jmix by jmix-framework.

the class InspectorFormBuilder method addField.

/**
 * Adds field to the specified form.
 * If the field should be custom, adds it to the specified customFields collection
 * which can be used later to create fieldGenerators
 *
 * @param metaProperty meta property of the item's property which field is creating
 * @param form         field group to which created field will be added
 */
protected void addField(InstanceContainer container, Form form, MetaProperty metaProperty, boolean isReadonly) {
    MetaClass metaClass = container.getEntityMetaClass();
    Range range = metaProperty.getRange();
    boolean isRequired = isRequired(metaProperty);
    UiEntityAttributeContext attributeContext = new UiEntityAttributeContext(metaClass, metaProperty.getName());
    accessManager.applyRegisteredConstraints(attributeContext);
    if (!attributeContext.canView())
        return;
    if (range.isClass()) {
        UiEntityContext entityContext = new UiEntityContext(range.asClass());
        accessManager.applyRegisteredConstraints(entityContext);
        if (!entityContext.isViewPermitted()) {
            return;
        }
    }
    ValueSource valueSource = new ContainerValueSource<>(container, metaProperty.getName());
    ComponentGenerationContext componentContext = new ComponentGenerationContext(metaClass, metaProperty.getName());
    componentContext.setValueSource(valueSource);
    Field field = (Field) uiComponentsGenerator.generate(componentContext);
    if (requireTextArea(metaProperty, getItem(), MAX_TEXTFIELD_STRING_LENGTH)) {
        field = uiComponents.create(TextArea.NAME);
    }
    if (isBoolean(metaProperty)) {
        field = createBooleanField();
    }
    if (range.isClass()) {
        EntityPicker pickerField = uiComponents.create(EntityPicker.class);
        EntityLookupAction lookupAction = actions.create(EntityLookupAction.class);
        lookupAction.setScreenClass(EntityInspectorBrowser.class);
        lookupAction.setScreenOptionsSupplier(() -> new MapScreenOptions(ParamsMap.of("entity", metaProperty.getRange().asClass().getName())));
        lookupAction.setOpenMode(OpenMode.THIS_TAB);
        pickerField.addAction(lookupAction);
        pickerField.addAction(actions.create(EntityClearAction.class));
        field = pickerField;
    }
    field.setValueSource(valueSource);
    field.setCaption(getPropertyCaption(metaClass, metaProperty));
    field.setRequired(isRequired);
    isReadonly = isReadonly || (disabledProperties != null && disabledProperties.contains(metaProperty.getName()));
    if (range.isClass() && !metadataTools.isEmbedded(metaProperty)) {
        field.setEditable(metadataTools.isOwningSide(metaProperty) && !isReadonly);
    } else {
        field.setEditable(!isReadonly);
    }
    field.setWidth(fieldWidth);
    if (isRequired) {
        field.setRequiredMessage(messageTools.getDefaultRequiredMessage(metaClass, metaProperty.getName()));
    }
    form.add(field);
}
Also used : UiEntityContext(io.jmix.ui.accesscontext.UiEntityContext) UiEntityAttributeContext(io.jmix.ui.accesscontext.UiEntityAttributeContext) Range(io.jmix.core.metamodel.model.Range) ContainerValueSource(io.jmix.ui.component.data.value.ContainerValueSource) EntityClearAction(io.jmix.ui.action.entitypicker.EntityClearAction) MetaClass(io.jmix.core.metamodel.model.MetaClass) ContainerValueSource(io.jmix.ui.component.data.value.ContainerValueSource) ValueSource(io.jmix.ui.component.data.ValueSource) EntityLookupAction(io.jmix.ui.action.entitypicker.EntityLookupAction) MapScreenOptions(io.jmix.ui.screen.MapScreenOptions)

Example 3 with MapScreenOptions

use of io.jmix.ui.screen.MapScreenOptions in project jmix by jmix-framework.

the class AddToSetAction method actionPerform.

@Override
public void actionPerform(Component component) {
    MetaClass entityMetaClass;
    if (target.getItems() instanceof EntityDataUnit) {
        entityMetaClass = ((EntityDataUnit) target.getItems()).getEntityMetaClass();
    } else {
        throw new UnsupportedOperationException("Unsupported data unit " + target.getItems());
    }
    String query;
    if (filter.getDatasource() != null) {
        query = filter.getDatasource().getQuery();
    } else {
        query = filter.getDataLoader().getQuery();
    }
    String[] strings = ValuePathHelper.parse(CubaComponentsHelper.getFilterComponentPath(filter));
    String componentId = ValuePathHelper.pathSuffix(strings);
    Set ownerSelection = target.getSelected();
    Map<String, Object> params = new HashMap<>();
    params.put("entityType", entityMetaClass.getName());
    params.put("items", ownerSelection);
    params.put("componentPath", CubaComponentsHelper.getFilterComponentPath(filter));
    params.put("componentId", componentId);
    params.put("foldersPane", filterHelper.getFoldersPane());
    params.put("entityClass", entityMetaClass.getJavaClass().getName());
    params.put("query", query);
    params.put("username", userSessionSource.getUserSession().getUser().getUsername());
    Screens screens = ComponentsHelper.getScreenContext(filter).getScreens();
    screens.create("saveSetInFolder", OpenMode.DIALOG, new MapScreenOptions(params)).show();
}
Also used : Set(java.util.Set) MetaClass(io.jmix.core.metamodel.model.MetaClass) HashMap(java.util.HashMap) EntityDataUnit(io.jmix.ui.component.data.meta.EntityDataUnit) MapScreenOptions(io.jmix.ui.screen.MapScreenOptions) Screens(io.jmix.ui.Screens)

Example 4 with MapScreenOptions

use of io.jmix.ui.screen.MapScreenOptions in project jmix by jmix-framework.

the class CubaScreens method openLookup.

@Override
public com.haulmont.cuba.gui.components.Window.Lookup openLookup(WindowInfo windowInfo, com.haulmont.cuba.gui.components.Window.Lookup.Handler handler, OpenType openType) {
    Map<String, Object> params = createParametersMap(windowInfo, Collections.emptyMap());
    MapScreenOptions options = new MapScreenOptions(params);
    Screen screen = createScreen(windowInfo, openType.getOpenMode(), options);
    applyOpenTypeParameters(screen.getWindow(), openType);
    ((LookupScreen) screen).setSelectHandler(new SelectHandlerAdapter(handler));
    show(screen);
    return screen instanceof com.haulmont.cuba.gui.components.Window.Lookup ? (com.haulmont.cuba.gui.components.Window.Lookup) screen : new ScreenLookupWrapper(screen);
}
Also used : LookupScreen(io.jmix.ui.screen.LookupScreen) LookupScreen(io.jmix.ui.screen.LookupScreen) EditorScreen(io.jmix.ui.screen.EditorScreen) Screen(io.jmix.ui.screen.Screen) ScreenLookupWrapper(com.haulmont.cuba.gui.screen.compatibility.ScreenLookupWrapper) MapScreenOptions(io.jmix.ui.screen.MapScreenOptions) SelectHandlerAdapter(com.haulmont.cuba.gui.components.compatibility.SelectHandlerAdapter)

Example 5 with MapScreenOptions

use of io.jmix.ui.screen.MapScreenOptions in project jmix by jmix-framework.

the class CubaScreens method openEditor.

@Override
public com.haulmont.cuba.gui.components.Window.Editor openEditor(WindowInfo windowInfo, Entity item, OpenType openType) {
    Map<String, Object> params = createParametersMap(windowInfo, Collections.singletonMap(WindowParams.ITEM.name(), item));
    MapScreenOptions options = new MapScreenOptions(params);
    Screen screen = createScreen(windowInfo, openType.getOpenMode(), options);
    applyOpenTypeParameters(screen.getWindow(), openType);
    EditorScreen editorScreen = (EditorScreen) screen;
    editorScreen.setEntityToEdit(item);
    show(screen);
    return screen instanceof com.haulmont.cuba.gui.components.Window.Editor ? (com.haulmont.cuba.gui.components.Window.Editor) screen : new ScreenEditorWrapper(screen);
}
Also used : EditorScreen(io.jmix.ui.screen.EditorScreen) LookupScreen(io.jmix.ui.screen.LookupScreen) EditorScreen(io.jmix.ui.screen.EditorScreen) Screen(io.jmix.ui.screen.Screen) MapScreenOptions(io.jmix.ui.screen.MapScreenOptions) ScreenEditorWrapper(com.haulmont.cuba.gui.screen.compatibility.ScreenEditorWrapper)

Aggregations

MapScreenOptions (io.jmix.ui.screen.MapScreenOptions)20 Screen (io.jmix.ui.screen.Screen)11 EditorScreen (io.jmix.ui.screen.EditorScreen)9 LookupScreen (io.jmix.ui.screen.LookupScreen)8 MetaClass (io.jmix.core.metamodel.model.MetaClass)4 HashMap (java.util.HashMap)4 LegacyFrame (com.haulmont.cuba.gui.screen.compatibility.LegacyFrame)3 ScreenEditorWrapper (com.haulmont.cuba.gui.screen.compatibility.ScreenEditorWrapper)3 AbstractEditor (com.haulmont.cuba.gui.components.AbstractEditor)2 SelectHandlerAdapter (com.haulmont.cuba.gui.components.compatibility.SelectHandlerAdapter)2 ScreenLookupWrapper (com.haulmont.cuba.gui.screen.compatibility.ScreenLookupWrapper)2 ScreenWrapper (com.haulmont.cuba.gui.screen.compatibility.ScreenWrapper)2 Screens (io.jmix.ui.Screens)2 ScreenFragment (io.jmix.ui.screen.ScreenFragment)2 EntityLoadInfo (com.haulmont.cuba.core.global.EntityLoadInfo)1 WindowManager (com.haulmont.cuba.gui.WindowManager)1 OpenType (com.haulmont.cuba.gui.WindowManager.OpenType)1 Filter (com.haulmont.cuba.gui.components.Filter)1 LegacyFragmentAdapter (com.haulmont.cuba.gui.components.compatibility.LegacyFragmentAdapter)1 DsContextImplementation (com.haulmont.cuba.gui.data.impl.DsContextImplementation)1