Example usage for com.vaadin.server UserError UserError

List of usage examples for com.vaadin.server UserError UserError

Introduction

In this page you can find the example usage for com.vaadin.server UserError UserError.

Prototype

public UserError(String textErrorMessage) 

Source Link

Document

Creates a textual error message of level ERROR.

Usage

From source file:annis.gui.ReportBugWindow.java

License:Apache License

public ReportBugWindow(final String bugEMailAddress, final byte[] screenImage, final String imageMimeType,
        Throwable cause) {//from w  w w  .j  av a 2s . c o  m
    this.cause = cause;

    setSizeUndefined();
    setCaption("Report Problem");

    ReportFormLayout layout = new ReportFormLayout();
    setContent(layout);

    layout.setWidth("100%");
    layout.setHeight("-1px");

    setHeight("420px");
    setWidth("750px");

    form = new FieldGroup(new BeanItem<>(new BugReport()));
    form.bindMemberFields(layout);
    form.setBuffered(true);

    final ReportBugWindow finalThis = this;
    btSubmit = new Button("Submit problem report", new Button.ClickListener() {

        @Override
        public void buttonClick(ClickEvent event) {
            try {
                form.commit();

                if (sendBugReport(bugEMailAddress, screenImage, imageMimeType)) {
                    Notification.show("Problem report was sent",
                            "We will answer your problem report as soon as possible",
                            Notification.Type.HUMANIZED_MESSAGE);
                }

                UI.getCurrent().removeWindow(finalThis);

            } catch (FieldGroup.CommitException ex) {
                List<String> errorFields = new LinkedList<>();
                for (Field f : form.getFields()) {
                    if (f instanceof AbstractComponent) {
                        AbstractComponent c = (AbstractComponent) f;
                        if (f.isValid()) {
                            c.setComponentError(null);
                        } else {
                            errorFields.add(f.getCaption());
                            c.setComponentError(new UserError("Validation failed: "));
                        }
                    }
                } // for each field
                String message = "Please check the error messages "
                        + "(place mouse over red triangle) for the following fields:<br />";
                message = message + StringUtils.join(errorFields, ",<br/>");
                Notification notify = new Notification("Validation failed", message,
                        Notification.Type.WARNING_MESSAGE, true);
                notify.show(UI.getCurrent().getPage());
            } catch (Exception ex) {
                log.error("Could not send bug report", ex);
                Notification.show("Could not send bug report", ex.getMessage(),
                        Notification.Type.WARNING_MESSAGE);
            }
        }
    });

    btCancel = new Button("Cancel", new Button.ClickListener() {

        @Override
        public void buttonClick(ClickEvent event) {
            form.discard();
            UI.getCurrent().removeWindow(finalThis);
        }
    });

    addScreenshotPreview(layout, screenImage, imageMimeType);

    HorizontalLayout buttons = new HorizontalLayout();
    buttons.addComponent(btSubmit);
    buttons.addComponent(btCancel);

    layout.addComponent(buttons);

}

From source file:com.cavisson.gui.dashboard.components.controls.ComboBoxes.java

License:Apache License

