Example usage for com.vaadin.ui CssLayout CssLayout

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

Introduction

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

Prototype

public CssLayout() 

Source Link

Document

Constructs an empty CssLayout.

Usage

From source file:com.esofthead.mycollab.module.project.view.settings.ComponentListViewImpl.java

License:Open Source License

private ComponentContainer constructTableActionControls() {
    final CssLayout layoutWrapper = new CssLayout();
    layoutWrapper.setWidth("100%");

    MHorizontalLayout layout = new MHorizontalLayout();
    layoutWrapper.addStyleName(UIConstants.TABLE_ACTION_CONTROLS);
    layoutWrapper.addComponent(layout);/*from w ww .  jav a 2  s .c  o m*/

    this.selectOptionButton = new SelectionOptionButton(tableItem);
    layout.addComponent(this.selectOptionButton);

    tableActionControls = new DefaultMassItemActionHandlerContainer();
    if (CurrentProjectVariables.canAccess(ProjectRolePermissionCollections.COMPONENTS)) {
        tableActionControls.addDeleteActionItem();
    }

    tableActionControls.addMailActionItem();
    tableActionControls.addDownloadPdfActionItem();
    tableActionControls.addDownloadExcelActionItem();
    tableActionControls.addDownloadCsvActionItem();

    layout.with(tableActionControls, selectedItemsNumberLabel).withAlign(selectedItemsNumberLabel,
            Alignment.MIDDLE_CENTER);
    return layoutWrapper;
}

From source file:com.esofthead.mycollab.module.project.view.settings.ProjectMemberListViewImpl.java

License:Open Source License

public ProjectMemberListViewImpl() {
    super();//from   ww  w.j  av a 2s. c o  m
    this.setMargin(new MarginInfo(false, true, false, true));
    MHorizontalLayout viewHeader = new MHorizontalLayout().withMargin(new MarginInfo(true, false, true, false))
            .withWidth("100%").withStyleName("hdr-view");
    viewHeader.setDefaultComponentAlignment(Alignment.MIDDLE_LEFT);

    Label headerText = new ProjectViewHeader(ProjectTypeConstants.MEMBER,
            AppContext.getMessage(ProjectMemberI18nEnum.VIEW_LIST_TITLE));
    headerText.setStyleName("hdr-text");

    viewHeader.with(headerText).expand(headerText);

    Button createBtn = new Button(AppContext.getMessage(ProjectMemberI18nEnum.BUTTON_NEW_INVITEES),
            new Button.ClickListener() {
                private static final long serialVersionUID = 1L;

                @Override
                public void buttonClick(Button.ClickEvent event) {
                    EventBusFactory.getInstance().post(new ProjectMemberEvent.GotoInviteMembers(this, null));
                }
            });
    createBtn.setEnabled(CurrentProjectVariables.canWrite(ProjectRolePermissionCollections.USERS));
    createBtn.setStyleName(UIConstants.THEME_GREEN_LINK);
    createBtn.setIcon(FontAwesome.PLUS);

    viewHeader.addComponent(createBtn);

    this.addComponent(viewHeader);

    contentLayout = new CssLayout();
    contentLayout.setWidth("100%");
    contentLayout.setStyleName("view-content");

    this.addComponent(contentLayout);
}

From source file:com.esofthead.mycollab.module.project.view.settings.ProjectMemberListViewImpl.java

License:Open Source License

