use of com.vaadin.ui.Component in project cuba by cuba-platform.
the class AccessGroupCompanion method initDragAndDrop.
@Override
public void initDragAndDrop(Table<User> usersTable, Tree<Group> groupsTree, Consumer<UserGroupChangedEvent> userGroupChangedHandler) {
com.vaadin.ui.Table vTable = usersTable.unwrap(com.vaadin.ui.Table.class);
vTable.setDragMode(com.vaadin.ui.Table.TableDragMode.MULTIROW);
CubaTree vTree = groupsTree.unwrap(CubaTree.class);
vTree.setDragMode(com.vaadin.ui.Tree.TreeDragMode.NODE);
vTree.setDropHandler(new DropHandler() {
@Override
public void drop(DragAndDropEvent dropEvent) {
DataBoundTransferable transferable = (DataBoundTransferable) dropEvent.getTransferable();
AbstractSelect.AbstractSelectTargetDetails dropData = ((AbstractSelect.AbstractSelectTargetDetails) dropEvent.getTargetDetails());
Component sourceComponent = transferable.getSourceComponent();
List<User> users = null;
if (sourceComponent instanceof com.vaadin.ui.Table) {
users = new ArrayList<>(usersTable.getSelected());
}
if (users == null) {
return;
}
if (users.isEmpty()) {
User user = convertToEntity(vTable.getItem(transferable.getItemId()), User.class);
users.add(user);
}
final Object targetItemId = dropData.getItemIdOver();
if (targetItemId == null) {
return;
}
Group group = convertToEntity(vTree.getItem(targetItemId), Group.class);
if (group == null) {
return;
}
userGroupChangedHandler.accept(new UserGroupChangedEvent(groupsTree, users, group));
}
@Override
public AcceptCriterion getAcceptCriterion() {
return new And(AbstractSelect.AcceptItem.ALL);
}
});
}
use of com.vaadin.ui.Component in project cuba by cuba-platform.
the class WebWindowManager method createCloseShortcut.
public ShortcutListener createCloseShortcut(Window.TopLevelWindow topLevelWindow) {
String closeShortcut = clientConfig.getCloseShortcut();
KeyCombination combination = KeyCombination.create(closeShortcut);
return new ShortcutListener("onClose", combination.getKey().getCode(), KeyCombination.Modifier.codes(combination.getModifiers())) {
@Override
public void handleAction(Object sender, Object target) {
WebAppWorkArea workArea = getConfiguredWorkArea(createWorkAreaContext(topLevelWindow));
if (workArea.getState() != AppWorkArea.State.WINDOW_CONTAINER) {
return;
}
if (workArea.getMode() == Mode.TABBED) {
TabSheetBehaviour tabSheet = workArea.getTabbedWindowContainer().getTabSheetBehaviour();
if (tabSheet != null) {
Layout layout = (Layout) tabSheet.getSelectedTab();
if (layout != null) {
tabSheet.focus();
WindowBreadCrumbs breadCrumbs = tabs.get(layout);
if (!canWindowBeClosed(breadCrumbs.getCurrentWindow())) {
return;
}
if (isCloseWithShortcutPrevented(breadCrumbs.getCurrentWindow())) {
return;
}
if (stacks.get(breadCrumbs).empty()) {
final Component previousTab = tabSheet.getPreviousTab(layout);
if (previousTab != null) {
breadCrumbs.getCurrentWindow().closeAndRun(Window.CLOSE_ACTION_ID, () -> tabSheet.setSelectedTab(previousTab));
} else {
breadCrumbs.getCurrentWindow().close(Window.CLOSE_ACTION_ID);
}
} else {
breadCrumbs.getCurrentWindow().close(Window.CLOSE_ACTION_ID);
}
}
}
} else {
Iterator<WindowBreadCrumbs> it = tabs.values().iterator();
if (it.hasNext()) {
Window currentWindow = it.next().getCurrentWindow();
if (!isCloseWithShortcutPrevented(currentWindow)) {
ui.focus();
currentWindow.close(Window.CLOSE_ACTION_ID);
}
}
}
}
};
}
use of com.vaadin.ui.Component in project cuba by cuba-platform.
the class WebWindowManager method showWindow.
@Override
protected void showWindow(final Window window, final String caption, final String description, OpenType type, final boolean multipleOpen) {
OpenType targetOpenType = type.copy();
// for backward compatibility only
copyDialogParamsToOpenType(targetOpenType);
overrideOpenTypeParams(targetOpenType, window.getDialogOptions());
boolean forciblyDialog = false;
if (targetOpenType.getOpenMode() != OpenMode.DIALOG && hasModalWindow()) {
targetOpenType.setOpenMode(OpenMode.DIALOG);
forciblyDialog = true;
}
if (targetOpenType.getOpenMode() == OpenMode.THIS_TAB && tabs.size() == 0) {
targetOpenType.setOpenMode(OpenMode.NEW_TAB);
}
final WindowOpenInfo openInfo = new WindowOpenInfo(window, targetOpenType.getOpenMode());
Component component;
window.setCaption(caption);
window.setDescription(description);
switch(targetOpenType.getOpenMode()) {
case NEW_TAB:
case NEW_WINDOW:
final WebAppWorkArea workArea = getConfiguredWorkArea(createWorkAreaContext(window));
workArea.switchTo(AppWorkArea.State.WINDOW_CONTAINER);
if (workArea.getMode() == Mode.SINGLE) {
VerticalLayout mainLayout = workArea.getSingleWindowContainer();
if (mainLayout.iterator().hasNext()) {
ComponentContainer oldLayout = (ComponentContainer) mainLayout.iterator().next();
WindowBreadCrumbs oldBreadCrumbs = tabs.get(oldLayout);
if (oldBreadCrumbs != null) {
Window oldWindow = oldBreadCrumbs.getCurrentWindow();
oldWindow.closeAndRun(MAIN_MENU_ACTION_ID, () -> showWindow(window, caption, description, OpenType.NEW_TAB, false));
return;
}
}
} else {
final Integer hashCode = getWindowHashCode(window);
ComponentContainer tab = null;
if (hashCode != null && !multipleOpen) {
tab = findTab(hashCode);
}
ComponentContainer oldLayout = tab;
final WindowBreadCrumbs oldBreadCrumbs = tabs.get(oldLayout);
if (oldBreadCrumbs != null && windowOpenMode.containsKey(oldBreadCrumbs.getCurrentWindow().getFrame()) && !multipleOpen) {
Window oldWindow = oldBreadCrumbs.getCurrentWindow();
selectWindowTab(((Window.Wrapper) oldBreadCrumbs.getCurrentWindow()).getWrappedWindow());
int tabPosition = -1;
final TabSheetBehaviour tabSheet = workArea.getTabbedWindowContainer().getTabSheetBehaviour();
String tabId = tabSheet.getTab(tab);
if (tabId != null) {
tabPosition = tabSheet.getTabPosition(tabId);
}
final int finalTabPosition = tabPosition;
oldWindow.closeAndRun(MAIN_MENU_ACTION_ID, () -> {
showWindow(window, caption, description, OpenType.NEW_TAB, false);
Window wrappedWindow = window;
if (window instanceof Window.Wrapper) {
wrappedWindow = ((Window.Wrapper) window).getWrappedWindow();
}
if (finalTabPosition >= 0 && finalTabPosition < tabSheet.getComponentCount() - 1) {
moveWindowTab(workArea, wrappedWindow, finalTabPosition);
}
});
return;
}
}
component = showWindowNewTab(window, multipleOpen);
break;
case THIS_TAB:
getConfiguredWorkArea(createWorkAreaContext(window)).switchTo(AppWorkArea.State.WINDOW_CONTAINER);
component = showWindowThisTab(window, caption, description);
break;
case DIALOG:
component = showWindowDialog(window, targetOpenType, forciblyDialog);
break;
default:
throw new UnsupportedOperationException();
}
openInfo.setData(component);
if (window instanceof Window.Wrapper) {
Window wrappedWindow = ((Window.Wrapper) window).getWrappedWindow();
windowOpenMode.put(wrappedWindow, openInfo);
} else {
windowOpenMode.put(window, openInfo);
}
afterShowWindow(window);
}
use of com.vaadin.ui.Component in project cuba by cuba-platform.
the class WebWindowManager method setWindowCaption.
@Override
public void setWindowCaption(Window window, String caption, String description) {
Window webWindow = window;
if (window instanceof Window.Wrapper) {
webWindow = ((Window.Wrapper) window).getWrappedWindow();
}
window.setCaption(caption);
window.setDebugId(description);
WindowOpenInfo openInfo = windowOpenMode.get(webWindow);
String formattedCaption;
if (openInfo != null && (openInfo.getOpenMode() == OpenMode.NEW_TAB || openInfo.getOpenMode() == OpenMode.NEW_WINDOW || openInfo.getOpenMode() == OpenMode.THIS_TAB)) {
formattedCaption = formatTabCaption(caption, description);
} else {
formattedCaption = formatTabDescription(caption, description);
}
if (openInfo != null) {
if (openInfo.getOpenMode() == OpenMode.DIALOG) {
com.vaadin.ui.Window dialog = (com.vaadin.ui.Window) openInfo.getData();
dialog.setCaption(formattedCaption);
} else {
if (getConfiguredWorkArea(createWorkAreaContext(window)).getMode() == Mode.SINGLE) {
return;
}
Component tabContent = (Component) openInfo.getData();
if (tabContent == null) {
return;
}
TabSheetBehaviour tabSheet = getConfiguredWorkArea(createWorkAreaContext(window)).getTabbedWindowContainer().getTabSheetBehaviour();
String tabId = tabSheet.getTab(tabContent);
if (tabId == null) {
return;
}
tabSheet.setTabCaption(tabId, formattedCaption);
String formattedDescription = formatTabDescription(caption, description);
if (!Objects.equals(formattedDescription, formattedCaption)) {
tabSheet.setTabDescription(tabId, formattedDescription);
} else {
tabSheet.setTabDescription(tabId, null);
}
}
}
}
use of com.vaadin.ui.Component in project cuba by cuba-platform.
the class WebWindowManager method closeWindow.
protected void closeWindow(Window window, WindowOpenInfo openInfo) {
if (!disableSavingScreenHistory) {
screenHistorySupport.saveScreenHistory(window, openInfo.getOpenMode());
}
WebWindow webWindow = (WebWindow) window;
webWindow.stopTimers();
switch(openInfo.getOpenMode()) {
case DIALOG:
{
final CubaWindow cubaDialogWindow = (CubaWindow) openInfo.getData();
cubaDialogWindow.forceClose();
fireListeners(window, tabs.size() != 0);
break;
}
case NEW_WINDOW:
case NEW_TAB:
{
final Layout layout = (Layout) openInfo.getData();
layout.removeComponent(WebComponentsHelper.getComposition(window));
WebAppWorkArea workArea = getConfiguredWorkArea(createWorkAreaContext(window));
if (workArea.getMode() == Mode.TABBED) {
TabSheetBehaviour tabSheet = workArea.getTabbedWindowContainer().getTabSheetBehaviour();
tabSheet.silentCloseTabAndSelectPrevious(layout);
tabSheet.removeComponent(layout);
} else {
VerticalLayout singleLayout = workArea.getSingleWindowContainer();
singleLayout.removeComponent(layout);
}
WindowBreadCrumbs windowBreadCrumbs = tabs.get(layout);
if (windowBreadCrumbs != null) {
windowBreadCrumbs.clearListeners();
windowBreadCrumbs.removeWindow();
}
tabs.remove(layout);
stacks.remove(windowBreadCrumbs);
fireListeners(window, !tabs.isEmpty());
if (tabs.isEmpty() && app.getConnection().isConnected()) {
workArea.switchTo(AppWorkArea.State.INITIAL_LAYOUT);
}
break;
}
case THIS_TAB:
{
final Layout layout = (Layout) openInfo.getData();
final WindowBreadCrumbs breadCrumbs = tabs.get(layout);
if (breadCrumbs == null) {
throw new IllegalStateException("Unable to close screen: breadCrumbs not found");
}
breadCrumbs.removeWindow();
Window currentWindow = breadCrumbs.getCurrentWindow();
if (!getStack(breadCrumbs).empty()) {
Pair<Window, Integer> entry = getStack(breadCrumbs).pop();
putToWindowMap(entry.getFirst(), entry.getSecond());
}
Component component = WebComponentsHelper.getComposition(currentWindow);
component.setSizeFull();
WebAppWorkArea workArea = getConfiguredWorkArea(createWorkAreaContext(window));
layout.removeComponent(WebComponentsHelper.getComposition(window));
if (app.getConnection().isConnected()) {
layout.addComponent(component);
if (workArea.getMode() == Mode.TABBED) {
TabSheetBehaviour tabSheet = workArea.getTabbedWindowContainer().getTabSheetBehaviour();
String tabId = tabSheet.getTab(layout);
String formattedCaption = formatTabCaption(currentWindow.getCaption(), currentWindow.getDescription());
tabSheet.setTabCaption(tabId, formattedCaption);
String formattedDescription = formatTabDescription(currentWindow.getCaption(), currentWindow.getDescription());
if (!Objects.equals(formattedCaption, formattedDescription)) {
tabSheet.setTabDescription(tabId, formattedDescription);
} else {
tabSheet.setTabDescription(tabId, null);
}
tabSheet.setTabIcon(tabId, iconResolver.getIconResource(currentWindow.getIcon()));
ContentSwitchMode contentSwitchMode = ContentSwitchMode.valueOf(currentWindow.getContentSwitchMode().name());
tabSheet.setContentSwitchMode(tabId, contentSwitchMode);
}
}
fireListeners(window, !tabs.isEmpty());
if (tabs.isEmpty() && app.getConnection().isConnected()) {
workArea.switchTo(AppWorkArea.State.INITIAL_LAYOUT);
}
break;
}
default:
{
throw new UnsupportedOperationException();
}
}
}
Aggregations