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.cookies.DebuggerCookie;
import org.openide.util.HelpCtx;
import org.openide.util.NbBundle;
import org.openide.util.actions.NodeAction;
import org.openide.nodes.Node;

/**
* Start the debugger.
* @see Debugger#startDebugger
* @see Debugger#go
* @see DebuggerCookie
*
* @author   Daniel Prusa
*/
public class StartDebuggerAction extends NodeAction {


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

    static final long serialVersionUID = 3565920123469616122L;


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

    private static boolean enabled = true;

    private boolean multisession = false;

    /** Should be a DO compiled before debugging? */
    private static boolean runCompilation = true;
    /** Workspace */
    private static String workspace = "Debugging"; // NOI18N


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

    /** Getter for local enabled flag.
    * @return true if debugging is enabled
    */
    boolean getEnabledFlag() {
        return enabled;
    }

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

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

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

    public void setMultisession (boolean b) {
        multisession = b;
    }

    /** Getter for multisession.
    * @return true if multisession debugger
    */
    boolean getMultisession() {
        return multisession;
    }

    /* This performer starts the debugger
    *
    * @param activatedNodes Currently activated nodes.
    */
    protected void performAction (final Node[] activatedNodes) {
        // ensure that the start debugger action can be performed on the passed nodes
        if (!enable (activatedNodes))
            return;
        try {
            int state = TopManager.getDefault ().getDebugger ().getState ();
            if (multisession || (state == Debugger.DEBUGGER_NOT_RUNNING)) {
                DebuggerPerformer.getDefault ().setDebuggerRunning (true);
                // start in different thread
                DebuggerPerformer.getDefault ().new StartDebugThread (
                    activatedNodes, false
                ).start ();
            }
        } 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) && (!multisession)) return false;
        try {
            int state = TopManager.getDefault ().getDebugger ().getState ();
            if ((!multisession)&&(state != Debugger.DEBUGGER_NOT_RUNNING)) return false;
            if ((activatedNodes == null) || (activatedNodes.length != 1)) return false;
            return null != activatedNodes[0].getCookie(DebuggerCookie.class);
        } catch (DebuggerNotFoundException e) {
            return false;
        }
    }

    /** Set whether to run compilation before debugging.
    * @param r true if so
    */
    public static void setRunCompilation(boolean r) {
        runCompilation = r;
    }
    /** Test whether compilation is to be run before debugging.
    * @return true if so
    */
    public static boolean getRunCompilation() {
        return runCompilation;
    }
    /**
    * Get the name of the workspace in which debugging is performed.
    * By default, the "Debugging" workspace.
    * @return the workspace name
    */
    public static String getWorkspace () {
        return workspace;
    }
    /**
    * Set the name of the workspace in which debugging is to be performed.
    * @param workspace the new workspace name
    */
    public static void setWorkspace (String workspace) {
        StartDebuggerAction.workspace = workspace;
    }
}
... 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.