use of com.haulmont.cuba.gui.components.Window in project cuba by cuba-platform.
the class WindowCreationHelper method applyUiPermissions.
/**
* Apply UI permissions to a frame.
*
* @param container frame
*/
public static void applyUiPermissions(Frame container) {
Window window = container instanceof Window ? (Window) container : ComponentsHelper.getWindow(container);
if (window == null) {
log.warn(String.format("Unable to find window for container %s with id '%s'", container.getClass(), container.getId()));
return;
}
UserSessionSource sessionSource = AppBeans.get(UserSessionSource.NAME);
UserSession userSession = sessionSource.getUserSession();
String screenId = window.getId();
Map<String, Integer> uiPermissions = userSession.getPermissionsByType(PermissionType.UI);
for (Map.Entry<String, Integer> permissionEntry : uiPermissions.entrySet()) {
String target = permissionEntry.getKey();
String targetComponentId = getTargetComponentId(target, screenId);
if (targetComponentId != null) {
if (targetComponentId.contains("[")) {
applyCompositeComponentPermission(window, screenId, permissionEntry.getValue(), targetComponentId);
} else if (targetComponentId.contains(">")) {
applyComponentActionPermission(window, screenId, permissionEntry.getValue(), targetComponentId);
} else {
applyComponentPermission(window, screenId, permissionEntry.getValue(), targetComponentId);
}
}
}
}
use of com.haulmont.cuba.gui.components.Window in project cuba by cuba-platform.
the class DesktopWindowManager method attachTab.
public void attachTab(WindowBreadCrumbs breadCrumbs, Stack<Map.Entry<Window, Integer>> stack, Window window, Integer hashCode, final JComponent tabContent, Map<Window, WindowOpenInfo> openInfos) {
frame.add(tabContent);
frame.addWindowListener(new ValidationAwareWindowClosingListener() {
@Override
public void windowClosingAfterValidation(WindowEvent e) {
closeTab(tabContent);
}
});
tabs.put(tabContent, breadCrumbs);
windowOpenMode.putAll(openInfos);
stacks.put(breadCrumbs, stack);
for (Map.Entry<Window, Integer> entry : stack) {
entry.getKey().setWindowManager(this);
}
window.setWindowManager(this);
if (hashCode != null) {
windows.put(window, hashCode);
}
JPopupMenu popupMenu = createWindowPopupMenu(window);
if (popupMenu.getComponentCount() > 0) {
frame.getRootPane().setComponentPopupMenu(popupMenu);
}
}
use of com.haulmont.cuba.gui.components.Window in project cuba by cuba-platform.
the class DesktopWindowManager method detachTab.
protected void detachTab(int tabIndex) {
// Create new top-level frame, put this tab to it with breadcrumbs.
// remove tab data from this window manager
JComponent tabContent = (JComponent) tabsPane.getComponentAt(tabIndex);
WindowBreadCrumbs breadCrumbs = tabs.get(tabContent);
Window window = breadCrumbs.getCurrentWindow();
if (window == null) {
throw new IllegalArgumentException("window is null");
}
// WindowOpenMode map
Map<Window, WindowOpenInfo> detachOpenModes = new HashMap<>();
detachOpenModes.put((Window) window.getFrame(), windowOpenMode.get(window.<Window>getFrame()));
windowOpenMode.remove(window.<Window>getFrame());
Stack<Map.Entry<Window, Integer>> stack = stacks.get(breadCrumbs);
for (Map.Entry<Window, Integer> entry : stack) {
WindowOpenInfo openInfo = windowOpenMode.get(entry.getKey().<Window>getFrame());
detachOpenModes.put((Window) entry.getKey().getFrame(), openInfo);
windowOpenMode.remove(entry.getKey().<Window>getFrame());
}
tabs.remove(tabContent);
Integer hashCode = windows.remove(window);
tabsPane.remove(tabIndex);
stacks.remove(breadCrumbs);
final TopLevelFrame windowFrame = createTopLevelFrame(window.getCaption());
App.getInstance().registerFrame(windowFrame);
windowFrame.setVisible(true);
windowFrame.getWindowManager().attachTab(breadCrumbs, stack, window, hashCode, tabContent, detachOpenModes);
}
use of com.haulmont.cuba.gui.components.Window in project cuba by cuba-platform.
the class DesktopWindowManager method setWindowCaption.
@Override
public void setWindowCaption(Window window, String caption, String description) {
Window desktopWindow = window;
if (window instanceof Window.Wrapper) {
desktopWindow = ((Window.Wrapper) window).getWrappedWindow();
}
window.setCaption(caption);
String formattedCaption = formatTabDescription(caption, description);
WindowOpenInfo openInfo = windowOpenMode.get(desktopWindow);
if (openInfo != null) {
OpenMode openMode = openInfo.getOpenMode();
if (openMode != OpenMode.DIALOG) {
if (tabsPane != null) {
int selectedIndex = tabsPane.getSelectedIndex();
if (selectedIndex != -1) {
setActiveWindowCaption(caption, description, selectedIndex);
}
} else if (!isMainWindowManager) {
setTopLevelWindowCaption(formattedCaption);
}
} else {
JDialog jDialog = (JDialog) openInfo.getData();
if (jDialog != null) {
jDialog.setTitle(formattedCaption);
}
}
}
}
use of com.haulmont.cuba.gui.components.Window in project cuba by cuba-platform.
the class DesktopWindowManager method showNewWindow.
protected JComponent showNewWindow(Window window, OpenType openType, String caption) {
window.setHeight("100%");
window.setWidth("100%");
TopLevelFrame windowFrame = createTopLevelFrame(caption);
windowFrame.setName(window.getId());
Dimension dimension = new Dimension();
dimension.width = 800;
if (openType.getWidth() != null) {
dimension.width = openType.getWidth().intValue();
}
dimension.height = 500;
if (openType.getHeight() != null) {
dimension.height = openType.getHeight().intValue();
}
boolean resizable = true;
if (openType.getResizable() != null) {
resizable = openType.getResizable();
}
windowFrame.setResizable(resizable);
windowFrame.setMinimumSize(dimension);
windowFrame.pack();
getDialogParams().reset();
WindowBreadCrumbs breadCrumbs = createBreadCrumbs();
breadCrumbs.addWindow(window);
JComponent tabContent = createTabPanel(window, breadCrumbs);
WindowOpenInfo openInfo = new WindowOpenInfo(window, OpenMode.NEW_WINDOW);
openInfo.setData(tabContent);
Map<Window, WindowOpenInfo> openInfos = new HashMap<>();
if (window instanceof Window.Wrapper) {
Window wrappedWindow = ((Window.Wrapper) window).getWrappedWindow();
openInfos.put(wrappedWindow, openInfo);
} else {
openInfos.put(window, openInfo);
}
windowFrame.getWindowManager().attachTab(breadCrumbs, new Stack<>(), window, getWindowHashCode(window), tabContent, openInfos);
App.getInstance().registerFrame(windowFrame);
windowFrame.setVisible(true);
return DesktopComponentsHelper.getComposition(window);
}
Aggregations