1 11 package org.eclipse.debug.internal.ui.viewers; 12 13 import org.eclipse.debug.internal.ui.viewers.model.provisional.IModelChangedListener; 14 import org.eclipse.debug.internal.ui.viewers.model.provisional.IModelDelta; 15 import org.eclipse.debug.internal.ui.viewers.model.provisional.IModelProxy; 16 import org.eclipse.jface.viewers.StructuredSelection; 17 18 23 public class TableUpdatePolicy extends org.eclipse.debug.internal.ui.viewers.AbstractUpdatePolicy implements IModelChangedListener { 24 25 public void modelChanged(IModelDelta delta, IModelProxy proxy) { 26 updateNodes(new IModelDelta[] {delta}); 27 } 28 29 private void handleState(IModelDelta node) { 30 AsynchronousViewer viewer = getViewer(); 31 if (viewer != null) { 32 Object element = node.getElement(); 33 viewer.update(element); 34 updateSelection(element, node.getFlags()); 35 } 36 } 37 private void handleContent(IModelDelta node) { 38 AsynchronousViewer viewer = getViewer(); 39 if (viewer != null) { 40 Object element = node.getElement(); 41 viewer.refresh(element); 42 updateSelection(element, node.getFlags()); 43 } 44 } 45 46 private void updateSelection(Object element, int flags) { 47 AsynchronousViewer viewer = getViewer(); 48 if (viewer != null) { 49 if ((flags & IModelDelta.SELECT) != 0) { 50 getViewer().setSelection(new StructuredSelection(element)); 51 } 52 } 53 } 54 55 protected void updateNodes(IModelDelta[] nodes) { 56 for (int i = 0; i < nodes.length; i++) { 57 IModelDelta node = nodes[i]; 58 int flags = node.getFlags(); 59 60 if ((flags & IModelDelta.STATE) != 0) { 61 handleState(node); 62 } 63 if ((flags & IModelDelta.CONTENT) != 0) { 64 handleContent(node); 65 } 66 if ((flags & IModelDelta.ADDED) != 0) { 67 handleAdd(node); 68 } 69 if ((flags & IModelDelta.REMOVED) != 0) { 70 handleRemove(node); 71 } 72 if ((flags & IModelDelta.REPLACED) != 0) { 73 handleReplace(node); 74 } 75 if ((flags & IModelDelta.INSERTED) != 0) { 76 handleInsert(node); 77 } 78 79 IModelDelta[] childNodes = node.getChildDeltas(); 80 updateNodes(childNodes); 81 } 82 } 83 84 private void handleInsert(IModelDelta node) { 85 AsynchronousTableViewer viewer = (AsynchronousTableViewer) getViewer(); 86 if (viewer != null) { 87 viewer.insert(node.getElement(), node.getIndex()); 88 updateSelection(node.getElement(), node.getFlags()); 89 } 90 } 91 92 private void handleReplace(IModelDelta node) { 93 AsynchronousTableViewer viewer = (AsynchronousTableViewer) getViewer(); 94 if (viewer != null) { 95 viewer.replace(node.getElement(), node.getReplacementElement()); 96 updateSelection(node.getReplacementElement(), node.getFlags()); 97 } 98 } 99 100 protected void handleAdd(IModelDelta node) { 101 ((AsynchronousTableViewer) getViewer()).add(node.getElement()); 102 updateSelection(node.getElement(), node.getFlags()); 103 } 104 105 protected void handleRemove(IModelDelta node) { 106 ((AsynchronousTableViewer) getViewer()).remove(node.getElement()); 107 } 108 } 109 | Popular Tags |