1 19 package org.openide.nodes; 20 21 import java.util.Arrays ; 22 import java.util.HashSet ; 23 24 25 29 public class NodeMemberEvent extends NodeEvent { 30 static final long serialVersionUID = -3973509253579305102L; 31 32 33 private boolean add; 34 35 36 private Node[] delta; 37 38 41 private Node[] from; 42 43 44 private int[] indices; 45 46 52 NodeMemberEvent(Node n, boolean add, Node[] delta, Node[] from) { 53 super(n); 54 this.add = add; 55 this.delta = delta; 56 this.from = from; 57 } 58 59 63 public final boolean isAddEvent() { 64 return add; 65 } 66 67 70 public final Node[] getDelta() { 71 return delta; 72 } 73 74 77 public synchronized int[] getDeltaIndices() { 78 if (indices != null) { 79 return indices; 80 } 81 82 if (from == null) { 84 from = getNode().getChildren().getNodes(); 86 } 87 88 java.util.List <Node> list = Arrays.asList(delta); 89 HashSet <Node> set = new HashSet <Node>(list); 90 91 indices = new int[delta.length]; 92 93 int j = 0; 94 int i = 0; 95 96 while ((i < from.length) && (j < indices.length)) { 97 if (set.contains(from[i])) { 98 indices[j++] = i; 99 } 100 101 i++; 102 } 103 104 if (j != delta.length) { 105 StringBuilder m = new StringBuilder (1000); 106 m.append("Some of a set of deleted nodes are not present in the original ones.\n"); m.append("See #15478; you may need to check that your Children.Keys keys are safely comparable."); m.append("\ni: ").append(i); m.append("\nj: ").append(j); m.append("\nThis: ").append(this); m.append("\nCurrent state:\n"); m.append(Arrays.asList(from)); 113 m.append("\nDelta:\n"); m.append(list); 115 throw new IllegalStateException (m.toString()); 116 } 117 118 return indices; 119 } 120 121 122 public String toString() { 123 StringBuilder sb = new StringBuilder (); 124 sb.append(getClass().getName()); 125 sb.append("[node="); sb.append(getSource()); 127 sb.append(", add="); sb.append(isAddEvent()); 129 130 Node[] deltaNodes = getDelta(); 131 int[] deltaIndices = getDeltaIndices(); 132 133 for (int i = 0; i < deltaNodes.length; i++) { 134 sb.append("\n "); sb.append(i); 136 sb.append(" at "); sb.append(deltaIndices[i]); 138 sb.append(" = "); sb.append(deltaNodes[i]); 140 } 141 142 sb.append("\n]"); 144 return sb.toString(); 145 } 146 } 147 | Popular Tags |