/** * Sets an empty {@link ValidationResult} as default result. * Useful at the begin of a validation sequence. */ public void clearResult() { defaultResult = new ValidationResult(); }
private void updateValidator() { ValidationResult result = new ValidationResult(); for (ValidationResult r : validatorMap.values()) { result.addAllFrom(r); } validationResultModel.setResult(result); acceptAction.setEnabled(!result.hasErrors()); for (Action a : getOthersActions()) { a.setEnabled(!result.hasErrors()); } }
/** * Checks and answers whether this validation result has messages or not. * * @return true if there are messages, false if not * * @see #getSeverity() * @see #hasErrors() * @see #hasWarnings() */ public boolean hasMessages() { return !isEmpty(); }
/** * Returns the collapsed validation result, i. e. a {@link ValidationResult} * that just consists of a single {@link ValidationMessage}; in this case * the collapsed validation message.<p> * * TODO: Consider changing the implementation to <pre> * ValidationResult wrapper = new ValidationResult(); * if (getExpandedValidationResult().hasMessages()) { * wrapper.add(collapsedMessage); * } * return wrapper; * </pre> * * @return the collapsed validation result * * @see #getExpandedValidationResult() */ public ValidationResult getCollapsedValidationResult() { ValidationResult wrapper = new ValidationResult(); wrapper.add(collapsedMessage); return wrapper; }
/** * Adds all messages from the given ValidationResult * to the list of messages that this validation result holds. * * @param validationResult the validation result to add messages from * * @throws NullPointerException if the validation result is {@code null} * @throws UnsupportedOperationException if the result is unmodifiable * * @see #addAll(List) */ public void addAllFrom(ValidationResult validationResult) { assertModifiable(); if (validationResult == null) throw new NullPointerException("The validation result to add must not be null."); addAll(validationResult.messageList); }
/** * Sets the component background according to the associated * validation result: default, error, warning. * * @param component the component to be visited * @param keyMap maps messages keys to associated validation results */ public void visit(JComponent component, Map<Object, ValidationResult> keyMap) { Object messageKeys = getMessageKeys(component); if (messageKeys == null) { return; } JTextComponent textChild = (JTextComponent) component; ensureCustomBackgroundStored(textChild); ValidationResult result = getAssociatedResult(component, keyMap); if ((result == null) || result.isEmpty()) { restoreBackground(textChild); } else if (result.hasErrors()) { setErrorBackground(textChild); } else if (result.hasWarnings()) { setWarningBackground(textChild); } } }
if (subResult != null) { if (result == null) { result = new ValidationResult(); result.addAllFrom(subResult); : ValidationResult.unmodifiableResult(result);
/** * Returns the concatenation of all validation results that are held * by this container. * * @return the concatenation of all validation results that are held * by this container * * @see #getCollapsedValidationResult() */ public ValidationResult getExpandedValidationResult() { ValidationResult concatenation = new ValidationResult(); for (ValidationResultModel resultModel : childResultModels) { concatenation.addAllFrom(resultModel.getResult()); } return concatenation; }
@Override public void updateValidation() { ValidationResult result = new ValidationResult(); boolean hasOneUnchecked = false; if ((listToList.getSelectionValues() != null) && (listToList.getSelectionValues().length > 0)) { hasOneUnchecked = true; } // Iterator<JCheckBox> ite = visibleBoxs.iterator(); // while ((ite.hasNext()) && (!hasOneUnchecked)) { // JCheckBox checkBox = ite.next(); // if (checkBox.isSelected()) { // hasOneUnchecked = true; // } // } if (!hasOneUnchecked) { result.add(new SimpleValidationMessage(StaticWidgetHelper.getSynaptixWidgetConstantsBundle().aColumnAtLeastMustBeSelected(), Severity.ERROR)); } validationResultModel.setResult(result); acceptAction.setEnabled(!result.hasErrors()); }
/** * Notifies all registered listeners about changes of the result itself * and the properties for severity, errors and messages. Useful to fire * all changes in a #setResult implementation. * * @param oldResult the old validation result * @param newResult the new validation result * * @throws NullPointerException if the old or new result is {@code null} * * @see #setResult(ValidationResult) * @see ValidationResultModelContainer#setResult(ValidationResult) */ protected final void firePropertyChanges( ValidationResult oldResult, ValidationResult newResult) { Severity oldSeverity = oldResult.getSeverity(); boolean oldErrors = oldResult.hasErrors(); boolean oldMessages = oldResult.hasMessages(); Severity newSeverity = newResult.getSeverity(); boolean newErrors = newResult.hasErrors(); boolean newMessages = newResult.hasMessages(); firePropertyChange(PROPERTY_RESULT, oldResult, newResult); firePropertyChange(PROPERTY_ERRORS, oldErrors, newErrors); firePropertyChange(PROPERTY_MESSAGES, oldMessages, newMessages); firePropertyChange(PROPERTY_SEVERITY, oldSeverity, newSeverity); }
protected abstract void updateValidation(ValidationResult result);
@Override public final void updateValidation() { ValidationResult result = new ValidationResult(); updateValidation(result); validationResultModel.setResult(result); acceptAction.setEnabled(!result.hasErrors()); }
/** * Adds an error <code>PropertyValidationMessage</code> to the specified * <code>ValidationResult</code>. * Uses the given property and message text. * * @param result the result the message will be added to * @param property describes the validated property * @param text the message text */ public void addError(ValidationResult result, String property, String text) { result.add(createError(property, text)); }
private static void updateText(JLabel label, ValidationResult result) { if (result.isEmpty()) { label.setText(""); return; } Severity severity = result.getSeverity(); for (ValidationMessage message : result) { if (message.severity() == severity) { label.setText(message.formattedText()); return; } } }
boolean attention = false; if (result != null) { if (result.hasErrors()) { erreur = true; this.setLogoImage(erreurImage); } else if (result.hasWarnings()) { attention = true; this.setLogoImage(attentionImage);
private void insertComponents() { ValidationResult result = model.getResult(); if (!result.isEmpty()) { for (ValidationMessage vm : result.getMessages()) { if (vm.key() instanceof JComponent) { Component c = (Component) vm.key(); if (c instanceof IToolTippableComponent) { c = ((IToolTippableComponent) c).getToolTipableComponent(); } List<ValidationMessage> vs = componentMap.get(c); if (vs == null) { vs = new ArrayList<ValidationMessage>(); componentMap.put(c, vs); c.addFocusListener(this); } vs.add(vm); Collections.sort(vs, SEVERITY_COMPARATOR); } } showWindow(); } }
/** * Returns the highest severity of this result's messages, * {@code Severity.OK} if there are no messages. * * @return the highest severity of this result's messages, * {@code Severity.OK} if there are no messages * * @see #hasMessages() * @see #hasErrors() * @see #hasWarnings() */ public Severity getSeverity() { return getSeverity(messageList); }
/** * Checks and answers if the specified component is associated with an * error message in the given validation result. As a prerequisite, * the component must have an <em>association key</em> set. That can * be done using {@link #setMessageKey(JComponent, Object)} or * {@link #setMessageKeys(JComponent, Object[])}.<p> * * <strong>Note:</strong> This method may become slow if invoked for larger * validation results <em>and</em> multiple components. In this case, * it is recommended to use {@link ValidationResult#keyMap()} instead. * The latter iterates once over the validation result and can be used later * to request the severity for multiple components in almost linear time. * * @param comp used to get the association key from * @param result used to lookup the validation messages from * @return true if the given component is associated with an error message * @throws NullPointerException if the component or validation result * is {@code null} * * @see #hasWarning(JComponent, ValidationResult) * @see #getMessageKeys(JComponent) */ public static boolean hasError(JComponent comp, ValidationResult result) { return result.subResult(getMessageKeys(comp)).hasErrors(); }
/** * Checks and answers if the specified component is associated with a * warning message in the given validation result. As a prerequisite, * the component must have a <em>message key</em> set. That can * be done using {@link #setMessageKey(JComponent, Object)} or * {@link #setMessageKeys(JComponent, Object[])}.<p> * * <strong>Note:</strong> This method may become slow if invoked for larger * validation results <em>and</em> multiple components. In this case, * it is recommended to use {@link ValidationResult#keyMap()} instead. * The latter iterates once over the validation result and can be used later * to request the severity for multiple components in almost linear time. * * @param comp used to get the association key from * @param result used to lookup the validation messages from * @return true if the given component is associated with a warning message * @throws NullPointerException if the component or validation result * is {@code null} * * @see #hasError(JComponent, ValidationResult) * @see #getMessageKeys(JComponent) */ public static boolean hasWarning(JComponent comp, ValidationResult result) { return result.subResult(getMessageKeys(comp)).hasWarnings(); }
/** * Creates and adds an error message to the list of validation messages * using the given validation message key, (format) text and optional * format arguments. * * @param key the key used to associate messages and components * @param text the format text to add * @param args optional text format arguments * * * @throws NullPointerException if the message text is {@code null} * @throws IllegalArgumentException if the message text is empty or whitespace * @throws UnsupportedOperationException if the result is unmodifiable * * @see #add(ValidationMessage) * @see #addWarning(String) * * @since 2.6 */ private ValidationResult addError(Object key, String text, Object... args) { checkModifiable(); add(new SimpleValidationMessage(Strings.get(text, args), Severity.ERROR, key)); return this; }