use of com.haulmont.cuba.gui.components.sys.FrameImplementation in project cuba by cuba-platform.
the class WebAbstractComponent method setId.
@Override
public void setId(String id) {
if (!Objects.equals(this.id, id)) {
if (frame != null) {
((FrameImplementation) frame).unregisterComponent(this);
}
this.id = id;
AppUI ui = AppUI.getCurrent();
if (ui != null) {
if (this.component != null && ui.isTestMode()) {
this.component.setCubaId(id);
}
}
assignDebugId();
if (frame != null) {
((FrameImplementation) frame).registerComponent(this);
}
}
}
use of com.haulmont.cuba.gui.components.sys.FrameImplementation in project cuba by cuba-platform.
the class CompositeComponent method setId.
@Override
public void setId(String id) {
if (!Objects.equals(this.id, id)) {
if (frame != null) {
((FrameImplementation) frame).unregisterComponent(this);
}
this.id = id;
AppUI ui = AppUI.getCurrent();
if (ui != null) {
if (root != null && ui.isTestMode()) {
com.vaadin.ui.Component vComponent = root.unwrap(com.vaadin.ui.Component.class);
if (vComponent != null) {
vComponent.setCubaId(id);
}
}
}
assignDebugId();
if (frame != null) {
((FrameImplementation) frame).registerComponent(this);
}
}
}
use of com.haulmont.cuba.gui.components.sys.FrameImplementation in project cuba by cuba-platform.
the class FragmentComponentLoader method createComponent.
@Override
public void createComponent() {
String src = element.attributeValue("src");
String screenId = element.attributeValue("screen");
if (src == null && screenId == null) {
throw new GuiDevelopmentException("Either 'src' or 'screen' must be specified for 'frame'", context, "fragment", element.attributeValue("id"));
}
String fragmentId;
if (element.attributeValue("id") != null) {
fragmentId = element.attributeValue("id");
} else if (screenId != null) {
fragmentId = screenId;
} else {
fragmentId = src;
}
FragmentHelper fragmentHelper = getFragmentHelper();
WindowInfo windowInfo;
if (src == null) {
// load screen class only once
windowInfo = getWindowConfig().getWindowInfo(screenId).resolve();
} else {
windowInfo = fragmentHelper.createFakeWindowInfo(src, fragmentId);
}
StopWatch createStopWatch = createStopWatch(ScreenLifeCycle.CREATE, windowInfo.getId());
Fragment fragment = factory.create(Fragment.NAME);
ScreenFragment controller = fragmentHelper.createController(windowInfo, fragment);
// setup screen and controller
ComponentLoaderContext parentContext = (ComponentLoaderContext) getContext();
FrameOwner hostController = parentContext.getFrame().getFrameOwner();
setHostController(controller, hostController);
setWindowId(controller, windowInfo.getId());
setFrame(controller, fragment);
setScreenContext(controller, new ScreenContextImpl(windowInfo, parentContext.getOptions(), getScreenContext(hostController)));
setScreenData(controller, new ScreenDataImpl());
FragmentImplementation fragmentImpl = (FragmentImplementation) fragment;
fragmentImpl.setFrameOwner(controller);
fragmentImpl.setId(fragmentId);
FragmentContextImpl frameContext = new FragmentContextImpl(fragment, innerContext);
((FrameImplementation) fragment).setContext(frameContext);
if (windowInfo.getTemplate() != null) {
String frameId = fragmentId;
if (parentContext.getFullFrameId() != null) {
frameId = parentContext.getFullFrameId() + "." + frameId;
}
innerContext = new ComponentLoaderContext(getComponentContext().getOptions());
innerContext.setMessagesPack(fragmentHelper.getMessagePack(windowInfo.getTemplate()));
innerContext.setCurrentFrameId(fragmentId);
innerContext.setFullFrameId(frameId);
innerContext.setFrame(fragment);
innerContext.setParent(parentContext);
innerContext.setProperties(loadProperties(element));
LayoutLoader layoutLoader = getLayoutLoader(innerContext);
ScreenXmlLoader screenXmlLoader = beanLocator.get(ScreenXmlLoader.NAME);
Element rootElement = screenXmlLoader.load(windowInfo.getTemplate(), windowInfo.getId(), getComponentContext().getParams());
String messagesPack = rootElement.attributeValue("messagesPack");
if (messagesPack != null) {
innerContext.setMessagesPack(messagesPack);
}
this.fragmentLoader = layoutLoader.createFragmentContent(fragment, rootElement);
}
createStopWatch.stop();
this.resultComponent = fragment;
}
use of com.haulmont.cuba.gui.components.sys.FrameImplementation in project cuba by cuba-platform.
the class WebFragments method createFragment.
protected <T extends ScreenFragment> T createFragment(FrameOwner parent, WindowInfo windowInfo, ScreenOptions options) {
if (windowInfo.getType() != WindowInfo.Type.FRAGMENT && !AbstractWindow.class.isAssignableFrom(windowInfo.getControllerClass())) {
throw new IllegalArgumentException(String.format("Unable to create fragment %s it is a screen: %s", windowInfo.getId(), windowInfo.getControllerClass()));
}
StopWatch createStopWatch = createStopWatch(ScreenLifeCycle.CREATE, windowInfo.getId());
Fragment fragment = uiComponents.create(Fragment.NAME);
ScreenFragment controller = fragmentHelper.createController(windowInfo, fragment);
// setup screen and controller
setHostController(controller, parent);
setWindowId(controller, windowInfo.getId());
setFrame(controller, fragment);
setScreenContext(controller, new ScreenContextImpl(windowInfo, options, getScreenContext(parent)));
setScreenData(controller, new ScreenDataImpl());
FragmentImplementation fragmentImpl = (FragmentImplementation) fragment;
fragmentImpl.setFrameOwner(controller);
fragmentImpl.setId(controller.getId());
createStopWatch.stop();
StopWatch loadStopWatch = createStopWatch(ScreenLifeCycle.LOAD, windowInfo.getId());
Frame parentFrame = getFrame(parent);
// fake parent loader context
ComponentLoaderContext loaderContext = new ComponentLoaderContext(options);
FragmentContextImpl frameContext = new FragmentContextImpl(fragment, loaderContext);
frameContext.setManualInitRequired(true);
((FrameImplementation) fragment).setContext(frameContext);
loaderContext.setCurrentFrameId(windowInfo.getId());
loaderContext.setFullFrameId(windowInfo.getId());
loaderContext.setFrame(fragment);
loaderContext.setParent(null);
loaderContext.setScreenData(UiControllerUtils.getScreenData(parent));
if (parent instanceof LegacyFrame) {
loaderContext.setDsContext(((LegacyFrame) parent).getDsContext());
}
// load XML if needed
if (windowInfo.getTemplate() != null) {
ComponentLoaderContext innerContext = new ComponentLoaderContext(options);
innerContext.setMessagesPack(fragmentHelper.getMessagePack(windowInfo.getTemplate()));
innerContext.setCurrentFrameId(windowInfo.getId());
innerContext.setFullFrameId(windowInfo.getId());
innerContext.setFrame(fragment);
innerContext.setParent(loaderContext);
LayoutLoader layoutLoader = beanLocator.getPrototype(LayoutLoader.NAME, innerContext);
Element rootElement = screenXmlLoader.load(windowInfo.getTemplate(), windowInfo.getId(), innerContext.getParams());
String messagesPack = rootElement.attributeValue("messagesPack");
if (messagesPack != null) {
innerContext.setMessagesPack(messagesPack);
}
ComponentLoader<Fragment> fragmentLoader = layoutLoader.createFragmentContent(fragment, rootElement);
fragmentLoader.loadComponent();
loaderContext.getInjectTasks().addAll(innerContext.getInjectTasks());
loaderContext.getInitTasks().addAll(innerContext.getInitTasks());
loaderContext.getPostInitTasks().addAll(innerContext.getPostInitTasks());
}
loaderContext.addInjectTask(new FragmentLoaderInjectTask(fragment, options, beanLocator));
loaderContext.addInitTask(new FragmentLoaderInitTask(fragment, options, loaderContext, beanLocator));
loadStopWatch.stop();
loaderContext.executeInjectTasks();
fragmentImpl.setFrame(parentFrame);
// noinspection unchecked
return (T) controller;
}
use of com.haulmont.cuba.gui.components.sys.FrameImplementation in project cuba by cuba-platform.
the class WebScrollBoxLayout method add.
@Override
public void add(Component childComponent, int index) {
if (childComponent.getParent() != null && childComponent.getParent() != this) {
throw new IllegalStateException("Component already has parent");
}
AbstractOrderedLayout newContent = null;
if (orientation == Orientation.VERTICAL && !(getContent() instanceof CubaVerticalActionsLayout)) {
newContent = new CubaVerticalActionsLayout();
newContent.setWidth(100, Sizeable.Unit.PERCENTAGE);
} else if (orientation == Orientation.HORIZONTAL && !(getContent() instanceof CubaHorizontalActionsLayout)) {
newContent = new CubaHorizontalActionsLayout();
}
if (newContent != null) {
newContent.setMargin((getContent()).getMargin());
newContent.setSpacing((getContent()).isSpacing());
newContent.setStyleName(SCROLLBOX_CONTENT_STYLENAME);
com.vaadin.ui.Component oldContent = component.getComponent(0);
newContent.setWidth(oldContent.getWidth(), oldContent.getWidthUnits());
newContent.setHeight(oldContent.getHeight(), oldContent.getHeightUnits());
component.removeAllComponents();
component.addComponent(newContent);
applyScrollBarsPolicy(scrollBarPolicy);
}
if (ownComponents.contains(childComponent)) {
int existingIndex = getContent().getComponentIndex(WebComponentsHelper.getComposition(childComponent));
if (index > existingIndex) {
index--;
}
remove(childComponent);
}
com.vaadin.ui.Component vComponent = WebComponentsHelper.getComposition(childComponent);
getContent().addComponent(vComponent, index);
getContent().setComponentAlignment(vComponent, WebWrapperUtils.toVaadinAlignment(childComponent.getAlignment()));
if (frame != null) {
if (childComponent instanceof BelongToFrame && ((BelongToFrame) childComponent).getFrame() == null) {
((BelongToFrame) childComponent).setFrame(frame);
} else {
((FrameImplementation) frame).registerComponent(childComponent);
}
}
if (index == ownComponents.size()) {
ownComponents.add(childComponent);
} else {
ownComponents.add(index, childComponent);
}
childComponent.setParent(this);
}
Aggregations