Example usage for com.vaadin.ui TextArea setValue

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

Introduction

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

Prototype

@Override
public void setValue(String value) 

Source Link

Document

Sets the value of this text field.

Usage

From source file:de.uni_tuebingen.qbic.qbicmainportlet.MultiscaleComponent.java

License:Open Source License

void buildEmptyComments() {

    // add comments
    VerticalLayout addComment = new VerticalLayout();
    addComment.setMargin(true);//from   w  ww.  ja va2 s. c o m
    addComment.setWidth(100, Unit.PERCENTAGE);
    final TextArea comments = new TextArea();
    comments.setInputPrompt("Write your comment here...");
    comments.setWidth(100, Unit.PERCENTAGE);
    comments.setRows(2);
    Button commentsOk = new Button("Add Comment");
    commentsOk.addStyleName(ValoTheme.BUTTON_FRIENDLY);
    commentsOk.addClickListener(new ClickListener() {
        /**
         * 
         */
        private static final long serialVersionUID = -5369241494545155677L;

        public void buttonClick(ClickEvent event) {
            if ("".equals(comments.getValue()))
                return;

            String newComment = comments.getValue();
            // reset comments
            comments.setValue("");
            // use some date format
            Date dNow = new Date();
            SimpleDateFormat ft = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");

            Note note = new Note();
            note.setComment(newComment);
            note.setUsername(controller.getUser());
            note.setTime(ft.format(dNow));

            // show it now
            // pastcomments.getContainerDataSource().addItem(note);
            notes.add(note);

            // TODO write back
            Label commentsLabel = new Label(translateComments(notes), ContentMode.HTML);
            commentsPanel.setContent(commentsLabel);

            // write back to openbis
            if (!controller.addNote(note)) {
                Notification.show("Could not add comment to sample. How did you do that?");
            }

        }

    });

    HorizontalLayout inputPrompt = new HorizontalLayout();
    inputPrompt.addComponent(comments);
    inputPrompt.addComponent(commentsOk);

    inputPrompt.setWidth(50, Unit.PERCENTAGE);
    inputPrompt.setComponentAlignment(commentsOk, Alignment.TOP_RIGHT);
    inputPrompt.setExpandRatio(comments, 1.0f);

    // addComment.addComponent(comments);
    // addComment.addComponent(commentsOk);

    addComment.addComponent(commentsPanel);
    addComment.addComponent(inputPrompt);

    // addComment.setComponentAlignment(comments, Alignment.TOP_CENTER);
    // addComment.setComponentAlignment(commentsOk, Alignment.MIDDLE_CENTER);

    addComment.setComponentAlignment(commentsPanel, Alignment.TOP_CENTER);
    addComment.setComponentAlignment(inputPrompt, Alignment.MIDDLE_CENTER);

    mainlayout.addComponent(addComment);

    // mainlayout.addComponent(pastcomments);
    Label commentsLabel = new Label("No comments added so far.", ContentMode.HTML);
    commentsPanel.setContent(commentsLabel);

    // mainlayout.addComponent(commentsPanel);
    // mainlayout.setComponentAlignment(commentsPanel,
    // Alignment.TOP_CENTER);
}

From source file:edu.nps.moves.mmowgli.modules.actionplans.HelpWantedDialog.java

License:Open Source License

