1 11 package org.eclipse.debug.internal.ui.viewers; 12 13 import java.util.ArrayList ; 14 15 import org.eclipse.debug.internal.ui.viewers.provisional.IModelChangedListener; 16 import org.eclipse.debug.internal.ui.viewers.provisional.IModelDelta; 17 import org.eclipse.jface.viewers.TreePath; 18 import org.eclipse.jface.viewers.TreeSelection; 19 20 25 public class TreeUpdatePolicy extends AbstractUpdatePolicy implements IModelChangedListener { 26 27 private TreePath fTreePath; 29 private IModelDelta fNode; 30 31 public void modelChanged(IModelDelta delta) { 32 updateNodes(new IModelDelta[] { delta }); 33 fTreePath = null; 34 fNode = null; 35 } 36 37 protected void updateNodes(IModelDelta[] nodes) { 38 AsynchronousTreeViewer viewer = (AsynchronousTreeViewer) getViewer(); 39 if (viewer == null) { 40 return; 41 } 42 43 for (int i = 0; i < nodes.length; i++) { 44 IModelDelta node = nodes[i]; 45 int flags = node.getFlags(); 46 47 if ((flags & IModelDelta.ADDED) != 0) { 48 handleAdd(viewer, node); 49 } 50 if ((flags & IModelDelta.REMOVED) != 0) { 51 handleRemove(viewer, node); 52 } 53 if ((flags & IModelDelta.CONTENT) != 0) { 54 handleContent(viewer, node); 55 } 56 if ((flags & IModelDelta.EXPAND) != 0) { 57 handleExpand(viewer, node); 58 } 59 if ((flags & IModelDelta.SELECT) != 0) { 60 handleSelect(viewer, node); 61 } 62 if ((flags & IModelDelta.STATE) != 0) { 63 handleState(viewer, node); 64 } 65 if ((flags & IModelDelta.INSERTED) != 0) { 66 } 68 if ((flags & IModelDelta.REPLACED) != 0) { 69 } 71 72 updateNodes(node.getNodes()); 73 } 74 } 75 76 protected void handleState(AsynchronousTreeViewer viewer, IModelDelta delta) { 77 viewer.update(delta.getElement()); 78 } 79 80 protected void handleSelect(AsynchronousTreeViewer viewer, IModelDelta delta) { 81 viewer.setSelection(new TreeSelection(getTreePath(delta))); 82 } 83 84 protected void handleExpand(AsynchronousTreeViewer viewer, IModelDelta delta) { 85 viewer.expand(new TreeSelection(getTreePath(delta))); 86 } 87 88 protected void handleContent(AsynchronousTreeViewer viewer, IModelDelta delta) { 89 viewer.refresh(delta.getElement()); 90 } 91 92 protected void handleRemove(AsynchronousTreeViewer viewer, IModelDelta delta) { 93 viewer.remove(getTreePath(delta)); 94 } 95 96 protected void handleAdd(AsynchronousTreeViewer viewer, IModelDelta delta) { 97 viewer.add(getTreePath(delta)); 98 } 99 100 protected TreePath getTreePath(IModelDelta node) { 101 if (node != fNode) { 102 ArrayList list = new ArrayList (); 103 list.add(0, node.getElement()); 104 while (node.getParent() != null) { 105 node = node.getParent(); 106 list.add(0, node.getElement()); 107 } 108 109 fTreePath = new TreePath(list.toArray()); 110 fNode = node; 111 } 112 return fTreePath; 113 } 114 115 } 116 | Popular Tags |