Example usage for com.vaadin.ui Button setIcon

List of usage examples for com.vaadin.ui Button setIcon

Introduction

In this page you can find the example usage for com.vaadin.ui Button setIcon.

Prototype

@Override
public void setIcon(Resource icon) 

Source Link

Document

Sets the component's icon.

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);/*w ww.j a v  a  2  s . co m*/
    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.WebComponentsHelper.java

License:Apache License

public static Button createButton(String icon) {
    ComponentsFactory cf = AppBeans.get(ComponentsFactory.NAME);
    com.haulmont.cuba.gui.components.Button button = cf
            .createComponent(com.haulmont.cuba.gui.components.Button.class);
    button.setIcon(icon);
    return (Button) unwrap(button);
}

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  v a2  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();/*from   w w  w. j  av  a 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.hris.payroll.thirteenthmonth.ThirteenthMonth.java

private Button generate13thMonth() {
    Button button = new Button("13th MONTH");
    button.setWidth("200px");
    button.setIcon(FontAwesome.SPINNER);
    button.addStyleName(ValoTheme.BUTTON_PRIMARY);
    button.addStyleName(ValoTheme.BUTTON_SMALL);
    button.addClickListener((Button.ClickEvent event) -> {
        status.setValue(" Loading...");
        current = 1.0;//from   w w w  .  j  a  v a2  s  .  c  o  m
        dataSize = es.findEmployeeByBranch(getBranchId(), employmentStatus.getValue().toString(),
                CommonUtil.convertStringToInteger(year.getValue().toString())).size();

        populateDataGrid();
    });

    return button;
}

From source file:com.hybridbpm.ui.component.adaptive.AdaptiveTaskEditor.java

License:Apache License

@Override
public void buttonClick(Button.ClickEvent event) {
    if (event.getButton().equals(btnSend)) {
    } else if (event.getButton().equals(btnProcess)) {
        adaptiveLayout.setVisible(false);
        templateLayout.removeAllComponents();
        templateLayout.setVisible(true);
        for (StartProcess startProcess : HybridbpmUI.getBpmAPI().getMyProcessToStart()) {
            String startTaskTitle = startProcess.getProcessModel()
                    .getTaskModelByName(startProcess.getTaskName()).getTitle();
            String processTitle = startProcess.getProcessModel().getTitle()
                    .getValue(HybridbpmUI.getCurrent().getLocale());
            Button button = new Button(processTitle + " (" + startTaskTitle + ")");
            button.setData(startProcess);
            button.addClickListener(this);
            button.setStyleName(ValoTheme.BUTTON_LINK);
            button.addStyleName(ValoTheme.BUTTON_SMALL);
            button.setIcon(FontAwesome.valueOf(startProcess.getIcon()));
            templateLayout.addComponent(button);
        }//from   w w  w.j  a va  2  s  . c om
        templateLayout.addComponent(btnBack);
        templateLayout.setComponentAlignment(btnBack, Alignment.BOTTOM_RIGHT);
    } else if (event.getButton().getData() instanceof StartProcess) {
        StartProcess spd = (StartProcess) event.getButton().getData();
        if (taskLayout != null && card.getComponentIndex(taskLayout) > -1) {
            card.removeComponent(taskLayout);
        }
        taskLayout = new TaskLayout(null, spd.getProcessModel().getName(), spd.getTaskName(), true);
        card.addComponents(taskLayout);
        card.setExpandRatio(taskLayout, 1f);
        card.setSizeFull();
        topLayout.setVisible(false);
        //            panelView.toggleMaximized(this, true);
    } else if (event.getButton().equals(btnBack)) {
        adaptiveLayout.setVisible(true);
        templateLayout.setVisible(false);
    }
}

From source file:com.hybridbpm.ui.component.bpm.StartProcessColumnGenerator.java

License:Apache License

@Override
public Object generateCell(Table source, Object itemId, Object columnId) {
    StartProcess spd = (StartProcess) itemId;
    Button button = new Button(spd.getProcessModel().getTitle().getValue(HybridbpmUI.getCurrent().getLocale()),
            clickListener);/*from   ww w  . j av a 2  s . com*/
    button.setData(spd);
    button.addStyleName(ValoTheme.BUTTON_LINK);
    button.setIcon(FontAwesome.valueOf(spd.getIcon()));
    button.setDescription("Start case");
    return button;
}

From source file:com.jain.addon.action.ActionButtonGroup.java

License:Apache License

private void findNAddIcon(JNAction action, Button actionButton) {
    if (StringHelper.isNotEmptyWithTrim(action.icon())) {
        String iconPath = PropertyReader.instance().getProperty(action.icon());

        if (StringHelper.isNotEmptyWithTrim(iconPath)) {
            ThemeResource icon = new ThemeResource(iconPath);
            actionButton.setIcon(icon);
        }//from   w  ww  . j  a  v a2 s.c  o  m
    }
}

From source file:com.klwork.explorer.ui.business.organization.GroupMenuBar.java

License:Apache License

protected void initActions() {
    Button newCaseButton = new Button();
    newCaseButton.setCaption(i18nManager.getMessage(Messages.EXPAND_MENU_INVITE));
    //WW_TODO Fix
    newCaseButton.setIcon(Images.TASK_16);
    addButton(newCaseButton);// w w w . j  a  va 2s  .c  o  m

    newCaseButton.addClickListener(new ClickListener() {
        public void buttonClick(ClickEvent event) {

        }
    });
}

From source file:com.klwork.explorer.ui.business.outproject.OutProjectManagerMenuBar.java

License:Apache License

protected void initActions() {
    Button newCaseButton = new Button();
    newCaseButton.setCaption(i18nManager.getMessage(Messages.EXPAND_MENU_INVITE));
    // WW_TODO Fix
    newCaseButton.setIcon(Images.TASK_16);
    addButton(newCaseButton);/*w  w w  .  j a  v  a2 s . c om*/

    newCaseButton.addClickListener(new ClickListener() {
        public void buttonClick(ClickEvent event) {

        }
    });
}