Java Code Examples for org.apache.wicket.ajax.AjaxRequestTarget#addChildren()
The following examples show how to use
org.apache.wicket.ajax.AjaxRequestTarget#addChildren() .
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: LinkFeatureEditor.java From webanno with Apache License 2.0 | 6 votes |
private void actionAdd(AjaxRequestTarget aTarget) { if (StringUtils.isBlank((String) field.getModelObject()) && getTraits().isEnableRoleLabels()) { error("Must set slot label before adding!"); aTarget.addChildren(getPage(), IFeedback.class); } else { @SuppressWarnings("unchecked") List<LinkWithRoleModel> links = (List<LinkWithRoleModel>) LinkFeatureEditor.this .getModelObject().value; AnnotatorState state = LinkFeatureEditor.this.stateModel.getObject(); LinkWithRoleModel m = new LinkWithRoleModel(); m.role = (String) field.getModelObject(); links.add(m); state.setArmedSlot(getModelObject(), links.size() - 1); // Need to re-render the whole form because a slot in another // link editor might get unarmed aTarget.add(getOwner()); } }
Example 2
Source File: KnowledgeBaseDetailsPanel.java From inception with Apache License 2.0 | 6 votes |
private void actionReindex(AjaxRequestTarget aTarget) { aTarget.addChildren(getPage(), IFeedback.class); KnowledgeBase kb = kbwModel.getObject().getKb(); try { log.info("Starting rebuilding full-text index of {} ... this may take a while ...", kb); kbService.rebuildFullTextIndex(kb); log.info("Completed rebuilding full-text index of {}", kb); success("Completed rebuilding full-text index"); } catch (Exception e) { error("Unable to rebuild full text index: " + e.getLocalizedMessage()); log.error("Unable to rebuild full text index for KB [{}]({}) in project [{}]({})", kb.getName(), kb.getRepositoryId(), kb.getProject().getName(), kb.getProject().getId(), e); } }
Example 3
Source File: StatementEditor.java From inception with Apache License 2.0 | 6 votes |
private void actionSave(AjaxRequestTarget aTarget, Form<KBStatement> aForm) { KBStatement modifiedStatement = aForm.getModelObject(); try { String language = aForm.getModelObject().getLanguage() != null ? aForm.getModelObject().getLanguage() : kbModel.getObject().getDefaultLanguage(); modifiedStatement.setLanguage(language); // persist the modified statement and replace the original, unchanged model kbService.upsertStatement(kbModel.getObject(), modifiedStatement); statement.setObject(modifiedStatement); // switch back to ViewMode and send notification to listeners actionCancelExistingStatement(aTarget); send(getPage(), Broadcast.BREADTH, new AjaxStatementChangedEvent(aTarget, statement.getObject())); } catch (RepositoryException e) { error("Unable to update statement: " + e.getLocalizedMessage()); LOG.error("Unable to update statement.", e); aTarget.addChildren(getPage(), IFeedback.class); } }
Example 4
Source File: BratAnnotationEditor.java From webanno with Apache License 2.0 | 5 votes |
@Override protected void render(AjaxRequestTarget aTarget) { try { bratRenderCommand(getCasProvider().get()).ifPresent(cmd -> { StringBuilder js = new StringBuilder(); if (DEFERRED_RENDERING) { js.append("setTimeout(function() {"); } if (ENABLE_IN_BROWSER_PROFILING) { js.append("Util.profileEnable(true);"); js.append("Util.profileClear();"); } if (ENABLE_IN_BROWSER_TRACE) { js.append("console.log('Rendering (" + vis.getMarkupId() + ")...');"); } js.append(cmd); if (ENABLE_IN_BROWSER_PROFILING) { js.append("Util.profileReport();"); } if (DEFERRED_RENDERING) { js.append("}, 0);"); } aTarget.appendJavaScript(js); }); } catch (IOException e) { LOG.error("Unable to load data", e); error("Unable to load data: " + ExceptionUtils.getRootCauseMessage(e)); aTarget.addChildren(getPage(), IFeedback.class); } }
Example 5
Source File: AnnotationDetailEditorPanel.java From webanno with Apache License 2.0 | 5 votes |
@Override public void actionDelete(AjaxRequestTarget aTarget) throws IOException, AnnotationException { CAS cas = getEditorCas(); AnnotatorState state = getModelObject(); int addr = state.getSelection().getAnnotation().getId(); AnnotationFS fs = selectAnnotationByAddr(cas, addr); AnnotationLayer layer = annotationService.findLayer(state.getProject(), fs); TypeAdapter adapter = annotationService.getAdapter(layer); if (layer.isReadonly()) { error("Cannot delete an annotation on a read-only layer."); aTarget.addChildren(getPage(), IFeedback.class); return; } AttachStatus attachStatus = checkAttachStatus(aTarget, state.getProject(), fs); if (attachStatus.readOnlyAttached) { error("Cannot delete an annotation to which annotations on read-only layers attach."); aTarget.addChildren(getPage(), IFeedback.class); return; } if (adapter instanceof SpanAdapter && attachStatus.attachCount > 0) { deleteAnnotationDialog.setContentModel( new StringResourceModel("DeleteDialog.text", this, Model.of(layer)) .setParameters(attachStatus.attachCount)); deleteAnnotationDialog.setConfirmAction(_target -> doDelete(_target, layer, addr)); deleteAnnotationDialog.show(aTarget); return; } doDelete(aTarget, layer, addr); }
Example 6
Source File: AnnotationDetailEditorPanel.java From webanno with Apache License 2.0 | 5 votes |
@Override public void actionClear(AjaxRequestTarget aTarget) throws AnnotationException { reset(aTarget); aTarget.addChildren(getPage(), IFeedback.class); onChange(aTarget); }
Example 7
Source File: LayerDetailForm.java From webanno with Apache License 2.0 | 5 votes |
private void actionCancel(AjaxRequestTarget aTarget) { setModelObject(null); featureDetailForm.setModelObject(null); aTarget.add(getParent()); aTarget.addChildren(getPage(), IFeedback.class); }
Example 8
Source File: ProjectLayersPanel.java From webanno with Apache License 2.0 | 5 votes |
private void actionImport(AjaxRequestTarget aTarget, Form<String> aForm) { List<FileUpload> uploadedFiles = fileUpload.getFileUploads(); Project project = ProjectLayersPanel.this.getModelObject(); if (isEmpty(uploadedFiles)) { error("Please choose file with layer details before uploading"); return; } else if (isNull(project.getId())) { error("Project not yet created, please save project details!"); return; } for (FileUpload uploadedFile : uploadedFiles) { try (BufferedInputStream bis = IOUtils.buffer(uploadedFile.getInputStream())) { byte[] buf = new byte[5]; bis.mark(buf.length + 1); bis.read(buf, 0, buf.length); bis.reset(); // If the file starts with an XML preamble, then we assume it is an UIMA // type system file. if (Arrays.equals(buf, new byte[] { '<', '?', 'x', 'm', 'l' })) { importUimaTypeSystemFile(bis); } else { importLayerFile(bis); } } catch (Exception e) { error("Error importing layers: " + ExceptionUtils.getRootCauseMessage(e)); aTarget.addChildren(getPage(), IFeedback.class); LOG.error("Error importing layers", e); } } featureDetailForm.setVisible(false); aTarget.add(ProjectLayersPanel.this); }
Example 9
Source File: LambdaMenuItem.java From webanno with Apache License 2.0 | 5 votes |
@Override public void onClick(AjaxRequestTarget aTarget) { try { action.accept(aTarget); } catch (Exception e) { Page page = (Page) PageRequestHandlerTracker.getLastHandler(RequestCycle.get()) .getPage(); LoggerFactory.getLogger(page.getClass()).error("Error: " + e.getMessage(), e); page.error("Error: " + e.getMessage()); aTarget.addChildren(page, IFeedback.class); } }
Example 10
Source File: ColoringRulesConfigurationPanel.java From webanno with Apache License 2.0 | 5 votes |
private void addColoringRule(AjaxRequestTarget aTarget, Form<ColoringRule> aForm) { ColoringRule coloringRule = aForm.getModelObject(); if (isBlank(coloringRule.getColor())) { error("Color is required"); aTarget.addChildren(getPage(), IFeedback.class); return; } if (isBlank(coloringRule.getPattern())) { error("Pattern is required"); aTarget.addChildren(getPage(), IFeedback.class); return; } try { Pattern.compile(coloringRule.getPattern()); } catch (PatternSyntaxException e) { error("Pattern is not a valid regular expression: " + e.getMessage()); aTarget.addChildren(getPage(), IFeedback.class); return; } coloringRules.getObject().add(coloringRule); aForm.setModelObject(new ColoringRule()); success("Coloring rule added. Do not forget to save the layer details!"); aTarget.addChildren(getPage(), IFeedback.class); aTarget.add(coloringRulesContainer); }
Example 11
Source File: SearchAnnotationSidebar.java From inception with Apache License 2.0 | 5 votes |
private void actionSearch(AjaxRequestTarget aTarget, Form<SearchOptions> aForm) { selectedResult = null; searchResultGroups.setItemsPerPage(searchOptions.getObject().getItemsPerPage()); executeSearchResultsGroupedQuery(aTarget); aTarget.add(mainContainer); aTarget.addChildren(getPage(), IFeedback.class); }
Example 12
Source File: ExternalSearchAnnotationSidebar.java From inception with Apache License 2.0 | 5 votes |
private void actionOpen(AjaxRequestTarget aTarget, ExternalSearchResult aResult) { try { searchStateModel.getObject().setSelectedResult(aResult); getAnnotationPage().actionShowSelectedDocument(aTarget, documentService.getSourceDocument(project, aResult.getDocumentId())); } catch (Exception e) { LOG.error("Unable to load document {}: {}", aResult.getDocumentId(), e.getMessage(), e); error("Unable to load document " + aResult.getDocumentId() + ": " + ExceptionUtils.getRootCauseMessage(e)); aTarget.addChildren(getPage(), IFeedback.class); } }
Example 13
Source File: AnnotationPageBase.java From webanno with Apache License 2.0 | 5 votes |
protected void handleException(AjaxRequestTarget aTarget, Exception aException) { LoggerFactory.getLogger(getClass()).error("Error: " + aException.getMessage(), aException); error("Error: " + aException.getMessage()); if (aTarget != null) { aTarget.addChildren(getPage(), IFeedback.class); } }
Example 14
Source File: AnnotationPage.java From webanno with Apache License 2.0 | 4 votes |
protected void updateDocumentView(AjaxRequestTarget aTarget, SourceDocument aPreviousDocument, StringValue aFocusParameter) { SourceDocument currentDocument = getModelObject().getDocument(); if (currentDocument == null) { return; } // If we arrive here and the document is not null, then we have a change of document // or a change of focus (or both) // Get current focus unit from parameters int focus = 0; if (aFocusParameter != null) { focus = aFocusParameter.toInt(0); } // If there is no change in the current document, then there is nothing to do. Mind // that document IDs are globally unique and a change in project does not happen unless // there is also a document change. if (aPreviousDocument != null && aPreviousDocument.equals(currentDocument) && focus == getModelObject().getFocusUnitIndex()) { return; } // never had set a document or is a new one if (aPreviousDocument == null || !aPreviousDocument.equals(currentDocument)) { actionLoadDocument(aTarget, focus); } else { try { getModelObject().moveToUnit(getEditorCas(), focus, TOP); actionRefreshDocument(aTarget); } catch (Exception e) { aTarget.addChildren(getPage(), IFeedback.class); LOG.info("Error reading CAS " + e.getMessage()); error("Error reading CAS " + e.getMessage()); } } }
Example 15
Source File: LambdaAjaxSubmitLink.java From webanno with Apache License 2.0 | 4 votes |
@Override protected void onError(AjaxRequestTarget aTarget) { aTarget.addChildren(getPage(), IFeedback.class); }
Example 16
Source File: ExcuseGradeAction.java From sakai with Educational Community License v2.0 | 4 votes |
@Override public ActionResponse handleEvent(final JsonNode params, final AjaxRequestTarget target) { final GradebookPage page = (GradebookPage) target.getPage(); target.addChildren(page, FeedbackPanel.class); final String assignmentId = params.get("assignmentId").asText(); final String studentUuid = params.get("studentId").asText(); String excuse = params.get("excuseBit").asText(); final String categoryId = params.has("categoryId") ? params.get("categoryId").asText() : null; boolean hasExcuse = false; if (StringUtils.equals(excuse, "1")) { excuse = "0"; } else if (StringUtils.equals(excuse, "0")) { excuse = "1"; hasExcuse = true; } final GradeSaveResponse result = businessService.saveExcuse(Long.valueOf(assignmentId), studentUuid, hasExcuse); if (result.equals(GradeSaveResponse.NO_CHANGE)) { target.add(page.updateLiveGradingMessage(page.getString("feedback.saved"))); } target.appendJavaScript( String.format("GbGradeTable.updateExcuse('%s', '%s', '%s');", assignmentId, studentUuid, excuse)); final CourseGrade studentCourseGrade = businessService.getCourseGrade(studentUuid); boolean isOverride = false; String grade = getGrade(studentCourseGrade, page); String points = "0"; if (studentCourseGrade != null) { if (studentCourseGrade.getPointsEarned() != null) { points = FormatHelper.formatDoubleToDecimal(studentCourseGrade.getPointsEarned()); } if (studentCourseGrade.getEnteredGrade() != null) { isOverride = true; } } String categoryScore = getCategoryScore(categoryId, studentUuid); List<Long> droppedItems = getDroppedItems(categoryId, studentUuid); target.add(page.updateLiveGradingMessage(page.getString("feedback.saved"))); return new ExcuseGradeAction.ExcuseGradeResponse( grade, points, isOverride, categoryScore, droppedItems); }
Example 17
Source File: ProjectImportPanel.java From webanno with Apache License 2.0 | 4 votes |
private void actionImport(AjaxRequestTarget aTarget, Form<Preferences> aForm) { List<FileUpload> exportedProjects = fileUpload.getFileUploads(); User currentUser = userRepository.getCurrentUser(); boolean currentUserIsAdministrator = userRepository.isAdministrator(currentUser); boolean currentUserIsProjectCreator = userRepository.isProjectCreator(currentUser); boolean createMissingUsers; boolean importPermissions; // Importing of permissions is only allowed if the importing user is an administrator if (currentUserIsAdministrator) { createMissingUsers = preferences.getObject().generateUsers; importPermissions = preferences.getObject().importPermissions; } // ... otherwise we force-disable importing of permissions so that the only remaining // permission for non-admin users is that they become the managers of projects they import. else { createMissingUsers = false; importPermissions = false; } // If the current user is a project creator then we assume that the user is importing the // project for own use, so we add the user as a project manager. We do not do this if the // user is "just" an administrator but not a project creator. Optional<User> manager = currentUserIsProjectCreator ? Optional.of(currentUser) : Optional.empty(); Project importedProject = null; for (FileUpload exportedProject : exportedProjects) { try { // Workaround for WICKET-6425 File tempFile = File.createTempFile("webanno-training", null); try ( InputStream is = new BufferedInputStream(exportedProject.getInputStream()); OutputStream os = new FileOutputStream(tempFile); ) { if (!ZipUtils.isZipStream(is)) { throw new IOException("Invalid ZIP file"); } IOUtils.copyLarge(is, os); if (!ImportUtil.isZipValidWebanno(tempFile)) { throw new IOException("ZIP file is not a WebAnno project archive"); } ProjectImportRequest request = new ProjectImportRequest(createMissingUsers, importPermissions, manager); importedProject = exportService.importProject(request, new ZipFile(tempFile)); } finally { tempFile.delete(); } } catch (Exception e) { aTarget.addChildren(getPage(), IFeedback.class); error("Error importing project: " + ExceptionUtils.getRootCauseMessage(e)); LOG.error("Error importing project", e); } } if (importedProject != null) { selectedModel.setObject(importedProject); aTarget.add(getPage()); Session.get().setMetaData(CURRENT_PROJECT, importedProject); } }
Example 18
Source File: SubclassCreationDialog.java From inception with Apache License 2.0 | 4 votes |
protected void actionCreateSubclass(AjaxRequestTarget aTarget, Form<KBConcept> aForm) { try { // get subclassof property KnowledgeBase kb = kbModel.getObject(); KBProperty property = kbService.readProperty(kb, kb.getSubclassIri().stringValue()) .get(); // check whether the subclass name already exists for this superclass List<KBHandle> existingSubclasses = kbService.listChildConcepts(kb, parentConceptHandleModel.getObject().getIdentifier(), true); for (KBHandle subclass : existingSubclasses) { if (newSubclassConceptModel.getObject().getName().equals(subclass.getName())) { error(new StringResourceModel("createSubclassErrorMsg", this).setParameters( subclass.getName(), parentConceptHandleModel.getObject().getUiLabel()).getString()); aTarget.addChildren(getPage(), IFeedback.class); return; } } // create the new concept KBConcept newConcept = newSubclassConceptModel.getObject(); kbService.createConcept(kb, newConcept); String parentConceptId = parentConceptHandleModel.getObject().getIdentifier(); // create the subclassof statement and add it to the knowledge base ValueFactory vf = SimpleValueFactory.getInstance(); KBStatement subclassOfStmt = new KBStatement(null, newConcept.toKBHandle(), property, vf.createIRI(parentConceptId)); //set reification to NONE just for "upserting" the statement, then restore old value Reification kbReification = kb.getReification(); try { kb.setReification(Reification.NONE); kbService.upsertStatement(kb, subclassOfStmt); } finally { kb.setReification(kbReification); } // close the dialog - this needs to be done before sending the event below because // that event will cause changes to the page layout and this in turn will trigger an // exception if we try to close the dialog after the layout change close(aTarget); // select newly created concept right away to show the statements send(SubclassCreationDialog.this.getPage(), Broadcast.BREADTH, new AjaxConceptSelectionEvent(aTarget, newConcept.toKBHandle(), true)); } catch (Exception e) { error("Unable to find property subclassof: " + e.getLocalizedMessage()); LOG.error("Unable to find property subclassof.", e); aTarget.addChildren(SubclassCreationDialog.this.getPage(), IFeedback.class); } }
Example 19
Source File: AnnotationDetailEditorPanel.java From webanno with Apache License 2.0 | 4 votes |
@Override public void actionReverse(AjaxRequestTarget aTarget) throws IOException, AnnotationException { aTarget.addChildren(getPage(), IFeedback.class); CAS cas = getEditorCas(); AnnotatorState state = getModelObject(); AnnotationFS idFs = selectAnnotationByAddr(cas, state.getSelection().getAnnotation().getId()); cas.removeFsFromIndexes(idFs); AnnotationFS originFs = selectAnnotationByAddr(cas, state.getSelection().getOrigin()); AnnotationFS targetFs = selectAnnotationByAddr(cas, state.getSelection().getTarget()); List<FeatureState> featureStates = getModelObject().getFeatureStates(); TypeAdapter adapter = annotationService.getAdapter(state.getSelectedAnnotationLayer()); if (adapter instanceof RelationAdapter) { // If no features, still create arc #256 AnnotationFS arc = ((RelationAdapter) adapter).add(state.getDocument(), state.getUser().getUsername(), targetFs, originFs, cas); state.getSelection().setAnnotation(new VID(getAddr(arc))); for (FeatureState featureState : featureStates) { adapter.setFeatureValue(state.getDocument(), state.getUser().getUsername(), cas, getAddr(arc), featureState.feature, featureState.value); } } else { error("chains cannot be reversed"); return; } // persist changes editorPage.writeEditorCas(cas); int sentenceNumber = getSentenceNumber(cas, originFs.getBegin()); state.setFocusUnitIndex(sentenceNumber); state.getDocument().setSentenceAccessed(sentenceNumber); autoScroll(cas); state.rememberFeatures(); // in case the user re-reverse it state.getSelection().reverseArc(); onChange(aTarget); }
Example 20
Source File: HtmlAnnotationEditor.java From inception with Apache License 2.0 | 4 votes |
@Override protected void respond(AjaxRequestTarget aTarget) { // We always refresh the feedback panel - only doing this in the case were actually // something worth reporting occurs is too much of a hassel... aTarget.addChildren(getPage(), IFeedback.class); final IRequestParameters reqParams = getRequest().getRequestParameters(); // We use "emulateHTTP" to get the method as a parameter - this makes it easier to // access the method without having to go to the native container request. String method = reqParams.getParameterValue("_method").toString(); // We use "emulateJSON" to get the JSON payload as a parameter - again makes it // easier to access the payload without having to go to the native container request. String payload = reqParams.getParameterValue("json").toString(); LOG.debug("[" + method + "]: " + payload); try { // Loading existing annotations if ("GET".equals(method)) { read(aTarget); } // Update existing annotation if ("PUT".equals(method) && StringUtils.isNotEmpty(payload)) { update(aTarget, payload); } // New annotation created if ("POST".equals(method) && StringUtils.isNotEmpty(payload)) { create(aTarget, payload); } // Existing annotation deleted if ("DELETE".equals(method) && StringUtils.isNotEmpty(payload)) { delete(aTarget, payload); } } catch (Exception e) { error("Error: " + e.getMessage()); LOG.error("Error: " + e.getMessage(), e); } }