Example usage for com.vaadin.ui.renderers DateRenderer DateRenderer

List of usage examples for com.vaadin.ui.renderers DateRenderer DateRenderer

Introduction

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

Prototype

public DateRenderer(DateFormat dateFormat) throws IllegalArgumentException 

Source Link

Document

Creates a new date renderer.

Usage

From source file:ch.wscr.management.ui.view.MemberView.java

/**
 * Die Darstellung der Daten im Grid mit Renderern anpassen
 *
 * @param grid das Grid fr die Mitgliederverwaltung
 *///from  w  ww . j ava 2s  .  com
private void setColumnRenderers(final Grid grid) {
    grid.getColumn("memberId").setRenderer(new EditDeleteButtonValueRenderer(
            new EditDeleteButtonValueRenderer.EditDeleteButtonClickListener() {
                @Override
                public void onEdit(ClickableRenderer.RendererClickEvent rendererClickEvent) {
                    grid.setEditorEnabled(true);
                    grid.editItem(rendererClickEvent.getItemId());
                }

                @Override
                public void onDelete(ClickableRenderer.RendererClickEvent rendererClickEvent) {

                }
            })).setWidth(120);

    grid.getColumn("driverLicense").setRenderer(new BooleanRenderer()).setWidth(120);
    grid.getColumn("birthDate").setRenderer(new DateRenderer(DateFormat.getDateInstance(DateFormat.SHORT)))
            .setWidth(120);
}

From source file:com.github.cjm.TmdbUI.java

private void addTvShowGrid() {

    tvShowGridLayout.setSpacing(true);// w  w w.jav  a2 s .c  om
    tvShowGridLayout.setWidth("100%");
    tvShowGrid = new Grid();
    tvShowGrid.setSizeFull();
    tvShows = new BeanItemContainer<>(TvShow.class);
    tvShowGrid.setColumns("name", "popularity", "voteAverage", "firstAirDate");
    tvShowGrid.setHeaderVisible(true);
    tvShowGrid.setContainerDataSource(tvShows);
    HeaderRow filterRow = tvShowGrid.appendHeaderRow();
    // Not really loading "all"; multiple pages up to some reasonable/polite limit 
    // (API is throttled and this is a demo afterall).
    tvShows.addAll(
            tvShowService.loadAll(TvShowService.RESOURCE_TV_POPULAR, TvShowCollection.class).getResults());
    tvShowGridLayout.addComponent(tvShowGrid);
    mainLayout.addComponent(tvShowGridLayout);

    tvShowGrid.getContainerDataSource().getContainerPropertyIds().stream().forEach((pid) -> {
        if (tvShowGrid.getColumn(pid) != null) {
            Grid.HeaderCell cell = filterRow.getCell(pid);

            TextField filterField = new TextField();
            filterField.setColumns(8);
            // Update filter When the filter input is changed
            filterField.addTextChangeListener(change -> {
                // Can't modify filters so need to replace
                tvShows.removeContainerFilters(pid);
                // (Re)create the filter if necessary
                if (!change.getText().isEmpty()) {
                    tvShows.addContainerFilter(new SimpleStringFilter(pid, change.getText(), true, false));
                }
            });
            filterField.setImmediate(true);
            cell.setComponent(filterField);

        }
    });

    SimpleDateFormat dateFormat = new SimpleDateFormat("MM/dd/yyyy");
    DateRenderer dateRenderer = new DateRenderer(dateFormat);
    tvShowGrid.getColumn("firstAirDate").setRenderer(dateRenderer);

    tvShowGrid.addItemClickListener((ItemClickEvent event) -> {
        if (event.isDoubleClick()) {
            User u = (User) username.getValue();
            if (u != null) {
                users.removeItem(u);
                TvShow tvShow = getSelectedTvShow();
                if (tvShow != null) {
                    favorites.addBean(tvShow);
                    List<Integer> i = new ArrayList<>();
                    favorites.getItemIds().stream().forEach((t) -> {
                        i.add(t.getId());
                    });
                    u.setFavoriteTvShows(new Integer[i.size()]);
                    u.setFavoriteTvShows(i.toArray(u.getFavoriteTvShows()));
                    userDao.save(u);
                    users.addBean(u);
                }
            }
        }
    });

}