@SuppressWarnings("serial")
@HibernateSessionThreadLocalConstructor/*w ww.  jav  a2 s . c om*/
public HelpWantedDialog(final Object aplnId, boolean interested) {
    setCaption(interested ? "Express Interest in Action Plan" : "Offer Assistance with Action Plan");
    setModal(true);
    setSizeUndefined();
    setWidth("500px");
    setHeight("550px");

    VerticalLayout vLay = new VerticalLayout();
    setContent(vLay);
    vLay.setMargin(true);
    vLay.setSpacing(true);
    vLay.setSizeFull();

    StringBuilder sb = new StringBuilder();

    ActionPlan ap = ActionPlan.getTL(aplnId);
    String s = ap.getHelpWanted();

    if (s != null) {
        vLay.addComponent(new Label(msg1));
        Label helpWantedLab = new Label(s);
        helpWantedLab.addStyleName("m-helpWantedLabel");
        helpWantedLab.setWidth("100%");
        vLay.addComponent(helpWantedLab);
    }

    vLay.addComponent(new Label(msg2));
    final TextArea toTA = new TextArea("To");
    toTA.addStyleName("m-textareaboldcaption");
    toTA.setWidth("100%");
    toTA.setRows(1);
    toTA.setNullRepresentation("");
    toTA.setValue(getAuthors(sb, ap));
    vLay.addComponent(toTA);

    final TextArea ccTA = new TextArea("CC");
    ccTA.addStyleName("m-textareaboldcaption");
    ccTA.setWidth("100%");
    ccTA.setRows(1);
    ccTA.setNullRepresentation("");

    PagesData pd = new PagesData();
    ccTA.setValue(pd.gettroubleMailto());

    vLay.addComponent(ccTA);

    final TextArea subjTA = new TextArea("Subject");
    subjTA.addStyleName("m-textareaboldcaption");
    subjTA.setWidth("100%");
    subjTA.setRows(2);
    subjTA.setNullRepresentation("");
    sb.setLength(0);
    sb.append("My interest in Action Plan ");
    sb.append(ap.getId());
    sb.append(", \"");
    sb.append(ap.getTitle());
    sb.append('"');
    subjTA.setValue(sb.toString());
    vLay.addComponent(subjTA);

    final TextArea msgTA = new TextArea("Message");
    msgTA.addStyleName("m-textareaboldcaption");
    msgTA.setWidth("100%");
    msgTA.setHeight("100%");
    msgTA.setNullRepresentation("");
    vLay.addComponent(msgTA);
    vLay.setExpandRatio(msgTA, 1.0f);

    HorizontalLayout buttLay = new HorizontalLayout();
    vLay.addComponent(buttLay);
    buttLay.setSpacing(true);
    buttLay.setWidth("100%");
    Label sp;
    buttLay.addComponent(sp = new Label());
    sp.setHeight("1px");
    buttLay.setExpandRatio(sp, 1.0f);

    Button canButt = new Button("Cancel");
    buttLay.addComponent(canButt);

    Button sendButt = new Button("Send to authors");
    buttLay.addComponent(sendButt);

    canButt.addClickListener(new ClickListener() {
        @Override
        public void buttonClick(ClickEvent event) {
            UI.getCurrent().removeWindow(HelpWantedDialog.this);
        }
    });

    sendButt.addClickListener(new ClickListener() {
        @Override
        @MmowgliCodeEntry
        @HibernateOpened
        @HibernateClosed
        public void buttonClick(ClickEvent event) {
            Object tos = toTA.getValue();
            if (tos == null || tos.toString().length() <= 0) {
                Notification.show("No recipients", Notification.Type.ERROR_MESSAGE);
                return;
            }
            Object cc = ccTA.getValue();
            if (cc == null || cc.toString().length() <= 0)
                cc = null;

            Object msg = msgTA.getValue();
            if (msg == null || msg.toString().length() <= 0) {
                Notification.show("No Message", Notification.Type.ERROR_MESSAGE);
                return;
            }
            Object subj = subjTA.getValue();
            if (subj == null)
                subj = "";

            HSess.init();

            List<User> authors = parseAuthorsTL(tos.toString().trim());
            MmowgliSessionGlobals globs = Mmowgli2UI.getGlobals();
            MailManager mmgr = AppMaster.instance().getMailManager();
            User me = globs.getUserTL();
            for (User u : authors) {
                mmgr.mailToUserTL(me.getId(), u.getId(), subj.toString(), msg.toString());
            }

            if (cc == null)
                mmgr.mailToUserTL(me.getId(), me.getId(), "(CC:)" + subj.toString(), msg.toString());
            else
                mmgr.mailToUserTL(me.getId(), me.getId(), subj.toString(), msg.toString(), cc.toString(),
                        MailManager.Channel.BOTH); // the cc is an email, not a user name

            UI.getCurrent().removeWindow(HelpWantedDialog.this);
            Notification.show("Message(s) sent", Notification.Type.HUMANIZED_MESSAGE); // fixed 21 Jan 2015

            HSess.close();
        }
    });
}

