1 19 20 package org.netbeans.core.ui.warmup; 21 22 import java.awt.EventQueue ; 23 24 import javax.swing.Action ; 25 import javax.swing.JMenuItem ; 26 27 import org.openide.actions.ToolsAction; 28 import org.openide.nodes.AbstractNode; 29 import org.openide.nodes.Children; 30 import org.openide.util.actions.Presenter; 31 import org.openide.util.actions.SystemAction; 32 import org.openide.util.ContextAwareAction; 33 import org.openide.util.Lookup; 34 import org.openide.windows.TopComponent; 35 36 37 42 public final class ContextMenuWarmUpTask implements Runnable { 43 44 public void run() { 45 org.openide.actions.ActionManager.getDefault().getContextActions(); 47 new javax.swing.JMenuItem (); 48 49 try { 51 EventQueue.invokeAndWait(new Runnable () { 52 public void run() { 53 warmUpToolsPopupMenuItem(); 54 } 55 }); 56 } catch (Exception e) { 57 e.printStackTrace(); 58 } 59 } 60 61 62 private static void warmUpToolsPopupMenuItem() { 63 SystemAction toolsAction = SystemAction.get(ToolsAction.class); 64 if(toolsAction instanceof ContextAwareAction) { 65 Lookup lookup = new org.openide.util.lookup.ProxyLookup( 68 new Lookup[] { 69 new AbstractNode(Children.LEAF).getLookup(), 71 new TopComponent().getLookup() 73 } 74 ); 75 76 Action action = ((ContextAwareAction)toolsAction) 77 .createContextAwareInstance(lookup); 78 if(action instanceof Presenter.Popup) { 79 JMenuItem toolsMenuItem = ((Presenter.Popup)action) 80 .getPopupPresenter(); 81 if(toolsMenuItem instanceof Runnable ) { 82 ((Runnable )toolsMenuItem).run(); 85 } 86 } 87 } 88 } 89 } 90 | Popular Tags |