Example usage for org.apache.wicket Application get

List of usage examples for org.apache.wicket Application get

Introduction

In this page you can find the example usage for org.apache.wicket Application get.

Prototype

public static Application get() 

Source Link

Document

Get Application for current thread.

Usage

From source file:com.mylab.wicket.jpa.ui.pages.select2.Select2ResourcesBehavior.java

License:Apache License

@Override
public void renderHead(Component component, IHeaderResponse response) {

    final ApplicationSettings settings = ApplicationSettings.get();

    // Include Wicket's provided jQuery reference
    response.render(JavaScriptHeaderItem
            .forReference(Application.get().getJavaScriptLibrarySettings().getJQueryReference()));

    if (settings.isIncludeJavascriptFull()) {
        response.render(JavaScriptHeaderItem.forReference(settings.getJavaScriptReferenceFull()));
    }//from  w  ww. j  a v  a  2 s  . c o m

    if (settings.isIncludeJavascript()) {
        response.render(JavaScriptHeaderItem.forReference(settings.getJavaScriptReference()));
    }

    if (settings.isIncludeCss()) {
        response.render(CssHeaderItem.forReference(settings.getCssReference()));
    }
}

From source file:com.mysticcoders.pastebin.web.pages.PasteListXmlPage.java

License:Apache License

/**
 * Creates a new instance.  No parameters are necessary.
 *///from   w  w  w  . j  a va2  s . co m
public PasteListXmlPage() {
    String privatePastebinName = ((PastebinApplication) Application.get()).getPrivatePastebinName();
    add(new ListView("pastes", new PasteEntriesModel(privatePastebinName)) {
        private static final long serialVersionUID = 1L;

        public void populateItem(ListItem item) {
            // paste element
            PasteEntry entry = (PasteEntry) item.getModelObject();
            item.add(new AttributeModifier("creationtime", new Model(DATE_FORMAT.format(entry.getCreated()))));
            item.add(new AttributeModifier("imagecount", new Model(entry.getImages().size())));
            item.add(new AttributeModifier("pasteid", new Model(entry.getId())));

            // channel element
            StringBuilder sb = new StringBuilder("<![CDATA[");
            sb.append(entry.getChannel() == null ? "" : entry.getChannel());
            sb.append("]]>");
            Label label = new Label("channel", new Model(sb.toString()));
            item.add(label);
            label.setEscapeModelStrings(false);
            label.setRenderBodyOnly(true);

            // line1 element
            sb = new StringBuilder("<![CDATA[");
            sb.append(entry.getCode().split("\\n|\\r\\n")[0]);
            sb.append("]]>");
            label = new Label("line1", new Model(sb.toString()));
            item.add(label);
            label.setEscapeModelStrings(false);
            label.setRenderBodyOnly(true);

            // url element
            HttpServletRequest req = ((WebRequest) getRequest()).getHttpServletRequest();
            StringBuilder url = new StringBuilder();
            //                StringBuilder url = new StringBuilder("http://");
            //                url.append(req.getServerName());
            //                if (req.getServerPort() != 80) {
            //                    url.append(':').append(req.getServerPort());
            //                }
            url.append(req.getContextPath());
            url.append('/');
            PageParameters parms = new PageParameters();
            parms.put("0", String.valueOf(entry.getId()));
            url.append(getPage().urlFor(PageMap.forName(PageMap.DEFAULT_NAME), ViewPastebinPage.class, parms));
            label = new Label("url", url.toString());
            item.add(label);
            label.setEscapeModelStrings(false);
            label.setRenderBodyOnly(true);

            // user element
            sb = new StringBuilder("<![CDATA[");
            sb.append(entry.getName());
            sb.append("]]>");
            label = new Label("user", sb.toString());
            item.add(label);
            label.setEscapeModelStrings(false);
            label.setRenderBodyOnly(true);
        }
    });
}

From source file:com.norconex.commons.wicket.model.ClassResourceModel.java

License:Apache License

