Example usage for com.vaadin.ui Button setStyleName

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

Introduction

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

Prototype

@Override
    public void setStyleName(String style) 

Source Link

Usage

From source file:com.foc.vaadin.gui.components.FVBlobDisplay.java

License:Apache License

public void displayPDFFile() {
    BlobResource blobResource = getBlobResource();
    if (blobResource != null) {
        String fileName = blobResource.getFilename();
        if (fileName != null) {
            String mimeType = blobResource.getMIMEType();

            StreamSource streamSource = new StreamSource() {
                private DownloadStream downloadStream = getBlobResource() != null
                        ? getBlobResource().getStream()
                        : null;//from w  w  w.jav a  2s . co m

                @Override
                public InputStream getStream() {

                    return downloadStream != null ? downloadStream.getStream() : null;
                }
            };
            String viewButtonCaption = "View "
                    + fileName.substring(fileName.lastIndexOf(".") + 1, fileName.length()) + " File";
            Button viewDocButton = new Button(viewButtonCaption);
            viewDocButton.setStyleName(Reindeer.BUTTON_LINK);
            if (streamSource != null) {
                StreamResource streamResource = new StreamResource(streamSource, fileName);
                streamResource.setMIMEType(mimeType);

                BrowserWindowOpener opener = new BrowserWindowOpener(streamResource);
                opener.extend(viewDocButton);
                settingsLayout.addComponent(viewDocButton);
                Resource resource = FVIconFactory.getInstance().getFVIcon(FVIconFactory.ICON_NOTE);
                Image image = new Image();
                image.setSource(resource);
                addComponent(image);
            }
        }
    }
}

From source file:com.foc.vaadin.gui.components.tableAndTree.FVColGen_FocProperty.java

License:Apache License

