Example usage for com.vaadin.ui RichTextArea RichTextArea

List of usage examples for com.vaadin.ui RichTextArea RichTextArea

Introduction

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

Prototype

public RichTextArea() 

Source Link

Document

Constructs an empty RichTextArea with no caption.

Usage

From source file:ac.uk.icl.dell.vaadin.glycanbuilder.ImportStructureFromStringDialog.java

License:Open Source License

private void initComponents() {
    importTypeSelectField = new Select("Sequence format", theCanvas.getImportFormats());
    importTypeSelectField.setNewItemsAllowed(false);
    importTypeSelectField.setNullSelectionAllowed(false);

    sequenceInputField = new RichTextArea();
    sequenceInputField.setImmediate(true);
    sequenceInputField.addListener(new Property.ValueChangeListener() {
        private static final long serialVersionUID = -6654910749910048984L;

        @Override/*from  w  w w  .  j  av a  2 s .  c  o m*/
        public void valueChange(ValueChangeEvent event) {
            sequenceInputField.commit();
            sequence = (String) event.getProperty().getValue();
        }
    });

    sequenceInputField.setHeight("90%");
    sequenceInputField.setWidth("100%");

    sequenceInputField.addStyleName("hide-richtext-toolbar");

    ok = new NativeButton("Import");
}

From source file:br.gov.frameworkdemoiselle.vaadin.util.FieldFactory.java

License:Open Source License

/**
 * Produces a RichText field.// www  .j av  a 2s  . co  m
 *
 * @param caption
 *            Field's caption.
 * @return Produced field.
 */
public static RichTextArea createRichText(String caption) {
    RichTextArea field = new RichTextArea();
    field.setNullRepresentation("");
    setBasicProperties(field, caption);
    return field;
}

From source file:com.anphat.customer.ui.CreateEmailForm.java

private void buildEmailContent() {
    sample = new RichTextArea();
    sample.setImmediate(true);/*  w  w  w .  j a v a 2  s  .  c  om*/
    sample.setWidth("100%");
    sample.setHeight("500px");
    mainLayout.addComponent(sample);
}

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

License:Apache License

