Example usage for org.apache.wicket.markup.html.link Link setOutputMarkupPlaceholderTag

List of usage examples for org.apache.wicket.markup.html.link Link setOutputMarkupPlaceholderTag

Introduction

In this page you can find the example usage for org.apache.wicket.markup.html.link Link setOutputMarkupPlaceholderTag.

Prototype

public final Component setOutputMarkupPlaceholderTag(final boolean outputTag) 

Source Link

Document

Render a placeholder tag when the component is not visible.

Usage

From source file:ro.fortsoft.wicket.pivot.web.PivotPanel.java

License:Apache License

@Override
protected void onInitialize() {
    super.onInitialize();

    // create a pivot model
    pivotModel = createPivotModel(getModelObject());

    // create pivot field action factory
    pivotFieldActionsFactory = createPivotFieldActionsFactory();

    pivotModel.calculate();/* w ww .  j av a2s  . c om*/

    areasContainer = new WebMarkupContainer("areas");
    areasContainer.setOutputMarkupId(true);
    add(areasContainer);

    RepeatingView areaRepeater = new RepeatingView("area");
    areasContainer.add(areaRepeater);
    List<PivotField.Area> areas = PivotField.Area.getValues();
    for (PivotField.Area area : areas) {
        areaRepeater.add(new PivotAreaPanel(areaRepeater.newChildId(), area));
    }

    pivotTable = createPivotTabel("pivotTable", pivotModel);
    add(pivotTable);

    modal = new ModalWindow("modal");
    modal.setAutoSize(true);
    add(modal);

    AjaxLink<Void> configStoreButton = new AjaxLink<Void>("configStoreButton") {
        private static final long serialVersionUID = 1L;

        @Override
        public void onClick(AjaxRequestTarget target) {
            modal.setTitle("Configuration");
            modal.setContent(
                    new PivotConfigStoragePanel(ModalWindow.CONTENT_ID, pivotModel, pivotConfigStorage));
            modal.setAutoSize(true);
            modal.show(target);
            modal.setWindowClosedCallback(new WindowClosedCallback() {
                private static final long serialVersionUID = 1L;

                @Override
                public void onClose(AjaxRequestTarget target) {
                    target.add(PivotPanel.this);
                    if (pivotModel.isAutoCalculate())
                        compute(target);
                    computeLink.setVisible(!pivotModel.isAutoCalculate());
                }
            });
        }

        @Override
        public boolean isVisible() {
            return super.isVisible() && pivotConfigStorage != null;
        }
    };
    add(configStoreButton);

    AjaxCheckBox showGrandTotalForColumnCheckBox = new AjaxCheckBox("showGrandTotalForColumn",
            new PropertyModel<Boolean>(this, "pivotModel.showGrandTotalForColumn")) {

        private static final long serialVersionUID = 1L;

        @Override
        protected void onUpdate(AjaxRequestTarget target) {
            if (pivotModel.isAutoCalculate()) {
                compute(target);
            }
        }

    };
    add(showGrandTotalForColumnCheckBox);

    AjaxCheckBox showGrandTotalForRowCheckBox = new AjaxCheckBox("showGrandTotalForRow",
            new PropertyModel<Boolean>(this, "pivotModel.showGrandTotalForRow")) {

        private static final long serialVersionUID = 1L;

        @Override
        protected void onUpdate(AjaxRequestTarget target) {
            if (pivotModel.isAutoCalculate()) {
                compute(target);
            }
        }

    };
    add(showGrandTotalForRowCheckBox);

    AjaxCheckBox autoCalculateCheckBox = new AjaxCheckBox("autoCalculate",
            new PropertyModel<Boolean>(this, "pivotModel.autoCalculate")) {

        private static final long serialVersionUID = 1L;

        @Override
        protected void onUpdate(AjaxRequestTarget target) {
            computeLink.setVisible(!pivotModel.isAutoCalculate());
            target.add(computeLink);

            if (pivotModel.isAutoCalculate() && !pivotTable.isVisible()) {
                compute(target);
            }
        }

    };
    add(autoCalculateCheckBox);

    computeLink = new IndicatingAjaxLink<Void>("compute") {

        private static final long serialVersionUID = 1L;

        @Override
        public void onClick(AjaxRequestTarget target) {
            compute(target);
        }

        /*
         * @Override public boolean isEnabled() { return verify(); }
         */

    };
    computeLink.setOutputMarkupPlaceholderTag(true);
    computeLink.add(AttributeModifier.append("class", new ButtonCssClassModel()));
    computeLink.setVisible(!pivotModel.isAutoCalculate());
    add(computeLink);

    downloadContainer = new WebMarkupContainer("downloadContainer");
    downloadContainer.setOutputMarkupPlaceholderTag(true);
    downloadContainer.setVisible(pivotTable.isVisible() && (pivotExporters.length > 0));
    add(downloadContainer);

    RepeatingView downloadExports = new RepeatingView("downloadExport");
    downloadContainer.add(downloadExports);
    for (final PivotExporter exporter : pivotExporters) {
        Link<Void> downloadLink = new Link<Void>(downloadExports.newChildId()) {
            private static final long serialVersionUID = 1L;

            @Override
            public void onClick() {
                pivotModel.calculate();
                ByteArrayOutputStream out = new ByteArrayOutputStream();
                try {
                    exporter.exportPivot(getPivotModel(), out);
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
                ResourceRequestHandler downloadHandler = new ResourceRequestHandler(
                        new ByteArrayResource(exporter.getFormatMimetype(), out.toByteArray(),
                                pivotExportFilename + "." + exporter.getFilenameExtension()),
                        null);
                RequestCycle.get().scheduleRequestHandlerAfterCurrent(downloadHandler);
            }
        };
        downloadExports.add(downloadLink);
        IModel<String> resourceModel = new StringResourceModel("downloadAs", downloadLink,
                Model.of(exporter.getFormatName()));
        downloadLink.add(new Label("label", resourceModel));
        downloadLink.setOutputMarkupPlaceholderTag(true);
        downloadLink.add(AttributeModifier.append("class", new ButtonCssClassModel()));
    }

    add(new PivotResourcesBehavior());
    if (pivotModel.isAutoCalculate()) {
        compute(null);
    }

    setOutputMarkupId(true);
}