mirror of
https://gitee.com/jmix/cuba.git
synced 2024-12-02 11:17:40 +08:00
New Screen API #575
Convenient methods: Screen.show() and ScreenFragment.init()
This commit is contained in:
parent
a95417153a
commit
069cc21dd2
@ -41,5 +41,5 @@ public interface Fragments {
|
||||
|
||||
ScreenFragment create(FrameOwner parent, WindowInfo windowInfo, ScreenOptions options);
|
||||
|
||||
void initialize(ScreenFragment fragment);
|
||||
void init(ScreenFragment fragment);
|
||||
}
|
@ -87,14 +87,16 @@ public class AbstractLookup extends AbstractWindow implements Lookup {
|
||||
|
||||
getFrame().add(lookupWindowActions.getFragment());
|
||||
|
||||
fragments.initialize(lookupWindowActions);
|
||||
lookupWindowActions.init();
|
||||
}
|
||||
|
||||
Element element = ((Component.HasXmlDescriptor) getFrame()).getXmlDescriptor();
|
||||
String lookupComponent = element.attributeValue("lookupComponent");
|
||||
if (!StringUtils.isEmpty(lookupComponent)) {
|
||||
Component component = getFrame().getComponent(lookupComponent);
|
||||
setLookupComponent(component);
|
||||
if (element != null) {
|
||||
String lookupComponent = element.attributeValue("lookupComponent");
|
||||
if (StringUtils.isNotEmpty(lookupComponent)) {
|
||||
Component component = getFrame().getComponent(lookupComponent);
|
||||
setLookupComponent(component);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -26,7 +26,6 @@ import java.util.Collection;
|
||||
* <br><br> A component must implement {@link com.haulmont.cuba.gui.components.HasPresentations} interface
|
||||
*
|
||||
* @see com.haulmont.cuba.security.entity.Presentation
|
||||
*
|
||||
*/
|
||||
public interface Presentations {
|
||||
|
||||
|
@ -27,6 +27,7 @@ import com.haulmont.cuba.gui.ComponentsHelper;
|
||||
import com.haulmont.cuba.gui.Dialogs.MessageType;
|
||||
import com.haulmont.cuba.gui.Notifications;
|
||||
import com.haulmont.cuba.gui.Notifications.NotificationType;
|
||||
import com.haulmont.cuba.gui.Screens;
|
||||
import com.haulmont.cuba.gui.components.*;
|
||||
import com.haulmont.cuba.gui.components.actions.BaseAction;
|
||||
import com.haulmont.cuba.gui.components.sys.WindowImplementation;
|
||||
@ -273,6 +274,15 @@ public abstract class Screen implements FrameOwner {
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convenient method to show the screen.
|
||||
*
|
||||
* @see Screens#show(Screen)
|
||||
*/
|
||||
public void show() {
|
||||
getScreenContext().getScreens().show(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* JavaDoc
|
||||
*
|
||||
|
@ -21,6 +21,7 @@ import com.haulmont.bali.events.Subscription;
|
||||
import com.haulmont.bali.events.TriggerOnce;
|
||||
import com.haulmont.cuba.core.global.BeanLocator;
|
||||
import com.haulmont.cuba.gui.ComponentsHelper;
|
||||
import com.haulmont.cuba.gui.Fragments;
|
||||
import com.haulmont.cuba.gui.components.Fragment;
|
||||
import com.haulmont.cuba.gui.components.sys.FragmentImplementation;
|
||||
import com.haulmont.cuba.gui.model.ScreenData;
|
||||
@ -137,6 +138,15 @@ public abstract class ScreenFragment implements FrameOwner {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Convenient method to perform programmatic initialization of the fragment.
|
||||
*
|
||||
* @see Fragments#init(ScreenFragment)
|
||||
*/
|
||||
public void init() {
|
||||
getScreenContext().getFragments().init(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* JavaDoc
|
||||
*
|
||||
|
@ -64,6 +64,7 @@ import java.util.function.Consumer;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkState;
|
||||
import static org.springframework.core.annotation.AnnotatedElementUtils.findMergedAnnotation;
|
||||
|
||||
/**
|
||||
* Wires {@link Inject}, {@link Named}, {@link WindowParam} fields/setters and {@link EventListener} methods.
|
||||
@ -119,7 +120,7 @@ public class UiControllerDependencyInjector {
|
||||
EventHub screenEvents = UiControllerUtils.getEventHub(frameOwner);
|
||||
|
||||
for (Method method : eventListenerMethods) {
|
||||
Subscribe annotation = method.getAnnotation(Subscribe.class);
|
||||
Subscribe annotation = findMergedAnnotation(method, Subscribe.class);
|
||||
checkState(annotation != null);
|
||||
|
||||
Consumer listener = new DeclarativeSubscribeExecutor(frameOwner, method);
|
||||
|
@ -20,6 +20,7 @@ import com.haulmont.cuba.core.global.BeanLocator;
|
||||
import com.haulmont.cuba.core.global.DevelopmentException;
|
||||
import com.haulmont.cuba.core.global.UserSessionSource;
|
||||
import com.haulmont.cuba.gui.Fragments;
|
||||
import com.haulmont.cuba.gui.UiComponents;
|
||||
import com.haulmont.cuba.gui.WindowParams;
|
||||
import com.haulmont.cuba.gui.components.Fragment;
|
||||
import com.haulmont.cuba.gui.components.Frame;
|
||||
@ -37,7 +38,6 @@ import com.haulmont.cuba.gui.sys.FrameContextImpl;
|
||||
import com.haulmont.cuba.gui.sys.ScreenContextImpl;
|
||||
import com.haulmont.cuba.gui.sys.ScreenDescriptorUtils;
|
||||
import com.haulmont.cuba.gui.xml.layout.ComponentLoader;
|
||||
import com.haulmont.cuba.gui.xml.layout.ComponentsFactory;
|
||||
import com.haulmont.cuba.gui.xml.layout.LayoutLoader;
|
||||
import com.haulmont.cuba.gui.xml.layout.ScreenXmlLoader;
|
||||
import com.haulmont.cuba.gui.xml.layout.loaders.ComponentLoaderContext;
|
||||
@ -66,7 +66,7 @@ public class WebFragments implements Fragments {
|
||||
@Inject
|
||||
protected BeanLocator beanLocator;
|
||||
@Inject
|
||||
protected ComponentsFactory componentsFactory;
|
||||
protected UiComponents uiComponents;
|
||||
@Inject
|
||||
protected UserSessionSource userSessionSource;
|
||||
|
||||
@ -109,7 +109,7 @@ public class WebFragments implements Fragments {
|
||||
|
||||
protected <T extends ScreenFragment> T createFragment(FrameOwner parent, WindowInfo windowInfo,
|
||||
ScreenOptions options) {
|
||||
Fragment fragment = componentsFactory.createComponent(Fragment.NAME);
|
||||
Fragment fragment = uiComponents.create(Fragment.NAME);
|
||||
ScreenFragment controller = createController(windowInfo, fragment, windowInfo.asFragment());
|
||||
|
||||
// setup screen and controller
|
||||
@ -157,8 +157,6 @@ public class WebFragments implements Fragments {
|
||||
layoutLoader.setLocale(getLocale());
|
||||
layoutLoader.setMessagesPack(getMessagePack(windowInfo.getTemplate()));
|
||||
|
||||
ScreenXmlLoader screenXmlLoader = beanLocator.get(ScreenXmlLoader.NAME);
|
||||
|
||||
Element windowElement = screenXmlLoader.load(windowInfo.getTemplate(), windowInfo.getId(),
|
||||
innerContext.getParams());
|
||||
|
||||
@ -181,7 +179,7 @@ public class WebFragments implements Fragments {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initialize(ScreenFragment controller) {
|
||||
public void init(ScreenFragment controller) {
|
||||
checkNotNullArgument(controller);
|
||||
|
||||
FragmentContextImpl fragmentContext = (FragmentContextImpl) controller.getFragment().getContext();
|
||||
|
@ -57,7 +57,6 @@ import com.haulmont.cuba.gui.sys.*;
|
||||
import com.haulmont.cuba.gui.util.OperationResult;
|
||||
import com.haulmont.cuba.gui.xml.data.DsContextLoader;
|
||||
import com.haulmont.cuba.gui.xml.layout.ComponentLoader;
|
||||
import com.haulmont.cuba.gui.xml.layout.ComponentsFactory;
|
||||
import com.haulmont.cuba.gui.xml.layout.LayoutLoader;
|
||||
import com.haulmont.cuba.gui.xml.layout.ScreenXmlLoader;
|
||||
import com.haulmont.cuba.gui.xml.layout.loaders.ComponentLoaderContext;
|
||||
@ -106,7 +105,7 @@ public class WebScreens implements Screens, WindowManager {
|
||||
@Inject
|
||||
protected UuidSource uuidSource;
|
||||
@Inject
|
||||
protected ComponentsFactory componentsFactory;
|
||||
protected UiComponents uiComponents;
|
||||
@Inject
|
||||
protected ScreenXmlLoader screenXmlLoader;
|
||||
@Inject
|
||||
@ -703,7 +702,7 @@ public class WebScreens implements Screens, WindowManager {
|
||||
container.add(screenFragment.getFragment());
|
||||
}
|
||||
|
||||
fragments.initialize(screenFragment);
|
||||
fragments.init(screenFragment);
|
||||
|
||||
return screenFragment instanceof Frame ? (Frame) screenFragment : new ScreenFragmentWrapper(screenFragment);
|
||||
}
|
||||
@ -931,16 +930,16 @@ public class WebScreens implements Screens, WindowManager {
|
||||
// should be changed
|
||||
ui.beforeTopLevelWindowInit();
|
||||
|
||||
window = componentsFactory.createComponent(RootWindow.NAME);
|
||||
window = uiComponents.create(RootWindow.NAME);
|
||||
break;
|
||||
|
||||
case THIS_TAB:
|
||||
case NEW_TAB:
|
||||
window = componentsFactory.createComponent(TabWindow.NAME);
|
||||
window = uiComponents.create(TabWindow.NAME);
|
||||
break;
|
||||
|
||||
case DIALOG:
|
||||
window = componentsFactory.createComponent(DialogWindow.NAME);
|
||||
window = uiComponents.create(DialogWindow.NAME);
|
||||
break;
|
||||
|
||||
default:
|
||||
|
Loading…
Reference in New Issue
Block a user