From source file:de.symeda.sormas.ui.caze.CaseGrid.java

License:Open Source License

@SuppressWarnings("unchecked")
public CaseGrid() {
    super(CaseIndexDto.class);
    setSizeFull();//from  ww  w  . j  a v  a  2s .co  m

    if (UserProvider.getCurrent().hasUserRight(UserRight.PERFORM_BULK_OPERATIONS)) {
        setSelectionMode(SelectionMode.MULTI);
    } else {
        setSelectionMode(SelectionMode.NONE);
    }

    DataProvider<CaseIndexDto, CaseCriteria> dataProvider = DataProvider
            .fromFilteringCallbacks(query -> FacadeProvider.getCaseFacade()
                    .getIndexList(UserProvider.getCurrent().getUuid(), query.getFilter().orElse(null),
                            query.getOffset(), query.getLimit(),
                            query.getSortOrders().stream()
                                    .map(sortOrder -> new SortProperty(sortOrder.getSorted(),
                                            sortOrder.getDirection() == SortDirection.ASCENDING))
                                    .collect(Collectors.toList()))
                    .stream(), query -> {
                        return (int) FacadeProvider.getCaseFacade().count(UserProvider.getCurrent().getUuid(),
                                query.getFilter().orElse(null));
                    });
    setDataProvider(dataProvider);

    Column<CaseIndexDto, String> diseaseShortColumn = addColumn(
            caze -> DiseaseHelper.toString(caze.getDisease(), caze.getDiseaseDetails()));
    diseaseShortColumn.setId(DISEASE_SHORT);
    diseaseShortColumn.setSortProperty(CaseIndexDto.DISEASE);

    setColumns(CaseIndexDto.UUID, CaseIndexDto.EPID_NUMBER, DISEASE_SHORT, CaseIndexDto.CASE_CLASSIFICATION,
            CaseIndexDto.OUTCOME, CaseIndexDto.INVESTIGATION_STATUS, CaseIndexDto.PERSON_FIRST_NAME,
            CaseIndexDto.PERSON_LAST_NAME, CaseIndexDto.DISTRICT_NAME, CaseIndexDto.HEALTH_FACILITY_NAME,
            CaseIndexDto.POINT_OF_ENTRY_NAME, CaseIndexDto.REPORT_DATE, CaseIndexDto.CREATION_DATE);

    ((Column<CaseIndexDto, String>) getColumn(CaseIndexDto.UUID)).setRenderer(new UuidRenderer());
    ((Column<CaseIndexDto, Date>) getColumn(CaseIndexDto.REPORT_DATE))
            .setRenderer(new DateRenderer(DateHelper.getLocalDateTimeFormat()));

    if (UserProvider.getCurrent().hasUserRight(UserRight.CASE_IMPORT)) {
        ((Column<CaseIndexDto, Date>) getColumn(CaseIndexDto.CREATION_DATE))
                .setRenderer(new DateRenderer(DateHelper.getLocalDateTimeFormat()));
    } else {
        removeColumn(CaseIndexDto.CREATION_DATE);
    }

    for (Column<?, ?> column : getColumns()) {
        column.setCaption(I18nProperties.getPrefixCaption(CaseIndexDto.I18N_PREFIX, column.getId().toString(),
                column.getCaption()));
    }

    addItemClickListener(e -> {
        if ((e.getColumn() != null && CaseIndexDto.UUID.equals(e.getColumn().getId()))
                || e.getMouseEventDetails().isDoubleClick()) {
            ControllerProvider.getCaseController().navigateToCase(e.getItem().getUuid());
        }
    });
}

From source file:de.symeda.sormas.ui.events.EventGrid.java

License:Open Source License

