Example usage for com.vaadin.ui HorizontalLayout setExpandRatio

List of usage examples for com.vaadin.ui HorizontalLayout setExpandRatio

Introduction

In this page you can find the example usage for com.vaadin.ui HorizontalLayout setExpandRatio.

Prototype

public void setExpandRatio(Component component, float ratio) 

Source Link

Document

This method is used to control how excess space in layout is distributed among components.

Usage

From source file:info.magnolia.security.app.dialog.field.WorkspaceAccessFieldFactory.java

License:Open Source License

protected Component createRuleRow(final AbstractOrderedLayout parentContainer,
        final AbstractJcrNodeAdapter ruleItem, final Label emptyLabel) {

    final HorizontalLayout ruleLayout = new HorizontalLayout();
    ruleLayout.setSpacing(true);//from  w w  w. j a va  2 s .c  o  m
    ruleLayout.setWidth("100%");

    NativeSelect accessRights = new NativeSelect();
    accessRights.setNullSelectionAllowed(false);
    accessRights.setImmediate(true);
    accessRights.setInvalidAllowed(false);
    accessRights.setNewItemsAllowed(false);
    accessRights.addItem(Permission.ALL);
    accessRights.setItemCaption(Permission.ALL, i18n.translate("security.workspace.field.readWrite"));
    accessRights.addItem(Permission.READ);
    accessRights.setItemCaption(Permission.READ, i18n.translate("security.workspace.field.readOnly"));
    accessRights.addItem(Permission.NONE);
    accessRights.setItemCaption(Permission.NONE, i18n.translate("security.workspace.field.denyAccess"));
    accessRights.setPropertyDataSource(ruleItem.getItemProperty(AccessControlList.PERMISSIONS_PROPERTY_NAME));
    ruleLayout.addComponent(accessRights);

    NativeSelect accessType = new NativeSelect();
    accessType.setNullSelectionAllowed(false);
    accessType.setImmediate(true);
    accessType.setInvalidAllowed(false);
    accessType.setNewItemsAllowed(false);
    accessType.setWidth("150px");
    accessType.addItem(AccessControlList.ACCESS_TYPE_NODE);
    accessType.setItemCaption(AccessControlList.ACCESS_TYPE_NODE,
            i18n.translate("security.workspace.field.selected"));
    accessType.addItem(AccessControlList.ACCESS_TYPE_CHILDREN);
    accessType.setItemCaption(AccessControlList.ACCESS_TYPE_CHILDREN,
            i18n.translate("security.workspace.field.subnodes"));
    accessType.addItem(AccessControlList.ACCESS_TYPE_NODE_AND_CHILDREN);
    accessType.setItemCaption(AccessControlList.ACCESS_TYPE_NODE_AND_CHILDREN,
            i18n.translate("security.workspace.field.selectedSubnodes"));
    Property accessTypeProperty = ruleItem.getItemProperty(ACCESS_TYPE_PROPERTY_NAME);
    accessType.setPropertyDataSource(accessTypeProperty);
    ruleLayout.addComponent(accessType);

    final TextField path = new TextField();
    path.setWidth("100%");
    path.setPropertyDataSource(ruleItem.getItemProperty(AccessControlList.PATH_PROPERTY_NAME));
    ruleLayout.addComponent(path);
    ruleLayout.setExpandRatio(path, 1.0f);

    Button chooseButton = new Button(i18n.translate("security.workspace.field.choose"));
    chooseButton.addClickListener(new Button.ClickListener() {

        @Override
        public void buttonClick(Button.ClickEvent event) {
            openChooseDialog(path);
        }
    });
    ruleLayout.addComponent(chooseButton);

    Button deleteButton = new Button();
    deleteButton.setHtmlContentAllowed(true);
    deleteButton.setCaption("<span class=\"" + "icon-trash" + "\"></span>");
    deleteButton.addStyleName("inline");
    deleteButton.setDescription(i18n.translate("security.workspace.field.delete"));
    deleteButton.addClickListener(new Button.ClickListener() {

        @Override
        public void buttonClick(Button.ClickEvent event) {
            parentContainer.removeComponent(ruleLayout);
            ruleItem.getParent().removeChild(ruleItem);
            if (parentContainer.getComponentCount() == 1) {
                parentContainer.addComponent(emptyLabel, 0);
            }
        }
    });
    ruleLayout.addComponent(deleteButton);

    return ruleLayout;
}

From source file:info.magnolia.ui.form.field.MultiField.java

License:Open Source License

/**
 * Create a single element.<br>/* www . j a va 2s .  c  om*/
 * This single element is composed of:<br>
 * - a configured field <br>
 * - a remove Button<br>
 */
