use of com.vaadin.ui.Component in project cuba by cuba-platform.
the class WebWindowManager method showFrame.
@Override
public void showFrame(com.haulmont.cuba.gui.components.Component parent, Frame frame) {
if (parent instanceof Container) {
Container container = (Container) parent;
for (com.haulmont.cuba.gui.components.Component c : container.getComponents()) {
if (c instanceof com.haulmont.cuba.gui.components.Component.Disposable) {
com.haulmont.cuba.gui.components.Component.Disposable disposable = (com.haulmont.cuba.gui.components.Component.Disposable) c;
if (!disposable.isDisposed()) {
disposable.dispose();
}
}
container.remove(c);
}
container.add(frame);
} else {
throw new IllegalStateException("Parent component must be com.haulmont.cuba.gui.components.Component.Container");
}
}
use of com.vaadin.ui.Component in project cuba by cuba-platform.
the class WebWindowManager method createNextWindowTabShortcut.
public ShortcutListener createNextWindowTabShortcut(Window.TopLevelWindow topLevelWindow) {
String nextTabShortcut = clientConfig.getNextTabShortcut();
KeyCombination combination = KeyCombination.create(nextTabShortcut);
return new ShortcutListener("onNextTab", combination.getKey().getCode(), KeyCombination.Modifier.codes(combination.getModifiers())) {
@Override
public void handleAction(Object sender, Object target) {
TabSheetBehaviour tabSheet = getConfiguredWorkArea(createWorkAreaContext(topLevelWindow)).getTabbedWindowContainer().getTabSheetBehaviour();
if (tabSheet != null && !hasDialogWindows() && tabSheet.getComponentCount() > 1) {
Component selectedTabComponent = tabSheet.getSelectedTab();
String tabId = tabSheet.getTab(selectedTabComponent);
int tabPosition = tabSheet.getTabPosition(tabId);
int newTabPosition = (tabPosition + 1) % tabSheet.getComponentCount();
String newTabId = tabSheet.getTab(newTabPosition);
tabSheet.setSelectedTab(newTabId);
moveFocus(tabSheet, newTabId);
}
}
};
}
use of com.vaadin.ui.Component in project cuba by cuba-platform.
the class WebWindowManager method createNewTabLayout.
protected Layout createNewTabLayout(final Window window, final boolean multipleOpen, WindowBreadCrumbs breadCrumbs, Component... additionalComponents) {
Layout layout = new CssLayout();
layout.setPrimaryStyleName("c-app-window-wrap");
layout.setSizeFull();
layout.addComponent(breadCrumbs);
if (additionalComponents != null) {
for (final Component c : additionalComponents) {
layout.addComponent(c);
}
}
final Component component = WebComponentsHelper.getComposition(window);
component.setSizeFull();
layout.addComponent(component);
WebAppWorkArea workArea = getConfiguredWorkArea(createWorkAreaContext(window));
if (workArea.getMode() == Mode.TABBED) {
layout.addStyleName("c-app-tabbed-window");
TabSheetBehaviour tabSheet = workArea.getTabbedWindowContainer().getTabSheetBehaviour();
String tabId;
Integer hashCode = getWindowHashCode(window);
ComponentContainer tab = null;
if (hashCode != null) {
tab = findTab(hashCode);
}
if (tab != null && !multipleOpen) {
tabSheet.replaceComponent(tab, layout);
tabSheet.removeComponent(tab);
tabs.put(layout, breadCrumbs);
tabId = tabSheet.getTab(layout);
} else {
tabs.put(layout, breadCrumbs);
tabId = "tab_" + uuidSource.createUuid();
tabSheet.addTab(layout, tabId);
if (ui.isTestMode()) {
String id = "tab_" + window.getId();
tabSheet.setTabTestId(tabId, ui.getTestIdManager().getTestId(id));
tabSheet.setTabCubaId(tabId, id);
}
}
String windowContentSwitchMode = window.getContentSwitchMode().name();
ContentSwitchMode contentSwitchMode = ContentSwitchMode.valueOf(windowContentSwitchMode);
tabSheet.setContentSwitchMode(tabId, contentSwitchMode);
String formattedCaption = formatTabCaption(window.getCaption(), window.getDescription());
tabSheet.setTabCaption(tabId, formattedCaption);
String formattedDescription = formatTabDescription(window.getCaption(), window.getDescription());
if (!Objects.equals(formattedCaption, formattedDescription)) {
tabSheet.setTabDescription(tabId, formattedDescription);
} else {
tabSheet.setTabDescription(tabId, null);
}
tabSheet.setTabIcon(tabId, iconResolver.getIconResource(window.getIcon()));
tabSheet.setTabClosable(tabId, true);
tabSheet.setTabCloseHandler(layout, (targetTabSheet, tabContent) -> {
// noinspection SuspiciousMethodCalls
WindowBreadCrumbs breadCrumbs1 = tabs.get(tabContent);
if (!canWindowBeClosed(breadCrumbs1.getCurrentWindow())) {
return;
}
Runnable closeTask = new TabCloseTask(breadCrumbs1);
closeTask.run();
// it is needed to force redraw tabsheet if it has a lot of tabs and part of them are hidden
targetTabSheet.markAsDirty();
});
tabSheet.setSelectedTab(layout);
} else {
tabs.put(layout, breadCrumbs);
layout.addStyleName("c-app-single-window");
VerticalLayout mainLayout = workArea.getSingleWindowContainer();
mainLayout.removeAllComponents();
mainLayout.addComponent(layout);
}
return layout;
}
use of com.vaadin.ui.Component in project cuba by cuba-platform.
the class WebWindowManager method createPreviousWindowTabShortcut.
public ShortcutListener createPreviousWindowTabShortcut(Window.TopLevelWindow topLevelWindow) {
String previousTabShortcut = clientConfig.getPreviousTabShortcut();
KeyCombination combination = KeyCombination.create(previousTabShortcut);
return new ShortcutListener("onPreviousTab", combination.getKey().getCode(), KeyCombination.Modifier.codes(combination.getModifiers())) {
@Override
public void handleAction(Object sender, Object target) {
TabSheetBehaviour tabSheet = getConfiguredWorkArea(createWorkAreaContext(topLevelWindow)).getTabbedWindowContainer().getTabSheetBehaviour();
if (tabSheet != null && !hasDialogWindows() && tabSheet.getComponentCount() > 1) {
Component selectedTabComponent = tabSheet.getSelectedTab();
String selectedTabId = tabSheet.getTab(selectedTabComponent);
int tabPosition = tabSheet.getTabPosition(selectedTabId);
int newTabPosition = (tabSheet.getComponentCount() + tabPosition - 1) % tabSheet.getComponentCount();
String newTabId = tabSheet.getTab(newTabPosition);
tabSheet.setSelectedTab(newTabId);
moveFocus(tabSheet, newTabId);
}
}
};
}
use of com.vaadin.ui.Component in project cuba by cuba-platform.
the class WebAbstractActionsHolderComponent method addAction.
@Override
public void addAction(Action action, int index) {
checkNotNullArgument(action, "action must be non null");
int oldIndex = findActionById(actionList, action.getId());
if (oldIndex >= 0) {
removeAction(actionList.get(oldIndex));
if (index > oldIndex) {
index--;
}
}
if (StringUtils.isNotEmpty(action.getCaption())) {
ContextMenuButton contextMenuButton = createContextMenuButton();
contextMenuButton.setStyleName("c-cm-button");
contextMenuButton.setAction(action);
contextMenuButtons.add(contextMenuButton);
Component newVButton = WebComponentsHelper.unwrap(contextMenuButton);
int visibleActionsIndex = 0;
int i = 0;
while (i < index && i < actionList.size()) {
if (StringUtils.isNotEmpty(actionList.get(i).getCaption())) {
visibleActionsIndex++;
}
i++;
}
contextMenuPopup.addComponent(newVButton, visibleActionsIndex);
}
actionList.add(index, action);
shortcutsDelegate.addAction(null, action);
attachAction(action);
actionsPermissions.apply(action);
}
Aggregations