@SuppressWarnings("unchecked")
public EventGrid() {
    super(EventIndexDto.class);
    setSizeFull();/*from ww w  . ja va 2s  .  c o  m*/

    if (UserProvider.getCurrent().hasUserRight(UserRight.PERFORM_BULK_OPERATIONS)) {
        setSelectionMode(SelectionMode.MULTI);
    } else {
        setSelectionMode(SelectionMode.NONE);
    }

    DataProvider<EventIndexDto, EventCriteria> dataProvider = DataProvider
            .fromFilteringCallbacks(query -> FacadeProvider.getEventFacade()
                    .getIndexList(UserProvider.getCurrent().getUuid(), query.getFilter().orElse(null),
                            query.getOffset(), query.getLimit(),
                            query.getSortOrders().stream()
                                    .map(sortOrder -> new SortProperty(sortOrder.getSorted(),
                                            sortOrder.getDirection() == SortDirection.ASCENDING))
                                    .collect(Collectors.toList()))
                    .stream(), query -> {
                        return (int) FacadeProvider.getEventFacade().count(UserProvider.getCurrent().getUuid(),
                                query.getFilter().orElse(null));
                    });
    setDataProvider(dataProvider);

    Column<EventIndexDto, String> diseaseShortColumn = addColumn(
            entry -> DiseaseHelper.toString(entry.getDisease(), entry.getDiseaseDetails()));
    diseaseShortColumn.setId(DISEASE_SHORT);
    diseaseShortColumn.setSortProperty(EventIndexDto.DISEASE);

    Column<EventIndexDto, String> informationSourceColumn = addColumn(
            event -> (event.getSrcFirstName() != null ? event.getSrcFirstName() : "") + " "
                    + (event.getSrcLastName() != null ? event.getSrcLastName() : "")
                    + (event.getSrcTelNo() != null && !event.getSrcTelNo().isEmpty()
                            ? " (" + event.getSrcTelNo() + ")"
                            : ""));
    informationSourceColumn.setId(INFORMATION_SOURCE);
    informationSourceColumn.setSortable(false);

    Column<EventIndexDto, String> pendingTasksColumn = addColumn(
            entry -> String.format(I18nProperties.getCaption(Captions.formatSimpleNumberFormat),
                    FacadeProvider.getTaskFacade().getPendingTaskCountByEvent(entry.toReference())));
    pendingTasksColumn.setId(NUMBER_OF_PENDING_TASKS);
    pendingTasksColumn.setSortable(false);

    setColumns(EventIndexDto.UUID, EventIndexDto.EVENT_STATUS, EventIndexDto.EVENT_DATE, DISEASE_SHORT,
            EventIndexDto.EVENT_DESC, EventIndexDto.EVENT_LOCATION, INFORMATION_SOURCE,
            EventIndexDto.REPORT_DATE_TIME, NUMBER_OF_PENDING_TASKS);

    ((Column<EventIndexDto, String>) getColumn(EventIndexDto.UUID)).setRenderer(new UuidRenderer());
    ((Column<EventIndexDto, Date>) getColumn(EventIndexDto.EVENT_DATE))
            .setRenderer(new DateRenderer(DateHelper.getLocalDateTimeFormat()));
    ((Column<EventIndexDto, Date>) getColumn(EventIndexDto.REPORT_DATE_TIME))
            .setRenderer(new DateRenderer(DateHelper.getLocalDateTimeFormat()));

    for (Column<?, ?> column : getColumns()) {
        column.setCaption(I18nProperties.getPrefixCaption(EventIndexDto.I18N_PREFIX, column.getId().toString(),
                column.getCaption()));
    }

    addItemClickListener(e -> {
        if ((e.getColumn() != null && EventIndexDto.UUID.equals(e.getColumn().getId()))
                || e.getMouseEventDetails().isDoubleClick()) {
            ControllerProvider.getEventController().navigateToData(e.getItem().getUuid());
        }
    });
}

