KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > core > ui > warmup > ContextMenuWarmUpTask


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.core.ui.warmup;
21
22 import java.awt.EventQueue JavaDoc;
23
24 import javax.swing.Action JavaDoc;
25 import javax.swing.JMenuItem JavaDoc;
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 /**
38  * Warm-up task for initing context menu
39  *
40  * @author Tomas Pavek, Peter Zavadsky
41  */

42 public final class ContextMenuWarmUpTask implements Runnable JavaDoc {
43
44     public void run() {
45         // For first context menu.
46
org.openide.actions.ActionManager.getDefault().getContextActions();
47         new javax.swing.JMenuItem JavaDoc();
48
49         // #30676 ToolsAction popup warm up.
50
try {
51             EventQueue.invokeAndWait(new Runnable JavaDoc() {
52                 public void run() {
53                     warmUpToolsPopupMenuItem();
54                 }
55             });
56         } catch (Exception JavaDoc e) {
57             e.printStackTrace();
58         }
59     }
60
61     /** Warms up tools action popup menu item. */
62     private static void warmUpToolsPopupMenuItem() {
63         SystemAction toolsAction = SystemAction.get(ToolsAction.class);
64         if(toolsAction instanceof ContextAwareAction) {
65             // Here is important to create proper lookup
66
// to warm up Tools sub actions.
67
Lookup lookup = new org.openide.util.lookup.ProxyLookup(
68                 new Lookup[] {
69                     // This part of lookup causes warm up of Node (cookie) actions.
70
new AbstractNode(Children.LEAF).getLookup(),
71                     // This part of lookup causes warm up of Callback actions.
72
new TopComponent().getLookup()
73                 }
74             );
75             
76             Action JavaDoc action = ((ContextAwareAction)toolsAction)
77                                 .createContextAwareInstance(lookup);
78             if(action instanceof Presenter.Popup) {
79                 JMenuItem JavaDoc toolsMenuItem = ((Presenter.Popup)action)
80                                                 .getPopupPresenter();
81                 if(toolsMenuItem instanceof Runnable JavaDoc) {
82                     // This actually makes the warm up.
83
// See ToolsAction.Popup impl.
84
((Runnable JavaDoc)toolsMenuItem).run();
85                 }
86             }
87         }
88     }
89 }
90
Popular Tags