Search in sources :

Example 1 with IFeedbackMessageFilter

use of org.apache.wicket.feedback.IFeedbackMessageFilter in project ocvn by devgateway.

the class FileInputBootstrapFormComponentWrapper method addFileUploadFeedbackComponent.

private void addFileUploadFeedbackComponent() {
    fileUploadFeedback.setOutputMarkupId(true);
    // show only the messages (fatal, success) generated by this component
    fileUploadFeedback.setFilter(new IFeedbackMessageFilter() {

        private static final long serialVersionUID = 1L;

        @Override
        public boolean accept(final FeedbackMessage message) {
            final Component reporter = message.getReporter();
            // for example errors like 'FIELD is required.'
            if (message.getLevel() == FeedbackMessage.ERROR) {
                return false;
            }
            return reporter != null && (FileInputBootstrapFormComponentWrapper.this.contains(reporter, true) || Objects.equal(FileInputBootstrapFormComponentWrapper.this, reporter));
        }
    });
    add(fileUploadFeedback);
}
Also used : IFeedbackMessageFilter(org.apache.wicket.feedback.IFeedbackMessageFilter) FeedbackMessage(org.apache.wicket.feedback.FeedbackMessage) FormComponent(org.apache.wicket.markup.html.form.FormComponent) Component(org.apache.wicket.Component)

Example 2 with IFeedbackMessageFilter

use of org.apache.wicket.feedback.IFeedbackMessageFilter in project wicket by apache.

the class BaseWicketTester method cleanupFeedbackMessages.

/**
 * Cleans up feedback messages given the specified filter.
 *
 * @param filter
 *            filter used to cleanup messages, accepted messages will be removed
 */
protected void cleanupFeedbackMessages(IFeedbackMessageFilter filter) {
    ApplicationSettings applicationSettings = application.getApplicationSettings();
    IFeedbackMessageFilter old = applicationSettings.getFeedbackMessageCleanupFilter();
    applicationSettings.setFeedbackMessageCleanupFilter(filter);
    getLastRenderedPage().detach();
    getSession().detach();
    applicationSettings.setFeedbackMessageCleanupFilter(old);
}
Also used : ApplicationSettings(org.apache.wicket.settings.ApplicationSettings) IFeedbackMessageFilter(org.apache.wicket.feedback.IFeedbackMessageFilter)

Example 3 with IFeedbackMessageFilter

use of org.apache.wicket.feedback.IFeedbackMessageFilter in project webanno by webanno.

the class ApplicationPageBase method commonInit.

private void commonInit() {
    Properties settings = SettingsUtil.getSettings();
    // Override locale to be used by application
    String locale = settings.getProperty(SettingsUtil.CFG_LOCALE, "en");
    switch(locale) {
        case "auto":
            // Do nothing - locale is picked up from browser
            break;
        default:
            // Override the locale in the session
            getSession().setLocale(Locale.forLanguageTag(locale));
            break;
    }
    // Add menubar
    try {
        Class<? extends Component> menubarClass = getApplication().getMetaData(MENUBAR_CLASS);
        if (menubarClass == null) {
            menubarClass = MenuBar.class;
        }
        add(ConstructorUtils.invokeConstructor(menubarClass, "menubar"));
    } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException | InstantiationException e1) {
        throw new RuntimeException(e1);
    }
    feedbackPanel = new BootstrapFeedbackPanel("feedbackPanel");
    feedbackPanel.setOutputMarkupId(true);
    feedbackPanel.setFilter((IFeedbackMessageFilter) aMessage -> {
        Authentication auth = SecurityContextHolder.getContext().getAuthentication();
        String username = auth != null ? auth.getName() : "SYSTEM";
        if (aMessage.isFatal()) {
            LOG.error("{}: {}", username, aMessage.getMessage());
        } else if (aMessage.isError()) {
            LOG.error("{}: {}", username, aMessage.getMessage());
        } else if (aMessage.isWarning()) {
            LOG.warn("{}: {}", username, aMessage.getMessage());
        } else if (aMessage.isInfo()) {
            LOG.info("{}: {}", username, aMessage.getMessage());
        } else if (aMessage.isDebug()) {
            LOG.debug("{}: {}", username, aMessage.getMessage());
        }
        return true;
    });
    add(feedbackPanel);
    versionLabel = new Label("version", SettingsUtil.getVersionString());
    add(versionLabel);
    // set up warnings shown when using an embedded DB or some unsupported browser
    boolean isBrowserWarningVisible = isBrowserWarningVisible(settings);
    boolean isDatabaseWarningVisible = isDatabaseWarningVisible(settings);
    embeddedDbWarning = new Label("embeddedDbWarning", new ResourceModel("warning.database"));
    embeddedDbWarning.setVisible(isDatabaseWarningVisible);
    add(embeddedDbWarning);
    browserWarning = new Label("browserWarning", new ResourceModel("warning.browser"));
    browserWarning.setVisible(isBrowserWarningVisible);
    add(browserWarning);
    WebMarkupContainer warningsContainer = new WebMarkupContainer("warnings");
    warningsContainer.setVisible(isBrowserWarningVisible || isDatabaseWarningVisible);
    add(warningsContainer);
}
Also used : RuntimeConfigurationType(org.apache.wicket.RuntimeConfigurationType) SettingsUtil(de.tudarmstadt.ukp.clarin.webanno.support.SettingsUtil) SpringBean(org.apache.wicket.spring.injection.annot.SpringBean) LoggerFactory(org.slf4j.LoggerFactory) IFeedbackMessageFilter(org.apache.wicket.feedback.IFeedbackMessageFilter) StringUtils(org.apache.commons.lang3.StringUtils) RequestCycle(org.apache.wicket.request.cycle.RequestCycle) DatabaseDriverService(de.tudarmstadt.ukp.clarin.webanno.support.db.DatabaseDriverService) PageParameters(org.apache.wicket.request.mapper.parameter.PageParameters) Locale(java.util.Locale) FeedbackPanel(org.apache.wicket.markup.html.panel.FeedbackPanel) NoOpResourceCachingStrategy(org.apache.wicket.request.resource.caching.NoOpResourceCachingStrategy) BootstrapFeedbackPanel(de.tudarmstadt.ukp.clarin.webanno.support.bootstrap.BootstrapFeedbackPanel) ClientProperties(org.apache.wicket.protocol.http.ClientProperties) SecurityContextHolder(org.springframework.security.core.context.SecurityContextHolder) Label(org.apache.wicket.markup.html.basic.Label) Properties(java.util.Properties) Logger(org.slf4j.Logger) Component(org.apache.wicket.Component) WebClientInfo(org.apache.wicket.protocol.http.request.WebClientInfo) WebSession(org.apache.wicket.protocol.http.WebSession) InvocationTargetException(java.lang.reflect.InvocationTargetException) WebMarkupContainer(org.apache.wicket.markup.html.WebMarkupContainer) Session(org.apache.wicket.Session) MetaDataKey(org.apache.wicket.MetaDataKey) ConstructorUtils(org.apache.commons.lang3.reflect.ConstructorUtils) WebPage(org.apache.wicket.markup.html.WebPage) ResourceModel(org.apache.wicket.model.ResourceModel) Authentication(org.springframework.security.core.Authentication) Label(org.apache.wicket.markup.html.basic.Label) ClientProperties(org.apache.wicket.protocol.http.ClientProperties) Properties(java.util.Properties) BootstrapFeedbackPanel(de.tudarmstadt.ukp.clarin.webanno.support.bootstrap.BootstrapFeedbackPanel) InvocationTargetException(java.lang.reflect.InvocationTargetException) WebMarkupContainer(org.apache.wicket.markup.html.WebMarkupContainer) Authentication(org.springframework.security.core.Authentication) ResourceModel(org.apache.wicket.model.ResourceModel)