From source file:de.symeda.sormas.ui.samples.SampleGrid.java

License:Open Source License

@SuppressWarnings("unchecked")
public SampleGrid() {
    super(SampleIndexDto.class);
    setSizeFull();//from w w w.  j  a  v a 2  s.co  m

    if (UserProvider.getCurrent().hasUserRight(UserRight.PERFORM_BULK_OPERATIONS)) {
        setSelectionMode(SelectionMode.MULTI);
    } else {
        setSelectionMode(SelectionMode.NONE);
    }

    DataProvider<SampleIndexDto, SampleCriteria> dataProvider = DataProvider
            .fromFilteringCallbacks(query -> FacadeProvider.getSampleFacade()
                    .getIndexList(UserProvider.getCurrent().getUuid(), query.getFilter().orElse(null),
                            query.getOffset(), query.getLimit(),
                            query.getSortOrders().stream()
                                    .map(sortOrder -> new SortProperty(sortOrder.getSorted(),
                                            sortOrder.getDirection() == SortDirection.ASCENDING))
                                    .collect(Collectors.toList()))
                    .stream(), query -> {
                        return (int) FacadeProvider.getSampleFacade().count(UserProvider.getCurrent().getUuid(),
                                query.getFilter().orElse(null));
                    });
    setDataProvider(dataProvider);

    Column<SampleIndexDto, String> editColumn = addColumn(entry -> VaadinIcons.EDIT.getHtml(),
            new HtmlRenderer());
    editColumn.setId(EDIT_BTN_ID);
    editColumn.setWidth(20);

    Column<SampleIndexDto, String> diseaseShortColumn = addColumn(
            sample -> DiseaseHelper.toString(sample.getDisease(), sample.getDiseaseDetails()));
    diseaseShortColumn.setId(DISEASE_SHORT);
    diseaseShortColumn.setSortProperty(SampleIndexDto.DISEASE);

    Column<SampleIndexDto, String> pathogenTestResultColumn = addColumn(sample -> {
        if (sample.getPathogenTestResult() != null) {
            return sample.getPathogenTestResult().toString();
        } else if (sample.getSpecimenCondition() == SpecimenCondition.NOT_ADEQUATE) {
            return I18nProperties.getCaption(Captions.sampleSpecimenNotAdequate);
        } else {
            return "";
        }
    });
    pathogenTestResultColumn.setId(PATHOGEN_TEST_RESULT);
    pathogenTestResultColumn.setSortProperty(SampleIndexDto.PATHOGEN_TEST_RESULT);

    setColumns(EDIT_BTN_ID, SampleIndexDto.LAB_SAMPLE_ID, SampleIndexDto.EPID_NUMBER,
            SampleIndexDto.ASSOCIATED_CASE, DISEASE_SHORT, SampleIndexDto.CASE_DISTRICT, SampleIndexDto.SHIPPED,
            SampleIndexDto.RECEIVED, SampleIndexDto.SHIPMENT_DATE, SampleIndexDto.RECEIVED_DATE,
            SampleIndexDto.LAB, SampleIndexDto.SAMPLE_MATERIAL, PATHOGEN_TEST_RESULT,
            SampleIndexDto.ADDITIONAL_TESTING_STATUS);

    ((Column<SampleIndexDto, Date>) getColumn(SampleIndexDto.SHIPMENT_DATE))
            .setRenderer(new DateRenderer(DateHelper.getLocalDateFormat()));
    ((Column<SampleIndexDto, Date>) getColumn(SampleIndexDto.RECEIVED_DATE))
            .setRenderer(new DateRenderer(DateHelper.getLocalDateFormat()));
    ((Column<SampleIndexDto, Boolean>) getColumn(SampleIndexDto.SHIPPED)).setRenderer(new BooleanRenderer());
    ((Column<SampleIndexDto, String>) getColumn(SampleIndexDto.RECEIVED)).setRenderer(new BooleanRenderer());
    ((Column<SampleIndexDto, String>) getColumn(SampleIndexDto.LAB)).setMaximumWidth(200);
    ((Column<SampleIndexDto, String>) getColumn(SampleIndexDto.ADDITIONAL_TESTING_STATUS)).setSortable(false);

    if (UserProvider.getCurrent().hasUserRole(UserRole.LAB_USER)
            || UserProvider.getCurrent().hasUserRole(UserRole.EXTERNAL_LAB_USER)) {
        removeColumn(SampleIndexDto.SHIPMENT_DATE);
    } else {
        removeColumn(SampleIndexDto.RECEIVED_DATE);
    }

    if (UserProvider.getCurrent().hasUserRole(UserRole.EXTERNAL_LAB_USER)) {
        removeColumn(SampleIndexDto.ASSOCIATED_CASE);
    }

    if (!UserProvider.getCurrent().hasUserRight(UserRight.ADDITIONAL_TEST_VIEW)) {
        removeColumn(SampleIndexDto.ADDITIONAL_TESTING_STATUS);
    }

    for (Column<?, ?> column : getColumns()) {
        column.setCaption(I18nProperties.getPrefixCaption(SampleIndexDto.I18N_PREFIX, column.getId().toString(),
                column.getCaption()));
    }

    addItemClickListener(e -> {
        if (e.getColumn() != null
                && (EDIT_BTN_ID.equals(e.getColumn().getId()) || e.getMouseEventDetails().isDoubleClick())) {
            ControllerProvider.getSampleController().navigateToData(e.getItem().getUuid());
        }
    });
}

