List of usage examples for org.apache.wicket.util.string Strings toMultilineMarkup
public static CharSequence toMultilineMarkup(final CharSequence s)
From source file:com.gitblit.wicket.freemarker.FreemarkerPanel.java
License:Apache License
/** * @see org.apache.wicket.markup.html.panel.Panel#onComponentTagBody(org.apache.wicket.markup. * MarkupStream, org.apache.wicket.markup.ComponentTag) *///from w ww .j av a 2 s . com @Override public void onComponentTagBody(MarkupStream markupStream, ComponentTag openTag) { if (!Strings.isEmpty(stackTraceAsString)) { // TODO: only display the Freemarker error/stacktrace in development // mode? replaceComponentTagBody(markupStream, openTag, Strings.toMultilineMarkup(stackTraceAsString)); } else if (!parseGeneratedMarkup) { // check that no components have been added in case the generated // markup should not be // parsed if (size() > 0) { throw new WicketRuntimeException( "Components cannot be added if the generated markup should not be parsed."); } if (evaluatedTemplate == null) { // initialize evaluatedTemplate getMarkupResourceStream(null, null); } replaceComponentTagBody(markupStream, openTag, evaluatedTemplate); } else { super.onComponentTagBody(markupStream, openTag); } }
From source file:org.dcm4chee.web.war.tc.TCDocumentsView.java
License:LGPL
public TCDocumentsView(final String id, IModel<? extends TCObject> model, final boolean editing) { super(id, model); this.editing = editing; final TCModalDialog removeDocDlg = TCModalDialog.getOkCancel("remove-doc-dialog", TCUtilities.getLocalizedString("tc.documents.removedialog.msg"), null); removeDocDlg.setInitialHeight(100);/*w ww .j a v a2s .co m*/ removeDocDlg.setInitialWidth(420); removeDocDlg.setUseInitialHeight(true); final WebMarkupContainer items = new WebMarkupContainer("document-items"); items.setOutputMarkupId(true); items.add(new ListView<TCDocumentObject>("document-item", new ListModel<TCDocumentObject>() { @Override public List<TCDocumentObject> getObject() { return getTC().getReferencedDocumentObjects(); } }) { @Override protected void populateItem(final ListItem<TCDocumentObject> item) { final TCDocumentObject doc = item.getModelObject(); // compile text MimeType mimeType = doc.getMimeType(); Date addedDate = doc.getDocumentAddedDate(); String docDescription = doc.getDocumentDescription(); if (docDescription == null) { docDescription = doc.getDocumentName(); } StringBuilder sbuilder = new StringBuilder(); if (docDescription != null) { sbuilder.append(docDescription).append("\n"); } sbuilder.append("<i>"); sbuilder.append(mimeType.getDocumentType().getHumanReadableName()); sbuilder.append("; "); sbuilder.append(TCUtilities.getLocalizedString("tc.documents.addedon.text")).append(" "); sbuilder.append(DateFormat.getDateInstance(DateFormat.MEDIUM).format(addedDate)); sbuilder.append("</i>"); // add components final WebMarkupContainer actions = new WebMarkupContainer("document-item-actions"); actions.setOutputMarkupId(true); actions.setOutputMarkupPlaceholderTag(true); actions.add(new ResourceLink<Void>("document-item-download-btn", doc.getDocumentContent(true)) .add(new TCHoverImage("document-item-download-image", ImageManager.IMAGE_TC_DISK_MONO, ImageManager.IMAGE_TC_DISK) .add(new ImageSizeBehaviour(20, 20, "vertical-align: middle;")) .add(new TooltipBehaviour("tc.documents.", "download")))); actions.add(new AjaxLink<Void>("document-item-remove-btn") { @Override public void onClick(AjaxRequestTarget target) { try { if (editing) { removeDocDlg.setCallback(new ModalDialogCallbackAdapter() { @Override public void dialogAcknowledged(AjaxRequestTarget target) { getEditableTC().removeReferencedDocument(doc); target.addComponent(items); } }); removeDocDlg.show(target); } } catch (Exception e) { log.error("Removing referenced document from teaching-file failed!", e); } } @Override public boolean isVisible() { return editing; } }.add(new TCHoverImage("document-item-remove-image", ImageManager.IMAGE_TC_CANCEL_MONO, ImageManager.IMAGE_TC_CANCEL).add(new ImageSizeBehaviour(20, 20, "vertical-align: middle;")) .add(new TooltipBehaviour("tc.documents.", "remove")))); item.add(new AttributeModifier("onmouseover", true, new Model<String>("$('#" + actions.getMarkupId(true) + "').show();"))); item.add(new AttributeModifier("onmouseout", true, new Model<String>("$('#" + actions.getMarkupId(true) + "').hide();"))); item.add(new ResourceLink<Void>("document-item-view-link", doc.getDocumentContent(false)) .add(new NonCachingImage("document-item-image", doc.getDocumentThumbnail()) .add(new TCMaxImageSizeBehavior(32, 32).setAdditionalCSS("vertical-align:middle"))) .add(new TooltipBehaviour("tc.documents.", "view")) .add(new AttributeAppender("target", true, new Model<String>("_blank"), " "))); item.add(new MultiLineLabel("document-item-text", sbuilder.toString()) { @Override protected void onComponentTagBody(final MarkupStream markupStream, final ComponentTag openTag) { final CharSequence body = Strings.toMultilineMarkup(getDefaultModelObjectAsString()); replaceComponentTagBody(markupStream, openTag, body.toString().replaceFirst("<p>", "<p style=\"margin:0px\">")); } }.setEscapeModelStrings(false)); item.add(actions); } }); final FileUploadField uploadField = new FileUploadField("file-upload-field") { @Override protected void onComponentTag(ComponentTag tag) { super.onComponentTag(tag); MimeType[] types = MimeType.values(); if (types != null && types.length > 0) { StringBuilder accept = new StringBuilder(); accept.append(types[0].getMimeTypeString()); for (int i = 1; i < types.length; i++) { accept.append(",").append(types[i].getMimeTypeString()); } tag.put("accept", accept.toString()); } } }; final long maxUploadSize = Bytes.megabytes(25).bytes(); final TextArea<String> uploadDescription = new TextArea<String>("file-upload-description-text", new Model<String>()); final Form<Void> uploadForm = new Form<Void>("file-upload-form"); uploadForm.setMultiPart(true); uploadForm.setMaxSize(Bytes.megabytes(25)); // seems that this doesn't work because of a bug in WICKET 1.4 uploadForm.add(new Label("file-upload-label", TCUtilities.getLocalizedString("tc.documents.upload.text"))); uploadForm.add(new Label("file-upload-description-label", TCUtilities.getLocalizedString("tc.documents.upload.description.text"))); uploadForm.add(uploadField); uploadForm.add(uploadDescription); uploadForm.add(new AjaxButton("file-upload-btn") { @Override public void onSubmit(AjaxRequestTarget target, Form<?> form) { final FileUpload upload = uploadField.getFileUpload(); if (upload != null) { String contentType = null, fileName = null; final long totalBytes = upload.getSize(); try { if (totalBytes > 0) { if (totalBytes <= maxUploadSize) { getEditableTC().addReferencedDocument( MimeType.get(contentType = upload.getContentType()), fileName = upload.getClientFileName(), upload.getInputStream(), uploadDescription.getModelObject()); } else { log.warn("File upload denied: Max upload size is " + maxUploadSize + " bytes!"); } } target.addComponent(items); } catch (Exception e) { log.error("Unable to upload teaching-file referenced document (content-type='" + contentType + "', file-name='" + fileName + "')!", e); } finally { upload.closeStreams(); uploadField.clearInput(); uploadDescription.clearInput(); uploadDescription.setModelObject(null); target.addComponent(uploadForm); } } } @Override public void onError(AjaxRequestTarget target, Form<?> form) { } @Override protected IAjaxCallDecorator getAjaxCallDecorator() { return new TCMaskingAjaxDecorator(true, true); } }.add(new Label("file-upload-btn-text", TCUtilities.getLocalizedString("tc.documents.upload.start.text")))); add(items); add(removeDocDlg); add(new WebMarkupContainer("file-upload") { @Override public boolean isVisible() { return editing; } }.add(new Image("file-upload-info-img", ImageManager.IMAGE_TC_INFO) { @Override protected void onComponentTag(ComponentTag tag) { super.onComponentTag(tag); StringBuilder sbuilder = new StringBuilder(); sbuilder.append( MessageFormat.format(TCUtilities.getLocalizedString("tc.documents.upload.maxsize.text"), Bytes.bytes(maxUploadSize).megabytes())); sbuilder.append("\n"); MimeType[] mimeTypes = MimeType.values(); if (mimeTypes != null) { boolean firstExt = true; int nExtPerLine = 8; int nExtInLine = 0; for (MimeType type : mimeTypes) { String[] exts = type.getSupportedFileExtensions(); if (exts != null) { for (String ext : exts) { String s = "*." + ext; if (firstExt) { sbuilder.append( TCUtilities.getLocalizedString("tc.documents.upload.files.text")); sbuilder.append("\n"); sbuilder.append(s); firstExt = false; nExtInLine++; } else { if (!sbuilder.toString().contains(s)) { if (nExtInLine == nExtPerLine) { sbuilder.append("\n"); nExtInLine = 0; } else { sbuilder.append(", "); } sbuilder.append(s); nExtInLine++; } } } } } } tag.put("title", sbuilder.toString()); } }.add(new ImageSizeBehaviour(16, 16, "vertical-align:middle;margin:5px;"))).add(uploadForm) .setMarkupId("documents-file-upload")); }
From source file:org.dcm4chee.web.war.tc.widgets.TCMultiLineLabel.java
License:LGPL
@Override protected void onComponentTagBody(final MarkupStream markupStream, final ComponentTag openTag) { final CharSequence body = Strings.toMultilineMarkup(getDefaultModelObjectAsString()); replaceComponentTagBody(markupStream, openTag, body.toString().replaceFirst("<p>", "<p style=\"margin:0px\">")); }
From source file:org.efaps.ui.wicket.components.values.LabelField.java
License:Apache License
@Override public void onComponentTagBody(final MarkupStream _markupStream, final ComponentTag _openTag) { final String content = getDefaultModelObjectAsString(); if (content.contains("\n")) { final CharSequence body = Strings.toMultilineMarkup(content); replaceComponentTagBody(_markupStream, _openTag, body); } else {// w ww .jav a2 s . c om replaceComponentTagBody(_markupStream, _openTag, content); } }
From source file:ro.fortsoft.wicket.jade.JadePanel.java
License:Apache License
@Override public void onComponentTagBody(MarkupStream markupStream, ComponentTag openTag) { if (!Strings.isEmpty(stackTraceAsString)) { // TODO: only display the Jade error/stacktrace in development mode? replaceComponentTagBody(markupStream, openTag, Strings.toMultilineMarkup(stackTraceAsString)); } else {// ww w .j a v a 2 s. com if (htmlMarkup == null) { // initialize htmlMarkup getMarkupResourceStream(null, null); } replaceComponentTagBody(markupStream, openTag, htmlMarkup); } }