Ejemplo n.º 1
0
 public TreeOperation handleTreeDeleteText(TreeDeleteText op1) {
   if (op1.path[0] != path[0]) {
     return op1;
   }
   if (op1.path[1] < path[1]) {
     return op1;
   }
   if (op1.path[1] == path[1]) { // meme chemin
     if (op1.getPosition() < start) {
       return op1;
     }
     if (op1.getPosition() == start || op1.getPosition() < end) {
       int[] tab = TreeUtils.addC(op1.path, 1, splitLeft ? 1 : 0);
       if (addStyle) {
         tab = TreeUtils.addLevel(tab);
       }
       return new TreeDeleteText(op1.getSiteId(), op1.getPosition() - start, tab);
     }
     int[] tab = TreeUtils.addC(op1.path, 1, splitLeft ? 2 : 1);
     if (addStyle) {
       tab = TreeUtils.addLevel(tab);
     }
     return new TreeDeleteText(op1.getSiteId(), op1.getPosition() - end, tab);
   }
   // op1.path[1]>path[1]
   int d = 0; // decalage
   if (splitLeft) {
     d++;
   }
   if (splitRight) {
     d++;
   }
   int[] tab = TreeUtils.addC(op1.path, 1, d);
   return new TreeDeleteText(op1.getSiteId(), op1.getPosition(), tab);
 }
Ejemplo n.º 2
0
 @Override
 protected TreeOperation handleTreeSplitItem(TreeSplitItem op1) {
   if (op1.path[0] != path[0]) {
     return op1;
   }
   if (op1.path[1] != path[1]) {
     return op1;
   }
   if (op1.path[2] < path[2]) {
     return op1;
   }
   if (op1.path[2] == path[2]) { // meme chemin
     if (op1.getPosition() < start) {
       return op1;
     }
     if (op1.getPosition() == start) {
       int[] tab = TreeUtils.addC(op1.path, 2, splitLeft ? 1 : 0);
       if (addStyle) {
         tab = TreeUtils.addLevel(tab);
       }
       return new TreeInsertParagraph(op1.getSiteId(), 0, tab, false);
     }
     if (op1.getPosition() < end) {
       int[] tab = TreeUtils.addC(op1.path, 2, splitLeft ? 1 : 0);
       if (addStyle) {
         tab = TreeUtils.addLevel(tab);
       }
       return new TreeInsertParagraph(
           op1.getSiteId(), op1.getPosition() - start, tab, op1.splitLeft);
     }
     int[] tab = TreeUtils.addC(op1.path, 2, splitLeft ? 2 : 1);
     if (op1.getPosition() == end) {
       return new TreeInsertParagraph(op1.getSiteId(), 0, tab, false);
     }
     return new TreeInsertParagraph(op1.getSiteId(), op1.getPosition() - end, tab, op1.splitLeft);
   }
   // op1.path[2]>path[2]
   int d = 0; // decalage
   if (splitLeft) {
     d++;
   }
   if (splitRight) {
     d++;
   }
   int[] tab = TreeUtils.addC(op1.path, 2, d);
   return new TreeInsertParagraph(op1.getSiteId(), op1.getPosition(), tab, op1.splitLeft);
 }