From source file:de.symeda.sormas.ui.task.TaskGrid.java

License:Open Source License

@SuppressWarnings("unchecked")
public TaskGrid() {
    super(TaskIndexDto.class);
    setSizeFull();/*w  ww. j a v  a2s .  co  m*/

    if (UserProvider.getCurrent().hasUserRight(UserRight.PERFORM_BULK_OPERATIONS)) {
        setSelectionMode(SelectionMode.MULTI);
    } else {
        setSelectionMode(SelectionMode.NONE);
    }

    DataProvider<TaskIndexDto, TaskCriteria> dataProvider = DataProvider
            .fromFilteringCallbacks(query -> FacadeProvider.getTaskFacade()
                    .getIndexList(UserProvider.getCurrent().getUuid(), query.getFilter().orElse(null),
                            query.getOffset(), query.getLimit(),
                            query.getSortOrders().stream()
                                    .map(sortOrder -> new SortProperty(sortOrder.getSorted(),
                                            sortOrder.getDirection() == SortDirection.ASCENDING))
                                    .collect(Collectors.toList()))
                    .stream(), query -> {
                        return (int) FacadeProvider.getTaskFacade().count(UserProvider.getCurrent().getUuid(),
                                query.getFilter().orElse(null));
                    });
    setDataProvider(dataProvider);

    Column<TaskIndexDto, String> editColumn = addColumn(entry -> VaadinIcons.EDIT.getHtml(),
            new HtmlRenderer());
    editColumn.setId(EDIT_BTN_ID);
    editColumn.setWidth(20);

    setStyleGenerator(item -> {
        if (item != null && item.getTaskStatus() != null) {
            switch (item.getTaskStatus()) {
            case REMOVED:
                return CssStyles.GRID_ROW_STATUS_DISCARDED;
            case NOT_EXECUTABLE:
                return CssStyles.GRID_ROW_STATUS_NOT;
            case DONE:
                return CssStyles.GRID_ROW_STATUS_DONE;
            case PENDING:
                return CssStyles.GRID_ROW_STATUS_PENDING;
            default:
                throw new IndexOutOfBoundsException(item.getTaskStatus().toString());
            }
        }
        return null;
    });

    setColumns(EDIT_BTN_ID, TaskIndexDto.CONTEXT_REFERENCE, TaskIndexDto.TASK_TYPE, TaskIndexDto.PRIORITY,
            TaskIndexDto.SUGGESTED_START, TaskIndexDto.DUE_DATE, TaskIndexDto.ASSIGNEE_USER,
            TaskIndexDto.ASSIGNEE_REPLY, TaskIndexDto.CREATOR_USER, TaskIndexDto.CREATOR_COMMENT,
            TaskIndexDto.TASK_STATUS);

    ((Column<TaskIndexDto, Date>) getColumn(TaskIndexDto.DUE_DATE))
            .setRenderer(new DateRenderer(DateHelper.getLocalDateTimeFormat()));
    ((Column<TaskIndexDto, Date>) getColumn(TaskIndexDto.SUGGESTED_START))
            .setRenderer(new DateRenderer(DateHelper.getLocalDateTimeFormat()));
    ((Column<TaskIndexDto, String>) getColumn(TaskIndexDto.CREATOR_COMMENT))
            .setRenderer(new ShortStringRenderer(50));

    Column<TaskIndexDto, ReferenceDto> contextColumn = (Column<TaskIndexDto, ReferenceDto>) getColumn(
            TaskIndexDto.CONTEXT_REFERENCE);
    contextColumn.setRenderer(new ReferenceDtoHtmlProvider(), new HtmlRenderer());
    contextColumn.setSortable(false);

    Column<TaskIndexDto, UserReferenceDto> assigneeUserColumn = (Column<TaskIndexDto, UserReferenceDto>) getColumn(
            TaskIndexDto.ASSIGNEE_USER);
    assigneeUserColumn.setRenderer(user -> {
        String html;
        if (user != null) {
            html = ControllerProvider.getTaskController().getUserCaptionWithPendingTaskCount(user);
        } else {
            html = "";
        }
        return html;
    }, new HtmlRenderer());

    Column<TaskIndexDto, TaskPriority> priorityColumn = (Column<TaskIndexDto, TaskPriority>) getColumn(
            TaskIndexDto.PRIORITY);
    priorityColumn.setStyleGenerator(item -> {
        if (item.getPriority() != null) {
            switch (item.getPriority()) {
            case HIGH:
                return CssStyles.GRID_CELL_PRIORITY_HIGH;
            case NORMAL:
                return CssStyles.GRID_CELL_PRIORITY_NORMAL;
            case LOW:
                return CssStyles.GRID_CELL_PRIORITY_LOW;
            default:
                throw new IndexOutOfBoundsException(item.getPriority().toString());
            }
        }
        return null;
    });

    Column<TaskIndexDto, Date> dueDateColumn = (Column<TaskIndexDto, Date>) getColumn(TaskIndexDto.DUE_DATE);
    dueDateColumn.setStyleGenerator(item -> {
        Date dueDate = item.getDueDate();
        if (dueDate != null && dueDate.before(new Date())) {
            return CssStyles.GRID_CELL_WARNING;
        }
        return null;
    });

    for (Column<?, ?> column : getColumns()) {
        column.setCaption(I18nProperties.getPrefixCaption(TaskIndexDto.I18N_PREFIX, column.getId().toString(),
                column.getCaption()));
    }

    addItemClickListener(this);
}