private Object getDisplayObject_ForProperty_Editable(FocObject focObject, FProperty property,
        FVTableColumn column, Object columnId) {
    Object objReturned = null;/*from ww  w . ja  v  a 2 s.  c  o m*/

    FField field = property != null ? property.getFocField() : null;

    if (field instanceof FImageField) {
        objReturned = (AbstractComponent) getTableTreeDelegate().newGuiComponent(focObject, column, property);
        FVImageField imageField = (FVImageField) objReturned;
        imageField.setWidth("60px");
        imageField.setHeight("50px");
    } else if (field instanceof FCloudStorageField) {
        FCloudStorageProperty csProp = (FCloudStorageProperty) property;
        if (csProp != null) {
            FVImageField imageField = new FVImageField(csProp, column.getAttributes());
            if (imageField.getBufferedImage() == null) {
                Resource resource = imageField.getResourceAndSetIcon();
                if (resource != null) {
                    Button docIcon = new Button();
                    docIcon.setStyleName(Runo.BUTTON_LINK);
                    docIcon.setWidth("-1px");
                    docIcon.setHeight("-1px");
                    docIcon.setIcon(resource);
                    objReturned = docIcon;
                }
            } else {
                Image image = imageField.getEmbedded();
                if (image != null) {
                    int maxWidth = 150;
                    int maxHeight = 150;
                    imageField.resizeImage(image, maxWidth, maxHeight);
                }
                objReturned = imageField;
            }
        }
    } else {
        objReturned = "";
        if (property != null) {
            AbstractComponent abstractComponent = (AbstractComponent) getTableTreeDelegate()
                    .newGuiComponent(focObject, column, property);

            if (abstractComponent != null) {
                objReturned = abstractComponent;
                abstractComponent.addStyleName("editableStyle");

                if (abstractComponent instanceof FVTextField) {
                    // ((FVTextField) abstractComponent).selectAll();
                    /*
                     * ((FVTextField) abstractComponent).addFocusListener(new
                     * FocusListener() { private boolean updating = false; public void
                     * focus(FocusEvent event) { if(!updating){ updating = true;
                     * ((FVTextField) abstractComponent).selectAll(); updating = false;
                     * } } });
                     */
                    // Adding the focus listener on the component to be used in the
                    // formula layout
                    if (getFormulaFocusListener() != null) {
                        ((FVTextField) abstractComponent).addFocusListener(getFormulaFocusListener());
                    }
                    if (isUseReadOnlyFlag()) {
                        ((FVTextField) abstractComponent).addFocusListener(getReadOnlyFocusListener(true));
                        ((FVTextField) abstractComponent).addBlurListener(getReadOnlyBlurListener(true));
                    }
                } else if (abstractComponent instanceof FVCheckBox) {
                    abstractComponent.setCaption("");
                } else if (abstractComponent instanceof FVComboBox) {
                    // Adding the focus listener on the component to be used in the
                    // formula layout
                    if (getFormulaFocusListener() != null) {
                        ((FVComboBox) abstractComponent).addFocusListener(getFormulaFocusListener());
                    }
                    if (isUseReadOnlyFlag()) {
                        ((FVComboBox) abstractComponent).addFocusListener(getReadOnlyFocusListener(true));
                        ((FVComboBox) abstractComponent).addBlurListener(getReadOnlyBlurListener(true));
                    }

                } else if (abstractComponent instanceof FVObjectPopupView) {
                    // Adding the focus listener on the component to be used in the
                    // formula layout
                    FVObjectPopupView popupView = ((FVObjectPopupView) abstractComponent);
                    if (popupView != null && getFormulaFocusListener() != null) {
                        popupView.addPopupVisibilityListener(new PopupVisibilityListener() {

                            @Override
                            public void popupVisibilityChange(PopupVisibilityEvent event) {
                                if (getTableTreeDelegate() != null && event != null
                                        && event.getPopupView() != null
                                        && event.getPopupView() instanceof FVObjectPopupView) {
                                    FVObjectPopupView popupView = (FVObjectPopupView) event.getPopupView();
                                    getTableTreeDelegate().adjustFormulaLayoutForComponent(popupView);
                                }
                            }
                        });
                        //                     popupView.addFocusListener(getFormulaFocusListener());
                    }
                    //                  if(isUseReadOnlyFlag()){
                    //                     popupView.addFocusListener(getReadOnlyFocusListener(true));
                    //                     popupView.addBlurListener(getReadOnlyBlurListener(true));
                    //                  }
                } else if (abstractComponent instanceof FVObjectSelector) {
                    // Adding the focus listener on the component to be used in the
                    // formula layout
                    FVObjectComboBox comboBox = ((FVObjectSelector) abstractComponent).getComboBox();
                    if (comboBox != null && getFormulaFocusListener() != null) {
                        comboBox.addFocusListener(getFormulaFocusListener());
                    }
                    if (isUseReadOnlyFlag()) {
                        comboBox.addFocusListener(getReadOnlyFocusListener(true));
                        comboBox.addBlurListener(getReadOnlyBlurListener(true));
                    }
                } else if (abstractComponent instanceof FVObjectComboBox && getFormulaFocusListener() != null) {
                    FVObjectComboBox comboBox = (FVObjectComboBox) abstractComponent;
                    if (comboBox != null) {
                        comboBox.addFocusListener(getFormulaFocusListener());
                    }
                    if (isUseReadOnlyFlag()) {
                        comboBox.addFocusListener(getReadOnlyFocusListener(true));
                        comboBox.addBlurListener(getReadOnlyBlurListener(true));
                    }
                } else if (abstractComponent instanceof FVMultipleChoiceComboBox
                        && getFormulaFocusListener() != null) {
                    FVMultipleChoiceComboBox comboBox = (FVMultipleChoiceComboBox) abstractComponent;
                    if (comboBox != null) {
                        comboBox.addFocusListener(getFormulaFocusListener());
                    }
                    if (isUseReadOnlyFlag()) {
                        comboBox.addFocusListener(getReadOnlyFocusListener(true));
                        comboBox.addBlurListener(getReadOnlyBlurListener(true));
                    }
                }
                // Setting the column and row Ids of component
                FocXMLGuiComponent focXMLGuiComponent = (FocXMLGuiComponent) abstractComponent;
                FocXMLGuiComponentDelegate focXMLGuiComponentDelegate = focXMLGuiComponent.getDelegate();
                if (focXMLGuiComponentDelegate != null) {
                    focXMLGuiComponentDelegate.setColumnId(columnId);
                    if (focObject != null && focObject.getReference() != null) {
                        focXMLGuiComponentDelegate.setRowId(focObject.getReference().getLong());
                    }
                }
                abstractComponent.setId(column.getDataPath());
                abstractComponent.setWidth("100%");// This was added to get the node
                                                   // name text field in the BKDN
                                                   // tree big enough to enter or see
                                                   // the value
                                                   // If we put 100% in the xml we get a small width extendable. but with
                                                   // this solution we have a fixed minimum width in the xml + the 100%
                                                   // allows us to change the width
                if (isUseReadOnlyFlag()) {
                    abstractComponent.setReadOnly(true);
                }
            }
        }
    }

    if (property != null && property.isInherited()) {
        FProperty inheritedProp = null;
        try {
            inheritedProp = property.getFocField().getInheritedPropertyGetter()
                    .getInheritedProperty(property.getFocObject(), property);
        } catch (Exception e) {
            Globals.logException(e);
        }
        if (inheritedProp != null) {
            objReturned = inheritedProp;
        }
    }
    return objReturned;
}

