Example usage for com.vaadin.ui Button focus

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

Introduction

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

Prototype

@Override
    public void focus() 

Source Link

Usage

From source file:org.apache.ace.webui.vaadin.component.ConfirmationDialog.java

License:Apache License

/**
 * Adds all components to this dialog.//from ww  w  . j ava2s .  c  o  m
 * 
 * @param message
 *            the optional message to display, can be <code>null</code>;
 * @param buttonNames
 *            the names of the buttons to add, never <code>null</code> or empty.
 */
protected void addComponents(String message, String defaultButton, String... buttonNames) {
    if (message != null) {
        addComponent(new Label(message));
    }

    GridLayout gl = new GridLayout(buttonNames.length + 1, 1);
    gl.setSpacing(true);
    gl.setWidth("100%");

    gl.addComponent(new Label(" "));
    gl.setColumnExpandRatio(0, 1.0f);

    for (String buttonName : buttonNames) {
        Button button = new Button(buttonName, this);
        button.setData(buttonName);
        if (defaultButton != null && defaultButton.equals(buttonName)) {
            button.setStyleName(Reindeer.BUTTON_DEFAULT);
            button.setClickShortcut(KeyCode.ENTER);
            // Request focus in this window...
            button.focus();
        }
        gl.addComponent(button);
    }

    addComponent(gl);
}

From source file:org.jumpmind.vaadin.ui.common.ConfirmDialog.java

License:Open Source License

public ConfirmDialog(String caption, String text, final IConfirmListener confirmListener) {
    setCaption(caption);/*from  w w w  . j  a v a  2s . c  o  m*/
    setModal(true);
    setResizable(true);
    setWidth(300, Unit.PIXELS);
    setHeight(200, Unit.PIXELS);
    setClosable(false);

    VerticalLayout layout = new VerticalLayout();
    layout.setSizeFull();
    layout.setSpacing(true);
    layout.setMargin(true);
    setContent(layout);

    if (isNotBlank(text)) {
        Label textLabel = new Label(text);
        layout.addComponent(textLabel);
        layout.setExpandRatio(textLabel, 1);
    }

    HorizontalLayout buttonLayout = new HorizontalLayout();
    buttonLayout.setStyleName(ValoTheme.WINDOW_BOTTOM_TOOLBAR);
    buttonLayout.setSpacing(true);
    buttonLayout.setWidth(100, Unit.PERCENTAGE);

    Label spacer = new Label(" ");
    buttonLayout.addComponent(spacer);
    buttonLayout.setExpandRatio(spacer, 1);

    Button cancelButton = new Button("Cancel");
    cancelButton.setClickShortcut(KeyCode.ESCAPE);
    cancelButton.addClickListener(new ClickListener() {
        private static final long serialVersionUID = 1L;

        @Override
        public void buttonClick(ClickEvent event) {
            UI.getCurrent().removeWindow(ConfirmDialog.this);
        }
    });
    buttonLayout.addComponent(cancelButton);

    Button okButton = new Button("Ok");
    okButton.setStyleName(ValoTheme.BUTTON_PRIMARY);
    okButton.setClickShortcut(KeyCode.ENTER);
    okButton.addClickListener(new ClickListener() {
        private static final long serialVersionUID = 1L;

        @Override
        public void buttonClick(ClickEvent event) {
            if (confirmListener.onOk()) {
                UI.getCurrent().removeWindow(ConfirmDialog.this);
            }
        }
    });
    buttonLayout.addComponent(okButton);

    layout.addComponent(buttonLayout);

    okButton.focus();

}

From source file:org.jumpmind.vaadin.ui.common.ResizableWindow.java

License:Open Source License

protected Button buildCloseButton() {
    Button closeButton = new Button("Close");
    closeButton.addStyleName(ValoTheme.BUTTON_PRIMARY);
    closeButton.addClickListener(new CloseButtonListener());
    closeButton.focus();
    return closeButton;
}

From source file:org.processbase.ui.core.template.DefaultConfirmDialogFactory.java

License:Open Source License

