List of usage examples for org.apache.wicket.ajax AjaxRequestTarget addChildren
void addChildren(MarkupContainer parent, Class<?> childCriteria);
childCriteria
From source file:com.chitek.ignition.drivers.generictcp.meta.config.ui.MessageConfigUI.java
License:Apache License
private DropDownChoice<Integer> getCurrentMessageIdDropdown() { IChoiceRenderer<Integer> messageConfigRender = new IChoiceRenderer<Integer>() { @Override/*from w w w. j a v a2 s .c o m*/ public Object getDisplayValue(Integer object) { return String.format("%d - %s", object, getConfig().getMessageConfig(object).getMessageAlias()); } @Override public String getIdValue(Integer object, int index) { return object.toString(); } }; IModel<List<Integer>> messageListModel = new LoadableDetachableModel<List<Integer>>() { @Override protected List<Integer> load() { List<MessageConfig> messages = getConfig().getMessageList(); List<Integer> list = new ArrayList<Integer>(messages.size()); for (MessageConfig messageConfig : messages) { list.add(messageConfig.getMessageId()); } return list; } }; DropDownChoice<Integer> dropDown = new DropDownChoice<Integer>("currentMessage", new PropertyModel<Integer>(this, "currentMessageId"), messageListModel, messageConfigRender); dropDown.add(new AjaxFormSubmitBehavior("onchange") { @Override protected void onSubmit(final AjaxRequestTarget target) { // Reset feedback messages target.addChildren(getPage(), FeedbackPanel.class); // Change the current message currentMessage = getConfig().getMessageConfig(currentMessageId); currentMessage.calcOffsets(getConfig().getMessageIdType().getByteSize()); // Refresh the form updateForm(target); } @Override protected void onError(final AjaxRequestTarget target) { // Add the drop down to revert the changed selection target.add(getComponent()); handleError(target); }; }); dropDown.add(new AjaxIndicatorAppender()); dropDown.setOutputMarkupId(true); return dropDown; }
From source file:com.chitek.ignition.drivers.generictcp.meta.config.ui.MessageConfigUI.java
License:Apache License
private DropDownChoice<MessageType> getMessageTypeDropdown() { DropDownChoice<MessageType> dropDown = new DropDownChoice<MessageType>("messageType", MessageType.getOptions(), new EnumChoiceRenderer<MessageType>(this)); dropDown.setOutputMarkupId(true);//from w w w . j av a2 s .com // When the MessageType is changed, the tag length type dropdowns are updated dropDown.add(new AjaxFormComponentUpdatingBehavior("onchange") { @Override protected void onUpdate(AjaxRequestTarget target) { updateTagLength(target); // Reset feedback messages target.addChildren(getPage(), FeedbackPanel.class); } }); return dropDown; }
From source file:com.chitek.ignition.drivers.generictcp.meta.config.ui.MessageConfigUI.java
License:Apache License
private DropDownChoice<OptionalDataType> getMessageIdTypeDropdown() { DropDownChoice<OptionalDataType> dropDown = new DropDownChoice<OptionalDataType>("messageIdType", new PropertyModel<OptionalDataType>(getDefaultModel(), "messageIdType"), OptionalDataType.getOptions(), new EnumChoiceRenderer<OptionalDataType>(this)); // When the MessageId Type is changed, the offsets are recalculated and displayed dropDown.add(new AjaxFormComponentUpdatingBehavior("onchange") { @Override//from w w w. j a va 2 s .c o m protected void onUpdate(AjaxRequestTarget target) { updateOffsets(target); // Reset feedback messages target.addChildren(getPage(), FeedbackPanel.class); } }); return dropDown; }
From source file:com.chitek.ignition.drivers.generictcp.meta.config.ui.MessageConfigUI.java
License:Apache License
private TextField<Integer> getMessageIdTextField() { TextField<Integer> textField = new FeedbackTextField<Integer>("messageId"); textField.setRequired(true);//from w w w . ja v a 2s . c om CompoundValidator<Integer> validator = new CompoundValidator<Integer>(); validator.add(new RangeValidator<Integer>(0, 65535)); validator.add(new UniqueMessageIdValidator()); textField.add(validator); textField.setOutputMarkupId(true); textField.add(new AjaxFormComponentUpdatingBehavior("onchange") { @Override protected void onUpdate(AjaxRequestTarget target) { // The id is the key for the message map, so we have to replace it here getConfig().messages.remove(currentMessageId); getConfig().addMessageConfig(currentMessage); currentMessageId = currentMessage.getMessageId(); target.add(currentMessageIdDropdown); // Clear feedback messages target.addChildren(getPage(), FeedbackPanel.class); target.add(getComponent()); } @Override protected void onError(AjaxRequestTarget target, RuntimeException e) { target.addChildren(getPage(), FeedbackPanel.class); target.add(getComponent()); } }); return textField; }
From source file:com.chitek.ignition.drivers.generictcp.meta.config.ui.MessageConfigUI.java
License:Apache License
private TextField<String> getMessageAliasTextField() { TextField<String> textField = new FeedbackTextField<String>("messageAlias"); textField.setRequired(true);/*from w w w . j av a 2 s. co m*/ CompoundValidator<String> validator = new CompoundValidator<String>(); validator.add(new PatternValidator("[A-Za-z0-9_]+")); validator.add(StringValidator.lengthBetween(1, 32)); validator.add(new UniqueMessageAliasValidator()); textField.add(validator); textField.setLabel(labelAlias); // Use the same label as the items textField.setOutputMarkupId(true); textField.add(new AjaxFormComponentUpdatingBehavior("onchange") { @Override protected void onUpdate(AjaxRequestTarget target) { target.add(currentMessageIdDropdown); target.addChildren(getPage(), FeedbackPanel.class); target.add(getComponent()); } @Override protected void onError(AjaxRequestTarget target, RuntimeException e) { target.addChildren(getPage(), FeedbackPanel.class); target.add(getComponent()); } }); return textField; }
From source file:com.chitek.ignition.drivers.generictcp.meta.config.ui.MessageConfigUI.java
License:Apache License
/** * Common handler for errors during an Ajax submit */// w w w . ja v a 2 s . com private void handleError(final AjaxRequestTarget target) { // Update feedback panel and components with errors target.addChildren(getPage(), FeedbackPanel.class); target.getPage().visitChildren(FormComponent.class, new IVisitor<Component, Void>() { @Override public void component(Component component, IVisit<Void> arg1) { if (component.hasErrorMessage()) { target.add(component); } } }); }
From source file:com.chitek.ignition.drivers.generictcp.meta.config.ui.MessageConfigUI.java
License:Apache License
/** * Button 'New' - Create a new message/* w w w . j av a 2s .c o m*/ */ private void handleNew(AjaxRequestTarget target) { // Increment message ID int newMessageId = getNextMessageId(currentMessageId); // Add the new message currentMessage = new MessageConfig(newMessageId); getConfig().addMessageConfig(currentMessage); currentMessageId = newMessageId; // Show feedback messages info(new StringResourceModel("info.new", this, null, newMessageId).getString()); target.addChildren(getPage(), FeedbackPanel.class); doValidation(); currentMessageIdDropdown.detachModels(); // This is necessary to refresh the drop down updateForm(target); }
From source file:com.chitek.ignition.drivers.generictcp.meta.config.ui.MessageConfigUI.java
License:Apache License
/** * Button 'Copy' - Copy the current message *//*from w ww.j a va 2 s .c o m*/ private void handleCopy(AjaxRequestTarget target) { // Increment message ID int newMessageId = getNextMessageId(currentMessageId); // Copy and add the new message MessageConfig current = currentMessage; currentMessage = current.copy(); currentMessage.setMessageId(newMessageId); currentMessage.setMessageAlias(""); getConfig().addMessageConfig(currentMessage); currentMessageId = newMessageId; // Show feedback messages info(new StringResourceModel("info.copy", this, null, newMessageId).getString()); target.addChildren(getPage(), FeedbackPanel.class); doValidation(); currentMessageIdDropdown.detachModels(); // This is necessary to refresh the drop down updateForm(target); }
From source file:com.chitek.ignition.drivers.generictcp.meta.config.ui.MessageConfigUI.java
License:Apache License
/** * Button 'Delete' (Ajax). Delete the current message. *///from w ww. ja v a 2 s.c om private void handleDelete(AjaxRequestTarget target) { getConfig().messages.remove(currentMessageId); // Show feedback messages info(new StringResourceModel("info.deleted", this, null, currentMessageId).getString()); target.addChildren(getPage(), FeedbackPanel.class); if (getConfig().messages.isEmpty()) { // No message left. Create a new message with id=1. getConfig().addMessageConfig(new MessageConfig(1)); } // Select the first configured message for initial display currentMessage = getConfig().getMessageList().get(0); currentMessageId = currentMessage.messageId; // Refresh the drop down choice target.add(currentMessageIdDropdown); doValidation(); updateForm(target); }
From source file:de.tudarmstadt.ukp.clarin.webanno.brat.annotation.BratAnnotator.java
License:Apache License
public BratAnnotator(String id, IModel<BratAnnotatorModel> aModel, final AnnotationDetailEditorPanel aEditor) { super(id, aModel); this.editor = aEditor; // Allow AJAX updates. setOutputMarkupId(true);/*ww w . j a va 2 s . co m*/ // The annotator is invisible when no document has been selected. Make sure that we can // make it visible via AJAX once the document has been selected. setOutputMarkupPlaceholderTag(true); if (getModelObject().getDocument() != null) { collection = "#" + getModelObject().getProject().getName() + "/"; } vis = new WebMarkupContainer("vis"); vis.setOutputMarkupId(true); controller = new AbstractDefaultAjaxBehavior() { private static final long serialVersionUID = 1L; @Override protected void respond(AjaxRequestTarget aTarget) { final IRequestParameters request = getRequest().getPostParameters(); aTarget.addChildren(getPage(), FeedbackPanel.class); // Parse annotation ID if present in request VID paramId; if (!request.getParameterValue(PARAM_ID).isEmpty() && !request.getParameterValue(PARAM_ARC_ID).isEmpty()) { throw new IllegalStateException("[id] and [arcId] cannot be both set at the same time!"); } else if (!request.getParameterValue(PARAM_ID).isEmpty()) { paramId = VID.parseOptional(request.getParameterValue(PARAM_ID).toString()); } else { paramId = VID.parseOptional(request.getParameterValue(PARAM_ARC_ID).toString()); } // Ignore ghosts if (paramId.isGhost()) { error("This is a ghost annotation, select layer and feature to annotate."); return; } // Get action String action = request.getParameterValue(PARAM_ACTION).toString(); // Load the CAS if necessary boolean requiresCasLoading = action.equals(SpanAnnotationResponse.COMMAND) || action.equals(ArcAnnotationResponse.COMMAND) || action.equals(GetDocumentResponse.COMMAND); JCas jCas = null; if (requiresCasLoading) { // Make sure we load the CAS only once here in case of an annotation action. try { jCas = getCas(getModelObject()); } catch (ClassNotFoundException e) { error("Invalid reader: " + e.getMessage()); } catch (IOException e) { error(e.getMessage()); } catch (UIMAException e) { error(ExceptionUtils.getRootCauseMessage(e)); } } // HACK: If an arc was clicked that represents a link feature, then open the // associated span annotation instead. if (paramId.isSlotSet() && action.equals(ArcAnnotationResponse.COMMAND)) { action = SpanAnnotationResponse.COMMAND; paramId = new VID(paramId.getId()); } BratAjaxCasController controller = new BratAjaxCasController(repository, annotationService); // Doing anything but a span annotation when a slot is armed will unarm it if (getModelObject().isSlotArmed() && !action.equals(SpanAnnotationResponse.COMMAND)) { getModelObject().clearArmedSlot(); } Object result = null; try { LOG.info("AJAX-RPC CALLED: [" + action + "]"); if (action.equals(WhoamiResponse.COMMAND)) { result = controller.whoami(); } else if (action.equals(SpanAnnotationResponse.COMMAND)) { assert jCas != null; // do not annotate closed documents if (editor.isAnnotationFinished()) { error("This document is already closed. Please ask your project manager to re-open it via the Montoring page"); LOG.error( "This document is already closed. Please ask your project manager to re-open it via the Montoring page"); return; } if (getModelObject().isSlotArmed()) { if (paramId.isSet()) { // Fill slot with existing annotation editor.setSlot(aTarget, jCas, getModelObject(), paramId.getId()); } else if (!CAS.TYPE_NAME_ANNOTATION .equals(getModelObject().getArmedFeature().getType())) { // Fill slot with new annotation (only works if a concrete type is // set for the link feature! SpanAdapter adapter = (SpanAdapter) getAdapter(annotationService, annotationService.getLayer(getModelObject().getArmedFeature().getType(), getModelObject().getProject())); Offsets offsets = getSpanOffsets(request, jCas, paramId); try { int id = adapter.add(jCas, offsets.getBegin(), offsets.getEnd(), null, null); editor.setSlot(aTarget, jCas, getModelObject(), id); } catch (BratAnnotationException e) { error(ExceptionUtils.getRootCauseMessage(e)); LOG.error(ExceptionUtils.getRootCauseMessage(e), e); } } else { throw new BratAnnotationException( "Unable to create annotation of type [" + CAS.TYPE_NAME_ANNOTATION + "]. Please click an annotation in stead of selecting new text."); } } else { /*if (paramId.isSet()) { getModelObject().setForwardAnnotation(false); }*/ // Doing anything but filling an armed slot will unarm it editor.clearArmedSlotModel(); getModelObject().clearArmedSlot(); Selection selection = getModelObject().getSelection(); selection.setRelationAnno(false); Offsets offsets = getSpanOffsets(request, jCas, paramId); selection.setAnnotation(paramId); selection.set(jCas, offsets.getBegin(), offsets.getEnd()); bratRenderHighlight(aTarget, selection.getAnnotation()); editor.reloadLayer(aTarget); if (selection.getAnnotation().isNotSet()) { selection.setAnnotate(true); editor.actionAnnotate(aTarget, getModelObject(), false); } else { selection.setAnnotate(false); bratRender(aTarget, jCas); result = new SpanAnnotationResponse(); } } } else if (action.equals(ArcAnnotationResponse.COMMAND)) { assert jCas != null; // do not annotate closed documents if (editor.isAnnotationFinished()) { error("This document is already closed. Please ask your project manager to re-open it via the Montoring page"); LOG.error( "This document is already closed. Please ask your project manager to re-open it via the Montoring page"); return; } Selection selection = getModelObject().getSelection(); selection.setRelationAnno(true); selection.setAnnotation(paramId); selection.setOriginType(request.getParameterValue(PARAM_ORIGIN_TYPE).toString()); selection.setOrigin(request.getParameterValue(PARAM_ORIGIN_SPAN_ID).toInteger()); selection.setTargetType(request.getParameterValue(PARAM_TARGET_TYPE).toString()); selection.setTarget(request.getParameterValue(PARAM_TARGET_SPAN_ID).toInteger()); bratRenderHighlight(aTarget, getModelObject().getSelection().getAnnotation()); editor.reloadLayer(aTarget); if (getModelObject().getSelection().getAnnotation().isNotSet()) { selection.setAnnotate(true); editor.actionAnnotate(aTarget, getModelObject(), false); } else { selection.setAnnotate(false); bratRender(aTarget, jCas); result = new ArcAnnotationResponse(); } } else if (action.equals(LoadConfResponse.COMMAND)) { result = controller.loadConf(); } else if (action.equals(GetCollectionInformationResponse.COMMAND)) { if (getModelObject().getProject() != null) { result = controller.getCollectionInformation(getModelObject().getAnnotationLayers()); } else { result = new GetCollectionInformationResponse(); } } else if (action.equals(GetDocumentResponse.COMMAND)) { if (getModelObject().getProject() != null) { result = controller.getDocumentResponse(getModelObject(), 0, jCas, true); } else { result = new GetDocumentResponse(); } } LOG.info("AJAX-RPC DONE: [" + action + "]"); } catch (ClassNotFoundException e) { LOG.error("Invalid reader: " + e.getMessage(), e); error("Invalid reader: " + e.getMessage()); } catch (Exception e) { error("Unexpected error: " + e.getMessage()); LOG.error(ExceptionUtils.getRootCauseMessage(e)); } // Serialize updated document to JSON if (result == null) { LOG.warn("AJAX-RPC: Action [" + action + "] produced no result!"); } else { String json = toJson(result); // Since we cannot pass the JSON directly to Brat, we attach it to the HTML // element into which BRAT renders the SVG. In our modified ajax.js, we pick it // up from there and then pass it on to BRAT to do the rendering. aTarget.prependJavaScript("Wicket.$('" + vis.getMarkupId() + "').temp = " + json + ";"); } aTarget.addChildren(getPage(), FeedbackPanel.class); if (getModelObject().getSelection().getAnnotation().isNotSet()) { editor.setAnnotationLayers(getModelObject()); } editor.reload(aTarget); if (BratAnnotatorUtility.isDocumentFinished(repository, getModelObject())) { error("This document is already closed. Please ask your project " + "manager to re-open it via the Montoring page"); } } }; add(vis); add(controller); }