List of usage examples for com.vaadin.ui VerticalLayout addComponent
@Override public void addComponent(Component c)
From source file:com.haulmont.cuba.web.gui.components.WebAbstractTable.java
License:Apache License
@Override public void addGeneratedColumn(String columnId, ColumnGenerator<? super E> generator) { checkNotNullArgument(columnId, "columnId is null"); checkNotNullArgument(generator, "generator is null for column id '%s'", columnId); MetaPropertyPath targetCol = getDatasource().getMetaClass().getPropertyPath(columnId); Object generatedColumnId = targetCol != null ? targetCol : columnId; Column column = getColumn(columnId); Column associatedRuntimeColumn = null; if (column == null) { Column newColumn = new Column(generatedColumnId); columns.put(newColumn.getId(), newColumn); columnsOrder.add(newColumn);/*from w w w. j av a 2 s . c o m*/ associatedRuntimeColumn = newColumn; newColumn.setOwner(this); } // save column order Object[] visibleColumns = component.getVisibleColumns(); boolean removeOldGeneratedColumn = component.getColumnGenerator(generatedColumnId) != null; // replace generator for column if exist if (removeOldGeneratedColumn) { component.removeGeneratedColumn(generatedColumnId); } component.addGeneratedColumn(generatedColumnId, new CustomColumnGenerator(generator, associatedRuntimeColumn) { @SuppressWarnings("unchecked") @Override public Object generateCell(com.vaadin.ui.Table source, Object itemId, Object columnId) { Entity entity = getDatasource().getItem(itemId); com.haulmont.cuba.gui.components.Component component = getColumnGenerator() .generateCell(entity); if (component == null) { return null; } if (component instanceof PlainTextCell) { return ((PlainTextCell) component).getText(); } if (component instanceof BelongToFrame) { BelongToFrame belongToFrame = (BelongToFrame) component; if (belongToFrame.getFrame() == null) { belongToFrame.setFrame(getFrame()); } } component.setParent(WebAbstractTable.this); com.vaadin.ui.Component vComponent = component.unwrapComposition(Component.class); // wrap field for show required asterisk if ((vComponent instanceof com.vaadin.ui.Field) && (((com.vaadin.ui.Field) vComponent).isRequired())) { VerticalLayout layout = new VerticalLayout(); layout.addComponent(vComponent); if (vComponent.getWidth() < 0) { layout.setWidthUndefined(); } layout.addComponent(vComponent); vComponent = layout; } return vComponent; } }); if (removeOldGeneratedColumn) { // restore column order component.setVisibleColumns(visibleColumns); } }
From source file:com.haulmont.cuba.web.gui.components.WebAbstractTable.java
License:Apache License
@Override public void showCustomPopupActions(List<Action> actions) { VerticalLayout customContextMenu = new VerticalLayout(); customContextMenu.setWidthUndefined(); customContextMenu.setStyleName("c-cm-container"); for (Action action : actions) { ContextMenuButton contextMenuButton = createContextMenuButton(); contextMenuButton.setStyleName("c-cm-button"); contextMenuButton.setAction(action); Component vButton = WebComponentsHelper.unwrap(contextMenuButton); customContextMenu.addComponent(vButton); }//ww w.j a va 2 s .c o m if (customContextMenu.getComponentCount() > 0) { component.showCustomPopup(customContextMenu); component.setCustomPopupAutoClose(true); } }
From source file:com.haulmont.cuba.web.log.LogWindow.java
License:Apache License
private void initUI() { ClientConfig clientConfig = AppBeans.<Configuration>get(Configuration.NAME).getConfig(ClientConfig.class); String closeShortcut = clientConfig.getCloseShortcut(); KeyCombination closeCombination = KeyCombination.create(closeShortcut); com.vaadin.event.ShortcutAction closeShortcutAction = new com.vaadin.event.ShortcutAction( "closeShortcutAction", closeCombination.getKey().getCode(), KeyCombination.Modifier.codes(closeCombination.getModifiers())); addActionHandler(new com.vaadin.event.Action.Handler() { @Override/* w ww.ja v a 2 s . co m*/ public com.vaadin.event.Action[] getActions(Object target, Object sender) { return new com.vaadin.event.Action[] { closeShortcutAction }; } @Override public void handleAction(com.vaadin.event.Action action, Object sender, Object target) { if (Objects.equals(action, closeShortcutAction)) { close(); } } }); VerticalLayout layout = new VerticalLayout(); layout.setSpacing(true); layout.setSizeFull(); setContent(layout); Panel scrollablePanel = new Panel(); scrollablePanel.setSizeFull(); VerticalLayout scrollContent = new VerticalLayout(); scrollContent.setSizeUndefined(); scrollablePanel.setContent(scrollContent); final Label label = new Label(); label.setContentMode(ContentMode.HTML); label.setValue(writeLog()); label.setSizeUndefined(); label.setStyleName("c-log-content"); ((Layout) scrollablePanel.getContent()).addComponent(label); HorizontalLayout topLayout = new HorizontalLayout(); topLayout.setWidth("100%"); topLayout.setHeightUndefined(); Messages messages = AppBeans.get(Messages.NAME); Button refreshBtn = new CubaButton(messages.getMessage(getClass(), "logWindow.refreshBtn"), (Button.ClickListener) event -> label.setValue(writeLog())); topLayout.addComponent(refreshBtn); layout.addComponent(topLayout); layout.addComponent(scrollablePanel); layout.setExpandRatio(scrollablePanel, 1.0f); }
From source file:com.haulmont.cuba.web.LoginWindow.java
License:Apache License
protected VerticalLayout createCenterLayout(int formWidth, int formHeight, int fieldWidth, boolean localesSelectVisible) { VerticalLayout centerLayout = new VerticalLayout(); centerLayout.setStyleName("cuba-login-bottom"); centerLayout.setWidth(formWidth + "px"); centerLayout.setHeight(formHeight + "px"); HorizontalLayout titleLayout = createTitleLayout(); centerLayout.addComponent(titleLayout); centerLayout.setComponentAlignment(titleLayout, Alignment.MIDDLE_CENTER); FormLayout loginFormLayout = createLoginFormLayout(fieldWidth, localesSelectVisible); centerLayout.addComponent(loginFormLayout); centerLayout.setComponentAlignment(loginFormLayout, Alignment.MIDDLE_CENTER); return centerLayout; }
From source file:com.haulmont.cuba.web.toolkit.ui.CubaColorPickerPopup.java
License:Apache License
@Override protected Component createSelectTab() { VerticalLayout selLayout = new VerticalLayout(); selLayout.setMargin(new MarginInfo(false, false, true, false)); selLayout.addComponent(selPreview); selLayout.addStyleName("seltab"); colorSelect = new CubaColorPickerSelect(); colorSelect.addColorChangeListener(this); selLayout.addComponent(colorSelect); return selLayout; }
From source file:com.haulmont.cuba.web.WebWindowManager.java
License:Apache License
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();//from ww w . j ava 2 s . co m 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, WebComponentsHelper.getIcon(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; }
From source file:com.haulmont.cuba.web.WebWindowManager.java
License:Apache License
@Override public void showMessageDialog(String title, String message, MessageType messageType) { backgroundWorker.checkUIAccess();/*from ww w . j a v a2s.co m*/ final com.vaadin.ui.Window vWindow = new CubaWindow(title); if (ui.isTestMode()) { vWindow.setCubaId("messageDialog"); vWindow.setId(ui.getTestIdManager().getTestId("messageDialog")); } String closeShortcut = clientConfig.getCloseShortcut(); KeyCombination closeCombination = KeyCombination.create(closeShortcut); vWindow.addAction(new ShortcutListener("Esc", closeCombination.getKey().getCode(), KeyCombination.Modifier.codes(closeCombination.getModifiers())) { @Override public void handleAction(Object sender, Object target) { vWindow.close(); } }); vWindow.addAction(new ShortcutListener("Enter", ShortcutAction.KeyCode.ENTER, null) { @Override public void handleAction(Object sender, Object target) { vWindow.close(); } }); VerticalLayout layout = new VerticalLayout(); layout.setStyleName("c-app-message-dialog"); layout.setSpacing(true); if (messageType.getWidth() != null && messageType.getWidth() == AUTO_SIZE_PX) { layout.setWidthUndefined(); } vWindow.setContent(layout); Label messageLab = new CubaLabel(); messageLab.setValue(message); if (MessageType.isHTML(messageType)) { messageLab.setContentMode(ContentMode.HTML); } else { messageLab.setContentMode(ContentMode.TEXT); } if (messageType.getWidth() != null && messageType.getWidth() == AUTO_SIZE_PX) { messageLab.setWidthUndefined(); } layout.addComponent(messageLab); DialogAction action = new DialogAction(Type.OK); Button button = WebComponentsHelper.createButton(); button.setCaption(action.getCaption()); button.setIcon(WebComponentsHelper.getIcon(action.getIcon())); button.addStyleName(WebButton.ICON_STYLE); button.addClickListener(event -> vWindow.close()); button.focus(); layout.addComponent(button); layout.setComponentAlignment(button, Alignment.BOTTOM_RIGHT); float width; SizeUnit unit; DialogParams dialogParams = getDialogParams(); if (messageType.getWidth() != null) { width = messageType.getWidth(); unit = messageType.getWidthUnit(); } else if (dialogParams.getWidth() != null) { width = dialogParams.getWidth(); unit = dialogParams.getWidthUnit(); } else { SizeWithUnit size = SizeWithUnit .parseStringSize(app.getThemeConstants().get("cuba.web.WebWindowManager.messageDialog.width")); width = size.getSize(); unit = size.getUnit(); } vWindow.setWidth(width, unit != null ? WebWrapperUtils.toVaadinUnit(unit) : Unit.PIXELS); vWindow.setResizable(false); boolean modal = true; if (!hasModalWindow()) { if (messageType.getModal() != null) { modal = messageType.getModal(); } else if (dialogParams.getModal() != null) { modal = dialogParams.getModal(); } } vWindow.setModal(modal); boolean closeOnClickOutside = false; if (vWindow.isModal()) { if (messageType.getCloseOnClickOutside() != null) { closeOnClickOutside = messageType.getCloseOnClickOutside(); } } ((CubaWindow) vWindow).setCloseOnClickOutside(closeOnClickOutside); if (messageType.getMaximized() != null) { if (messageType.getMaximized()) { vWindow.setWindowMode(WindowMode.MAXIMIZED); } else { vWindow.setWindowMode(WindowMode.NORMAL); } } dialogParams.reset(); ui.addWindow(vWindow); vWindow.center(); vWindow.focus(); }
From source file:com.haulmont.cuba.web.WebWindowManager.java
License:Apache License
@Override public void showOptionDialog(String title, String message, MessageType messageType, Action[] actions) { backgroundWorker.checkUIAccess();/*from w w w . j av a2 s. co m*/ final com.vaadin.ui.Window window = new CubaWindow(title); if (ui.isTestMode()) { window.setCubaId("optionDialog"); window.setId(ui.getTestIdManager().getTestId("optionDialog")); } window.setClosable(false); Label messageLab = new CubaLabel(); messageLab.setValue(message); if (MessageType.isHTML(messageType)) { messageLab.setContentMode(ContentMode.HTML); } else { messageLab.setContentMode(ContentMode.TEXT); } if (messageType.getWidth() != null && messageType.getWidth() == AUTO_SIZE_PX) { messageLab.setWidthUndefined(); } float width; SizeUnit unit; if (messageType.getWidth() != null) { width = messageType.getWidth(); unit = messageType.getWidthUnit(); } else if (getDialogParams().getWidth() != null) { width = getDialogParams().getWidth(); unit = getDialogParams().getWidthUnit(); } else { SizeWithUnit size = SizeWithUnit .parseStringSize(app.getThemeConstants().get("cuba.web.WebWindowManager.optionDialog.width")); width = size.getSize(); unit = size.getUnit(); } if (messageType.getModal() != null) { log.warn("MessageType.modal is not supported for showOptionDialog"); } getDialogParams().reset(); window.setWidth(width, unit != null ? WebWrapperUtils.toVaadinUnit(unit) : Unit.PIXELS); window.setResizable(false); window.setModal(true); boolean closeOnClickOutside = false; if (window.isModal()) { if (messageType.getCloseOnClickOutside() != null) { closeOnClickOutside = messageType.getCloseOnClickOutside(); } } ((CubaWindow) window).setCloseOnClickOutside(closeOnClickOutside); if (messageType.getMaximized() != null) { if (messageType.getMaximized()) { window.setWindowMode(WindowMode.MAXIMIZED); } else { window.setWindowMode(WindowMode.NORMAL); } } VerticalLayout layout = new VerticalLayout(); layout.setStyleName("c-app-option-dialog"); layout.setSpacing(true); if (messageType.getWidth() != null && messageType.getWidth() == AUTO_SIZE_PX) { layout.setWidthUndefined(); } window.setContent(layout); HorizontalLayout buttonsContainer = new HorizontalLayout(); buttonsContainer.setSpacing(true); boolean hasPrimaryAction = false; Map<Action, Button> buttonMap = new HashMap<>(); for (Action action : actions) { Button button = WebComponentsHelper.createButton(); button.setCaption(action.getCaption()); button.addClickListener(event -> { try { action.actionPerform(null); } finally { ui.removeWindow(window); } }); if (StringUtils.isNotEmpty(action.getIcon())) { button.setIcon(WebComponentsHelper.getIcon(action.getIcon())); button.addStyleName(WebButton.ICON_STYLE); } if (action instanceof AbstractAction && ((AbstractAction) action).isPrimary()) { button.addStyleName("c-primary-action"); button.focus(); hasPrimaryAction = true; } if (ui.isTestMode()) { button.setCubaId("optionDialog_" + action.getId()); button.setId(ui.getTestIdManager().getTestId("optionDialog_" + action.getId())); } buttonsContainer.addComponent(button); buttonMap.put(action, button); } assignDialogShortcuts(buttonMap); if (!hasPrimaryAction && actions.length > 0) { ((Button) buttonsContainer.getComponent(0)).focus(); } layout.addComponent(messageLab); layout.addComponent(buttonsContainer); layout.setExpandRatio(messageLab, 1); layout.setComponentAlignment(buttonsContainer, Alignment.BOTTOM_RIGHT); ui.addWindow(window); window.center(); }
From source file:com.haulmont.cuba.web.widgets.CubaColorPickerPopup.java
License:Apache License
@Override protected Component createSelectTab() { VerticalLayout selLayout = new VerticalLayout(); selLayout.setSpacing(false);//from ww w .j a va 2 s. c o m selLayout.setMargin(new MarginInfo(false, false, true, false)); selLayout.addComponent(selPreview); selLayout.addStyleName("seltab"); colorSelect = new CubaColorPickerSelect(); colorSelect.addValueChangeListener(this::colorChanged); selLayout.addComponent(colorSelect); return selLayout; }
From source file:com.hivesys.dashboard.view.repository.DragAndDropBox.java
private void showComponent(final Component c, final String name) { final VerticalLayout layout = new VerticalLayout(); layout.setSizeUndefined();/* w w w.j a v a 2 s.c o m*/ layout.setMargin(true); final Window w = new Window(name, layout); w.addStyleName("dropdisplaywindow"); w.setSizeUndefined(); w.setResizable(false); c.setSizeUndefined(); layout.addComponent(c); UI.getCurrent().addWindow(w); }