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.netbeans.modules.debugger.projects;

import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.util.Collections;
import java.util.Set;
import org.netbeans.api.debugger.ActionsManager;

import org.netbeans.api.debugger.Breakpoint;

import org.netbeans.api.debugger.DebuggerManager;
import org.netbeans.api.debugger.DebuggerManagerListener;
import org.netbeans.api.debugger.Session;
import org.netbeans.api.debugger.Watch;
import org.netbeans.api.debugger.jpda.MethodBreakpoint;
import org.netbeans.api.project.Project;
import org.netbeans.spi.debugger.ActionsProviderSupport;
import org.netbeans.spi.project.ActionProvider;


/**
*
* @author   Jan Jancura
*/
public class StepIntoActionProvider extends ActionsProviderSupport {

//    private MethodBreakpoint breakpoint;
    
    {
        Listener listener = new Listener ();
        MainProjectManager.getDefault ().addPropertyChangeListener (listener);
//        DebuggerManager.getDebuggerManager ().addDebuggerListener (listener);
        
        setEnabled (
            ActionsManager.ACTION_STEP_INTO,
            shouldBeEnabled ()
        );
    }
    
    public Set getActions () {
        return Collections.singleton (ActionsManager.ACTION_STEP_INTO);
    }
    
    public void doAction (Object action) {
        
        // 1) set breakpoint
//        if (breakpoint != null) {
//            DebuggerManager.getDebuggerManager ().removeBreakpoint (breakpoint);
//            breakpoint = null;
//        }
//        breakpoint = MethodBreakpoint.create ();
//        breakpoint.setClassExclusionFilters (new String[] {
//            "java*","sun.*"
//        });
//        breakpoint.setMethodName ("main");
//        breakpoint.setHidden (true);
//        DebuggerManager.getDebuggerManager ().addBreakpoint (breakpoint);
        
        // 2) start debugging of project
        ((ActionProvider) MainProjectManager.getDefault ().
            getMainProject ().getLookup ().lookup (
                ActionProvider.class
            )).invokeAction (
                ActionProvider.COMMAND_DEBUG_STEP_INTO, 
                MainProjectManager.getDefault ().getMainProject ().getLookup ()
            );
    }
    
    private boolean shouldBeEnabled () {
        
        // check if current project supports this action
        Project p = MainProjectManager.getDefault ().getMainProject ();
        if (p == null) return false;
        ActionProvider actionProvider = (ActionProvider) p.getLookup ().
            lookup (ActionProvider.class);
        if (actionProvider == null) return false;
        String[] sa = actionProvider.getSupportedActions ();
        int i, k = sa.length;
        for (i = 0; i < k; i++)
            if (ActionProvider.COMMAND_DEBUG_STEP_INTO.equals (sa [i]))
                break;
        if (i == k) return false;
        
        // check if this action should be enabled
        return actionProvider.isActionEnabled (
            ActionProvider.COMMAND_DEBUG_STEP_INTO,
            MainProjectManager.getDefault ().getMainProject ().getLookup ()
        );
    }
    
    
    private class Listener implements PropertyChangeListener/*, 
    DebuggerManagerListener */{
        public void propertyChange (PropertyChangeEvent e) {
            setEnabled (
                ActionsManager.ACTION_STEP_INTO,
                shouldBeEnabled ()
            );
        }
//        public void sessionRemoved (Session session) {
//            if (breakpoint != null) {
//                DebuggerManager.getDebuggerManager ().removeBreakpoint (breakpoint);
//                breakpoint = null;
//            }
//        }
//        
//        public void breakpointAdded (Breakpoint breakpoint) {}
//        public void breakpointRemoved (Breakpoint breakpoint) {}
//        public Breakpoint[] initBreakpoints () {
//            return new Breakpoint [0];
//        }
//        public void initWatches () {}
//        public void sessionAdded (Session session) {}
//        public void watchAdded (Watch watch) {}
//        public void watchRemoved (Watch watch) {}
    }
}
... this post is sponsored by my books ...

#1 New Release!

FP Best Seller

 

new blog posts

 

Copyright 1998-2024 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.