private Component createEntryComponent(Object propertyId, Property<?> property) {

    final HorizontalLayout layout = new HorizontalLayout();
    layout.setWidth(100, Unit.PERCENTAGE);
    layout.setHeight(-1, Unit.PIXELS);

    final Field<?> field = createLocalField(fieldDefinition, property, true); // creates property datasource if given property is null
    layout.addComponent(field);

    // bind the field's property to the item
    if (property == null) {
        property = field.getPropertyDataSource();
        ((PropertysetItem) getPropertyDataSource().getValue()).addItemProperty(propertyId, property);
    }
    final Property<?> propertyReference = property;
    // set layout to full width
    layout.setWidth(100, Unit.PERCENTAGE);

    // distribute space in favour of field over delete button
    layout.setExpandRatio(field, 1);
    if (definition.isReadOnly()) {
        return layout;
    }

    // move up Button
    Button moveUpButton = new Button();
    moveUpButton.setHtmlContentAllowed(true);
    moveUpButton.setCaption("<span class=\"" + "icon-arrow2_n" + "\"></span>");
    moveUpButton.addStyleName("inline");
    moveUpButton.setDescription(buttonCaptionMoveUp);
    moveUpButton.addClickListener(new Button.ClickListener() {

        @Override
        public void buttonClick(Button.ClickEvent event) {
            onMove(layout, propertyReference, true);
        }
    });

    // move down Button
    Button moveDownButton = new Button();
    moveDownButton.setHtmlContentAllowed(true);
    moveDownButton.setCaption("<span class=\"" + "icon-arrow2_s" + "\"></span>");
    moveDownButton.addStyleName("inline");
    moveDownButton.setDescription(buttonCaptionMoveDown);
    moveDownButton.addClickListener(new Button.ClickListener() {

        @Override
        public void buttonClick(Button.ClickEvent event) {
            onMove(layout, propertyReference, false);
        }
    });

    // Delete Button
    Button deleteButton = new Button();
    deleteButton.setHtmlContentAllowed(true);
    deleteButton.setCaption("<span class=\"" + "icon-trash" + "\"></span>");
    deleteButton.addStyleName("inline");
    deleteButton.setDescription(buttonCaptionRemove);
    deleteButton.addClickListener(new ClickListener() {

        @Override
        public void buttonClick(ClickEvent event) {
            onDelete(layout, propertyReference);
        }
    });

    layout.addComponents(moveUpButton, moveDownButton, deleteButton);

    // make sure button stays aligned with the field and not with the optional field label when used
    layout.setComponentAlignment(deleteButton, Alignment.BOTTOM_RIGHT);
    layout.setComponentAlignment(moveUpButton, Alignment.BOTTOM_RIGHT);
    layout.setComponentAlignment(moveDownButton, Alignment.BOTTOM_RIGHT);

    return layout;
}

From source file:infodoc.ui.module.help.AboutWindow.java

License:Open Source License

public AboutWindow() {
    super(InfodocConstants.uiAbout);
    addStyleName(InfodocTheme.WINDOW_OPAQUE);
    setIcon(new ThemeResource(InfodocTheme.iconAbout));
    setSizeUndefined();/*from w  w  w .jav  a2 s .c om*/
    setWidth("580px");
    setResizable(false);

    String installedModules = InfodocConstants.infodocModules.replace(" ", "");
    String installedModulesHtml = "";

    for (String module : installedModules.split(",")) {
        installedModulesHtml += "<span style='margin-left: 20px;'>" + module + "</span><br/>";
    }

    String top = "<h2><i>InfoDoc " + InfodocConstants.infodocVersion + "</i></h2>" + "Modules:" + "<pre><small>"
            + installedModulesHtml + "</small></pre>" + "<br/>License granted to:"
            + "<pre><small><span style='margin-left: 20px;'>" + InfodocConstants.infodocCompanyName + "</span>"
            + (InfodocConstants.infodocCompanyId == null ? ""
                    : "<br/><span style='margin-left: 20px;'> " + InfodocConstants.infodocCompanyId + "</span>")
            + (InfodocConstants.infodocCompanyAddress == null ? ""
                    : "<br/><span style='margin-left: 20px;'>" + InfodocConstants.infodocCompanyAddress
                            + "</span></pre></small>")
            + "<br/><br/>";

    String lower = "<br/>Contact the developer: <a href='" + InfodocConstants.infodocDeveloperUrl + "'>"
            + InfodocConstants.infodocDeveloperUrl + "</a>," + "<br/><b>All rights reserved</b>.";

    Label topLabel = new Label(top, Label.CONTENT_XHTML);
    Label lowerLabel = new Label(lower, Label.CONTENT_XHTML);
    lowerLabel.addStyleName(InfodocTheme.LABEL_TINY);

    VerticalLayout rightLayout = new VerticalLayout();
    rightLayout.setMargin(true);
    rightLayout.setStyleName(InfodocTheme.PANEL_LIGHT);
    rightLayout.addStyleName(InfodocTheme.PANEL_BORDERLESS);
    rightLayout.addStyleName(InfodocTheme.COOL_FONT);
    rightLayout.addComponent(topLabel);
    rightLayout.addComponent(lowerLabel);

    VerticalLayout leftLayout = new VerticalLayout();
    leftLayout.setWidth("130px");
    leftLayout.addComponent(new Label("<h2></h2>", Label.CONTENT_XHTML));
    leftLayout.addComponent(new Embedded(null, new ThemeResource(InfodocTheme.infodocBoxImage)));

    HorizontalLayout layout = new HorizontalLayout();
    layout.setSizeFull();
    layout.addComponent(leftLayout);
    layout.addComponent(rightLayout);
    layout.setExpandRatio(rightLayout, 1);

    Panel panel = new Panel();
    panel.addComponent(layout);

    setContent(panel);
}