From source file:com.foc.vaadin.gui.components.tableAndTree.FVColGen_FocProperty.java

License:Apache License

private Object getDisplayObject_ForProperty_NonEditable(FocObject focObject, FProperty property,
        FVTableColumn column, Object columnId) {
    Object objReturned = null;//from w  ww  . ja  va 2s.  c o m
    FField field = property != null ? property.getFocField() : null;
    if (property != null) {
        // Remove the editable component in case the editing status has changed
        // --------------------------------------------------------------------
        String objRef = focObject != null && focObject.getReference() != null
                ? focObject.getReference().toString()
                : null;
        String compName = TableTreeDelegate.newComponentName(getTableName(), objRef, (String) column.getName());
        FocXMLLayout focXMLLayout = getFocXMLLayout();
        if (focXMLLayout != null) {
            FocXMLGuiComponent comp = focXMLLayout.removeComponentByName(compName);
            if (comp != null) {
                comp.dispose();
            }
        }
        // --------------------------------------------------------------------
        objReturned = property.vaadin_TableDisplayObject(column.getFormat(), column.getCaptionProp());

        if (objReturned instanceof Boolean) {
            if (((Boolean) objReturned).booleanValue()) {
                objReturned = new Embedded("", new ThemeResource("../runo/icons/16/ok.png"));
            } else {
                // objReturned = new Embedded("", new
                // ThemeResource("../runo/icons/16/cancel.png"));
                objReturned = FVIconFactory.getInstance().getFVIcon_Embedded(FVIconFactory.ICON_EMPTY,
                        FVIconFactory.SIZE_SMALL);
            }
        } else if (field instanceof FCloudStorageField) {
            FCloudStorageProperty csProp = (FCloudStorageProperty) property;
            if (csProp != null) {
                FVImageField imageField = new FVImageField(csProp, column.getAttributes());
                if (imageField.getBufferedImage() == null) {
                    Resource resource = imageField.getResourceAndSetIcon();
                    if (resource != null) {
                        Button docIcon = new Button();
                        docIcon.setStyleName(Runo.BUTTON_LINK);
                        docIcon.setWidth("-1px");
                        docIcon.setHeight("-1px");
                        docIcon.setIcon(resource);
                        objReturned = docIcon;
                    }
                } else {
                    Image image = imageField.getEmbedded();
                    if (image != null) {
                        int maxWidth = 150;
                        int maxHeight = 150;
                        imageField.resizeImage(image, maxWidth, maxHeight);
                    }
                    objReturned = imageField;
                }
            }
        } else if (property instanceof FObject || property instanceof FDate || property instanceof FString
                || property instanceof FDouble || property instanceof FInt
                || property instanceof FMultipleChoice) {
            if (property instanceof FMultipleChoice) {
                objReturned = property.getString();
            }
            FVLabel lbl = null;
            String styleAttrib = column.getAttributes() != null
                    ? column.getAttributes().getValue(FXML.ATT_STYLE)
                    : null;
            int maxCharacters = column.getMaxCharacters();
            String ttt = null;

            if (styleAttrib != null && !styleAttrib.isEmpty()) {
                lbl = new FVLabel((String) objReturned);
                lbl.parseStyleAttributeValue(styleAttrib);
                objReturned = lbl;
            } else if (property instanceof FDouble
                    || (property instanceof FInt && !(property instanceof FMultipleChoice))) {
                lbl = new FVLabelInTable(property, focObject, column);
                lbl.copyMemoryToGui();
                lbl.addStyleName("foc-text-right");
                objReturned = lbl;
            }

            if (property instanceof FMultipleChoice) {
                Object itemObj = ((FMultipleChoice) property).getValue();
                if (itemObj != null && itemObj instanceof FMultipleChoiceItem) {
                    FMultipleChoiceItem item = (FMultipleChoiceItem) itemObj;
                    if (lbl == null) {
                        String iconNameInFontAwesome = item != null ? item.getIconFontAwesomeName() : null;
                        if (iconNameInFontAwesome == null) {
                            lbl = new FVLabel(item.getTitle());
                            //                        lbl.setIcon(FVIconFactory.getInstance().getFVIcon_Small(path));
                        } else {
                            FontAwesome icon = FontAwesome.valueOf(iconNameInFontAwesome);
                            lbl = new FVLabel("");
                            lbl.setCaption(null);
                            lbl.setContentMode(ContentMode.HTML);
                            lbl.setValue(item.getTitle() + " " + icon.getHtml());
                        }

                        objReturned = lbl;
                    }
                }
            }

            //If RTL I have t put the String in a label to align right
            if (lbl == null && getFocXMLLayout().isRTL()) {
                lbl = new FVLabelInTable(property, focObject, column);
                lbl.copyMemoryToGui();
                lbl.addStyleName("foc-text-right");
                objReturned = lbl;
            }

            //Setting the TTT is necessary
            //We have 2 conditions: either the objReturned is String or Label.
            //----------------------------
            if (lbl != null) {
                String originalValue = lbl.getValue();
                if (maxCharacters > 0 && originalValue != null && originalValue.length() > maxCharacters) {
                    ttt = originalValue;

                    //                  lbl.setLocale();
                    if (getFocXMLLayout().isRTL()) {
                        lbl.addStyleName("foc-cellComment-left");
                        //                     lbl.setLocale(new Locale("ar"));
                        StringBuffer buff = new StringBuffer(ttt.substring(0, maxCharacters));
                        //                     buff.append("...");
                        buff.append("...");
                        lbl.setValue(buff.toString());
                    } else {
                        lbl.addStyleName("foc-cellComment-right");
                        lbl.setValue(ttt.substring(0, maxCharacters) + "...");
                    }
                }
            } else if (objReturned instanceof String) {
                String originalValue = (String) objReturned;
                if (maxCharacters > 0 && originalValue != null && originalValue.length() > maxCharacters) {
                    ttt = originalValue;
                    if (getFocXMLLayout().isRTL()) {
                        objReturned = ttt.substring(0, maxCharacters) + "...";
                    } else {
                        objReturned = ttt.substring(0, maxCharacters) + "...";
                    }
                }
            }
            if (ttt != null && getTableTreeDelegate() != null) {
                getTableTreeDelegate().addCellTooltipText(focObject.getReference(), columnId, ttt);
            }
            //----------------------------

            if (lbl != null) {
                if (getFocXMLLayout().isRTL())
                    lbl.addStyleName("foc-text-right");
                FocXMLGuiComponent focXMLGuiComponent = lbl;
                FocXMLGuiComponentDelegate componentDelegate = focXMLGuiComponent.getDelegate();
                if (componentDelegate != null) {
                    componentDelegate.setColumnId(columnId);
                    if (focObject != null && focObject.getReference() != null) {
                        componentDelegate.setRowId(focObject.getReference().getLong());
                    }
                }
            }
            if (lbl != null && getFocXMLLayout() != null)
                getFocXMLLayout().putComponent(compName, lbl);
            FocXMLAttributes attributes = column.getAttributes();
            if (attributes != null && attributes.getValue(FXML.ATT_LINK) != null
                    && attributes.getValue(FXML.ATT_LINK).equals("true")) {
                HyperLinkButton button = new HyperLinkButton(focObject, objReturned, compName);
                button.addClickListener(hyperLinkButtonListener);
                button.addStyleName("focLinkInTable");
                objReturned = button;

                //               if(getTableTreeDelegate().getViewContainer_ForOpen() == ITableTree.VIEW_CONTAINER_NEW_BROWSER_TAB){
                //                 BrowserWindowOpener opener = null; 
                //                 opener = new BrowserWindowOpener(UI.getCurrent().getClass());
                //                opener.extend(button);
                //               }
            }
        } else {
            objReturned = property;
            //            if((property instanceof FMultipleChoice)){
            //               FocXMLAttributes attributes = column.getAttributes();
            //               if(attributes != null && attributes.getValue(FXML.ATT_LINK) != null && attributes.getValue(FXML.ATT_LINK).equals("true")){
            //                  HyperLinkButton button = new HyperLinkButton(focObject, property.getString());
            //                  button.addClickListener(hyperLinkButtonListener);
            //                  button.addStyleName("focLinkInTable");
            //                  objReturned = button;
            //               }
            //            }
        }
    }
    //      if(objReturned instanceof String){
    //         objReturned = new Label(objReturned.toString());
    //      }
    return objReturned;
}