public ComboBoxes() {
    setMargin(true);/*from w  w  w .  j a  v a 2 s  . c  o  m*/

    Label h1 = new Label("Combo Boxes");
    h1.addStyleName("h1");
    addComponent(h1);

    HorizontalLayout row = new HorizontalLayout();
    row.addStyleName("wrapping");
    row.setSpacing(true);
    addComponent(row);

    ComboBox combo = new ComboBox("Normal");
    combo.setInputPrompt("You can type here");
    combo.setContainerDataSource(ValoThemeUI.generateContainer(200, false));
    combo.setNullSelectionAllowed(false);
    combo.select(combo.getItemIds().iterator().next());
    combo.setItemCaptionPropertyId(ValoThemeUI.CAPTION_PROPERTY);
    combo.setItemIconPropertyId(ValoThemeUI.ICON_PROPERTY);
    combo.setItemIcon(combo.getItemIds().iterator().next(), new ThemeResource("../runo/icons/16/document.png"));
    row.addComponent(combo);

    CssLayout group = new CssLayout();
    group.setCaption("Grouped with a Button");
    group.addStyleName("v-component-group");
    row.addComponent(group);

    combo = new ComboBox();
    combo.setInputPrompt("You can type here");
    combo.setContainerDataSource(ValoThemeUI.generateContainer(200, false));
    combo.setNullSelectionAllowed(false);
    combo.select(combo.getItemIds().iterator().next());
    combo.setItemCaptionPropertyId(ValoThemeUI.CAPTION_PROPERTY);
    combo.setItemIconPropertyId(ValoThemeUI.ICON_PROPERTY);
    combo.setWidth("240px");
    group.addComponent(combo);
    Button today = new Button("Do It");
    group.addComponent(today);

    combo = new ComboBox("Explicit size");
    combo.setInputPrompt("You can type here");
    combo.addItem("Option One");
    combo.addItem("Option Two");
    combo.addItem("Option Three");
    combo.setWidth("260px");
    combo.setHeight("60px");
    row.addComponent(combo);

    combo = new ComboBox("No text input allowed");
    combo.setInputPrompt("You can click here");
    combo.addItem("Option One");
    combo.addItem("Option Two");
    combo.addItem("Option Three");
    combo.setTextInputAllowed(false);
    combo.setNullSelectionAllowed(false);
    combo.select("Option One");
    row.addComponent(combo);

    combo = new ComboBox("Error");
    combo.setInputPrompt("You can type here");
    combo.addItem("Option One");
    combo.addItem("Option Two");
    combo.addItem("Option Three");
    combo.setNullSelectionAllowed(false);
    combo.select("Option One");
    combo.setComponentError(new UserError("Fix it, now!"));
    row.addComponent(combo);

    combo = new ComboBox("Error, borderless");
    combo.setInputPrompt("You can type here");
    combo.addItem("Option One");
    combo.addItem("Option Two");
    combo.addItem("Option Three");
    combo.setNullSelectionAllowed(false);
    combo.select("Option One");
    combo.setComponentError(new UserError("Fix it, now!"));
    combo.addStyleName("borderless");
    row.addComponent(combo);

    combo = new ComboBox("Disabled");
    combo.setInputPrompt("You can't type here");
    combo.addItem("Option One");
    combo.addItem("Option Two");
    combo.addItem("Option Three");
    combo.setEnabled(false);
    row.addComponent(combo);

    combo = new ComboBox("Custom color");
    combo.setInputPrompt("You can type here");
    combo.setContainerDataSource(ValoThemeUI.generateContainer(200, false));
    combo.setItemCaptionPropertyId(ValoThemeUI.CAPTION_PROPERTY);
    combo.setItemIconPropertyId(ValoThemeUI.ICON_PROPERTY);
    combo.addStyleName("color1");
    row.addComponent(combo);

    combo = new ComboBox("Custom color");
    combo.setInputPrompt("You can type here");
    combo.setContainerDataSource(ValoThemeUI.generateContainer(200, false));
    combo.setItemCaptionPropertyId(ValoThemeUI.CAPTION_PROPERTY);
    combo.setItemIconPropertyId(ValoThemeUI.ICON_PROPERTY);
    combo.addStyleName("color2");
    row.addComponent(combo);

    combo = new ComboBox("Custom color");
    combo.setInputPrompt("You can type here");
    combo.setContainerDataSource(ValoThemeUI.generateContainer(200, false));
    combo.setItemCaptionPropertyId(ValoThemeUI.CAPTION_PROPERTY);
    combo.setItemIconPropertyId(ValoThemeUI.ICON_PROPERTY);
    combo.addStyleName("color3");
    row.addComponent(combo);

    combo = new ComboBox("Small");
    combo.setInputPrompt("You can type here");
    combo.setContainerDataSource(ValoThemeUI.generateContainer(200, false));
    combo.setItemCaptionPropertyId(ValoThemeUI.CAPTION_PROPERTY);
    combo.setItemIconPropertyId(ValoThemeUI.ICON_PROPERTY);
    combo.addStyleName("small");
    row.addComponent(combo);

    combo = new ComboBox("Large");
    combo.setInputPrompt("You can type here");
    combo.setContainerDataSource(ValoThemeUI.generateContainer(200, false));
    combo.setItemCaptionPropertyId(ValoThemeUI.CAPTION_PROPERTY);
    combo.setItemIconPropertyId(ValoThemeUI.ICON_PROPERTY);
    combo.addStyleName("large");
    row.addComponent(combo);

    combo = new ComboBox("Borderless");
    combo.setInputPrompt("You can type here");
    combo.addItem("Option One");
    combo.addItem("Option Two");
    combo.addItem("Option Three");
    combo.addStyleName("borderless");
    row.addComponent(combo);

    combo = new ComboBox("Tiny");
    combo.setInputPrompt("You can type here");
    combo.setContainerDataSource(ValoThemeUI.generateContainer(200, false));
    combo.setItemCaptionPropertyId(ValoThemeUI.CAPTION_PROPERTY);
    combo.setItemIconPropertyId(ValoThemeUI.ICON_PROPERTY);
    combo.addStyleName("tiny");
    row.addComponent(combo);

    combo = new ComboBox("Huge");
    combo.setInputPrompt("You can type here");
    combo.setContainerDataSource(ValoThemeUI.generateContainer(200, false));
    combo.setItemCaptionPropertyId(ValoThemeUI.CAPTION_PROPERTY);
    combo.setItemIconPropertyId(ValoThemeUI.ICON_PROPERTY);
    combo.addStyleName("huge");
    row.addComponent(combo);
}

From source file:com.cavisson.gui.dashboard.components.controls.CommonParts.java

License:Apache License

