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; } } }
/** * Checks and answers whether the given list of validation messages * includes message with the specified Severity. * * @param messages the List of ValidationMessages to check * @param severity the Severity to check * @return true if the given messages list includes error messages, * false if not */ private static boolean hasSeverity( List<ValidationMessage> messages, Severity severity) { for (ValidationMessage message : messages) { if (message.severity() == severity) { return true; } } return false; }
/** * Returns an unmodifiable sub result of this result that consists of * all messages that share the specified message key. If the specified key * is {@code null}, this method returns an empty result. * The returned result is a copy, so changes in this result won't affect it. * * @param messageKey the key to look for, can be {@code null} * @return a sub result containing all messages that share the * specified key, or the empty result if the key is {@code null} * * @see #subResult(int, int) */ public ValidationResult subResult(Object messageKey) { if (messageKey == null) return EMPTY; List<ValidationMessage> messages = new ArrayList<ValidationMessage>(); for (ValidationMessage message : messageList) { if (messageKey.equals(message.key())) { messages.add(message); } } return new ValidationResult(messages, false); }
private static String getMessagesToolTipText(ValidationResult result) { List<ValidationMessage> messages = result.getMessages(); StringBuilder buffer = new StringBuilder("<html>"); //$NON-NLS-1$ for (Iterator<ValidationMessage> it = messages.iterator(); it.hasNext();) { ValidationMessage message = it.next(); buffer.append(message.formattedText()); if (it.hasNext()) { buffer.append("<br/>"); //$NON-NLS-1$ } } buffer.append("</html>"); //$NON-NLS-1$ return buffer.toString(); }
/** * Checks and answers whether the given list of validation messages * includes message with the specified Severity. * * @param messages the List of ValidationMessages to check * @param severity the Severity to check * @return true if the given messages list includes error messages, * false if not */ private static boolean hasSeverity( List<ValidationMessage> messages, Severity severity) { for (ValidationMessage message : messages) { if (message.severity() == severity) { return true; } } return false; }
/** * Returns an unmodifiable sub result of this result that consists of * all messages that share the specified message key. If the specified key * is {@code null}, this method returns an empty result. * The returned result is a copy, so changes in this result won't affect it. * * @param messageKey the key to look for, can be {@code null} * @return a sub result containing all messages that share the * specified key, or the empty result if the key is {@code null} * * @see #subResult(int, int) */ public ValidationResult subResult(Object messageKey) { if (messageKey == null) { return EMPTY; } List<ValidationMessage> messages = new ArrayList<ValidationMessage>(); for (ValidationMessage message : messageList) { if (messageKey.equals(message.key())) { messages.add(message); } } return new ValidationResult(messages, false); }
/** * Returns a string representation of the given list of messages. * * @param messages the List of ValidationMessages to iterate * @return a string representation of the given list of messages */ private static String getMessagesText(List<ValidationMessage> messages) { if (messages.isEmpty()) { return "OK"; } StringBuilder builder = new StringBuilder(); for (ValidationMessage message : messages) { if (builder.length() > 0) { builder.append("\n"); } builder.append(message.formattedText()); } return builder.toString(); }
private JDefaultToolTip createToolTip(ValidationMessage vm) { JDefaultToolTip res = null; switch (vm.severity()) { case ERROR: res = new JRedToolTip(vm.formattedText()); break; case OK: res = new JGreenToolTip(vm.formattedText()); break; case WARNING: res = new JOrangeToolTip(vm.formattedText()); break; default: res = new JRedToolTip(vm.formattedText()); break; } res.setInsetsToolTip(new Insets(2, 5, 2, 5)); return res; }
/** * Returns an unmodifiable sub result of this result that consists of * all messages that share the specified message keys. If the array of keys * is {@code null}, this method returns an empty result. * The returned result is a copy, so changes in this result won't affect it. * * @param messageKeys the keys to look for, can be {@code null} * @return a sub result containing all messages that share the specified * keys, or the empty result if the key array is {@code null} * * @see #subResult(int, int) * * @since 1.4 */ public ValidationResult subResult(Object[] messageKeys) { if (messageKeys == null) { return EMPTY; } List<ValidationMessage> messages = new ArrayList<ValidationMessage>(); for (ValidationMessage message : messageList) { Object messageKey = message.key(); for (Object key : messageKeys) { if (messageKey.equals(key)) { messages.add(message); } } } return new ValidationResult(messages, false); }
/** * Returns a string representation of the given list of messages. * * @param messages the List of ValidationMessages to iterate * @return a string representation of the given list of messages */ private static String getMessagesText(List<ValidationMessage> messages) { if (messages.isEmpty()) { return "OK"; } StringBuilder builder = new StringBuilder(); for (ValidationMessage message : messages) { if (builder.length() > 0) { builder.append('\n'); } builder.append(message.formattedText()); } return builder.toString(); }
/** * In addition to the superclass behavior, this method * assumes that the value is a ValidationMessage. * It sets the renderer's icon to the one associated with the * ValidationMessage's severity and sets the renderer's text * to the message's formatted text. */ @Override public Component getListCellRendererComponent( JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { super.getListCellRendererComponent( list, value, index, false, // Ignore the selection state false); // Ignore the cell focus state ValidationMessage message = (ValidationMessage) value; this.setIcon(ValidationResultViewFactory.getIcon(message.severity())); this.setText(message.formattedText()); return this; } }
/** * Returns the highest severity of this result's messages, * <code>Severity.OK</code> if there are no messages. * A single validation message can have only the severity * error or warning. Hence, this method returns the error severity * if there's at least one error message; and it returns * the warning severity, otherwise - assuming that there are * no other severities.<p> * * TODO: Consider changing the iteration to build the * maximum of the message severities. This would make it * easier for users that want to change this library's semantics. * For example if someone adds Severity.FATAL, this algorithm * may return an unexpected result. * * @param messages the List of ValidationMessages to check * @return the highest severity of this result's messages, * <code>Severity.OK</code> if there are no messages */ private static Severity getSeverity(List<ValidationMessage> messages) { if (messages.isEmpty()) { return Severity.OK; } for (ValidationMessage message : messages) { if (message.severity() == Severity.ERROR) { return Severity.ERROR; } } return Severity.WARNING; }
/** * Returns an unmodifiable sub result of this result that consists of * all messages that share the specified message keys. If the array of keys * is {@code null}, this method returns an empty result. * The returned result is a copy, so changes in this result won't affect it. * * @param messageKeys the keys to look for, can be {@code null} * @return a sub result containing all messages that share the specified * keys, or the empty result if the key array is {@code null} * * @see #subResult(int, int) * * @since 1.4 */ public ValidationResult subResult(Object[] messageKeys) { if (messageKeys == null) { return EMPTY; } List<ValidationMessage> messages = new ArrayList<ValidationMessage>(); for (ValidationMessage message : messageList) { Object messageKey = message.key(); for (Object key : messageKeys) { if (messageKey.equals(key)) { messages.add(message); } } } return new ValidationResult(messages, false); }
private static void updateText(JLabel label, ValidationResult result) { label.setText(result.hasMessages() ? result.getMessages().get(0).formattedText() : ""); }
/** * In addition to the superclass behavior, this method * assumes that the value is a ValidationMessage. * It sets the renderer's icon to the one associated with the * ValidationMessage's severity and sets the renderer's text * to the message's formatted text. */ @Override public Component getListCellRendererComponent( JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { super.getListCellRendererComponent( list, value, index, false, // Ignore the selection state false); // Ignore the cell focus state ValidationMessage message = (ValidationMessage) value; this.setIcon(ValidationResultViewFactory.getIcon(message.severity())); this.setText(message.formattedText()); return this; } }
/** * Returns an unmodifiable List of ValidationMessage that * that is the sublist of message with the given Severity. * * @param messages the List of ValidationMessages to iterate * @param severity the Severity to look for * @return the sublist of error messages */ private static List<ValidationMessage> getMessagesWithSeverity( List<ValidationMessage> messages, Severity severity) { List<ValidationMessage> errorMessages = new ArrayList<ValidationMessage>(); for (ValidationMessage message : messages) { if (message.severity() == severity) { errorMessages.add(message); } } return Collections.unmodifiableList(errorMessages); }
new HashMap<Object, List<ValidationMessage>>(); for (ValidationMessage message : messageList) { Object key = message.key(); List<ValidationMessage> associatedMessages = messageMap.get(key); if (associatedMessages == null) {
/** * Returns an unmodifiable List of ValidationMessage that * that is the sublist of message with the given Severity. * * @param messages the List of ValidationMessages to iterate * @param severity the Severity to look for * @return the sublist of error messages */ private static List<ValidationMessage> getMessagesWithSeverity( List<ValidationMessage> messages, Severity severity) { List<ValidationMessage> errorMessages = new ArrayList<ValidationMessage>(); for (ValidationMessage message : messages) { if (message.severity() == severity) { errorMessages.add(message); } } return Collections.unmodifiableList(errorMessages); }
new HashMap<Object, List<ValidationMessage>>(); for (ValidationMessage message : messageList) { Object key = message.key(); List<ValidationMessage> associatedMessages = messageMap.get(key); if (associatedMessages == null) {