Example usage for org.apache.wicket.markup.html.link ResourceLink ResourceLink

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

Introduction

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

Prototype

public ResourceLink(final String id, final IResource resource) 

Source Link

Document

Constructs a link directly to the provided resource.

Usage

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/*w w w.  ja v  a2s. c o  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   ww  w  .jav a  2s .co 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.ja v a  2  s  . com*/
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  .  ja v  a2  s  .c o  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:de.inren.frontend.health.backup.BackupRestorePanel.java

License:Apache License

private Component getMyBackupLink(String id) {
    Calendar cal = Calendar.getInstance();

    final String key = "HealthBackup_" + getUser().getUsername() + "_" + cal.getTime().toString() + ".xml";

    ResourceReference rr = new ResourceReference(key) {

        @Override//from  www  . jav a  2 s .c  o  m
        public IResource getResource() {
            return new ByteArrayResource("text/xml") {

                @Override
                protected byte[] getData(Attributes attributes) {
                    try {
                        String xml = healthXmlBackupRestoreService.dumpDbToXml(getUser().getUsername());
                        return xml.getBytes("UTF-8");
                    } catch (Exception e) {
                        log.error(e.getMessage(), e);
                        throw new RuntimeException(e.getMessage());
                    }
                }
            };
        }
    };
    return new ResourceLink(id, rr);
}

From source file:de.inren.frontend.health.backup.BackupRestorePanel.java

License:Apache License

private Component getAllBackupLink(String id) {
    Calendar cal = Calendar.getInstance();

    final String key = "HealthBackup_AllUser" + "_" + cal.getTime().toString() + ".xml";

    ResourceReference rr = new ResourceReference(key) {

        @Override//from  w  ww.  java 2s  .  com
        public IResource getResource() {
            return new ByteArrayResource("text/xml") {

                @Override
                protected byte[] getData(Attributes attributes) {
                    try {
                        String xml = healthXmlBackupRestoreService.dumpDbToXml();
                        return xml.getBytes("UTF-8");
                    } catch (Exception e) {
                        log.error(e.getMessage(), e);
                        throw new RuntimeException(e.getMessage());
                    }
                }
            };
        }
    };
    return new ResourceLink(id, rr);
}

From source file:de.jetwick.ui.ResultsPanel.java

License:Apache License

public ResultsPanel(String id, final String toLanguage) {
    super(id);//  w ww .  j a v a 2s.  co  m

    add(new Label("qm", new PropertyModel(this, "queryMessage")));
    add(new Label("qmWarn", new PropertyModel(this, "queryMessageWarn")) {

        @Override
        public boolean isVisible() {
            return queryMessageWarn != null && queryMessageWarn.length() > 0;
        }
    });

    add(createHitLink(15));
    add(createHitLink(30));
    add(createHitLink(60));

    Model qModel = new Model() {

        @Override
        public Serializable getObject() {
            if (query == null)
                return "";
            String str = query;
            if (str.length() > 20)
                str = str.substring(0, 20) + "..";
            return "Find origin of '" + str + "'";
        }
    };
    findOriginLink = new LabeledLink("findOriginLink", null, qModel, false) {

        @Override
        public void onClick(AjaxRequestTarget target) {
            PageParameters pp = new PageParameters();
            pp.add("findOrigin", query);
            setResponsePage(TweetSearchPage.class, pp);
        }
    };

    add(findOriginLink);
    translateAllLink = new LabeledLink("translateAllLink", null, new Model<String>() {

        @Override
        public String getObject() {
            if (translateAll)
                return "Show original language";
            else
                // get english name of iso language chars
                return "Translate tweets into " + new Locale(toLanguage).getDisplayLanguage(new Locale("en"));
        }
    }) {

        @Override
        public void onClick(AjaxRequestTarget target) {
            if (target == null)
                return;

            translateAll = !translateAll;
            if (!translateAll)
                translateMap.clear();
            target.addComponent(ResultsPanel.this);
        }
    };

    add(translateAllLink);
    add(createSortLink("sortRelevance", ElasticTweetSearch.RELEVANCE, "desc"));
    add(createSortLink("sortRetweets", ElasticTweetSearch.RT_COUNT, "desc"));
    add(createSortLink("sortLatest", ElasticTweetSearch.DATE, "desc"));
    add(createSortLink("sortOldest", ElasticTweetSearch.DATE, "asc"));

    add(new DialogUtilsBehavior());

    userView = new ListView("users", users) {

        @Override
        public void populateItem(final ListItem item) {
            final JUser user = (JUser) item.getModelObject();
            String name = user.getScreenName();
            if (user.getRealName() != null)
                name = user.getRealName() + "  (" + name + ")";

            LabeledLink userNameLink = new LabeledLink("userNameLink", name, false) {

                @Override
                public void onClick(AjaxRequestTarget target) {
                    onUserClick(user.getScreenName(), null);
                }
            };
            item.add(userNameLink);
            Link showLatestTweets = new Link("profileUrl") {

                @Override
                public void onClick() {
                    onUserClick(user.getScreenName(), null);
                }
            };
            item.add(showLatestTweets.add(new ContextImage("profileImg", user.getProfileImageUrl())));

            final List<JTweet> tweets = new ArrayList<JTweet>();
            int counter = 0;
            for (JTweet tw : user.getOwnTweets()) {
                if (tweetsPerUser > 0 && counter >= tweetsPerUser)
                    break;

                tweets.add(tw);
                allTweets.put(tw.getTwitterId(), tw);
                counter++;
            }
            ListView tweetView = new ListView("tweets", tweets) {

                @Override
                public void populateItem(final ListItem item) {
                    item.add(createOneTweet("oneTweet", toLanguage).init(item.getModel(), false));
                }
            };
            item.add(tweetView);
        }
    };

    add(userView);
    WebResource export = new WebResource() {

        @Override
        public IResourceStream getResourceStream() {
            return new StringResourceStream(getTweetsAsString(), "text/plain");
        }

        @Override
        protected void setHeaders(WebResponse response) {
            super.setHeaders(response);
            response.setAttachmentHeader("tweets.txt");
        }
    };

    export.setCacheable(false);
    add(new ResourceLink("exportTsvLink", export));
    add(new Link("exportHtmlLink") {

        @Override
        public void onClick() {
            onHtmlExport();
        }
    });
}

