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

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

Introduction

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

Prototype

public StringBufferResourceStream(final String contentType) 

Source Link

Document

Constructor.

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//from w  w  w . j  ava 2 s  . c  o  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:wicket.contrib.tinymce.settings.JazzySpellChecker.java

License:Apache License

/**
 * Construct spell checker resource.//from   w ww . j  av  a  2s  .  c  o m
 */
public JazzySpellChecker() {
    // todo load dict file from jazzy.jar archive.
    InputStream inputStream = getClass().getClassLoader().getResourceAsStream(dictFile);
    InputStreamReader reader = new InputStreamReader(inputStream);
    try {
        dict = new SpellDictionaryHashMap(reader);
    } catch (IOException e) {
        throw new RuntimeException(e);
    } finally {
        try {
            reader.close();
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
    resourceStream = new StringBufferResourceStream(contentType);
}