private Component generateMemberBlock(final SimpleProjectMember member) {
    CssLayout memberBlock = new CssLayout();
    memberBlock.addStyleName("member-block");

    VerticalLayout blockContent = new VerticalLayout();
    MHorizontalLayout blockTop = new MHorizontalLayout();
    Image memberAvatar = UserAvatarControlFactory.createUserAvatarEmbeddedComponent(member.getMemberAvatarId(),
            100);/*  w w w  .ja va2s  .c o  m*/
    blockTop.addComponent(memberAvatar);

    VerticalLayout memberInfo = new VerticalLayout();

    Button deleteBtn = new Button("", FontAwesome.TRASH_O);
    deleteBtn.addClickListener(new Button.ClickListener() {
        @Override
        public void buttonClick(ClickEvent clickEvent) {
            ConfirmDialogExt.show(UI.getCurrent(),
                    AppContext.getMessage(GenericI18Enum.DIALOG_DELETE_TITLE, SiteConfiguration.getSiteName()),
                    AppContext.getMessage(GenericI18Enum.DIALOG_DELETE_SINGLE_ITEM_MESSAGE),
                    AppContext.getMessage(GenericI18Enum.BUTTON_YES),
                    AppContext.getMessage(GenericI18Enum.BUTTON_NO), new ConfirmDialog.Listener() {
                        private static final long serialVersionUID = 1L;

                        @Override
                        public void onClose(ConfirmDialog dialog) {
                            if (dialog.isConfirmed()) {
                                ProjectMemberService prjMemberService = ApplicationContextUtil
                                        .getSpringBean(ProjectMemberService.class);
                                member.setStatus(ProjectMemberStatusConstants.INACTIVE);
                                prjMemberService.updateWithSession(member, AppContext.getUsername());

                                EventBusFactory.getInstance().post(
                                        new ProjectMemberEvent.GotoList(ProjectMemberListViewImpl.this, null));
                            }
                        }
                    });
        }
    });
    deleteBtn.addStyleName(UIConstants.BUTTON_ICON_ONLY);

    blockContent.addComponent(deleteBtn);
    deleteBtn.setVisible(CurrentProjectVariables.canWrite(ProjectRolePermissionCollections.USERS));
    blockContent.setComponentAlignment(deleteBtn, Alignment.TOP_RIGHT);

    LabelLink memberLink = new LabelLink(member.getMemberFullName(),
            ProjectLinkBuilder.generateProjectMemberFullLink(member.getProjectid(), member.getUsername()));

    memberLink.setWidth("100%");
    memberLink.addStyleName("member-name");

    memberInfo.addComponent(memberLink);

    String roleLink = "<a href=\"" + AppContext.getSiteUrl() + GenericLinkUtils.URL_PREFIX_PARAM
            + ProjectLinkGenerator.generateRolePreviewLink(member.getProjectid(), member.getProjectRoleId())
            + "\"";
    Label memberRole = new Label();
    memberRole.setContentMode(ContentMode.HTML);
    memberRole.setStyleName("member-role");
    if (member.isAdmin()) {
        memberRole.setValue(roleLink + "style=\"color: #B00000;\">" + "Project Admin" + "</a>");
    } else {
        memberRole.setValue(roleLink + "style=\"color:gray;font-size:12px;\">" + member.getRoleName() + "</a>");
    }
    memberRole.setSizeUndefined();
    memberInfo.addComponent(memberRole);

    Label memberEmailLabel = new Label(
            "<a href='mailto:" + member.getUsername() + "'>" + member.getUsername() + "</a>", ContentMode.HTML);
    memberEmailLabel.addStyleName("member-email");
    memberEmailLabel.setWidth("100%");
    memberInfo.addComponent(memberEmailLabel);

    Label memberSinceLabel = new Label("Member since: " + AppContext.formatDate(member.getJoindate()));
    memberSinceLabel.addStyleName("member-email");
    memberSinceLabel.setWidth("100%");
    memberInfo.addComponent(memberSinceLabel);

    if (RegisterStatusConstants.SENT_VERIFICATION_EMAIL.equals(member.getStatus())) {
        final VerticalLayout waitingNotLayout = new VerticalLayout();
        Label infoStatus = new Label(AppContext.getMessage(ProjectMemberI18nEnum.WAITING_ACCEPT_INVITATION));
        infoStatus.addStyleName("member-email");
        waitingNotLayout.addComponent(infoStatus);

        ButtonLink resendInvitationLink = new ButtonLink(
                AppContext.getMessage(ProjectMemberI18nEnum.BUTTON_RESEND_INVITATION),
                new Button.ClickListener() {
                    private static final long serialVersionUID = 1L;

                    @Override
                    public void buttonClick(ClickEvent event) {
                        ProjectMemberMapper projectMemberMapper = ApplicationContextUtil
                                .getSpringBean(ProjectMemberMapper.class);
                        member.setStatus(RegisterStatusConstants.VERIFICATING);
                        projectMemberMapper.updateByPrimaryKeySelective(member);
                        waitingNotLayout.removeAllComponents();
                        Label statusEmail = new Label(
                                AppContext.getMessage(ProjectMemberI18nEnum.SENDING_EMAIL_INVITATION));
                        statusEmail.addStyleName("member-email");
                        waitingNotLayout.addComponent(statusEmail);
                    }
                });
        resendInvitationLink.setStyleName("link");
        resendInvitationLink.addStyleName("member-email");
        waitingNotLayout.addComponent(resendInvitationLink);
        memberInfo.addComponent(waitingNotLayout);
    } else if (RegisterStatusConstants.ACTIVE.equals(member.getStatus())) {
        Label lastAccessTimeLbl = new Label("Logged in "
                + DateTimeUtils.getPrettyDateValue(member.getLastAccessTime(), AppContext.getUserLocale()));
        lastAccessTimeLbl.addStyleName("member-email");
        memberInfo.addComponent(lastAccessTimeLbl);
    } else if (RegisterStatusConstants.VERIFICATING.equals(member.getStatus())) {
        Label infoStatus = new Label(AppContext.getMessage(ProjectMemberI18nEnum.SENDING_EMAIL_INVITATION));
        infoStatus.addStyleName("member-email");
        memberInfo.addComponent(infoStatus);
    }

    String bugStatus = member.getNumOpenBugs() + " open bug";
    if (member.getNumOpenBugs() > 1) {
        bugStatus += "s";
    }

    String taskStatus = member.getNumOpenTasks() + " open task";
    if (member.getNumOpenTasks() > 1) {
        taskStatus += "s";
    }

    Label memberWorkStatus = new Label(bugStatus + " - " + taskStatus);
    memberInfo.addComponent(memberWorkStatus);
    memberInfo.setWidth("100%");

    blockTop.addComponent(memberInfo);
    blockTop.setExpandRatio(memberInfo, 1.0f);
    blockTop.setWidth("100%");
    blockContent.addComponent(blockTop);

    blockContent.setWidth("100%");

    memberBlock.addComponent(blockContent);
    return memberBlock;
}

From source file:com.esofthead.mycollab.module.project.view.settings.ProjectRoleListViewImpl.java

