Exemple #1
0
 /** Records an error in any editors that match the path, returning true if any editors matched. */
 private static boolean processEditors(
     DelegateMap delegateMap,
     AbstractEditorDelegate<?, ?> baseDelegate,
     String absolutePath,
     SimpleViolation error) {
   List<Editor<?>> editors = delegateMap.getEditorByPath(absolutePath);
   if (editors == null) {
     return false;
   }
   // No EditorDelegate to attach it to, so record on the baseDelegate
   // with the appropriate editor & path.
   for (Editor<?> editor : editors) {
     baseDelegate.recordError(
         error.getMessage(), null, error.getUserDataObject(), error.getPath(), editor);
   }
   return true;
 }
Exemple #2
0
  /** Maps an abstract representation of a violation into the appropriate EditorDelegate. */
  public static void pushViolations(
      Iterable<SimpleViolation> violations, EditorDriver<?> driver, KeyMethod keyMethod) {
    if (violations == null) {
      return;
    }

    DelegateMap delegateMap = DelegateMap.of(driver, keyMethod);

    // For each violation
    for (SimpleViolation error : violations) {
      Object key = error.getKey();
      List<AbstractEditorDelegate<?, ?>> delegateList = delegateMap.get(key);
      if (delegateList != null) {

        // For each delegate editing some record...
        for (AbstractEditorDelegate<?, ?> baseDelegate : delegateList) {

          // compute its base path in the hierarchy...
          String basePath = baseDelegate.getPath();

          // and the absolute path of the leaf editor receiving the error.
          String absolutePath = (basePath.length() > 0 ? basePath + "." : "") + error.getPath();
          final String originalAbsolutePath = absolutePath;
          while (true) {
            if (processLeafDelegates(delegateMap, originalAbsolutePath, absolutePath, error)) {
              break;
            } else if (processEditors(delegateMap, baseDelegate, absolutePath, error)) {
              break;
            } else {
              // This is guaranteed to never happen because we should always
              // process a delegate/editor if the absolutePath is empty.
              // Still, we have the check here to prevent an infinite
              // loop if something goes wrong.
              if (absolutePath.isEmpty()) {
                throw new IllegalStateException("No editor: " + originalAbsolutePath);
              }
              absolutePath = getParentPath(absolutePath);
            }
          }
        }
      }
    }
  }