From source file:nl.knaw.dans.dccd.web.download.DownloadPanel.java

License:Apache License

private void init() {
    //      add(new ResourceLink(DOWNLOAD_XML, getXMLWebResource(project)));
    add(new ResourceLink(DOWNLOAD_XML, getXMLWebResource()));
}

From source file:nl.knaw.dans.dccd.web.search.SearchResultDownloadPage.java

License:Apache License

private void init() {
    // get the back page
    backPage = ((DccdSession) Session.get()).getRedirectPage(getPage().getClass());
    // The back button or link
    Link backButton = new Link("backButton", new ResourceModel("backButton")) {
        private static final long serialVersionUID = 1L;

        @Override/*from ww w  .  j a v  a  2 s .  co  m*/
        public void onClick() {
            // get the previous page, and try to browse back
            Page page = backPage;
            if (page != null) {
                //   if (page instanceof BasePage)
                //      ((BasePage)page).refresh();
                setResponsePage(page);
            } else {
                // just go back to a new instance of HomePage
                setResponsePage(HomePage.class);
            }
        }
    };
    add(backButton);

    // result message 
    // Not the a panel for displaying just the total results message
    //add(new SearchResultMessagePanel("resultMessage", (SearchModel)getDefaultModel()));
    SearchData searchData = ((SearchModel) getDefaultModel()).getObject();
    SearchResult<? extends DccdSB> searchResult = (SearchResult<? extends DccdSB>) searchData.getResult();
    SearchRequestBuilder originalRequestBuilder = searchData.getRequestBuilder();
    int totalHits = searchResult.getTotalHits();
    String queryString = originalRequestBuilder.getRequest().getQuery().getQueryString();
    add(new UnescapedLabel("resultMessage", new StringResourceModel("search.download.resultMessage", this, null,
            new Object[] { totalHits, Strings.escapeMarkup(queryString) })));

    // Need the user for the permission check
    user = (DccdUser) ((DccdSession) getSession()).getUser();

    // add form
    Form form = new Form("form");
    add(form);

    // Note mabe use a DynamicWebResource?
    WebResource export = new WebResource() {
        private static final long serialVersionUID = -3015006109107869870L;

        @Override
        public IResourceStream getResourceStream() {
            return getResourceStreamForXML();
        }

        @Override
        protected void setHeaders(WebResponse response) {
            super.setHeaders(response);

            setHeadersForXML(response);
        }
    };
    export.setCacheable(false);

    final ResourceLink downloadLink = new ResourceLink("downloadSearchResults", export);
    downloadLink.setOutputMarkupPlaceholderTag(true);
    downloadLink.setVisible(false);
    downloadLink.setOutputMarkupId(true);
    form.add(downloadLink);

    final Label waitMsgLabel = new Label("myLabel",
            new StringResourceModel("search.download.fileconstruction.waitMessage", this, null));
    waitMsgLabel.setOutputMarkupPlaceholderTag(true);
    waitMsgLabel.setVisible(true);
    waitMsgLabel.setOutputMarkupId(true);
    form.add(waitMsgLabel);

    IndicatingAjaxButton submitButton = new IndicatingAjaxButton("submitButton") {
        protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
            // TODO Auto-generated method stub
            logger.debug("Onsubmit called, start work");

            theData = getAllResultsAsXMLInParts();//getAllResultsAsXML();

            logger.debug("Done with work");
            // TODO enable downlod button?
            downloadLink.setVisible(true);
            target.addComponent(downloadLink);

            waitMsgLabel.setVisible(false);
            target.addComponent(waitMsgLabel);

            this.setVisible(false);
            target.addComponent(this);
        }
    };
    submitButton.setOutputMarkupId(true);
    form.add(submitButton);
}