Panel tooltips() {
    Panel p = new Panel("Tooltips");
    HorizontalLayout content = new HorizontalLayout() {
        {/*ww w  .ja va2 s  .  c  om*/
            setSpacing(true);
            setMargin(true);
            addStyleName("wrapping");

            addComponent(new Label("Try out different tooltips/descriptions by hovering over the labels."));

            Label label = new Label("Simple");
            label.addStyleName("bold");
            label.setDescription("Simple tooltip message");
            addComponent(label);

            label = new Label("Long");
            label.addStyleName("bold");
            label.setDescription(
                    "Long tooltip message. Inmensae subtilitatis, obscuris et malesuada fames. Salutantibus vitae elit libero, a pharetra augue.");
            addComponent(label);

            label = new Label("HTML tooltip");
            label.addStyleName("bold");
            label.setDescription(
                    "<div><h1>Ut enim ad minim veniam, quis nostrud exercitation</h1><p><span>Morbi fringilla convallis sapien, id pulvinar odio volutpat.</span> <span>Vivamus sagittis lacus vel augue laoreet rutrum faucibus.</span> <span>Donec sed odio operae, eu vulputate felis rhoncus.</span> <span>At nos hinc posthac, sitientis piros Afros.</span> <span>Tu quoque, Brute, fili mi, nihil timor populi, nihil!</span></p><p><span>Gallia est omnis divisa in partes tres, quarum.</span> <span>Praeterea iter est quasdam res quas ex communi.</span> <span>Cum ceteris in veneratione tui montes, nascetur mus.</span> <span>Quam temere in vitiis, legem sancimus haerentia.</span> <span>Idque Caesaris facere voluntate liceret: sese habere.</span></p></div>");
            addComponent(label);

            label = new Label("With an error message");
            label.addStyleName("bold");
            label.setDescription("Simple tooltip message");
            label.setComponentError(new UserError("Something terrible has happened"));
            addComponent(label);

            label = new Label("With a long error message");
            label.addStyleName("bold");
            label.setDescription("Simple tooltip message");
            label.setComponentError(new UserError(
                    "<h2>Contra legem facit qui id facit quod lex prohibet <span>Tityre, tu patulae recubans sub tegmine fagi  dolor.</span> <span>Tityre, tu patulae recubans sub tegmine fagi  dolor.</span> <span>Prima luce, cum quibus mons aliud  consensu ab eo.</span> <span>Quid securi etiam tamquam eu fugiat nulla pariatur.</span> <span>Fabio vel iudice vincam, sunt in culpa qui officia.</span> <span>Nihil hic munitissimus habendi senatus locus, nihil horum?</span></p><p><span>Plura mihi bona sunt, inclinet, amari petere vellent.</span> <span>Integer legentibus erat a ante historiarum dapibus.</span> <span>Quam diu etiam furor iste tuus nos eludet?</span> <span>Nec dubitamus multa iter quae et nos invenerat.</span> <span>Quisque ut dolor gravida, placerat libero vel, euismod.</span> <span>Quae vero auctorem tractata ab fiducia dicuntur.</span></h2>",
                    AbstractErrorMessage.ContentMode.HTML, ErrorLevel.CRITICAL));
            addComponent(label);

            label = new Label("Error message only");
            label.addStyleName("bold");
            label.setComponentError(new UserError("Something terrible has happened"));
            addComponent(label);
        }
    };
    p.setContent(content);
    return p;

}

From source file:com.cavisson.gui.dashboard.components.controls.DateFields.java

License:Apache License

public DateFields() {
    setMargin(true);//  w  w w.j a  v  a2 s .  c  o  m

    Label h1 = new Label("Date Fields");
    h1.addStyleName("h1");
    addComponent(h1);

    HorizontalLayout row = new HorizontalLayout();
    row.addStyleName("wrapping");
    row.setSpacing(true);
    addComponent(row);

    DateField date = new DateField("Default resolution");
    setDate(date);
    row.addComponent(date);

    date = new DateField("Error");
    setDate(date);
    date.setComponentError(new UserError("Fix it, now!"));
    row.addComponent(date);

    date = new DateField("Error, borderless");
    setDate(date);
    date.setComponentError(new UserError("Fix it, now!"));
    date.addStyleName("borderless");
    row.addComponent(date);

    CssLayout group = new CssLayout();
    group.setCaption("Grouped with a Button");
    group.addStyleName("v-component-group");
    row.addComponent(group);

    final DateField date2 = new DateField();
    group.addComponent(date2);

    Button today = new Button("Today", new ClickListener() {
        @Override
        public void buttonClick(ClickEvent event) {
            date2.setValue(new Date());
        }
    });
    group.addComponent(today);

    date = new DateField("Default resolution, explicit size");
    setDate(date);
    row.addComponent(date);
    date.setWidth("260px");
    date.setHeight("60px");

    date = new DateField("Second resolution");
    setDate(date);
    date.setResolution(Resolution.SECOND);
    row.addComponent(date);

    date = new DateField("Minute resolution");
    setDate(date);
    date.setResolution(Resolution.MINUTE);
    row.addComponent(date);

    date = new DateField("Hour resolution");
    setDate(date);
    date.setResolution(Resolution.HOUR);
    row.addComponent(date);

    date = new DateField("Disabled");
    setDate(date);
    date.setResolution(Resolution.HOUR);
    date.setEnabled(false);
    row.addComponent(date);

    date = new DateField("Day resolution");
    setDate(date);
    date.setResolution(Resolution.DAY);
    row.addComponent(date);

    date = new DateField("Month resolution");
    setDate(date);
    date.setResolution(Resolution.MONTH);
    row.addComponent(date);

    date = new DateField("Year resolution");
    setDate(date);
    date.setResolution(Resolution.YEAR);
    row.addComponent(date);

    date = new DateField("Custom color");
    setDate(date);
    date.setResolution(Resolution.DAY);
    date.addStyleName("color1");
    row.addComponent(date);

    date = new DateField("Custom color");
    setDate(date);
    date.setResolution(Resolution.DAY);
    date.addStyleName("color2");
    row.addComponent(date);

    date = new DateField("Custom color");
    setDate(date);
    date.setResolution(Resolution.DAY);
    date.addStyleName("color3");
    row.addComponent(date);

    date = new DateField("Small");
    setDate(date);
    date.setResolution(Resolution.DAY);
    date.addStyleName("small");
    row.addComponent(date);

    date = new DateField("Large");
    setDate(date);
    date.setResolution(Resolution.DAY);
    date.addStyleName("large");
    row.addComponent(date);

    date = new DateField("Borderless");
    setDate(date);
    date.setResolution(Resolution.DAY);
    date.addStyleName("borderless");
    row.addComponent(date);

    date = new DateField("Week numbers");
    setDate(date);
    date.setResolution(Resolution.DAY);
    date.setLocale(new Locale("fi", "fi"));
    date.setShowISOWeekNumbers(true);
    row.addComponent(date);

    date = new DateField("US locale");
    setDate(date);
    date.setResolution(Resolution.SECOND);
    date.setLocale(new Locale("en", "US"));
    row.addComponent(date);

    date = new DateField("Custom format");
    setDate(date);
    date.setDateFormat("E dd/MM/yyyy");
    row.addComponent(date);

    date = new DateField("Tiny");
    setDate(date);
    date.setResolution(Resolution.DAY);
    date.addStyleName("tiny");
    row.addComponent(date);

    date = new DateField("Huge");
    setDate(date);
    date.setResolution(Resolution.DAY);
    date.addStyleName("huge");
    row.addComponent(date);

    date = new InlineDateField("Date picker");
    setDate(date);
    row.addComponent(date);

    date = new InlineDateField("Date picker with week numbers");
    setDate(date);
    date.setLocale(new Locale("fi", "fi"));
    date.setShowISOWeekNumbers(true);
    row.addComponent(date);
}

