Java Code Examples for org.apache.wicket.markup.html.form.DropDownChoice#setModel()

The following examples show how to use org.apache.wicket.markup.html.form.DropDownChoice#setModel() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ActiveLearningSidebar.java    From inception with Apache License 2.0 6 votes vote down vote up
private Form<Void> createSessionControlForm()
{
    Form<Void> form = new Form<>(CID_SESSION_CONTROL_FORM);

    DropDownChoice<AnnotationLayer> layersDropdown = new BootstrapSelect<>(CID_SELECT_LAYER);
    layersDropdown.setModel(alStateModel.bind("layer"));
    layersDropdown.setChoices(LoadableDetachableModel.of(this::listLayersWithRecommenders));
    layersDropdown.setChoiceRenderer(new LambdaChoiceRenderer<>(AnnotationLayer::getUiName));
    layersDropdown.add(LambdaBehavior.onConfigure(it -> it.setEnabled(!alStateModel
        .getObject().isSessionActive())));
    layersDropdown.setOutputMarkupId(true);
    layersDropdown.setRequired(true);
    form.add(layersDropdown);
    
    form.add(new LambdaAjaxSubmitLink(CID_START_SESSION_BUTTON, this::actionStartSession)
            .add(visibleWhen(() -> !alStateModel.getObject().isSessionActive())));
    form.add(new LambdaAjaxLink(CID_STOP_SESSION_BUTTON, this::actionStopSession)
        .add(visibleWhen(() -> alStateModel.getObject().isSessionActive())));
    form.add(visibleWhen(() -> alStateModel.getObject().isDoExistRecommenders()));

    return form;
}
 
Example 2
Source File: StatementGroupPanel.java    From inception with Apache License 2.0 6 votes vote down vote up
public NewStatementGroupFragment(String aId) {
    super(aId, "newStatementGroup", StatementGroupPanel.this, groupModel);
                
    IModel<KBProperty> property = Model.of();
    
    Form<KBProperty> form = new Form<>("form", property);
    DropDownChoice<KBProperty> type = new BootstrapSelect<>("property");
    type.setModel(property);
    type.setChoiceRenderer(new ChoiceRenderer<>("uiLabel"));            
    type.setChoices(getUnusedProperties());
    type.setRequired(true);
    type.setOutputMarkupId(true);
    form.add(type);
    focusComponent = type;
    
    form.add(new LambdaAjaxButton<>("create", this::actionNewProperty));
    form.add(new LambdaAjaxLink("cancel", this::actionCancelNewProperty));
    add(form);
}
 
Example 3
Source File: DocumentMetadataAnnotationSelectionPanel.java    From inception with Apache License 2.0 5 votes vote down vote up
public DocumentMetadataAnnotationSelectionPanel(String aId, IModel<Project> aProject,
        IModel<SourceDocument> aDocument, IModel<String> aUsername,
        CasProvider aCasProvider, AnnotationPage aAnnotationPage,
        AnnotationActionHandler aActionHandler, AnnotatorState aState)
{
    super(aId, aProject);

    setOutputMarkupPlaceholderTag(true);
    
    annotationPage = aAnnotationPage;
    sourceDocument = aDocument;
    username = aUsername;
    jcasProvider = aCasProvider;
    project = aProject;
    selectedLayer = Model.of();
    actionHandler = aActionHandler;
    state = aState;

    annotationsContainer = new WebMarkupContainer(CID_ANNOTATIONS_CONTAINER);
    annotationsContainer.setOutputMarkupId(true);
    annotationsContainer.add(createAnnotationList());
    add(annotationsContainer);
    
    DropDownChoice<AnnotationLayer> layer = new BootstrapSelect<>(CID_LAYER);
    layer.setModel(selectedLayer);
    layer.setChoices(this::listMetadataLayers);
    layer.setChoiceRenderer(new ChoiceRenderer<>("uiName"));
    layer.add(new LambdaAjaxFormComponentUpdatingBehavior("change"));
    add(layer);
    
    add(new LambdaAjaxLink(CID_CREATE, this::actionCreate));
}
 