From source file:de.symeda.sormas.ui.visit.VisitGrid.java

License:Open Source License

@SuppressWarnings("unchecked")
public VisitGrid() {
    super(VisitIndexDto.class);
    setSizeFull();//www  .  j  a  v  a 2  s  .c o m

    if (UserProvider.getCurrent().hasUserRight(UserRight.PERFORM_BULK_OPERATIONS)) {
        setSelectionMode(SelectionMode.MULTI);
    } else {
        setSelectionMode(SelectionMode.NONE);
    }

    DataProvider<VisitIndexDto, VisitCriteria> dataProvider = DataProvider
            .fromFilteringCallbacks(query -> FacadeProvider.getVisitFacade()
                    .getIndexList(query.getFilter().orElse(null), query.getOffset(), query.getLimit(),
                            query.getSortOrders().stream()
                                    .map(sortOrder -> new SortProperty(sortOrder.getSorted(),
                                            sortOrder.getDirection() == SortDirection.ASCENDING))
                                    .collect(Collectors.toList()))
                    .stream(), query -> {
                        return (int) FacadeProvider.getVisitFacade().count(query.getFilter().orElse(null));
                    });
    setDataProvider(dataProvider);

    Column<VisitIndexDto, String> editColumn = addColumn(entry -> VaadinIcons.EDIT.getHtml(),
            new HtmlRenderer());
    editColumn.setId(EDIT_BTN_ID);
    editColumn.setWidth(20);

    setColumns(EDIT_BTN_ID, VisitIndexDto.VISIT_DATE_TIME, VisitIndexDto.VISIT_STATUS,
            VisitIndexDto.VISIT_REMARKS, VisitIndexDto.DISEASE, VisitIndexDto.SYMPTOMATIC,
            VisitIndexDto.TEMPERATURE);

    ((Column<VisitIndexDto, Date>) getColumn(VisitIndexDto.VISIT_DATE_TIME))
            .setRenderer(new DateRenderer(DateHelper.getLocalDateTimeFormat()));
    ((Column<VisitIndexDto, String>) getColumn(VisitIndexDto.SYMPTOMATIC)).setRenderer(new BooleanRenderer());

    for (Column<?, ?> column : getColumns()) {
        column.setCaption(I18nProperties.getPrefixCaption(VisitIndexDto.I18N_PREFIX, column.getId().toString(),
                column.getCaption()));
    }

    addItemClickListener(e -> {
        if (e.getColumn() != null
                && (EDIT_BTN_ID.equals(e.getColumn().getId()) || e.getMouseEventDetails().isDoubleClick())) {
            ControllerProvider.getVisitController().editVisit(e.getItem().getUuid(), getCriteria().getContact(),
                    r -> reload());
        }
    });
}

