Example usage for com.vaadin.ui VerticalLayout setWidthUndefined

List of usage examples for com.vaadin.ui VerticalLayout setWidthUndefined

Introduction

In this page you can find the example usage for com.vaadin.ui VerticalLayout setWidthUndefined.

Prototype

@Override
    public void setWidthUndefined() 

Source Link

Usage

From source file:com.haulmont.cuba.web.exception.NoUserSessionHandler.java

License:Apache License

protected void showNoUserSessionDialog(App app) {
    Messages messages = AppBeans.get(Messages.NAME);

    Window dialog = new NoUserSessionExceptionDialog();
    dialog.setStyleName("c-nousersession-dialog");
    dialog.setCaption(messages.getMainMessage("dialogs.Information", locale));
    dialog.setClosable(false);/* ww w .j  a v a 2 s . com*/
    dialog.setResizable(false);
    dialog.setModal(true);

    AppUI ui = app.getAppUI();

    if (ui.isTestMode()) {
        dialog.setCubaId("optionDialog");
        dialog.setId(ui.getTestIdManager().getTestId("optionDialog"));
    }

    Label messageLab = new CubaLabel();
    messageLab.setWidthUndefined();
    messageLab.setValue(messages.getMainMessage("noUserSession.message", locale));

    VerticalLayout layout = new VerticalLayout();
    layout.setSpacing(true);
    layout.setWidthUndefined();
    layout.setStyleName("c-nousersession-dialog-layout");
    layout.setSpacing(true);
    dialog.setContent(layout);

    Button reloginBtn = new Button();
    if (ui.isTestMode()) {
        reloginBtn.setCubaId("reloginBtn");
        reloginBtn.setId(ui.getTestIdManager().getTestId("reloginBtn"));
    }
    reloginBtn.addStyleName(WebButton.ICON_STYLE);
    reloginBtn.addStyleName("c-primary-action");
    reloginBtn.addClickListener(event -> relogin());
    reloginBtn.setCaption(messages.getMainMessage(Type.OK.getMsgKey()));

    String iconName = AppBeans.get(Icons.class).get(Type.OK.getIconKey());
    reloginBtn.setIcon(WebComponentsHelper.getIcon(iconName));

    ClientConfig clientConfig = AppBeans.get(Configuration.class).getConfig(ClientConfig.class);
    setClickShortcut(reloginBtn, clientConfig.getCommitShortcut());

    reloginBtn.focus();

    layout.addComponent(messageLab);
    layout.addComponent(reloginBtn);

    layout.setComponentAlignment(reloginBtn, Alignment.BOTTOM_RIGHT);

    ui.addWindow(dialog);

    dialog.center();
}

From source file:com.haulmont.cuba.web.gui.components.presentations.PresentationEditor.java

License:Apache License

protected void initLayout() {
    ThemeConstants theme = App.getInstance().getThemeConstants();

    VerticalLayout root = new VerticalLayout();
    root.setWidthUndefined();
    root.setSpacing(true);/* w  ww .j av a  2  s  . c om*/
    setContent(root);

    messages = AppBeans.get(Messages.class);

    nameField = new TextField(messages.getMainMessage("PresentationsEditor.name"));
    nameField.setWidth(theme.get("cuba.web.PresentationEditor.name.width"));
    nameField.setValue(getPresentationCaption());
    root.addComponent(nameField);

    autoSaveField = new CheckBox();
    autoSaveField.setCaption(messages.getMainMessage("PresentationsEditor.autoSave"));
    autoSaveField.setValue(BooleanUtils.isTrue(presentation.getAutoSave()));
    root.addComponent(autoSaveField);

    defaultField = new CheckBox();
    defaultField.setCaption(messages.getMainMessage("PresentationsEditor.default"));
    defaultField.setValue(presentation.getId().equals(component.getDefaultPresentationId()));
    root.addComponent(defaultField);

    if (allowGlobalPresentations) {
        globalField = new CheckBox();
        globalField.setCaption(messages.getMainMessage("PresentationsEditor.global"));
        globalField.setValue(!isNew && presentation.getUser() == null);
        root.addComponent(globalField);
    }

    HorizontalLayout buttons = new HorizontalLayout();
    buttons.setSpacing(true);
    buttons.setWidthUndefined();
    root.addComponent(buttons);
    root.setComponentAlignment(buttons, Alignment.MIDDLE_LEFT);

    Button commitButton = new CubaButton(messages.getMainMessage("PresentationsEditor.save"));
    commitButton.addClickListener(event -> {
        if (validate()) {
            commit();
            close();
        }
    });
    buttons.addComponent(commitButton);

    Button closeButton = new CubaButton(messages.getMainMessage("PresentationsEditor.close"));
    closeButton.addClickListener(event -> {
        close();
    });
    buttons.addComponent(closeButton);

    nameField.focus();
}

From source file:com.haulmont.cuba.web.gui.components.table.AbbreviatedCellClickListener.java

License:Apache License