From source file:io.mateu.ui.vaadin.framework.MyUI.java

License:Apache License

/**
 * abre una vista. La colocar en el lado derecho
 *
 * @param ui/*from  w  w  w  . j av  a2s . com*/
 * @param view
 */
public static void addView(MyUI ui, AbstractView view) {

    if (view == null) {
        System.out.println("abriendo vista null");
        ui.getViewDisplay().removeAllComponents();
    } else {

        System.out.println("abriendo vista " + view.getClass().getName() + "::" + view.getViewId());

        ViewLayout v = new ViewLayout(view);
        if (view instanceof AbstractDialog) {

            AbstractDialog d = (AbstractDialog) view;

            // Create a sub-window and set the content
            Window subWindow = new Window(((AbstractDialog) view).getTitle());

            HorizontalLayout footer = new HorizontalLayout();
            footer.setWidth("100%");
            footer.setSpacing(true);
            footer.addStyleName(ValoTheme.WINDOW_BOTTOM_TOOLBAR);

            Label footerText = new Label("");
            footerText.setSizeUndefined();

            Button ok;
            if (d instanceof AbstractAddRecordDialog) {
                ok = new Button("Add record", e -> {
                    List<String> errors = v.getView().getForm().validate();
                    if (errors.size() > 0) {
                        io.mateu.ui.core.client.app.MateuUI.notifyErrors(errors);
                    } else {
                        //if (d.isCloseOnOk()) subWindow.close();
                        ((AbstractAddRecordDialog) view).addAndClean(v.getView().getForm().getData());
                    }
                });
            } else {
                ok = new Button(d.getOkText(), e -> {
                    List<String> errors = v.getView().getForm().validate();
                    if (errors.size() > 0) {
                        io.mateu.ui.core.client.app.MateuUI.notifyErrors(errors);
                    } else {
                        if (d.isCloseOnOk())
                            subWindow.close();
                        ((AbstractDialog) view).onOk(v.getView().getForm().getData());
                    }
                });
            }
            ok.addStyleName(ValoTheme.BUTTON_PRIMARY);
            ok.setClickShortcut(ShortcutAction.KeyCode.ENTER);

            footer.addComponents(footerText);

            for (AbstractAction a : d.getActions()) {
                Button b = new Button(a.getName(), e -> {
                    a.run();
                });
                //b.addStyleName(ValoTheme.BUTTON_);
                //b.setClickShortcut(ShortcutAction.KeyCode.ENTER);
                if ("previous".equalsIgnoreCase(a.getName())) {
                    b.setIcon(VaadinIcons.ANGLE_LEFT);
                } else if ("next".equalsIgnoreCase(a.getName())) {
                    b.setIcon(VaadinIcons.ANGLE_RIGHT);
                }
                footer.addComponent(b);
            }

            if (d instanceof AbstractListEditorDialog) {
                AbstractListEditorDialog lv = (AbstractListEditorDialog) d;

                Property<Integer> pos = new SimpleObjectProperty<>();

                pos.setValue(lv.getInitialPos());

                Button prev = new Button("Previous", e -> {
                    List<String> errors = v.getView().getForm().validate();
                    if (errors.size() > 0) {
                        io.mateu.ui.core.client.app.MateuUI.notifyErrors(errors);
                    } else {

                        if (pos.getValue() > 0) {
                            lv.setData(pos.getValue(), view.getForm().getData());
                            pos.setValue(pos.getValue() - 1);
                            view.getForm().setData(lv.getData(pos.getValue()));
                        }

                    }
                });
                prev.setIcon(VaadinIcons.ANGLE_LEFT);
                footer.addComponent(prev);

                Button next = new Button("Next", e -> {
                    List<String> errors = v.getView().getForm().validate();
                    if (errors.size() > 0) {
                        io.mateu.ui.core.client.app.MateuUI.notifyErrors(errors);
                    } else {

                        if (pos.getValue() < lv.getListSize() - 1) {
                            lv.setData(pos.getValue(), view.getForm().getData());
                            pos.setValue(pos.getValue() + 1);
                            view.getForm().setData(lv.getData(pos.getValue()));
                        }

                    }
                });
                next.setIcon(VaadinIcons.ANGLE_RIGHT);
                footer.addComponent(next);

                pos.addListener(new ChangeListener<Integer>() {
                    @Override
                    public void changed(ObservableValue<? extends Integer> observable, Integer oldValue,
                            Integer newValue) {
                        if (newValue <= 0) {
                            prev.setEnabled(false);
                        } else {
                            prev.setEnabled(true);
                        }
                        if (newValue < lv.getListSize() - 1) {
                            next.setEnabled(true);
                        } else {
                            next.setEnabled(false);
                        }
                    }
                });

            }

            footer.addComponents(ok); //, cancel);
            footer.setExpandRatio(footerText, 1);

            v.addComponent(footer);

            subWindow.setContent(v);

            // Center it in the browser window
            subWindow.center();

            subWindow.setModal(true);

            // Open it in the UI
            ui.addWindow(subWindow);

        } else {

            System.out.println("aadiendo vista al contenedor de vistas");

            ui.getViewDisplay().removeAllComponents();
            ui.getViewDisplay().addComponent(v);

            ui.refreshMenu(v.getArea(), v.getMenu());

        }

    }

}