public ConfirmDialog create(final String caption, final String message, final String okCaption,
        final String cancelCaption) {

    // Create a confirm dialog
    final ConfirmDialog confirm = new ConfirmDialog();
    confirm.setCaption(caption != null ? caption : DEFAULT_CAPTION);

    // Close listener implementation
    confirm.addListener(new Window.CloseListener() {

        private static final long serialVersionUID = 1971800928047045825L;

        public void windowClose(CloseEvent ce) {
            confirm.setConfirmed(false);
            if (confirm.getListener() != null) {
                confirm.getListener().onClose(confirm);
            }//from  w w w . ja  va 2 s.  c om
        }
    });

    // Create content
    VerticalLayout c = (VerticalLayout) confirm.getContent();
    c.setSizeFull();
    c.setSpacing(true);

    // Panel for scrolling lengthty messages.
    Panel scroll = new Panel(new VerticalLayout());
    scroll.setScrollable(true);
    c.addComponent(scroll);
    scroll.setWidth("100%");
    scroll.setHeight("100%");
    scroll.setStyleName(Reindeer.PANEL_LIGHT);
    c.setExpandRatio(scroll, 1f);

    // Always HTML, but escape
    Label text = new Label("", Label.CONTENT_RAW);
    scroll.addComponent(text);
    confirm.setMessageLabel(text);
    confirm.setMessage(message);

    HorizontalLayout buttons = new HorizontalLayout();
    c.addComponent(buttons);
    buttons.setSpacing(true);

    buttons.setHeight(format(BUTTON_HEIGHT) + "em");
    buttons.setWidth("100%");
    Label spacer = new Label("");
    buttons.addComponent(spacer);
    spacer.setWidth("100%");
    buttons.setExpandRatio(spacer, 1f);

    final Button cancel = new Button(cancelCaption != null ? cancelCaption : DEFAULT_CANCEL_CAPTION);
    cancel.setData(false);
    cancel.setClickShortcut(KeyCode.ESCAPE, null);
    buttons.addComponent(cancel);
    buttons.setComponentAlignment(cancel, Alignment.MIDDLE_RIGHT);
    confirm.setCancelButton(cancel);

    final Button ok = new Button(okCaption != null ? okCaption : DEFAULT_OK_CAPTION);
    ok.setData(true);
    ok.setClickShortcut(KeyCode.ENTER, null);
    ok.setStyleName(Reindeer.BUTTON_DEFAULT);
    ok.focus();
    buttons.addComponent(ok);
    buttons.setComponentAlignment(ok, Alignment.MIDDLE_RIGHT);
    confirm.setOkButton(ok);

    // Create a listener for buttons
    Button.ClickListener cb = new Button.ClickListener() {
        private static final long serialVersionUID = 3525060915814334881L;

        public void buttonClick(ClickEvent event) {
            // Copy the button date to window for passing through either
            // "OK" or "CANCEL"
            confirm.setConfirmed(event.getButton() == ok);

            // This has to be invoked as the window.close
            // event is not fired when removed.
            if (confirm.getListener() != null) {
                confirm.getListener().onClose(confirm);
            }
            confirm.close();

        }

    };
    cancel.addListener(cb);
    ok.addListener(cb);

    // Approximate the size of the dialog
    double[] dim = getDialogDimensions(message, ConfirmDialog.CONTENT_TEXT_WITH_NEWLINES);
    confirm.setWidth(format(dim[0]) + "em");
    confirm.setHeight(format(dim[1]) + "em");
    confirm.setResizable(false);

    return confirm;
}

From source file:org.processbase.ui.servlet.MainWindow.java

License:Open Source License

void openLogoutWindow() {
    Window logout = new Window(((PbApplication) getApplication()).getPbMessages().getString("btnLogout"));
    logout.setModal(true);/*  w w  w.ja  va  2  s . c o  m*/
    //        logout.setStyleName(Reindeer.WINDOW_BLACK);
    logout.setWidth("260px");
    logout.setResizable(false);
    logout.setClosable(false);
    logout.setDraggable(false);
    logout.setCloseShortcut(KeyCode.ESCAPE, null);

    Label helpText = new Label("Are you sure you want to log out?", Label.CONTENT_XHTML);
    logout.addComponent(helpText);

    HorizontalLayout buttons = new HorizontalLayout();
    buttons.setSpacing(true);
    Button yes = new Button(((PbApplication) getApplication()).getPbMessages().getString("btnLogout"),
            new Button.ClickListener() {

                public void buttonClick(ClickEvent event) {
                    WebApplicationContext applicationContext = (WebApplicationContext) getApplication()
                            .getContext();
                    getApplication().close();
                    applicationContext.getHttpSession().invalidate();
                }
            });
    yes.setStyleName(Reindeer.BUTTON_DEFAULT);
    yes.focus();
    buttons.addComponent(yes);
    Button no = new Button(((PbApplication) getApplication()).getPbMessages().getString("btnCancel"),
            new Button.ClickListener() {

                public void buttonClick(ClickEvent event) {
                    removeWindow(event.getButton().getWindow());
                }
            });
    buttons.addComponent(no);

    logout.addComponent(buttons);
    ((VerticalLayout) logout.getContent()).setComponentAlignment(buttons, Alignment.MIDDLE_CENTER);
    ((VerticalLayout) logout.getContent()).setSpacing(true);

    addWindow(logout);
}