Example 4
Source File: ImportDocumentsPanel.java    From webanno with Apache License 2.0 5 votes vote down vote up
public ImportDocumentsPanel(String aId, IModel<Project> aProject)
{
    super(aId);

    projectModel = aProject;
    
    Form<Void> form = new Form<>("form");
    add(form);
    
    format = Model.of();
    List<String> readableFormats = listReadableFormats();
    if (!readableFormats.isEmpty()) {
        if (readableFormats.contains("Plain text")) {
            format.setObject("Plain text");
        }
        else {
            format.setObject(readableFormats.get(0));
        }
    }
    
    form.add(fileUpload = new BootstrapFileInputField("documents"));
    fileUpload.getConfig().showPreview(false);
    fileUpload.getConfig().showUpload(false);
    fileUpload.getConfig().showRemove(false);
    fileUpload.setRequired(true);

    DropDownChoice<String> formats = new BootstrapSelect<>("format");
    formats.setModel(format);
    formats.setChoices(LambdaModel.of(this::listReadableFormats));
    form.add(formats);
    
    form.add(new LambdaAjaxButton<>("import", this::actionImport));
}
 
Example 5
Source File: KnowledgeBasePanel.java    From inception with Apache License 2.0 4 votes vote down vote up
public KnowledgeBasePanel(String id, IModel<Project> aProjectModel,
        IModel<KnowledgeBase> aKbModel)
{
    super(id, aKbModel);

    setOutputMarkupId(true);

    kbModel = aKbModel;
    
    // add the selector for the knowledge bases
    DropDownChoice<KnowledgeBase> ddc = new BootstrapSelect<KnowledgeBase>("knowledgebases",
            LoadableDetachableModel
                    .of(() -> kbService.getEnabledKnowledgeBases(aProjectModel.getObject())));
    
    ddc.add(new LambdaAjaxFormComponentUpdatingBehavior("change", t -> {
        long projectId = aProjectModel.getObject().getId();
        String kbName = aKbModel.getObject().getName();

        PageParameters params = new PageParameters()
            .set(PAGE_PARAM_PROJECT_ID, projectId)
            .set(PAGE_PARAM_KB_NAME, kbName);

        setResponsePage(KnowledgeBasePage.class, params);
    }));

    ddc.setModel(aKbModel);
    ddc.setChoiceRenderer(new ChoiceRenderer<>("name"));
    add(ddc);

    add(createSearchField("searchBar", searchHandleModel, aProjectModel));

    add(conceptTreePanel = new ConceptTreePanel("concepts", kbModel, selectedConceptHandle));
    add(propertyListPanel = new PropertyListPanel("properties", kbModel,
            selectedPropertyHandle));
    
    detailContainer = new WebMarkupContainer(DETAIL_CONTAINER_MARKUP_ID);
    detailContainer.setOutputMarkupId(true);
    add(detailContainer);
    
    details = new EmptyPanel(DETAILS_MARKUP_ID);
    detailContainer.add(details);
}
 
