/nodes/src/com/bluemarsh/jswat/nodes/stack/PopFramesAction.java

http://jswat.googlecode.com/ · Java · 129 lines · 88 code · 8 blank · 33 comment · 17 complexity · 75cc51e90173845285b63f4f6d7a30aa MD5 · raw file

  1. /*
  2. * The contents of this file are subject to the terms of the Common Development
  3. * and Distribution License (the License). You may not use this file except in
  4. * compliance with the License.
  5. *
  6. * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
  7. * or http://www.netbeans.org/cddl.txt.
  8. *
  9. * When distributing Covered Code, include this CDDL Header Notice in each file
  10. * and include the License file at http://www.netbeans.org/cddl.txt.
  11. * If applicable, add the following below the CDDL Header, with the fields
  12. * enclosed by brackets [] replaced by your own identifying information:
  13. * "Portions Copyrighted [year] [name of copyright owner]"
  14. *
  15. * The Original Software is JSwat. The Initial Developer of the Original
  16. * Software is Nathan L. Fiedler. Portions created by Nathan L. Fiedler
  17. * are Copyright (C) 2005-2010. All Rights Reserved.
  18. *
  19. * Contributor(s): Nathan L. Fiedler.
  20. *
  21. * $Id: PopFramesAction.java 255 2010-01-22 08:51:48Z nathanfiedler $
  22. */
  23. package com.bluemarsh.jswat.nodes.stack;
  24. import com.bluemarsh.jswat.core.context.ContextProvider;
  25. import com.bluemarsh.jswat.core.context.DebuggingContext;
  26. import com.bluemarsh.jswat.core.session.Session;
  27. import com.bluemarsh.jswat.core.session.SessionManager;
  28. import com.bluemarsh.jswat.core.session.SessionProvider;
  29. import com.sun.jdi.IncompatibleThreadStateException;
  30. import com.sun.jdi.InvalidStackFrameException;
  31. import com.sun.jdi.NativeMethodException;
  32. import com.sun.jdi.StackFrame;
  33. import com.sun.jdi.ThreadReference;
  34. import com.sun.jdi.VirtualMachine;
  35. import org.openide.DialogDisplayer;
  36. import org.openide.ErrorManager;
  37. import org.openide.NotifyDescriptor;
  38. import org.openide.nodes.Node;
  39. import org.openide.util.HelpCtx;
  40. import org.openide.util.NbBundle;
  41. import org.openide.util.actions.NodeAction;
  42. /**
  43. * Implements the action of popping frames from the stack.
  44. *
  45. * @author Nathan Fiedler
  46. */
  47. public class PopFramesAction extends NodeAction {
  48. /** silence the compiler warnings */
  49. private static final long serialVersionUID = 1L;
  50. @Override
  51. protected boolean asynchronous() {
  52. return false;
  53. }
  54. @Override
  55. protected boolean enable(Node[] nodes) {
  56. if (nodes != null && nodes.length == 1) {
  57. SessionManager sm = SessionProvider.getSessionManager();
  58. Session session = sm.getCurrent();
  59. try {
  60. if (session.isSuspended()) {
  61. DebuggingContext dc = ContextProvider.getContext(session);
  62. if (dc.getThread() != null) {
  63. GetFrameCookie gfc = nodes[0].getCookie(GetFrameCookie.class);
  64. if (gfc != null) {
  65. // Add one for easy comparison to check if this is
  66. // the earliest frame, which can never be popped.
  67. int frame = gfc.getFrameIndex() + 1;
  68. if (frame < dc.getThread().frameCount()) {
  69. VirtualMachine vm = session.getConnection().getVM();
  70. return vm.canPopFrames() && vm.canBeModified();
  71. }
  72. }
  73. }
  74. }
  75. } catch (IncompatibleThreadStateException itse) {
  76. ErrorManager.getDefault().notify(itse);
  77. }
  78. }
  79. return false;
  80. }
  81. @Override
  82. public HelpCtx getHelpCtx() {
  83. return HelpCtx.DEFAULT_HELP;
  84. }
  85. @Override
  86. public String getName() {
  87. return NbBundle.getMessage(PopFramesAction.class,
  88. "LBL_StackView_PopFramesAction");
  89. }
  90. @Override
  91. protected void performAction(Node[] nodes) {
  92. if (nodes != null && nodes.length == 1) {
  93. GetFrameCookie gfc = nodes[0].getCookie(GetFrameCookie.class);
  94. if (gfc != null) {
  95. int index = gfc.getFrameIndex();
  96. Session session = SessionProvider.getCurrentSession();
  97. DebuggingContext dc = ContextProvider.getContext(session);
  98. ThreadReference thread = dc.getThread();
  99. try {
  100. StackFrame frame = thread.frame(index);
  101. thread.popFrames(frame);
  102. } catch (NativeMethodException nme) {
  103. NotifyDescriptor desc = new NotifyDescriptor.Message(
  104. NbBundle.getMessage(PopFramesAction.class,
  105. "ERR_StackView_PoppingNativeMethod"),
  106. NotifyDescriptor.ERROR_MESSAGE);
  107. DialogDisplayer.getDefault().notify(desc);
  108. } catch (IncompatibleThreadStateException itse) {
  109. // view should have been cleared already
  110. ErrorManager.getDefault().notify(itse);
  111. } catch (InvalidStackFrameException isfe) {
  112. // This happens if user tries to pop all of the frames.
  113. ErrorManager.getDefault().notify(isfe);
  114. } finally {
  115. // Cause the context to be reset no matter what happens.
  116. dc.setThread(thread, false);
  117. }
  118. }
  119. }
  120. }
  121. }