From source file:io.mateu.ui.vaadin.framework.MyUI.java

License:Apache License

/**
 * construye el menu//from  w  w w  . ja v a  2s.c  om
 *
 * @param request
 * @return
 */
CssLayout buildMenu(VaadinRequest request) {

    HorizontalLayout top = new HorizontalLayout();
    top.setWidth("100%");
    top.setDefaultComponentAlignment(Alignment.MIDDLE_LEFT);
    top.addStyleName(ValoTheme.MENU_TITLE);
    menu.addComponent(top);
    //menu.addComponent(createThemeSelect());

    Button showMenu = new Button("Menu", new ClickListener() {
        @Override
        public void buttonClick(ClickEvent event) {
            if (menu.getStyleName().contains("valo-menu-visible")) {
                menu.removeStyleName("valo-menu-visible");
            } else {
                menu.addStyleName("valo-menu-visible");
            }
        }
    });
    showMenu.addStyleName(ValoTheme.BUTTON_PRIMARY);
    showMenu.addStyleName(ValoTheme.BUTTON_SMALL);
    showMenu.addStyleName("valo-menu-toggle");
    showMenu.setIcon(FontAwesome.LIST);
    menu.addComponent(showMenu);

    //Label title = new Label("<h3><strong>" + getApp().getName() + "</strong></h3>", ContentMode.HTML);

    Button title = new Button(getApp().getName(), new ClickListener() {
        @Override
        public void buttonClick(ClickEvent event) {
            Page.getCurrent().open("#!",
                    (event.isAltKey() || event.isCtrlKey()) ? "_blank" : Page.getCurrent().getWindowName());
        }
    });
    title.addStyleName(ValoTheme.BUTTON_LINK);
    title.addStyleName("tituloapp");

    title.setSizeUndefined();
    top.addComponent(title);
    top.setExpandRatio(title, 1);

    settings = new MenuBar();
    settings.addStyleName("user-menu");
    settings.addStyleName("mi-user-menu");
    menu.addComponent(settings);

    HorizontalLayout navlinks = new HorizontalLayout();
    navlinks.setSpacing(true);

    {
        Button nav = new Button(VaadinIcons.ARROWS_CROSS, new ClickListener() {
            @Override
            public void buttonClick(ClickEvent event) {
                Page.getCurrent().open("#!nav",
                        (event.isAltKey() || event.isCtrlKey()) ? "_blank" : Page.getCurrent().getWindowName());
            }
        });
        nav.addStyleName(ValoTheme.BUTTON_LINK);
        nav.setDescription("Search inside menu");
        nav.addStyleName("navlink");

        navlinks.addComponent(nav);
    }

    if (MateuUI.getApp().isFavouritesAvailable()) {
        Button nav = new Button(VaadinIcons.USER_STAR, new ClickListener() {
            @Override
            public void buttonClick(ClickEvent event) {
                Page.getCurrent().open("#!favourites",
                        (event.isAltKey() || event.isCtrlKey()) ? "_blank" : Page.getCurrent().getWindowName());
            }
        });
        nav.addStyleName(ValoTheme.BUTTON_LINK);
        nav.addStyleName("navlink");
        nav.setDescription("My favourites");
        nav.setVisible(MateuUI.getApp().getUserData() != null);

        linkFavoritos = nav;

        navlinks.addComponent(nav);
    }

    if (MateuUI.getApp().isLastEditedAvailable()) {
        Button nav = new Button(VaadinIcons.RECORDS, new ClickListener() {
            @Override
            public void buttonClick(ClickEvent event) {
                Page.getCurrent().open("#!lastedited",
                        (event.isAltKey() || event.isCtrlKey()) ? "_blank" : Page.getCurrent().getWindowName());
            }
        });
        nav.addStyleName(ValoTheme.BUTTON_LINK);
        nav.addStyleName("navlink");
        nav.setDescription("Last edited records");
        nav.setVisible(MateuUI.getApp().getUserData() != null);

        linkUltimosRegistros = nav;

        navlinks.addComponent(nav);
    }

    HorizontalLayout aux = new HorizontalLayout(navlinks);
    aux.setSpacing(false);
    aux.addStyleName("contenedoriconosnav");
    menu.addComponent(aux);

    if (MateuUI.getApp().isFavouritesAvailable()) {
        aux = new HorizontalLayout();
        {
            Button nav = new Button(VaadinIcons.STAR, new ClickListener() {
                @Override
                public void buttonClick(ClickEvent event) {
                    System.out.println(Page.getCurrent().getUriFragment());
                    System.out.println(Page.getCurrent().getLocation());
                }
            });
            nav.addStyleName(ValoTheme.BUTTON_LINK);
            nav.addStyleName("navlink");
            nav.setDescription("Add current page to my favourites");
            nav.setVisible(MateuUI.getApp().getUserData() != null);

            linkNuevoFavorito = nav;

            aux.addComponent(nav);
        }
        aux.setSpacing(false);
        aux.addStyleName("contenedoriconosnav");
        menu.addComponent(aux);
    }

    menuItemsLayout.setPrimaryStyleName("valo-menuitems");
    menu.addComponent(menuItemsLayout);

    refreshMenu(null, null);

    return menu;
}

