private AutoCompleteTextField<KBHandle> createAutoCompleteTextField() { AutoCompleteTextField<KBHandle> field = new AutoCompleteTextField<KBHandle>("value", LambdaModelAdapter.of(this::getSelectedKBItem, this::setSelectedKBItem), new TextRenderer<KBHandle>("uiLabel"), KBHandle.class) { private static final long serialVersionUID = 5683897252648514996L; @Override protected List<KBHandle> getChoices(String input) { return listInstances(actionHandler, input); } @Override public void onConfigure(JQueryBehavior behavior) { super.onConfigure(behavior); behavior.setOption("autoWidth", true); } @Override protected IJQueryTemplate newTemplate() { return KendoChoiceDescriptionScriptReference.template(); } }; return field; }
public static <T extends Serializable> LambdaModelAdapter<T> of( SerializableSupplier<T> aSupplier, SerializableConsumer<T> aConsumer) { return new LambdaModelAdapter<T>(aSupplier, aConsumer); }
private void setSelectedKBItem(KBHandle value, Item<LinkWithRoleModel> aItem, AnnotationFeature linkedAnnotationFeature) { if (aItem.getModelObject().targetAddr != -1) { try { JCas jCas = actionHandler.getEditorCas(); AnnotationFS selectedFS = WebAnnoCasUtil .selectByAddr(jCas, aItem.getModelObject().targetAddr); WebAnnoCasUtil.setFeature(selectedFS, linkedAnnotationFeature, value != null ? value.getIdentifier() : value); LOG.info("change the value"); qualifierModel.detach(); // Save the CAS. This must be done explicitly here since the KBItem dropdown // is not the focus-component of this editor. In fact, there could be multiple // KBItem dropdowns in this feature editor since we can have multilpe modifiers. // For focus-components, the AnnotationFeatureForm already handles adding the // saving behavior. actionHandler.actionCreateOrUpdate( RequestCycle.get().find(AjaxRequestTarget.class).get(), jCas); } catch (Exception e) { LOG.error("Error: " + e.getMessage(), e); error("Error: " + e.getMessage()); } } }
private void setSelectedKBItem(KBHandle value, Item<LinkWithRoleModel> aItem, AnnotationFeature linkedAnnotationFeature) { if (aItem.getModelObject().targetAddr != -1) { try { JCas jCas = actionHandler.getEditorCas(); AnnotationFS selectedFS = WebAnnoCasUtil .selectByAddr(jCas, aItem.getModelObject().targetAddr); WebAnnoCasUtil.setFeature(selectedFS, linkedAnnotationFeature, value != null ? value.getIdentifier() : value); LOG.info("change the value"); qualifierModel.detach(); // Save the CAS. This must be done explicitly here since the KBItem dropdown // is not the focus-component of this editor. In fact, there could be multiple // KBItem dropdowns in this feature editor since we can have multilpe modifiers. // For focus-components, the AnnotationFeatureForm already handles adding the // saving behavior. actionHandler.actionCreateOrUpdate( RequestCycle.get().find(AjaxRequestTarget.class).get(), jCas); } catch (Exception e) { LOG.error("Error: " + e.getMessage(), e); error("Error: " + e.getMessage()); } } }
private AutoCompleteTextField<KBHandle> createAutoCompleteTextField() { AutoCompleteTextField<KBHandle> field = new AutoCompleteTextField<KBHandle>("value", LambdaModelAdapter.of(this::getSelectedKBItem, this::setSelectedKBItem), new TextRenderer<KBHandle>("uiLabel"), KBHandle.class) { private static final long serialVersionUID = 5683897252648514996L; @Override protected List<KBHandle> getChoices(String input) { return listInstances(actionHandler, input); } @Override public void onConfigure(JQueryBehavior behavior) { super.onConfigure(behavior); behavior.setOption("autoWidth", true); } @Override protected IJQueryTemplate newTemplate() { return KendoChoiceDescriptionScriptReference.template(); } }; return field; }
public LambdaModelAdapter<T> build() { return new LambdaModelAdapter<T>(supplier, consumer); } }
public RecommendationSidebar(String aId, IModel<AnnotatorState> aModel, AnnotationActionHandler aActionHandler, JCasProvider aJCasProvider, AnnotationPage aAnnotationPage) { super(aId, aModel, aActionHandler, aJCasProvider, aAnnotationPage); IModel<Preferences> modelPreferences = LambdaModelAdapter.of( () -> recommendationService.getPreferences(aModel.getObject().getUser(), aModel.getObject().getProject()), (v) -> recommendationService.setPreferences(aModel.getObject().getUser(), aModel.getObject().getProject(), v)); Form<Preferences> form = new Form<>("form", CompoundPropertyModel.of(modelPreferences)); form.add(new NumberTextField<Integer>("maxPredictions", Integer.class) .setMinimum(1) .setMaximum(10) .setStep(1)); form.add(new CheckBox("showAllPredictions")); form.add(new LambdaAjaxButton<>("save", (_target, _form) -> aAnnotationPage.actionRefreshDocument(_target))); add(form); LearningCurveChartPanel chartContainer = new LearningCurveChartPanel(LEARNING_CURVE,aModel); chartContainer.setVisibilityAllowed(recommendationService.showLearningCurveDiagram()); add(chartContainer); } }
private ComboBox<String> languageComboBox(String id, IModel<String> aModel) { // Only set kbModel object if it has not been initialized yet if (aModel.getObject() == null) { aModel.setObject(languages.get(0)); } IModel<String> adapter = new LambdaModelAdapter<String>(aModel::getObject, aModel::setObject); ComboBox<String> comboBox = new ComboBox<String>(id, adapter, languages); comboBox.setOutputMarkupId(true); comboBox.setRequired(true); comboBox.add(new LambdaAjaxFormComponentUpdatingBehavior("change", t -> { // Do nothing just update the kbModel values })); return comboBox; }
}))); IModel<Pair<String, String>> typeModel = LambdaModelAdapter.of(() -> { return listTypes().stream() .filter(r -> r.getKey().equals(repositoryModel.getObject().getType()))
private ComboBox<String> languageComboBox(String id, IModel<String> aModel) { // Only set kbModel object if it has not been initialized yet if (aModel.getObject() == null) { aModel.setObject(languages.get(0)); } IModel<String> adapter = new LambdaModelAdapter<String>(aModel::getObject, aModel::setObject); ComboBox<String> comboBox = new ComboBox<String>(id, adapter, languages); comboBox.setOutputMarkupId(true); comboBox.setRequired(true); comboBox.add(new LambdaAjaxFormComponentUpdatingBehavior("change", t -> { // Do nothing just update the kbModel values })); return comboBox; }
}))); IModel<Pair<String, String>> typeModel = LambdaModelAdapter.of(() -> { return listTypes().stream() .filter(r -> r.getKey().equals(repositoryModel.getObject().getType()))
private ComboBox<String> buildComboBox(String id, IModel<IRI> model, List<IRI> iris) { // Only set model object if it has not been initialized yet if (model.getObject() == null) { model.setObject(iris.get(0)); } List<String> choices = iris.stream().map(IRI::stringValue).collect(Collectors.toList()); IModel<String> adapter = new LambdaModelAdapter<String>( () -> { return model.getObject() != null ? model.getObject().stringValue() : null; }, str -> { model.setObject(str != null ? SimpleValueFactory.getInstance().createIRI(str) : null); }); ComboBox<String> comboBox = new ComboBox<>(id, adapter, choices); comboBox.add(LambdaBehavior.enabledWhen(() -> SchemaProfile.CUSTOMSCHEMA.equals(selectedSchemaProfile.getObject()))); comboBox.setOutputMarkupId(true); comboBox.setRequired(true); comboBox.add(Validators.IRI_VALIDATOR); // Do nothing just update the model values comboBox.add(new LambdaAjaxFormComponentUpdatingBehavior("change")); return comboBox; }
LambdaModelAdapter.of(this::getKBHandleModel, this::setKBHandleModel), new TextRenderer<KBHandle>("uiLabel"), KBHandle.class)
private ComboBox<String> buildComboBox(String id, IModel<IRI> model, List<IRI> iris) { // Only set model object if it has not been initialized yet if (model.getObject() == null) { model.setObject(iris.get(0)); } List<String> choices = iris.stream().map(IRI::stringValue).collect(Collectors.toList()); IModel<String> adapter = new LambdaModelAdapter<String>( () -> { return model.getObject() != null ? model.getObject().stringValue() : null; }, str -> { model.setObject(str != null ? SimpleValueFactory.getInstance().createIRI(str) : null); }); ComboBox<String> comboBox = new ComboBox<>(id, adapter, choices); comboBox.add(LambdaBehavior.enabledWhen(() -> SchemaProfile.CUSTOMSCHEMA.equals(selectedSchemaProfile.getObject()))); comboBox.setOutputMarkupId(true); comboBox.setRequired(true); comboBox.add(Validators.IRI_VALIDATOR); // Do nothing just update the model values comboBox.add(new LambdaAjaxFormComponentUpdatingBehavior("change")); return comboBox; }
LambdaModelAdapter.of(this::getKBHandleModel, this::setKBHandleModel), new TextRenderer<KBHandle>("uiLabel"), KBHandle.class)
private TextField<String> buildTextField(String id, IModel<IRI> model) { IModel<String> adapter = new LambdaModelAdapter<String>( () -> model.getObject().stringValue(), str -> model.setObject(SimpleValueFactory.getInstance().createIRI(str))); TextField<String> iriTextfield = new TextField<>(id, adapter); iriTextfield.setOutputMarkupId(true); iriTextfield.add(new LambdaAjaxFormComponentUpdatingBehavior("change", t -> { // Do nothing just update the model values })); iriTextfield.setEnabled(false); return iriTextfield; }
.of(() -> aAnnotationPage.getMetaData(CURRENT_ES_USER_STATE), searchState -> aAnnotationPage.setMetaData(CURRENT_ES_USER_STATE, searchState)));
private TextField<String> buildTextField(String id, IModel<IRI> model) { IModel<String> adapter = new LambdaModelAdapter<String>( () -> model.getObject().stringValue(), str -> model.setObject(SimpleValueFactory.getInstance().createIRI(str))); TextField<String> iriTextfield = new TextField<>(id, adapter); iriTextfield.setOutputMarkupId(true); iriTextfield.add(new LambdaAjaxFormComponentUpdatingBehavior("change", t -> { // Do nothing just update the model values })); iriTextfield.setEnabled(false); return iriTextfield; }
layerTypes.setNullValid(false); layerTypes.setChoiceRenderer(new ChoiceRenderer<>("uiName")); layerTypes.setModel(LambdaModelAdapter.of( () -> layerSupportRegistry.getLayerType(LayerDetailForm.this.getModelObject()), (v) -> LayerDetailForm.this.getModelObject().setType(v.getName())));
levels.setLabelPosition(LabelPosition.WRAP_AFTER); levels.setModel(new LambdaModelAdapter<Collection<PermissionLevel>>(() -> { return projectRepository.getProjectPermissionLevels(user.getObject(), project.getObject());