1 11 package org.eclipse.debug.internal.ui.viewers.provisional; 12 13 14 15 23 public class ModelDelta implements IModelDelta { 24 25 private IModelDelta fParent; 26 private Object fElement; 27 private int fFlags; 28 private ModelDelta[] fNodes = EMPTY_NODES; 29 private Object fReplacement; 30 private int fIndex; 31 private static final ModelDelta[] EMPTY_NODES = new ModelDelta[0]; 32 33 39 public ModelDelta(Object element, int flags) { 40 fElement = element; 41 fFlags = flags; 42 } 43 44 52 public ModelDelta(Object element, Object replacement, int flags) { 53 fElement = element; 54 fReplacement = replacement; 55 fFlags = flags; 56 } 57 58 66 public ModelDelta(Object element, int index, int flags) { 67 fElement = element; 68 fIndex = index; 69 fFlags = flags; 70 } 71 72 75 public Object getElement() { 76 return fElement; 77 } 78 79 82 public int getFlags() { 83 return fFlags; 84 } 85 86 94 public ModelDelta addNode(Object element, int flags) { 95 ModelDelta node = new ModelDelta(element, flags); 96 node.setParent(this); 97 addDelta(node); 98 return node; 99 } 100 101 111 public ModelDelta addNode(Object element, Object replacement, int flags) { 112 ModelDelta node = new ModelDelta(element, replacement, flags); 113 node.setParent(this); 114 addDelta(node); 115 return node; 116 } 117 118 127 public ModelDelta addNode(Object element, int index, int flags) { 128 ModelDelta node = new ModelDelta(element, index, flags); 129 node.setParent(this); 130 addDelta(node); 131 return node; 132 } 133 134 139 void setParent(ModelDelta node) { 140 fParent = node; 141 } 142 143 146 public IModelDelta getParent() { 147 return fParent; 148 } 149 150 153 public Object getReplacementElement() { 154 return fReplacement; 155 } 156 157 160 public int getIndex() { 161 return fIndex; 162 } 163 164 167 public ModelDelta[] getNodes() { 168 return fNodes; 169 } 170 171 private void addDelta(ModelDelta delta) { 172 if (fNodes.length == 0) { 173 fNodes = new ModelDelta[]{delta}; 174 } else { 175 ModelDelta[] nodes = new ModelDelta[fNodes.length + 1]; 176 System.arraycopy(fNodes, 0, nodes, 0, fNodes.length); 177 nodes[fNodes.length] = delta; 178 fNodes = nodes; 179 } 180 } 181 182 public String toString() { 183 StringBuffer buf = new StringBuffer (); 184 buf.append("Model Delta Start\n"); appendDetail(buf, this); 186 buf.append("Model Delta End\n"); return buf.toString(); 188 } 189 190 private void appendDetail(StringBuffer buf, ModelDelta delta) { 191 buf.append("\tElement: "); buf.append(delta.fElement); 193 buf.append('\n'); 194 buf.append("\t\tFlags: "); int flags = delta.getFlags(); 196 if (flags == 0) { 197 buf.append("NO_CHANGE"); } else { 199 if ((flags & IModelDelta.ADDED) > 0) { 200 buf.append("ADDED | "); } 202 if ((flags & IModelDelta.CONTENT) > 0) { 203 buf.append("CONTENT | "); } 205 if ((flags & IModelDelta.EXPAND) > 0) { 206 buf.append("EXPAND | "); } 208 if ((flags & IModelDelta.INSERTED) > 0) { 209 buf.append("INSERTED | "); } 211 if ((flags & IModelDelta.REMOVED) > 0) { 212 buf.append("REMOVED | "); } 214 if ((flags & IModelDelta.REPLACED) > 0) { 215 buf.append("REPLACED | "); } 217 if ((flags & IModelDelta.SELECT) > 0) { 218 buf.append("SELECT | "); } 220 if ((flags & IModelDelta.STATE) > 0) { 221 buf.append("STATE | "); } 223 } 224 buf.append('\n'); 225 ModelDelta[] nodes = delta.getNodes(); 226 for (int i = 0; i < nodes.length; i++) { 227 appendDetail(buf, nodes[i]); 228 } 229 } 230 } 231 | Popular Tags |