License:Open Source License

private ComponentContainer constructTableActionControls() {
    final CssLayout layoutWrapper = new CssLayout();
    layoutWrapper.setWidth("100%");
    final MHorizontalLayout layout = new MHorizontalLayout();
    layoutWrapper.addStyleName(UIConstants.TABLE_ACTION_CONTROLS);
    layoutWrapper.addComponent(layout);//from   w  w w.  j a v a2  s. c  o m

    this.selectOptionButton = new SelectionOptionButton(this.tableItem);
    layout.addComponent(this.selectOptionButton);

    final Button deleteBtn = new Button(AppContext.getMessage(GenericI18Enum.BUTTON_DELETE));
    deleteBtn.setEnabled(CurrentProjectVariables.canAccess(ProjectRolePermissionCollections.ROLES));

    this.tableActionControls = new DefaultMassItemActionHandlersContainer();
    if (CurrentProjectVariables.canAccess(ProjectRolePermissionCollections.ROLES)) {
        tableActionControls.addActionItem(MassItemActionHandler.DELETE_ACTION, FontAwesome.TRASH_O, "delete",
                AppContext.getMessage(GenericI18Enum.BUTTON_DELETE));
    }

    tableActionControls.addDownloadActionItem(MassItemActionHandler.EXPORT_PDF_ACTION, FontAwesome.FILE_PDF_O,
            "export", "export.pdf", AppContext.getMessage(GenericI18Enum.BUTTON_EXPORT_PDF));

    tableActionControls.addDownloadActionItem(MassItemActionHandler.EXPORT_EXCEL_ACTION,
            FontAwesome.FILE_EXCEL_O, "export", "export.xlsx",
            AppContext.getMessage(GenericI18Enum.BUTTON_EXPORT_EXCEL));

    tableActionControls.addDownloadActionItem(MassItemActionHandler.EXPORT_CSV_ACTION, FontAwesome.FILE_TEXT_O,
            "export", "export.csv", AppContext.getMessage(GenericI18Enum.BUTTON_EXPORT_CSV));

    layout.addComponent(this.tableActionControls);
    layout.addComponent(this.selectedItemsNumberLabel);
    layout.setComponentAlignment(this.selectedItemsNumberLabel, Alignment.MIDDLE_CENTER);
    return layoutWrapper;
}

From source file:com.esofthead.mycollab.module.project.view.settings.ProjectRoleReadViewImpl.java

License:Open Source License

public ProjectRoleReadViewImpl() {
    this.headerText = new Label();
    headerText.setCaption(AppContext.getMessage(ProjectRoleI18nEnum.FORM_READ_TITLE));
    headerText.setIcon(FontAwesome.USERS);
    headerText.addStyleName("header-text");

    this.headerText.setSizeUndefined();
    this.addComponent(constructHeader());

    previewForm = initPreviewForm();/*from www . jav  a  2s .  c  o  m*/
    ComponentContainer actionControls = createButtonControls();
    if (actionControls != null) {
        actionControls.addStyleName("control-buttons");
    }

    addHeaderRightContent(actionControls);

    CssLayout contentWrapper = new CssLayout();
    contentWrapper.setStyleName("content-wrapper");

    previewLayout = new DefaultReadViewLayout("");

    contentWrapper.addComponent(previewLayout);

    previewLayout.addBody(previewForm);

    this.addComponent(contentWrapper);
}

From source file:com.esofthead.mycollab.module.project.view.settings.VersionListViewImpl.java

License:Open Source License

private ComponentContainer constructTableActionControls() {
    final CssLayout layoutWrapper = new CssLayout();
    layoutWrapper.setWidth("100%");
    MHorizontalLayout layout = new MHorizontalLayout();
    layoutWrapper.addStyleName(UIConstants.TABLE_ACTION_CONTROLS);
    layoutWrapper.addComponent(layout);//  w  ww  . j a  v a2 s  . c o  m

    this.selectOptionButton = new SelectionOptionButton(this.tableItem);
    layout.addComponent(this.selectOptionButton);

    tableActionControls = new DefaultMassItemActionHandlerContainer();

    if (CurrentProjectVariables.canAccess(ProjectRolePermissionCollections.VERSIONS)) {
        tableActionControls.addDeleteActionItem();
    }

    tableActionControls.addMailActionItem();
    tableActionControls.addDownloadPdfActionItem();
    tableActionControls.addDownloadExcelActionItem();
    tableActionControls.addDownloadCsvActionItem();

    layout.with(tableActionControls, selectedItemsNumberLabel).withAlign(selectedItemsNumberLabel,
            Alignment.MIDDLE_CENTER);
    return layoutWrapper;
}

From source file:com.esofthead.mycollab.module.project.view.task.components.TaskRowRenderer.java

License:Open Source License