From source file:org.vaadin.dialogs.DefaultConfirmDialogFactory.java

License:Mozilla Public License

public ConfirmDialog create(final String caption, final String message, final String okCaption,
        final String cancelCaption) {

    // Create a confirm dialog
    final ConfirmDialog confirm = new ConfirmDialog();
    confirm.setCaption(caption != null ? caption : DEFAULT_CAPTION);

    // Close listener implementation
    confirm.addListener(new Window.CloseListener() {

        private static final long serialVersionUID = 1971800928047045825L;

        public void windowClose(CloseEvent ce) {

            // Only process if still enabled
            if (confirm.isEnabled()) {
                confirm.setEnabled(false); // avoid double processing
                confirm.setConfirmed(false);
                if (confirm.getListener() != null) {
                    confirm.getListener().onClose(confirm);
                }//from   w ww.  java2 s .c om
            }
        }
    });

    // Create content
    VerticalLayout c = (VerticalLayout) confirm.getContent();
    c.setSizeFull();
    c.setSpacing(true);

    // Panel for scrolling lengthty messages.
    Panel scroll = new Panel(new VerticalLayout());
    scroll.setScrollable(true);
    c.addComponent(scroll);
    scroll.setWidth("100%");
    scroll.setHeight("100%");
    scroll.setStyleName(Reindeer.PANEL_LIGHT);
    c.setExpandRatio(scroll, 1f);

    // Always HTML, but escape
    Label text = new Label("", Label.CONTENT_RAW);
    scroll.addComponent(text);
    confirm.setMessageLabel(text);
    confirm.setMessage(message);

    HorizontalLayout buttons = new HorizontalLayout();
    c.addComponent(buttons);
    buttons.setSpacing(true);

    buttons.setHeight(format(BUTTON_HEIGHT) + "em");
    buttons.setWidth("100%");
    Label spacerLeft = new Label("");
    buttons.addComponent(spacerLeft);
    spacerLeft.setWidth("100%");
    buttons.setExpandRatio(spacerLeft, 1f);

    final Button cancel = new Button(cancelCaption != null ? cancelCaption : DEFAULT_CANCEL_CAPTION);
    cancel.setData(false);
    cancel.setClickShortcut(KeyCode.ESCAPE, null);
    buttons.addComponent(cancel);

    confirm.setCancelButton(cancel);

    final Button ok = new Button(okCaption != null ? okCaption : DEFAULT_OK_CAPTION);
    ok.setData(true);
    ok.setClickShortcut(KeyCode.ENTER, null);
    ok.focus();
    buttons.addComponent(ok);
    confirm.setOkButton(ok);

    Label spacerRight = new Label("");
    buttons.addComponent(spacerRight);
    spacerRight.setWidth("100%");
    buttons.setExpandRatio(spacerRight, 1f);
    // Create a listener for buttons
    Button.ClickListener cb = new Button.ClickListener() {
        private static final long serialVersionUID = 3525060915814334881L;

        public void buttonClick(ClickEvent event) {
            // Copy the button date to window for passing through either
            // "OK" or "CANCEL". Only process id still enabled.
            if (confirm.isEnabled()) {
                confirm.setEnabled(false); // Avoid double processing

                confirm.setConfirmed(event.getButton() == ok);

                // We need to cast this way, because of the backward
                // compatibility issue in 6.4 series.
                Component parent = confirm.getParent();
                if (parent instanceof Window) {
                    try {
                        Method m = Window.class.getDeclaredMethod("removeWindow", Window.class);
                        m.invoke(parent, confirm);
                    } catch (Exception e) {
                        throw new RuntimeException(
                                "Failed to remove confirmation dialog from the parent window.", e);
                    }
                }

                // This has to be invoked as the window.close
                // event is not fired when removed.
                if (confirm.getListener() != null) {
                    confirm.getListener().onClose(confirm);
                }
            }

        }

    };
    cancel.addListener(cb);
    ok.addListener(cb);

    // Approximate the size of the dialog
    double[] dim = getDialogDimensions(message, ConfirmDialog.CONTENT_TEXT_WITH_NEWLINES);
    confirm.setWidth(format(dim[0]) + "em");
    confirm.setHeight(format(dim[1]) + "em");
    confirm.setResizable(false);

    return confirm;
}