From source file:org.jpos.qi.minigl.AccountsView.java

License:Open Source License

public void formatEntriesGrid() {
    String pattern = getApp().getMessage("datetime");
    SimpleDateFormat dateFormat = new SimpleDateFormat(pattern);
    entryGrid.getColumn("account").setHidden(true);
    entryGrid.addColumn(glEntry -> glEntry.getTransaction().getTimestamp()).setId("timestamp")
            .setRenderer(new DateRenderer(dateFormat)).setCaption(getCaptionFromId("timestamp"))
            .setSortable(true).setHidable(false);
    entryGrid.addColumn(GLEntry::getBalance).setId("balance").setRenderer(createAmountRenderer())
            .setStyleGenerator(cellStyle -> "align-right").setCaption(getCaptionFromId("balance"))
            .setSortable(true).setHidable(false);
    entryGrid.sort("timestamp");
    entryGrid.setColumnOrder("timestamp", "detail", "tags", "layer", "debit", "credit", "balance");
    entryGrid.setHeightByRows(10);/* w ww  . j  av  a  2 s.  c  o m*/

    //HEADER
    entryGrid.getDefaultHeaderRow().getCell("balance").setStyleName("align-right");
    HeaderRow initialBalanceHeader = entryGrid.appendHeaderRow();
    HeaderCell label = initialBalanceHeader.join("timestamp", "detail", "tags", "layer", "credit", "debit");
    label.setText("Initial Balance");
    HeaderCell value = initialBalanceHeader.getCell("balance");
    value.setStyleName("amount-header");

    //FOOTER
    FooterRow footer = entryGrid.appendFooterRow();
    FooterCell totalCell = footer.join("timestamp", "detail", "tags", "layer");
    totalCell.setHtml("<strong>TOTAL</strong>");
    FooterCell debitTotal = footer.getCell("debit");
    debitTotal.setStyleName("align-right");
    FooterCell creditTotal = footer.getCell("credit");
    creditTotal.setStyleName("align-right");
    FooterCell balanceTotal = footer.getCell("balance");
    balanceTotal.setStyleName("align-right");
}