@Override
protected String load() {
    Locale theLocale = locale;//from  www.  j  av  a 2  s.c  om
    if (theLocale == null) {
        theLocale = Session.get().getLocale();
    }
    List<IStringResourceLoader> loaders = Application.get().getResourceSettings().getStringResourceLoaders();
    for (IStringResourceLoader loader : loaders) {
        String string = loader.loadStringResource(klass, key, theLocale, Session.get().getStyle(), null);
        if (StringUtils.isNotBlank(string)) {
            return string;
        }
    }
    return null;
}

From source file:com.norconex.commons.wicket.resource.loader.StringResourceLoaderUtil.java

License:Apache License

/**
 * Relies on the {@link PackageStringResourceLoader} class to get
 * a string./*from  w w  w .ja v  a  2  s. c  o  m*/
 * @param klass the class used derive the package
 * @param key the string key
 * @param locale locale to use to return string
 * @return the proper string
 */
public static String getString(final Class<?> klass, final String key, final Locale locale) {
    List<IStringResourceLoader> loaders = Application.get().getResourceSettings().getStringResourceLoaders();
    for (IStringResourceLoader loader : loaders) {
        String string = loader.loadStringResource(klass, key, locale, Session.get().getStyle(), null);
        if (StringUtils.isNotBlank(string)) {
            return string;
        }
    }
    return null;
}

From source file:com.norconex.commons.wicket.ThreadContextMocker.java

License:Apache License

/**
 * Invoke the constructor in the current wicket request.
 *//*from   ww w . j  av  a 2s.  c om*/
public ThreadContextMocker() {
    super();
    this.application = Application.get();
    this.session = Session.get();
}

From source file:com.norconex.commons.wicket.WicketClass.java

License:Apache License

public Application getApplication() {
    return Application.get();
}

From source file:com.premiumminds.webapp.wicket.bootstrap.BootstrapPaginator.java

License:Open Source License

/**
 * Creates a paginator/*from   w  ww  . j  av  a2 s  .  c o m*/
 * 
 * @param id component id
 * @param totalResults model for total results
 * @param resultsPerPage number of results per page
 */