From source file:io.mateu.ui.vaadin.framework.MyUI.java

License:Apache License

/**
 * are el dilogo para autenticarse//ww w. j  a  v  a2  s  .  c  o  m
 */
private void openLoginDialog(boolean gohome) {

    // Create a sub-window and set the content
    Window subWindow = new Window("Login");

    subWindow.setWidth("375px");

    FormLayout f = new FormLayout();
    f.setMargin(true);

    TextField l;
    f.addComponent(l = new TextField("Username"));
    PasswordField p;
    f.addComponent(p = new PasswordField("Password"));
    Label e;
    f.addComponent(e = new Label());

    VerticalLayout v = new VerticalLayout();
    v.addComponent(f);

    HorizontalLayout footer = new HorizontalLayout();
    footer.setWidth("100%");
    footer.setSpacing(true);
    footer.addStyleName(ValoTheme.WINDOW_BOTTOM_TOOLBAR);

    Label footerText = new Label("");
    footerText.setSizeUndefined();

    Button forgot = new Button("Forgot password", new ClickListener() {
        @Override
        public void buttonClick(ClickEvent clickEvent) {
            e.setValue("Asking for email...");
            io.mateu.ui.core.client.app.MateuUI.getBaseService().forgotPassword(l.getValue(),
                    new AsyncCallback<Void>() {

                        @Override
                        public void onFailure(Throwable caught) {
                            e.setValue("" + caught.getClass().getName() + ": " + caught.getMessage());
                        }

                        @Override
                        public void onSuccess(Void result) {
                            e.setValue("Email sent. Please check your inbox");
                        }
                    });
        }
    });
    //forgot.addStyleName(ValoTheme.BUTTON_);

    Button ok = new Button("Login", new ClickListener() {
        @Override
        public void buttonClick(ClickEvent clickEvent) {
            e.setValue("Authenticating...");
            io.mateu.ui.core.client.app.MateuUI.getBaseService().authenticate(l.getValue(), p.getValue(),
                    new AsyncCallback<UserData>() {

                        @Override
                        public void onFailure(Throwable caught) {
                            e.setValue("" + caught.getClass().getName() + ": " + caught.getMessage());
                        }

                        @Override
                        public void onSuccess(UserData result) {
                            e.setValue("OK!");
                            getApp().setUserData(result);
                            VaadinSession.getCurrent().setAttribute("usuario", "admin");
                            subWindow.close();

                            if (MateuUI.getApp().isFavouritesAvailable())
                                linkFavoritos.setVisible(true);
                            if (MateuUI.getApp().isLastEditedAvailable())
                                linkUltimosRegistros.setVisible(true);
                            if (MateuUI.getApp().isFavouritesAvailable())
                                linkNuevoFavorito.setVisible(true);

                            refreshSettings();
                            refreshMenu(null, null);
                            System.out.println("STATE:" + navigator.getState());
                            System.out.println("URIFRAGMENT:" + Page.getCurrent().getUriFragment());
                            navigator.navigateTo((gohome) ? "" : navigator.getState());
                        }
                    });
        }
    });
    ok.addStyleName(ValoTheme.BUTTON_PRIMARY);
    ok.setClickShortcut(ShortcutAction.KeyCode.ENTER);

    Button cancel = new Button("Cancel");

    footer.addComponents(footerText, forgot, ok); //, cancel);
    footer.setExpandRatio(footerText, 1);

    v.addComponent(footer);

    subWindow.setContent(v);

    // Center it in the browser window
    subWindow.center();

    subWindow.setModal(true);

    // Open it in the UI
    UI.getCurrent().addWindow(subWindow);

    l.focus();
}

