|
What this is
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.ArrayList; 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.DebuggerEngine; import org.netbeans.api.debugger.DebuggerManager; import org.netbeans.api.debugger.DebuggerManagerListener; import org.netbeans.spi.debugger.ContextProvider; import org.netbeans.api.debugger.Session; import org.netbeans.api.debugger.Watch; import org.netbeans.api.debugger.jpda.JPDADebugger; import org.netbeans.api.project.Project; import org.netbeans.spi.debugger.ActionsProviderSupport; import org.netbeans.spi.project.ActionProvider; import org.netbeans.api.java.project.JavaProjectConstants; import org.openide.loaders.DataObject; import org.openide.nodes.Node; import org.openide.util.Lookup; import org.openide.util.lookup.Lookups; import org.openide.windows.TopComponent; /** * * @author Jan Jancura */ public class FixActionProvider extends ActionsProviderSupport { private JPDADebugger debugger; private Listener listener; public FixActionProvider (ContextProvider lookupProvider) { debugger = (JPDADebugger) lookupProvider.lookupFirst (null, JPDADebugger.class); listener = new Listener (); MainProjectManager.getDefault ().addPropertyChangeListener (listener); debugger.addPropertyChangeListener (JPDADebugger.PROP_STATE, listener); TopComponent.getRegistry ().addPropertyChangeListener (listener); setEnabled ( ActionsManager.ACTION_FIX, shouldBeEnabled () ); } private void destroy () { debugger.removePropertyChangeListener (debugger.PROP_STATE, listener); MainProjectManager.getDefault ().removePropertyChangeListener (listener); TopComponent.getRegistry ().removePropertyChangeListener (listener); } public Set getActions () { return Collections.singleton (ActionsManager.ACTION_FIX); } public void doAction (Object action) { ((ActionProvider) MainProjectManager.getDefault (). getMainProject ().getLookup ().lookup ( ActionProvider.class )).invokeAction ( JavaProjectConstants.COMMAND_DEBUG_FIX, getLookup () ); } private boolean shouldBeEnabled () { // check if current debugger supports this action if (!debugger.canFixClasses()) return false; // 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 (JavaProjectConstants.COMMAND_DEBUG_FIX.equals (sa [i])) break; if (i == k) return false; // check if this action should be enabled return ((ActionProvider) p.getLookup ().lookup ( ActionProvider.class )).isActionEnabled ( JavaProjectConstants.COMMAND_DEBUG_FIX, getLookup () ); } private Lookup getLookup () { Node[] nodes = TopComponent.getRegistry ().getActivatedNodes (); int i, k = nodes.length; ArrayList l = new ArrayList (); for (i = 0; i < k; i++) { Object o = nodes [i].getCookie (DataObject.class); if (o != null) l.add (o); } return Lookups.fixed (l.toArray (new DataObject [l.size ()])); } private class Listener implements PropertyChangeListener, DebuggerManagerListener { public void propertyChange (PropertyChangeEvent e) { boolean en = shouldBeEnabled (); setEnabled ( ActionsManager.ACTION_FIX, en ); if (debugger.getState () == debugger.STATE_DISCONNECTED) destroy (); } public void sessionRemoved (Session session) {} 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) {} public void engineAdded (DebuggerEngine engine) {} public void engineRemoved (DebuggerEngine engine) {} } } |
... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
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.