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