use of com.haulmont.cuba.gui.screen.compatibility.LegacyFrame in project cuba by cuba-platform.
the class FragmentLoader method loadDsContext.
protected void loadDsContext(@Nullable Element dsContextElement) {
DsContext dsContext = null;
if (resultComponent.getFrameOwner() instanceof LegacyFrame) {
DsContextLoader dsContextLoader;
DsContext parentDsContext = getComponentContext().getParent().getDsContext();
if (parentDsContext != null) {
dsContextLoader = new DsContextLoader(parentDsContext.getDataSupplier());
} else {
dsContextLoader = new DsContextLoader(new GenericDataSupplier());
}
dsContext = dsContextLoader.loadDatasources(dsContextElement, parentDsContext, getComponentContext().getAliasesMap());
((ComponentLoaderContext) context).setDsContext(dsContext);
}
if (dsContext != null) {
FrameOwner frameOwner = getComponentContext().getFrame().getFrameOwner();
if (frameOwner instanceof LegacyFrame) {
LegacyFrame frame = (LegacyFrame) frameOwner;
frame.setDsContext(dsContext);
for (Datasource ds : dsContext.getAll()) {
if (ds instanceof DatasourceImplementation) {
((DatasourceImplementation) ds).initialized();
}
}
dsContext.setFrameContext(resultComponent.getContext());
}
}
}
use of com.haulmont.cuba.gui.screen.compatibility.LegacyFrame in project cuba by cuba-platform.
the class WebEntityLinkField method openEntityEditor.
protected void openEntityEditor() {
V value = getValue();
Entity entity = null;
if (value instanceof Entity) {
entity = (Entity) value;
} else if (getValueSource() instanceof EntityValueSource) {
entity = ((EntityValueSource) getValueSource()).getItem();
}
if (entity == null) {
return;
}
Window window = ComponentsHelper.getWindow(this);
if (window == null) {
throw new IllegalStateException("Please specify Frame for EntityLinkField");
}
ScreenContext context = ComponentsHelper.getScreenContext(this);
if (entity instanceof SoftDelete && ((SoftDelete) entity).isDeleted()) {
Messages messages = AppBeans.get(Messages.NAME);
context.getNotifications().create(Notifications.NotificationType.HUMANIZED).withCaption(messages.getMainMessage("OpenAction.objectIsDeleted")).show();
return;
}
if (window.getFrameOwner() instanceof LegacyFrame) {
LegacyFrame frameOwner = (LegacyFrame) window.getFrameOwner();
DataSupplier dataSupplier = frameOwner.getDsContext().getDataSupplier();
entity = dataSupplier.reload(entity, View.MINIMAL);
} else {
DataManager dataManager = beanLocator.get(DataManager.NAME);
entity = dataManager.reload(entity, View.MINIMAL);
}
String windowAlias = screen;
WindowConfig windowConfig = AppBeans.get(WindowConfig.NAME);
if (windowAlias == null) {
windowAlias = windowConfig.getEditorScreenId(entity.getMetaClass());
}
Screen screenEditor = screenBuilders.editor(entity.getMetaClass().getJavaClass(), window.getFrameOwner()).withScreenId(windowAlias).editEntity(entity).withOpenMode(screenOpenMode).withOptions(new MapScreenOptions(screenParams != null ? screenParams : new HashMap<>())).build();
screenEditor.addAfterCloseListener(event -> {
// move focus to component
component.focus();
String closeActionId = null;
CloseAction closeAction = event.getCloseAction();
if (closeAction instanceof StandardCloseAction) {
closeActionId = ((StandardCloseAction) closeAction).getActionId();
}
Screen screenSource = null;
if (StringUtils.isNotEmpty(closeActionId) && Window.COMMIT_ACTION_ID.equals(closeActionId)) {
Entity item = null;
screenSource = event.getSource();
if (screenSource instanceof EditorScreen) {
item = ((EditorScreen) screenSource).getEditedEntity();
}
if (item != null) {
afterCommitOpenedEntity(item);
}
}
fireEditorCloseEvent(screenSource == null ? null : (EditorScreen) screenSource, closeActionId);
});
screenEditor.show();
}
use of com.haulmont.cuba.gui.screen.compatibility.LegacyFrame in project cuba by cuba-platform.
the class WebAccordion method initComponentTabChangeListener.
protected void initComponentTabChangeListener() {
// after all lazy tabs listeners
if (!componentTabChangeListenerInitialized) {
component.addSelectedTabChangeListener(event -> {
if (context instanceof ComponentLoader.ComponentContext) {
((ComponentLoader.ComponentContext) context).executeInjectTasks();
((ComponentLoader.ComponentContext) context).executeInitTasks();
}
// Fire GUI listener
fireTabChanged();
// We suppose that context.executePostInitTasks() executes a task once and then remove it from task list.
if (context instanceof ComponentLoader.ComponentContext) {
((ComponentLoader.ComponentContext) context).executePostInitTasks();
}
Window window = ComponentsHelper.getWindow(WebAccordion.this);
if (window != null) {
if (window.getFrameOwner() instanceof LegacyFrame) {
DsContext dsContext = ((LegacyFrame) window.getFrameOwner()).getDsContext();
if (dsContext != null) {
((DsContextImplementation) dsContext).resumeSuspended();
}
}
} else {
LoggerFactory.getLogger(WebAccordion.class).warn("Please specify Frame for Accordion");
}
});
componentTabChangeListenerInitialized = true;
}
}
use of com.haulmont.cuba.gui.screen.compatibility.LegacyFrame in project cuba by cuba-platform.
the class HasWindowManager method openFrame.
/**
* Load a frame registered in {@code screens.xml} and optionally show it inside a parent component of this
* frame. <br> It is recommended to use {@link Fragments} bean instead.
*
* @param parent if specified, all parent's sub components will be removed and the frame will be added
* @param windowAlias frame ID as defined in {@code screens.xml}
* @return frame's controller instance
*/
@Deprecated
default Frame openFrame(@Nullable Component parent, String windowAlias) {
WindowConfig windowConfig = AppBeans.get(WindowConfig.NAME);
WindowInfo windowInfo = windowConfig.getWindowInfo(windowAlias);
Frame parentFrame;
if (this instanceof LegacyFrame) {
parentFrame = ((LegacyFrame) this).getWrappedFrame();
} else {
parentFrame = ((Frame) this);
}
return getWindowManager().openFrame(parentFrame, parent, windowInfo);
}
use of com.haulmont.cuba.gui.screen.compatibility.LegacyFrame in project cuba by cuba-platform.
the class RelatedEntitiesBean method openRelatedScreen.
@Override
public void openRelatedScreen(Collection<? extends Entity> selectedEntities, MetaClass metaClass, MetaProperty metaProperty, 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 = 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"), Frame.NotificationType.WARNING);
}
if (screen instanceof LegacyFrame) {
LegacyFrame legacyFrame = (LegacyFrame) screen;
((DsContextImplementation) legacyFrame.getDsContext()).resumeSuspended();
}
} else {
windowManager.showNotification(messages.getMainMessage("actions.Related.NotSelected"), Frame.NotificationType.HUMANIZED);
}
}
Aggregations