List of usage examples for org.apache.wicket.request.resource ByteArrayResource ByteArrayResource
public ByteArrayResource(final String contentType, final byte[] array, final String filename)
From source file:cz.zcu.kiv.eegdatabase.wui.ui.licenses.components.DownloadRequestAttachmentPanel.java
License:Apache License
public DownloadRequestAttachmentPanel(String id, IModel<PersonalLicense> model) { super(id);/*from w w w. j ava2 s.c o m*/ boolean isContent = model.getObject() != null && model.getObject().getAttachmentContent() != null; ByteArrayResource res; if (isContent) { byte[] attachmentContent = facade .getPersonalLicenseAttachmentContent(model.getObject().getPersonalLicenseId()); res = new ByteArrayResource("", attachmentContent, model.getObject().getAttachmentFileName()); } else { res = new ByteArrayResource(""); } add(new ResourceLink<Void>("link", res).setVisibilityAllowed(isContent)); }
From source file:cz.zcu.kiv.eegdatabase.wui.ui.licenses.components.LicenseDownloadLinkPanel.java
License:Open Source License
public LicenseDownloadLinkPanel(String id, IModel<License> model) { super(id);/* w w w .j a v a 2 s . co m*/ final License license = model.getObject(); boolean isContent = license != null && license.getAttachmentFileName() != null; ByteArrayResource res; if (isContent) { res = new ByteArrayResource("", licenseFacade.getLicenseAttachmentContent(license.getLicenseId()), license.getAttachmentFileName()); } else { res = new ByteArrayResource(""); } ResourceLink<Void> downloadLink = new ResourceLink<Void>("download", res); downloadLink.setVisibilityAllowed(isContent); downloadLink.add(new Label("fileName", new Model<String>(license.getAttachmentFileName())) .setVisibilityAllowed(isContent)); add(downloadLink); //add(new Label("noFile", new Model<String>("")).setVisibilityAllowed(!isContent)); }
From source file:cz.zcu.kiv.eegdatabase.wui.ui.licenses.components.LicenseEditForm.java
License:Apache License
@SuppressWarnings("serial") private void addBlueprintSelect() { IModel<License> selectedBlueprintModel = new Model<License>(); licenseChoice = new AjaxDropDownChoice<License>("blueprintSelect", selectedBlueprintModel, blueprintsModel, new ChoiceRenderer<License>("title")) { @Override/*from w w w . ja v a 2 s . com*/ protected void onSelectionChangeAjaxified(AjaxRequestTarget target, final License option) { if (option == null || option.getLicenseId() == 0) { form.getModelObject().setLicense(null); form.getModelObject().setPrice(BigDecimal.ZERO); saveButton.setVisibilityAllowed(false); priceInput.setEnabled(false); licenseDetails.setVisible(false); } else { priceInput.setEnabled(option.getLicenseType() == LicenseType.COMMERCIAL); licenseDetails.setVisible(true); licenseLink.setVisible(option.getLink() != null); if (option.getAttachmentFileName() != null) { ByteArrayResource res; res = new ByteArrayResource("", licenseFacade.getLicenseAttachmentContent(option.getLicenseId()), option.getAttachmentFileName()) { @Override public void configureResponse(final AbstractResource.ResourceResponse response, final IResource.Attributes attributes) { response.setCacheDuration(Duration.NONE); response.setFileName(option.getAttachmentFileName()); } }; ResourceLink<Void> newLink = new ResourceLink<Void>("fileDownload", res); newLink.add(new Label("fileName", option.getAttachmentFileName())); downloadLink.replaceWith(newLink); downloadLink = newLink; downloadLink.setVisible(true); } else { downloadLink.setVisible(false); } form.getModelObject().setLicense(option); saveButton.setVisibilityAllowed(true); } target.add(form); } }; licenseChoice.setNullValid(true); form.add(licenseChoice); }
From source file:cz.zcu.kiv.eegdatabase.wui.ui.licenses.components.LicensePriceForm.java
License:Apache License
@SuppressWarnings("serial") private void addDropDownChoice(final IModel<List<License>> licenseChoices) { dropDownChoice = new AjaxDropDownChoice<License>("licenseSelect", new Model<License>(), licenseChoices, new ChoiceRenderer<License>("title")) { @Override/*from ww w . ja v a 2 s .co m*/ protected void onSelectionChangeAjaxified(AjaxRequestTarget target, final License option) { if (option == null || option.getLicenseId() == 0) { //LicensePriceForm.this.form.setModelObject(null); //LicensePriceForm.this.form.clearInput(); clearForm(); } else { priceInput.setEnabled(option.getLicenseType() == LicenseType.COMMERCIAL); licenseDetails.setVisible(true); licenseLink.setVisible(option.getLink() != null); if (option.getAttachmentFileName() != null) { ByteArrayResource res; res = new ByteArrayResource("", licenseFacade.getLicenseAttachmentContent(option.getLicenseId()), option.getAttachmentFileName()) { @Override public void configureResponse(final AbstractResource.ResourceResponse response, final IResource.Attributes attributes) { response.setCacheDuration(Duration.NONE); response.setFileName(option.getAttachmentFileName()); } }; ResourceLink<Void> newLink = new ResourceLink<Void>("fileDownload", res); newLink.add(new Label("fileName", option.getAttachmentFileName())); downloadLink.replaceWith(newLink); downloadLink = newLink; downloadLink.setVisible(true); } else { downloadLink.setVisible(false); } LicensePriceForm.this.form.setModelObject(option); saveButton.setVisibilityAllowed(true); } target.add(LicensePriceForm.this); } }; dropDownChoice.setNullValid(true); form.add(dropDownChoice); }
From source file:cz.zcu.kiv.eegdatabase.wui.ui.licenses.components.ViewLicensePanel.java
public ViewLicensePanel(String id, final IModel<License> model, boolean showRemoveButton) { super(id, new CompoundPropertyModel<License>(model)); this.model = model; add(new Label("title")); add(new Label("licenseType")); add(new MultiLineLabel("description")); IModel<String> link = new PropertyModel<String>(model, "link"); licenseLink = new ExternalLink("link", link, link); add(licenseLink);//from w w w . j av a 2 s . c o m add(new Label("attachmentFileName")); boolean isContent = model.getObject() != null && model.getObject().getAttachmentFileName() != null; ByteArrayResource res; if (isContent) { res = new ByteArrayResource("", facade.getLicenseAttachmentContent(model.getObject().getLicenseId()), model.getObject().getAttachmentFileName()); } else { res = new ByteArrayResource(""); } downloadLink = new ResourceLink<Void>("download", res); downloadLink.setVisible(isContent); add(downloadLink); this.form = new Form<Void>("form"); add(form); button = new AjaxButton("removeButton", ResourceUtils.getModel("button.remove")) { @Override protected void onSubmit(AjaxRequestTarget target, Form<?> form) { onRemoveAction(model, target, form); } @Override protected void onConfigure() { super.onConfigure(); this.setVisible(true); } }; button.setVisibilityAllowed(showRemoveButton); form.add(button); }
From source file:cz.zcu.kiv.eegdatabase.wui.ui.licenses.components.ViewLicensePanel.java
@SuppressWarnings("unchecked") @Override//from ww w . j av a2 s. c o m protected void onConfigure() { super.onConfigure(); licenseLink.setVisible(model.getObject() != null && model.getObject().getLink() != null); boolean isContent = model.getObject() != null && model.getObject().getAttachmentFileName() != null; ByteArrayResource res; if (isContent) { res = new ByteArrayResource("", facade.getLicenseAttachmentContent(model.getObject().getLicenseId()), model.getObject().getAttachmentFileName()); } else { res = new ByteArrayResource(""); } ResourceLink<Void> newLink = new ResourceLink<Void>("download", res); downloadLink = (ResourceLink<Void>) downloadLink.replaceWith(newLink); downloadLink.setVisible(isContent); }
From source file:cz.zcu.kiv.eegdatabase.wui.ui.licenses.LicenseDetailPage.java
License:Open Source License
private void setupPageComponents(Integer licenseId) { Person user = EEGDataBaseSession.get().getLoggedUser(); add(new ButtonPageMenu("leftMenu", AdministrationPageLeftMenu.values()) .setVisibilityAllowed(user.getAuthority().equals(UserRole.ROLE_ADMIN.toString()))); final License license = licenseFacade.read(licenseId); add(new Label("title", license.getTitle())); add(new Label("description", license.getDescription())); add(new Label("type", license.getLicenseType().toString())); ExternalLink link = new ExternalLink("link", license.getLink(), license.getLink()); link.setVisible(license.getLink() != null); add(link);// w w w . j a va2s.co m add(new Label("attachmentFileName", license.getAttachmentFileName())); boolean isContent = license != null && license.getAttachmentFileName() != null; ByteArrayResource res; if (isContent) { res = new ByteArrayResource("", licenseFacade.getLicenseAttachmentContent(license.getLicenseId()), license.getAttachmentFileName()); } else { res = new ByteArrayResource(""); } ResourceLink<Void> downloadLink = new ResourceLink<Void>("download", res); downloadLink.setVisible(isContent); add(downloadLink); }
From source file:gr.abiss.calipso.wicket.components.ByteDataRequestTarget.java
License:Open Source License
public void respond(IRequestCycle requestCycle) { ResourceRequestHandler handler = new ResourceRequestHandler( new ByteArrayResource(this.mime, this.getData(null), fileName), null); requestCycle.scheduleRequestHandlerAfterCurrent(handler); }
From source file:org.apache.isis.viewer.wicket.ui.components.scalars.isisapplib.IsisBlobPanel.java
License:Apache License
protected IResource newResource(final Blob blob) { return new ByteArrayResource(blob.getMimeType().getBaseType(), blob.getBytes(), blob.getName()); }
From source file:org.isisaddons.wicket.pdfjs.cpt.ui.PdfJsViewerPanel.java
License:Apache License
@Override protected MarkupContainer addComponentForRegular() { MarkupContainer containerIfRegular = new WebMarkupContainer("scalarIfRegular"); addOrReplace(containerIfRegular);/* ww w . j a va2s. c o m*/ final ObjectAdapter adapter = scalarModel.getObject(); if (adapter != null) { final PdfJsViewerFacet pdfJsViewerFacet = scalarModel.getFacet(PdfJsViewerFacet.class); final PdfJsViewerAdvisor.InstanceKey instanceKey = buildKey(); final PdfJsConfig config = pdfJsViewerFacet != null ? pdfJsViewerFacet.configFor(instanceKey) : new PdfJsConfig(); config.withDocumentUrl(urlFor(IResourceListener.INTERFACE, null)); PdfJsPanel pdfJsPanel = new PdfJsPanel(ID_SCALAR_VALUE, config); MarkupContainer prevPageButton = createComponent("prevPage", config); MarkupContainer nextPageButton = createComponent("nextPage", config); MarkupContainer currentZoomSelect = createComponent("currentZoom", config); MarkupContainer currentPageLabel = createComponent("currentPage", config); MarkupContainer totalPagesLabel = createComponent("totalPages", config); MarkupContainer currentHeightSelect = createComponent("currentHeight", config); MarkupContainer printButton = createComponent("print", config); //MarkupContainer downloadButton = createComponent("download", config); final Blob blob = getBlob(); final IResource bar = new ByteArrayResource(blob.getMimeType().getBaseType(), blob.getBytes(), blob.getName()); final ResourceLink<Void> downloadLink = new ResourceLink<>("download", bar); containerIfRegular.addOrReplace(pdfJsPanel, prevPageButton, nextPageButton, currentPageLabel, totalPagesLabel, currentZoomSelect, currentHeightSelect, printButton, downloadLink); // Label fileNameIfCompact = new Label("fileNameIfCompact", blob.getName()); // downloadLink.add(fileNameIfCompact); containerIfRegular.addOrReplace( new NotificationPanel(ID_FEEDBACK, pdfJsPanel, new ComponentFeedbackMessageFilter(pdfJsPanel))); } else { permanentlyHide(ID_SCALAR_VALUE, ID_FEEDBACK); } return containerIfRegular; }