public TextFields() {
    setMargin(true);//from w  w w  .ja  v  a2s  . co 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.dungnv.streetfood.ui.RichTextWinDowUI.java

public void init() {
    layoutWindow = new CssLayout();
    layoutWindow.setSizeFull();//from   w  ww. j a v  a 2s  . c  o m
    richTextArea = new RichTextArea();
    richTextArea.setSizeFull();
    layoutWindow.addComponent(richTextArea);

    btnCloseWindow = new Button();
    btnCloseWindow.setCaption(FontAwesome.SAVE.getLabel().setSize3x().spin().getCssHtml());
    btnCloseWindow.setCaptionAsHtml(true);
    btnCloseWindow.addStyleName("float-button");
    layoutWindow.addComponent(btnCloseWindow);

    btnEdit = new Button(FontAwesome.EDIT.getLabel().flipHorizontal().getCssHtml());
    btnEdit.setCaptionAsHtml(true);
    this.addComponent(btnEdit);
}

From source file:com.esofthead.mycollab.module.crm.ui.components.CommentInput.java

License:Open Source License

@SuppressWarnings("rawtypes")
CommentInput(final ReloadableComponent component, final CommentType typeVal, final String typeidVal,
        final Integer extraTypeIdVal, final boolean cancelButtonEnable, final boolean isSendingEmailRelay,
        final Class emailHandler) {
    this.setWidth("600px");
    setSpacing(true);/*from ww w.  j av a2s.  c o  m*/

    type = typeVal;
    typeid = typeidVal;
    extraTypeId = extraTypeIdVal;

    commentArea = new RichTextArea();
    commentArea.setWidth("100%");
    commentArea.setHeight("200px");

    final AttachmentPanel attachments = new AttachmentPanel();

    final MHorizontalLayout controlsLayout = new MHorizontalLayout().withWidth("100%");

    final MultiFileUploadExt uploadExt = new MultiFileUploadExt(attachments);
    uploadExt.addComponent(attachments);
    controlsLayout.with(uploadExt).withAlign(uploadExt, Alignment.TOP_LEFT).expand(uploadExt);

    final Button saveBtn = new Button(AppContext.getMessage(GenericI18Enum.BUTTON_POST),
            new Button.ClickListener() {
                private static final long serialVersionUID = 1L;

                @Override
                public void buttonClick(final Button.ClickEvent event) {
                    final Comment comment = new Comment();
                    comment.setComment(Jsoup.clean(commentArea.getValue(), Whitelist.relaxed()));
                    comment.setCreatedtime(new GregorianCalendar().getTime());
                    comment.setCreateduser(AppContext.getUsername());
                    comment.setSaccountid(AppContext.getAccountId());
                    comment.setType(type.toString());
                    comment.setTypeid(typeid);
                    comment.setExtratypeid(extraTypeId);

                    final CommentService commentService = ApplicationContextUtil
                            .getSpringBean(CommentService.class);
                    int commentId;
                    if (isSendingEmailRelay) {
                        commentId = commentService.saveWithSession(comment, AppContext.getUsername(),
                                isSendingEmailRelay, emailHandler);
                    } else {
                        commentId = commentService.saveWithSession(comment, AppContext.getUsername(), false,
                                emailHandler);
                    }

                    String attachmentPath = "";
                    if (CommentType.CRM_NOTE.equals(type)) {
                        attachmentPath = AttachmentUtils.getCrmNoteCommentAttachmentPath(
                                AppContext.getAccountId(), Integer.parseInt(typeid), commentId);
                    } else {
                        // do nothing
                    }

                    if (!"".equals(attachmentPath)) {
                        attachments.saveContentsToRepo(attachmentPath);
                    }

                    // save success, clear comment area and load list
                    // comments again
                    commentArea.setValue("");
                    attachments.removeAllAttachmentsDisplay();
                    component.reload();
                }
            });
    saveBtn.setStyleName(UIConstants.THEME_GREEN_LINK);
    saveBtn.setIcon(FontAwesome.SEND);
    controlsLayout.with(saveBtn).withAlign(saveBtn, Alignment.TOP_RIGHT);

    if (cancelButtonEnable) {
        final Button cancelBtn = new Button(AppContext.getMessage(GenericI18Enum.BUTTON_CANCEL),
                new Button.ClickListener() {
                    private static final long serialVersionUID = 1L;

                    @Override
                    public void buttonClick(final ClickEvent event) {
                        component.cancel();
                    }
                });
        cancelBtn.setStyleName(UIConstants.THEME_GRAY_LINK);
        controlsLayout.addComponent(cancelBtn);
        controlsLayout.setComponentAlignment(cancelBtn, Alignment.TOP_RIGHT);
    }

    MVerticalLayout editBox = new MVerticalLayout();

    MHorizontalLayout commentWrap = new MHorizontalLayout().withWidth("100%");
    commentWrap.addStyleName("message");

    SimpleUser currentUser = AppContext.getSession();
    VerticalLayout userBlock = new VerticalLayout();
    userBlock.setDefaultComponentAlignment(Alignment.TOP_CENTER);
    userBlock.setWidth("80px");
    userBlock.setSpacing(true);
    userBlock.addComponent(UserAvatarControlFactory.createUserAvatarButtonLink(currentUser.getAvatarid(),
            currentUser.getDisplayName()));
    Label userName = new Label(currentUser.getDisplayName());
    userName.setStyleName("user-name");
    userBlock.addComponent(userName);

    commentWrap.addComponent(userBlock);
    VerticalLayout textAreaWrap = new VerticalLayout();
    textAreaWrap.setStyleName("message-container");
    textAreaWrap.setWidth("100%");
    textAreaWrap.addComponent(editBox);

    commentWrap.addComponent(textAreaWrap);
    commentWrap.setExpandRatio(textAreaWrap, 1.0f);

    editBox.addComponent(commentArea);
    editBox.addComponent(controlsLayout);
    this.addComponent(commentWrap);
}

From source file:com.esofthead.mycollab.module.crm.ui.components.CrmCommentInput.java

License:Open Source License

CrmCommentInput(final ReloadableComponent component, final String typeVal) {
    super();// w  w  w.  j  a  v  a2 s .  co m
    this.withMargin(new MarginInfo(true, true, false, true)).withFullWidth().withStyleName("message");

    SimpleUser currentUser = AppContext.getUser();
    UserBlock userBlock = new UserBlock(currentUser.getUsername(), currentUser.getAvatarid(),
            currentUser.getDisplayName());

    MVerticalLayout textAreaWrap = new MVerticalLayout().withFullWidth().withStyleName("message-container");
    this.with(userBlock, textAreaWrap).expand(textAreaWrap);

    type = typeVal;

    commentArea = new RichTextArea();
    commentArea.setWidth("100%");
    commentArea.setHeight("200px");

    final AttachmentPanel attachments = new AttachmentPanel();

    final MHorizontalLayout controlsLayout = new MHorizontalLayout().withFullWidth();
    controlsLayout.setDefaultComponentAlignment(Alignment.TOP_RIGHT);

    final MultiFileUploadExt uploadExt = new MultiFileUploadExt(attachments);
    uploadExt.addComponent(attachments);
    controlsLayout.with(uploadExt).withAlign(uploadExt, Alignment.TOP_LEFT).expand(uploadExt);

    final Button cancelBtn = new Button(AppContext.getMessage(GenericI18Enum.BUTTON_CLEAR),
            new Button.ClickListener() {
                private static final long serialVersionUID = 1L;

                @Override
                public void buttonClick(ClickEvent event) {
                    commentArea.setValue("");
                }
            });
    cancelBtn.setStyleName(UIConstants.BUTTON_OPTION);

    final Button newCommentBtn = new Button(AppContext.getMessage(GenericI18Enum.BUTTON_POST),
            new Button.ClickListener() {
                private static final long serialVersionUID = 1L;

                @Override
                public void buttonClick(final Button.ClickEvent event) {
                    CommentWithBLOBs comment = new CommentWithBLOBs();
                    comment.setComment(Jsoup.clean(commentArea.getValue(), Whitelist.relaxed()));
                    comment.setCreatedtime(new GregorianCalendar().getTime());
                    comment.setCreateduser(AppContext.getUsername());
                    comment.setSaccountid(AppContext.getAccountId());
                    comment.setType(type);
                    comment.setTypeid(typeId);

                    CommentService commentService = AppContextUtil.getSpringBean(CommentService.class);
                    int commentId = commentService.saveWithSession(comment, AppContext.getUsername());

                    String attachmentPath = AttachmentUtils.getCommentAttachmentPath(typeVal,
                            AppContext.getAccountId(), null, typeId, commentId);

                    if (!"".equals(attachmentPath)) {
                        attachments.saveContentsToRepo(attachmentPath);
                    }

                    // save success, clear comment area and load list
                    // comments again
                    commentArea.setValue("");
                    attachments.removeAllAttachmentsDisplay();
                    component.reload();
                }
            });
    newCommentBtn.setStyleName(UIConstants.BUTTON_ACTION);
    newCommentBtn.setIcon(FontAwesome.SEND);
    controlsLayout.with(cancelBtn, newCommentBtn);
    textAreaWrap.with(commentArea, controlsLayout);
}

From source file:com.esofthead.mycollab.module.project.ui.components.ProjectCommentInput.java

License:Open Source License

ProjectCommentInput(final ReloadableComponent component, final CommentType typeVal,
        final Integer extraTypeIdVal, final boolean cancelButtonEnable, final boolean isSendingEmailRelay,
        final Class<? extends SendingRelayEmailNotificationAction> emailHandler) {
    super();//w w  w. j  a  va 2  s.  co m
    this.withWidth("100%").withStyleName("message");

    final SimpleUser currentUser = AppContext.getSession();
    MVerticalLayout userBlock = new MVerticalLayout().withMargin(false).withWidth("80px");
    userBlock.setDefaultComponentAlignment(Alignment.TOP_CENTER);

    ClickListener gotoUser = new ClickListener() {
        private static final long serialVersionUID = 1L;

        @Override
        public void buttonClick(ClickEvent event) {
            EventBusFactory.getInstance()
                    .post(new ProjectMemberEvent.GotoRead(this, currentUser.getUsername()));
        }
    };

    Button userAvatarBtn = UserAvatarControlFactory.createUserAvatarButtonLink(currentUser.getAvatarid(),
            currentUser.getDisplayName());
    userAvatarBtn.addClickListener(gotoUser);
    userBlock.addComponent(userAvatarBtn);
    Button userName = new Button(currentUser.getDisplayName());
    userName.setStyleName("user-name");
    userName.addStyleName("link");
    userName.addStyleName(UIConstants.WORD_WRAP);
    userName.addClickListener(gotoUser);
    userBlock.addComponent(userName);

    this.addComponent(userBlock);
    MVerticalLayout textAreaWrap = new MVerticalLayout().withWidth("100%").withStyleName("message-container");
    this.addComponent(textAreaWrap);
    this.setExpandRatio(textAreaWrap, 1.0f);

    type = typeVal;
    extraTypeId = extraTypeIdVal;

    commentArea = new RichTextArea();
    commentArea.setWidth("100%");
    commentArea.setHeight("200px");

    final AttachmentPanel attachments = new AttachmentPanel();

    final MHorizontalLayout controlsLayout = new MHorizontalLayout().withSpacing(true).withMargin(false)
            .withWidth("100%");

    final MultiFileUploadExt uploadExt = new MultiFileUploadExt(attachments);
    uploadExt.addComponent(attachments);
    controlsLayout.with(uploadExt).withAlign(uploadExt, Alignment.TOP_LEFT).expand(uploadExt);

    final Label emptySpace = new Label();
    controlsLayout.addComponent(emptySpace);
    controlsLayout.setExpandRatio(emptySpace, 1.0f);

    if (cancelButtonEnable) {
        final Button cancelBtn = new Button(AppContext.getMessage(GenericI18Enum.BUTTON_CANCEL),
                new Button.ClickListener() {
                    private static final long serialVersionUID = 1L;

                    @Override
                    public void buttonClick(final ClickEvent event) {
                        component.cancel();
                    }
                });
        cancelBtn.setStyleName(UIConstants.THEME_GRAY_LINK);
        controlsLayout.addComponent(cancelBtn);
        controlsLayout.setComponentAlignment(cancelBtn, Alignment.TOP_RIGHT);
    }

    final Button newCommentBtn = new Button(AppContext.getMessage(GenericI18Enum.BUTTON_POST),
            new Button.ClickListener() {
                private static final long serialVersionUID = 1L;

                @Override
                public void buttonClick(final Button.ClickEvent event) {
                    final Comment comment = new Comment();
                    comment.setComment(Jsoup.clean(commentArea.getValue(), Whitelist.relaxed()));
                    comment.setCreatedtime(new GregorianCalendar().getTime());
                    comment.setCreateduser(AppContext.getUsername());
                    comment.setSaccountid(AppContext.getAccountId());
                    comment.setType(type.toString());
                    comment.setTypeid("" + typeId);
                    comment.setExtratypeid(extraTypeId);

                    final CommentService commentService = ApplicationContextUtil
                            .getSpringBean(CommentService.class);
                    int commentId = commentService.saveWithSession(comment, AppContext.getUsername(),
                            isSendingEmailRelay, emailHandler);

                    String attachmentPath = AttachmentUtils.getProjectEntityCommentAttachmentPath(typeVal,
                            AppContext.getAccountId(), CurrentProjectVariables.getProjectId(), typeId,
                            commentId);

                    if (!"".equals(attachmentPath)) {
                        attachments.saveContentsToRepo(attachmentPath);
                    }

                    // save success, clear comment area and load list
                    // comments again
                    commentArea.setValue("");
                    attachments.removeAllAttachmentsDisplay();
                    component.reload();
                }
            });
    newCommentBtn.setStyleName(UIConstants.THEME_GREEN_LINK);
    newCommentBtn.setIcon(FontAwesome.SEND);
    controlsLayout.with(newCommentBtn).withAlign(newCommentBtn, Alignment.TOP_RIGHT);

    textAreaWrap.addComponent(commentArea);
    textAreaWrap.addComponent(controlsLayout);
}

From source file:com.esofthead.mycollab.module.project.view.bug.BugEditFormFieldFactory.java

License:Open Source License

@Override
protected Field<?> onCreateField(final Object propertyId) {
    final SimpleBug beanItem = attachForm.getBean();
    if (propertyId.equals("environment")) {
        return new RichTextArea();
    } else if (propertyId.equals("description")) {
        return new RichTextArea();
    } else if (propertyId.equals("priority")) {
        return new BugPriorityComboBox();
    } else if (propertyId.equals("assignuser")) {
        ProjectMemberSelectionField field = new ProjectMemberSelectionField();
        field.addValueChangeListener(new Property.ValueChangeListener() {
            @Override// ww  w.j  a  v a 2 s.c o m
            public void valueChange(Property.ValueChangeEvent valueChangeEvent) {
                Property property = valueChangeEvent.getProperty();
                SimpleProjectMember member = (SimpleProjectMember) property.getValue();
                if (member != null) {
                    subscribersComp.addFollower(member.getUsername());
                }
            }
        });
        return field;
    } else if (propertyId.equals("id")) {
        attachmentUploadField = new ProjectFormAttachmentUploadField();
        if (beanItem.getId() != null) {
            attachmentUploadField.getAttachments(beanItem.getProjectid(), ProjectTypeConstants.BUG,
                    beanItem.getId());
        }
        return attachmentUploadField;
    } else if (propertyId.equals("severity")) {
        return new BugSeverityComboBox();
    } else if (propertyId.equals("components")) {
        componentSelect = new ComponentMultiSelectField();
        return componentSelect;
    } else if (propertyId.equals("affectedVersions")) {
        affectedVersionSelect = new VersionMultiSelectField();
        return affectedVersionSelect;
    } else if (propertyId.equals("fixedVersions")) {
        fixedVersionSelect = new VersionMultiSelectField();
        return fixedVersionSelect;
    } else if (propertyId.equals("summary")) {
        final TextField tf = new TextField();
        if (isValidateForm) {
            tf.setNullRepresentation("");
            tf.setRequired(true);
            tf.setRequiredError("Summary must be not null");
        }

        return tf;
    } else if (propertyId.equals("milestoneid")) {
        final MilestoneComboBox milestoneBox = new MilestoneComboBox();
        milestoneBox.addValueChangeListener(new Property.ValueChangeListener() {
            private static final long serialVersionUID = 1L;

            @Override
            public void valueChange(Property.ValueChangeEvent event) {
                String milestoneName = milestoneBox.getItemCaption(milestoneBox.getValue());
                beanItem.setMilestoneName(milestoneName);
            }
        });
        return milestoneBox;
    } else if (propertyId.equals("estimatetime") || (propertyId.equals("estimateremaintime"))) {
        return new DoubleField();
    } else if (propertyId.equals("selected")) {
        return subscribersComp;
    } else if (BugWithBLOBs.Field.startdate.equalTo(propertyId)
            || BugWithBLOBs.Field.enddate.equalTo(propertyId)
            || BugWithBLOBs.Field.duedate.equalTo(propertyId)) {
        return new DateTimeOptionField(true);
    }

    return null;
}

From source file:com.esofthead.mycollab.module.project.view.bug.BugRelatedField.java

License:Open Source License

public void displayRelatedBugs(final SimpleBug bug) {
    this.bug = bug;
    VerticalLayout mainLayout = new VerticalLayout();
    mainLayout.setWidth("100%");
    mainLayout.setMargin(true);//  ww w .ja  va  2  s .c  om
    mainLayout.setSpacing(true);

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

    Label lbBug = new Label("Bug:");
    lbBug.setWidth("70px");
    layoutAdd.addComponent(lbBug);
    layoutAdd.setComponentAlignment(lbBug, Alignment.MIDDLE_LEFT);

    itemField = new TextField();
    itemField.setWidth("300px");
    itemField.setNullRepresentation("");
    itemField.setReadOnly(true);
    itemField.setEnabled(true);
    layoutAdd.addComponent(itemField);
    layoutAdd.setComponentAlignment(itemField, Alignment.MIDDLE_LEFT);

    browseBtn = new Button("", new Button.ClickListener() {
        private static final long serialVersionUID = 1L;

        @Override
        public void buttonClick(com.vaadin.ui.Button.ClickEvent event) {
            callItemSelectionWindow();

        }
    });
    browseBtn.setIcon(MyCollabResource.newResource(WebResourceIds._16_browseItem));
    browseBtn.setStyleName("link");

    layoutAdd.addComponent(browseBtn);
    layoutAdd.setComponentAlignment(browseBtn, Alignment.MIDDLE_LEFT);

    clearBtn = new Button("", new Button.ClickListener() {
        private static final long serialVersionUID = 1L;

        @Override
        public void buttonClick(com.vaadin.ui.Button.ClickEvent event) {
            setItemFieldValue("");
        }
    });
    clearBtn.setIcon(MyCollabResource.newResource("icons/16/clearItem.png"));
    clearBtn.setStyleName("link");

    layoutAdd.addComponent(clearBtn);
    layoutAdd.setComponentAlignment(clearBtn, Alignment.MIDDLE_LEFT);

    Label lbIs = new Label("is");
    layoutAdd.addComponent(lbIs);
    layoutAdd.setComponentAlignment(lbIs, Alignment.MIDDLE_LEFT);

    comboRelation = new BugRelationComboBox();
    comboRelation.setWidth("200px");
    layoutAdd.addComponent(comboRelation);
    layoutAdd.setComponentAlignment(comboRelation, Alignment.MIDDLE_LEFT);

    btnRelate = new Button("Relate");
    btnRelate.setStyleName(UIConstants.THEME_GREEN_LINK);
    btnRelate.setIcon(MyCollabResource.newResource(WebResourceIds._16_addRecord));

    ProjectMemberService memberService = ApplicationContextUtil.getSpringBean(ProjectMemberService.class);
    SimpleProjectMember member = memberService.findMemberByUsername(AppContext.getUsername(),
            CurrentProjectVariables.getProjectId(), AppContext.getAccountId());

    if (member != null) {
        btnRelate.setEnabled((member.getIsadmin() || (AppContext.getUsername().equals(bug.getAssignuser()))
                || (AppContext.getUsername().equals(bug.getLogby())))
                && CurrentProjectVariables.canWrite(ProjectRolePermissionCollections.BUGS));
    }

    btnRelate.addClickListener(new Button.ClickListener() {
        private static final long serialVersionUID = 1L;

        @Override
        public void buttonClick(com.vaadin.ui.Button.ClickEvent event) {
            if (!itemField.getValue().toString().trim().equals("") && relatedBean != null
                    && !relatedBean.getSummary().equals(bug.getSummary())) {
                SimpleRelatedBug relatedBug = new SimpleRelatedBug();
                relatedBug.setBugid(bug.getId());
                relatedBug.setRelatedid(relatedBean.getId());
                relatedBug.setRelatetype((String) comboRelation.getValue());
                relatedBug.setComment(txtComment.getValue().toString());
                relatedBugService.saveWithSession(relatedBug, AppContext.getUsername());

                SimpleRelatedBug oppositeRelation = new SimpleRelatedBug();
                oppositeRelation.setBugid(relatedBean.getId());
                oppositeRelation.setRelatedid(bug.getId());
                oppositeRelation.setComment(txtComment.getValue().toString());

                if (comboRelation.getValue().toString().equals(BugRelationConstants.PARENT)) {
                    oppositeRelation.setRelatetype(BugRelationConstants.CHILD);
                } else if (comboRelation.getValue().toString().equals(BugRelationConstants.CHILD)) {
                    oppositeRelation.setRelatetype(BugRelationConstants.PARENT);
                } else if (comboRelation.getValue().toString().equals(BugRelationConstants.RELATED)) {
                    oppositeRelation.setRelatetype(BugRelationConstants.RELATED);
                } else if (comboRelation.getValue().toString().equals(BugRelationConstants.BEFORE)) {
                    oppositeRelation.setRelatetype(BugRelationConstants.AFTER);
                } else if (comboRelation.getValue().toString().equals(BugRelationConstants.AFTER)) {
                    oppositeRelation.setRelatetype(BugRelationConstants.BEFORE);
                } else if (comboRelation.getValue().toString().equals(BugRelationConstants.DUPLICATED)) {
                    oppositeRelation.setRelatetype(BugRelationConstants.DUPLICATED);
                    BugService bugService = ApplicationContextUtil.getSpringBean(BugService.class);
                    bug.setStatus(BugStatus.Resolved.name());
                    bug.setResolution(BugResolution.Duplicate.name());
                    bugService.updateWithSession(bug, AppContext.getUsername());
                }
                relatedBugService.saveWithSession(oppositeRelation, AppContext.getUsername());

                setCriteria();

                setItemFieldValue("");
                txtComment.setValue("");
                relatedBean = null;
            }
        }
    });
    layoutAdd.addComponent(btnRelate);
    layoutAdd.setComponentAlignment(btnRelate, Alignment.MIDDLE_LEFT);

    Label lbInstruction = new Label("<strong>Relate to an existing ticket</strong>", ContentMode.HTML);
    mainLayout.addComponent(lbInstruction);

    mainLayout.addComponent(layoutAdd);

    HorizontalLayout layoutComment = new HorizontalLayout();
    layoutComment.setSpacing(true);
    Label lbComment = new Label("Comment:");
    lbComment.setWidth("70px");
    layoutComment.addComponent(lbComment);
    layoutComment.setComponentAlignment(lbComment, Alignment.TOP_LEFT);
    txtComment = new RichTextArea();
    txtComment.setHeight("130px");
    txtComment.setWidth("565px");
    layoutComment.addComponent(txtComment);
    layoutComment.setComponentAlignment(txtComment, Alignment.MIDDLE_LEFT);
    mainLayout.addComponent(layoutComment);

    tableItem = new DefaultPagedBeanTable<RelatedBugService, BugRelatedSearchCriteria, SimpleRelatedBug>(
            ApplicationContextUtil.getSpringBean(RelatedBugService.class), SimpleRelatedBug.class,
            Arrays.asList(
                    new TableViewField(BugI18nEnum.RELATED_BUG_NAME, "bugName",
                            UIConstants.TABLE_EX_LABEL_WIDTH),
                    new TableViewField(BugI18nEnum.RELATED_BUG_TYPE, "relatetype",
                            UIConstants.TABLE_S_LABEL_WIDTH),
                    new TableViewField(BugI18nEnum.RELATED_BUG_COMMENT, "comment",
                            UIConstants.TABLE_EX_LABEL_WIDTH),
                    new TableViewField(null, "id", UIConstants.TABLE_CONTROL_WIDTH)));

    tableItem.addGeneratedColumn("bugName", new Table.ColumnGenerator() {
        private static final long serialVersionUID = 1L;

        @Override
        public com.vaadin.ui.Component generateCell(Table source, final Object itemId, Object columnId) {
            final SimpleRelatedBug relatedItem = tableItem.getBeanByIndex(itemId);
            String bugname = "[%s-%s] %s";
            bugname = String.format(bugname, CurrentProjectVariables.getProject().getShortname(),
                    relatedItem.getRelatedid(), relatedItem.getBugName());

            BugService bugService = ApplicationContextUtil.getSpringBean(BugService.class);
            final SimpleBug bug = bugService.findById(relatedItem.getRelatedid(), AppContext.getAccountId());

            LabelLink b = new LabelLink(bugname,
                    ProjectLinkBuilder.generateBugPreviewFullLink(bug.getBugkey(), bug.getProjectShortName()));

            if (StringUtils.isNotBlank(bug.getPriority())) {
                String iconPriority = ProjectResources.getIconResourceLink12ByBugPriority(bug.getPriority());

                b.setIconLink(iconPriority);
            }

            if (BugStatus.Verified.name().equals(bug.getStatus())) {
                b.addStyleName(UIConstants.LINK_COMPLETED);
            } else if (bug.getDuedate() != null
                    && (bug.getDuedate().before(new GregorianCalendar().getTime()))) {
                b.addStyleName(UIConstants.LINK_OVERDUE);
            }
            b.setWidth("100%");
            return b;

        }
    });

    tableItem.addGeneratedColumn("id", new ColumnGenerator() {
        private static final long serialVersionUID = 1L;

        @Override
        public Object generateCell(Table source, Object itemId, Object columnId) {
            final SimpleRelatedBug relatedItem = tableItem.getBeanByIndex(itemId);

            Button deleteBtn = new Button(null, new Button.ClickListener() {
                private static final long serialVersionUID = 1L;

                @Override
                public void buttonClick(com.vaadin.ui.Button.ClickEvent event) {
                    BugRelatedSearchCriteria relateBugIdCriteria = new BugRelatedSearchCriteria();
                    relateBugIdCriteria.setBugId(new NumberSearchField(relatedItem.getBugid()));
                    relateBugIdCriteria.setRelatedId(new NumberSearchField(relatedItem.getRelatedid()));

                    relatedBugService.removeByCriteria(relateBugIdCriteria, AppContext.getAccountId());

                    BugRelatedSearchCriteria relateIdCriteria = new BugRelatedSearchCriteria();
                    relateIdCriteria.setBugId(new NumberSearchField(relatedItem.getRelatedid()));
                    relateIdCriteria.setRelatedId(new NumberSearchField(relatedItem.getBugid()));

                    relatedBugService.removeByCriteria(relateIdCriteria, AppContext.getAccountId());

                    BugRelatedField.this.setCriteria();
                }
            });
            deleteBtn.setStyleName("link");
            deleteBtn.setIcon(MyCollabResource.newResource("icons/16/delete.png"));
            relatedItem.setExtraData(deleteBtn);

            ProjectMemberService memberService = ApplicationContextUtil
                    .getSpringBean(ProjectMemberService.class);
            SimpleProjectMember member = memberService.findMemberByUsername(AppContext.getUsername(),
                    CurrentProjectVariables.getProjectId(), AppContext.getAccountId());

            if (member != null) {
                deleteBtn.setEnabled(
                        member.getIsadmin() || (AppContext.getUsername().equals(bug.getAssignuser()))
                                || (AppContext.getUsername().equals(bug.getLogby())));
            }
            return deleteBtn;
        }
    });

    mainLayout.addComponent(tableItem);

    setCriteria();

    this.setCompositionRoot(mainLayout);
}