From source file:io.mateu.ui.vaadin.framework.MyUI.java

License:Apache License

/**
 * abre el dilogo para cambiar el password
 *
 *///from  w  w w.ja  va2s  .  c om
private void changePassword() {
    // Create a sub-window and set the content
    Window subWindow = new Window("Change password");

    subWindow.setWidth("375px");

    FormLayout f = new FormLayout();
    f.setMargin(true);

    PasswordField l;
    f.addComponent(l = new PasswordField("Current password"));
    PasswordField p;
    f.addComponent(p = new PasswordField("New password"));
    PasswordField p2;
    f.addComponent(p2 = new PasswordField("Repeat password"));
    Label e;
    f.addComponent(e = new Label());

    VerticalLayout v = new VerticalLayout();
    v.addComponent(f);

    HorizontalLayout footer = new HorizontalLayout();
    footer.setWidth("100%");
    footer.setSpacing(true);
    footer.addStyleName(ValoTheme.WINDOW_BOTTOM_TOOLBAR);

    Label footerText = new Label("");
    footerText.setSizeUndefined();

    Button ok = new Button("Change it!", new ClickListener() {
        @Override
        public void buttonClick(ClickEvent clickEvent) {
            if (l.getValue() == null || "".equals(l.getValue().trim()))
                e.setValue("Old password is required");
            else if (p.getValue() == null || "".equals(p.getValue().trim()))
                e.setValue("New password is required");
            else if (p2.getValue() == null || "".equals(p2.getValue().trim()))
                e.setValue("New password repeated is required");
            else if (!p.getValue().equals(p2.getValue()))
                e.setValue("New password and new password repeated must be equal");
            else {
                e.setValue("Changing password...");

                io.mateu.ui.core.client.app.MateuUI.getBaseService().changePassword(
                        getApp().getUserData().getLogin(), l.getValue(), p.getValue(),
                        new AsyncCallback<Void>() {

                            @Override
                            public void onFailure(Throwable caught) {
                                e.setValue("" + caught.getClass().getName() + ": " + caught.getMessage());
                            }

                            @Override
                            public void onSuccess(Void result) {
                                e.setValue("OK!");
                                subWindow.close();
                            }
                        });

            }
        }
    });
    ok.addStyleName(ValoTheme.BUTTON_PRIMARY);
    ok.setClickShortcut(ShortcutAction.KeyCode.ENTER);

    Button cancel = new Button("Cancel");

    footer.addComponents(footerText, ok); //, cancel);
    footer.setExpandRatio(footerText, 1);

    v.addComponent(footer);

    subWindow.setContent(v);

    // Center it in the browser window
    subWindow.center();

    subWindow.setModal(true);

    // Open it in the UI
    UI.getCurrent().addWindow(subWindow);

    l.focus();
}

