List of usage examples for org.apache.wicket.markup.html.link DownloadLink DownloadLink
public DownloadLink(String id, IModel<File> model)
From source file:com.axway.ats.testexplorer.pages.testcase.statistics.CsvWriter.java
License:Apache License
public DownloadLink getDownloadChartDataLink() { final String fileName = "chartDataFile.csv"; downloadFile = new DownloadLink("download", new File(fileName)) { private static final long serialVersionUID = 1L; @Override/* w w w . j ava2s. c o m*/ public void onClick() { IResourceStream resourceStream = new FileResourceStream( new org.apache.wicket.util.file.File(generateFile(fileName))); getRequestCycle() .scheduleRequestHandlerAfterCurrent(new ResourceStreamRequestHandler(resourceStream) { }.setFileName(fileName).setContentDisposition(ContentDisposition.ATTACHMENT)); downloadFile.setDeleteAfterDownload(true); } }; return downloadFile; }
From source file:com.doculibre.constellio.wicket.components.holders.DownloadLinkHolder.java
License:Open Source License
public DownloadLinkHolder(String id, File file, String fileName) { super(id);//from w w w .ja v a 2 s.c o m DownloadLink downloadLink = new DownloadLink("downloadLink", file); add(downloadLink); downloadLink.add(new Label("fileName", fileName)); }
From source file:com.evolveum.midpoint.gui.api.component.result.OperationResultPanel.java
License:Apache License
private void initHeader(WebMarkupContainer box) { WebMarkupContainer iconType = new WebMarkupContainer(ID_ICON_TYPE); iconType.setOutputMarkupId(true);/*from w ww. j a va2s .co m*/ iconType.add(new AttributeAppender("class", new AbstractReadOnlyModel<String>() { private static final long serialVersionUID = 1L; @Override public String getObject() { StringBuilder sb = new StringBuilder(); OpResult message = getModelObject(); switch (message.getStatus()) { case IN_PROGRESS: case NOT_APPLICABLE: sb.append(" fa-info"); break; case SUCCESS: sb.append(" fa-check"); break; case FATAL_ERROR: sb.append(" fa-ban"); break; case PARTIAL_ERROR: case UNKNOWN: case WARNING: case HANDLED_ERROR: default: sb.append(" fa-warning"); } return sb.toString(); } })); box.add(iconType); Label message = createMessage(); AjaxLink<String> showMore = new AjaxLink<String>(ID_MESSAGE) { private static final long serialVersionUID = 1L; @Override public void onClick(AjaxRequestTarget target) { OpResult result = OperationResultPanel.this.getModelObject(); result.setShowMore(!result.isShowMore()); result.setAlreadyShown(false); // hack to be able to expand/collapse OpResult after rendered. target.add(OperationResultPanel.this); } }; showMore.add(message); box.add(showMore); AjaxLink<String> backgroundTask = new AjaxLink<String>(ID_BACKGROUND_TASK) { private static final long serialVersionUID = 1L; @Override public void onClick(AjaxRequestTarget target) { final OpResult opResult = OperationResultPanel.this.getModelObject(); String oid = opResult.getBackgroundTaskOid(); if (oid == null || !opResult.isBackgroundTaskVisible()) { return; // just for safety } ObjectReferenceType ref = ObjectTypeUtil.createObjectRef(oid, ObjectTypes.TASK); WebComponentUtil.dispatchToObjectDetailsPage(ref, getPageBase(), false); } }; backgroundTask.add(new VisibleEnableBehaviour() { private static final long serialVersionUID = 1L; @Override public boolean isVisible() { return getModelObject().getBackgroundTaskOid() != null && getModelObject().isBackgroundTaskVisible(); } }); box.add(backgroundTask); AjaxLink<String> showAll = new AjaxLink<String>(ID_SHOW_ALL) { private static final long serialVersionUID = 1L; @Override public void onClick(AjaxRequestTarget target) { showHideAll(true, OperationResultPanel.this.getModelObject(), target); } }; showAll.add(new VisibleEnableBehaviour() { private static final long serialVersionUID = 1L; @Override public boolean isVisible() { return !OperationResultPanel.this.getModelObject().isShowMore(); } }); box.add(showAll); AjaxLink<String> hideAll = new AjaxLink<String>(ID_HIDE_ALL) { private static final long serialVersionUID = 1L; @Override public void onClick(AjaxRequestTarget target) { showHideAll(false, OperationResultPanel.this.getModel().getObject(), target); } }; hideAll.add(new VisibleEnableBehaviour() { private static final long serialVersionUID = 1L; @Override public boolean isVisible() { return OperationResultPanel.this.getModelObject().isShowMore(); } }); box.add(hideAll); AjaxLink<String> close = new AjaxLink<String>("close") { private static final long serialVersionUID = 1L; @Override public void onClick(AjaxRequestTarget target) { close(target); } }; box.add(close); DownloadLink downloadXml = new DownloadLink("downloadXml", new AbstractReadOnlyModel<File>() { private static final long serialVersionUID = 1L; @Override public File getObject() { String home = getPageBase().getMidpointConfiguration().getMidpointHome(); File f = new File(home, "result"); DataOutputStream dos = null; try { dos = new DataOutputStream(new FileOutputStream(f)); dos.writeBytes(OperationResultPanel.this.getModel().getObject().getXml()); } catch (IOException e) { LOGGER.error("Could not download result: {}", e.getMessage(), e); } finally { IOUtils.closeQuietly(dos); } return f; } }); downloadXml.setDeleteAfterDownload(true); box.add(downloadXml); }
From source file:eu.uqasar.web.pages.qmodel.QModelImportPage.java
License:Apache License
public QModelImportPage(PageParameters parameters) { super(parameters); logger.info("QModelImportPage::QModelImportPage start"); final Form<?> form = new Form<Void>("form") { /**//from w w w .j a v a 2 s . c o m * */ private static final long serialVersionUID = 4949407424211758709L; @Override protected void onSubmit() { logger.info("QModelImportPage::onSubmit starts"); errorMessage = ""; try { FileUpload upload = file.getFileUpload(); if (upload == null) { errorMessage = "qmodel.empty.file.error"; logger.info("QModelImportPage::onSubmit no file uploaded"); } else { logger.info("QModelImportPage::onSubmit some file uploaded"); if (upload.getSize() > Bytes.kilobytes(MAX_SIZE).bytes()) { errorMessage = "qmodel.max.file.error"; logger.info("QModelImportPage::onSubmit MAX_SIZE size" + upload.getSize()); } else { logger.info("QModelImportPage::onSubmit file name " + upload.getClientFileName() + " File-Size: " + Bytes.bytes(upload.getSize()).toString() + "content-type " + upload.getContentType()); user = UQasar.getSession().getLoggedInUser(); if (user.getCompany() != null) { company = companyService.getById(user.getCompany().getId()); } if (upload.getContentType() != null && upload.getContentType().equals(XML_CONTENT)) { //parsing qm = parse(upload, true); } else if (upload.getContentType() != null && (upload.getContentType().equals(JSON_CONTENT) || upload.getContentType().equals(OCT_CONTENT))) { //json candidate qm = parse(upload, false); } else { //file not valid errorMessage = "qmodel.type.file.error"; } } } if (qm != null) { qm.setUpdateDate(DateTime.now().toDate()); if (qm.getCompanyId() != 0) { qm.setCompany(companyService.getById(qm.getCompanyId())); } else { if (company != null) { qm.setCompany(company); qm.setCompanyId(company.getId()); } } qm = (QModel) qmodelService.create(qm); } } catch (uQasarException ex) { if (ex.getMessage().contains("nodeKey")) { errorMessage = "qmodel.key.unique"; } } catch (JsonProcessingException ex) { logger.info("JsonProcessingException----------------------------------------"); if (ex.getMessage().contains("expecting comma to separate ARRAY entries")) { errorMessage = "qmodel.json.parse.error"; } else if (ex.getMessage().contains("Unexpected character")) { errorMessage = "qmodel.json.char.error"; } else if (ex.getMessage().contains("Can not construct instance")) { errorMessage = "qmodel.json.enum.error"; } else { logger.info("JsonProcessingException----------------------------"); errorMessage = "qmodel.xml.parse.error"; } } catch (JAXBException ex) { logger.info("JAXBException----------------------------"); errorMessage = "qmodel.xml.parse.error"; } catch (Exception ex) { logger.info("IOException----------------------------"); errorMessage = "qmodel.import.importError"; } finally { PageParameters parameters = new PageParameters(); if (null != errorMessage && !errorMessage.equals("")) { logger.info("Attaching error message"); parameters.add(QModelImportPage.LEVEL_PARAM, FeedbackMessage.ERROR); parameters.add(QModelImportPage.MESSAGE_PARAM, getLocalizer().getString(errorMessage, this)); setResponsePage(QModelImportPage.class, parameters); } else { logger.info("qmodel successfully created: redirection"); //qmodel successfully created: redirection parameters.add(BasePage.LEVEL_PARAM, FeedbackMessage.SUCCESS); parameters.add(BasePage.MESSAGE_PARAM, getLocalizer().getString("treenode.imported.message", this)); parameters.add("qmodel-key", qm.getNodeKey()); parameters.add("name", qm.getName()); setResponsePage(QModelViewPage.class, parameters); } } } }; // create the file upload field file = new FileUploadField("file"); form.addOrReplace(file); form.add(new Label("max", new AbstractReadOnlyModel<String>() { /** * */ private static final long serialVersionUID = 3532428309651830468L; @Override public String getObject() { return (Bytes.kilobytes(MAX_SIZE)).toString(); } })); // add progress bar form.add(new UploadProgressBar("progress", form, file)); ServletContext context = ((WebApplication) getApplication()).getServletContext(); // Download xml example File filexml = new File(context.getRealPath("/assets/files/qmodel.xml")); DownloadLink xmlLink = new DownloadLink("xmlLink", filexml); form.add(xmlLink); // Download json example File filejson = new File(context.getRealPath("/assets/files/qmodel.json")); DownloadLink jsonLink = new DownloadLink("jsonLink", filejson); form.add(jsonLink); add(form); logger.info("QModelImportPage::QModelImportPage ends"); }
From source file:org.artifactory.webapp.wicket.page.logs.SystemLogsViewPanel.java
License:Open Source License
/** * Add a link to enable the download of the system log file *///from w w w .j a va 2 s .c o m private void addSystemLogsLink() { // This is very ugly and should be removed when we upgrade wicket, see RTFACT-5470 for explanation downloadLink = new DownloadLink("systemLogsLink", systemLogFile) { @Override public void onClick() { final File file = getModelObject(); IResourceStream resourceStream = new FileResourceStream(new org.apache.wicket.util.file.File(file)); ResourceStreamRequestHandler handler = new ResourceStreamRequestHandler(resourceStream) { @Override public void respond(IRequestCycle requestCycle) { IResource.Attributes attributes = new IResource.Attributes(requestCycle.getRequest(), requestCycle.getResponse()); ResourceStreamResource resource = new ResourceStreamResource(this.getResourceStream()) { @Override protected void configureCache(ResourceResponse data, Attributes attributes) { Response response = attributes.getResponse(); ((WebResponse) response).disableCaching(); } }; resource.setFileName(file.getName()); resource.setContentDisposition(ContentDisposition.ATTACHMENT); resource.respond(attributes); } }; getRequestCycle().scheduleRequestHandlerAfterCurrent(handler); } }; add(downloadLink); downloadLink.add(linkLabel); downloadLink.setOutputMarkupId(true); linkLabel.setOutputMarkupId(true); }
From source file:org.headsupdev.agile.app.artifacts.RepositoryBrowsePanel.java
License:Open Source License
public RepositoryBrowsePanel(String id, File path, String pathStr, final Project project, final Class pageClass) { super(id);// w w w .ja va2s .c om this.project = project; add(CSSPackageResource.getHeaderContribution(getClass(), "repository.css")); if (pathStr == null) { pathStr = ""; if (project != null) { if (pageClass.equals(ProjectsRepository.class)) { pathStr = project.getId(); } else { if (project instanceof MavenTwoProject) { MavenTwoProject m2Project = (MavenTwoProject) project; pathStr = m2Project.getGroupId().replace('.', File.separatorChar) + File.separatorChar + m2Project.getArtifactId(); } else if (project instanceof AntProject) { AntProject antProject = (AntProject) project; String org = antProject.getOrganisation(); String module = antProject.getModule(); if (org != null && org.trim().length() > 0 && module != null && module.trim().length() > 0) { pathStr = org.replace('.', File.separatorChar) + File.separatorChar + module; } } } } } if (pathStr.length() > 1 && pathStr.charAt(pathStr.length() - 1) != File.separatorChar) { pathStr += File.separatorChar; } if (!StringUtil.isEmpty(pathStr)) { resolvedPath = new File(path, pathStr); } else { resolvedPath = path; } boolean missing = !resolvedPath.exists(); if (missing && pathStr.contains(FileUtil.LATEST_ITEM_NAME)) { resolvedPath = FileUtil.replaceLatest(resolvedPath); missing = !resolvedPath.exists(); } File[] fileArr = resolvedPath.listFiles(); List<File> files; if (fileArr == null) { files = new LinkedList<File>(); } else { files = Arrays.asList(fileArr); } Collections.sort(files); WebMarkupContainer parent = new WebMarkupContainer("parent"); if (StringUtil.isEmpty(pathStr) || (pageClass.equals(ProjectsRepository.class) && (pathStr.equals(project.getId() + File.separatorChar) || pathStr.equals(File.separatorChar + project.getId() + File.separatorChar)))) { Mime parentFolder = Mime.get("parent-folder"); Link iconLink = new BookmarkablePageLink("parent-icon-link", ListRepositories.class, getProjectPageParameters()); iconLink.add(new Image("parent-icon", new ResourceReference(Mime.class, parentFolder.getIconName()))); parent.add(iconLink); Link link = new BookmarkablePageLink("parent-link", ListRepositories.class, getProjectPageParameters()); parent.add(link); } else { Mime parentFolder = Mime.get("parent-folder"); PageParameters params = new PageParameters(); String parentPath = new File(pathStr).getParent(); if (parentPath == null) { params.add("project", "all"); } else { params.add("project", project.getId()); params.add("path", parentPath.replace(File.separatorChar, ':') + ":"); } Link iconLink = new BookmarkablePageLink("parent-icon-link", pageClass, params); iconLink.add(new Image("parent-icon", new ResourceReference(Mime.class, parentFolder.getIconName()))); parent.add(iconLink); Link link = new BookmarkablePageLink("parent-link", pageClass, params); parent.add(link); } add(parent); // assume we should show latest until we find a file that is not suitable boolean showLatest = files.size() > 0; File _latestFile = null; for (File file : files) { if (file.isHidden()) { continue; } showLatest = showLatest && FileUtil.isFileNumeric(file); if (showLatest) { // was a number, so let's create a latest item; if (_latestFile == null) { _latestFile = file; } else { if (_latestFile.lastModified() < file.lastModified()) { _latestFile = file; } } } } if (showLatest) { List<File> newFiles = new LinkedList<File>(); newFiles.addAll(files); newFiles.add(0, new File(FileUtil.LATEST_ITEM_NAME)); files = newFiles; } final File latestFile = _latestFile; final boolean latestIsFile = latestFile != null && latestFile.isFile(); final String repoPath = pathStr; add(new StripedListView<File>("browse-items", files) { protected void populateItem(ListItem<File> listItem) { super.populateItem(listItem); File file = listItem.getModelObject(); Link link, iconLink; Mime mime; String label = file.getName(); if (file.getName().equals(FileUtil.LATEST_ITEM_NAME)) { label = FileUtil.LATEST_ITEM_NAME + " (" + latestFile.getName() + ")"; if (latestIsFile) { mime = Mime.get(Mime.MIME_FILE_LINK); listItem.add(new Label("size", new FormattedSizeModel(file.length()))); } else { mime = Mime.get(Mime.MIME_FOLDER_LINK); listItem.add(new Label("size", "")); } file = latestFile; PageParameters params = getProjectPageParameters(); params.add("path", repoPath.replace(File.separatorChar, ':') + FileUtil.LATEST_ITEM_NAME + ":"); iconLink = new BookmarkablePageLink("browse-icon-link", pageClass, params); link = new BookmarkablePageLink("browse-link", pageClass, params); } else if (file.isDirectory()) { File metadata = new File(file, "maven-metadata.xml"); File releaseMetadata = new File(file, file.getParentFile().getName() + "-" + file.getName() + ".pom"); File parentMeta = new File(file.getParentFile(), "maven-metadata.xml"); if (metadata.exists() || releaseMetadata.exists()) { mime = Mime.get("package"); if (parentMeta.exists()) { String artifact = repoPath.substring(0, repoPath.length() - 1) .replace(File.separatorChar, '.'); int lastDot = artifact.lastIndexOf('.'); artifact = artifact.substring(0, lastDot) + ":" + artifact.substring(lastDot + 1); label = artifact + ":" + label; } else { label = repoPath.substring(0, repoPath.length() - 1).replace(File.separatorChar, '.') + ":" + label; } } else { mime = Mime.get("folder"); } PageParameters params = getProjectPageParameters(); params.add("path", repoPath.replace(File.separatorChar, ':') + file.getName() + ":"); iconLink = new BookmarkablePageLink("browse-icon-link", pageClass, params); link = new BookmarkablePageLink("browse-link", pageClass, params); listItem.add(new Label("size", "")); } else { mime = Mime.get(file.getName()); iconLink = new DownloadLink("browse-icon-link", file); link = new DownloadLink("browse-link", file); listItem.add(new Label("size", new FormattedSizeModel(file.length()))); } link.add(new Label("browse-label", label)); listItem.add(link); iconLink.add(new Image("browse-icon", new ResourceReference(Mime.class, mime.getIconName()))); listItem.add(iconLink); Date modified = new Date(file.lastModified()); listItem.add(new Label("modified", new FormattedDurationModel(modified, new Date()) { public String getObject() { return super.getObject() + " ago"; } })); } }.setVisible(!missing)); add(new WebMarkupContainer("missing").setVisible(missing)); }
From source file:org.headsupdev.agile.app.docs.View.java
License:Open Source License
public void layout() { super.layout(); add(CSSPackageResource.getHeaderContribution(getClass(), "doc.css")); title = getPageParameters().getString("page"); if (title == null || title.length() == 0) { title = Document.DEFAULT_PAGE; }// w ww . jav a 2s.c o m doc = DocsApplication.getDocument(title, getProject()); View.layoutMenuItems(this); WebMarkupContainer details = new WebMarkupContainer("details"); add(details); PageParameters titledParameters = getPageParameters(); if (!titledParameters.containsKey("page")) { titledParameters.add("page", title); } if (doc == null) { addLink(new BookmarkableMenuLink(getPageClass("docs/edit"), getPageParameters(), "create")); add(new WebMarkupContainer("content").setVisible(false)); WebMarkupContainer notfound = new WebMarkupContainer("notfound"); notfound.add(new Label("page", title)); notfound.add(new Label("project", getProject().getAlias())); notfound.add(new BookmarkablePageLink("create", getPageClass("docs/edit"), titledParameters)); add(notfound); details.setVisible(false); return; } addLink(new BookmarkableMenuLink(getPageClass("docs/edit"), titledParameters, "edit")); watching = doc.getWatchers().contains(getSession().getUser()); addLink(new MenuLink() { public String getLabel() { if (watching) { return "unwatch"; } return "watch"; } public void onClick() { toggleWatching(); } }); addLink(new BookmarkableMenuLink(getPageClass("docs/comment"), getPageParameters(), "comment")); addLink(new BookmarkableMenuLink(getPageClass("docs/attach"), getPageParameters(), "attach")); add(new WebMarkupContainer("notfound").setVisible(false)); add(new Label("content", getContent(doc)).setEscapeModelStrings(false)); List<Attachment> attachmentList = new LinkedList<Attachment>(); attachmentList.addAll(doc.getAttachments()); Collections.sort(attachmentList, new Comparator<Attachment>() { public int compare(Attachment attachment1, Attachment attachment2) { return attachment1.getCreated().compareTo(attachment2.getCreated()); } }); details.add(new ListView<Attachment>("attachments", attachmentList) { protected void populateItem(ListItem<Attachment> listItem) { Attachment attachment = listItem.getModelObject(); listItem.add(new Label("username", attachment.getUser().getFullnameOrUsername())); listItem.add(new Label("created", new FormattedDateModel(attachment.getCreated(), ((HeadsUpSession) getSession()).getTimeZone()))); File file = attachment.getFile(getStorage()); Mime mime = Mime.get(file.getName()); listItem.add(new Image("attachment-icon", new ResourceReference(Mime.class, mime.getIconName()))); Link download = new DownloadLink("attachment-link", file); download.add(new Label("attachment-label", attachment.getFilename())); listItem.add(download); Comment comment = attachment.getComment(); if (comment != null) { Label commentLabel = new Label("comment", new MarkedUpTextModel(comment.getComment(), getProject())); commentLabel.setEscapeModelStrings(false); listItem.add(commentLabel); } else { listItem.add(new WebMarkupContainer("comment").setVisible(false)); } } }); List<Comment> commentList = new LinkedList<Comment>(); commentList.addAll(doc.getComments()); Collections.sort(commentList, new Comparator<Comment>() { public int compare(Comment comment1, Comment comment2) { return comment1.getCreated().compareTo(comment2.getCreated()); } }); details.add(new ListView<Comment>("comments", commentList) { protected void populateItem(ListItem<Comment> listItem) { listItem.add(new CommentPanel("comment", listItem.getModel(), getProject())); } }); }
From source file:org.headsupdev.agile.app.issues.ViewIssue.java
License:Open Source License
public void layout() { super.layout(); add(CSSPackageResource.getHeaderContribution(getClass(), "issue.css")); add(CSSPackageResource.getHeaderContribution(IssueListPanel.class, "issue.css")); if (!IdPatternValidator.isValidId(getPageParameters().getString("id"))) { userError("Invalid issue id"); return;/*from w ww .java2 s.c om*/ } issueId = getPageParameters().getLong("id"); issue = IssuesApplication.getIssue(issueId, getProject()); if (issue == null) { notFoundError(); return; } watching = issue.getWatchers().contains(getSession().getUser()); List<MenuLink> links = getLinks(issue); if (issue.getStatus() < Issue.STATUS_CLOSED) { links.add(1, new MenuLink() { public String getLabel() { if (watching) { return "unwatch"; } return "watch"; } public void onClick() { toggleWatching(); } }); } addLinks(links); issuePanel = new IssuePanel("issue", issue); add(issuePanel); final List<Attachment> attachmentList = new LinkedList<Attachment>(); attachmentList.addAll(issue.getAttachments()); Collections.sort(attachmentList, new Comparator<Attachment>() { public int compare(Attachment attachment1, Attachment attachment2) { return attachment1.getCreated().compareTo(attachment2.getCreated()); } }); add(new ListView<Attachment>("attachments", attachmentList) { private Attachment attachment; protected void populateItem(ListItem<Attachment> listItem) { attachment = listItem.getModelObject(); PageParameters params = new PageParameters(); listItem.add(new GravatarLinkPanel("avatar", attachment.getUser(), HeadsUpPage.DEFAULT_AVATAR_EDGE_LENGTH)); params.add("username", attachment.getUser().getUsername()); params.add("silent", "true"); BookmarkablePageLink usernameLink = new BookmarkablePageLink("usernameLink", ViewIssue.this.getPageClass("account"), params); usernameLink.add(new Label("username", attachment.getUser().getFullnameOrUsername())); listItem.add(usernameLink); listItem.add(new Label("created", new FormattedDateModel(attachment.getCreated(), ((HeadsUpSession) getSession()).getTimeZone()))); final File file = attachment.getFile(getStorage()); Mime mime = Mime.get(file.getName()); listItem.add(new Image("attachment-icon", new ResourceReference(Mime.class, mime.getIconName()))); listItem.add(new EmbeddedFilePanel("embed", attachment.getFile(getStorage()), getProject())); Link download = new DownloadLink("attachment-link", file); download.add(new Label("attachment-label", attachment.getFilename())); listItem.add(download); User currentUser = ((HeadsUpSession) getSession()).getUser(); listItem.add(new AjaxFallbackLink("attachment-delete") { @Override public void onClick(AjaxRequestTarget ajaxRequestTarget) { ConfirmDialog dialog = new ConfirmDialog(HeadsUpPage.DIALOG_PANEL_ID, "Delete Attachment", "delete this attachment") { @Override public void onDialogConfirmed() { attachment = (Attachment) ((HibernateStorage) getStorage()).getHibernateSession() .merge(attachment); issue = (Issue) ((HibernateStorage) getStorage()).getHibernateSession() .merge(issue); attachmentList.remove(attachment); issue.getAttachments().remove(attachment); ((HibernateStorage) getStorage()).delete(attachment); attachment.getFile(getStorage()).delete(); } }; showDialog(dialog, ajaxRequestTarget); } }.setVisible(Manager.getSecurityInstance().userHasPermission(currentUser, new IssueEditPermission(), getProject()))); Comment comment = attachment.getComment(); if (comment != null) { Label commentLabel = new Label("comment", new MarkedUpTextModel(comment.getComment(), getProject())); commentLabel.setEscapeModelStrings(false); listItem.add(commentLabel); } else { listItem.add(new WebMarkupContainer("comment").setVisible(false)); } } }); final List commentList = new LinkedList(); commentList.addAll(issue.getComments()); if (issue.getTimeWorked() != null && Boolean.parseBoolean( issue.getProject().getConfigurationValue(StoredProject.CONFIGURATION_TIMETRACKING_ENABLED))) { commentList.addAll(issue.getTimeWorked()); } Collections.sort(commentList, new Comparator() { public int compare(Object o1, Object o2) { Date date1 = null, date2 = null; if (o1 instanceof Comment) { date1 = ((Comment) o1).getCreated(); } else if (o1 instanceof DurationWorked) { date1 = ((DurationWorked) o1).getDay(); } if (o2 instanceof Comment) { date2 = ((Comment) o2).getCreated(); } else if (o2 instanceof DurationWorked) { date2 = ((DurationWorked) o2).getDay(); } if (date1 == null || date2 == null) { if (date1 == null) { if (date2 == null) { return 0; } else { return 1; } } else { return -1; } } return date1.compareTo(date2); } }); add(new ListView<Serializable>("comments", commentList) { protected void populateItem(final ListItem listItem) { IssueCommentPanel panel = new IssueCommentPanel("comment", listItem.getModel(), getProject(), commentList, issue) { @Override public void showConfirmDialog(ConfirmDialog dialog, AjaxRequestTarget target) { showDialog(dialog, target); } @Override public Link getEditLink() { PageParameters params = new PageParameters(); params.put("project", getProject()); params.put("id", issue.getId()); params.put("commentId", getComment().getId()); return new BookmarkablePageLink("editComment", EditComment.class, params); } }; listItem.add(panel); } }); }
From source file:org.headsupdev.agile.web.components.EmbeddedFilePanel.java
License:Open Source License
public EmbeddedFilePanel(final String id, final File file, final Project project) { super(id);// w w w . j a v a 2s. c o m add(CSSPackageResource.getHeaderContribution(getClass(), "embeddedfile.css")); add(JavascriptPackageResource.getHeaderContribution(getClass(), "highlight/shCore.js")); add(JavascriptPackageResource.getHeaderContribution(getClass(), "highlight/shAutoloader.js")); add(JavascriptPackageResource.getHeaderContribution(getClass(), "highlight/bootstrap.js")); add(CSSPackageResource.getHeaderContribution(getClass(), "highlight/shCoreDefault.css")); final Mime mime = Mime.get(file.getName()); if (mime.isEmbeddableImage()) { WebMarkupContainer image = new WebMarkupContainer("image-content"); image.add(new Image("image", new DynamicImageResource() { protected byte[] getImageData() { try { return toImageData(ImageIO.read(file)); } catch (IOException e) { Manager.getLogger("BrowseFile").error("Unable to load data to image", e); return null; } } }.setCacheable(false))); add(image); add(new WebMarkupContainer("text-content").setVisible(false)); add(new WebMarkupContainer("binary-content").setVisible(false)); add(new WebMarkupContainer("object-content").setVisible(false)); return; } if (mime.isEmbeddableAudio() || mime.isEmbeddableVideo()) { WebMarkupContainer container = new WebMarkupContainer("object-content"); final WebMarkupContainer object = new WebMarkupContainer("object"); object.add(new AttributeModifier("type", true, new Model<String>() { @Override public String getObject() { // TODO add real mime types to the mime library if (mime.isEmbeddableAudio()) { return "audio/" + mime.getExtension(); } else { return "video/" + mime.getExtension(); } } })); object.add(new AttributeModifier("data", true, new Model<String>() { @Override public String getObject() { String storagePath = Manager.getStorageInstance().getDataDirectory().getAbsolutePath(); if (file.getAbsolutePath().length() > storagePath.length() + 1) { String filePath = file.getAbsolutePath().substring(storagePath.length() + 1); filePath = filePath.replace(File.separatorChar, ':'); try { filePath = URLEncoder.encode(filePath, "UTF-8"); // funny little hack here, guess the decoding is not right filePath = filePath.replace("+", "%20"); } catch (UnsupportedEncodingException e) { // ignore } String urlPath = object.urlFor(new ResourceReference("embed")).toString(); return urlPath.replace("/all/", "/" + project.getId() + "/") + "/path/" + filePath; } return ""; // not supported, someone is hacking the system... } })); container.add(object); add(container); add(new WebMarkupContainer("text-content").setVisible(false)); add(new WebMarkupContainer("binary-content").setVisible(false)); add(new WebMarkupContainer("image-content").setVisible(false)); return; } // offer a download link for binary (or unknown) files if (mime.isBinary()) { WebMarkupContainer binary = new WebMarkupContainer("binary-content"); binary.add(new DownloadLink("download", file)); add(binary); add(new WebMarkupContainer("text-content").setVisible(false)); add(new WebMarkupContainer("image-content").setVisible(false)); add(new WebMarkupContainer("object-content").setVisible(false)); return; } String content = "(unable to read file)"; // for other types try to parse the content FileInputStream in = null; try { in = new FileInputStream(file); content = IOUtil.toString(in).replace("<", "<").replace(">", ">"); } catch (IOException e) { Manager.getLogger("BrowseFile").error("Exception rendering file highlighting", e); } finally { IOUtil.close(in); } add(new Label("text-content", content).setEscapeModelStrings(false) .add(new AttributeModifier("class", true, new Model<String>() { @Override public String getObject() { if (mime.getSyntax() != null) { return "code brush: " + mime.getSyntax(); } return "code brush: text"; } }))); add(new WebMarkupContainer("binary-content").setVisible(false)); add(new WebMarkupContainer("image-content").setVisible(false)); add(new WebMarkupContainer("object-content").setVisible(false)); }
From source file:org.jabylon.log.viewer.pages.LogViewerPage.java
License:Open Source License
@Override protected void construct() { super.construct(); final TextArea<String> nextLog = new TextArea<String>("nextLog", logcontent); add(nextLog);/*from w w w .j a v a2s.c o m*/ nextLog.setOutputMarkupId(true); nextLog.add(new AjaxSelfUpdatingTimerBehavior(Duration.seconds(1)) { private static final long serialVersionUID = 4831467550166004945L; @Override protected void onPostProcessTarget(AjaxRequestTarget target) { super.onPostProcessTarget(target); String chunk = readChunk(40); if (chunk == null) chunk = ""; logcontent.setObject(chunk); target.appendJavaScript("updateLog();"); target.add(nextLog); } }); final DropDownChoice<LogLevel> logLevel = new DropDownChoice<LogLevel>("loglevel", new EnumSetList(), new LogLevelRenderer()); logLevel.setModel(Model.of(LogbackUtil.getLogLevel())); logLevel.add(new AjaxFormComponentUpdatingBehavior("onchange") { private static final long serialVersionUID = -4582780686636922915L; protected void onUpdate(AjaxRequestTarget target) { LogbackUtil.setLogLevel(logLevel.getModelObject()); } }); add(logLevel); File logFile = new File(LogbackUtil.getLogFiles().get(0).getLocation()); add(new DownloadLink("dowloadLog", logFile)); }