@SuppressWarnings("serial")
public BootstrapPaginator(String id, IModel<Integer> totalResults, int resultsPerPage) {
    super(id, Model.of(0));
    stripTags = Application.get().getMarkupSettings().getStripWicketTags();
    setOutputMarkupId(true);

    this.totalResults = totalResults;
    this.numberResultsPerPage = resultsPerPage;

    add(new SquaresContainer("first") {
        @Override
        protected void onConfigure() {
            super.onConfigure();
            setEnabled(getModelObject() > 0);
            setVisible(showFirstButton && (!hiddenFirstButton || getThreshold() > 0));
        }
    }.add(new AjaxLink<Void>("link") {
        @Override
        public void onClick(AjaxRequestTarget target) {
            BootstrapPaginator.this.setModelObject(0);
            target.add(BootstrapPaginator.this);
            onPageChange(target, BootstrapPaginator.this.getModel());
        }

    }));
    add(new SquaresContainer("previous") {
        @Override
        protected void onConfigure() {
            super.onConfigure();
            setEnabled(BootstrapPaginator.this.getModelObject() > 0);
            setVisible(showPreviousButton
                    && (!hiddenPreviousButton || BootstrapPaginator.this.getModelObject() > 0));
        }
    }.add(new AjaxLink<Void>("link") {
        @Override
        public void onClick(AjaxRequestTarget target) {
            BootstrapPaginator.this.setModelObject(BootstrapPaginator.this.getModelObject() - 1);
            target.add(BootstrapPaginator.this);
            onPageChange(target, BootstrapPaginator.this.getModel());
        }

    }));
    add(new SquaresContainer("next") {
        @Override
        protected void onConfigure() {
            super.onConfigure();
            setEnabled(BootstrapPaginator.this.getModelObject() < getTotalPages() - 1);
            setVisible(showNextButton
                    && (!hiddenNextButton || BootstrapPaginator.this.getModelObject() < (getTotalPages() - 1)));
        }
    }.add(new AjaxLink<Void>("link") {
        @Override
        public void onClick(AjaxRequestTarget target) {
            BootstrapPaginator.this.setModelObject(BootstrapPaginator.this.getModelObject() + 1);
            target.add(BootstrapPaginator.this);
            onPageChange(target, BootstrapPaginator.this.getModel());
        }

    }));
    add(new SquaresContainer("last") {
        @Override
        protected void onConfigure() {
            super.onConfigure();
            setEnabled(BootstrapPaginator.this.getModelObject() < getTotalPages() - 1);
            setVisible(
                    showLastButton && (!hiddenLastButton || getThreshold() < (getTotalPages() - pagesToShow)));
        }
    }.add(new AjaxLink<Void>("link") {
        @Override
        public void onClick(AjaxRequestTarget target) {
            BootstrapPaginator.this.setModelObject(getTotalPages() - 1);
            target.add(BootstrapPaginator.this);
            onPageChange(target, BootstrapPaginator.this.getModel());
        }

    }));
    add(new WebMarkupContainer("previousPages") {
        @Override
        protected void onConfigure() {
            super.onConfigure();
            setVisible(showMorePagesInformation && getThreshold() > 0);
        }
    });
    add(new WebMarkupContainer("nextPages") {
        @Override
        protected void onConfigure() {
            super.onConfigure();
            setVisible(showMorePagesInformation && getThreshold() < (getTotalPages() - pagesToShow));
        }
    });

    IModel<Integer> pages = new LoadableDetachableModel<Integer>() {
        @Override
        protected Integer load() {
            return Math.min(getTotalPages(), pagesToShow);
        }
    };

    add(new Loop("page", pages) {

        @Override
        protected void populateItem(final LoopItem item) {
            final int threshold = getThreshold();
            item.add(AttributeModifier.append("class", new LoadableDetachableModel<String>() {

                @Override
                protected String load() {
                    return item.getIndex() + getThreshold() == BootstrapPaginator.this.getModelObject()
                            ? "active"
                            : "";
                }
            }));
            item.add(new AjaxLink<Void>("link") {

                @Override
                protected void onConfigure() {
                    super.onConfigure();
                };

                @Override
                public void onClick(AjaxRequestTarget target) {
                    BootstrapPaginator.this.setModelObject(item.getIndex() + threshold);
                    target.add(BootstrapPaginator.this);
                    onPageChange(target, BootstrapPaginator.this.getModel());
                }
            }.add(new Label("label", new LoadableDetachableModel<Integer>() {

                @Override
                protected Integer load() {
                    return item.getIndex() + threshold + 1;
                }
            })));
        }
    });
}

From source file:com.premiumminds.webapp.wicket.bootstrap.BootstrapPaginator.java

License:Open Source License

@Override
protected void onRender() {
    Application.get().getMarkupSettings().setStripWicketTags(true);
    super.onRender();
}

From source file:com.premiumminds.webapp.wicket.bootstrap.BootstrapPaginator.java

License:Open Source License

@Override
protected void onAfterRenderChildren() {
    super.onAfterRenderChildren();
    Application.get().getMarkupSettings().setStripWicketTags(stripTags);
}

From source file:com.pushinginertia.wicket.core.ResourceModelUtils.java

License:Open Source License

/**
 * Get the localized string using all of the supplied parameters. This method is left public to
 * allow developers full control over string resource loading. However, it is recommended that
 * one of the other convenience methods in the class are used as they handle all of the work
 * related to obtaining the current user locale and style information.
 *
 * @param resourceKey//from   ww  w . j ava  2 s .  co  m
 *            The key to obtain the resource for
 * @return The string resource
 * @throws java.util.MissingResourceException
 *             If resource not found and configuration dictates that exception should be thrown
 */
public static String getString(String resourceKey) {
    return Application.get().getResourceSettings().getLocalizer().getString(resourceKey, (Component) null);
}