Search in sources :

Example 1 with Message

use of org.ovirt.engine.ui.frontend.Message in project ovirt-engine by oVirt.

the class ErrorMessageFormatter method getDescription2MsgMap.

private static Map<String, Set<String>> getDescription2MsgMap(List<Message> msgList) {
    Map<String, Set<String>> desc2Msgs = new HashMap<>();
    for (Message msg : msgList) {
        String desc = msg.getDescription();
        if (desc == null) {
            // $NON-NLS-1$
            desc = "";
        }
        desc = desc.trim();
        Set<String> msgs = desc2Msgs.get(desc);
        if (msgs == null) {
            msgs = new HashSet<>();
            desc2Msgs.put(desc, msgs);
        }
        msgs.add(msg.getText());
    }
    return desc2Msgs;
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) Message(org.ovirt.engine.ui.frontend.Message) HashMap(java.util.HashMap)

Example 2 with Message

use of org.ovirt.engine.ui.frontend.Message in project ovirt-engine by oVirt.

the class ErrorMessageFormatter method formatMessages.

public static String formatMessages(List<Message> values) {
    // If one error message without description no need to format
    if (values.size() == 1) {
        Message msg = values.get(0);
        if (msg.getDescription() == null || "".equals(msg.getDescription())) {
            // $NON-NLS-1$
            return msg.getText();
        }
    }
    SafeHtmlBuilder allSb = new SafeHtmlBuilder();
    // $NON-NLS-1$
    allSb.append(SafeHtmlUtils.fromTrustedString("<br/><br/>"));
    Map<String, Set<String>> desc2msgs = getDescription2MsgMap(values);
    for (Map.Entry<String, Set<String>> entry : desc2msgs.entrySet()) {
        String desc = entry.getKey();
        SafeHtml sh = buildItemList(entry.getValue());
        if (!"".equals(desc)) {
            // $NON-NLS-1$
            // $NON-NLS-1$
            allSb.append(SafeHtmlUtils.fromString(desc + ":"));
        }
        allSb.append(sh);
    }
    return allSb.toSafeHtml().asString();
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) Message(org.ovirt.engine.ui.frontend.Message) SafeHtml(com.google.gwt.safehtml.shared.SafeHtml) SafeHtmlBuilder(com.google.gwt.safehtml.shared.SafeHtmlBuilder) HashMap(java.util.HashMap) Map(java.util.Map)

Example 3 with Message

use of org.ovirt.engine.ui.frontend.Message in project ovirt-engine by oVirt.

the class FrontendEventsHandlerImpl method runMultipleActionsFailed.

public void runMultipleActionsFailed(List<ActionType> actions, List<ActionReturnValue> returnValues, MessageFormatter messageFormatter) {
    List<Message> errors = new ArrayList<>();
    int actionNum = 0;
    for (ActionReturnValue v : returnValues) {
        if (isRaiseErrorModalPanel(actions.get(actionNum++), v.getFault())) {
            String description = // $NON-NLS-1$ //$NON-NLS-2$
            (v.getDescription() != null && !"".equals(v.getDescription().trim())) || returnValues.size() == 1 ? v.getDescription() : ConstantsManager.getInstance().getConstants().action() + " " + actionNum;
            if (!v.isValid()) {
                for (String validateMessage : v.getValidationMessages()) {
                    errors.add(new Message(description, validateMessage));
                }
            } else {
                errors.add(new Message(description, v.getFault().getMessage()));
            }
        }
    }
    errorPopupManager.show(messageFormatter.format(ErrorMessageFormatter.formatMessages(errors)));
}
Also used : Message(org.ovirt.engine.ui.frontend.Message) ActionReturnValue(org.ovirt.engine.core.common.action.ActionReturnValue) ArrayList(java.util.ArrayList)

Aggregations

Message (org.ovirt.engine.ui.frontend.Message)3 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 Set (java.util.Set)2 SafeHtml (com.google.gwt.safehtml.shared.SafeHtml)1 SafeHtmlBuilder (com.google.gwt.safehtml.shared.SafeHtmlBuilder)1 ArrayList (java.util.ArrayList)1 Map (java.util.Map)1 ActionReturnValue (org.ovirt.engine.core.common.action.ActionReturnValue)1