/nodes/src/com/bluemarsh/jswat/nodes/stack/PopFramesAction.java
Java | 129 lines | 88 code | 8 blank | 33 comment | 17 complexity | 75cc51e90173845285b63f4f6d7a30aa MD5 | raw file
Possible License(s): MPL-2.0-no-copyleft-exception
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 */ 23package com.bluemarsh.jswat.nodes.stack; 24 25import com.bluemarsh.jswat.core.context.ContextProvider; 26import com.bluemarsh.jswat.core.context.DebuggingContext; 27import com.bluemarsh.jswat.core.session.Session; 28import com.bluemarsh.jswat.core.session.SessionManager; 29import com.bluemarsh.jswat.core.session.SessionProvider; 30import com.sun.jdi.IncompatibleThreadStateException; 31import com.sun.jdi.InvalidStackFrameException; 32import com.sun.jdi.NativeMethodException; 33import com.sun.jdi.StackFrame; 34import com.sun.jdi.ThreadReference; 35import com.sun.jdi.VirtualMachine; 36import org.openide.DialogDisplayer; 37import org.openide.ErrorManager; 38import org.openide.NotifyDescriptor; 39import org.openide.nodes.Node; 40import org.openide.util.HelpCtx; 41import org.openide.util.NbBundle; 42import org.openide.util.actions.NodeAction; 43 44/** 45 * Implements the action of popping frames from the stack. 46 * 47 * @author Nathan Fiedler 48 */ 49public class PopFramesAction extends NodeAction { 50 51 /** silence the compiler warnings */ 52 private static final long serialVersionUID = 1L; 53 54 @Override 55 protected boolean asynchronous() { 56 return false; 57 } 58 59 @Override 60 protected boolean enable(Node[] nodes) { 61 if (nodes != null && nodes.length == 1) { 62 SessionManager sm = SessionProvider.getSessionManager(); 63 Session session = sm.getCurrent(); 64 try { 65 if (session.isSuspended()) { 66 DebuggingContext dc = ContextProvider.getContext(session); 67 if (dc.getThread() != null) { 68 GetFrameCookie gfc = nodes[0].getCookie(GetFrameCookie.class); 69 if (gfc != null) { 70 // Add one for easy comparison to check if this is 71 // the earliest frame, which can never be popped. 72 int frame = gfc.getFrameIndex() + 1; 73 if (frame < dc.getThread().frameCount()) { 74 VirtualMachine vm = session.getConnection().getVM(); 75 return vm.canPopFrames() && vm.canBeModified(); 76 } 77 } 78 } 79 } 80 } catch (IncompatibleThreadStateException itse) { 81 ErrorManager.getDefault().notify(itse); 82 } 83 } 84 return false; 85 } 86 87 @Override 88 public HelpCtx getHelpCtx() { 89 return HelpCtx.DEFAULT_HELP; 90 } 91 92 @Override 93 public String getName() { 94 return NbBundle.getMessage(PopFramesAction.class, 95 "LBL_StackView_PopFramesAction"); 96 } 97 98 @Override 99 protected void performAction(Node[] nodes) { 100 if (nodes != null && nodes.length == 1) { 101 GetFrameCookie gfc = nodes[0].getCookie(GetFrameCookie.class); 102 if (gfc != null) { 103 int index = gfc.getFrameIndex(); 104 Session session = SessionProvider.getCurrentSession(); 105 DebuggingContext dc = ContextProvider.getContext(session); 106 ThreadReference thread = dc.getThread(); 107 try { 108 StackFrame frame = thread.frame(index); 109 thread.popFrames(frame); 110 } catch (NativeMethodException nme) { 111 NotifyDescriptor desc = new NotifyDescriptor.Message( 112 NbBundle.getMessage(PopFramesAction.class, 113 "ERR_StackView_PoppingNativeMethod"), 114 NotifyDescriptor.ERROR_MESSAGE); 115 DialogDisplayer.getDefault().notify(desc); 116 } catch (IncompatibleThreadStateException itse) { 117 // view should have been cleared already 118 ErrorManager.getDefault().notify(itse); 119 } catch (InvalidStackFrameException isfe) { 120 // This happens if user tries to pop all of the frames. 121 ErrorManager.getDefault().notify(isfe); 122 } finally { 123 // Cause the context to be reset no matter what happens. 124 dc.setThread(thread, false); 125 } 126 } 127 } 128 } 129}