From source file:com.cavisson.gui.dashboard.components.controls.Forms.java

License:Apache License

public Forms() {
    setSpacing(true);/*from w ww  .j a v  a  2s.  com*/
    setMargin(true);

    Label title = new Label("Forms");
    title.addStyleName("h1");
    addComponent(title);

    final FormLayout form = new FormLayout();
    form.setMargin(false);
    form.setWidth("800px");
    form.addStyleName("light");
    addComponent(form);

    Label section = new Label("Personal Info");
    section.addStyleName("h2");
    section.addStyleName("colored");
    form.addComponent(section);
    StringGenerator sg = new StringGenerator();

    TextField name = new TextField("Name");
    name.setValue(sg.nextString(true) + " " + sg.nextString(true));
    name.setWidth("50%");
    form.addComponent(name);

    DateField birthday = new DateField("Birthday");
    birthday.setValue(new Date(80, 0, 31));
    form.addComponent(birthday);

    TextField username = new TextField("Username");
    username.setValue(sg.nextString(false) + sg.nextString(false));
    username.setRequired(true);
    form.addComponent(username);

    OptionGroup sex = new OptionGroup("Sex");
    sex.addItem("Female");
    sex.addItem("Male");
    sex.select("Male");
    sex.addStyleName("horizontal");
    form.addComponent(sex);

    section = new Label("Contact Info");
    section.addStyleName("h3");
    section.addStyleName("colored");
    form.addComponent(section);

    TextField email = new TextField("Email");
    email.setValue(sg.nextString(false) + "@" + sg.nextString(false) + ".com");
    email.setWidth("50%");
    email.setRequired(true);
    form.addComponent(email);

    TextField location = new TextField("Location");
    location.setValue(sg.nextString(true) + ", " + sg.nextString(true));
    location.setWidth("50%");
    location.setComponentError(new UserError("This address doesn't exist"));
    form.addComponent(location);

    TextField phone = new TextField("Phone");
    phone.setWidth("50%");
    form.addComponent(phone);

    HorizontalLayout wrap = new HorizontalLayout();
    wrap.setSpacing(true);
    wrap.setDefaultComponentAlignment(Alignment.MIDDLE_LEFT);
    wrap.setCaption("Newsletter");
    CheckBox newsletter = new CheckBox("Subscribe to newsletter", true);
    wrap.addComponent(newsletter);

    ComboBox period = new ComboBox();
    period.setTextInputAllowed(false);
    period.addItem("Daily");
    period.addItem("Weekly");
    period.addItem("Montly");
    period.setNullSelectionAllowed(false);
    period.select("Weekly");
    period.addStyleName("small");
    period.setWidth("10em");
    wrap.addComponent(period);
    form.addComponent(wrap);

    section = new Label("Additional Info");
    section.addStyleName("h4");
    section.addStyleName("colored");
    form.addComponent(section);

    TextField website = new TextField("Website");
    website.setInputPrompt("http://");
    website.setWidth("100%");
    form.addComponent(website);

    TextArea shortbio = new TextArea("Short Bio");
    shortbio.setValue(
            "Quis aute iure reprehenderit in voluptate velit esse. Cras mattis iudicium purus sit amet fermentum.");
    shortbio.setWidth("100%");
    shortbio.setRows(2);
    form.addComponent(shortbio);

    final RichTextArea bio = new RichTextArea("Bio");
    bio.setWidth("100%");
    bio.setValue(
            "<div><p><span>Integer legentibus erat a ante historiarum dapibus.</span> <span>Vivamus sagittis lacus vel augue laoreet rutrum faucibus.</span> <span>A communi observantia non est recedendum.</span> <span>Morbi fringilla convallis sapien, id pulvinar odio volutpat.</span> <span>Ab illo tempore, ab est sed immemorabili.</span> <span>Quam temere in vitiis, legem sancimus haerentia.</span></p><p><span>Morbi odio eros, volutpat ut pharetra vitae, lobortis sed nibh.</span> <span>Quam diu etiam furor iste tuus nos eludet?</span> <span>Cum sociis natoque penatibus et magnis dis parturient.</span> <span>Quam diu etiam furor iste tuus nos eludet?</span> <span>Tityre, tu patulae recubans sub tegmine fagi  dolor.</span></p><p><span>Curabitur blandit tempus ardua ridiculus sed magna.</span> <span>Phasellus laoreet lorem vel dolor tempus vehicula.</span> <span>Etiam habebis sem dicantur magna mollis euismod.</span> <span>Hi omnes lingua, institutis, legibus inter se differunt.</span></p></div>");
    form.addComponent(bio);

    form.setReadOnly(true);
    bio.setReadOnly(true);

    Button edit = new Button("Edit", new ClickListener() {
        @Override
        public void buttonClick(ClickEvent event) {
            boolean readOnly = form.isReadOnly();
            if (readOnly) {
                bio.setReadOnly(false);
                form.setReadOnly(false);
                form.removeStyleName("light");
                event.getButton().setCaption("Save");
                event.getButton().addStyleName("primary");
            } else {
                bio.setReadOnly(true);
                form.setReadOnly(true);
                form.addStyleName("light");
                event.getButton().setCaption("Edit");
                event.getButton().removeStyleName("primary");
            }
        }
    });

    HorizontalLayout footer = new HorizontalLayout();
    footer.setMargin(new MarginInfo(true, false, true, false));
    footer.setSpacing(true);
    footer.setDefaultComponentAlignment(Alignment.MIDDLE_LEFT);
    form.addComponent(footer);
    footer.addComponent(edit);

    Label lastModified = new Label("Last modified by you a minute ago");
    lastModified.addStyleName("light");
    footer.addComponent(lastModified);
}