From source file:com.foc.vaadin.gui.layouts.validationLayout.FVValidationLayout.java

License:Apache License

private Button newButton(String iconName) {
    Button button = new Button("");

    if (validationSettings.getDiscardLink() != null && !validationSettings.getDiscardLink().isEmpty()) {
        button.setCaption(validationSettings.getDiscardLink());
    } else {/*from  ww w  .j  a v  a  2 s.  c  om*/
        button.setIcon(FVIconFactory.getInstance().getFVIcon_Big(iconName));
    }
    if (!Globals.isValo())
        button.setStyleName(BaseTheme.BUTTON_LINK);
    return button;
}

From source file:com.github.fbhd.view.MainView.java

private void createButtons() {
    buttonLayout = new HorizontalLayout();
    buttonLayout.setSpacing(true);//w ww . j  a  v  a 2 s  .com

    Button btnLogin = new Button("Login");
    btnLogin.setStyleName(ValoTheme.BUTTON_PRIMARY);

    btnLogin.addClickListener((Button.ClickEvent event) -> {
        doLogin();
    });

    Button btnCancel = new Button("Cancel");

    btnCancel.addClickListener((Button.ClickEvent event) -> {

    });

    buttonLayout.addComponents(btnLogin, btnCancel);
    mainLayout.addComponent(buttonLayout);
}