public TaskRowRenderer(final SimpleTask task) {
    this.task = task;
    withSpacing(true).withMargin(false).withFullWidth().addStyleName(UIConstants.BORDER_LIST_ROW);

    taskSettingPopupBtn = new PopupButton();
    taskSettingPopupBtn.setIcon(FontAwesome.COGS);
    taskSettingPopupBtn.addStyleName(UIConstants.BUTTON_ICON_ONLY);
    OptionPopupContent filterBtnLayout = createPopupContent();
    taskSettingPopupBtn.setContent(filterBtnLayout);

    toogleTaskField = new ToggleTaskSummaryField(task);
    MHorizontalLayout headerLayout = new MHorizontalLayout().withFullWidth()
            .withMargin(new MarginInfo(false, true, false, false));

    TaskPopupFieldFactory popupFieldFactory = ViewManager.getCacheComponent(TaskPopupFieldFactory.class);
    AbstractComponent priorityField = popupFieldFactory.createPriorityPopupField(task);
    AbstractComponent assigneeField = popupFieldFactory.createAssigneePopupField(task);
    headerLayout.with(taskSettingPopupBtn, priorityField, assigneeField, toogleTaskField)
            .expand(toogleTaskField);//ww  w  . j ava2 s .co m

    CssLayout footer = new CssLayout();

    AbstractComponent commentField = popupFieldFactory.createCommentsPopupField(task);
    footer.addComponent(commentField);

    AbstractComponent followerView = popupFieldFactory.createFollowersPopupField(task);
    footer.addComponent(followerView);

    AbstractComponent statusField = popupFieldFactory.createStatusPopupField(task);
    footer.addComponent(statusField);

    AbstractComponent milestoneField = popupFieldFactory.createMilestonePopupField(task);
    footer.addComponent(milestoneField);

    AbstractComponent percentageField = popupFieldFactory.createPercentagePopupField(task);
    footer.addComponent(percentageField);

    String deadlineTooltip = String.format("%s: %s", AppContext.getMessage(GenericI18Enum.FORM_DUE_DATE),
            AppContext.formatDate(task.getDeadline()));
    AbstractComponent deadlineField = popupFieldFactory.createDeadlinePopupField(task);
    deadlineField.setDescription(deadlineTooltip);
    footer.addComponent(deadlineField);

    AbstractComponent startDateField = popupFieldFactory.createStartDatePopupField(task);
    footer.addComponent(startDateField);

    AbstractComponent endDateField = popupFieldFactory.createEndDatePopupField(task);
    footer.addComponent(endDateField);

    if (!SiteConfiguration.isCommunityEdition()) {
        AbstractComponent billableHoursField = popupFieldFactory.createBillableHoursPopupField(task);
        footer.addComponent(billableHoursField);

        AbstractComponent nonBillableHours = popupFieldFactory.createNonBillableHoursPopupField(task);
        footer.addComponent(nonBillableHours);
    }

    this.with(headerLayout, footer);
}

From source file:com.esofthead.mycollab.module.project.view.task.TaskGroupReorderViewImpl.java

License:Open Source License

private void constructHeader() {
    CssLayout headerWrapper = new CssLayout();
    headerWrapper.setWidth("100%");
    headerWrapper.addStyleName("taskgroup-header");

    HorizontalLayout header = new HorizontalLayout();
    header.setSpacing(true);/*from   www .j  a v a 2  s .  c o  m*/
    header.setWidth("100%");
    Label headerLbl = new Label("All Tasks");
    headerLbl.setStyleName("h2");
    header.addComponent(headerLbl);
    header.setComponentAlignment(headerLbl, Alignment.MIDDLE_LEFT);
    header.setExpandRatio(headerLbl, 1.0f);

    Button backToListBtn = new Button("Back to dashboard", new Button.ClickListener() {
        private static final long serialVersionUID = 1L;

        @Override
        public void buttonClick(Button.ClickEvent event) {
            EventBusFactory.getInstance().post(new TaskListEvent.GotoTaskListScreen(this, null));
        }
    });
    backToListBtn.setStyleName(UIConstants.THEME_GREEN_LINK);
    header.addComponent(backToListBtn);
    header.setComponentAlignment(backToListBtn, Alignment.MIDDLE_RIGHT);

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

        @Override
        public void buttonClick(Button.ClickEvent event) {
            EventBusFactory.getInstance().post(new TaskListEvent.SaveReoderTaskList(event, changeSet));
        }
    });
    saveOrderBtn.setStyleName(UIConstants.THEME_GREEN_LINK);
    header.addComponent(saveOrderBtn);
    header.setComponentAlignment(saveOrderBtn, Alignment.MIDDLE_RIGHT);

    headerWrapper.addComponent(header);

    this.addComponent(headerWrapper);

    final DDVerticalLayout ddLayout = new DDVerticalLayout();
    ddLayout.addStyleName("taskgroup-reorder");
    ddLayout.setComponentVerticalDropRatio(0.3f);
    ddLayout.setDragMode(LayoutDragMode.CLONE);
    ddLayout.setDropHandler(new DropHandler() {
        private static final long serialVersionUID = 1L;

        @Override
        public AcceptCriterion getAcceptCriterion() {
            return new Not(VerticalLocationIs.MIDDLE);
        }

        @Override
        public void drop(DragAndDropEvent event) {
            LayoutBoundTransferable transferable = (LayoutBoundTransferable) event.getTransferable();

            DDVerticalLayout.VerticalLayoutTargetDetails details = (DDVerticalLayout.VerticalLayoutTargetDetails) event
                    .getTargetDetails();

            TaskListComponent comp = (TaskListComponent) transferable.getComponent();

            int currentIndex = ddLayout.getComponentIndex(comp);
            int newIndex = details.getOverIndex();

            ddLayout.removeComponent(comp);

            if (currentIndex > newIndex && details.getDropLocation() == VerticalDropLocation.BOTTOM) {
                newIndex++;
            }

            SimpleTaskList dropTaskList = comp.getTaskList();
            dropTaskList.setGroupindex(newIndex);
            changeSet.add(dropTaskList);
            ddLayout.addComponent(comp, newIndex);

            // change affected task list items
            for (int i = 0; i < ddLayout.getComponentCount(); i++) {
                TaskListComponent affectedComp = (TaskListComponent) ddLayout.getComponent(i);
                SimpleTaskList affectedTaskList = affectedComp.getTaskList();
                affectedTaskList.setGroupindex(i);
                changeSet.add(affectedTaskList);
            }
        }
    });

    taskLists = new BeanList<ProjectTaskListService, TaskListSearchCriteria, SimpleTaskList>(null,
            ApplicationContextUtil.getSpringBean(ProjectTaskListService.class), TaskListRowDisplayHandler.class,
            ddLayout);
    this.addComponent(taskLists);
}