From source file:com.cavisson.gui.dashboard.components.controls.TextFields.java

License:Apache License

public TextFields() {
    setMargin(true);/*from  w ww .ja va 2s. c o  m*/

    Label h1 = new Label("Text Fields");
    h1.addStyleName("h1");
    addComponent(h1);

    HorizontalLayout row = new HorizontalLayout();
    row.addStyleName("wrapping");
    row.setSpacing(true);
    addComponent(row);

    TextField tf = new TextField("Normal");
    tf.setInputPrompt("First name");
    tf.setIcon(testIcon.get());
    row.addComponent(tf);

    tf = new TextField("Custom color");
    tf.setInputPrompt("Email");
    tf.addStyleName("color1");
    row.addComponent(tf);

    tf = new TextField("User Color");
    tf.setInputPrompt("Gender");
    tf.addStyleName("color2");
    row.addComponent(tf);

    tf = new TextField("Themed");
    tf.setInputPrompt("Age");
    tf.addStyleName("color3");
    row.addComponent(tf);

    tf = new TextField("Error");
    tf.setValue("Somethings wrong");
    tf.setComponentError(new UserError("Fix it, now!"));
    row.addComponent(tf);

    tf = new TextField("Error, borderless");
    tf.setValue("Somethings wrong");
    tf.setComponentError(new UserError("Fix it, now!"));
    tf.addStyleName("borderless");
    row.addComponent(tf);

    tf = new TextField("Read-only");
    tf.setInputPrompt("Nationality");
    tf.setValue("Finnish");
    tf.setReadOnly(true);
    row.addComponent(tf);

    tf = new TextField("Small");
    tf.setValue("Field value");
    tf.addStyleName("small");
    row.addComponent(tf);

    tf = new TextField("Large");
    tf.setValue("Field value");
    tf.addStyleName("large");
    tf.setIcon(testIcon.get(true));
    row.addComponent(tf);

    tf = new TextField("Icon inside");
    tf.setInputPrompt("Ooh, an icon");
    tf.addStyleName("inline-icon");
    tf.setIcon(testIcon.get());
    row.addComponent(tf);

    tf = new TextField("Large, Icon inside");
    tf.setInputPrompt("Ooh, an icon");
    tf.addStyleName("large");
    tf.addStyleName("inline-icon");
    tf.setIcon(testIcon.get());
    row.addComponent(tf);

    tf = new TextField("Small, Icon inside");
    tf.setInputPrompt("Ooh, an icon");
    tf.addStyleName("small");
    tf.addStyleName("inline-icon");
    tf.setIcon(testIcon.get());
    row.addComponent(tf);

    tf = new TextField("16px supported by default");
    tf.setInputPrompt("Image icon");
    tf.addStyleName("inline-icon");
    tf.setIcon(testIcon.get(true, 16));
    row.addComponent(tf);

    tf = new TextField();
    tf.setValue("Font, no caption");
    tf.addStyleName("inline-icon");
    tf.setIcon(testIcon.get());
    row.addComponent(tf);

    tf = new TextField();
    tf.setValue("Image, no caption");
    tf.addStyleName("inline-icon");
    tf.setIcon(testIcon.get(true, 16));
    row.addComponent(tf);

    CssLayout group = new CssLayout();
    group.addStyleName("v-component-group");
    row.addComponent(group);

    tf = new TextField();
    tf.setInputPrompt("Grouped with a button");
    tf.addStyleName("inline-icon");
    tf.setIcon(testIcon.get());
    tf.setWidth("260px");
    group.addComponent(tf);

    Button button = new Button("Do It");
    // button.addStyleName("primary");
    group.addComponent(button);

    tf = new TextField("Borderless");
    tf.setInputPrompt("Write here");
    tf.addStyleName("inline-icon");
    tf.addStyleName("borderless");
    tf.setIcon(testIcon.get());
    row.addComponent(tf);

    tf = new TextField("Right-aligned");
    tf.setValue("1,234");
    tf.addStyleName("align-right");
    row.addComponent(tf);

    tf = new TextField("Centered");
    tf.setInputPrompt("Guess what?");
    tf.addStyleName("align-center");
    row.addComponent(tf);

    PasswordField pwf = new PasswordField("Password");
    pwf.setInputPrompt("Secret words");
    pwf.addStyleName("inline-icon");
    pwf.setIcon(FontAwesome.LOCK);
    row.addComponent(pwf);

    pwf = new PasswordField("Password, right-aligned");
    pwf.setInputPrompt("Secret words");
    pwf.addStyleName("inline-icon");
    pwf.addStyleName("align-right");
    pwf.setIcon(FontAwesome.LOCK);
    row.addComponent(pwf);

    pwf = new PasswordField("Password, centered");
    pwf.setInputPrompt("Secret words");
    pwf.addStyleName("inline-icon");
    pwf.addStyleName("align-center");
    pwf.setIcon(FontAwesome.LOCK);
    row.addComponent(pwf);

    tf = new TextField("Tiny");
    tf.setValue("Field value");
    tf.addStyleName("tiny");
    row.addComponent(tf);

    tf = new TextField("Huge");
    tf.setValue("Field value");
    tf.addStyleName("huge");
    row.addComponent(tf);

    h1 = new Label("Text Areas");
    h1.addStyleName("h1");
    addComponent(h1);

    row = new HorizontalLayout();
    row.addStyleName("wrapping");
    row.setSpacing(true);
    addComponent(row);

    TextArea ta = new TextArea("Normal");
    ta.setInputPrompt("Write your comment");
    row.addComponent(ta);

    ta = new TextArea("Inline icon");
    ta.setInputPrompt("Inline icon not really working");
    ta.addStyleName("inline-icon");
    ta.setIcon(testIcon.get());
    row.addComponent(ta);

    ta = new TextArea("Custom color");
    ta.addStyleName("color1");
    ta.setInputPrompt("Write your comment");
    row.addComponent(ta);

    ta = new TextArea("Custom color, read-only");
    ta.addStyleName("color2");
    ta.setValue("Field value, spanning multiple lines of text");
    ta.setReadOnly(true);
    row.addComponent(ta);

    ta = new TextArea("Custom color");
    ta.addStyleName("color3");
    ta.setValue("Field value, spanning multiple lines of text");
    row.addComponent(ta);

    ta = new TextArea("Small");
    ta.addStyleName("small");
    ta.setInputPrompt("Write your comment");
    row.addComponent(ta);

    ta = new TextArea("Large");
    ta.addStyleName("large");
    ta.setInputPrompt("Write your comment");
    row.addComponent(ta);

    ta = new TextArea("Borderless");
    ta.addStyleName("borderless");
    ta.setInputPrompt("Write your comment");
    row.addComponent(ta);

    ta = new TextArea("Right-aligned");
    ta.addStyleName("align-right");
    ta.setValue("Field value, spanning multiple lines of text");
    row.addComponent(ta);

    ta = new TextArea("Centered");
    ta.addStyleName("align-center");
    ta.setValue("Field value, spanning multiple lines of text");
    row.addComponent(ta);

    ta = new TextArea("Tiny");
    ta.addStyleName("tiny");
    ta.setInputPrompt("Write your comment");
    row.addComponent(ta);

    ta = new TextArea("Huge");
    ta.addStyleName("huge");
    ta.setInputPrompt("Write your comment");
    row.addComponent(ta);

    RichTextArea rta = new RichTextArea();
    rta.setValue("<b>Some</b> <i>rich</i> content");
    row.addComponent(rta);

    rta = new RichTextArea("Read-only");
    rta.setValue("<b>Some</b> <i>rich</i> content");
    rta.setReadOnly(true);
    row.addComponent(rta);
}