Example 4 with IFeedbackMessageFilter

use of org.apache.wicket.feedback.IFeedbackMessageFilter in project oc-explorer by devgateway.

the class FileInputBootstrapFormComponentWrapper method addFileUploadFeedbackComponent.

private void addFileUploadFeedbackComponent() {
    fileUploadFeedback.setOutputMarkupId(true);
    // show only the messages (fatal, success) generated by this component
    fileUploadFeedback.setFilter(new IFeedbackMessageFilter() {

        private static final long serialVersionUID = 1L;

        @Override
        public boolean accept(final FeedbackMessage message) {
            final Component reporter = message.getReporter();
            // for example errors like 'FIELD is required.'
            if (message.getLevel() == FeedbackMessage.ERROR) {
                return false;
            }
            return reporter != null && (FileInputBootstrapFormComponentWrapper.this.contains(reporter, true) || Objects.equal(FileInputBootstrapFormComponentWrapper.this, reporter));
        }
    });
    add(fileUploadFeedback);
}
Also used : IFeedbackMessageFilter(org.apache.wicket.feedback.IFeedbackMessageFilter) FeedbackMessage(org.apache.wicket.feedback.FeedbackMessage) FormComponent(org.apache.wicket.markup.html.form.FormComponent) Component(org.apache.wicket.Component)

Aggregations

IFeedbackMessageFilter (org.apache.wicket.feedback.IFeedbackMessageFilter)4 Component (org.apache.wicket.Component)3 FeedbackMessage (org.apache.wicket.feedback.FeedbackMessage)2 FormComponent (org.apache.wicket.markup.html.form.FormComponent)2 SettingsUtil (de.tudarmstadt.ukp.clarin.webanno.support.SettingsUtil)1 BootstrapFeedbackPanel (de.tudarmstadt.ukp.clarin.webanno.support.bootstrap.BootstrapFeedbackPanel)1 DatabaseDriverService (de.tudarmstadt.ukp.clarin.webanno.support.db.DatabaseDriverService)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Locale (java.util.Locale)1 Properties (java.util.Properties)1 StringUtils (org.apache.commons.lang3.StringUtils)1 ConstructorUtils (org.apache.commons.lang3.reflect.ConstructorUtils)1 MetaDataKey (org.apache.wicket.MetaDataKey)1 RuntimeConfigurationType (org.apache.wicket.RuntimeConfigurationType)1 Session (org.apache.wicket.Session)1 WebMarkupContainer (org.apache.wicket.markup.html.WebMarkupContainer)1 WebPage (org.apache.wicket.markup.html.WebPage)1 Label (org.apache.wicket.markup.html.basic.Label)1 FeedbackPanel (org.apache.wicket.markup.html.panel.FeedbackPanel)1 ResourceModel (org.apache.wicket.model.ResourceModel)1