1 11 package org.eclipse.debug.core.model; 12 13 14 import java.util.Map ; 15 16 import org.eclipse.core.resources.IMarker; 17 import org.eclipse.core.resources.IResource; 18 import org.eclipse.core.resources.IResourceRuleFactory; 19 import org.eclipse.core.resources.IWorkspace; 20 import org.eclipse.core.resources.IWorkspaceRunnable; 21 import org.eclipse.core.resources.ResourcesPlugin; 22 import org.eclipse.core.runtime.CoreException; 23 import org.eclipse.core.runtime.IProgressMonitor; 24 import org.eclipse.core.runtime.IStatus; 25 import org.eclipse.core.runtime.PlatformObject; 26 import org.eclipse.core.runtime.Status; 27 import org.eclipse.core.runtime.jobs.ISchedulingRule; 28 import org.eclipse.debug.core.DebugException; 29 import org.eclipse.debug.core.DebugPlugin; 30 import org.eclipse.debug.core.IBreakpointManager; 31 import org.eclipse.debug.internal.core.DebugCoreMessages; 32 33 41 42 public abstract class Breakpoint extends PlatformObject implements IBreakpoint { 43 44 static { 45 DebugPlugin.getDefault().getBreakpointManager().getBreakpoints(); 48 } 49 50 53 private IMarker fMarker= null; 54 55 58 public void setMarker(IMarker marker) throws CoreException { 59 fMarker= marker; 60 } 61 62 65 public boolean equals(Object item) { 66 if (item instanceof IBreakpoint) { 67 return getMarker().equals(((IBreakpoint)item).getMarker()); 68 } 69 return false; 70 } 71 72 75 public int hashCode() { 76 return getMarker().hashCode(); 77 } 78 79 82 public void setEnabled(boolean enabled) throws CoreException { 83 if (enabled != isEnabled()) { 84 setAttribute(ENABLED, enabled); 85 } 86 } 87 88 91 public boolean isEnabled() throws CoreException { 92 return getMarker().getAttribute(ENABLED, false); 93 } 94 95 98 public boolean isRegistered() throws CoreException { 99 IMarker marker= getMarker(); 100 return marker.exists() && marker.getAttribute(REGISTERED, true); 101 } 102 103 106 public void setRegistered(boolean registered) throws CoreException { 107 if (isRegistered() != registered) { 108 setAttribute(REGISTERED, registered); 109 IBreakpointManager mgr = DebugPlugin.getDefault().getBreakpointManager(); 110 if (registered) { 111 mgr.addBreakpoint(this); 112 } else { 113 mgr.removeBreakpoint(this, false); 114 } 115 } 116 } 117 118 121 public void delete() throws CoreException { 122 DebugPlugin.getDefault().getBreakpointManager().removeBreakpoint(this, false); 123 getMarker().delete(); 124 } 125 126 129 public IMarker getMarker() { 130 return fMarker; 131 } 132 133 136 public boolean isPersisted() throws CoreException { 137 return getMarker().getAttribute(PERSISTED, true); 138 } 139 140 143 public void setPersisted(boolean persisted) throws CoreException { 144 if (isPersisted() != persisted) { 145 setAttributes(new String [] {PERSISTED, IMarker.TRANSIENT}, new Object [] {Boolean.valueOf(persisted), Boolean.valueOf(!persisted)}); 146 } 147 } 148 149 160 protected void setAttribute(final String attributeName, final boolean value) throws CoreException { 161 IWorkspace workspace= ResourcesPlugin.getWorkspace(); 162 IWorkspaceRunnable runnable= new IWorkspaceRunnable() { 163 public void run(IProgressMonitor monitor) throws CoreException { 164 ensureMarker().setAttribute(attributeName, value); 165 } 166 }; 167 168 workspace.run(runnable, getMarkerRule(), 0, null); 169 } 170 171 182 protected void setAttribute(final String attributeName, final int value) throws CoreException { 183 IWorkspace workspace= ResourcesPlugin.getWorkspace(); 184 IWorkspaceRunnable runnable= new IWorkspaceRunnable() { 185 public void run(IProgressMonitor monitor) throws CoreException { 186 ensureMarker().setAttribute(attributeName, value); 187 } 188 }; 189 190 workspace.run(runnable, getMarkerRule(), 0, null); 191 } 192 193 204 protected void setAttribute(final String attributeName, final Object value) throws CoreException { 205 IWorkspace workspace= ResourcesPlugin.getWorkspace(); 206 IWorkspaceRunnable runnable= new IWorkspaceRunnable() { 207 public void run(IProgressMonitor monitor) throws CoreException { 208 ensureMarker().setAttribute(attributeName, value); 209 } 210 }; 211 212 workspace.run(runnable, getMarkerRule(), 0, null); 213 } 214 215 226 protected void setAttributes(final String [] attributeNames, final Object [] values) throws CoreException { 227 IWorkspace workspace= ResourcesPlugin.getWorkspace(); 228 IWorkspaceRunnable runnable= new IWorkspaceRunnable() { 229 public void run(IProgressMonitor monitor) throws CoreException { 230 ensureMarker().setAttributes(attributeNames, values); 231 } 232 }; 233 234 workspace.run(runnable, getMarkerRule(), IWorkspace.AVOID_UPDATE, null); 235 } 236 237 247 protected void setAttributes(final Map attributes) throws CoreException{ 248 IWorkspace workspace= ResourcesPlugin.getWorkspace(); 249 IWorkspaceRunnable runnable= new IWorkspaceRunnable() { 250 public void run(IProgressMonitor monitor) throws CoreException { 251 ensureMarker().setAttributes(attributes); 252 } 253 }; 254 255 workspace.run(runnable, getMarkerRule(), IWorkspace.AVOID_UPDATE, null); 256 } 257 258 265 protected IMarker ensureMarker() throws DebugException { 266 IMarker m = getMarker(); 267 if (m == null || !m.exists()) { 268 throw new DebugException(new Status(IStatus.ERROR, DebugPlugin.getUniqueIdentifier(), DebugException.REQUEST_FAILED, 269 DebugCoreMessages.Breakpoint_no_associated_marker, null)); 270 } 271 return m; 272 } 273 274 280 protected boolean markerExists() { 281 IMarker m = getMarker(); 282 return (m != null && m.exists()); 283 } 284 285 294 protected ISchedulingRule getMarkerRule(IResource resource) { 295 ISchedulingRule rule = null; 296 if (resource != null) { 297 IResourceRuleFactory ruleFactory = ResourcesPlugin.getWorkspace().getRuleFactory(); 298 rule = ruleFactory.markerRule(resource); 299 } 300 return rule; 301 } 302 303 312 protected ISchedulingRule getMarkerRule() { 313 ISchedulingRule rule = null; 314 IMarker marker = getMarker(); 315 if (marker != null) { 316 IResource resource = marker.getResource(); 317 if (resource != null) { 318 IResourceRuleFactory ruleFactory = ResourcesPlugin.getWorkspace().getRuleFactory(); 319 rule = ruleFactory.markerRule(resource); 320 } 321 } 322 return rule; 323 } 324 325 333 protected void run(ISchedulingRule rule, IWorkspaceRunnable wr) throws DebugException { 334 try { 335 ResourcesPlugin.getWorkspace().run(wr, rule, 0, null); 336 } catch (CoreException e) { 337 throw new DebugException(e.getStatus()); 338 } 339 } 340 341 } 342 | Popular Tags |