From source file:com.github.fbhd.view.TicketView.java

private void createButtons() {
    buttonLayout = new HorizontalLayout();
    buttonLayout.setSpacing(true);/*w w w .j a  v a 2 s  .  c  om*/

    Button btnSubmit = new Button("Submit");
    btnSubmit.setStyleName(ValoTheme.BUTTON_PRIMARY);

    btnSubmit.addClickListener((Button.ClickEvent event) -> {
        persistAndContinue(ConfirmationView.VIEW_NAME);
    });

    Button btnCancel = new Button("Cancel");

    btnCancel.addClickListener((Button.ClickEvent event) -> {

    });

    buttonLayout.addComponents(btnSubmit, btnCancel);
    mainLayout.addComponent(buttonLayout);
}

From source file:com.github.peholmst.mvp4vaadin.navigation.ui.NavigationBar.java

License:Apache License

/**
 * Creates and adds a new button to the navigation bar. Listeners etc. will
 * be added by the {@link #addBreadcrumbForView(ControllableView)} method.
 * /*from   ww  w  . j  ava2  s  .c  o  m*/
 * @param viewName
 *            the name of the view to show on the button.
 * @return the added button.
 */
protected Button addViewButton(String viewName) {
    final Button btn = new Button(viewName);
    btn.setStyleName(BaseTheme.BUTTON_LINK);
    btn.setSizeUndefined();
    btn.addStyleName(BREADCRUMB_ELEMENT);
    addComponent(btn);
    // setComponentAlignment(btn, Alignment.MIDDLE_LEFT);
    return btn;
}

From source file:com.github.peholmst.springsecuritydemo.ui.LoginView.java

