New Screen API #575

Convenient methods: Screen.show() and ScreenFragment.init()
This commit is contained in:
Yuriy Artamonov 2018-09-17 17:28:43 +04:00
parent a95417153a
commit 069cc21dd2
8 changed files with 39 additions and 20 deletions

View File

@ -41,5 +41,5 @@ public interface Fragments {
ScreenFragment create(FrameOwner parent, WindowInfo windowInfo, ScreenOptions options);
void initialize(ScreenFragment fragment);
void init(ScreenFragment fragment);
}

View File

@ -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);
}
}
}

View File

@ -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 {

View File

@ -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
*

View File

@ -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
*

View File

@ -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);

View File

@ -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();

View File

@ -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: