List of usage examples for org.apache.wicket.ajax AjaxRequestTarget focusComponent
void focusComponent(Component component);
From source file:org.hippoecm.frontend.plugins.console.menu.property.PropertyDialog.java
License:Apache License
public PropertyDialog(IModelReference<Node> modelReference) { this.modelReference = modelReference; final IModel<Node> model = modelReference.getModel(); getParent().add(CssClass.append("property-dialog")); // list defined properties for automatic completion choiceModel = new LoadableDetachableModel<Map<String, List<PropertyDefinition>>>() { protected Map<String, List<PropertyDefinition>> load() { Map<String, List<PropertyDefinition>> choices = new HashMap<>(); Node node = model.getObject(); try { NodeType pnt = node.getPrimaryNodeType(); for (PropertyDefinition pd : pnt.getPropertyDefinitions()) { List<PropertyDefinition> list = choices.get(pd.getName()); if (list == null) { list = new ArrayList<>(5); }/*from w w w. j a v a 2 s .c o m*/ list.add(pd); choices.put(pd.getName(), list); } for (NodeType nt : node.getMixinNodeTypes()) { for (PropertyDefinition pd : nt.getPropertyDefinitions()) { List<PropertyDefinition> list = choices.get(pd.getName()); if (list == null) { list = new ArrayList<>(5); } list.add(pd); choices.put(pd.getName(), list); } } // remove already set properties from suggestions: final Set<String> properties = new HashSet<>(choices.keySet()); for (String property : properties) { if (!isResidual(property) && node.hasProperty(property)) { choices.remove(property); } } } catch (RepositoryException e) { log.warn("Unable to populate autocomplete list for property names", e); } return choices; } }; // checkbox for property ismultiple final CheckBox checkBox = new CheckBox("isMultiple", new Model<Boolean>() { @Override public void setObject(Boolean multiple) { PropertyDialog.this.isMultiple = multiple; } @Override public Boolean getObject() { if (PropertyDialog.this.name != null) { List<PropertyDefinition> propdefs = choiceModel.getObject().get(PropertyDialog.this.name); if (propdefs != null) { for (PropertyDefinition pd : propdefs) { if (PropertyType.nameFromValue(pd.getRequiredType()).equals(type)) { // somehow need to set isMultiple here, otherwise it doesn't get picked up... PropertyDialog.this.isMultiple = pd.isMultiple(); return pd.isMultiple(); } } } } return PropertyDialog.this.isMultiple; } }); checkBox.setOutputMarkupId(true); add(checkBox); // dropdown for property type final DropDownChoice<String> ddChoice = new DropDownChoice<String>("types") { @Override public List<? extends String> getChoices() { if (PropertyDialog.this.name != null) { List<PropertyDefinition> propdefs = choiceModel.getObject().get(PropertyDialog.this.name); if (propdefs != null) { List<String> result = new ArrayList<>(propdefs.size()); for (PropertyDefinition pd : propdefs) { result.add(PropertyType.nameFromValue(pd.getRequiredType())); } return result; } } return ALL_TYPES; } }; ddChoice.setModel(new Model<String>() { @Override public void setObject(String object) { type = object; } @Override public String getObject() { List<? extends String> choices = ddChoice.getChoices(); if (choices.size() == 1) { type = choices.iterator().next(); } return type; } }); ddChoice.setRequired(true); ddChoice.setOutputMarkupId(true); ddChoice.add(new AjaxFormComponentUpdatingBehavior("onchange") { @Override protected void onUpdate(AjaxRequestTarget target) { } }); add(ddChoice); values = new LinkedList<>(); values.add(""); final WebMarkupContainer valuesContainer = new WebMarkupContainer("valuesContainer"); valuesContainer.setOutputMarkupId(true); add(valuesContainer); valuesContainer.add(new ListView<String>("values", values) { @Override protected void populateItem(final ListItem<String> item) { final TextField textField = new TextField<>("val", item.getModel()); textField.add(new OnChangeAjaxBehavior() { @Override protected void onUpdate(final AjaxRequestTarget target) { } }); item.add(textField); if (focusOnLatestValue && item.getIndex() == (values.size() - 1)) { AjaxRequestTarget ajax = RequestCycle.get().find(AjaxRequestTarget.class); if (ajax != null) { ajax.focusComponent(textField); } focusOnLatestValue = false; } final AjaxLink deleteLink = new AjaxLink("removeLink") { @Override public void onClick(final AjaxRequestTarget target) { values.remove(item.getIndex()); target.add(valuesContainer); } @Override public boolean isVisible() { return super.isVisible() && item.getIndex() > 0; } }; deleteLink.add(TitleAttribute.set(getString("property.value.remove"))); deleteLink.add(new InputBehavior(new KeyType[] { KeyType.Enter }, EventType.click) { @Override protected String getTarget() { return "'" + deleteLink.getMarkupId() + "'"; } }); item.add(deleteLink); } }); final AjaxLink addLink = new AjaxLink("addLink") { @Override public void onClick(final AjaxRequestTarget target) { values.add(""); target.add(valuesContainer); focusOnLatestValue = true; } @Override public boolean isVisible() { return isMultiple; } }; addLink.add(TitleAttribute.set(getString("property.value.add"))); addLink.add(new InputBehavior(new KeyType[] { KeyType.Enter }, EventType.click) { @Override protected String getTarget() { return "'" + addLink.getMarkupId() + "'"; } }); valuesContainer.add(addLink); checkBox.add(new AjaxFormComponentUpdatingBehavior("onchange") { @Override protected void onUpdate(AjaxRequestTarget target) { target.add(valuesContainer); if (!isMultiple && values.size() > 1) { String first = values.get(0); values.clear(); values.add(first); } } }); // text field for property name AutoCompleteSettings settings = new AutoCompleteSettings(); settings.setAdjustInputWidth(false); settings.setUseSmartPositioning(true); settings.setShowCompleteListOnFocusGain(true); settings.setShowListOnEmptyInput(true); // Setting a max height will trigger a correct recalculation of the height when the list of items is filtered settings.setMaxHeightInPx(400); final TextField<String> nameField = new AutoCompleteTextFieldWidget<String>("name", PropertyModel.of(this, "name"), settings) { @Override protected Iterator<String> getChoices(String input) { List<String> result = new ArrayList<>(); for (String propName : choiceModel.getObject().keySet()) { if (propName.contains(input)) { result.add(propName); } } return result.iterator(); } @Override protected void onUpdate(final AjaxRequestTarget target) { super.onUpdate(target); target.add(ddChoice); target.add(checkBox); target.add(valuesContainer); focusOnLatestValue = true; } }; nameField.setRequired(true); add(nameField); setFocus(nameField); }
From source file:org.hippoecm.frontend.widgets.NameUriField.java
License:Apache License
private Component createUrlAction() { final AjaxLink<Boolean> uriAction = new AjaxLink<Boolean>("uriAction") { @Override/* www.java2 s . c o m*/ public void onClick(final AjaxRequestTarget target) { urlIsEditable = !urlIsEditable; urlComponent.modelChanging(); urlModel.setObject(getName()); urlComponent.modelChanged(); final Form<?> form = urlComponent.getForm(); if (form.hasFeedbackMessage()) { form.getFeedbackMessages().clear(); } if (!urlComponent.isValid()) { urlComponent.validate(); } target.add(this); target.add(urlComponent); target.focusComponent(urlIsEditable ? urlComponent : nameComponent); } }; uriAction.add(new Label("uriActionLabel", ReadOnlyModel.of(() -> getString(urlIsEditable ? "url-reset" : "url-edit")))); return uriAction; }
From source file:org.hippoecm.frontend.widgets.NameUriField.java
License:Apache License
@Override protected void onBeforeRender() { final AjaxRequestTarget target = RequestCycle.get().find(AjaxRequestTarget.class); if (target != null) { target.focusComponent(nameComponent); }// w ww . j ava 2 s . c o m super.onBeforeRender(); }
From source file:org.obiba.onyx.quartz.core.wicket.layout.impl.standard.DefaultPageLayout.java
License:Open Source License
/** * Set the focus to the first input of the first question. * @param target/*from ww w. j av a2 s . c om*/ */ private void setFocus(final AjaxRequestTarget target) { if (target == null) return; // must do that after rendering, otherwise there is nothing populated in the views. target.addListener(new AjaxRequestTarget.IListener() { public void onAfterRespond(Map<String, Component> map, IJavascriptResponse response) { DefaultPageLayout.this.visitChildren(new IVisitor<Component>() { public Object component(Component component) { if (component instanceof Radio || component instanceof CheckBox || component instanceof DropDownChoice<?>) { target.focusComponent(component); return STOP_TRAVERSAL; } return null; } }); } public void onBeforeRespond(Map<String, Component> map, AjaxRequestTarget target1) { } }); }
From source file:org.obiba.onyx.wicket.action.ActionDefinitionPanel.java
License:Open Source License
public ActionDefinitionPanel(String id, ActionDefinition definition, AjaxRequestTarget target) { super(id);//from w w w . jav a 2 s . c om Action action = new Action(definition); setDefaultModel(new Model<Action>(action)); add(feedback = new FeedbackWindow("feedback")); feedback.setOutputMarkupId(true); add(new Label("operator", userSessionService.getUserName())); // password field User operatorTemplate = new User(); PasswordTextField password = new PasswordTextField("password", new PropertyModel<String>(operatorTemplate, "password")); password.setRequired(definition.isAskPassword()); password.add(new IValidator<String>() { public void validate(IValidatable<String> validatable) { if (userSessionService.authenticate(validatable.getValue()) == false) { validatable.error(new UserValidationError()); } } }); add(password.setEnabled(definition.isAskPassword())); // participant barcode field Participant participantTemplate = new Participant(); TextField<String> barcode = new TextField<String>("ParticipantCode", new PropertyModel<String>(participantTemplate, "barcode")); barcode.setRequired(definition.isAskParticipantId()); barcode.add(new IValidator<String>() { public void validate(IValidatable<String> validatable) { if (!activeInterviewService.getParticipant().getBarcode().equals(validatable.getValue())) { validatable.error(new ParticipantValidationError()); } } }); add(barcode.setEnabled(definition.isAskParticipantId())); Object commentNoteKey = new PropertyModel<Object>(definition, "commentNote").getObject(); String defaultNote = new StringResourceModel("AnonymousComments", this, null).getString(); Label commentNoteLabel = new Label("commentNote", new SpringStringResourceModel(commentNoteKey != null ? commentNoteKey.toString() : "", defaultNote) .getString()); add(commentNoteLabel.setEnabled(definition.isAskComment())); TextArea<String> commentArea = new TextArea<String>("comment", new PropertyModel<String>(this, "action.comment")); commentArea.setRequired(definition.isAskComment() && definition.isCommentMandatory()); commentArea.add(new StringValidator.MaximumLengthValidator(2000)); add(commentArea.setEnabled(definition.isAskComment())); // request for focus on first field if (password.isEnabled()) { password.setOutputMarkupId(true); target.focusComponent(password); } else if (barcode.isEnabled()) { barcode.setOutputMarkupId(true); target.focusComponent(barcode); } else if (commentArea.isEnabled()) { commentArea.setOutputMarkupId(true); target.focusComponent(commentArea); } action.setEventReason(definition.getDefaultReason()); DropDownChoice<String> reasonsDropDown = new DropDownChoice<String>("reasonsSelect", new PropertyModel<String>(ActionDefinitionPanel.this, "action.eventReason"), definition.getReasons(), new IChoiceRenderer<String>() { public Object getDisplayValue(String object) { return new SpringStringResourceModel(object).getString(); } public String getIdValue(String object, int index) { return object; } }); reasonsDropDown.setLabel(new ResourceModel("Reason")); reasonsDropDown.setRequired(definition.isReasonMandatory()); reasonsDropDown.setEnabled(definition.getReasons().size() > 0); add(reasonsDropDown); }
From source file:org.obiba.onyx.wicket.data.DataField.java
License:Open Source License
/** * Focus request on the inner input field. * @param target/*from ww w .java 2 s . com*/ */ public void focusField(AjaxRequestTarget target) { target.focusComponent(input.getField()); }
From source file:org.onehippo.forge.settings.management.config.formdata.FormdataConfigPanel.java
License:Apache License
private void addExclusionPaths(FormdataConfig formdataConfig) { final WebMarkupContainer listContainer = new WebMarkupContainer("excludedPathsView"); //generate a markup-id so the contents can be updated through an AJAX call listContainer.setOutputMarkupId(true); // Don't do this in a listview final ListView<String> excludedPathsView; excludedPathsView = new ListView<String>("formdata-excludedPaths", new PropertyModel(formdataConfig, "excludepaths")) { private static final long serialVersionUID = 1L; @Override//from w w w .j a va 2s. co m protected void populateItem(final ListItem<String> item) { RequiredTextField extensionField = new RequiredTextField("formdata-path", item.getModel()); extensionField.setOutputMarkupId(true); item.add(extensionField); AjaxSubmitLink remove = new AjaxSubmitLink("remove") { private static final long serialVersionUID = 1L; @Override protected void onSubmit(AjaxRequestTarget target, Form form) { getModelObject().remove(item.getModelObject()); target.add(listContainer); } }; remove.setDefaultFormProcessing(false); item.add(remove); } }; AjaxLink addExtension = new AjaxLink("add-path") { private static final long serialVersionUID = 1L; @Override public void onClick(AjaxRequestTarget target) { excludedPathsView.getModelObject().add(""); target.add(listContainer); target.focusComponent(this); } }; excludedPathsView.setReuseItems(true); listContainer.add(excludedPathsView); listContainer.add(addExtension); add(listContainer); }
From source file:org.onehippo.forge.settings.management.config.social.SocialMediaConfigPanel.java
License:Apache License
public SocialMediaConfigPanel(IPluginContext context, IPluginConfig config) { super(context, config, new ResourceModel("title")); socialMediaServiceConfigModel = new SocialMediaServiceConfigModel(); final WebMarkupContainer listContainer = new WebMarkupContainer("servicesView"); listContainer.setOutputMarkupId(true); final SocialMediaServiceListView socialservicesView = new SocialMediaServiceListView("socialservices", socialMediaServiceConfigModel.getObject().getServices()); AjaxLink addService = new AjaxLink("add-service") { private static final long serialVersionUID = 1L; @Override//from w w w . j a va 2s .com public void onClick(AjaxRequestTarget target) { final SocialMediaService newService = socialMediaServiceConfigModel.getObject() .addService("unknown"); if (newService != null) { socialservicesView.getModelObject().add(newService); } target.add(listContainer); target.focusComponent(this); } }; listContainer.add(socialservicesView); listContainer.add(addService); add(listContainer); }
From source file:org.onehippo.forge.settings.management.config.upload.AssetValidationServiceConfigPanel.java
License:Apache License
private void addAllowedExtensionsField(AssetValidationServiceConfig assetValidationServiceConfig) { final WebMarkupContainer listContainer = new WebMarkupContainer("allowedExtensionsView"); //generate a markup-id so the contents can be updated through an AJAX call listContainer.setOutputMarkupId(true); // Don't do this in a listview final ListView<String> allowedExtensionsView; allowedExtensionsView = new ListView<String>("assetvalidation-allowedExtensions", new PropertyModel(assetValidationServiceConfig, "allowedExtensions")) { private static final long serialVersionUID = 1L; @Override/* ww w .ja v a2 s . c o m*/ protected void populateItem(final ListItem<String> item) { RequiredTextField extensionField = new RequiredTextField("asset-extension", item.getModel()); extensionField.setOutputMarkupId(true); item.add(extensionField); AjaxSubmitLink remove = new AjaxSubmitLink("remove") { private static final long serialVersionUID = 1L; @Override protected void onSubmit(AjaxRequestTarget target, Form form) { getModelObject().remove(item.getModelObject()); target.add(listContainer); } }; remove.setDefaultFormProcessing(false); item.add(remove); } }; AjaxLink addExtension = new AjaxLink("add-extension") { private static final long serialVersionUID = 1L; @Override public void onClick(AjaxRequestTarget target) { allowedExtensionsView.getModelObject().add(""); target.add(listContainer); target.focusComponent(this); } }; allowedExtensionsView.setReuseItems(true); listContainer.add(allowedExtensionsView); listContainer.add(addExtension); add(listContainer); }
From source file:org.onehippo.forge.settings.management.config.upload.ImageValidationServiceConfigPanel.java
License:Apache License
private void addAllowedExtensionsField(ImageValidationServiceConfig imageValidationServiceConfig) { final WebMarkupContainer listContainer = new WebMarkupContainer("allowedExtensionsView"); //generate a markup-id so the contents can be updated through an AJAX call listContainer.setOutputMarkupId(true); // Don't do this in a listview final ListView<String> allowedExtensionsView; allowedExtensionsView = new ListView<String>("imagevalidation-allowedExtensions", new PropertyModel(imageValidationServiceConfig, "allowedExtensions")) { private static final long serialVersionUID = 1L; @Override// www.j a va 2 s. c om protected void populateItem(final ListItem<String> item) { RequiredTextField extensionField = new RequiredTextField("image-extension", item.getModel()); extensionField.setOutputMarkupId(true); item.add(extensionField); AjaxSubmitLink remove = new AjaxSubmitLink("remove") { private static final long serialVersionUID = 1L; @Override protected void onSubmit(AjaxRequestTarget target, Form form) { getModelObject().remove(item.getModelObject()); target.add(listContainer); } }; remove.setDefaultFormProcessing(false); item.add(remove); } }; AjaxLink addExtension = new AjaxLink("add-extension") { private static final long serialVersionUID = 1L; @Override public void onClick(AjaxRequestTarget target) { allowedExtensionsView.getModelObject().add(""); target.add(listContainer); target.focusComponent(this); } }; allowedExtensionsView.setReuseItems(true); listContainer.add(allowedExtensionsView); listContainer.add(addExtension); add(listContainer); }