License:Apache License

@SuppressWarnings("serial")
protected void init() {
    final Panel loginPanel = new Panel();
    loginPanel.setCaption(getApplication().getMessage("login.title"));
    ((VerticalLayout) loginPanel.getContent()).setSpacing(true);

    final TextField username = new TextField(getApplication().getMessage("login.username"));
    username.setWidth("100%");
    loginPanel.addComponent(username);//from www  .ja  v  a 2 s.c om

    final TextField password = new TextField(getApplication().getMessage("login.password"));
    password.setSecret(true);
    password.setWidth("100%");
    loginPanel.addComponent(password);

    final Button loginButton = new Button(getApplication().getMessage("login.button"));
    loginButton.setStyleName("primary");
    // TODO Make it possible to submit the form by pressing <Enter> in any
    // of the text fields
    loginPanel.addComponent(loginButton);
    ((VerticalLayout) loginPanel.getContent()).setComponentAlignment(loginButton, Alignment.MIDDLE_RIGHT);
    loginButton.addListener(new Button.ClickListener() {

        @Override
        public void buttonClick(ClickEvent event) {
            final Authentication auth = new UsernamePasswordAuthenticationToken(username.getValue(),
                    password.getValue());
            try {
                if (logger.isDebugEnabled()) {
                    logger.debug("Attempting authentication for user '" + auth.getName() + "'");
                }
                Authentication returned = getAuthenticationManager().authenticate(auth);
                if (logger.isDebugEnabled()) {
                    logger.debug("Authentication for user '" + auth.getName() + "' succeeded");
                }
                fireEvent(new LoginEvent(LoginView.this, returned));
            } catch (BadCredentialsException e) {
                if (logger.isDebugEnabled()) {
                    logger.debug("Bad credentials for user '" + auth.getName() + "'", e);
                }
                getWindow().showNotification(getApplication().getMessage("login.badCredentials.title"),
                        getApplication().getMessage("login.badCredentials.descr"),
                        Notification.TYPE_WARNING_MESSAGE);
            } catch (DisabledException e) {
                if (logger.isDebugEnabled()) {
                    logger.debug("Account disabled for user '" + auth.getName() + "'", e);
                }
                getWindow().showNotification(getApplication().getMessage("login.disabled.title"),
                        getApplication().getMessage("login.disabled.descr"), Notification.TYPE_WARNING_MESSAGE);
            } catch (LockedException e) {
                if (logger.isDebugEnabled()) {
                    logger.debug("Account locked for user '" + auth.getName() + "'", e);
                }
                getWindow().showNotification(getApplication().getMessage("login.locked.title"),
                        getApplication().getMessage("login.locked.descr"), Notification.TYPE_WARNING_MESSAGE);
            } catch (Exception e) {
                if (logger.isErrorEnabled()) {
                    logger.error("Error while attempting authentication for user '" + auth.getName() + "'");
                }
                ExceptionUtils.handleException(getWindow(), e);
            }
        }
    });

    HorizontalLayout languages = new HorizontalLayout();
    languages.setSpacing(true);
    final Button.ClickListener languageListener = new Button.ClickListener() {

        @Override
        public void buttonClick(ClickEvent event) {
            Locale locale = (Locale) event.getButton().getData();
            if (logger.isDebugEnabled()) {
                logger.debug("Changing locale to [" + locale + "] and restarting the application");
            }
            getApplication().setLocale(locale);
            getApplication().close();
        }
    };
    for (Locale locale : getApplication().getSupportedLocales()) {
        if (!getLocale().equals(locale)) {
            final Button languageButton = new Button(getApplication().getLocaleDisplayName(locale));
            languageButton.setStyleName(Button.STYLE_LINK);
            languageButton.setData(locale);
            languageButton.addListener(languageListener);
            languages.addComponent(languageButton);
        }
    }
    loginPanel.addComponent(languages);

    loginPanel.setWidth("300px");

    final HorizontalLayout viewLayout = new HorizontalLayout();
    viewLayout.addComponent(loginPanel);
    viewLayout.setComponentAlignment(loginPanel, Alignment.MIDDLE_CENTER);
    viewLayout.setSizeFull();
    viewLayout.setMargin(true);

    setCompositionRoot(viewLayout);
    setSizeFull();
}