Example 6
Source File: LinkFeatureTraitsEditor.java    From webanno with Apache License 2.0 4 votes vote down vote up
public LinkFeatureTraitsEditor(String aId, SlotFeatureSupport aFS,
        IModel<AnnotationFeature> aFeatureModel)
{
    super(aId, aFeatureModel);
    
    // We cannot retain a reference to the actual SlotFeatureSupport instance because that
    // is not serializable, but we can retain its ID and look it up again from the registry
    // when required.
    featureSupportId = aFS.getId();
    feature = aFeatureModel;
    
    traits = Model.of(readTraits());
    
    Form<Traits> form = new Form<Traits>(MID_FORM, CompoundPropertyModel.of(traits))
    {
        private static final long serialVersionUID = -3109239605783291123L;

        @Override
        protected void onSubmit()
        {
            super.onSubmit();
            // when saving reset the selected tagset if role labels are not enabled
            if (!traits.getObject().isEnableRoleLabels()) {
                feature.getObject().setTagset(null);
            }
            writeTraits();
        }
    };
    form.setOutputMarkupPlaceholderTag(true);
    add(form);
    
    MultiSelect<Tag> defaultSlots  = new MultiSelect<Tag>("defaultSlots") {
        private static final long serialVersionUID = 8231304829756188352L;
        
        @Override
        public void onConfigure(JQueryBehavior aBehavior)
        {
            super.onConfigure(aBehavior);
            //aBehavior.setOption("placeholder", Options.asString(getString("placeholder")));
            aBehavior.setOption("filter", Options.asString("contains"));
            aBehavior.setOption("autoClose", false);
        }
    };
    defaultSlots.setChoices(LambdaModel.of(this::listTags));
    defaultSlots.setChoiceRenderer(new ChoiceRenderer<>("name"));
    defaultSlots.add(visibleWhen(() -> traits.getObject().isEnableRoleLabels()
            && feature.getObject().getTagset() != null));
    form.add(defaultSlots);

    CheckBox enableRoleLabels = new CheckBox("enableRoleLabels");
    enableRoleLabels.setModel(PropertyModel.of(traits, "enableRoleLabels"));
    enableRoleLabels.add(new LambdaAjaxFormComponentUpdatingBehavior("change", 
        target -> target.add(form)
    ));
    form.add(enableRoleLabels);
    
    DropDownChoice<TagSet> tagset = new BootstrapSelect<>("tagset");
    tagset.setOutputMarkupPlaceholderTag(true);
    tagset.setOutputMarkupId(true);
    tagset.setChoiceRenderer(new ChoiceRenderer<>("name"));
    tagset.setNullValid(true);
    tagset.setModel(PropertyModel.of(aFeatureModel, "tagset"));
    tagset.setChoices(LambdaModel.of(() -> annotationService
            .listTagSets(aFeatureModel.getObject().getProject())));
    tagset.add(new LambdaAjaxFormComponentUpdatingBehavior("change", target -> {
        traits.getObject().setDefaultSlots(new ArrayList<>());
        target.add(form);
    }));
    tagset.add(visibleWhen(() -> traits.getObject().isEnableRoleLabels()));
    form.add(tagset);
}
 