@SuppressWarnings("unchecked")
@Override/*from  ww  w.  j a v  a2  s  .  c  o  m*/
public void onClick(Entity item, String columnId) {
    Table.Column column = table.getColumn(columnId);
    MetaProperty metaProperty;
    String value;
    if (DynamicAttributesUtils.isDynamicAttribute(columnId)) {
        metaProperty = dynamicAttributesTools.getMetaPropertyPath(item.getMetaClass(), columnId)
                .getMetaProperty();
        value = dynamicAttributesTools.getDynamicAttributeValueAsString(metaProperty,
                item.getValueEx(columnId));
    } else {
        value = item.getValueEx(columnId);
    }
    if (column.getMaxTextLength() != null) {
        boolean isMultiLineCell = StringUtils.contains(value, "\n");
        if (value == null
                || (value.length() <= column.getMaxTextLength() + MAX_TEXT_LENGTH_GAP && !isMultiLineCell)) {
            // todo artamonov if we click with CTRL and Table is multiselect then we lose previous selected items
            //noinspection SuspiciousMethodCalls
            if (!table.getSelected().contains(item)) {
                table.setSelected(item);
            }
            // do not show popup view
            return;
        }
    }

    VerticalLayout layout = new VerticalLayout();
    layout.setMargin(false);
    layout.setSpacing(false);
    layout.setWidthUndefined();
    layout.setStyleName("c-table-view-textcut");

    CubaTextArea textArea = new CubaTextArea();
    textArea.setValue(Strings.nullToEmpty(value));
    textArea.setReadOnly(true);

    CubaResizableTextAreaWrapper content = new CubaResizableTextAreaWrapper(textArea);
    content.setResizableDirection(ResizeDirection.BOTH);

    // todo implement injection for ThemeConstains in components
    ThemeConstants theme = App.getInstance().getThemeConstants();
    if (theme != null) {
        content.setWidth(theme.get("cuba.web.Table.abbreviatedPopupWidth"));
        content.setHeight(theme.get("cuba.web.Table.abbreviatedPopupHeight"));
    } else {
        content.setWidth("320px");
        content.setHeight("200px");
    }

    layout.addComponent(content);

    CubaEnhancedTable enhancedTable = table.unwrap(CubaEnhancedTable.class);
    enhancedTable.showCustomPopup(layout);
    enhancedTable.setCustomPopupAutoClose(false);
}

From source file:com.haulmont.cuba.web.gui.components.table.WebTableFieldFactory.java

License:Apache License

protected Component getComponentImplementation(com.haulmont.cuba.gui.components.Component columnComponent) {
    com.vaadin.ui.Component composition = columnComponent.unwrapComposition(com.vaadin.ui.Component.class);
    Component componentImpl = composition;
    if (composition instanceof com.vaadin.v7.ui.Field && ((com.vaadin.v7.ui.Field) composition).isRequired()) {
        VerticalLayout layout = new VerticalLayout(); // vaadin8 replace with CssLayout
        layout.setMargin(false);/*  w  w w  . j  a v  a  2 s.c  om*/
        layout.setSpacing(false);
        layout.addComponent(composition);

        if (composition.getWidth() < 0) {
            layout.setWidthUndefined();
        }

        componentImpl = layout;
    }
    return componentImpl;
}

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 ww.  ja va2  s  . co 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);
    }/*from   w  ww. j  a v  a 2s . c  om*/

    if (customContextMenu.getComponentCount() > 0) {
        component.showCustomPopup(customContextMenu);
        component.setCustomPopupAutoClose(true);
    }
}

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 w w  w. j a va 2  s . c  om*/

    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();/*w w w . j a  va  2 s  .  c  o  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.swifta.mats.web.usermanagement.AddUserModule.java

public VerticalLayout getAddUserForm() {

    VerticalLayout addUserContainer = new VerticalLayout();
    addUserContainer.setWidthUndefined();
    addUserContainer.setWidthUndefined();
    addUserContainer.setMargin(new MarginInfo(false, true, true, true));
    addUserContainer.setStyleName("c_add_user");
    addUserContainer.addComponent(getNewUserContainer());

    return addUserContainer;
}

From source file:fi.jasoft.dragdroplayouts.demo.views.DragdropDragGrabFilterDemo.java

License:Apache License

private Panel createCompositeChild(String caption) {
    Panel compositePanel = new Panel();
    compositePanel.setWidthUndefined();//w  w w  .ja  v a 2 s  .co m
    compositePanel.setCaption("Composite Widget " + caption);

    VerticalLayout content = new VerticalLayout();
    content.setWidthUndefined();
    compositePanel.setContent(content);

    content.addComponent(new Label("Grab me to drag Panel"));
    content.addComponent(new Button("Cannot be grabbed"));
    content.addComponent(new TextField("Cannot be grabbed TextField"));
    content.addComponent(new Label("Grab me too!"));

    for (int i = 0; i < content.getComponentCount(); i++) {
        content.getComponent(i).setWidth(100, Unit.PERCENTAGE);
    }

    return compositePanel;
}