1 11 package org.eclipse.debug.internal.ui.viewers.update; 12 13 import org.eclipse.debug.core.model.IDebugElement; 14 import org.eclipse.debug.core.model.IStackFrame; 15 import org.eclipse.debug.internal.ui.viewers.model.provisional.IModelSelectionPolicy; 16 import org.eclipse.debug.internal.ui.viewers.model.provisional.IPresentationContext; 17 import org.eclipse.debug.ui.IDebugUIConstants; 18 import org.eclipse.jface.viewers.ISelection; 19 import org.eclipse.jface.viewers.IStructuredSelection; 20 21 26 public class DefaultSelectionPolicy implements IModelSelectionPolicy { 27 28 private IDebugElement fDebugElement; 29 30 36 public DefaultSelectionPolicy(IDebugElement element) { 37 fDebugElement = element; 38 } 39 40 43 public boolean contains(ISelection selection, IPresentationContext context) { 44 if (IDebugUIConstants.ID_DEBUG_VIEW.equals(context.getId())) { 45 if (selection instanceof IStructuredSelection) { 46 IStructuredSelection ss = (IStructuredSelection) selection; 47 Object element = ss.getFirstElement(); 48 if (element instanceof IDebugElement) { 49 IDebugElement debugElement = (IDebugElement) element; 50 return fDebugElement.getDebugTarget().equals(debugElement.getDebugTarget()); 51 } 52 } 53 } 54 return false; 55 } 56 57 60 public boolean overrides(ISelection existing, ISelection candidate, IPresentationContext context) { 61 if (IDebugUIConstants.ID_DEBUG_VIEW.equals(context.getId())) { 62 if (existing instanceof IStructuredSelection && candidate instanceof IStructuredSelection) { 63 IStructuredSelection ssExisting = (IStructuredSelection) existing; 64 IStructuredSelection ssCandidate = (IStructuredSelection) candidate; 65 return overrides(ssExisting.getFirstElement(), ssCandidate.getFirstElement()); 66 } 67 } 68 return true; 69 } 70 71 protected boolean overrides(Object existing, Object candidate) { 72 if (existing == null) { 73 return true; 74 } 75 if (existing.equals(candidate)) { 76 return true; 77 } 78 if (existing instanceof IStackFrame && candidate instanceof IStackFrame) { 79 IStackFrame curr = (IStackFrame) existing; 80 IStackFrame next = (IStackFrame) candidate; 81 return curr.getThread().equals(next.getThread()) || !isSticky(existing); 82 } 83 return !isSticky(existing); 84 } 85 86 89 public boolean isSticky(ISelection selection, IPresentationContext context) { 90 if (IDebugUIConstants.ID_DEBUG_VIEW.equals(context.getId())) { 91 if (selection instanceof IStructuredSelection) { 92 return isSticky(((IStructuredSelection)selection).getFirstElement()); 93 } 94 } 95 return false; 96 } 97 98 protected boolean isSticky(Object element) { 99 if (element instanceof IStackFrame) { 100 IStackFrame frame = (IStackFrame) element; 101 return frame.isSuspended(); 102 } 103 return false; 104 } 105 106 109 public ISelection replaceInvalidSelection(ISelection selection, ISelection newSelection) { 110 return newSelection; 111 } 112 } 113 | Popular Tags |