Example 7
Source File: StringFeatureTraitsEditor.java    From webanno with Apache License 2.0 4 votes vote down vote up
public StringFeatureTraitsEditor(String aId,
        UimaPrimitiveFeatureSupport_ImplBase<StringFeatureTraits> aFS,
        IModel<AnnotationFeature> aFeature)
{
    super(aId, aFeature);

    // We cannot retain a reference to the actual SlotFeatureSupport instance because that
    // is not serializable, but we can retain its ID and look it up again from the registry
    // when required.
    featureSupportId = aFS.getId();
    feature = aFeature;

    traits = CompoundPropertyModel.of(getFeatureSupport().readTraits(feature.getObject()));

    keyBindings = newKeyBindingsConfigurationPanel(aFeature);
    add(keyBindings);

    Form<StringFeatureTraits> form = new Form<StringFeatureTraits>(MID_FORM, traits)
    {
        private static final long serialVersionUID = -3109239605783291123L;

        @Override
        protected void onSubmit()
        {
            super.onSubmit();

            // Tagsets only are allowed for single-row input fields, not for textareas
            if (traits.getObject().isMultipleRows()) {
                feature.getObject().setTagset(null);
            } else {
                traits.getObject().setDynamicSize(false);
            }

            getFeatureSupport().writeTraits(feature.getObject(), traits.getObject());
        }
    };
    form.setOutputMarkupPlaceholderTag(true);
    add(form);

    NumberTextField<Integer> collapsedRows = new NumberTextField<>("collapsedRows",
            Integer.class);
    collapsedRows.setModel(PropertyModel.of(traits, "collapsedRows"));
    collapsedRows.setMinimum(1);
    collapsedRows.add(visibleWhen(() -> traits.getObject().isMultipleRows()
            && !traits.getObject().isDynamicSize()));
    form.add(collapsedRows);

    NumberTextField<Integer> expandedRows = new NumberTextField<>("expandedRows",
            Integer.class);
    expandedRows.setModel(PropertyModel.of(traits, "expandedRows"));
    expandedRows.setMinimum(1);
    expandedRows.add(visibleWhen(() -> traits.getObject().isMultipleRows() 
            && !traits.getObject().isDynamicSize()));
    form.add(expandedRows);

    DropDownChoice<TagSet> tagset = new BootstrapSelect<>("tagset");
    tagset.setOutputMarkupPlaceholderTag(true);
    tagset.setChoiceRenderer(new ChoiceRenderer<>("name"));
    tagset.setNullValid(true);
    tagset.setModel(PropertyModel.of(aFeature, "tagset"));
    tagset.setChoices(LoadableDetachableModel
            .of(() -> annotationService.listTagSets(aFeature.getObject().getProject())));
    tagset.add(visibleWhen(() -> !traits.getObject().isMultipleRows()));
    // If we change the tagset, the input component for the key bindings may change, so we need
    // to re-generate the key bindings
    tagset.add(new LambdaAjaxFormComponentUpdatingBehavior("change", _target -> {
        KeyBindingsConfigurationPanel newKeyBindings = newKeyBindingsConfigurationPanel(
                aFeature);
        keyBindings.replaceWith(newKeyBindings);
        keyBindings = newKeyBindings;
        _target.add(keyBindings);
    }));
    form.add(tagset);

    CheckBox multipleRows = new CheckBox("multipleRows");
    multipleRows.setModel(PropertyModel.of(traits, "multipleRows"));
    multipleRows.add(
            new LambdaAjaxFormComponentUpdatingBehavior("change", target -> target.add(form)));
    form.add(multipleRows);

    CheckBox dynamicSize = new CheckBox("dynamicSize");
    dynamicSize.setModel(PropertyModel.of(traits, "dynamicSize"));
    dynamicSize.add(new LambdaAjaxFormComponentUpdatingBehavior("change",
        target -> target.add(form)
    ));
    dynamicSize.add(visibleWhen(() -> traits.getObject().isMultipleRows()));
    form.add(dynamicSize);
}
 
Example 8
Source File: AnnotationPreferencesDialogContent.java    From webanno with Apache License 2.0 4 votes vote down vote up
private ListView<AnnotationLayer> createLayerContainer()
{
    return new ListView<AnnotationLayer>("annotationLayers")
    {
        private static final long serialVersionUID = -4040731191748923013L;

        @Override
        protected void populateItem(ListItem<AnnotationLayer> aItem)
        {
            Preferences prefs = form.getModelObject();
            AnnotationLayer layer = aItem.getModelObject();
            Set<Long> hiddenLayerIds = stateModel.getObject().getPreferences()
                    .getHiddenAnnotationLayerIds();
            
            // add visibility checkbox
            CheckBox layerVisible = new CheckBox("annotationLayerActive",
                    Model.of(!hiddenLayerIds.contains(layer.getId())));

            layerVisible.add(new LambdaAjaxFormComponentUpdatingBehavior("change", _target -> {
                if (!layerVisible.getModelObject()) {
                    hiddenLayerIds.add(layer.getId());
                }
                else {
                    hiddenLayerIds.remove(layer.getId());
                }
            }));
            aItem.add(layerVisible);

            // add coloring strategy choice
            DropDownChoice<ColoringStrategyType> layerColor = new BootstrapSelect<>(
                    "layercoloring");
            layerColor.setModel(Model.of(prefs.colorPerLayer.get(layer.getId())));
            layerColor.setChoiceRenderer(new ChoiceRenderer<>("descriptiveName"));
            layerColor.setChoices(asList(ColoringStrategyType.values()));
            layerColor.add(new LambdaAjaxFormComponentUpdatingBehavior("change", _target ->
                    prefs.colorPerLayer.put(layer.getId(), layerColor.getModelObject())));
            aItem.add(layerColor);

            // add label
            aItem.add(new Label("annotationLayerDesc", layer.getUiName()));
        }
    };
}