From source file:io.mateu.ui.vaadin.framework.MyUI.java

License:Apache License

/**
 * abre el dilogo para editar el perfil/*from w  w  w  .ja  v  a 2 s . c  o  m*/
 *
 */
private void editProfile() {
    // Create a sub-window and set the content
    Window subWindow = new Window("My profile");

    subWindow.setWidth("375px");

    FormLayout f = new FormLayout();
    f.setMargin(true);

    TextField l;
    f.addComponent(l = new TextField("Name"));
    l.setValue(getApp().getUserData().getName());
    TextField p;
    f.addComponent(p = new TextField("Email"));
    p.setValue(getApp().getUserData().getEmail());
    Label e;
    f.addComponent(e = new Label());

    VerticalLayout v = new VerticalLayout();
    v.addComponent(f);

    HorizontalLayout footer = new HorizontalLayout();
    footer.setWidth("100%");
    footer.setSpacing(true);
    footer.addStyleName(ValoTheme.WINDOW_BOTTOM_TOOLBAR);

    Label footerText = new Label("");
    footerText.setSizeUndefined();

    Button ok = new Button("Update it!", new ClickListener() {
        @Override
        public void buttonClick(ClickEvent clickEvent) {
            e.setValue("Authenticating...");
            io.mateu.ui.core.client.app.MateuUI.getBaseService().updateProfile(
                    getApp().getUserData().getLogin(), l.getValue(), p.getValue(), null,
                    new AsyncCallback<Void>() {

                        @Override
                        public void onFailure(Throwable caught) {
                            e.setValue("" + caught.getClass().getName() + ": " + caught.getMessage());
                        }

                        @Override
                        public void onSuccess(Void result) {
                            e.setValue("OK!");
                            getApp().getUserData().setName(l.getValue());
                            getApp().getUserData().setEmail(p.getValue());
                            subWindow.close();
                            refreshSettings();
                        }
                    });
        }
    });
    ok.addStyleName(ValoTheme.BUTTON_PRIMARY);
    ok.setClickShortcut(ShortcutAction.KeyCode.ENTER);

    Button cancel = new Button("Cancel");

    footer.addComponents(footerText, ok); //, cancel);
    footer.setExpandRatio(footerText, 1);

    v.addComponent(footer);

    subWindow.setContent(v);

    // Center it in the browser window
    subWindow.center();

    subWindow.setModal(true);

    // Open it in the UI
    UI.getCurrent().addWindow(subWindow);

    l.focus();
}

From source file:io.mateu.ui.vaadin.framework.MyUI.java

License:Apache License

/**
 * abre el dilogo para cambiar la foto/*from   ww  w .  j  av a2  s .c  o m*/
 *
 *
 */
