Example usage for org.apache.wicket.util.resource StringBufferResourceStream append

List of usage examples for org.apache.wicket.util.resource StringBufferResourceStream append

Introduction

In this page you can find the example usage for org.apache.wicket.util.resource StringBufferResourceStream append.

Prototype

public StringBufferResourceStream append(final CharSequence s) 

Source Link

Document

Adds to this string buffer resource

Usage

From source file:ca.travelagency.salesreports.SalesSummaryPanel.java

License:Apache License

public SalesSummaryPanel(String id, SalesSearch salesSearch) {
    super(id, new CompoundPropertyModel<InvoiceSales>(InvoiceSalesModel.make(salesSearch)));

    ListView<MonthlyDistribution> listView = new ListView<MonthlyDistribution>(
            InvoiceSales.Properties.monthlyDistribution.name()) {
        private static final long serialVersionUID = 1L;

        @Override/* w w  w.  j  ava 2  s.co m*/
        protected ListItem<MonthlyDistribution> newItem(int index, IModel<MonthlyDistribution> itemModel) {
            return new OddEvenListItem<MonthlyDistribution>(index, itemModel);
        }

        @Override
        protected void populateItem(final ListItem<MonthlyDistribution> item) {
            item.setModel(new CompoundPropertyModel<MonthlyDistribution>(item.getModelObject()));

            item.add(new Label(MonthlyDistribution.Properties.dateAsString.name()));

            Link<Void> link = new Link<Void>(LINK_TO_INVOICES) {
                private static final long serialVersionUID = 1L;

                @Override
                public void onClick() {
                    getAuthenticatedSession().clearInvoiceFilter();
                    InvoiceFilter invoiceFilter = getAuthenticatedSession().getInvoiceFilter();
                    invoiceFilter.setSystemUser(getSystemUser());
                    Date date = item.getModelObject().getDate();
                    invoiceFilter.setInvoiceDateFrom(date);
                    invoiceFilter.setInvoiceDateTo(DateUtils.addDays(DateUtils.addMonths(date, 1), -1));
                    setResponsePage(new InvoicesPage());
                }
            };
            link.add(new Label(MonthlyDistribution.Properties.count.name()));
            item.add(link);

            item.add(new Label(MonthlyDistribution.Properties.salesAmounts.name() + Condition.SEPARATOR
                    + SalesAmounts.Properties.saleAsString.name()));
            item.add(new Label(MonthlyDistribution.Properties.salesAmounts.name() + Condition.SEPARATOR
                    + SalesAmounts.Properties.costAsString.name()));
            item.add(new Label(MonthlyDistribution.Properties.salesAmounts.name() + Condition.SEPARATOR
                    + SalesAmounts.Properties.commissionAsString.name()));
            item.add(new Label(MonthlyDistribution.Properties.salesAmounts.name() + Condition.SEPARATOR
                    + SalesAmounts.Properties.commissionReceivedAsString.name()));
            item.add(new Label(MonthlyDistribution.Properties.salesAmounts.name() + Condition.SEPARATOR
                    + SalesAmounts.Properties.commissionVerifiedAsString.name()));
            item.add(new Label(MonthlyDistribution.Properties.salesAmounts.name() + Condition.SEPARATOR
                    + SalesAmounts.Properties.taxOnCommissionAsString.name()));
            item.add(new Label(MonthlyDistribution.Properties.salesAmounts.name() + Condition.SEPARATOR
                    + SalesAmounts.Properties.paidAsString.name()));
        }
    };
    add(listView);

    Link<String> downloadLink = new Link<String>(EXPORT_TO_CSV, Model.of(makeCsvOutput())) {
        private static final long serialVersionUID = 1L;

        @Override
        public void onClick() {
            StringBufferResourceStream resourceStream = new StringBufferResourceStream("text/csv");
            resourceStream.append((CharSequence) getDefaultModelObject());

            ResourceStreamRequestHandler handler = new ResourceStreamRequestHandler(resourceStream)
                    .setFileName("export.csv").setContentDisposition(ContentDisposition.ATTACHMENT);

            getRequestCycle().scheduleRequestHandlerAfterCurrent(handler);
        }
    };
    downloadLink.setVisible(!getSales().getMonthlyDistribution().isEmpty());
    add(downloadLink);
}

From source file:org.wicketstuff.minis.apanel.APanel.java

License:Apache License

/**
 * {@inheritDoc}//  w  ww  .  jav  a2 s.com
 */
public IResourceStream getMarkupResourceStream(final MarkupContainer container, final Class<?> containerClass) {
    if (container != this)
        throw new IllegalArgumentException("Container " + container + " must be instance " + this);

    final StringBufferResourceStream resourceStream = new StringBufferResourceStream();
    resourceStream.append(thisPanelRenderer.getMarkup((APanel) container));
    return resourceStream;
}