From source file:edu.nps.moves.mmowgli.modules.administration.ActionPlansGameDesignPanel.java

License:Open Source License

@HibernateSessionThreadLocalConstructor
public ActionPlansGameDesignPanel(GameDesignGlobals globs) {
    super(false, globs);
    Game game = Game.getTL(1L);//from  www .  jav a2s .  c o m
    String thePlanTxt = game.getDefaultActionPlanThePlanText();
    String talkTxt = game.getDefaultActionPlanTalkText();
    String imagesTxt = game.getDefaultActionPlanImagesText();
    String videosTxt = game.getDefaultActionPlanVideosText();
    String mapTxt = game.getDefaultActionPlanMapText();

    TextArea ta;
    ta = (TextArea) addEditLine("1 \"The Plan\" Tab Instructions", "Game.defaultActionPlanThePlanText", game,
            game.getId(), "DefaultActionPlanThePlanText").ta;
    ta.setValue(thePlanTxt);
    ta.setRows(5);
    ta = (TextArea) addEditLine("2 \"Talk it Over\" Tab Instructions", "Game.defaultActionPlanTalkText", game,
            game.getId(), "DefaultActionPlanTalkText").ta;
    ta.setValue(talkTxt);
    ta.setRows(5);
    ta = (TextArea) addEditLine("3 Images Tab Instructions", "Game.defaultActionPlanImagesText", game,
            game.getId(), "DefaultActionPlanImagesText").ta;
    ta.setValue(imagesTxt);
    ta.setRows(5);
    ta = (TextArea) addEditLine("4 Videos Tab Instructions", "Game.defaultActionPlanVideosText", game,
            game.getId(), "DefaultActionPlanVideosText").ta;
    ta.setValue(videosTxt);
    ta.setRows(5);
    ta = (TextArea) addEditLine("5 Map Tab Instructions", "Game.defaultActionPlanMapText", game, game.getId(),
            "DefaultActionPlanMapText").ta;
    ta.setValue(mapTxt);
    ta.setRows(5);

}

From source file:edu.nps.moves.mmowgli.modules.administration.MapGameDesignPanel.java

License:Open Source License

