use of com.haulmont.cuba.gui.components.Component in project cuba by cuba-platform.
the class DesktopGridLayout method removeAll.
@Override
public void removeAll() {
wrappers.clear();
impl.removeAll();
componentByIds.clear();
captions.clear();
List<Component> components = new ArrayList<>(ownComponents);
ownComponents.clear();
for (Component component : components) {
if (component instanceof DesktopAbstractComponent && !isEnabledWithParent()) {
((DesktopAbstractComponent) component).setParentEnabled(true);
}
component.setParent(null);
DesktopContainerHelper.assignContainer(component, null);
}
requestRepaint();
}
use of com.haulmont.cuba.gui.components.Component in project cuba by cuba-platform.
the class WindowCreationHelper method applyComponentActionPermission.
/**
* Process permissions for actions in action holder
*
* @param window Window
* @param screenId Screen Id
* @param permissionValue Permission value
* @param componentId Component Id
*/
private static void applyComponentActionPermission(Window window, String screenId, Integer permissionValue, String componentId) {
final Matcher matcher = COMPONENT_ACTION_PATTERN.matcher(componentId);
if (matcher.find()) {
final String customComponentId = matcher.group(1);
final String actionId = matcher.group(2);
final Component actionHolderComponent = window.getComponent(customComponentId);
if (actionHolderComponent != null) {
if (actionHolderComponent instanceof Component.SecuredActionsHolder) {
ActionsPermissions permissions = ((Component.SecuredActionsHolder) actionHolderComponent).getActionsPermissions();
if (permissionValue == UiPermissionValue.HIDE.getValue()) {
permissions.addHiddenActionPermission(actionId);
} else if (permissionValue == UiPermissionValue.READ_ONLY.getValue()) {
permissions.addDisabledActionPermission(actionId);
}
} else {
log.warn(String.format("Couldn't apply permission on action %s for component %s in window %s", actionId, customComponentId, screenId));
}
} else {
log.info(String.format("Couldn't find component %s in window %s", componentId, screenId));
}
} else {
log.warn(String.format("Incorrect permission definition for component %s in window %s", componentId, screenId));
}
}
use of com.haulmont.cuba.gui.components.Component in project cuba by cuba-platform.
the class DsContextImpl method get.
@Override
public Datasource get(String id) {
Preconditions.checkNotNullArgument(id, "Null datasource ID");
Datasource ds = null;
if (!id.contains(".")) {
ds = datasourceMap.get(id);
if (ds == null && parent != null) {
ds = parent.get(id);
}
} else {
if (windowContext != null) {
String nestedFramePath = id.substring(0, id.indexOf("."));
Component nestedFrame = getFrameContext().getFrame().getComponent(nestedFramePath);
if ((nestedFrame) != null && (nestedFrame instanceof Frame)) {
String nestedDsId = id.substring(id.indexOf(".") + 1);
ds = ((Frame) nestedFrame).getDsContext().get(nestedDsId);
}
}
}
return ds;
}
use of com.haulmont.cuba.gui.components.Component in project cuba by cuba-platform.
the class DesktopWindowManager method addShortcuts.
protected void addShortcuts(Window window, OpenType openType) {
ClientConfig clientConfig = configuration.getConfig(ClientConfig.class);
String closeShortcut = clientConfig.getCloseShortcut();
window.addAction(new com.haulmont.cuba.gui.components.AbstractAction("closeWindowShortcutAction", closeShortcut) {
@Override
public void actionPerform(Component component) {
if (openType.getOpenMode() != OpenMode.DIALOG || BooleanUtils.isNotFalse(window.getDialogOptions().getCloseable())) {
if (!isCloseWithShortcutPrevented(window)) {
window.close("close");
}
}
}
});
String previousTabShortcut = clientConfig.getPreviousTabShortcut();
window.addAction(new com.haulmont.cuba.gui.components.AbstractAction("onPreviousTab", previousTabShortcut) {
@Override
public void actionPerform(Component component) {
if (window.getWindowManager() != DesktopWindowManager.this) {
// detached tab
return;
}
if (isMainWindowManager && getLastDialogWindow() == null && tabsPane.getTabCount() > 1) {
int selectedIndex = getSelectedTabIndex();
int newIndex = (selectedIndex + tabsPane.getTabCount() - 1) % tabsPane.getTabCount();
java.awt.Component newTab = tabsPane.getComponentAt(newIndex);
tabsPane.setSelectedComponent(newTab);
moveFocus(newTab);
}
}
});
String nextTabShortcut = clientConfig.getNextTabShortcut();
window.addAction(new com.haulmont.cuba.gui.components.AbstractAction("onNextTab", nextTabShortcut) {
@Override
public void actionPerform(Component component) {
if (window.getWindowManager() != DesktopWindowManager.this) {
// detached tab
return;
}
if (isMainWindowManager && getLastDialogWindow() == null && tabsPane.getTabCount() > 1) {
int selectedIndex = getSelectedTabIndex();
int newIndex = (selectedIndex + 1) % tabsPane.getTabCount();
java.awt.Component newTab = tabsPane.getComponentAt(newIndex);
tabsPane.setSelectedComponent(newTab);
moveFocus(newTab);
}
}
});
}
use of com.haulmont.cuba.gui.components.Component in project cuba by cuba-platform.
the class DesktopWindowManager method checkModificationsAndCloseAll.
public void checkModificationsAndCloseAll(final Runnable runIfOk, @Nullable final Runnable runIfCancel) {
boolean modified = false;
for (Window window : getOpenWindows()) {
if (!disableSavingScreenHistory) {
screenHistorySupport.saveScreenHistory(window, windowOpenMode.get(window).getOpenMode());
}
recursiveFramesClose = true;
try {
if (window instanceof WrappedWindow && ((WrappedWindow) window).getWrapper() != null) {
((WrappedWindow) window).getWrapper().saveSettings();
} else {
window.saveSettings();
}
} finally {
recursiveFramesClose = false;
}
if (window.getDsContext() != null && window.getDsContext().isModified()) {
modified = true;
}
}
disableSavingScreenHistory = true;
if (modified) {
showOptionDialog(messages.getMainMessage("closeUnsaved.caption"), messages.getMainMessage("discardChangesOnClose"), MessageType.WARNING, new Action[] { new com.haulmont.cuba.gui.components.AbstractAction(messages.getMainMessage("closeApplication")) {
@Override
public void actionPerform(com.haulmont.cuba.gui.components.Component component) {
if (runIfOk != null)
runIfOk.run();
}
@Override
public String getIcon() {
return "icons/ok.png";
}
}, new com.haulmont.cuba.gui.components.AbstractAction(messages.getMainMessage("actions.Cancel"), Status.PRIMARY) {
@Override
public void actionPerform(com.haulmont.cuba.gui.components.Component component) {
if (runIfCancel != null)
runIfCancel.run();
}
@Override
public String getIcon() {
return "icons/cancel.png";
}
} });
} else {
runIfOk.run();
}
}
Aggregations