use of com.haulmont.cuba.gui.components.Window in project cuba by cuba-platform.
the class WebWindowManager method createTopLevelWindow.
public void createTopLevelWindow(WindowInfo windowInfo) {
ui.beforeTopLevelWindowInit();
String template = windowInfo.getTemplate();
Window.TopLevelWindow topLevelWindow;
Map<String, Object> params = Collections.emptyMap();
if (template != null) {
// noinspection unchecked
topLevelWindow = (Window.TopLevelWindow) createWindow(windowInfo, OpenType.NEW_TAB, params, LayoutLoaderConfig.getWindowLoaders(), true);
} else {
Class screenClass = windowInfo.getScreenClass();
if (screenClass != null) {
// noinspection unchecked
topLevelWindow = (Window.TopLevelWindow) createWindowByScreenClass(windowInfo, params);
} else {
throw new DevelopmentException("Unable to load top level window");
}
}
// detect work area
Window windowImpl = ((Window.Wrapper) topLevelWindow).getWrappedWindow();
if (topLevelWindow instanceof AbstractMainWindow) {
AbstractMainWindow mainWindow = (AbstractMainWindow) topLevelWindow;
// bind system UI components to AbstractMainWindow
ComponentsHelper.walkComponents(windowImpl, component -> {
if (component instanceof AppWorkArea) {
mainWindow.setWorkArea((AppWorkArea) component);
} else if (component instanceof UserIndicator) {
mainWindow.setUserIndicator((UserIndicator) component);
} else if (component instanceof FoldersPane) {
mainWindow.setFoldersPane((FoldersPane) component);
}
return false;
});
}
ui.setTopLevelWindow(topLevelWindow);
// load menu
ComponentsHelper.walkComponents(windowImpl, component -> {
if (component instanceof TopLevelWindowAttachListener) {
((TopLevelWindowAttachListener) component).topLevelWindowAttached(topLevelWindow);
}
return false;
});
if (topLevelWindow instanceof Window.HasWorkArea) {
AppWorkArea workArea = ((Window.HasWorkArea) topLevelWindow).getWorkArea();
if (workArea != null) {
workArea.addStateChangeListener(new AppWorkArea.StateChangeListener() {
@Override
public void stateChanged(AppWorkArea.State newState) {
if (newState == AppWorkArea.State.WINDOW_CONTAINER) {
initTabShortcuts();
// listener used only once
getConfiguredWorkArea(createWorkAreaContext(topLevelWindow)).removeStateChangeListener(this);
}
}
});
}
}
afterShowWindow(topLevelWindow);
}
use of com.haulmont.cuba.gui.components.Window in project cuba by cuba-platform.
the class WebWindowManager method showWindowThisTab.
protected Component showWindowThisTab(final Window window, final String caption, final String description) {
getDialogParams().reset();
WebAppWorkArea workArea = getConfiguredWorkArea(createWorkAreaContext(window));
Layout layout;
if (workArea.getMode() == Mode.TABBED) {
TabSheetBehaviour tabSheet = workArea.getTabbedWindowContainer().getTabSheetBehaviour();
layout = (Layout) tabSheet.getSelectedTab();
} else {
layout = (Layout) workArea.getSingleWindowContainer().getComponent(0);
}
final WindowBreadCrumbs breadCrumbs = tabs.get(layout);
if (breadCrumbs == null) {
throw new IllegalStateException("BreadCrumbs not found");
}
final Window currentWindow = breadCrumbs.getCurrentWindow();
Set<Map.Entry<Window, Integer>> set = windows.entrySet();
boolean pushed = false;
for (Map.Entry<Window, Integer> entry : set) {
if (entry.getKey().equals(currentWindow)) {
windows.remove(currentWindow);
getStack(breadCrumbs).push(new Pair<>(entry.getKey(), entry.getValue()));
pushed = true;
break;
}
}
if (!pushed) {
getStack(breadCrumbs).push(new Pair<>(currentWindow, null));
}
removeFromWindowMap(currentWindow);
layout.removeComponent(WebComponentsHelper.getComposition(currentWindow));
final Component component = WebComponentsHelper.getComposition(window);
component.setSizeFull();
layout.addComponent(component);
breadCrumbs.addWindow(window);
if (workArea.getMode() == Mode.TABBED) {
TabSheetBehaviour tabSheet = workArea.getTabbedWindowContainer().getTabSheetBehaviour();
String tabId = tabSheet.getTab(layout);
String formattedCaption = formatTabCaption(caption, description);
tabSheet.setTabCaption(tabId, formattedCaption);
String formattedDescription = formatTabDescription(caption, description);
if (!Objects.equals(formattedCaption, formattedDescription)) {
tabSheet.setTabDescription(tabId, formattedDescription);
} else {
tabSheet.setTabDescription(tabId, null);
}
tabSheet.setTabIcon(tabId, iconResolver.getIconResource(window.getIcon()));
ContentSwitchMode contentSwitchMode = ContentSwitchMode.valueOf(window.getContentSwitchMode().name());
tabSheet.setContentSwitchMode(tabId, contentSwitchMode);
} else {
layout.markAsDirtyRecursive();
}
return layout;
}
use of com.haulmont.cuba.gui.components.Window in project cuba by cuba-platform.
the class TaskHandlerImpl method detachCloseListener.
private void detachCloseListener() {
// force remove close listener
Frame ownerFrame = getTask().getOwnerFrame();
if (ownerFrame != null) {
Window ownerWindow = ComponentsHelper.getWindowImplementation(ownerFrame);
if (ownerWindow != null) {
ownerWindow.removeCloseListener(closeListener);
String windowClass = ownerFrame.getClass().getCanonicalName();
log.trace("Resources were disposed. Task: {}. Frame: {}", taskExecutor.getTask(), windowClass);
} else {
log.trace("Empty ownerWindow. Resources were not disposed. Task: {}", taskExecutor.getTask());
}
} else {
log.trace("Empty ownerFrame. Resources were not disposed. Task: {}", taskExecutor.getTask());
}
closeListener = null;
}
use of com.haulmont.cuba.gui.components.Window 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) {
Preconditions.checkNotNullArgument(metaClass, "MetaClass can't be null");
Preconditions.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 screen;
if (descriptor != null && StringUtils.isNotEmpty(descriptor.getScreenId())) {
screen = descriptor.getScreenId();
} else {
screen = windowConfig.getBrowseScreenId(metaProperty.getRange().asClass());
}
if (StringUtils.isEmpty(screen)) {
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();
}
Window window = windowManager.openWindow(windowConfig.getWindowInfo(screen), openType, params);
boolean found = ComponentsHelper.walkComponents(window, screenComponent -> {
if (!(screenComponent instanceof Filter)) {
return false;
} else {
MetaClass actualMetaClass = ((Filter) screenComponent).getDatasource().getMetaClass();
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;
}
});
if (!found) {
windowManager.showNotification(messages.getMainMessage("actions.Related.FilterNotFound"), Frame.NotificationType.WARNING);
}
((DsContextImplementation) window.getDsContext()).resumeSuspended();
} else {
windowManager.showNotification(messages.getMainMessage("actions.Related.NotSelected"), Frame.NotificationType.HUMANIZED);
}
}
use of com.haulmont.cuba.gui.components.Window in project cuba by cuba-platform.
the class WebDataGrid method handleDoubleClickAction.
protected void handleDoubleClickAction() {
Action action = getItemClickAction();
if (action == null) {
action = getEnterAction();
if (action == null) {
action = getAction("edit");
if (action == null) {
action = getAction("view");
}
}
}
if (action != null && action.isEnabled()) {
Window window = ComponentsHelper.getWindowImplementation(WebDataGrid.this);
if (window instanceof Window.Wrapper) {
window = ((Window.Wrapper) window).getWrappedWindow();
}
if (!(window instanceof Window.Lookup)) {
action.actionPerform(WebDataGrid.this);
} else {
Window.Lookup lookup = (Window.Lookup) window;
com.haulmont.cuba.gui.components.Component lookupComponent = lookup.getLookupComponent();
if (lookupComponent != this)
action.actionPerform(WebDataGrid.this);
else if (action.getId().equals(WindowDelegate.LOOKUP_ITEM_CLICK_ACTION_ID)) {
action.actionPerform(WebDataGrid.this);
}
}
}
}
Aggregations