@HibernateSessionThreadLocalConstructor
@SuppressWarnings("serial")
public MapGameDesignPanel(GameDesignGlobals globs) {
    super(false, globs);
    Game g = Game.getTL();/*from   w ww  . ja  v a2 s .c om*/
    TextArea titleTA;
    final Serializable uid = Mmowgli2UI.getGlobals().getUserID();

    titleTA = (TextArea) addEditLine("Map Title", "Game.mapTitle", g, g.getId(), "MapTitle").ta;
    titleTA.setValue(g.getMapTitle());
    titleTA.setRows(1);

    latTA = addEditLine("Map Initial Latitude", "Game.mmowgliMapLatitude");
    boolean lastRO = latTA.isReadOnly();
    latTA.setReadOnly(false);
    latTA.setValue("" + g.getMapLatitude());
    latTA.setRows(1);
    latTA.setReadOnly(lastRO);
    latTA.addValueChangeListener(new Property.ValueChangeListener() {
        @Override
        @MmowgliCodeEntry
        @HibernateOpened
        @HibernateClosed
        public void valueChange(ValueChangeEvent event) {
            HSess.init();
            try {
                String val = event.getProperty().getValue().toString();
                double lat = Double.parseDouble(val);
                Game g = Game.getTL();
                g.setMapLatitude(lat);
                Game.updateTL();
                GameEventLogger.logGameDesignChangeTL("Map latitude", val, uid);
            } catch (Exception ex) {
                new Notification("Parameter error",
                        "<html>Check for proper decimal format.</br>New value not committed.",
                        Notification.Type.WARNING_MESSAGE, true).show(Page.getCurrent());
            }
            HSess.close();
        }
    });

    lonTA = addEditLine("Map Initial Longitude", "Game.mmowgliMapLongitude");
    lastRO = lonTA.isReadOnly();
    lonTA.setReadOnly(false);
    lonTA.setValue("" + g.getMapLongitude());
    lonTA.setRows(1);
    lonTA.setReadOnly(lastRO);
    lonTA.addValueChangeListener(new Property.ValueChangeListener() {
        @Override
        @MmowgliCodeEntry
        @HibernateOpened
        @HibernateClosed
        public void valueChange(ValueChangeEvent event) {
            //System.out.println("lon valueChange");
            HSess.init();
            try {
                String val = event.getProperty().getValue().toString();
                double lon = Double.parseDouble(val);
                Game g = Game.getTL();
                g.setMapLongitude(lon);
                Game.updateTL();
                GameEventLogger.logGameDesignChangeTL("Map longitude", val, uid);
            } catch (Exception ex) {
                new Notification("Parameter error",
                        "<html>Check for proper decimal format.</br>New value not committed.",
                        Notification.Type.WARNING_MESSAGE, true).show(Page.getCurrent());
            }
            HSess.close();
        }
    });

    zoomTA = addEditLine("Map Initial Zoom", "Game.mmowgliMapZoom");
    lastRO = zoomTA.isReadOnly();
    zoomTA.setReadOnly(false);
    zoomTA.setValue("" + g.getMapZoom());
    zoomTA.setRows(1);
    zoomTA.setReadOnly(lastRO);
    zoomTA.addValueChangeListener(new Property.ValueChangeListener() {
        @Override
        @MmowgliCodeEntry
        @HibernateOpened
        @HibernateClosed
        public void valueChange(ValueChangeEvent event) {
            HSess.init();
            try {
                String val = event.getProperty().getValue().toString();
                int zoom = Integer.parseInt(val);
                Game g = Game.getTL();
                g.setMapZoom(zoom);
                Game.updateTL();
                GameEventLogger.logGameDesignChangeTL("Map zoom", val, uid);
            } catch (Exception ex) {
                new Notification("Parameter error",
                        "Check for proper integer format.</br>New value not committed.",
                        Notification.Type.WARNING_MESSAGE, true).show(Page.getCurrent());
            }
            HSess.close();
        }
    });
    Button b;
    this.addComponentLine(b = new Button("Set to generic Mmowgli Map Defaults", new MapDefaultSetter()));
    b.setEnabled(!globs.readOnlyCheck(false));
}

From source file:edu.nps.moves.mmowgli.modules.administration.ReportsGameDesignPanel.java

License:Open Source License

@HibernateSessionThreadLocalConstructor
@SuppressWarnings("serial")
public ReportsGameDesignPanel(GameDesignGlobals globs) {
    super(false, globs);
    Game g = Game.getTL();/* w ww.j a v a 2 s . co  m*/
    long period = g.getReportIntervalMinutes();

    TextArea ta;

    ta = addEditLine("1 Game Reports publishing interval (minutes)", "Game.reportIntervalMinutes");
    boolean lastRO = ta.isReadOnly();
    ta.setReadOnly(false);
    ta.setValue("" + period);
    ta.setRows(1);
    ta.setReadOnly(lastRO);
    ta.addValueChangeListener(new Property.ValueChangeListener() {
        @Override
        @MmowgliCodeEntry
        @HibernateOpened
        @HibernateClosed
        public void valueChange(ValueChangeEvent event) {
            //System.out.println("msid valueChange");
            HSess.init();
            try {
                String val = event.getProperty().getValue().toString();
                long lg = Long.parseLong(val);
                if (lg < 0)
                    throw new Exception();

                MmowgliSessionGlobals globs = Mmowgli2UI.getGlobals();
                Game gm = Game.getTL(1L);
                gm.setReportIntervalMinutes(lg);
                Game.updateTL();
                GameEventLogger.logGameDesignChangeTL("Report interval", "" + "" + lg, globs.getUserID());

                // Wake it up
                AppMaster.instance().pokeReportGenerator();
            } catch (Exception ex) {
                new Notification("Parameter error",
                        "<html>Check for proper positive integer format.</br>New value not committed.",
                        Notification.Type.WARNING_MESSAGE, true).show(Page.getCurrent());
            }
            HSess.close();
        }
    });
    addEditBoolean("2 Indicate PDF reports available", "Game.pdfAvailable", g, 1L, "PdfAvailable");
    addEditBoolean("2 Show hidden cards", "Game.reportsShowHiddenCards", g, 1L, "ReportsShowHiddenCards");
}

