1 11 package org.eclipse.debug.internal.ui.viewers.update; 12 13 import java.util.HashSet ; 14 import java.util.Set ; 15 16 import org.eclipse.debug.core.DebugPlugin; 17 import org.eclipse.debug.core.ILaunch; 18 import org.eclipse.debug.core.ILaunchManager; 19 import org.eclipse.debug.core.ILaunchesListener2; 20 import org.eclipse.debug.internal.ui.viewers.model.provisional.IModelDelta; 21 import org.eclipse.debug.internal.ui.viewers.model.provisional.IPresentationContext; 22 import org.eclipse.debug.internal.ui.viewers.model.provisional.ModelDelta; 23 import org.eclipse.debug.internal.ui.viewers.provisional.AbstractModelProxy; 24 import org.eclipse.jface.viewers.Viewer; 25 26 31 public class LaunchProxy extends AbstractModelProxy implements ILaunchesListener2 { 32 33 private ILaunch fLaunch; 34 35 39 private Set fPrevChildren = new HashSet (); 40 41 46 public LaunchProxy(ILaunch launch) { 47 fLaunch = launch; 48 } 49 50 53 public void init(IPresentationContext context) { 54 super.init(context); 55 DebugPlugin.getDefault().getLaunchManager().addLaunchListener(this); 56 } 57 58 61 public void installed(Viewer viewer) { 62 installModelProxies(); 64 } 65 66 69 public void dispose() { 70 super.dispose(); 71 DebugPlugin.getDefault().getLaunchManager().removeLaunchListener(this); 72 fPrevChildren.clear(); 73 fLaunch = null; 74 } 75 76 79 public void launchesTerminated(ILaunch[] launches) { 80 for (int i = 0; i < launches.length; i++) { 81 if (launches[i] == fLaunch) { 82 fireDelta(IModelDelta.STATE | IModelDelta.CONTENT | IModelDelta.UNINSTALL); 83 } 84 } 85 } 86 87 90 public void launchesRemoved(ILaunch[] launches) { 91 } 92 93 96 public void launchesAdded(ILaunch[] launches) { 97 } 98 99 102 public void launchesChanged(ILaunch[] launches) { 103 for (int i = 0; i < launches.length; i++) { 104 if (launches[i] == fLaunch) { 105 fireDelta(IModelDelta.STATE | IModelDelta.CONTENT); 106 installModelProxies(); 107 } 108 } 109 } 110 111 116 protected void installModelProxies() { 117 boolean changes = false; 118 ILaunchManager manager = DebugPlugin.getDefault().getLaunchManager(); 119 ILaunch[] allLaunches = manager.getLaunches(); 120 ModelDelta root = new ModelDelta(manager, 0, IModelDelta.NO_CHANGE, allLaunches.length); 121 Object [] children = fLaunch.getChildren(); 122 ModelDelta launchDelta = root.addNode(fLaunch, indexOf(fLaunch, allLaunches), IModelDelta.EXPAND, children.length); 123 for (int j = 0; j < children.length; j++) { 124 Object child = children[j]; 125 if (fPrevChildren.add(child)) { 126 changes = true; 127 launchDelta.addNode(child, indexOf(child, children), IModelDelta.INSTALL, -1); 128 } 129 } 130 if (changes) { 131 fireModelChanged(root); 132 } 133 } 134 135 141 protected int indexOf(Object element, Object [] list) { 142 for (int i = 0; i < list.length; i++) { 143 if (element == list[i]) { 144 return i; 145 } 146 } 147 return -1; 148 } 149 150 154 protected void fireDelta(int flags) { 155 ModelDelta delta = new ModelDelta(DebugPlugin.getDefault().getLaunchManager(), IModelDelta.NO_CHANGE); 156 delta.addNode(fLaunch, flags); 157 fireModelChanged(delta); 158 } 159 160 } 161 | Popular Tags |