From source file:com.etest.valo.ComboBoxes.java

License:Apache License

public ComboBoxes() {
    setMargin(true);//from ww  w  . j  a v  a2 s. c o  m

    Label h1 = new Label("Combo Boxes");
    h1.addStyleName("h1");
    addComponent(h1);

    HorizontalLayout row = new HorizontalLayout();
    row.addStyleName("wrapping");
    row.setSpacing(true);
    addComponent(row);

    ComboBox combo = new ComboBox("Normal");
    combo.setInputPrompt("You can type here");
    combo.setContainerDataSource(MainUI.generateContainer(200, false));
    combo.setNullSelectionAllowed(false);
    combo.select(combo.getItemIds().iterator().next());
    combo.setItemCaptionPropertyId(MainUI.CAPTION_PROPERTY);
    combo.setItemIconPropertyId(MainUI.ICON_PROPERTY);
    combo.setItemIcon(combo.getItemIds().iterator().next(), new ThemeResource("../runo/icons/16/document.png"));
    row.addComponent(combo);

    CssLayout group = new CssLayout();
    group.setCaption("Grouped with a Button");
    group.addStyleName("v-component-group");
    row.addComponent(group);

    combo = new ComboBox();
    combo.setInputPrompt("You can type here");
    combo.setContainerDataSource(MainUI.generateContainer(200, false));
    combo.setNullSelectionAllowed(false);
    combo.select(combo.getItemIds().iterator().next());
    combo.setItemCaptionPropertyId(MainUI.CAPTION_PROPERTY);
    combo.setItemIconPropertyId(MainUI.ICON_PROPERTY);
    combo.setWidth("240px");
    group.addComponent(combo);
    Button today = new Button("Do It");
    group.addComponent(today);

    combo = new ComboBox("Explicit size");
    combo.setInputPrompt("You can type here");
    combo.addItem("Option One");
    combo.addItem("Option Two");
    combo.addItem("Option Three");
    combo.setWidth("260px");
    combo.setHeight("60px");
    row.addComponent(combo);

    combo = new ComboBox("No text input allowed");
    combo.setInputPrompt("You can click here");
    combo.addItem("Option One");
    combo.addItem("Option Two");
    combo.addItem("Option Three");
    combo.setTextInputAllowed(false);
    combo.setNullSelectionAllowed(false);
    combo.select("Option One");
    row.addComponent(combo);

    combo = new ComboBox("Error");
    combo.setInputPrompt("You can type here");
    combo.addItem("Option One");
    combo.addItem("Option Two");
    combo.addItem("Option Three");
    combo.setNullSelectionAllowed(false);
    combo.select("Option One");
    combo.setComponentError(new UserError("Fix it, now!"));
    row.addComponent(combo);

    combo = new ComboBox("Error, borderless");
    combo.setInputPrompt("You can type here");
    combo.addItem("Option One");
    combo.addItem("Option Two");
    combo.addItem("Option Three");
    combo.setNullSelectionAllowed(false);
    combo.select("Option One");
    combo.setComponentError(new UserError("Fix it, now!"));
    combo.addStyleName("borderless");
    row.addComponent(combo);

    combo = new ComboBox("Disabled");
    combo.setInputPrompt("You can't type here");
    combo.addItem("Option One");
    combo.addItem("Option Two");
    combo.addItem("Option Three");
    combo.setEnabled(false);
    row.addComponent(combo);

    combo = new ComboBox("Custom color");
    combo.setInputPrompt("You can type here");
    combo.setContainerDataSource(MainUI.generateContainer(200, false));
    combo.setItemCaptionPropertyId(MainUI.CAPTION_PROPERTY);
    combo.setItemIconPropertyId(MainUI.ICON_PROPERTY);
    combo.addStyleName("color1");
    row.addComponent(combo);

    combo = new ComboBox("Custom color");
    combo.setInputPrompt("You can type here");
    combo.setContainerDataSource(MainUI.generateContainer(200, false));
    combo.setItemCaptionPropertyId(MainUI.CAPTION_PROPERTY);
    combo.setItemIconPropertyId(MainUI.ICON_PROPERTY);
    combo.addStyleName("color2");
    row.addComponent(combo);

    combo = new ComboBox("Custom color");
    combo.setInputPrompt("You can type here");
    combo.setContainerDataSource(MainUI.generateContainer(200, false));
    combo.setItemCaptionPropertyId(MainUI.CAPTION_PROPERTY);
    combo.setItemIconPropertyId(MainUI.ICON_PROPERTY);
    combo.addStyleName("color3");
    row.addComponent(combo);

    combo = new ComboBox("Small");
    combo.setInputPrompt("You can type here");
    combo.setContainerDataSource(MainUI.generateContainer(200, false));
    combo.setItemCaptionPropertyId(MainUI.CAPTION_PROPERTY);
    combo.setItemIconPropertyId(MainUI.ICON_PROPERTY);
    combo.addStyleName("small");
    row.addComponent(combo);

    combo = new ComboBox("Large");
    combo.setInputPrompt("You can type here");
    combo.setContainerDataSource(MainUI.generateContainer(200, false));
    combo.setItemCaptionPropertyId(MainUI.CAPTION_PROPERTY);
    combo.setItemIconPropertyId(MainUI.ICON_PROPERTY);
    combo.addStyleName("large");
    row.addComponent(combo);

    combo = new ComboBox("Borderless");
    combo.setInputPrompt("You can type here");
    combo.addItem("Option One");
    combo.addItem("Option Two");
    combo.addItem("Option Three");
    combo.addStyleName("borderless");
    row.addComponent(combo);

    combo = new ComboBox("Tiny");
    combo.setInputPrompt("You can type here");
    combo.setContainerDataSource(MainUI.generateContainer(200, false));
    combo.setItemCaptionPropertyId(MainUI.CAPTION_PROPERTY);
    combo.setItemIconPropertyId(MainUI.ICON_PROPERTY);
    combo.addStyleName("tiny");
    row.addComponent(combo);

    combo = new ComboBox("Huge");
    combo.setInputPrompt("You can type here");
    combo.setContainerDataSource(MainUI.generateContainer(200, false));
    combo.setItemCaptionPropertyId(MainUI.CAPTION_PROPERTY);
    combo.setItemIconPropertyId(MainUI.ICON_PROPERTY);
    combo.addStyleName("huge");
    row.addComponent(combo);
}

