Example usage for com.vaadin.ui TextArea setCursorPosition

List of usage examples for com.vaadin.ui TextArea setCursorPosition

Introduction

In this page you can find the example usage for com.vaadin.ui TextArea setCursorPosition.

Prototype

public void setCursorPosition(int pos) 

Source Link

Document

Sets the cursor position in the field.

Usage

From source file:fi.semantum.strategia.Utils.java

License:Open Source License

public static void editTextAndId(final Main main, String title, final Base container) {

    final Database database = main.getDatabase();

    final Window subwindow = new Window(title, new VerticalLayout());
    subwindow.setModal(true);/* ww  w  .  jav a  2  s . c om*/
    subwindow.setWidth("400px");
    subwindow.setHeight("500px");
    subwindow.setResizable(false);

    VerticalLayout winLayout = (VerticalLayout) subwindow.getContent();
    winLayout.setMargin(true);
    winLayout.setSpacing(true);

    final TextField tf = new TextField();
    tf.setCaption("Lyhytnimi:");
    tf.addStyleName(ValoTheme.TEXTFIELD_SMALL);
    tf.setValue(container.getId(database));
    tf.setWidth("100%");
    winLayout.addComponent(tf);

    final TextArea ta = new TextArea();
    ta.setCaption("Teksti:");
    ta.setValue(container.getText(database));
    ta.setWidth("100%");
    ta.setHeight("290px");
    winLayout.addComponent(ta);

    Button save = new Button("Tallenna", new Button.ClickListener() {

        private static final long serialVersionUID = 6641880870005364983L;

        public void buttonClick(ClickEvent event) {
            String idValue = tf.getValue();
            String value = ta.getValue();
            main.removeWindow(subwindow);
            container.modifyId(main, idValue);
            container.modifyText(main, value);
            Collection<String> tags = Tag.extractTags(value);
            database.assertTags(tags);
            ArrayList<Tag> tagObjects = new ArrayList<Tag>();
            for (String s : tags)
                tagObjects.add(database.getOrCreateTag(s));
            container.assertRelatedTags(database, tagObjects);
            Updates.update(main, true);
            Property emails = Property.find(database, Property.EMAIL);
            String addr = emails.getPropertyValue(container);
            if (addr != null && !addr.isEmpty()) {
                String[] addrs = addr.split(",");
                if (addrs.length > 0) {
                    try {
                        Email.send(addrs, "Muutos strategiakartassa: " + container.getId(database),
                                "Kyttj " + main.account.getId(database)
                                        + " on muuttanut strategiakarttaa.<br/><br/>Lyhytnimi: "
                                        + container.getId(database) + "<br/><br/>Teksti: "
                                        + container.getText(database));
                    } catch (MessagingException e) {
                        e.printStackTrace();
                    }
                }
            }
        }

    });

    Button discard = new Button("Peru muutokset", new Button.ClickListener() {

        private static final long serialVersionUID = -784522457615993823L;

        public void buttonClick(ClickEvent event) {
            Updates.update(main, true);
            main.removeWindow(subwindow);
        }

    });

    HorizontalLayout hl2 = new HorizontalLayout();
    hl2.setSpacing(true);
    hl2.addComponent(save);
    hl2.addComponent(discard);
    winLayout.addComponent(hl2);
    winLayout.setComponentAlignment(hl2, Alignment.MIDDLE_CENTER);
    main.addWindow(subwindow);

    ta.setCursorPosition(ta.getValue().length());

}