1 11 package org.eclipse.debug.internal.ui.actions.breakpoints; 12 13 14 import java.util.ArrayList ; 15 import java.util.Iterator ; 16 import java.util.List ; 17 18 import org.eclipse.debug.core.ILaunch; 19 import org.eclipse.debug.core.model.IBreakpoint; 20 import org.eclipse.debug.core.model.IDebugElement; 21 import org.eclipse.debug.core.model.IDebugTarget; 22 import org.eclipse.debug.core.model.IProcess; 23 import org.eclipse.debug.internal.ui.DebugPluginImages; 24 import org.eclipse.debug.internal.ui.DebugUIPlugin; 25 import org.eclipse.debug.internal.ui.IDebugHelpContextIds; 26 import org.eclipse.debug.internal.ui.actions.ActionMessages; 27 import org.eclipse.debug.internal.ui.actions.ToggleFilterAction; 28 import org.eclipse.debug.internal.ui.views.breakpoints.BreakpointContainer; 29 import org.eclipse.debug.internal.ui.views.breakpoints.BreakpointsView; 30 import org.eclipse.debug.ui.IDebugUIConstants; 31 import org.eclipse.jface.viewers.ISelection; 32 import org.eclipse.jface.viewers.IStructuredSelection; 33 import org.eclipse.jface.viewers.StructuredViewer; 34 import org.eclipse.jface.viewers.Viewer; 35 import org.eclipse.jface.viewers.ViewerFilter; 36 import org.eclipse.ui.ISelectionListener; 37 import org.eclipse.ui.IViewPart; 38 import org.eclipse.ui.IWorkbenchPart; 39 import org.eclipse.ui.PlatformUI; 40 41 49 public class ShowSupportedBreakpointsAction extends ToggleFilterAction implements ISelectionListener { 50 51 54 private BreakpointsView fView; 55 56 59 private List fDebugTargets= new ArrayList (2); 60 61 65 class BreakpointFilter extends ViewerFilter { 66 67 70 public boolean select(Viewer viewer, Object parentElement, Object element) { 71 if (element instanceof BreakpointContainer) { 72 IBreakpoint[] breakpoints = ((BreakpointContainer) element).getBreakpoints(); 74 for (int i = 0; i < breakpoints.length; i++) { 75 if (select(viewer, element, breakpoints[i])) { 76 return true; 77 } 78 } 79 return false; 80 } 81 IBreakpoint breakpoint= (IBreakpoint)element; 82 if (fDebugTargets.isEmpty()) { 83 return true; 84 } 85 Iterator iterator= fDebugTargets.iterator(); 86 while (iterator.hasNext()) { 87 IDebugTarget target = (IDebugTarget) iterator.next(); 88 if (target.supportsBreakpoint(breakpoint)) { 89 return true; 90 } 91 92 } 93 return false; 94 } 95 96 } 97 98 public ShowSupportedBreakpointsAction(StructuredViewer viewer, IViewPart view) { 99 super(); 100 setText(ActionMessages.ShowSupportedBreakpointsAction_Show_For_Selected); 101 setToolTipText(ActionMessages.ShowSupportedBreakpointsAction_tooltip); 102 setViewerFilter(new BreakpointFilter()); 103 setViewer(viewer); 104 setImageDescriptor(DebugPluginImages.getImageDescriptor(IDebugUIConstants.IMG_OBJS_DEBUG_TARGET)); 105 setChecked(false); 106 setId(DebugUIPlugin.getUniqueIdentifier() + ".ShowSupportedBreakpointsAction"); 108 setView(view); 109 PlatformUI.getWorkbench().getHelpSystem().setHelp( 110 this, 111 IDebugHelpContextIds.SHOW_BREAKPOINTS_FOR_MODEL_ACTION); 112 113 } 114 115 116 117 public void dispose() { 118 if (isChecked()) { 119 getView().getSite().getPage().removeSelectionListener(IDebugUIConstants.ID_DEBUG_VIEW, this); 120 } 121 } 122 123 126 public void selectionChanged(IWorkbenchPart part, ISelection selection) { 127 if (selection instanceof IStructuredSelection) { 128 IStructuredSelection ss= (IStructuredSelection)selection; 129 List debugTargets= getDebugTargets(ss); 130 if (!isChecked()) { 131 fDebugTargets= debugTargets; 132 return; 133 } 134 if (debugTargets.isEmpty()) { 135 if(fDebugTargets.isEmpty()) { 136 return; 137 } 138 reapplyFilters(debugTargets); 139 return; 140 } 141 if (fDebugTargets.isEmpty()) { 142 reapplyFilters(debugTargets); 143 return; 144 } 145 146 if (debugTargets.size() == fDebugTargets.size()) { 147 List copy= new ArrayList (debugTargets.size()); 148 Iterator iter= fDebugTargets.iterator(); 149 while (iter.hasNext()) { 150 IDebugTarget target = (IDebugTarget) iter.next(); 151 Iterator newDebugTargets= debugTargets.iterator(); 152 while (newDebugTargets.hasNext()) { 153 IDebugTarget newTarget= (IDebugTarget)newDebugTargets.next(); 154 copy.add(newTarget); 155 if (target.equals(newTarget)) { 156 newDebugTargets.remove(); 157 } 158 } 159 } 160 if (debugTargets.isEmpty()) { 162 return; 163 } 164 reapplyFilters(copy); 165 } 166 } 167 } 168 169 170 174 protected void reapplyFilters(List debugTargets) { 175 fDebugTargets= debugTargets; 176 getViewer().refresh(); 177 } 178 179 protected IViewPart getView() { 180 return fView; 181 } 182 183 protected void setView(IViewPart view) { 184 fView = (BreakpointsView) view; 185 } 186 187 protected List getDebugTargets(IStructuredSelection ss) { 188 List debugTargets= new ArrayList (2); 189 Iterator i= ss.iterator(); 190 while (i.hasNext()) { 191 Object next= i.next(); 192 if (next instanceof IDebugElement) { 193 debugTargets.add(((IDebugElement)next).getDebugTarget()); 194 } else if (next instanceof ILaunch) { 195 IDebugTarget[] targets= ((ILaunch)next).getDebugTargets(); 196 for (int j = 0; j < targets.length; j++) { 197 debugTargets.add(targets[j]); 198 } 199 } else if (next instanceof IProcess) { 200 IDebugTarget target= (IDebugTarget)((IProcess)next).getAdapter(IDebugTarget.class); 201 if (target != null) { 202 debugTargets.add(target); 203 } 204 } 205 } 206 return debugTargets; 207 } 208 209 213 protected void valueChanged(boolean on) { 214 if (getViewer().getControl().isDisposed()) { 215 return; 216 } 217 if (on) { 218 getView().getSite().getPage().addSelectionListener(IDebugUIConstants.ID_DEBUG_VIEW, this); 219 ISelection selection= getView().getSite().getPage().getSelection(IDebugUIConstants.ID_DEBUG_VIEW); 220 selectionChanged(null, selection); 221 } else { 222 getView().getSite().getPage().removeSelectionListener(IDebugUIConstants.ID_DEBUG_VIEW, this); 223 } 224 super.valueChanged(on); 225 fView.getViewer().refresh(); 226 } 227 228 } 229 | Popular Tags |