List of usage examples for org.apache.wicket.markup.html.link DownloadLink DownloadLink
public DownloadLink(String id, IModel<File> fileModel, IModel<String> fileNameModel)
From source file:com.axway.ats.testexplorer.pages.testcase.attachments.AttachmentsPanel.java
License:Apache License
@SuppressWarnings({ "unchecked", "rawtypes" }) public AttachmentsPanel(String id, final String testcaseId, final PageParameters parameters) { super(id);/* w ww . j a v a2s. c o m*/ form = new Form<Object>("form"); buttonPanel = new WebMarkupContainer("buttonPanel"); noButtonPanel = new WebMarkupContainer("noButtonPanel"); fileContentContainer = new TextArea<String>("textFile", new Model<String>("")); imageContainer = new WebMarkupContainer("imageFile"); fileContentInfo = new Label("fileContentInfo", new Model<String>("")); buttons = getAllAttachedFiles(testcaseId); form.add(fileContentContainer); form.add(imageContainer); form.add(fileContentInfo); form.add(buttonPanel); add(noButtonPanel); add(form); buttonPanel.setVisible(!(buttons == null)); fileContentContainer.setVisible(false); imageContainer.setVisible(false); fileContentInfo.setVisible(false); noButtonPanel.setVisible(buttons == null); // if noButtonPanel is visible, do not show form and vice versa form.setVisible(!noButtonPanel.isVisible()); noButtonPanel.add(new Label("description", noButtonPanelInfo)); final ListView lv = new ListView("buttons", buttons) { private static final long serialVersionUID = 1L; @Override protected void populateItem(final ListItem item) { if (item.getIndex() % 2 != 0) { item.add(AttributeModifier.replace("class", "oddRow")); } final String viewedFile = buttons.get(item.getIndex()); final String name = getFileSimpleName(buttons.get(item.getIndex())); final Label buttonLabel = new Label("name", name); Label fileSize = new Label("fileSize", getFileSize(viewedFile)); downloadFile = new DownloadLink("download", new File(" "), ""); downloadFile.setModelObject(new File(viewedFile)); downloadFile.setVisible(true); alink = new AjaxLink("alink", item.getModel()) { private static final long serialVersionUID = 1L; @Override public void onClick(AjaxRequestTarget target) { fileContentInfo.setVisible(true); String fileContent = new String(); if (!isImage(viewedFile)) { fileContentContainer.setVisible(true); imageContainer.setVisible(false); fileContent = getFileContent(viewedFile, name); fileContentContainer.setModelObject(fileContent); } else { PageNavigation navigation = null; try { navigation = ((TestExplorerSession) Session.get()).getDbReadConnection() .getNavigationForTestcase(testcaseId, getTESession().getTimeOffset()); } catch (DatabaseAccessException e) { LOG.error("Can't get runId, suiteId and dbname for testcase with id=" + testcaseId, e); } String runId = navigation.getRunId(); String suiteId = navigation.getSuiteId(); String dbname = TestExplorerUtils.extractPageParameter(parameters, "dbname"); fileContentInfo.setDefaultModelObject("Previewing '" + name + "' image"); final String url = "AttachmentsServlet?&runId=" + runId + "&suiteId=" + suiteId + "&testcaseId=" + testcaseId + "&dbname=" + dbname + "&fileName=" + name; imageContainer.add(new AttributeModifier("src", new Model<String>(url))); imageContainer.setVisible(true); fileContentContainer.setVisible(false); } // first setting all buttons with the same state String reverseButtonsState = "var cusid_ele = document.getElementsByClassName('attachedButtons'); " + "for (var i = 0; i < cusid_ele.length; ++i) { " + "var item = cusid_ele[i]; " + "item.style.color= \"#000000\";" + "}"; // setting CSS style to the pressed button and its label String pressClickedButton = "var span = document.evaluate(\"//a[@class='button attachedButtons']/span[text()='" + name + "']\", " + "document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;" + "span.style.backgroundPosition=\"left bottom\";" + "span.style.padding=\"6px 0 4px 18px\";" + "var button = document.evaluate(\"//a[@class='button attachedButtons']/span[text()='" + name + "']/..\", " + "document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;" + "button.style.backgroundPosition=\"right bottom\";" + "button.style.color=\"#000000\";" + "button.style.outline=\"medium none\";"; // I could not figure out how it works with wicket, so i did it with JS target.appendJavaScript(reverseButtonsState); target.appendJavaScript(pressClickedButton); target.add(form); } }; alink.add(buttonLabel); item.add(alink); item.add(downloadFile); item.add(fileSize); } }; buttonPanel.add(lv); }
From source file:eu.esdihumboldt.hale.server.projects.war.components.ProjectList.java
License:Open Source License
/** * Constructor/*from w w w .j a va2 s.c o m*/ * * @param id the panel id * @param showCaption if the caption shall be shown */ public ProjectList(String id, boolean showCaption) { super(id); // projects list final IModel<? extends List<String>> projectsModel = new LoadableDetachableModel<List<String>>() { private static final long serialVersionUID = 7277175702043541004L; @Override protected List<String> load() { return new ArrayList<String>(projects.getResources()); } }; final ListView<String> projectList = new ListView<String>("projects", projectsModel) { private static final long serialVersionUID = -6740090246572869212L; /** * @see ListView#populateItem(ListItem) */ @Override protected void populateItem(ListItem<String> item) { final boolean odd = item.getIndex() % 2 != 0; if (odd) { item.add(AttributeModifier.replace("class", "odd")); } final String id = item.getModelObject(); // identifier item.add(new Label("identifier", id)); // status Status status = projects.getStatus(id); String statusImagePath; String statusTitle; switch (status) { case ACTIVE: statusImagePath = "images/ok.png"; statusTitle = "Active"; break; case INACTIVE: statusImagePath = "images/sleeping.gif"; statusTitle = "Inactive"; break; case BROKEN: statusImagePath = "images/error.gif"; statusTitle = "Project cannot be loaded"; break; case NOT_AVAILABLE: default: statusImagePath = "images/unknown.gif"; statusTitle = "Project file missing or not set"; } WebComponent statusImage = new WebComponent("status"); statusImage.add(AttributeModifier.replace("src", statusImagePath)); statusImage.add(AttributeModifier.replace("title", statusTitle)); item.add(statusImage); // action String actionImagePath; String actionTitle; boolean showAction; Link<?> actionLink; switch (status) { case ACTIVE: actionTitle = "Stop"; actionImagePath = "images/stop.gif"; showAction = true; actionLink = new Link<Void>("action") { private static final long serialVersionUID = 393941411843332519L; @Override public void onClick() { projects.deactivate(id); } }; break; case BROKEN: case NOT_AVAILABLE: actionTitle = "Rescan"; actionImagePath = "images/refresh.gif"; showAction = true; actionLink = new Link<Void>("action") { private static final long serialVersionUID = -4403828305588875839L; @Override public void onClick() { projects.triggerScan(); } }; break; case INACTIVE: default: actionTitle = "Start"; actionImagePath = "images/start.gif"; showAction = status.equals(Status.INACTIVE); actionLink = new Link<Void>("action") { private static final long serialVersionUID = 393941411843332519L; @Override public void onClick() { projects.activate(id); } }; break; } WebComponent actionImage = new WebComponent("image"); actionImage.add(AttributeModifier.replace("src", actionImagePath)); actionImage.add(AttributeModifier.replace("title", actionTitle)); actionLink.add(actionImage); actionLink.setVisible(showAction); item.add(actionLink); // name String projectName = ""; ProjectInfo info = projects.getInfo(id); if (info != null) { projectName = info.getName(); } item.add(new Label("name", projectName)); // download log File logFile = projects.getLoadReports(id); DownloadLink log = new DownloadLink("log", logFile, id + ".log"); log.setVisible(logFile != null && logFile.exists()); WebComponent logImage = new WebComponent("image"); if (status == Status.BROKEN) { logImage.add(AttributeModifier.replace("src", "images/error_log.gif")); } log.add(logImage); item.add(log); } }; add(projectList); boolean noProjects = projectsModel.getObject().isEmpty(); // caption WebMarkupContainer caption = new WebMarkupContainer("caption"); caption.setVisible(showCaption && !noProjects); add(caption); add(new WebMarkupContainer("noprojects").setVisible(noProjects)); }
From source file:eu.esdihumboldt.hale.server.webtransform.war.pages.StatusPage.java
License:Open Source License
@Override protected void addControls(boolean loggedIn) { super.addControls(loggedIn); final String workspaceId = getPageParameters().get(PARAMETER_WORKSPACE).toOptionalString(); if (workspaceId == null || workspaceId.isEmpty()) { throw new AbortWithHttpErrorCodeException(HttpServletResponse.SC_NOT_FOUND, "Workspace ID not specified."); }/*from w ww.ja va 2s.c o m*/ try { workspaces.getWorkspaceFolder(workspaceId); } catch (FileNotFoundException e) { throw new AbortWithHttpErrorCodeException(HttpServletResponse.SC_NOT_FOUND, "Workspace does not exist."); } final IModel<TransformationWorkspace> workspace = new LoadableDetachableModel<TransformationWorkspace>() { private static final long serialVersionUID = 2600444242247550094L; @Override protected TransformationWorkspace load() { return new TransformationWorkspace(workspaceId); } }; // job panel final Serializable family = AbstractTransformationJob.createFamily(workspaceId); final JobPanel jobs = new JobPanel("jobs", family, true); add(jobs); // status final Label status = new Label("status", new LoadableDetachableModel<String>() { private static final long serialVersionUID = -4351763182104835300L; @Override protected String load() { if (workspace.getObject().isTransformationFinished()) { if (workspace.getObject().isTransformationSuccessful()) { return "Transformation completed."; } else { return "Transformation failed."; } } else { if (Job.getJobManager().find(family).length > 0) { return "Transformation is running:"; } else { return "No transformation running."; } } } }); status.setOutputMarkupId(true); add(status); // result final WebMarkupContainer result = new WebMarkupContainer("result"); result.setOutputMarkupId(true); add(result); final WebMarkupContainer update = new WebMarkupContainer("update") { private static final long serialVersionUID = -2591480922683644827L; @Override public boolean isVisible() { return workspace.getObject().isTransformationFinished(); } }; result.add(update); // result : report File reportFile = workspace.getObject().getReportFile(); DownloadLink report = new DownloadLink("log", reportFile, reportFile.getName()); update.add(report); // result : file list IModel<? extends List<File>> resultFilesModel = new LoadableDetachableModel<List<File>>() { private static final long serialVersionUID = -7971872898614031331L; @Override protected List<File> load() { return Arrays.asList(workspace.getObject().getTargetFolder().listFiles()); } }; final ListView<File> fileList = new ListView<File>("file", resultFilesModel) { private static final long serialVersionUID = -8045643864251639540L; @Override protected void populateItem(ListItem<File> item) { // download link DownloadLink download = new DownloadLink("download", item.getModelObject(), item.getModelObject().getName()); item.add(download); // file name download.add(new Label("name", item.getModelObject().getName())); } }; update.add(fileList); // leaseEnd String leaseEnd; try { leaseEnd = workspaces.getLeaseEnd(workspaceId).toString(DateTimeFormat.mediumDateTime()); } catch (IOException e) { leaseEnd = "unknown"; } add(new Label("leaseEnd", leaseEnd)); boolean transformationFinished = workspace.getObject().isTransformationFinished(); if (transformationFinished) { // disable job timer jobs.getTimer().stopOnNextUpdate(); } else { // timer add(new AbstractAjaxTimerBehavior(Duration.milliseconds(1500)) { private static final long serialVersionUID = -3726349470723024150L; @Override protected void onTimer(AjaxRequestTarget target) { if (workspace.getObject().isTransformationFinished()) { // update status and result target.add(status); target.add(result); // stop timers stop(target); jobs.getTimer().stopOnNextUpdate(); } } }); } }
From source file:org.devgateway.eudevfin.reports.ui.pages.ReportsExport.java
License:Open Source License
public ReportsExport(final PageParameters parameters) { super(parameters); String reportType = parameters.get("reportType").toString(""); pageTitle.setDefaultModel(new StringResourceModel("navbar.reports.export." + reportType, this, null, null)); Label subtitleReportsExport = new Label("subtitleReportsExport", new StringResourceModel("navbar.reports.subtitleReportsExport", this, null, null)); add(subtitleReportsExport);//from www.ja va 2s . c o m final List<Integer> years = this.txService.findDistinctReportingYears(); // if the list of years is empty add the current year (ODAEU-322) if (years.size() == 0) { years.add(Calendar.getInstance().get(Calendar.YEAR) - 1); } DropDownChoice<Integer> year = new DropDownChoice<Integer>("reportYear", years, new IChoiceRenderer<Integer>() { private static final long serialVersionUID = 8801460052416367398L; public Object getDisplayValue(Integer value) { return value; } public String getIdValue(Integer object, int index) { return String.valueOf(years.get(index)); } }); add(year); List<String> dataSources = new ArrayList<String>(); dataSources.add(REPORT_DATASOURCE_AQ); dataSources.add(REPORT_DATASOURCE_CRS); DropDownChoice<String> dataSource = new DropDownChoice<String>("dataSource", dataSources, new IChoiceRenderer<String>() { @Override public Object getDisplayValue(String object) { return object; } @Override public String getIdValue(String object, int index) { return object; } }); WebMarkupContainer dataSourceGroup = new WebMarkupContainer("dataSourceGroup"); if (!reportType.equalsIgnoreCase(REPORT_AQ)) { dataSourceGroup.setVisibilityAllowed(false); } dataSourceGroup.add(dataSource); add(dataSourceGroup); HiddenField<String> field = new HiddenField<String>("reportType", Model.of("")); field.setModelValue(new String[] { reportType }); add(field); // get the 'Approved Reports' files // get the name of the Country String serverInstance = ""; Organization organizationForCurrentUser = AuthUtils.getOrganizationForCurrentUser(); if (organizationForCurrentUser != null) { serverInstance = organizationForCurrentUser.getDonorName(); } // set the files path and names String tmpDirPath = System.getProperty("java.io.tmpdir"); String dirPath = tmpDirPath + File.separator + serverInstance + "Repository" + File.separator + reportType; File dir = new File(dirPath); List<File> listFiles = new ArrayList(); if (dir.exists()) { for (final File reportFile : dir.listFiles()) { // check if there are files and that the name begins with the report type, for example 'DAC1_2013.pdf' if (reportFile.isFile() && reportFile.getName().startsWith(reportType.toUpperCase())) { listFiles.add(reportFile); } } } // sort the files name Collections.sort(listFiles); Label downloadApprovedReports = new Label("downloadApprovedReports", new StringResourceModel("navbar.reports.downloadApprovedReports", this, null, null)); add(downloadApprovedReports); add(new ListView<File>("listFiles", listFiles) { public void populateItem(final ListItem<File> item) { final File downloadFile = item.getModelObject(); IModel<File> fileModel = new Model(downloadFile); DownloadLink downloadLink = new DownloadLink("downloadLink", fileModel, downloadFile.getName()); downloadLink.add(new Label("downloadText", downloadFile.getName())); item.add(downloadLink); } }); if (listFiles == null || listFiles.size() == 0) { downloadApprovedReports.setVisibilityAllowed(false); } }
From source file:org.sakaiproject.scorm.ui.reporting.pages.ResultsListPage.java
License:Educational Community License
public ResultsListPage(PageParameters pageParams) { super(pageParams); final long contentPackageId = pageParams.getLong("contentPackageId"); final ContentPackage contentPackage = contentService.getContentPackage(contentPackageId); // SCO-94 - deny users who do not have scorm.view.results permission String context = lms.currentContext(); boolean canViewResults = lms.canViewResults(context); Label heading = new Label("heading", new ResourceModel("page.heading.notAllowed")); add(heading);//from w ww . j a v a 2 s . c o m final AttemptDataProvider dataProvider = new AttemptDataProvider(contentPackageId); dataProvider.setFilterConfigurerVisible(true); dataProvider.setTableTitle(getLocalizer().getString("table.title", this)); // SCO-127 buildExportHeaders(); AbstractReadOnlyModel<File> fileModel = new AbstractReadOnlyModel<File>() { @Override public File getObject() { File tempFile = null; try { tempFile = File.createTempFile(contentPackage.getTitle() + "_results", ".csv"); InputStream data = new ByteArrayInputStream(generateExportCSV(dataProvider).getBytes()); Files.writeTo(tempFile, data); } catch (IOException ex) { LOG.error("Could not generate results export: ", ex); } return tempFile; } }; DownloadLink btnExport = new DownloadLink("btnExport", fileModel, contentPackage.getTitle() + "_results.csv"); btnExport.setDeleteAfterDownload(true); add(btnExport); if (!canViewResults) { btnExport.setVisibilityAllowed(false); heading.setVisibilityAllowed(true); add(new WebMarkupContainer("attemptPresenter")); add(new WebMarkupContainer("details")); } else { // SCO-94 heading.setVisibilityAllowed(false); addBreadcrumb(new Model(contentPackage.getTitle()), ResultsListPage.class, new PageParameters(), false); EnhancedDataPresenter presenter = new EnhancedDataPresenter("attemptPresenter", getColumns(), dataProvider); add(presenter); add(new ContentPackageDetailPanel("details", contentPackage)); } }
From source file:org.wicketstuff.table.cell.renders.file.FileRender.java
License:Apache License
@Override public Component getRenderComponent(String id, IModel model, SelectableListItem parent, int row, int column) { final File f = (File) model.getObject(); if (f != null && f.exists()) { return new DownloadLink(id, f, f.getName()) { @Override//from w w w. jav a 2s . co m protected void onComponentTag(ComponentTag tag) { tag.setName("a"); super.onComponentTag(tag); } @Override protected void onComponentTagBody(MarkupStream markupStream, ComponentTag openTag) { super.onComponentTagBody(markupStream, openTag); getResponse().write(f.getName()); } }; } else { return new Label(id, f == null ? null : f.getName()); } }