From source file:edu.nps.moves.mmowgli.modules.administration.ScoringGameDesignPanel.java

License:Open Source License

@HibernateSessionThreadLocalConstructor
public ScoringGameDesignPanel(GameDesignGlobals globs) {
    super(false, globs);
    Game g = Game.getTL();//  w  ww . ja v  a 2s . c o m
    TextArea ta = (TextArea) addEditLine("Card authorship points", "Game.cardAuthorPoints", g, 1L,
            "CardAuthorPoints", null, Float.class, "Points for the author on card creation").ta;
    ta.setValue("" + g.getCardAuthorPoints());
    setupFloatValueListener(ta);
    ta.setRows(1);

    ta = (TextArea) addEditLine("Card ancestor points", "Game.cardAncestorPoints", g, 1L, "CardAncestorPoints",
            null, Float.class, "Point bonus (adjusted by factor below) for card parents").ta;
    ta.setValue("" + g.getCardAncestorPoints());
    setupFloatValueListener(ta);
    ta.setRows(1);

    ta = (TextArea) addEditLine("Card ancestor generation factors", "Game.cardAncestorPointsGenerationFactors",
            g, 1L, "CardAncestorPointsGenerationFactors", null, String.class,
            "Factors multiplied by ancestor points to calculate ancestor card points").ta;
    ta.setValue(g.getCardAncestorPointsGenerationFactors());
    setupFactorsListener(ta);
    ta.setRows(1);
    /*
        addEditBoolean("Earliest ancestor highest reward", "Game.cardAncestorEarlyPointsBias", g, 1L, "CardAncestorEarlyPointsBias",
            "Default is ON, meaning the ancestor increment factor favors the author of earliest card instead of the nearest ancestor card");
    */
    addSeparator();

    ta = (TextArea) addEditLine("Card super-interesting bonus points", "Game.cardSuperInterestingPoints", g, 1L,
            "CardSuperInterestingPoints", null, Float.class,
            "Points added to card author when card is marked super-interesting (points removed if card unmarked)").ta;
    ta.setValue("" + g.getCardSuperInterestingPoints());
    setupFloatValueListener(ta);
    ta.setRows(1);

    if (Game.getTL().isActionPlansEnabled()) {
        addSeparator();

        ta = (TextArea) addEditLine("Action plan authorship points", "Game.actionPlanAuthorPoints", g, 1L,
                "ActionPlanAuthorPoints", null, Float.class,
                "Points awarded to players who accept action plan authorship invitations").ta;
        ta.setValue("" + g.getActionPlanAuthorPoints());
        setupFloatValueListener(ta);
        ta.setRows(1);

        //    ta = (TextArea)addEditLine("Action plan thumb points", "Game.actionPlanThumbPoints", g, 1L, "ActionPlanThumbPoints",null,Float.class,
        //        "Point bonus (adusted by factor) based on ").ta;
        //    ta.setValue(g.getActionPlanThumbPoints());
        //    ta.setRows(1);
        //
        ta = (TextArea) addEditLine("Action plan thumb factor", "Game.actionPlanThumbFactor", g, 1L,
                "ActionPlanThumbFactor", null, Float.class,
                "A point bonus for each plan author is calulated by the product of this factor and total user thumb ratings").ta;
        ta.setValue("" + g.getActionPlanThumbFactor());
        setupFloatValueListener(ta);
        ta.setRows(1);

        ta = (TextArea) addEditLine("Action plan comment points", "Game.actionPlanCommentPoints", g, 1L,
                "ActionPlanCommentPoints", null, Float.class,
                "Point bonus for each plan author when a non-author comment is entered").ta;
        ta.setValue("" + g.getActionPlanCommentPoints());
        setupFloatValueListener(ta);
        ta.setRows(1);

        ta = (TextArea) addEditLine("Action plan rater points", "Game.actionPlanRaterPoints", g, 1L,
                "ActionPlanRaterPoints", null, Float.class,
                "Point bonus to player for first rating an action plan -- removed if unrated").ta;
        ta.setValue("" + g.getActionPlanRaterPoints());
        setupFloatValueListener(ta);
        ta.setRows(1);

        ta = (TextArea) addEditLine("Action plan commenter points", "Game.userActionPlanCommentPoints", g, 1L,
                "UserActionPlanCommentPoints", null, Float.class,
                "Point bonus for commenter when posting a comment to an action plan.").ta;
        ta.setValue("" + g.getUserActionPlanCommentPoints());
        setupFloatValueListener(ta);
        ta.setRows(1);
    }
    /*
        addSeparator();
            
        ta = (TextArea)addEditLine("Action plan super-interesting bonus points", "Game.cardSuperInterestingPoints", g, 1L, "CardSuperInterestingPoints",null,Float.class,
            "Point bonus for each plan author when a plan is marked \"super-interesting\" by a game-master (points removed if plan unmarked)").ta;
        ta.setValue(g.getCardSuperInterestingPoints());
        setupFloatValueListener(ta);
        ta.setRows(1);
    */
    addSeparator();

    ta = (TextArea) addEditLine("New user bonus for answering registration question",
            "Game.userSignupAnswerPoints", g, 1L, "UserSignupAnswerPoints", null, Float.class,
            "Point bonus if a new user chooses to answer the optional question posed during the registration process").ta;
    ta.setValue("" + g.getUserSignupAnswerPoints());
    setupFloatValueListener(ta);
    ta.setRows(1);
}