From source file:org.jpos.util.QIUtils.java

License:Open Source License

public static Renderer createTimestampRenderer() {
    DateFormat dateFormat = new SimpleDateFormat(QI.getQI().getMessage("timestampformat"));
    return new DateRenderer(dateFormat);
}

From source file:org.jumpmind.metl.ui.views.design.ManageProjectsPanel.java

License:Open Source License

public ManageProjectsPanel(ApplicationContext context, DesignNavigator projectNavigator) {
    this.setSizeFull();
    this.context = context;
    this.projectNavigator = projectNavigator;

    ButtonBar buttonBar = new ButtonBar();
    addComponent(buttonBar);/*from  ww  w .ja v a2  s.c om*/

    newProjectButton = buttonBar.addButton("New Project", Icons.PROJECT);
    newProjectButton.addClickListener(event -> newProject());

    editButton = buttonBar.addButton("Edit Project", FontAwesome.EDIT);
    editButton.addClickListener(event -> edit(projectGrid));

    removeButton = buttonBar.addButton("Remove Project", Icons.DELETE);
    removeButton.addClickListener(event -> removeProject());

    gridContainer = new BeanItemContainer<>(Project.class);
    projectGrid = new Grid();
    projectGrid.setSizeFull();
    projectGrid.setEditorEnabled(true);
    projectGrid.setSelectionMode(SelectionMode.MULTI);

    projectGrid.addColumn("name", String.class).setHeaderCaption("Name").setExpandRatio(2);
    projectGrid.addColumn("description", String.class).setHeaderCaption("Description").setExpandRatio(1);
    projectGrid.addColumn("createTime", Date.class).setHeaderCaption("Create Time").setWidth(185)
            .setMaximumWidth(200).setRenderer(new DateRenderer(UiConstants.DATETIME_FORMAT)).setEditable(false);

    projectGrid.setContainerDataSource(gridContainer);
    projectGrid.setEditorFieldFactory(new FieldFactory());
    projectGrid.addSortListener(event -> {
        lastSortOrder = event.getSortOrder();
    });
    projectGrid.addSelectionListener(event -> setButtonsEnabled());
    projectGrid.addItemClickListener(new GridClickListener(projectGrid));
    projectGrid.addSelectionListener((event) -> {
        Set<Object> removed = event.getRemoved();
        for (Object remove : removed) {
            projectGrid.setDetailsVisible(remove, false);
        }
        Set<Object> selected = event.getSelected();
        for (Object select : selected) {
            projectGrid.setDetailsVisible(select, true);
        }

    });

    projectGrid.getEditorFieldGroup().addCommitHandler(new FieldGroup.CommitHandler() {

        private static final long serialVersionUID = 1L;

        @Override
        public void preCommit(CommitEvent commitEvent) throws CommitException {
        }

        @Override
        public void postCommit(CommitEvent commitEvent) throws CommitException {
            Project item = (Project) projectGrid.getEditedItemId();
            IConfigurationService configurationService = context.getConfigurationService();
            configurationService.save(item);
            projectGrid.markAsDirty();
        }
    });

    HeaderRow filteringHeader = projectGrid.appendHeaderRow();
    HeaderCell logTextFilterCell = filteringHeader.getCell("name");
    TextField filterField = new TextField();
    filterField.setInputPrompt("Filter");
    filterField.addStyleName(ValoTheme.TEXTFIELD_TINY);
    filterField.setWidth("100%");

    filterField.addTextChangeListener(change -> {
        gridContainer.removeContainerFilters("name");
        if (!change.getText().isEmpty()) {
            gridContainer.addContainerFilter(new SimpleStringFilter("name", change.getText(), true, false));
        }
    });
    logTextFilterCell.setComponent(filterField);

    projectGrid.setDetailsGenerator((rowReference) -> buildVersionGrid((Project) rowReference.getItemId()));

    addComponent(projectGrid);
    setExpandRatio(projectGrid, 1);

    setButtonsEnabled();

}