From source file:com.github.peholmst.springsecuritydemo.ui.MainView.java

License:Apache License

/**
 * TODO Document me!/*from w ww  . ja v a 2  s . c o m*/
 * 
 * @return
 */
protected Component createTicketBrowser() {
    final HorizontalLayout toolbar = new HorizontalLayout();
    toolbar.setSpacing(true);
    toolbar.setWidth("100%");

    final Button refreshButton = new Button(getApplication().getMessage("tickets.refresh.caption"));
    refreshButton.setIcon(new ThemeResource("icons/16/refresh.png"));
    refreshButton.setStyleName("small");
    refreshButton.setDescription(getApplication().getMessage("tickets.refresh.descr"));
    toolbar.addComponent(refreshButton);
    toolbar.setComponentAlignment(refreshButton, Alignment.MIDDLE_LEFT);

    final Button addButton = new Button(getApplication().getMessage("tickets.add.caption"));
    addButton.setIcon(new ThemeResource("icons/16/add.png"));
    addButton.setStyleName("small");
    addButton.setDescription(getApplication().getMessage("tickets.add.descr"));
    toolbar.addComponent(addButton);
    toolbar.setComponentAlignment(addButton, Alignment.MIDDLE_RIGHT);

    final SplitPanel splitPanel = new SplitPanel();
    splitPanel.setSizeFull();

    final Table ticketsTable = new Table();
    ticketsTable.setSizeFull();
    splitPanel.addComponent(ticketsTable);

    splitPanel.addComponent(new Label("The form for editing tickets will show up here"));

    final VerticalLayout browser = new VerticalLayout();
    browser.setSizeFull();
    browser.addComponent(toolbar);
    browser.addComponent(splitPanel);
    browser.setExpandRatio(splitPanel, 1.0f);

    return browser;
}

From source file:com.github.peholmst.springsecuritydemo.ui.MainView.java

License:Apache License

/**
 * TODO Document me!/*from  w  w  w.j  a v a 2s .c  o  m*/
 * 
 * @return
 */
@SuppressWarnings("serial")
protected Component createHeader() {
    final HorizontalLayout header = new HorizontalLayout();
    header.setMargin(true);
    header.setWidth("100%");

    /*
     * Header label will contain the name and version of the application.
     */
    final Label headerLabel = new Label(
            getApplication().getMessage("app.title", getApplication().getVersion()));
    headerLabel.setStyleName("appHeaderText");
    header.addComponent(headerLabel);
    header.setStyleName("appHeader");
    header.setExpandRatio(headerLabel, 1.0f);
    header.setComponentAlignment(headerLabel, Alignment.MIDDLE_LEFT);

    /*
     * User links contains information about the current user and a button
     * for logging out.
     */
    final HorizontalLayout userLinks = new HorizontalLayout();
    userLinks.setStyleName("appHeaderUserLinks");
    userLinks.setSpacing(true);

    /*
     * The user label contains the name of the current user.
     */
    final Label userLabel = new Label(
            getApplication().getMessage("main.currentlyLoggedIn", getApplication().getUser().getName()),
            Label.CONTENT_XHTML);
    userLinks.addComponent(userLabel);
    userLinks.setComponentAlignment(userLabel, Alignment.MIDDLE_LEFT);
    userLabel.setSizeUndefined();

    /*
     * The logout button closes the application, effectively logging the
     * user out.
     */
    final Button logoutButton = new Button(getApplication().getMessage("main.logout.caption"),
            new Button.ClickListener() {

                @Override
                public void buttonClick(ClickEvent event) {
                    // TODO Add confirmation
                    getApplication().close();
                }
            });
    logoutButton.setDescription(getApplication().getMessage("main.logout.descr"));
    logoutButton.setStyleName("small");
    userLinks.addComponent(logoutButton);
    userLinks.setComponentAlignment(logoutButton, Alignment.MIDDLE_RIGHT);

    header.addComponent(userLinks);
    header.setComponentAlignment(userLinks, Alignment.MIDDLE_RIGHT);
    return header;
}