1 11 package org.eclipse.ant.internal.ui.model; 12 13 import com.ibm.icu.text.MessageFormat; 14 import java.util.ArrayList ; 15 import java.util.Iterator ; 16 import java.util.List ; 17 18 import org.eclipse.ant.internal.ui.AntUIPlugin; 19 import org.eclipse.ant.internal.ui.debug.model.AntLineBreakpoint; 20 import org.eclipse.ant.internal.ui.debug.model.DebugModelMessages; 21 import org.eclipse.core.resources.IMarker; 22 import org.eclipse.core.resources.IMarkerDelta; 23 import org.eclipse.core.resources.IWorkspaceRunnable; 24 import org.eclipse.core.resources.ResourcesPlugin; 25 import org.eclipse.core.runtime.CoreException; 26 import org.eclipse.core.runtime.IProgressMonitor; 27 import org.eclipse.debug.core.DebugPlugin; 28 import org.eclipse.debug.core.IBreakpointsListener; 29 import org.eclipse.debug.core.model.IBreakpoint; 30 31 public class AntModelCore implements IBreakpointsListener { 32 33 private static AntModelCore inst; 34 35 public static AntModelCore getDefault() { 36 if (inst == null) { 37 inst= new AntModelCore(); 38 } 39 40 return inst; 41 } 42 43 private List fModelChangeListeners= new ArrayList (); 44 45 private AntModelCore() { } 46 47 public void addAntModelListener(IAntModelListener listener) { 48 synchronized (fModelChangeListeners) { 49 fModelChangeListeners.add(listener); 50 } 51 } 52 53 public void removeAntModelListener(IAntModelListener listener) { 54 synchronized (fModelChangeListeners) { 55 fModelChangeListeners.remove(listener); 56 } 57 } 58 59 public void notifyAntModelListeners(AntModelChangeEvent event) { 60 Iterator i; 61 synchronized (fModelChangeListeners) { 62 i= new ArrayList (fModelChangeListeners).iterator(); 63 } 64 while (i.hasNext()) { 65 ((IAntModelListener)i.next()).antModelChanged(event); 66 } 67 } 68 69 75 private void updateBreakpointMessages(final IBreakpoint[] breakpoints) { 76 IWorkspaceRunnable runnable = new IWorkspaceRunnable() { 77 public void run(IProgressMonitor monitor) throws CoreException { 78 for (int i = 0; i < breakpoints.length; i++) { 79 IBreakpoint breakpoint= breakpoints[i]; 80 if (breakpoint instanceof AntLineBreakpoint) { 81 IMarker marker = breakpoint.getMarker(); 82 if (marker.exists()) { 83 int lineNumber= marker.getAttribute(IMarker.LINE_NUMBER, 0); 84 marker.setAttribute(IMarker.MESSAGE, MessageFormat.format(DebugModelMessages.AntLineBreakpoint_0, new String [] {Integer.toString(lineNumber)})); 85 } 86 } 87 } 88 } 89 }; 90 try { 91 ResourcesPlugin.getWorkspace().run(runnable, null, 0, null); 92 } catch (CoreException e) { 93 AntUIPlugin.log(e); 94 } 95 } 96 97 public void breakpointsAdded(IBreakpoint[] breakpoints) { 98 } 99 100 public void breakpointsRemoved(IBreakpoint[] breakpoints, IMarkerDelta[] deltas) { 101 } 102 103 public void breakpointsChanged(IBreakpoint[] breakpoints, IMarkerDelta[] deltas) { 104 updateBreakpointMessages(breakpoints); 105 } 106 107 public void stopBreakpointListening() { 108 DebugPlugin.getDefault().getBreakpointManager().removeBreakpointListener(this); 109 } 110 111 public void startBreakpointListening() { 112 DebugPlugin.getDefault().getBreakpointManager().addBreakpointListener(this); 113 } 114 } 115 | Popular Tags |