From source file:org.vaadin.spring.samples.security.ui.login.views.LoginView.java

License:Apache License

private Component buildFields() {
    HorizontalLayout fields = new HorizontalLayout();
    fields.setSpacing(true);/* w ww. j  a  v  a2 s .  c  om*/
    fields.addStyleName("fields");

    username = new TextField("Username");
    username.setIcon(FontAwesome.USER);
    username.addStyleName(ValoTheme.TEXTFIELD_INLINE_ICON);

    password = new PasswordField("Password");
    password.setIcon(FontAwesome.LOCK);
    password.addStyleName(ValoTheme.TEXTFIELD_INLINE_ICON);

    final Button signin = new Button("Sign In");
    signin.addStyleName(ValoTheme.BUTTON_PRIMARY);
    signin.setClickShortcut(KeyCode.ENTER);
    signin.focus();

    fields.addComponents(username, password, signin);
    fields.setComponentAlignment(signin, Alignment.BOTTOM_LEFT);

    signin.addClickListener(new ClickListener() {

        private static final long serialVersionUID = 1L;

        @Override
        public void buttonClick(final ClickEvent event) {

            try {

                security.login(username.getValue(), password.getValue());

            } catch (AuthenticationException e) {
                e.printStackTrace();
            } catch (Exception e) {
                e.printStackTrace();
            }
            // TODO Register Remember me Token

            /*
             * Redirect is handled by the VaadinRedirectStrategy
             * User is redirected to either always the default
             * or the URL the user request before authentication
             * 
             * Strategy is configured within SecurityConfiguration
             * Defaults to User request URL.
             */
        }
    });

    return fields;
}

From source file:ru.codeinside.gses.webui.executor.ExecutorFactory.java

License:Mozilla Public License

static void showTask(final Changer changer, final Task task, final ProcessDefinitionEntity def) {
    final VerticalLayout layout = new VerticalLayout();
    layout.setMargin(true);/*from  w ww. j  a  v a 2 s .c om*/
    layout.setSpacing(true);
    layout.setSizeFull();
    final Button cancel = new Button("?", new Button.ClickListener() {
        private static final long serialVersionUID = 1L;

        @Override
        public void buttonClick(ClickEvent event) {
            changer.back();
        }
    });
    cancel.setClickShortcut(KeyCode.ESCAPE, 0);
    layout.addComponent(cancel);

    HorizontalLayout hl = new HorizontalLayout();
    hl.setSizeFull();
    hl.setSpacing(true);
    layout.addComponent(hl);
    layout.setExpandRatio(cancel, 0.01f);
    layout.setExpandRatio(hl, 0.99f);

    VerticalLayout vl = new VerticalLayout();
    vl.setSizeFull();
    vl.setSpacing(true);
    hl.addComponent(vl);

    final String procedureName = Flash.flash().getExecutorService().getProcedureNameByDefinitionId(def.getId());
    vl.addComponent(new ProcedureHistoryPanel(task.getId()));

    ShowDiagramComponentParameterObject parameterObject = new ShowDiagramComponentParameterObject();
    final String procVersion = def.getVersion() + "";
    parameterObject.windowHeader = procedureName + "v. " + procVersion;
    parameterObject.width = "600px";
    parameterObject.executionId = task.getExecutionId();
    parameterObject.changer = changer;
    parameterObject.processDefinitionId = def.getId();
    parameterObject.caption = "";
    ShowDiagramComponent showDiagramComponent = new ShowDiagramComponent(parameterObject);
    hl.addComponent(showDiagramComponent);
    hl.setExpandRatio(vl, 0.5f);
    hl.setExpandRatio(showDiagramComponent, 0.5f);

    changer.change(layout);
    cancel.focus();
}