Example usage for com.vaadin.ui Label setSizeUndefined

List of usage examples for com.vaadin.ui Label setSizeUndefined

Introduction

In this page you can find the example usage for com.vaadin.ui Label setSizeUndefined.

Prototype

@Override
    public void setSizeUndefined() 

Source Link

Usage

From source file:info.magnolia.ui.form.field.factory.AbstractFieldFactory.java

License:Open Source License

@Override
public View getView() {
    final CssLayout fieldView = new CssLayout();
    fieldView.setStyleName("field-view");

    Label label = new Label();
    label.setSizeUndefined();
    label.setCaption(getFieldDefinition().getLabel());

    if (getFieldDefinition().getClass().isAssignableFrom(TextFieldDefinition.class)) {
        final TextFieldDefinition textFieldDefinition = (TextFieldDefinition) getFieldDefinition();
        if (textFieldDefinition.getRows() > 0) {
            label.addStyleName("textarea");
        }//from   w  ww.  j a  v  a 2 s . c  o m
    }
    if (definition.getConverterClass() != null) {
        Converter converter = initializeConverter(definition.getConverterClass());
        label.setConverter(converter);
    }

    Property<?> property = initializeProperty();

    label.setPropertyDataSource(property);

    fieldView.addComponent(label);

    return new View() {
        @Override
        public Component asVaadinComponent() {
            return fieldView;
        }
    };
}

From source file:info.magnolia.ui.form.field.upload.basic.BasicUploadField.java

License:Open Source License

/**
 * @return Thumbnail Component./*  w w  w.ja  v a 2s  .c om*/
 */
protected Component createThumbnailComponent() {
    Label thumbnail = new Label("", ContentMode.HTML);
    thumbnail.setSizeUndefined();
    thumbnail.addStyleName("preview-image");
    thumbnail.addStyleName("file-preview");
    thumbnail.addStyleName(createIconStyleName());
    return thumbnail;
}

From source file:info.magnolia.ui.framework.app.stub.StubView.java

License:Open Source License

public StubView(String iconId) {
    layout.addStyleName("app-stub-view");
    layout.setSizeFull();/* w ww.j ava 2 s. co  m*/

    final Label icon = new Label("", ContentMode.HTML);
    icon.addStyleName("icon");
    icon.setSizeUndefined();
    icon.addStyleName(iconId);
    layout.addComponent(icon);
    layout.setComponentAlignment(icon, Alignment.MIDDLE_CENTER);
}

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

License:Apache License

/**
 * abre una vista. La colocar en el lado derecho
 *
 * @param ui//  w w  w . ja  v  a2s  . c  om
 * @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

/**
 * are el dilogo para autenticarse// w  ww . j  a  v  a 2 s. co 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
 *
 *///ww w.  j a v  a  2s.co m
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/*www . 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//  ww w .j  ava2  s .  co  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:io.mateu.ui.vaadin.framework.MyUI.java

License:Apache License

/**
 * crea el men pa un rea concreta/*  w  ww.  ja v a 2 s  . co  m*/
 *
 * @param a
 */
private void buildMenuOptions(AbstractArea a) {

    Label label = null;

    // recger la opcin de men selecionada de la url
    String s = navigator.getState();
    System.out.println("state=" + s);

    for (AbstractModule m : a.getModules()) {

        label = new Label(m.getName(), ContentMode.HTML);
        label.setPrimaryStyleName(ValoTheme.MENU_SUBTITLE);
        label.addStyleName(ValoTheme.LABEL_H4);
        label.setSizeUndefined();
        menuItemsLayout.addComponent(label);

        for (MenuEntry e : m.getMenu()) {

            addMenu(a, e);

        }
    }
}

From source file:it.vige.greenarea.bpm.custom.ui.dettaglio.admin.letturafiltri.LetturaFiltriPanel.java

License:Apache License

protected void addEmptySpace(ComponentContainer container) {
    Label emptySpace = new Label("&nbsp;", CONTENT_XHTML);
    emptySpace.setSizeUndefined();
    container.addComponent(emptySpace);/*from  w  w w .  ja v  a  2s .c  o  m*/
}