Search in sources :

Example 1 with AbstractTextComponent

use of org.apache.wicket.markup.html.form.AbstractTextComponent in project webanno by webanno.

the class TextFeatureEditor method createFieldComboBox.

private AbstractTextComponent createFieldComboBox() {
    AbstractTextComponent field;
    if (getModelObject().feature.getTagset() != null) {
        field = new StyledComboBox<Tag>("value", PropertyModel.of(getModel(), "tagset")) {

            private static final long serialVersionUID = -1735694425658462932L;

            @Override
            protected void onInitialize() {
                super.onInitialize();
                // Ensure proper order of the initializing JS header items: first combo box
                // behavior (in super.onInitialize()), then tooltip.
                Options options = new Options(DescriptionTooltipBehavior.makeTooltipOptions());
                options.set("content", FUNCTION_FOR_TOOLTIP);
                add(new TooltipBehavior("#" + getMarkupId() + "_listbox *[title]", options) {

                    private static final long serialVersionUID = 1854141593969780149L;

                    @Override
                    protected String $() {
                        // with a slight delay hoping that all is set up after 1 second.
                        return "try {setTimeout(function () { " + super.$() + " }, 1000); } catch (err) {}; ";
                    }
                });
            }

            @Override
            protected void onConfigure() {
                super.onConfigure();
                // Trigger a re-loading of the tagset from the server as constraints may have
                // changed the ordering
                AjaxRequestTarget target = RequestCycle.get().find(AjaxRequestTarget.class);
                if (target != null) {
                    LOG.trace("onInitialize() requesting datasource re-reading");
                    target.appendJavaScript(String.format("var $w = %s; if ($w) { $w.dataSource.read(); }", KendoUIBehavior.widget(this, ComboBoxBehavior.METHOD)));
                }
            }
        };
    } else {
        field = new TextField<String>("value");
    }
    // Ensure that markup IDs of feature editor focus components remain constant across
    // refreshes of the feature editor panel. This is required to restore the focus.
    field.setOutputMarkupId(true);
    field.setMarkupId(ID_PREFIX + getModelObject().feature.getId());
    return field;
}
Also used : AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) Options(com.googlecode.wicket.jquery.core.Options) TooltipBehavior(com.googlecode.wicket.jquery.ui.widget.tooltip.TooltipBehavior) DescriptionTooltipBehavior(de.tudarmstadt.ukp.clarin.webanno.support.DescriptionTooltipBehavior) Tag(de.tudarmstadt.ukp.clarin.webanno.model.Tag) AbstractTextComponent(org.apache.wicket.markup.html.form.AbstractTextComponent)

Aggregations

Options (com.googlecode.wicket.jquery.core.Options)1 TooltipBehavior (com.googlecode.wicket.jquery.ui.widget.tooltip.TooltipBehavior)1 Tag (de.tudarmstadt.ukp.clarin.webanno.model.Tag)1 DescriptionTooltipBehavior (de.tudarmstadt.ukp.clarin.webanno.support.DescriptionTooltipBehavior)1 AjaxRequestTarget (org.apache.wicket.ajax.AjaxRequestTarget)1 AbstractTextComponent (org.apache.wicket.markup.html.form.AbstractTextComponent)1