1 11 package org.eclipse.debug.internal.ui.viewers; 12 13 import java.util.ArrayList ; 14 import java.util.Iterator ; 15 import java.util.List ; 16 17 18 22 public class AsynchronousTableModel extends AsynchronousModel { 23 24 29 public AsynchronousTableModel(AsynchronousViewer viewer) { 30 super(viewer); 31 } 32 33 36 protected void add(ModelNode parent, Object element) {} 37 38 43 public void add(Object [] elements) { 44 TableAddRequestMonitor update = new TableAddRequestMonitor(getRootNode(), elements, this); 45 requestScheduled(update); 46 update.done(); 47 } 48 49 54 protected void added(Object [] elements) { 55 List kids = null; 56 boolean changed = false; 57 synchronized (this) { 58 ModelNode[] childrenNodes = getRootNode().getChildrenNodes(); 59 if (childrenNodes == null) { 60 kids = new ArrayList (elements.length); 61 } else { 62 kids = new ArrayList (elements.length + childrenNodes.length); 63 for (int i = 0; i < childrenNodes.length; i++) { 64 kids.add(childrenNodes[i].getElement()); 65 } 66 } 67 for (int i = 0; i < elements.length; i++) { 68 if (!kids.contains(elements[i])) { 69 kids.add(elements[i]); 70 changed = true; 71 } 72 } 73 } 74 if (changed) { 75 setChildren(getRootNode(), kids); 76 } 77 } 78 79 85 public void insert(Object [] elements, int index) { 86 TableAddRequestMonitor update = new TableInsertRequestMonitor(getRootNode(), elements, index, this); 87 requestScheduled(update); 88 update.done(); 89 } 90 91 97 protected void inserted(Object [] elements, int index) { 98 List kids = null; 99 boolean changed = false; 100 synchronized (this) { 101 ModelNode[] childrenNodes = getRootNode().getChildrenNodes(); 102 if (childrenNodes == null) { 103 kids = new ArrayList (elements.length); 104 } else { 105 kids = new ArrayList (elements.length + childrenNodes.length); 106 for (int i = 0; i < childrenNodes.length; i++) { 107 kids.add(childrenNodes[i].getElement()); 108 } 109 } 110 for (int i = 0; i < elements.length; i++) { 111 if (!kids.contains(elements[i])) { 112 kids.add(index, elements[i]); 113 index++; 114 changed = true; 115 } 116 } 117 } 118 if (changed) { 119 setChildren(getRootNode(), kids); 120 } 121 } 122 123 128 public void remove(Object [] elements) { 129 TableRemoveRequestMonitor update = new TableRemoveRequestMonitor(getRootNode(), elements, this); 130 requestScheduled(update); 131 update.done(); 132 } 133 134 139 protected void removed(Object [] elements) { 140 List kids = null; 141 boolean changed = false; 142 synchronized (this) { 143 ModelNode[] childrenNodes = getRootNode().getChildrenNodes(); 144 if (childrenNodes != null) { 145 kids = new ArrayList (childrenNodes.length); 146 for (int i = 0; i < childrenNodes.length; i++) { 147 kids.add(childrenNodes[i].getElement()); 148 } 149 } 150 for (int i = 0; i < elements.length; i++) { 151 if (kids.remove(elements[i])) { 152 changed = true; 153 } 154 } 155 } 156 if (changed) { 157 setChildren(getRootNode(), kids); 158 } 159 } 160 161 166 public void replace(Object element, Object replacement) { 167 TableReplaceRequestMonitor update = new TableReplaceRequestMonitor(getRootNode(), element, replacement, this); 168 requestScheduled(update); 169 update.done(); 170 } 171 172 177 protected void replaced(Object element, Object replacement) { 178 Object [] filtered = filter(getRootNode().getElement(), new Object [] { replacement }); 179 if (filtered.length == 0) { 180 remove(new Object []{element}); 181 return; 182 } 183 List list = new ArrayList (); 184 synchronized (this) { 185 ModelNode[] nodes = getNodes(element); 186 for (int i = 0; i < nodes.length; i++) { 187 ModelNode node = nodes[i]; 188 node.remap(replacement); 189 list.add(node); 190 } 191 } 192 if (!list.isEmpty()) { 193 Iterator iterator = list.iterator(); 194 while (iterator.hasNext()) { 195 ModelNode node = (ModelNode) iterator.next(); 196 getViewer().nodeChanged(node); 197 } 198 } 199 } 200 } 201 | Popular Tags |