Ejemplo n.º 3
0
  public TreeOperation handleTreeStyle(TreeStyle op1) {

    String pTag = priority(op1.TAG_NAME, this.TAG_NAME);

    if (op1.path[0] != path[0]) {
      return op1;
    }
    if (op1.path[1] < path[1]) {
      return op1;
    }
    int d = 0; // decalage;
    if (splitLeft) {
      d++;
    }
    if (splitRight) {
      d++;
    }
    if (op1.path[1] > path[1]) {
      int[] tab = TreeUtils.addC(op1.path, 1, d);
      return new TreeStyle(
          op1.siteId,
          tab,
          op1.start,
          op1.end,
          op1.param,
          op1.value,
          op1.addStyle,
          op1.splitLeft,
          op1.splitRight,
          op1.TAG_NAME);
    }
    // op1.path=path
    // utilisation de l'ID pour l'édition du même paramètre
    ArrayList<TreeOperation> list = new ArrayList<TreeOperation>();
    if (op1.start < start) {
      if (op1.end <= start) { // style1 before style2
        return new TreeStyle(
            op1.siteId,
            op1.path,
            op1.start,
            op1.end,
            op1.param,
            op1.value,
            op1.addStyle,
            op1.splitLeft,
            op1.end == start ? false : true,
            op1.TAG_NAME);
      }
      list.add(
          new TreeStyle(
              op1.siteId,
              op1.path,
              op1.start,
              start,
              op1.param,
              op1.value,
              op1.addStyle,
              op1.splitLeft,
              false,
              op1.TAG_NAME));
      if (op1.end >= end) { // style2 into style1
        if (!(op1.param.equals(param))
            || op1.siteId < siteId) { // no conflict between s1 and s2, or s1 win
          list.add(
              new TreeStyle(
                  op1.siteId,
                  !addStyle
                      ? TreeUtils.addC(op1.path, 1, op1.splitLeft ? 2 : 1)
                      : TreeUtils.addLevel(TreeUtils.addC(op1.path, 1, op1.splitLeft ? 2 : 1)),
                  0,
                  end - start,
                  op1.param,
                  op1.value,
                  false,
                  false,
                  false,
                  pTag));
        } else { // apply op2 style to split the String
          list.add(
              new TreeStyle(
                  op1.siteId,
                  !addStyle
                      ? TreeUtils.addC(op1.path, 1, op1.splitLeft ? 2 : 1)
                      : TreeUtils.addLevel(TreeUtils.addC(op1.path, 1, op1.splitLeft ? 2 : 1)),
                  0,
                  end - start,
                  op1.param,
                  value,
                  false,
                  false,
                  false,
                  pTag));
        }
        if (op1.end != end) {
          list.add(
              new TreeStyle(
                  op1.siteId,
                  TreeUtils.addC(op1.path, 1, op1.splitLeft ? 3 : 2),
                  0,
                  op1.end - end,
                  op1.param,
                  op1.value,
                  op1.addStyle,
                  false,
                  op1.splitRight,
                  op1.TAG_NAME));
        }
        return new TreeCompositeOperation(list);
      }
      // op1.end<end && op1.end>start
      if (!(op1.param.equals(param))
          || op1.siteId < siteId) { // no conflict between s1 and s2, or s1 win
        list.add(
            new TreeStyle(
                op1.siteId,
                !addStyle
                    ? TreeUtils.addC(op1.path, 1, op1.splitLeft ? 2 : 1)
                    : TreeUtils.addLevel(TreeUtils.addC(op1.path, 1, op1.splitLeft ? 2 : 1)),
                0,
                op1.end - start,
                op1.param,
                op1.value,
                false,
                false,
                true,
                pTag));
      } else { // apply op2 style to split the String
        list.add(
            new TreeStyle(
                op1.siteId,
                !addStyle
                    ? TreeUtils.addC(op1.path, 1, op1.splitLeft ? 2 : 1)
                    : TreeUtils.addLevel(TreeUtils.addC(op1.path, 1, op1.splitLeft ? 2 : 1)),
                0,
                op1.end - start,
                op1.param,
                value,
                false,
                false,
                true,
                pTag));
      }
      return new TreeCompositeOperation(list);
    }
    if (op1.start == start) {
      if (!(op1.param.equals(param))
          || op1.siteId < siteId) { // no conflict between s1 and s2, or s1 win
        list.add(
            new TreeStyle(
                op1.siteId,
                !addStyle
                    ? TreeUtils.addC(op1.path, 1, op1.splitLeft ? 1 : 0)
                    : TreeUtils.addLevel(TreeUtils.addC(op1.path, 1, op1.splitLeft ? 1 : 0)),
                0,
                (op1.end >= end) ? end - start : op1.end - op1.start,
                op1.param,
                op1.value,
                false,
                false,
                op1.end <= end ? false : true,
                pTag));
      } else { // apply op2 style to split the String
        list.add(
            new TreeStyle(
                op1.siteId,
                !addStyle
                    ? TreeUtils.addC(op1.path, 1, op1.start == 0 ? 0 : 1)
                    : TreeUtils.addLevel(TreeUtils.addC(op1.path, 1, op1.start == 0 ? 0 : 1)),
                0,
                (op1.end >= end) ? end - start : op1.end - op1.start,
                op1.param,
                value,
                false,
                false,
                op1.end <= end ? false : true,
                pTag));
      }
      if (op1.end > end) {
        list.add(
            new TreeStyle(
                op1.siteId,
                TreeUtils.addC(op1.path, 1, op1.splitLeft ? 2 : 1),
                0,
                op1.end - end,
                op1.param,
                op1.value,
                op1.addStyle,
                false,
                op1.splitRight,
                op1.TAG_NAME));
      }
      if (list.size() == 1) {
        return list.get(0);
      }
      return new TreeCompositeOperation(list);
    }
    // op1.start>start
    if (op1.start >= end) { // style1 after style2
      return new TreeStyle(
          op1.siteId,
          TreeUtils.addC(op1.path, 1, splitLeft ? 2 : 1),
          op1.start - end,
          op1.end - end,
          op1.param,
          op1.value,
          op1.addStyle,
          op1.start == end ? false : true,
          op1.splitRight,
          op1.TAG_NAME);
    }
    if (op1.end <= end) { // style1 between style 2
      if (!(op1.param.equals(param))
          || op1.siteId < siteId) { // no conflict between s1 and s2, or s1 win
        return new TreeStyle(
            op1.siteId,
            !addStyle
                ? TreeUtils.addC(op1.path, 1, splitLeft ? 1 : 0)
                : TreeUtils.addLevel(TreeUtils.addC(op1.path, 1, splitLeft ? 1 : 0)),
            op1.start - start,
            op1.end - start,
            op1.param,
            op1.value,
            false,
            true,
            op1.end == end ? false : true,
            pTag);
      } else { // apply op2 style to split the String
        return new TreeStyle(
            op1.siteId,
            !addStyle
                ? TreeUtils.addC(op1.path, 1, splitLeft ? 1 : 0)
                : TreeUtils.addLevel(TreeUtils.addC(op1.path, 1, splitLeft ? 1 : 0)),
            op1.start - start,
            op1.end - start,
            op1.param,
            value,
            false,
            true,
            op1.end == end ? false : true,
            pTag);
      }
    }
    // last case : s2<s1<e2<e1
    if (!(op1.param.equals(param))
        || op1.siteId < siteId) { // no conflict between s1 and s2, or s1 win
      list.add(
          new TreeStyle(
              op1.siteId,
              !addStyle
                  ? TreeUtils.addC(op1.path, 1, splitLeft ? 1 : 0)
                  : TreeUtils.addLevel(TreeUtils.addC(op1.path, 1, splitLeft ? 1 : 0)),
              op1.start - start,
              end - start,
              op1.param,
              op1.value,
              false,
              true,
              false,
              pTag));
    } else { // apply op2 style to split the String
      list.add(
          new TreeStyle(
              op1.siteId,
              !addStyle
                  ? TreeUtils.addC(op1.path, 1, splitLeft ? 1 : 0)
                  : TreeUtils.addLevel(TreeUtils.addC(op1.path, 1, splitLeft ? 1 : 0)),
              op1.start - start,
              end - start,
              op1.param,
              value,
              false,
              true,
              false,
              pTag));
    }
    list.add(
        new TreeStyle(
            op1.siteId,
            TreeUtils.addC(op1.path, 1, splitLeft ? 3 : 2),
            0,
            op1.end - end,
            op1.param,
            op1.value,
            op1.addStyle,
            false,
            op1.splitRight,
            op1.TAG_NAME));
    return new TreeCompositeOperation(list);
  }