From source file:ontopoly.pages.AdminPage.java

License:Apache License

public AdminPage(PageParameters parameters) {
    super(parameters);

    // Adding part containing title and help link
    createTitle();/*from ww  w  .j  a va2s. co m*/

    final Form<Object> form = new Form<Object>("form");
    form.setOutputMarkupId(true);
    add(form);

    // First column of radio buttons
    final List<String> contentCategories = Arrays.asList(
            new ResourceModel("AdminPage.export.entire.topic.map").getObject().toString(),
            new ResourceModel("AdminPage.export.topic.map.without.schema").getObject().toString(),
            new ResourceModel("AdminPage.export.only.schema").getObject().toString());
    content = (String) contentCategories.get(0);
    RadioChoice<String> contentRadioChoice = new RadioChoice<String>("content",
            new PropertyModel<String>(this, "content"), contentCategories);
    contentRadioChoice.add(new AjaxFormChoiceComponentUpdatingBehavior() {
        @Override
        protected void onUpdate(AjaxRequestTarget target) {
            // no-op
        }
    });
    form.add(contentRadioChoice);

    TopicMap topicMap = getTopicMap();

    // Second column of radio buttons
    List<String> syntaxCategories = Arrays.asList("ltm", "xtm1", "xtm2", "xtm21", "rdf", "tmxml");

    syntax = syntaxCategories.get(1);
    filename = topicMap.getId();

    final AjaxOntopolyTextField fileNameTextField = new AjaxOntopolyTextField("fileNameTextField",
            new PropertyModel<String>(this, "filename"));

    RadioChoice<String> syntaxRadioChoice = new RadioChoice<String>("syntax",
            new PropertyModel<String>(this, "syntax"), syntaxCategories, new IChoiceRenderer<String>() {
                public Object getDisplayValue(String object) {
                    return new ResourceModel("AdminPage.export.syntax." + object).getObject(); // "export.syntax.ltm", "export.syntax.xtm1", "export.syntax.xtm2", "export.syntax.rdf" ...
                }

                public String getIdValue(String object, int index) {
                    return object;
                }
            });
    syntaxRadioChoice.add(new AjaxFormChoiceComponentUpdatingBehavior() {
        @Override
        protected void onUpdate(AjaxRequestTarget target) {
            if (target != null)
                target.addComponent(form);
        }
    });
    form.add(syntaxRadioChoice);

    // Third column of radio buttons
    List<String> actionCategories = Arrays.asList(
            new ResourceModel("AdminPage.export.download").getObject().toString(),
            new ResourceModel("AdminPage.export.view").getObject().toString());
    action = actionCategories.get(0).toString();
    RadioChoice<String> actionRadioChoice = new RadioChoice<String>("action",
            new PropertyModel<String>(this, "action"), actionCategories);
    form.add(actionRadioChoice);
    actionRadioChoice.add(new AjaxFormChoiceComponentUpdatingBehavior() {
        @Override
        protected void onUpdate(AjaxRequestTarget target) {
            if (target != null) {
                target.addComponent(form);
            }
        }
    });
    form.add(fileNameTextField);

    WebResource export = new WebResource() {

        @Override
        public IResourceStream getResourceStream() {
            AbstractResourceStreamWriter abstractResourceStreamWriter = new AbstractResourceStreamWriter() {
                public void write(OutputStream output) {
                    ExportUtils.Content contentchoice = ExportUtils.Content.ENTIRE_TOPIC_MAP;
                    if (content.equals((String) contentCategories.get(1)))
                        contentchoice = ExportUtils.Content.INSTANCES_ONLY;
                    else if (content.equals((String) contentCategories.get(2)))
                        contentchoice = ExportUtils.Content.SCHEMA_ONLY;
                    try {
                        ExportUtils.export(getTopicMap(), syntax, contentchoice,
                                new OutputStreamWriter(output, "utf-8"));
                    } catch (UnsupportedEncodingException e) {
                        throw new OntopiaRuntimeException(e);
                    }

                }

                public String getContentType() {
                    return syntax.equalsIgnoreCase("ltm") ? "text/plain" : "text/xml";
                }
            };

            return abstractResourceStreamWriter;
        }

        @Override
        protected void setHeaders(WebResponse response) {
            super.setHeaders(response);
            if (action.equals(new ResourceModel("AdminPage.export.download").getObject().toString())) {
                response.setAttachmentHeader(fileNameTextField.getModel().getObject());
            }
        }
    };
    export.setCacheable(false);

    ResourceLink<Object> resourceLink = new ResourceLink<Object>("export", export);
    resourceLink.add(new SimpleAttributeModifier("value",
            new ResourceModel("AdminPage.export.button").getObject().toString()));
    form.add(resourceLink);

    // initialize parent components
    initParentComponents();
}