Search in sources :

Example 11 with ScreenFragment

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

the class FilterEditAction method execute.

@SuppressWarnings({ "unchecked", "rawtypes" })
@Override
public void execute() {
    if (filter.getFrame() == null) {
        throw new IllegalStateException("Filter component is not attached to the Frame");
    }
    Filter.Configuration currentConfiguration = filter.getCurrentConfiguration();
    boolean isNewConfiguration = Objects.equals(currentConfiguration.getId(), filter.getEmptyConfiguration().getId());
    LogicalFilterComponent rootComponent = currentConfiguration.getRootLogicalFilterComponent();
    Class modelClass = filterComponents.getModelClass(rootComponent.getClass());
    FilterConverter converter = filterComponents.getConverterByComponentClass(rootComponent.getClass(), filter);
    Map<String, Object> valuesMap = filterSupport.initConfigurationValuesMap(currentConfiguration);
    LogicalFilterCondition model = (LogicalFilterCondition) converter.convertToModel(rootComponent);
    Screen editScreen = createEditScreen(modelClass, model);
    applyScreenConfigurer(editScreen);
    ScreenFragment screenFragment = filterSupport.createFilterConfigurationFragment(editScreen.getWindow().getFrameOwner(), isNewConfiguration, currentConfiguration);
    Fragment fragment = screenFragment.getFragment();
    fragment.setWidthFull();
    editScreen.getWindow().add(fragment, 0);
    editScreen.getWindow().setCaption(messages.getMessage(FilterEditAction.class, "configurationEdit.caption"));
    if (editScreen instanceof GroupFilterConditionEdit) {
        Component groupConditionBox = editScreen.getWindow().getComponent("groupConditionBox");
        if (groupConditionBox instanceof Component.HasCaption) {
            ((Component.HasCaption) groupConditionBox).setCaption(messages.getMessage(FilterEditAction.class, "configurationEdit.rootGroupCondition"));
        }
    }
    editScreen.addAfterCloseListener(afterCloseEvent -> {
        if (afterCloseEvent.closedWith(StandardOutcome.COMMIT)) {
            LogicalFilterCondition filterCondition = (LogicalFilterCondition) ((FilterConditionEdit) afterCloseEvent.getSource()).getInstanceContainer().getItem();
            onEditScreenAfterCommit(screenFragment, filterCondition, converter, isNewConfiguration, currentConfiguration, valuesMap);
        } else {
            filterSupport.resetConfigurationValuesMap(currentConfiguration, valuesMap);
        }
    });
    editScreen.show();
}
Also used : Screen(io.jmix.ui.screen.Screen) LogicalFilterCondition(io.jmix.ui.entity.LogicalFilterCondition) GroupFilterConditionEdit(io.jmix.ui.app.filter.condition.GroupFilterConditionEdit) FilterConditionEdit(io.jmix.ui.app.filter.condition.FilterConditionEdit) FilterConverter(io.jmix.ui.component.filter.converter.FilterConverter) ScreenFragment(io.jmix.ui.screen.ScreenFragment) Fragment(io.jmix.ui.component.Fragment) GroupFilterConditionEdit(io.jmix.ui.app.filter.condition.GroupFilterConditionEdit) ScreenFragment(io.jmix.ui.screen.ScreenFragment) Filter(io.jmix.ui.component.Filter) LogicalFilterComponent(io.jmix.ui.component.LogicalFilterComponent) Component(io.jmix.ui.component.Component) LogicalFilterComponent(io.jmix.ui.component.LogicalFilterComponent)

Example 12 with ScreenFragment

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

the class FragmentHelper method createController.

@SuppressWarnings("unchecked")
public ScreenFragment createController(WindowInfo windowInfo, Fragment fragment) {
    Class screenClass = windowInfo.getControllerClass();
    // new screens cannot be opened in fragments
    if (!ScreenFragment.class.isAssignableFrom(screenClass)) {
        throw new IllegalStateException(String.format("Fragment controllers should inherit ScreenFragment." + " UI controller is not ScreenFragment - %s %s", windowInfo.toString(), screenClass.getSimpleName()));
    }
    ScreenFragment controller;
    try {
        controller = (ScreenFragment) invokeConstructor(screenClass);
    } catch (NoSuchMethodException | InstantiationException | IllegalAccessException | InvocationTargetException e) {
        throw new RuntimeException("Unable to create instance of screen class " + screenClass);
    }
    return controller;
}
Also used : ScreenFragment(io.jmix.ui.screen.ScreenFragment) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 13 with ScreenFragment

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

the class UiControllerPropertyInjector method findComponent.

@Nullable
protected Component findComponent(String componentId) {
    Component component = null;
    Window window = null;
    if (sourceScreen != null) {
        window = sourceScreen.getWindow();
    } else if (frameOwner instanceof ScreenFragment) {
        FrameOwner host = ((ScreenFragment) frameOwner).getHostController();
        if (host instanceof Screen) {
            window = ((Screen) host).getWindow();
        }
    } else if (frameOwner instanceof Screen) {
        window = ((Screen) frameOwner).getWindow();
    }
    if (window != null) {
        component = window.getComponent(componentId);
    }
    return component;
}
Also used : Window(io.jmix.ui.component.Window) ScreenFragment(io.jmix.ui.screen.ScreenFragment) FrameOwner(io.jmix.ui.screen.FrameOwner) Screen(io.jmix.ui.screen.Screen) Component(io.jmix.ui.component.Component) Nullable(javax.annotation.Nullable)

Aggregations

ScreenFragment (io.jmix.ui.screen.ScreenFragment)13 Component (io.jmix.ui.component.Component)5 FrameOwner (io.jmix.ui.screen.FrameOwner)5 Screen (io.jmix.ui.screen.Screen)5 Fragment (io.jmix.ui.component.Fragment)4 WindowInfo (io.jmix.ui.WindowInfo)3 Messages (io.jmix.core.Messages)2 Widget (io.jmix.dashboards.model.Widget)2 WidgetRepository (io.jmix.dashboardsui.repository.WidgetRepository)2 WidgetTypeInfo (io.jmix.dashboardsui.repository.WidgetTypeInfo)2 MapScreenOptions (io.jmix.ui.screen.MapScreenOptions)2 StringUtils (org.apache.commons.lang3.StringUtils)2 Element (org.dom4j.Element)2 Logger (org.slf4j.Logger)2 LoggerFactory (org.slf4j.LoggerFactory)2 Autowired (org.springframework.beans.factory.annotation.Autowired)2 UiComponents (com.haulmont.cuba.gui.UiComponents)1 LegacyFragmentAdapter (com.haulmont.cuba.gui.components.compatibility.LegacyFragmentAdapter)1 LegacyFrame (com.haulmont.cuba.gui.screen.compatibility.LegacyFrame)1 ScreenFragmentWrapper (com.haulmont.cuba.gui.screen.compatibility.ScreenFragmentWrapper)1