private void removeValue(AjaxRequestTarget target) { ValueWrapper wrapper = model.getObject(); ItemWrapper propertyWrapper = wrapper.getItem(); List<ValueWrapper> values = propertyWrapper.getValues(); Component inputPanel = this.get(ID_VALUE_CONTAINER).get(ID_INPUT); switch (wrapper.getStatus()) { case ADDED: values.remove(wrapper); break; case DELETED: error("Couldn't delete already deleted item: " + wrapper.toString()); target.add(((PageBase) getPage()).getFeedbackPanel()); case NOT_CHANGED: wrapper.setStatus(ValueStatus.DELETED); break; } int count = countUsableValues(propertyWrapper); if (count == 0 && !hasEmptyPlaceholder(propertyWrapper)) { if (inputPanel instanceof ValueChoosePanel) { values.add( new ValueWrapper(propertyWrapper, new PrismReferenceValue(null), ValueStatus.ADDED)); } else { values.add( new ValueWrapper(propertyWrapper, new PrismPropertyValue(null), ValueStatus.ADDED)); } } ListView parent = findParent(ListView.class); target.add(parent.getParent()); }
private void checkResponse(AjaxRequestTarget target) { // Show cancel if (response.isCancelVisible()) { cancelDiv.setVisible(true); target.addComponent(cancelDiv); } // Show retry if (response.isRetryVisible()) { retryDiv.setVisible(true); target.addComponent(retryDiv); } // Show error Text if (PortalUtils.exists(response.getErrorMessage())) { errorMsg.setVisible(true); target.addComponent(errorMsg); } // Return to URL if (PortalUtils.exists(response.getReturnUrl()) && response.isRedirect()) try { getWebRequestCycle() .getWebResponse() .getHttpServletResponse() .sendRedirect(response.getReturnUrl()); isRedirected = true; } catch (IOException e) { LOG.error( "#An error occurred while redirecting to the return url[" + response.getReturnUrl() + "]", e); return; } }
private void update(AjaxRequestTarget target) { JCas jCas = null; try { CuratorUtil.updatePanel( target, automateView, curationContainer, mergeVisualizer, repository, annotationSelectionByUsernameAndAddress, curationSegment, annotationService, userRepository); jCas = repository.readCorrectionCas(bModel.getDocument()); } catch (UIMAException e) { error(ExceptionUtils.getRootCauseMessage(e)); } catch (ClassNotFoundException e) { error(e.getMessage()); } catch (IOException e) { error(e.getMessage()); } catch (BratAnnotationException e) { error(e.getMessage()); } gotoPageTextField.setModelObject(getFirstSentenceNumber(jCas, bModel.getSentenceAddress()) + 1); gotoPageAddress = getSentenceAddress(jCas, gotoPageTextField.getModelObject()); target.add(gotoPageTextField); target.add(automateView); target.add(numberOfPages); }
@Override protected void onDeleteSubmit(AjaxRequestTarget target, Form<?> form) { Application.getBean(FieldLanguagesValuesDao.class) .delete(getModelObject(), WebSession.getUserId()); target.add(panel.listContainer); target.appendJavaScript("labelsInit();"); }
private void savePerformed(boolean raw, String operationName, AjaxRequestTarget target) { clearOldFeedback(); OperationResult result = new OperationResult(operationName); if (!validateInput(raw)) { error(getString("pageImportObject.message.nullFile")); target.add(getFeedbackPanel()); return; } InputStream stream = null; try { Task task = createSimpleTask(operationName); stream = getInputStream(raw); getModelService().importObjectsFromStream(stream, model.getObject(), task, result); result.recomputeStatus(); } catch (Exception ex) { result.recordFatalError("Couldn't import file.", ex); LoggingUtils.logUnexpectedException(LOGGER, "Couldn't import file", ex); } finally { if (stream != null) { IOUtils.closeQuietly(stream); } } showResult(result); target.add(PageImportObject.this); }
@Override protected void onSubmit(AjaxRequestTarget target, Form<?> form) { try { Product product = (Product) form.getDefaultModelObject(); if (product.getId() == 0) { product.setActive(true); productDataProvider.persist(product); } else { productDataProvider.merge(product); } ProductViewOrEditPanel.this.removeAll(); ProductViewOrEditPanel.this.add(new ProductViewFragement().setOutputMarkupId(true)); } catch (RuntimeException e) { LOGGER.warn(e.getMessage(), e); String[] messages = e.getMessage().split(": "); String message = messages[messages.length - 1]; warn(message.substring(0, 1).toUpperCase() + message.substring(1)); } finally { target.add(target.getPage()); } }
private void updateValidZoomRanges( final ZoomLevelDropDownChoice zoomStart, final ZoomLevelDropDownChoice zoomStop, final ZoomLevelDropDownChoice minCachedLevel, final ZoomLevelDropDownChoice maxCachedLevel, AjaxRequestTarget target) { // zoomStart.processInput(); Integer min = zoomStart.getModelObject(); if (min != null) { zoomStop.setAllowedMin(min.intValue()); minCachedLevel.setAllowedMin(min.intValue()); maxCachedLevel.setAllowedMin(min.intValue()); } Integer max = zoomStop.getModelObject(); if (max != null) { minCachedLevel.setAllowedMax(max.intValue()); maxCachedLevel.setAllowedMax(max.intValue()); } Integer minCached = minCachedLevel.getModelObject(); if (minCached != null) { maxCachedLevel.setAllowedMin(minCached.intValue()); } if (null != target) { target.addComponent(zoomStop); target.addComponent(minCachedLevel); target.addComponent(maxCachedLevel); } }
@Override protected void onSearch(AjaxRequestTarget target) { target.add(feedbackPanel); // Set study in context Long studyId = (Long) SecurityUtils.getSubject() .getSession() .getAttribute(au.org.theark.core.Constants.STUDY_CONTEXT_ID); // Get a list of all Fields for the Study in context Study study = iArkCommonService.getStudy(studyId); Upload searchUpload = getModelObject().getUpload(); searchUpload.setStudy(study); searchUpload.setArkFunction( iArkCommonService.getArkFunctionByName(Constants.FUNCTION_KEY_VALUE_DATA_DICTIONARY)); Collection<Upload> uploadCollection = iArkCommonService.searchUploads(searchUpload); if (uploadCollection != null && uploadCollection.size() == 0) { this.info("Uploads with the specified criteria does not exist in the system."); target.add(feedbackPanel); } getModelObject().setUploadCollection(uploadCollection); listView.removeAll(); arkCrudContainerVO.getSearchResultPanelContainer().setVisible(true); target.add(arkCrudContainerVO.getSearchResultPanelContainer()); }
private void importReportFromStreamPerformed(AjaxRequestTarget target) { String xml = xmlEditorModel.getObject(); if (StringUtils.isEmpty(xml)) { error(getString("PageNewReport.message.emptyXml")); target.add(getFeedbackPanel()); return; } OperationResult result = new OperationResult(OPERATION_IMPORT_REPORT_XML); InputStream stream = null; try { setResponsePage(new PageReport(new ReportDto(Base64.encodeBase64(xml.getBytes())))); } catch (Exception ex) { result.recordFatalError("Couldn't import object.", ex); LoggingUtils.logException(LOGGER, "Error occured during xml import", ex); } finally { if (stream != null) { IOUtils.closeQuietly(stream); } } if (result.isSuccess()) { xmlEditorModel.setObject(null); } showResult(result); target.add(getFeedbackPanel()); }
private void importAccount(AjaxRequestTarget target, AccountContentDto row) { List<AccountContentDto> accounts = isAnythingSelected(target, row); if (accounts.isEmpty()) { return; } OperationResult result = new OperationResult(OPERATION_CREATE_USER_FROM_ACCOUNTS); for (AccountContentDto dto : accounts) { OperationResult subResult = result.createMinorSubresult(OPERATION_CREATE_USER_FROM_ACCOUNT); try { getModelService() .importFromResource( dto.getAccountOid(), createSimpleTask(OPERATION_CREATE_USER_FROM_ACCOUNT), subResult); } catch (Exception ex) { subResult.computeStatus( getString("pageContentAccounts.message.cantImportAccount", dto.getAccountOid())); LoggingUtils.logException( LOGGER, "Can't import account {},oid={}", ex, dto.getAccountName(), dto.getAccountOid()); } finally { subResult.computeStatusIfUnknown(); } } result.computeStatus(); showResult(result); target.add(getFeedbackPanel()); target.add(getTable()); }
@Override public void onEvent(IEvent event) { // Page level SaveModelEvents triggered by button in the Page Detail Form: if (event.getPayload() instanceof SaveModelEvent) { SaveModelEvent modelEvent = (SaveModelEvent) event.getPayload(); switch (modelEvent.getOperation()) { case ADD: add((Page3EO) modelEvent.getEntity()); break; case UPDATE: modelChanged(); break; case DELETE: prune(); break; default: LOG.error("onEvent caught invalid operation"); break; } AjaxRequestTarget target = ((SaveModelEvent) event.getPayload()).getAjaxRequestTarget(); LOG.debug(".onEvent AJAX - Page3 - SaveModelEvent: " + target.toString()); } // Page level AJAX events - replace TreeGrid: else if (event.getPayload() instanceof AjaxRequestTarget) { LOG.info("Page level AjaxRequestTarget Event Occurred"); AjaxRequestTarget target = ((AjaxRequestTarget) event.getPayload()); target.add(grid); } }
/* * (non-Javadoc) * @see net.rrm.ehour.persistence.persistence.ui.common.ajax.AjaxAwareContainer#ajaxEventReceived(net.rrm.ehour.persistence.persistence.ui.common.ajax.AjaxEvent) */ @Override @SuppressWarnings("unchecked") public boolean ajaxEventReceived(AjaxEvent ajaxEvent) { if (ajaxEvent.getEventType() == CommonAjaxEventType.SUBMIT_ERROR) { return processFormSubmitError(ajaxEvent.getTarget()); } else if (ajaxEvent instanceof PayloadAjaxEvent) { PayloadAjaxEvent<AdminBackingBean> payloadEvent = (PayloadAjaxEvent<AdminBackingBean>) ajaxEvent; AdminBackingBean backingBean = payloadEvent.getPayload(); AjaxEventType type = ajaxEvent.getEventType(); AjaxRequestTarget target = ajaxEvent.getTarget(); try { processFormSubmit(target, backingBean, type); } catch (Exception e) { logger.error("While trying to persist/delete", e); backingBean.setServerMessage(getLocalizer().getString("general.saveError", this)); target.add(this); return false; } } return true; }
public void updatePanel(AjaxRequestTarget aTarget, CurationContainer aCC) throws UIMAException, ClassNotFoundException, IOException, BratAnnotationException { JCas jCas = repository.readCurationCas(bModel.getDocument()); final int sentenceAddress = getAddr( selectSentenceAt(jCas, bModel.getSentenceBeginOffset(), bModel.getSentenceEndOffset())); bModel.setSentenceAddress(sentenceAddress); final Sentence sentence = selectByAddr(jCas, Sentence.class, sentenceAddress); List<Sentence> followingSentences = selectFollowing(jCas, Sentence.class, sentence, bModel.getPreferences().getWindowSize()); // Check also, when getting the last sentence address in the display window, if this is the // last sentence or the ONLY sentence in the document Sentence lastSentenceAddressInDisplayWindow = followingSentences.size() == 0 ? sentence : followingSentences.get(followingSentences.size() - 1); if (curationView == null) { curationView = new SourceListView(); } curationView.setCurationBegin(sentence.getBegin()); curationView.setCurationEnd(lastSentenceAddressInDisplayWindow.getEnd()); int ws = bModel.getPreferences().getWindowSize(); Sentence fs = BratAjaxCasUtil.selectSentenceAt( jCas, bModel.getSentenceBeginOffset(), bModel.getSentenceEndOffset()); int l = BratAjaxCasUtil.getLastSentenceAddressInDisplayWindow(jCas, getAddr(fs), ws); Sentence ls = (Sentence) selectByAddr(jCas, FeatureStructure.class, l); fSn = BratAjaxCasUtil.getSentenceNumber(jCas, fs.getBegin()); lSn = BratAjaxCasUtil.getSentenceNumber(jCas, ls.getBegin()); sentencesListView.addOrReplace(sentenceList); aTarget.add(sentencesListView); /* * corssSentAnnoView.addOrReplace(crossSentAnnoList); aTarget.add(corssSentAnnoView); */ aTarget.add(suggestionViewPanel); if (annotate) { annotator.bratRender(aTarget, editor.getCas(bModel)); annotator.bratSetHighlight(aTarget, bModel.getSelection().getAnnotation()); } else { annotator.bratRenderLater(aTarget); } annotate = false; CuratorUtil.updatePanel( aTarget, suggestionViewPanel, aCC, annotator, repository, annotationSelectionByUsernameAndAddress, curationView, annotationService, userRepository); }
private static void replace(AjaxRequestTarget target, Component component) { component.add(new DisplayNoneBehavior()); target.prependJavaScript( "notify|jQuery('#" + component.getMarkupId() + "').slideUp(1000, notify);"); target.add(component); target.appendJavaScript("jQuery('#" + component.getMarkupId() + "').slideDown(1000);"); }
@Override protected void onNewSubmit(AjaxRequestTarget target, Form<?> f) { Fieldlanguagesvalues flv = new Fieldlanguagesvalues(); flv.setLanguage_id(panel.language.getLanguage_id()); this.setModelObject(flv); target.add(this); target.appendJavaScript("labelsInit();"); }
private void importReportFromFilePerformed(AjaxRequestTarget target) { OperationResult result = new OperationResult(OPERATION_IMPORT_REPORT); FileUploadField file = (FileUploadField) get(createComponentPath(ID_MAIN_FORM, ID_INPUT, ID_INPUT_FILE, ID_FILE_INPUT)); final FileUpload uploadedFile = file.getFileUpload(); if (uploadedFile == null) { error(getString("PageNewReport.message.nullFile")); target.add(getFeedbackPanel()); return; } InputStream stream = null; File newFile = null; try { // Create new file MidPointApplication application = getMidpointApplication(); WebApplicationConfiguration config = application.getWebApplicationConfiguration(); File folder = new File(config.getImportFolder()); if (!folder.exists() || !folder.isDirectory()) { folder.mkdir(); } newFile = new File(folder, uploadedFile.getClientFileName()); // Check new file, delete if it already exists if (newFile.exists()) { newFile.delete(); } // Save file // Task task = createSimpleTask(OPERATION_IMPORT_FILE); newFile.createNewFile(); uploadedFile.writeTo(newFile); InputStreamReader reader = new InputStreamReader(new FileInputStream(newFile), "utf-8"); // reader. stream = new ReaderInputStream(reader, reader.getEncoding()); byte[] reportIn = IOUtils.toByteArray(stream); setResponsePage(new PageReport(new ReportDto(Base64.encodeBase64(reportIn)))); } catch (Exception ex) { result.recordFatalError("Couldn't import file.", ex); LoggingUtils.logException(LOGGER, "Couldn't import file", ex); } finally { if (stream != null) { IOUtils.closeQuietly(stream); } if (newFile != null) { FileUtils.deleteQuietly(newFile); } } showResult(result); target.add(getFeedbackPanel()); }
private void resetPerformed(AjaxRequestTarget target) { OperationResult result = new OperationResult(PageInternals.class.getName() + ".changeTimeReset"); clock.resetOverride(); model.reset(); result.recordSuccess(); showResult(result); target.add(getMainForm()); target.add(getFeedbackPanel()); }
private void refreshTable(AjaxRequestTarget target) { Table panel = getReportOutputTable(); ReportsStorage storage = getSessionStorage().getReports(); storage.setReportOutputSearch(searchModel.getObject()); storage.setReportOutputsPaging(null); panel.setCurrentPage(0); target.add((Component) panel); target.add(getFeedbackPanel()); }
private void searchPerformed(AjaxRequestTarget target) { ObjectQuery query = createQuery(); TablePanel panel = getTable(); DataTable table = panel.getDataTable(); AccountContentDataProvider provider = (AccountContentDataProvider) table.getDataProvider(); provider.setQuery(query); table.setCurrentPage(0); target.add(panel); target.add(getFeedbackPanel()); }
@Override protected void onSaveSubmit(AjaxRequestTarget target, Form<?> form) { Fieldlanguagesvalues flv = getModelObject(); Fieldvalues fv = flv.getFieldvalues(); Application.getBean(FieldValueDao.class).update(fv, WebSession.getUserId()); flv.setFieldvalues(fv); Application.getBean(FieldLanguagesValuesDao.class).update(flv, WebSession.getUserId()); hideNewRecord(); target.add(panel.listContainer); target.appendJavaScript("labelsInit();"); }
@Override public void onEvent(final IEvent<?> event) { if (event.getPayload() instanceof SelectModelEvent) { SelectModelEvent modelEvent = (SelectModelEvent) event.getPayload(); final Page3EO page3EO = (Page3EO) modelEvent.getEntity(); this.setModelObject(page3EO); LOG.info("Received SelectModelEvent, customer: " + page3EO.getCustomer()); } else if (event.getPayload() instanceof AjaxRequestTarget) { AjaxRequestTarget target = ((AjaxRequestTarget) event.getPayload()); LOG.info(".onEvent AjaxRequestTarget: " + target.toString()); target.add(editForm); } }
@Override protected void onUpdate(AjaxRequestTarget target) { updateState(); MarkupContainer form = (MarkupContainer) get("saveResultsForm"); Component saveResultsLink = form.get("saveResultsLink"); Component addResultsLink = form.get("addResultsLink"); Component subtractResultsLink = form.get("subtractResultsLink"); Component intersectResultsLink = form.get("intersectResultsLink"); target.add(addResultsLink); target.add(subtractResultsLink); target.add(saveResultsLink); target.add(intersectResultsLink); }
private void savePerformed(AjaxRequestTarget target) { ObjectViewDto dto = model.getObject(); if (StringUtils.isEmpty(dto.getXml())) { error(getString("pageResourceEdit.message.emptyXml")); target.add(getFeedbackPanel()); return; } Task task = createSimpleTask(OPERATION_SAVE_RESOURCE); OperationResult result = task.getResult(); try { Holder<PrismObject<ResourceType>> objectHolder = new Holder<PrismObject<ResourceType>>(null); validateObject(dto.getXml(), objectHolder, false, result); if (result.isAcceptable()) { PrismObject<ResourceType> newResource = objectHolder.getValue(); updateConnectorRef(newResource, task, result); if (!isEditing()) { // we're adding new resource ObjectDelta delta = ObjectDelta.createAddDelta(newResource); getModelService() .executeChanges(WebMiscUtil.createDeltaCollection(delta), null, task, result); } else { // we're editing existing resource PrismObject<ResourceType> oldResource = dto.getObject(); ObjectDelta<ResourceType> delta = oldResource.diff(newResource); getModelService() .executeChanges( WebMiscUtil.createDeltaCollection(delta), ModelExecuteOptions.createRaw(), task, result); } result.computeStatus(); } } catch (Exception ex) { LoggingUtils.logException(LOGGER, "Couldn't save resource", ex); result.recordFatalError("Couldn't save resource.", ex); } if (WebMiscUtil.isSuccessOrHandledError(result)) { showResultInSession(result); setResponsePage(PageResources.class); } else { showResult(result); target.add(getFeedbackPanel()); } }
@Override protected void onRefreshSubmit(AjaxRequestTarget target, Form<?> form) { Fieldlanguagesvalues flv = getModelObject(); if (flv.getFieldlanguagesvalues_id() != null) { flv = Application.getBean(FieldLanguagesValuesDao.class) .get(getModelObject().getFieldlanguagesvalues_id()); } else { flv = new Fieldlanguagesvalues(); } this.setModelObject(flv); target.add(this); target.appendJavaScript("labelsInit();"); }
private void removeOwnerPerformed(AjaxRequestTarget target, AccountContentDto row) { List<AccountContentDto> accounts = isAnythingSelected(target, row); if (accounts.isEmpty()) { return; } for (AccountContentDto dto : accounts) { reloadOwnerChangeModel(dto.getAccountOid(), dto.getOwnerOid()); ownerChangePerformed(target, null); } target.add(getTable()); target.add(getFeedbackPanel()); }
private void deleteDefinitionPerformed( AjaxRequestTarget target, AccessCertificationDefinitionType definition) { OperationResult result = new OperationResult(OPERATION_DELETE_DEFINITION); try { Task task = createSimpleTask(OPERATION_DELETE_DEFINITION); ObjectDelta<AccessCertificationDefinitionType> delta = ObjectDelta.createDeleteDelta( AccessCertificationDefinitionType.class, definition.getOid(), getPrismContext()); getModelService() .executeChanges(WebComponentUtil.createDeltaCollection(delta), null, task, result); } catch (Exception ex) { result.recordPartialError("Couldn't delete campaign definition.", ex); LoggingUtils.logUnexpectedException(LOGGER, "Couldn't delete campaign definition", ex); } result.computeStatusIfUnknown(); if (result.isSuccess()) { result.recordStatus( OperationResultStatus.SUCCESS, "The definition has been successfully deleted."); } getDefinitionsTable().clearCache(); showResult(result); target.add(getFeedbackPanel(), getDefinitionsTable()); }
public void filterChanged( boolean sort, boolean requiredLabelsChanged, boolean otherLabelsChanged) { // Re-render what is needed AjaxRequestTarget art = getRequestCycle().find(AjaxRequestTarget.class); art.add(eventsList); if (requiredLabelsChanged) { art.add(requiredLabelsWrapper); art.add(sidePanel.getRequiredLabelsWrapper()); } if (otherLabelsChanged) { art.add(sidePanel); } }
/** * Called if this panel is uses Ajax. * * @param target */ protected void defaultReturnAction(AjaxRequestTarget target) { ModalWindow modal = (ModalWindow) findParent(ModalWindow.class); if (modal != null) { Component refreshParent = WicketResourceUtils.findOutputMarkupIdParent(modal); ModalWindow.closeCurrent(target); if (refreshParent != null) { target.addComponent(refreshParent); } } else { Component refreshParent = WicketResourceUtils.findOutputMarkupIdParent(this); if (refreshParent != null) { this.replaceWith(newReturnComponent(getId())); target.addComponent(refreshParent); } } }
protected void onUpdateError(AjaxRequestTarget target, Exception ex) { String message = "Error occurred while fetching data: " + ex.getMessage(); Label errorLabel = new Label(ID_BODY, message); replace(errorLabel); target.add(this); }
@Override protected boolean processFormSubmit( AjaxRequestTarget target, AdminBackingBean backingBean, AjaxEventType type) throws Exception { UserManageBackingBean userManageBackingBean = (UserManageBackingBean) backingBean; boolean eventHandled; try { User user = userManageBackingBean.getUser(); eventHandled = false; if (type == USER_CREATED) { userService.persistNewUser(user, user.getPassword()); } else if (type == USER_UPDATED) { userService.persistEditedUser(user); String password = user.getPassword(); if (StringUtils.isNotBlank(password)) { userService.changePassword(user.getUsername(), password); } } else if (type == USER_DELETED) { deleteUser(userManageBackingBean); } } catch (ObjectNotUniqueException obnu) { backingBean.setServerMessage(obnu.getMessage()); target.add(this); eventHandled = true; } return !eventHandled; }