1 11 package org.eclipse.debug.internal.ui.views.launch; 12 13 14 import java.util.Iterator ; 15 16 import org.eclipse.core.runtime.IAdaptable; 17 import org.eclipse.core.runtime.IProgressMonitor; 18 import org.eclipse.core.runtime.IStatus; 19 import org.eclipse.core.runtime.MultiStatus; 20 import org.eclipse.core.runtime.Status; 21 import org.eclipse.core.runtime.jobs.Job; 22 import org.eclipse.debug.core.DebugException; 23 import org.eclipse.debug.core.DebugPlugin; 24 import org.eclipse.debug.core.ILaunch; 25 import org.eclipse.debug.core.ILaunchManager; 26 import org.eclipse.debug.core.model.IDebugElement; 27 import org.eclipse.debug.core.model.IDebugTarget; 28 import org.eclipse.debug.core.model.IProcess; 29 import org.eclipse.debug.core.model.IStackFrame; 30 import org.eclipse.debug.core.model.ITerminate; 31 import org.eclipse.debug.internal.ui.DebugUIPlugin; 32 import org.eclipse.debug.internal.ui.DelegatingModelPresentation; 33 import org.eclipse.debug.internal.ui.IDebugHelpContextIds; 34 import org.eclipse.debug.internal.ui.actions.AddToFavoritesAction; 35 import org.eclipse.debug.internal.ui.actions.EditLaunchConfigurationAction; 36 import org.eclipse.debug.internal.ui.commands.actions.DebugCommandAction; 37 import org.eclipse.debug.internal.ui.commands.actions.DisconnectCommandAction; 38 import org.eclipse.debug.internal.ui.commands.actions.DropToFrameCommandAction; 39 import org.eclipse.debug.internal.ui.commands.actions.ResumeCommandAction; 40 import org.eclipse.debug.internal.ui.commands.actions.StepIntoCommandAction; 41 import org.eclipse.debug.internal.ui.commands.actions.StepOverCommandAction; 42 import org.eclipse.debug.internal.ui.commands.actions.StepReturnCommandAction; 43 import org.eclipse.debug.internal.ui.commands.actions.SuspendCommandAction; 44 import org.eclipse.debug.internal.ui.commands.actions.TerminateAllAction; 45 import org.eclipse.debug.internal.ui.commands.actions.TerminateAndRelaunchAction; 46 import org.eclipse.debug.internal.ui.commands.actions.TerminateAndRemoveAction; 47 import org.eclipse.debug.internal.ui.commands.actions.TerminateCommandAction; 48 import org.eclipse.debug.internal.ui.commands.actions.ToggleStepFiltersAction; 49 import org.eclipse.debug.internal.ui.sourcelookup.EditSourceLookupPathAction; 50 import org.eclipse.debug.internal.ui.sourcelookup.LookupSourceAction; 51 import org.eclipse.debug.internal.ui.viewers.model.InternalTreeModelViewer; 52 import org.eclipse.debug.internal.ui.viewers.model.VirtualFindAction; 53 import org.eclipse.debug.internal.ui.viewers.model.provisional.IModelChangedListener; 54 import org.eclipse.debug.internal.ui.viewers.model.provisional.IModelDelta; 55 import org.eclipse.debug.internal.ui.viewers.model.provisional.IModelDeltaVisitor; 56 import org.eclipse.debug.internal.ui.viewers.model.provisional.IModelProxy; 57 import org.eclipse.debug.internal.ui.viewers.model.provisional.TreeModelViewer; 58 import org.eclipse.debug.internal.ui.views.DebugModelPresentationContext; 59 import org.eclipse.debug.internal.ui.views.DebugUIViewsMessages; 60 import org.eclipse.debug.ui.AbstractDebugView; 61 import org.eclipse.debug.ui.DebugUITools; 62 import org.eclipse.debug.ui.IDebugModelPresentation; 63 import org.eclipse.debug.ui.IDebugUIConstants; 64 import org.eclipse.debug.ui.contexts.AbstractDebugContextProvider; 65 import org.eclipse.debug.ui.contexts.DebugContextEvent; 66 import org.eclipse.jface.action.GroupMarker; 67 import org.eclipse.jface.action.IMenuManager; 68 import org.eclipse.jface.action.IToolBarManager; 69 import org.eclipse.jface.action.Separator; 70 import org.eclipse.jface.dialogs.MessageDialog; 71 import org.eclipse.jface.viewers.DoubleClickEvent; 72 import org.eclipse.jface.viewers.ISelection; 73 import org.eclipse.jface.viewers.ISelectionChangedListener; 74 import org.eclipse.jface.viewers.IStructuredSelection; 75 import org.eclipse.jface.viewers.SelectionChangedEvent; 76 import org.eclipse.jface.viewers.StructuredViewer; 77 import org.eclipse.jface.viewers.TreeSelection; 78 import org.eclipse.jface.viewers.Viewer; 79 import org.eclipse.swt.SWT; 80 import org.eclipse.swt.events.KeyAdapter; 81 import org.eclipse.swt.events.KeyEvent; 82 import org.eclipse.swt.widgets.Composite; 83 import org.eclipse.ui.IMemento; 84 import org.eclipse.ui.IPageListener; 85 import org.eclipse.ui.IPartListener2; 86 import org.eclipse.ui.IPerspectiveDescriptor; 87 import org.eclipse.ui.IPerspectiveListener2; 88 import org.eclipse.ui.IViewSite; 89 import org.eclipse.ui.IWorkbenchActionConstants; 90 import org.eclipse.ui.IWorkbenchPage; 91 import org.eclipse.ui.IWorkbenchPart; 92 import org.eclipse.ui.IWorkbenchPartReference; 93 import org.eclipse.ui.IWorkbenchWindow; 94 import org.eclipse.ui.PartInitException; 95 import org.eclipse.ui.actions.SelectionListenerAction; 96 import org.eclipse.ui.dialogs.PropertyDialogAction; 97 import org.eclipse.ui.part.IShowInSource; 98 import org.eclipse.ui.part.IShowInTarget; 99 import org.eclipse.ui.part.IShowInTargetList; 100 import org.eclipse.ui.part.ShowInContext; 101 import org.eclipse.ui.progress.UIJob; 102 103 public class LaunchView extends AbstractDebugView implements ISelectionChangedListener, IPerspectiveListener2, IPageListener, IShowInTarget, IShowInSource, IShowInTargetList, IPartListener2 { 104 105 public static final String ID_CONTEXT_ACTIVITY_BINDINGS = "contextActivityBindings"; 107 private static final String TERMINATE = "terminate"; 109 private static final String DISCONNECT = "disconnect"; 111 private static final String SUSPEND = "suspend"; 113 private static final String RESUME = "resume"; 115 private static final String STEP_RETURN = "step_return"; 117 private static final String STEP_OVER = "step_over"; 119 private static final String DROP_TO_FRAME = "drop_to_frame"; 121 private static final String STEP_INTO = "step_into"; 123 private static final String TERMINATE_AND_REMOVE = "terminate_and_remove"; 125 private static final String TERMINATE_ALL = "terminate_all"; 127 private static final String TERMINATE_AND_RELAUNCH = "terminate_relaunch"; 129 private static final String TOGGLE_STEP_FILTERS = "toggle_step_filters"; 131 134 private boolean fIsActive = true; 135 136 139 private IDebugModelPresentation fPresentation = null; 140 141 private EditLaunchConfigurationAction fEditConfigAction = null; 142 private AddToFavoritesAction fAddToFavoritesAction = null; 143 private EditSourceLookupPathAction fEditSourceAction = null; 144 private LookupSourceAction fLookupAction = null; 145 146 class ContextProvider extends AbstractDebugContextProvider implements IModelChangedListener { 147 148 private ISelection fContext = null; 149 private TreeModelViewer fViewer = null; 150 private Visitor fVisitor = new Visitor(); 151 152 class Visitor implements IModelDeltaVisitor { 153 public boolean visit(IModelDelta delta, int depth) { 154 Object element = delta.getElement(); 155 if ((delta.getFlags() & (IModelDelta.STATE | IModelDelta.CONTENT)) > 0) { 156 if ((delta.getFlags() & IModelDelta.SELECT) == 0) { 158 if ((delta.getFlags() & IModelDelta.CONTENT) > 0) { 160 possibleChange(element, DebugContextEvent.ACTIVATED); 162 } else if ((delta.getFlags() & IModelDelta.STATE) > 0) { 163 possibleChange(element, DebugContextEvent.STATE); 165 } 166 } 167 } 168 return true; 169 } 170 } 171 172 public ContextProvider(TreeModelViewer viewer) { 173 super(LaunchView.this); 174 fViewer = viewer; 175 fViewer.addModelChangedListener(this); 176 } 177 178 protected void dispose() { 179 fContext = null; 180 fViewer.removeModelChangedListener(this); 181 } 182 183 186 public synchronized ISelection getActiveContext() { 187 return fContext; 188 } 189 190 protected void activate(ISelection selection) { 191 synchronized (this) { 192 fContext = selection; 193 } 194 fire(new DebugContextEvent(this, selection, DebugContextEvent.ACTIVATED)); 195 } 196 197 protected void possibleChange(Object element, int type) { 198 DebugContextEvent event = null; 199 synchronized (this) { 200 if (fContext instanceof IStructuredSelection) { 201 IStructuredSelection ss = (IStructuredSelection) fContext; 202 if (!(ss.size() == 1 && ss.getFirstElement().equals(element))) { 203 return; 204 } 205 } else { 206 return; 207 } 208 event = new DebugContextEvent(this, fContext, type); 209 } 210 if (getControl().getDisplay().getThread() == Thread.currentThread()) { 211 fire(event); 212 } else { 213 final DebugContextEvent finalEvent = event; 214 Job job = new UIJob("context change") { public IStatus runInUIThread(IProgressMonitor monitor) { 216 synchronized (ContextProvider.this) { 218 if (fContext instanceof IStructuredSelection) { 219 IStructuredSelection ss = (IStructuredSelection) fContext; 220 Object changed = ((IStructuredSelection)finalEvent.getContext()).getFirstElement(); 221 if (!(ss.size() == 1 && ss.getFirstElement().equals(changed))) { 222 return Status.OK_STATUS; 223 } 224 } 225 } 226 fire(finalEvent); 227 return Status.OK_STATUS; 228 } 229 }; 230 job.setSystem(true); 231 job.schedule(); 232 } 233 } 234 235 238 public void modelChanged(IModelDelta delta, IModelProxy proxy) { 239 delta.accept(fVisitor); 240 } 241 242 } 243 244 247 private ContextProvider fProvider; 248 249 252 protected String getHelpContextId() { 253 return IDebugHelpContextIds.DEBUG_VIEW; 254 } 255 256 259 protected void createActions() { 260 setAction("Properties", new PropertyDialogAction(getSite(), getSite().getSelectionProvider())); fEditConfigAction = new EditLaunchConfigurationAction(); 262 fAddToFavoritesAction = new AddToFavoritesAction(); 263 fEditSourceAction = new EditSourceLookupPathAction(this); 264 fLookupAction = new LookupSourceAction(this); 265 setAction(FIND_ACTION, new VirtualFindAction((InternalTreeModelViewer) getViewer())); 266 267 addCapabilityAction(new TerminateCommandAction(), TERMINATE); 268 addCapabilityAction(new DisconnectCommandAction(), DISCONNECT); 269 addCapabilityAction(new SuspendCommandAction(), SUSPEND); 270 addCapabilityAction(new ResumeCommandAction(), RESUME); 271 addCapabilityAction(new StepReturnCommandAction(), STEP_RETURN); 272 addCapabilityAction(new StepOverCommandAction(), STEP_OVER); 273 addCapabilityAction(new StepIntoCommandAction(), STEP_INTO); 274 addCapabilityAction(new DropToFrameCommandAction(), DROP_TO_FRAME); 275 addCapabilityAction(new TerminateAndRemoveAction(), TERMINATE_AND_REMOVE); 276 addCapabilityAction(new TerminateAndRelaunchAction(), TERMINATE_AND_RELAUNCH); 277 addCapabilityAction(new TerminateAllAction(), TERMINATE_ALL); 278 addCapabilityAction(new ToggleStepFiltersAction(), TOGGLE_STEP_FILTERS); 279 } 280 281 282 288 private void addCapabilityAction(DebugCommandAction capability, String actionID) { 289 capability.init(this); 290 setAction(actionID, capability); 291 } 292 293 298 private void disposeCommandAction(String actionID) { 299 DebugCommandAction action = (DebugCommandAction) getAction(actionID); 300 action.dispose(); 301 } 302 303 306 protected Viewer createViewer(Composite parent) { 307 fPresentation = new DelegatingModelPresentation(); 308 TreeModelViewer viewer = new TreeModelViewer(parent, 309 SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.VIRTUAL, 310 new DebugModelPresentationContext(IDebugUIConstants.ID_DEBUG_VIEW, fPresentation)); 311 312 viewer.addSelectionChangedListener(this); 313 viewer.getControl().addKeyListener(new KeyAdapter() { 314 public void keyPressed(KeyEvent event) { 315 if (event.character == SWT.DEL && event.stateMask == 0) { 316 handleDeleteKeyPressed(); 317 } 318 } 319 }); 320 getSite().setSelectionProvider(viewer); 322 viewer.setInput(DebugPlugin.getDefault().getLaunchManager()); 323 fProvider = new ContextProvider(viewer); 325 DebugUITools.getDebugContextManager().getContextService(getSite().getWorkbenchWindow()).addDebugContextProvider(fProvider); 326 return viewer; 327 } 328 329 private void handleDeleteKeyPressed() { 330 IStructuredSelection selection= (IStructuredSelection) getViewer().getSelection(); 331 Iterator iter= selection.iterator(); 332 Object item; 333 boolean itemsToTerminate= false; 334 ITerminate terminable; 335 while (iter.hasNext()) { 336 item= iter.next(); 337 if (item instanceof ITerminate) { 338 terminable= (ITerminate) item; 339 if (terminable.canTerminate() && !terminable.isTerminated()) { 340 itemsToTerminate= true; 341 break; 342 } 343 } 344 } 345 if (itemsToTerminate) { 346 if (!MessageDialog.openQuestion(getSite().getShell(), DebugUIViewsMessages.LaunchView_Terminate_and_Remove_1, DebugUIViewsMessages.LaunchView_Terminate_and_remove_selected__2)) { 348 return; 349 } 350 } 351 MultiStatus status= new MultiStatus(DebugUIPlugin.getUniqueIdentifier(), DebugException.REQUEST_FAILED, DebugUIViewsMessages.LaunchView_Exceptions_occurred_attempting_to_terminate_and_remove_3, null); 352 iter= selection.iterator(); 353 while (iter.hasNext()) { 354 try { 355 terminateAndRemove(iter.next()); 356 } catch (DebugException exception) { 357 status.merge(exception.getStatus()); 358 } 359 } 360 if (!status.isOK()) { 361 IWorkbenchWindow window= DebugUIPlugin.getActiveWorkbenchWindow(); 362 if (window != null) { 363 DebugUIPlugin.errorDialog(window.getShell(), DebugUIViewsMessages.LaunchView_Terminate_and_Remove_4, DebugUIViewsMessages.LaunchView_Terminate_and_remove_failed_5, status); 364 } else { 365 DebugUIPlugin.log(status); 366 } 367 } 368 } 369 370 373 public static void terminateAndRemove(Object element) throws DebugException { 374 ILaunch launch= null; 375 ITerminate terminable = null; 376 if (element instanceof ILaunch) { 377 launch= (ILaunch) element; 378 } else if (element instanceof IDebugElement) { 379 launch= ((IDebugElement) element).getLaunch(); 380 } else if (element instanceof IProcess) { 381 launch= ((IProcess) element).getLaunch(); 382 } 383 terminable = launch; 384 if (terminable == null) { 385 if (element instanceof ITerminate) { 386 terminable = (ITerminate) element; 387 } 388 } 389 if (terminable == null) { 390 return; 391 } 392 if (!(terminable.canTerminate() || terminable.isTerminated())) { 393 return; 395 } 396 try { 397 if (!terminable.isTerminated()) { 398 terminable.terminate(); 399 } 400 } finally { 401 if (launch != null) { 402 ILaunchManager lManager= DebugPlugin.getDefault().getLaunchManager(); 403 lManager.removeLaunch(launch); 404 } 405 } 406 } 407 408 private void commonInit(IViewSite site) { 409 site.getPage().addPartListener((IPartListener2) this); 410 site.getWorkbenchWindow().addPageListener(this); 411 site.getWorkbenchWindow().addPerspectiveListener(this); 412 } 413 414 417 public void init(IViewSite site) throws PartInitException { 418 super.init(site); 419 commonInit(site); 420 } 421 422 425 public void init(IViewSite site, IMemento memento) throws PartInitException { 426 super.init(site, memento); 427 commonInit(site); 428 } 429 430 433 protected void configureToolBar(IToolBarManager tbm) { 434 tbm.add(new Separator(IDebugUIConstants.THREAD_GROUP)); 435 tbm.add(new Separator(IDebugUIConstants.STEP_GROUP)); 436 tbm.add(new GroupMarker(IDebugUIConstants.STEP_INTO_GROUP)); 437 tbm.add(new GroupMarker(IDebugUIConstants.STEP_OVER_GROUP)); 438 tbm.add(new GroupMarker(IDebugUIConstants.STEP_RETURN_GROUP)); 439 tbm.add(new GroupMarker(IDebugUIConstants.EMPTY_STEP_GROUP)); 440 tbm.add(new Separator(IDebugUIConstants.RENDER_GROUP)); 441 442 tbm.appendToGroup(IDebugUIConstants.THREAD_GROUP, getAction(RESUME)); 443 tbm.appendToGroup(IDebugUIConstants.THREAD_GROUP, getAction(SUSPEND)); 444 tbm.appendToGroup(IDebugUIConstants.THREAD_GROUP, getAction(TERMINATE)); 445 tbm.appendToGroup(IDebugUIConstants.THREAD_GROUP, getAction(DISCONNECT)); 446 447 tbm.appendToGroup(IDebugUIConstants.STEP_INTO_GROUP, getAction(STEP_INTO)); 448 tbm.appendToGroup(IDebugUIConstants.STEP_OVER_GROUP, getAction(STEP_OVER)); 449 tbm.appendToGroup(IDebugUIConstants.STEP_RETURN_GROUP, getAction(STEP_RETURN)); 450 451 tbm.appendToGroup(IDebugUIConstants.EMPTY_STEP_GROUP, getAction(DROP_TO_FRAME)); 452 453 tbm.appendToGroup(IDebugUIConstants.RENDER_GROUP, getAction(TOGGLE_STEP_FILTERS)); 454 } 455 456 459 public void dispose() { 460 DebugUITools.getDebugContextManager().getContextService(getSite().getWorkbenchWindow()).removeDebugContextProvider(fProvider); 461 disposeActions(); 462 fProvider.dispose(); 463 Viewer viewer = getViewer(); 464 if (viewer != null) { 465 viewer.removeSelectionChangedListener(this); 466 } 467 IWorkbenchPage page = getSite().getPage(); 468 page.removePartListener((IPartListener2) this); 469 IWorkbenchWindow window = getSite().getWorkbenchWindow(); 470 window.removePerspectiveListener(this); 471 window.removePageListener(this); 472 473 super.dispose(); 474 } 475 476 private void disposeActions() { 477 PropertyDialogAction properties = (PropertyDialogAction) getAction("Properties"); properties.dispose(); 479 480 disposeCommandAction(TERMINATE); 481 disposeCommandAction(DISCONNECT); 482 disposeCommandAction(SUSPEND); 483 disposeCommandAction(RESUME); 484 disposeCommandAction(STEP_RETURN); 485 disposeCommandAction(STEP_OVER); 486 disposeCommandAction(STEP_INTO); 487 disposeCommandAction(DROP_TO_FRAME); 488 disposeCommandAction(TERMINATE_AND_REMOVE); 489 disposeCommandAction(TERMINATE_AND_RELAUNCH); 490 disposeCommandAction(TERMINATE_ALL); 491 } 492 493 499 public void selectionChanged(SelectionChangedEvent event) { 500 fProvider.activate(event.getSelection()); 501 updateObjects(); 502 } 503 504 507 public void doubleClick(DoubleClickEvent event) { 508 ISelection selection= event.getSelection(); 509 if (!(selection instanceof IStructuredSelection)) { 510 return; 511 } 512 IStructuredSelection ss= (IStructuredSelection)selection; 513 Object o= ss.getFirstElement(); 514 if (o == null || o instanceof IStackFrame) { 515 return; 516 } 517 StructuredViewer viewer = (StructuredViewer) getViewer(); 518 viewer.refresh(o); 519 } 520 521 524 public void perspectiveActivated(IWorkbenchPage page, IPerspectiveDescriptor perspective) { 525 setActive(page.findView(getSite().getId()) != null); 526 updateObjects(); 527 } 528 529 532 public void perspectiveChanged(IWorkbenchPage page, IPerspectiveDescriptor perspective, String changeId) { 533 setActive(page.findView(getSite().getId()) != null); 534 } 535 536 539 public void perspectiveChanged(IWorkbenchPage page, IPerspectiveDescriptor perspective, IWorkbenchPartReference partRef, String changeId) { 540 } 541 542 545 public void pageActivated(IWorkbenchPage page) { 546 if (getSite().getPage().equals(page)) { 547 setActive(true); 548 updateObjects(); 549 } 550 } 551 552 555 public void pageClosed(IWorkbenchPage page) { 556 } 557 558 561 public void pageOpened(IWorkbenchPage page) { 562 } 563 564 567 public IDebugModelPresentation getPresentation(String id) { 568 return ((DelegatingModelPresentation)fPresentation).getPresentation(id); 569 } 570 571 574 protected void fillContextMenu(IMenuManager menu) { 575 576 menu.add(new Separator(IDebugUIConstants.EMPTY_EDIT_GROUP)); 577 menu.add(new Separator(IDebugUIConstants.EDIT_GROUP)); 578 menu.add(getAction(FIND_ACTION)); 579 menu.add(new Separator(IDebugUIConstants.EMPTY_STEP_GROUP)); 580 menu.add(new Separator(IDebugUIConstants.STEP_GROUP)); 581 menu.add(new GroupMarker(IDebugUIConstants.STEP_INTO_GROUP)); 582 menu.add(new GroupMarker(IDebugUIConstants.STEP_OVER_GROUP)); 583 menu.add(new GroupMarker(IDebugUIConstants.STEP_RETURN_GROUP)); 584 menu.add(new Separator(IDebugUIConstants.RENDER_GROUP)); 585 menu.add(new Separator(IDebugUIConstants.EMPTY_THREAD_GROUP)); 586 menu.add(new Separator(IDebugUIConstants.THREAD_GROUP)); 587 menu.add(new Separator(IDebugUIConstants.EMPTY_LAUNCH_GROUP)); 588 menu.add(new Separator(IDebugUIConstants.LAUNCH_GROUP)); 589 IStructuredSelection selection = (IStructuredSelection) getSite().getSelectionProvider().getSelection(); 590 updateAndAdd(menu, fEditConfigAction, selection); 591 updateAndAdd(menu, fAddToFavoritesAction, selection); 592 updateAndAdd(menu, fEditSourceAction, selection); 593 updateAndAdd(menu, fLookupAction, selection); 594 menu.add(new Separator(IDebugUIConstants.EMPTY_RENDER_GROUP)); 595 menu.add(new Separator(IDebugUIConstants.RENDER_GROUP)); 596 menu.add(new Separator(IDebugUIConstants.PROPERTY_GROUP)); 597 PropertyDialogAction action = (PropertyDialogAction)getAction("Properties"); 601 TreeSelection sel = (TreeSelection) fProvider.getActiveContext(); 602 boolean enabled = true; 603 if(sel != null && sel.size() > 0) { 604 enabled = !(sel.getFirstElement() instanceof ILaunch); 605 } 606 action.setEnabled(action.isApplicableForSelection() && enabled); 607 menu.add(action); 608 menu.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS)); 609 610 menu.appendToGroup(IDebugUIConstants.LAUNCH_GROUP, getAction(TERMINATE_AND_REMOVE)); 611 menu.appendToGroup(IDebugUIConstants.LAUNCH_GROUP, getAction(TERMINATE_ALL)); 612 613 menu.appendToGroup(IDebugUIConstants.THREAD_GROUP, getAction(RESUME)); 614 menu.appendToGroup(IDebugUIConstants.THREAD_GROUP, getAction(SUSPEND)); 615 menu.appendToGroup(IDebugUIConstants.THREAD_GROUP, getAction(TERMINATE)); 616 menu.appendToGroup(IDebugUIConstants.THREAD_GROUP, getAction(TERMINATE_AND_RELAUNCH)); 617 menu.appendToGroup(IDebugUIConstants.THREAD_GROUP, getAction(DISCONNECT)); 618 619 menu.appendToGroup(IDebugUIConstants.STEP_INTO_GROUP, getAction(STEP_INTO)); 620 menu.appendToGroup(IDebugUIConstants.STEP_OVER_GROUP, getAction(STEP_OVER)); 621 menu.appendToGroup(IDebugUIConstants.STEP_RETURN_GROUP, getAction(STEP_RETURN)); 622 623 menu.appendToGroup(IDebugUIConstants.EMPTY_STEP_GROUP, getAction(DROP_TO_FRAME)); 624 625 menu.appendToGroup(IDebugUIConstants.RENDER_GROUP, getAction(TOGGLE_STEP_FILTERS)); 626 } 627 628 636 private void updateAndAdd(IMenuManager menu, SelectionListenerAction action, IStructuredSelection selection) { 637 action.selectionChanged(selection); 638 if (action.isEnabled()) { 639 menu.add(action); 640 } 641 } 642 643 652 protected void setActive(boolean active) { 653 fIsActive = active; 654 } 655 656 663 protected boolean isActive() { 664 return fIsActive && getViewer() != null; 665 } 666 667 670 public boolean show(ShowInContext context) { 671 ISelection selection = context.getSelection(); 672 if (selection != null) { 673 if (selection instanceof IStructuredSelection) { 674 IStructuredSelection ss = (IStructuredSelection)selection; 675 if (ss.size() == 1) { 676 Object obj = ss.getFirstElement(); 677 if (obj instanceof IDebugTarget || obj instanceof IProcess) { 678 Viewer viewer = getViewer(); 679 if (viewer instanceof InternalTreeModelViewer) { 680 InternalTreeModelViewer tv = (InternalTreeModelViewer) viewer; 681 tv.setSelection(selection, true, true); 682 } else { 683 viewer.setSelection(selection, true); 684 } 685 return true; 686 } 687 } 688 } 689 } 690 return false; 691 } 692 693 696 public ShowInContext getShowInContext() { 697 if (isActive()) { 698 IStructuredSelection selection = (IStructuredSelection)getViewer().getSelection(); 699 if (selection.size() == 1) { 700 Object object = selection.getFirstElement(); 701 if (object instanceof IAdaptable) { 702 IAdaptable adaptable = (IAdaptable) object; 703 IShowInSource show = (IShowInSource) adaptable.getAdapter(IShowInSource.class); 704 if (show != null) { 705 return show.getShowInContext(); 706 } 707 } 708 } 709 } 710 return null; 711 } 712 713 716 public String [] getShowInTargetIds() { 717 if (isActive()) { 718 IStructuredSelection selection = (IStructuredSelection)getViewer().getSelection(); 719 if (selection.size() == 1) { 720 Object object = selection.getFirstElement(); 721 if (object instanceof IAdaptable) { 722 IAdaptable adaptable = (IAdaptable) object; 723 IShowInTargetList show = (IShowInTargetList) adaptable.getAdapter(IShowInTargetList.class); 724 if (show != null) { 725 return show.getShowInTargetIds(); 726 } 727 } 728 } 729 } 730 return new String [0]; 731 } 732 733 736 public void partClosed(IWorkbenchPartReference partRef) { 737 } 738 739 742 public void partVisible(IWorkbenchPartReference partRef) { 743 IWorkbenchPart part = partRef.getPart(false); 744 if (part == this) { 745 setActive(true); 746 getSite().getPage().showActionSet(IDebugUIConstants.DEBUG_ACTION_SET); 754 } 755 } 756 757 760 public void partOpened(IWorkbenchPartReference partRef) { 761 } 762 763 766 public void partActivated(IWorkbenchPartReference partRef) { 767 } 768 769 772 public void partBroughtToTop(IWorkbenchPartReference partRef) { 773 } 774 775 778 public void partDeactivated(IWorkbenchPartReference partRef) { 779 } 780 781 784 public void partHidden(IWorkbenchPartReference partRef) { 785 } 786 787 790 public void partInputChanged(IWorkbenchPartReference partRef) { 791 } 792 793 796 protected void becomesVisible() { 797 super.becomesVisible(); 798 getViewer().refresh(); 799 } 800 801 802 803 } 804 | Popular Tags |