alvinalexander.com | career | drupal | java | mac | mysql | perl | scala | uml | unix  

What this is

This file is included in the DevDaily.com "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

Other links

The source code

/*
 *                 Sun Public License Notice
 * 
 * The contents of this file are subject to the Sun Public License
 * Version 1.0 (the "License"). You may not use this file except in
 * compliance with the License. A copy of the License is available at
 * http://www.sun.com/
 * 
 * The Original Code is NetBeans. The Initial Developer of the Original
 * Code is Sun Microsystems, Inc. Portions Copyright 1997-2004 Sun
 * Microsystems, Inc. All Rights Reserved.
 */

package org.openide.actions;

import java.util.Locale;
import org.openide.TopManager;
import org.openide.debugger.Debugger;
import org.openide.debugger.DebuggerNotFoundException;
import org.openide.cookies.DebuggerCookie;
import org.openide.util.HelpCtx;
import org.openide.util.NbBundle;
import org.openide.nodes.Node;

/** Trace into a method in the debugger.
* Starts the debugger if needed.
*
* @see Debugger#traceInto
* @author   Jan Jancura
*/
public class TraceIntoAction extends GoAction {

    static final long serialVersionUID = -2094716396729169502L;

    private boolean enabled = true;

    /* This performer starts the debugger (if isn't started yet),
    * or calls the traceInto method of debugger in the other case.
    *
    * @param activatedNodes Currently activated nodes.
    */
    public void performAction (final Node[] activatedNodes) {
        try {
            int state = TopManager.getDefault ().getDebugger ().getState ();
            if (state == Debugger.DEBUGGER_NOT_RUNNING) {
                // ensure that the start debugger action can be performed on the passed nodes
                if (!enable (activatedNodes))
                    return;
                // start in different thread
                DebuggerPerformer.getDefault ().setDebuggerRunning (true);
                DebuggerPerformer.getDefault ().new StartDebugThread (
                    activatedNodes, true
                ).start ();
            } else
                if (state == Debugger.DEBUGGER_STOPPED) {
                    DebuggerPerformer.getDefault ().setDebuggerRunning (true);
                    try {
                        TopManager.getDefault ().getDebugger ().traceInto ();
                    } catch (org.openide.debugger.DebuggerException e) {
                        DebuggerPerformer.getDefault ().
                            notifyDebuggerException (e);
                    }
                }    
        } catch (DebuggerNotFoundException e) {
        }
    }

    /* Enables Trace into action when only one data object which supports
    * debugging (isDebuggingAllowed () == true) is selected.
    *
    * @param activatedNodes Currently activated nodes.
    */
    protected boolean enable (final Node[] activatedNodes) {
        if (!enabled) return false;
        try {
            int state = TopManager.getDefault ().getDebugger ().getState ();
            if (state != Debugger.DEBUGGER_NOT_RUNNING) return state == Debugger.DEBUGGER_STOPPED;
            if ((activatedNodes == null) || (activatedNodes.length != 1)) return false;
            return null != activatedNodes[0].getCookie(DebuggerCookie.class);
        } catch (DebuggerNotFoundException e) {
            return false;
        }
    }

    /** Set whether the debugger action is enabled in general.
    * @param e true if so
    */
    public void changeEnabled (boolean e) {
        enabled = e;
        setEnabled (enable (getActivatedNodes ()));
    }

    /* @return the action's icon */
    public String getName () {
        return NbBundle.getBundle("org.openide.deprecated.Bundle", Locale.getDefault(), StepOutAction.class.getClassLoader()).getString("TraceInto");
    }

    /* @return the action's help context */
    public HelpCtx getHelpCtx () {
        return new HelpCtx (TraceIntoAction.class);
    }

    /* @return the action's icon */
    protected String iconResource () {
        return "org/openide/deprecated/traceInto.gif"; // NOI18N
    }

}
... this post is sponsored by my books ...

#1 New Release!

FP Best Seller

 

new blog posts

 

Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.

A percentage of advertising revenue from
pages under the /java/jwarehouse URI on this website is
paid back to open source projects.