From source file:com.etest.valo.Forms.java

License:Apache License

public Forms() {
    setSpacing(true);//w  ww .  j  a v  a 2s .c om
    setMargin(true);

    Label title = new Label("Forms");
    title.addStyleName("h1");
    addComponent(title);

    final FormLayout form = new FormLayout();
    form.setMargin(false);
    form.setWidth("800px");
    form.addStyleName("light");
    addComponent(form);

    Label section = new Label("Personal Info");
    section.addStyleName("h2");
    section.addStyleName("colored");
    form.addComponent(section);
    StringGenerator sg = new StringGenerator();

    TextField name = new TextField("Name");
    name.setValue(sg.nextString(true) + " " + sg.nextString(true));
    name.setWidth("50%");
    form.addComponent(name);

    DateField birthday = new DateField("Birthday");
    birthday.setValue(new Date(80, 0, 31));
    form.addComponent(birthday);

    TextField username = new TextField("Username");
    username.setValue(sg.nextString(false) + sg.nextString(false));
    username.setRequired(true);
    form.addComponent(username);

    OptionGroup sex = new OptionGroup("Sex");
    sex.addItem("Female");
    sex.addItem("Male");
    sex.select("Male");
    sex.addStyleName("horizontal");
    form.addComponent(sex);

    section = new Label("Contact Info");
    section.addStyleName("h3");
    section.addStyleName("colored");
    form.addComponent(section);

    TextField email = new TextField("Email");
    email.setValue(sg.nextString(false) + "@" + sg.nextString(false) + ".com");
    email.setWidth("50%");
    email.setRequired(true);
    form.addComponent(email);

    TextField location = new TextField("Location");
    location.setValue(sg.nextString(true) + ", " + sg.nextString(true));
    location.setWidth("50%");
    location.setComponentError(new UserError("This address doesn't exist"));
    form.addComponent(location);

    TextField phone = new TextField("Phone");
    phone.setWidth("50%");
    form.addComponent(phone);

    HorizontalLayout wrap = new HorizontalLayout();
    wrap.setSpacing(true);
    wrap.setDefaultComponentAlignment(Alignment.MIDDLE_LEFT);
    wrap.setCaption("Newsletter");
    CheckBox newsletter = new CheckBox("Subscribe to newsletter", true);
    wrap.addComponent(newsletter);

    ComboBox period = new ComboBox();
    period.setTextInputAllowed(false);
    period.addItem("Daily");
    period.addItem("Weekly");
    period.addItem("Monthly");
    period.setNullSelectionAllowed(false);
    period.select("Weekly");
    period.addStyleName("small");
    period.setWidth("10em");
    wrap.addComponent(period);
    form.addComponent(wrap);

    section = new Label("Additional Info");
    section.addStyleName("h4");
    section.addStyleName("colored");
    form.addComponent(section);

    TextField website = new TextField("Website");
    website.setInputPrompt("http://");
    website.setWidth("100%");
    form.addComponent(website);

    TextArea shortbio = new TextArea("Short Bio");
    shortbio.setValue(
            "Quis aute iure reprehenderit in voluptate velit esse. Cras mattis iudicium purus sit amet fermentum.");
    shortbio.setWidth("100%");
    shortbio.setRows(2);
    form.addComponent(shortbio);

    final RichTextArea bio = new RichTextArea("Bio");
    bio.setWidth("100%");
    bio.setValue(
            "<div><p><span>Integer legentibus erat a ante historiarum dapibus.</span> <span>Vivamus sagittis lacus vel augue laoreet rutrum faucibus.</span> <span>A communi observantia non est recedendum.</span> <span>Morbi fringilla convallis sapien, id pulvinar odio volutpat.</span> <span>Ab illo tempore, ab est sed immemorabili.</span> <span>Quam temere in vitiis, legem sancimus haerentia.</span></p><p><span>Morbi odio eros, volutpat ut pharetra vitae, lobortis sed nibh.</span> <span>Quam diu etiam furor iste tuus nos eludet?</span> <span>Cum sociis natoque penatibus et magnis dis parturient.</span> <span>Quam diu etiam furor iste tuus nos eludet?</span> <span>Tityre, tu patulae recubans sub tegmine fagi  dolor.</span></p><p><span>Curabitur blandit tempus ardua ridiculus sed magna.</span> <span>Phasellus laoreet lorem vel dolor tempus vehicula.</span> <span>Etiam habebis sem dicantur magna mollis euismod.</span> <span>Hi omnes lingua, institutis, legibus inter se differunt.</span></p></div>");
    form.addComponent(bio);

    form.setReadOnly(true);
    bio.setReadOnly(true);

    Button edit = new Button("Edit", new ClickListener() {
        @Override
        public void buttonClick(ClickEvent event) {
            boolean readOnly = form.isReadOnly();
            if (readOnly) {
                bio.setReadOnly(false);
                form.setReadOnly(false);
                form.removeStyleName("light");
                event.getButton().setCaption("Save");
                event.getButton().addStyleName("primary");
            } else {
                bio.setReadOnly(true);
                form.setReadOnly(true);
                form.addStyleName("light");
                event.getButton().setCaption("Edit");
                event.getButton().removeStyleName("primary");
            }
        }
    });

    HorizontalLayout footer = new HorizontalLayout();
    footer.setMargin(new MarginInfo(true, false, true, false));
    footer.setSpacing(true);
    footer.setDefaultComponentAlignment(Alignment.MIDDLE_LEFT);
    form.addComponent(footer);
    footer.addComponent(edit);

    Label lastModified = new Label("Last modified by you a minute ago");
    lastModified.addStyleName("light");
    footer.addComponent(lastModified);
}