From source file:com.esofthead.mycollab.module.project.view.task.TaskSearchTableDisplay.java

License:Open Source License

public TaskSearchTableDisplay(TableViewField requiredColumn, List<TableViewField> displayColumns) {
    super(ApplicationContextUtil.getSpringBean(ProjectTaskService.class), SimpleTask.class, requiredColumn,
            displayColumns);//from   w ww.  ja v a2  s.  c om

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

        @Override
        public com.vaadin.ui.Component generateCell(Table source, final Object itemId, Object columnId) {
            final SimpleTask task = TaskSearchTableDisplay.this.getBeanByIndex(itemId);

            CssLayout taskName = new CssLayout();

            String taskname = "[%s-%s] %s";
            taskname = String.format(taskname, CurrentProjectVariables.getProject().getShortname(),
                    task.getTaskkey(), task.getTaskname());
            LabelLink b = new LabelLink(taskname, ProjectLinkBuilder
                    .generateTaskPreviewFullLink(task.getTaskkey(), task.getProjectShortname()));
            b.setDescription(ProjectTooltipGenerator.generateToolTipTask(AppContext.getUserLocale(), task,
                    AppContext.getSiteUrl(), AppContext.getTimezone()));

            if (StringUtils.isNotBlank(task.getPriority())) {
                b.setIconLink(ProjectResources.getIconResourceLink12ByTaskPriority(task.getPriority()));

            }

            if (task.getPercentagecomplete() != null && 100d == task.getPercentagecomplete()) {
                b.addStyleName(UIConstants.LINK_COMPLETED);
            } else {
                if ("Pending".equals(task.getStatus())) {
                    b.addStyleName(UIConstants.LINK_PENDING);
                } else if ((task.getEnddate() != null
                        && (task.getEnddate().before(new GregorianCalendar().getTime())))
                        || (task.getActualenddate() != null
                                && (task.getActualenddate().before(new GregorianCalendar().getTime())))
                        || (task.getDeadline() != null
                                && (task.getDeadline().before(new GregorianCalendar().getTime())))) {
                    b.addStyleName(UIConstants.LINK_OVERDUE);
                }
            }

            taskName.addComponent(b);
            taskName.setWidth("100%");
            taskName.setHeightUndefined();
            return taskName;

        }
    });

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

        @Override
        public com.vaadin.ui.Component generateCell(Table source, final Object itemId, Object columnId) {
            final SimpleTask task = TaskSearchTableDisplay.this.getBeanByIndex(itemId);
            Double percomp = (task.getPercentagecomplete() == null) ? new Double(0)
                    : task.getPercentagecomplete();
            ProgressPercentageIndicator progress = new ProgressPercentageIndicator(percomp);
            progress.setWidth("100px");
            return progress;
        }
    });

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

        @Override
        public com.vaadin.ui.Component generateCell(Table source, final Object itemId, Object columnId) {
            final SimpleTask task = TaskSearchTableDisplay.this.getBeanByIndex(itemId);
            return new Label(AppContext.formatDate(task.getStartdate()));

        }
    });

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

        @Override
        public com.vaadin.ui.Component generateCell(Table source, final Object itemId, Object columnId) {
            final SimpleTask task = TaskSearchTableDisplay.this.getBeanByIndex(itemId);
            return new Label(AppContext.formatDate(task.getDeadline()));

        }
    });

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

        @Override
        public com.vaadin.ui.Component generateCell(Table source, final Object itemId, Object columnId) {
            final SimpleTask task = TaskSearchTableDisplay.this.getBeanByIndex(itemId);
            PopupButton taskSettingPopupBtn = new PopupButton();
            VerticalLayout filterBtnLayout = new VerticalLayout();
            filterBtnLayout.setMargin(true);
            filterBtnLayout.setSpacing(true);
            filterBtnLayout.setWidth("100px");

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

                        @Override
                        public void buttonClick(ClickEvent event) {
                            EventBusFactory.getInstance()
                                    .post(new TaskEvent.GotoEdit(TaskSearchTableDisplay.this, task));
                        }
                    });
            editButton.setEnabled(CurrentProjectVariables.canWrite(ProjectRolePermissionCollections.TASKS));
            editButton.setStyleName("link");
            filterBtnLayout.addComponent(editButton);

            if ((task.getPercentagecomplete() != null && task.getPercentagecomplete() != 100)
                    || task.getPercentagecomplete() == null) {
                Button closeBtn = new Button("Close", new Button.ClickListener() {
                    private static final long serialVersionUID = 1L;

                    @Override
                    public void buttonClick(Button.ClickEvent event) {
                        task.setStatus("Closed");
                        task.setPercentagecomplete(100d);

                        ProjectTaskService projectTaskService = ApplicationContextUtil
                                .getSpringBean(ProjectTaskService.class);
                        projectTaskService.updateWithSession(task, AppContext.getUsername());

                        fireTableEvent(new TableClickEvent(TaskSearchTableDisplay.this, task, "closeTask"));
                    }
                });
                closeBtn.setStyleName("link");
                closeBtn.setEnabled(CurrentProjectVariables.canWrite(ProjectRolePermissionCollections.TASKS));
                filterBtnLayout.addComponent(closeBtn);
            } else {
                Button reOpenBtn = new Button("ReOpen", new Button.ClickListener() {
                    private static final long serialVersionUID = 1L;

                    @Override
                    public void buttonClick(Button.ClickEvent event) {
                        task.setStatus("Open");
                        task.setPercentagecomplete(0d);

                        ProjectTaskService projectTaskService = ApplicationContextUtil
                                .getSpringBean(ProjectTaskService.class);
                        projectTaskService.updateWithSession(task, AppContext.getUsername());
                        fireTableEvent(new TableClickEvent(TaskSearchTableDisplay.this, task, "reopenTask"));
                    }
                });
                reOpenBtn.setStyleName("link");
                reOpenBtn.setEnabled(CurrentProjectVariables.canWrite(ProjectRolePermissionCollections.TASKS));
                filterBtnLayout.addComponent(reOpenBtn);
            }

            if (!"Pending".equals(task.getStatus())) {
                if (!"Closed".equals(task.getStatus())) {
                    Button pendingBtn = new Button("Pending", new Button.ClickListener() {
                        private static final long serialVersionUID = 1L;

                        @Override
                        public void buttonClick(ClickEvent event) {
                            task.setStatus("Pending");
                            task.setPercentagecomplete(0d);

                            ProjectTaskService projectTaskService = ApplicationContextUtil
                                    .getSpringBean(ProjectTaskService.class);
                            projectTaskService.updateWithSession(task, AppContext.getUsername());
                            fireTableEvent(
                                    new TableClickEvent(TaskSearchTableDisplay.this, task, "pendingTask"));
                        }
                    });
                    pendingBtn.setStyleName("link");
                    pendingBtn.setEnabled(
                            CurrentProjectVariables.canWrite(ProjectRolePermissionCollections.TASKS));
                    filterBtnLayout.addComponent(pendingBtn);
                }
            } else {
                Button reOpenBtn = new Button("ReOpen", new Button.ClickListener() {
                    private static final long serialVersionUID = 1L;

                    @Override
                    public void buttonClick(Button.ClickEvent event) {
                        task.setStatus("Open");
                        task.setPercentagecomplete(0d);

                        ProjectTaskService projectTaskService = ApplicationContextUtil
                                .getSpringBean(ProjectTaskService.class);
                        projectTaskService.updateWithSession(task, AppContext.getUsername());

                        fireTableEvent(new TableClickEvent(TaskSearchTableDisplay.this, task, "reopenTask"));
                    }
                });
                reOpenBtn.setStyleName("link");
                reOpenBtn.setEnabled(CurrentProjectVariables.canWrite(ProjectRolePermissionCollections.TASKS));
                filterBtnLayout.addComponent(reOpenBtn);
            }

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

                        @Override
                        public void buttonClick(ClickEvent event) {
                            ConfirmDialogExt.show(UI.getCurrent(),
                                    AppContext.getMessage(GenericI18Enum.DIALOG_DELETE_TITLE,
                                            SiteConfiguration.getSiteName()),
                                    AppContext.getMessage(GenericI18Enum.DIALOG_DELETE_SINGLE_ITEM_MESSAGE),
                                    AppContext.getMessage(GenericI18Enum.BUTTON_YES),
                                    AppContext.getMessage(GenericI18Enum.BUTTON_NO),
                                    new ConfirmDialog.Listener() {
                                        private static final long serialVersionUID = 1L;

                                        @Override
                                        public void onClose(ConfirmDialog dialog) {
                                            if (dialog.isConfirmed()) {
                                                ProjectTaskService projectTaskService = ApplicationContextUtil
                                                        .getSpringBean(ProjectTaskService.class);
                                                projectTaskService.removeWithSession(task.getId(),
                                                        AppContext.getUsername(), AppContext.getAccountId());
                                                fireTableEvent(new TableClickEvent(TaskSearchTableDisplay.this,
                                                        task, "deleteTask"));
                                            }
                                        }
                                    });
                        }
                    });
            deleteBtn.setStyleName("link");
            deleteBtn.setEnabled(CurrentProjectVariables.canAccess(ProjectRolePermissionCollections.TASKS));
            filterBtnLayout.addComponent(deleteBtn);

            taskSettingPopupBtn.setIcon(MyCollabResource.newResource("icons/16/item_settings.png"));
            taskSettingPopupBtn.setStyleName("link");
            taskSettingPopupBtn.setContent(filterBtnLayout);
            return taskSettingPopupBtn;
        }
    });

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

        @Override
        public com.vaadin.ui.Component generateCell(Table source, final Object itemId, Object columnId) {
            final SimpleTask task = TaskSearchTableDisplay.this.getBeanByIndex(itemId);
            return new ProjectUserLink(task.getAssignuser(), task.getAssignUserAvatarId(),
                    task.getAssignUserFullName());

        }
    });
    this.setWidth("100%");
}

