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.debugger.Debugger;
import org.openide.debugger.DebuggerNotFoundException;
import org.openide.TopManager;
import org.openide.util.HelpCtx;
import org.openide.util.NbBundle;
import org.openide.util.actions.NodeAction;
import org.openide.nodes.Node;

/**
* Continue debugging.
* @see org.openide.debugger.Debugger#startDebugger
* @see org.openide.debugger.Debugger#go
* @see org.openide.cookies.DebuggerCookie
*
* @author   Jan Jancura
*/
public class GoAction extends NodeAction {


    // static ..........................................................................................

    static final long serialVersionUID = 3403920608369616104L;


    // variables ..........................................................................................

    private boolean enabled = true;


    // other methods......................................................................................

    /** 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("Go");
    }

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

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


    /* This performer starts the debugger (if isn't started yet),
    * or calls the go method of debugger in the other case.
    *
    * @param activatedNodes Currently activated nodes.
    */
    protected void performAction (final Node[] activatedNodes) {
        try {
            int state = TopManager.getDefault ().getDebugger ().getState ();
            if (state == Debugger.DEBUGGER_STOPPED)
                DebuggerPerformer.getDefault ().setDebuggerRunning (true);
            try {
                TopManager.getDefault ().getDebugger ().go ();
            } catch (org.openide.debugger.DebuggerException e) {
                DebuggerPerformer.getDefault ().notifyDebuggerException (e);
            }
        } catch (DebuggerNotFoundException e) {
        }
    }

    /* Enables go 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 ();
            return state == Debugger.DEBUGGER_STOPPED;
        } catch (DebuggerNotFoundException e) {
            return false;
        }
    }

}
... 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.