From source file:com.freebox.engeneering.application.view.AbstractFieldGroup.java

License:Apache License

/**
 * Sets component error to field group layout
 *
 * @param localizedMessage - localized message
 *//*w  w  w  . ja v a  2 s . com*/
public void setComponentError(String localizedMessage) {
    getContent().setComponentError(new UserError(localizedMessage));
}

From source file:com.gnts.asm.txn.AssetDetails.java

License:Open Source License

@Override
protected void validateDetails() throws ValidationException {
    boolean errorflag = false;
    logger.info("Company ID : " + companyid + " | User Name : " + username + " > " + "Validating Data ");
    if (tfAssetName.getValue() == null || tfAssetName.getValue().trim().length() == 0) {
        tfAssetName.setComponentError(new UserError(GERPErrorCodes.NULL_ASSET_NAME));
        errorflag = true;//from w w w .  j a v a 2s. c o  m
    } else {
        tfAssetName.setComponentError(null);
    }
    if ((cbAssetType.getValue() == null)) {
        cbAssetType.setComponentError(new UserError(GERPErrorCodes.NULL_ASSET_TYPE));
        errorflag = true;
    } else {
        cbAssetType.setComponentError(null);
    }
    if ((tfAssetLocation.getValue() == null || tfAssetLocation.getValue().trim().length() == 0)) {
        tfAssetLocation.setComponentError(new UserError(GERPErrorCodes.NULL_ASSET_LOCATION));
        errorflag = true;
    } else {
        tfAssetLocation.setComponentError(null);
    }
    if ((cbBrand.getValue() == null)) {
        cbBrand.setComponentError(new UserError(GERPErrorCodes.NULL_ASST_BRAND_NAME));
        errorflag = true;
    } else {
        cbBrand.setComponentError(null);
    }
    if ((cbCategory.getValue() == null)) {
        cbCategory.setComponentError(new UserError(GERPErrorCodes.NULL_CATGRY_NAME));
        errorflag = true;
    } else {
        cbCategory.setComponentError(null);
    }
    if ((cbDept.getValue() == null)) {
        cbDept.setComponentError(new UserError(GERPErrorCodes.NULL_DEPT_NAME));
        errorflag = true;
    } else {
        cbDept.setComponentError(null);
    }
    if (errorflag) {
        logger.warn("Company ID : " + companyid + " | User Name : " + username + " > "
                + "Throwing ValidationException. User data is > " + tfAssetName.getValue());
        throw new ERPException.ValidationException();
    }
}