From source file:edu.nps.moves.mmowgli.modules.administration.SeedCardsGameDesignPanel.java

License:Open Source License

private void makeEditLines(Card[] arr) {
    TextArea ta;
    for (int n = 0; n < arr.length; n++) {
        Card cd = arr[n];/*ww w  .  j  a  va  2 s  . c  om*/
        String hidn = cd.isHidden() ? " (hidden)" : "";
        String type = cd.getCardType().getTitle();
        ta = (TextArea) addEditLine("" + (n + 1) + " " + type + " Seed Card" + hidn, "Card.text", cd,
                cd.getId(), "Text").ta;
        ta.setValue(cd.getText());
    }
}

From source file:edu.nps.moves.mmowgli.modules.userprofile.DefineAwardsDialog.java

License:Open Source License

private TextArea makeTa(String val) {
    TextArea tf = new TextArea();
    tf.setRows(2);//from  w  w w.j av a2 s.  c o  m
    tf.setValue(val);
    tf.setWidth("100%");
    return tf;
}

From source file:eu.maxschuster.vaadin.signaturefield.demo.DemoUI.java

License:Apache License

@Override
protected void init(VaadinRequest request) {

    getPage().setTitle(pageTitle);//from w  w  w .j  av  a 2 s  .  c o m

    final VerticalLayout margin = new VerticalLayout();
    setContent(margin);

    final VerticalLayout layout = new VerticalLayout();
    layout.setMargin(true);
    layout.setSpacing(true);
    layout.setWidth("658px");
    margin.addComponent(layout);
    margin.setComponentAlignment(layout, Alignment.TOP_CENTER);

    final Label header1 = new Label(pageTitle);
    header1.addStyleName("h1");
    header1.setSizeUndefined();
    layout.addComponent(header1);
    layout.setComponentAlignment(header1, Alignment.TOP_CENTER);

    final TabSheet tabSheet = new TabSheet();
    tabSheet.setWidth("100%");
    layout.addComponent(tabSheet);
    layout.setComponentAlignment(tabSheet, Alignment.TOP_CENTER);

    final Panel signaturePanel = new Panel();
    signaturePanel.addStyleName("signature-panel");
    signaturePanel.setWidth("100%");
    tabSheet.addTab(signaturePanel, "Demo");

    final VerticalLayout signatureLayout = new VerticalLayout();
    signatureLayout.setMargin(true);
    signatureLayout.setSpacing(true);
    signatureLayout.setSizeFull();
    signaturePanel.setContent(signatureLayout);

    final SignatureField signatureField = new SignatureField();
    signatureField.setWidth("100%");
    signatureField.setHeight("318px");
    signatureField.setPenColor(Color.ULTRAMARINE);
    signatureField.setBackgroundColor("white");
    signatureField.setConverter(new StringToDataUrlConverter());
    signatureField.setPropertyDataSource(dataUrlProperty);
    signatureField.setVelocityFilterWeight(0.7);
    signatureLayout.addComponent(signatureField);
    signatureLayout.setComponentAlignment(signatureField, Alignment.MIDDLE_CENTER);

    final HorizontalLayout buttonLayout = new HorizontalLayout();
    buttonLayout.setSpacing(true);
    buttonLayout.setWidth("100%");
    signatureLayout.addComponent(buttonLayout);

    final Button clearButton = new Button("Clear", new ClickListener() {

        @Override
        public void buttonClick(ClickEvent event) {
            signatureField.clear();
        }
    });
    buttonLayout.addComponent(clearButton);
    buttonLayout.setComponentAlignment(clearButton, Alignment.MIDDLE_LEFT);

    final Label message = new Label("Sign above");
    message.setSizeUndefined();
    buttonLayout.addComponent(message);
    buttonLayout.setComponentAlignment(message, Alignment.MIDDLE_CENTER);

    final ButtonLink saveButtonLink = new ButtonLink("Save", null);
    saveButtonLink.setTargetName("_blank");
    buttonLayout.addComponent(saveButtonLink);
    buttonLayout.setComponentAlignment(saveButtonLink, Alignment.MIDDLE_RIGHT);

    final Panel optionsPanel = new Panel();
    optionsPanel.setSizeFull();
    tabSheet.addTab(optionsPanel, "Options");

    final FormLayout optionsLayout = new FormLayout();
    optionsLayout.setMargin(true);
    optionsLayout.setSpacing(true);
    optionsPanel.setContent(optionsLayout);

    final ComboBox mimeTypeComboBox = new ComboBox(null, mimeTypeContainer);
    optionsLayout.addComponent(mimeTypeComboBox);
    mimeTypeComboBox.setItemCaptionPropertyId("mimeType");
    mimeTypeComboBox.setNullSelectionAllowed(false);
    mimeTypeComboBox.addValueChangeListener(new ValueChangeListener() {

        @Override
        public void valueChange(ValueChangeEvent event) {
            MimeType mimeType = (MimeType) event.getProperty().getValue();
            signatureField.setMimeType(mimeType);
        }
    });
    mimeTypeComboBox.setValue(MimeType.PNG);
    mimeTypeComboBox.setCaption("Result MIME-Type");

    final CheckBox immediateCheckBox = new CheckBox("immediate", false);
    optionsLayout.addComponent(immediateCheckBox);
    immediateCheckBox.addValueChangeListener(new ValueChangeListener() {

        @Override
        public void valueChange(ValueChangeEvent event) {
            boolean immediate = (Boolean) event.getProperty().getValue();
            signatureField.setImmediate(immediate);
        }
    });

    final CheckBox readOnlyCheckBox = new CheckBox("readOnly", false);
    optionsLayout.addComponent(readOnlyCheckBox);
    readOnlyCheckBox.addValueChangeListener(new ValueChangeListener() {

        @Override
        public void valueChange(ValueChangeEvent event) {
            boolean readOnly = (Boolean) event.getProperty().getValue();
            signatureField.setReadOnly(readOnly);
            mimeTypeComboBox.setReadOnly(readOnly);
            clearButton.setEnabled(!readOnly);
        }
    });

    final CheckBox requiredCheckBox = new CheckBox("required (causes bug that clears field)", false);
    optionsLayout.addComponent(requiredCheckBox);
    requiredCheckBox.addValueChangeListener(new ValueChangeListener() {

        @Override
        public void valueChange(ValueChangeEvent event) {
            boolean required = (Boolean) event.getProperty().getValue();
            signatureField.setRequired(required);
        }
    });

    final CheckBox clearButtonEnabledButton = new CheckBox("clearButtonEnabled", false);
    optionsLayout.addComponent(clearButtonEnabledButton);
    clearButtonEnabledButton.addValueChangeListener(new ValueChangeListener() {

        @Override
        public void valueChange(ValueChangeEvent event) {
            boolean clearButtonEnabled = (Boolean) event.getProperty().getValue();
            signatureField.setClearButtonEnabled(clearButtonEnabled);
        }
    });

    final Panel resultPanel = new Panel("Results:");
    resultPanel.setWidth("100%");
    layout.addComponent(resultPanel);

    final VerticalLayout resultLayout = new VerticalLayout();
    resultLayout.setMargin(true);
    resultPanel.setContent(resultLayout);

    final Image stringPreviewImage = new Image("String preview image:");
    stringPreviewImage.setWidth("500px");
    resultLayout.addComponent(stringPreviewImage);

    final Image dataUrlPreviewImage = new Image("DataURL preview image:");
    dataUrlPreviewImage.setWidth("500px");
    resultLayout.addComponent(dataUrlPreviewImage);

    final TextArea textArea = new TextArea("DataURL:");
    textArea.setWidth("100%");
    textArea.setHeight("300px");
    resultLayout.addComponent(textArea);

    final Label emptyLabel = new Label();
    emptyLabel.setCaption("Is Empty:");
    emptyLabel.setValue(String.valueOf(signatureField.isEmpty()));
    resultLayout.addComponent(emptyLabel);

    signatureField.addValueChangeListener(new ValueChangeListener() {

        @Override
        public void valueChange(ValueChangeEvent event) {
            String signature = (String) event.getProperty().getValue();
            stringPreviewImage.setSource(signature != null ? new ExternalResource(signature) : null);
            textArea.setValue(signature);
            emptyLabel.setValue(String.valueOf(signatureField.isEmpty()));
        }
    });
    dataUrlProperty.addValueChangeListener(new ValueChangeListener() {

        @Override
        public void valueChange(ValueChangeEvent event) {
            try {
                final DataUrl signature = (DataUrl) event.getProperty().getValue();
                dataUrlPreviewImage.setSource(
                        signature != null ? new ExternalResource(serializer.serialize(signature)) : null);
                StreamResource streamResource = null;
                if (signature != null) {
                    StreamSource streamSource = new StreamSource() {

                        @Override
                        public InputStream getStream() {
                            return new ByteArrayInputStream(signature.getData());
                        }
                    };
                    MimeType mimeType = MimeType.valueOfMimeType(signature.getMimeType());
                    String extension = null;

                    switch (mimeType) {
                    case JPEG:
                        extension = "jpg";
                        break;
                    case PNG:
                        extension = "png";
                        break;
                    }

                    streamResource = new StreamResource(streamSource, "signature." + extension);
                    streamResource.setMIMEType(signature.getMimeType());
                    streamResource.setCacheTime(0);
                }
                saveButtonLink.setResource(streamResource);
            } catch (MalformedURLException e) {
                logger.error(e.getMessage(), e);
            }
        }
    });
}

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);//from   w  ww.j av  a2s. c o m
    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());

}