private void uploadFoto() {
    // Create a sub-window and set the content
    Window subWindow = new Window("My photo");

    subWindow.setWidth("475px");

    FormLayout f = new FormLayout();
    f.setMargin(true);

    Label e = new Label();

    Image image = new Image();

    class MyUploader implements Upload.Receiver, Upload.SucceededListener {

        File file;

        public File getFile() {
            return file;
        }

        public OutputStream receiveUpload(String fileName, String mimeType) {
            // Create and return a file output stream

            System.out.println("receiveUpload(" + fileName + "," + mimeType + ")");

            FileOutputStream os = null;
            if (fileName != null && !"".equals(fileName)) {

                long id = fileId++;
                String extension = ".tmp";
                if (fileName == null || "".equals(fileName.trim()))
                    fileName = "" + id + extension;
                if (fileName.lastIndexOf(".") < fileName.length() - 1) {
                    extension = fileName.substring(fileName.lastIndexOf("."));
                    fileName = fileName.substring(0, fileName.lastIndexOf("."));
                }
                File temp = null;
                try {
                    temp = File.createTempFile(fileName, extension);
                    os = new FileOutputStream(file = temp);
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }

            return os;
        }

        public void uploadSucceeded(Upload.SucceededEvent event) {
            // Show the uploaded file in the image viewer
            image.setSource(new FileResource(file));
            System.out.println("uploadSucceeded(" + file.getAbsolutePath() + ")");

        }

        public FileLocator getFileLocator() throws IOException {

            String extension = ".tmp";
            String fileName = file.getName();

            if (file.getName() == null || "".equals(file.getName().trim()))
                fileName = "" + getId();
            if (fileName.lastIndexOf(".") < fileName.length() - 1) {
                extension = fileName.substring(fileName.lastIndexOf("."));
                fileName = fileName.substring(0, fileName.lastIndexOf(".")).replaceAll(" ", "_");
            }

            java.io.File temp = (System.getProperty("tmpdir") == null)
                    ? java.io.File.createTempFile(fileName, extension)
                    : new java.io.File(new java.io.File(System.getProperty("tmpdir")), fileName + extension);

            System.out.println("java.io.tmpdir=" + System.getProperty("java.io.tmpdir"));
            System.out.println("Temp file : " + temp.getAbsolutePath());

            if (System.getProperty("tmpdir") == null || !temp.exists()) {
                System.out.println("writing temp file to " + temp.getAbsolutePath());
                Files.copy(file, temp);
            } else {
                System.out.println("temp file already exists");
            }

            String baseUrl = System.getProperty("tmpurl");
            URL url = null;
            try {
                if (baseUrl == null) {
                    url = file.toURI().toURL();
                } else
                    url = new URL(baseUrl + "/" + file.getName());
            } catch (MalformedURLException e) {
                e.printStackTrace();
            }
            return new FileLocator(0, file.getName(), url.toString(), file.getAbsolutePath());
        }
    }
    ;
    MyUploader receiver = new MyUploader();

    Upload upload = new Upload(null, receiver);
    //upload.setImmediateMode(false);
    upload.addSucceededListener(receiver);

    f.addComponent(image);

    f.addComponent(upload);

    f.addComponent(e);

    VerticalLayout v = new VerticalLayout();
    v.addComponent(f);

    HorizontalLayout footer = new HorizontalLayout();
    footer.setWidth("100%");
    footer.setSpacing(true);
    footer.addStyleName(ValoTheme.WINDOW_BOTTOM_TOOLBAR);

    Label footerText = new Label("");
    footerText.setSizeUndefined();

    Button ok = new Button("Change it!", new ClickListener() {
        @Override
        public void buttonClick(ClickEvent clickEvent) {
            e.setValue("Changing photo...");
            try {
                FileLocator loc = receiver.getFileLocator();

                io.mateu.ui.core.client.app.MateuUI.getBaseService()
                        .updateFoto(getApp().getUserData().getLogin(), loc, new AsyncCallback<Void>() {

                            @Override
                            public void onFailure(Throwable caught) {
                                e.setValue("" + caught.getClass().getName() + ": " + caught.getMessage());
                            }

                            @Override
                            public void onSuccess(Void result) {
                                e.setValue("OK!");
                                getApp().getUserData().setPhoto(loc.getUrl());
                                foto = (getApp().getUserData().getPhoto() != null)
                                        ? new ExternalResource(getApp().getUserData().getPhoto())
                                        : new ClassResource("profile-pic-300px.jpg");
                                subWindow.close();

                                refreshSettings();

                            }
                        });

            } catch (IOException e1) {
                e1.printStackTrace();
                io.mateu.ui.core.client.app.MateuUI.alert("" + e1.getClass().getName() + ":" + e1.getMessage());
            }

        }
    });
    ok.addStyleName(ValoTheme.BUTTON_PRIMARY);
    ok.setClickShortcut(ShortcutAction.KeyCode.ENTER);

    Button cancel = new Button("Cancel");

    footer.addComponents(footerText, ok); //, cancel);
    footer.setExpandRatio(footerText, 1);

    v.addComponent(footer);

    subWindow.setContent(v);

    // Center it in the browser window
    subWindow.center();

    subWindow.setModal(true);

    // Open it in the UI
    UI.getCurrent().addWindow(subWindow);

    upload.focus();
}

From source file:it.vige.greenarea.bpm.custom.ui.form.GreenareaAbstractFormPropertyRenderer.java

License:Apache License

protected HorizontalLayout getButtons(final String item, final Table table) {
    FormProperty operations = getOperations();
    @SuppressWarnings("unchecked")
    Map<String, String> mapOperations = (Map<String, String>) operations.getType().getInformation("values");

    HorizontalLayout buttons = new HorizontalLayout();
    buttons.setSpacing(true);/*from   www .j av a  2 s  .c o m*/
    buttons.setWidth(80, UNITS_PIXELS);
    buttons.addStyleName(STYLE_DETAIL_BLOCK);
    for (String operation : mapOperations.keySet()) {
        if (operation.equals(MODIFICA.name()) || operation.equals(CANCELLAZIONE.name())
                || operation.equals(DETTAGLIO.name()) || operation.equals(INSERIMENTO.name())) {
            addButton(operation, buttons, item, table);
        }
    }

    Label buttonSpacer = new Label();
    buttons.addComponent(buttonSpacer);
    buttons.setExpandRatio(buttonSpacer, 1.0f);
    return buttons;
}