From source file:com.esofthead.mycollab.module.project.view.task.TaskTableDisplay.java

License:Open Source License

public TaskTableDisplay(TableViewField requiredColumn, List<TableViewField> displayColumns, int displayNums) {
    super(ApplicationContextUtil.getSpringBean(ProjectTaskService.class), SimpleTask.class, requiredColumn,
            displayColumns);//from   ww  w .j a va  2  s.com
    this.displayNumItems = displayNums;

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

        @Override
        public com.vaadin.ui.Component generateCell(Table source, final Object itemId, Object columnId) {
            final SimpleTask task = TaskTableDisplay.this.getBeanByIndex(itemId);

            CssLayout taskName = new CssLayout();

            String taskname = "[%s-%s] %s";
            taskname = String.format(taskname, CurrentProjectVariables.getProject().getShortname(),
                    task.getTaskkey(), task.getTaskname());

            LabelLink b = new LabelLink(taskname, ProjectLinkBuilder
                    .generateTaskPreviewFullLink(task.getTaskkey(), task.getProjectShortname()));
            b.setDescription(ProjectTooltipGenerator.generateToolTipTask(AppContext.getUserLocale(), task,
                    AppContext.getSiteUrl(), AppContext.getTimezone()));

            if (StringUtils.isNotBlank(task.getPriority())) {
                b.setIconLink(ProjectResources.getIconResourceLink12ByTaskPriority(task.getPriority()));

            }

            if (task.isCompleted()) {
                b.addStyleName(UIConstants.LINK_COMPLETED);
            } else if (task.isPending()) {
                b.addStyleName(UIConstants.LINK_PENDING);
            } else if (task.isOverdue()) {
                b.addStyleName(UIConstants.LINK_OVERDUE);
            }

            taskName.addComponent(b);
            taskName.setWidth("100%");
            taskName.setHeightUndefined();
            return taskName;

        }
    });

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

        @Override
        public com.vaadin.ui.Component generateCell(Table source, final Object itemId, Object columnId) {
            final SimpleTask task = TaskTableDisplay.this.getBeanByIndex(itemId);
            Double percomp = (task.getPercentagecomplete() == null) ? new Double(0)
                    : task.getPercentagecomplete();
            ProgressPercentageIndicator progress = new ProgressPercentageIndicator(percomp);
            progress.setWidth("100px");
            return progress;
        }
    });

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

        @Override
        public com.vaadin.ui.Component generateCell(Table source, final Object itemId, Object columnId) {
            final SimpleTask task = TaskTableDisplay.this.getBeanByIndex(itemId);
            return new Label(AppContext.formatDate(task.getStartdate()));

        }
    });

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

        @Override
        public com.vaadin.ui.Component generateCell(Table source, final Object itemId, Object columnId) {
            final SimpleTask task = TaskTableDisplay.this.getBeanByIndex(itemId);
            return new Label(AppContext.formatDate(task.getDeadline()));

        }
    });

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

        @Override
        public com.vaadin.ui.Component generateCell(Table source, final Object itemId, Object columnId) {
            final SimpleTask task = TaskTableDisplay.this.getBeanByIndex(itemId);
            PopupButton taskSettingPopupBtn = new PopupButton();
            taskSettingPopupBtn.setIcon(MyCollabResource.newResource("icons/16/item_settings.png"));
            taskSettingPopupBtn.setStyleName("link");
            taskSettingPopupBtn.addStyleName("noDefaultIcon");

            MVerticalLayout filterBtnLayout = new MVerticalLayout().withSpacing(true).withMargin(true)
                    .withWidth("100px");

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

                        @Override
                        public void buttonClick(ClickEvent event) {
                            EventBusFactory.getInstance()
                                    .post(new TaskEvent.GotoEdit(TaskTableDisplay.this, task));
                        }
                    });
            editButton.setEnabled(CurrentProjectVariables.canWrite(ProjectRolePermissionCollections.TASKS));
            editButton.setStyleName("link");
            filterBtnLayout.addComponent(editButton);

            if ((task.getPercentagecomplete() != null && task.getPercentagecomplete() != 100)
                    || task.getPercentagecomplete() == null) {
                Button closeBtn = new Button(AppContext.getMessage(GenericI18Enum.BUTTON_CLOSE),
                        new Button.ClickListener() {
                            private static final long serialVersionUID = 1L;

                            @Override
                            public void buttonClick(Button.ClickEvent event) {
                                task.setStatus(StatusI18nEnum.Closed.name());
                                task.setPercentagecomplete(100d);

                                ProjectTaskService projectTaskService = ApplicationContextUtil
                                        .getSpringBean(ProjectTaskService.class);
                                projectTaskService.updateSelectiveWithSession(task, AppContext.getUsername());

                                fireTableEvent(new TableClickEvent(TaskTableDisplay.this, task, "closeTask"));
                            }
                        });
                closeBtn.setStyleName("link");
                closeBtn.setEnabled(CurrentProjectVariables.canWrite(ProjectRolePermissionCollections.TASKS));
                filterBtnLayout.addComponent(closeBtn);
            } else {
                Button reOpenBtn = new Button("ReOpen", new Button.ClickListener() {
                    private static final long serialVersionUID = 1L;

                    @Override
                    public void buttonClick(Button.ClickEvent event) {
                        task.setStatus(StatusI18nEnum.Open.name());
                        task.setPercentagecomplete(0d);

                        ProjectTaskService projectTaskService = ApplicationContextUtil
                                .getSpringBean(ProjectTaskService.class);
                        projectTaskService.updateSelectiveWithSession(task, AppContext.getUsername());
                        fireTableEvent(new TableClickEvent(TaskTableDisplay.this, task, "reopenTask"));
                    }
                });
                reOpenBtn.setStyleName("link");
                reOpenBtn.setEnabled(CurrentProjectVariables.canWrite(ProjectRolePermissionCollections.TASKS));
                filterBtnLayout.addComponent(reOpenBtn);
            }

            if (!"Pending".equals(task.getStatus())) {
                if (!"Closed".equals(task.getStatus())) {
                    Button pendingBtn = new Button("Pending", new Button.ClickListener() {
                        private static final long serialVersionUID = 1L;

                        @Override
                        public void buttonClick(ClickEvent event) {
                            task.setStatus("Pending");
                            task.setPercentagecomplete(0d);

                            ProjectTaskService projectTaskService = ApplicationContextUtil
                                    .getSpringBean(ProjectTaskService.class);
                            projectTaskService.updateSelectiveWithSession(task, AppContext.getUsername());
                            fireTableEvent(new TableClickEvent(TaskTableDisplay.this, task, "pendingTask"));
                        }
                    });
                    pendingBtn.setStyleName("link");
                    pendingBtn.setEnabled(
                            CurrentProjectVariables.canWrite(ProjectRolePermissionCollections.TASKS));
                    filterBtnLayout.addComponent(pendingBtn);
                }
            } else {
                Button reOpenBtn = new Button("ReOpen", new Button.ClickListener() {
                    private static final long serialVersionUID = 1L;

                    @Override
                    public void buttonClick(Button.ClickEvent event) {
                        task.setStatus("Open");
                        task.setPercentagecomplete(0d);

                        ProjectTaskService projectTaskService = ApplicationContextUtil
                                .getSpringBean(ProjectTaskService.class);
                        projectTaskService.updateSelectiveWithSession(task, AppContext.getUsername());

                        fireTableEvent(new TableClickEvent(TaskTableDisplay.this, task, "reopenTask"));
                    }
                });
                reOpenBtn.setStyleName("link");
                reOpenBtn.setEnabled(CurrentProjectVariables.canWrite(ProjectRolePermissionCollections.TASKS));
                filterBtnLayout.addComponent(reOpenBtn);
            }

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

                        @Override
                        public void buttonClick(ClickEvent event) {
                            ConfirmDialogExt.show(UI.getCurrent(),
                                    AppContext.getMessage(GenericI18Enum.DIALOG_DELETE_TITLE,
                                            SiteConfiguration.getSiteName()),
                                    AppContext.getMessage(GenericI18Enum.DIALOG_DELETE_SINGLE_ITEM_MESSAGE),
                                    AppContext.getMessage(GenericI18Enum.BUTTON_YES),
                                    AppContext.getMessage(GenericI18Enum.BUTTON_NO),
                                    new ConfirmDialog.Listener() {
                                        private static final long serialVersionUID = 1L;

                                        @Override
                                        public void onClose(ConfirmDialog dialog) {
                                            if (dialog.isConfirmed()) {
                                                ProjectTaskService projectTaskService = ApplicationContextUtil
                                                        .getSpringBean(ProjectTaskService.class);
                                                projectTaskService.removeWithSession(task.getId(),
                                                        AppContext.getUsername(), AppContext.getAccountId());
                                                fireTableEvent(new TableClickEvent(TaskTableDisplay.this, task,
                                                        "deleteTask"));
                                            }
                                        }
                                    });
                        }
                    });
            deleteBtn.setStyleName("link");
            deleteBtn.setEnabled(CurrentProjectVariables.canAccess(ProjectRolePermissionCollections.TASKS));
            filterBtnLayout.addComponent(deleteBtn);

            taskSettingPopupBtn.setContent(filterBtnLayout);
            return taskSettingPopupBtn;
        }
    });

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

        @Override
        public com.vaadin.ui.Component generateCell(Table source, final Object itemId, Object columnId) {
            final SimpleTask task = TaskTableDisplay.this.getBeanByIndex(itemId);
            return new ProjectUserLink(task.getAssignuser(), task.getAssignUserAvatarId(),
                    task.getAssignUserFullName());

        }
    });
    this.setWidth("100%");
}