KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > i18n > I18nAction


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
21 package org.netbeans.modules.i18n;
22
23 import org.openide.cookies.EditorCookie;
24 import org.openide.loaders.DataObject;
25 import org.openide.nodes.Node;
26 import org.openide.util.HelpCtx;
27 import org.openide.util.actions.NodeAction;
28 import org.netbeans.api.project.FileOwnerQuery;
29
30
31 /**
32  * Internationalize action. Runs "i18n session" over specified source. Finds
33  * non-i19n-ized hard coded strings and offers them i18n-ize to user in step-by-step
34  * manner.
35  *
36  * @author Petr Jiricka
37  * @see I18nManager
38  */

39 public class I18nAction extends NodeAction {
40
41     /** Generated sreial version UID. */
42     static final long serialVersionUID =3322896507302889271L;
43
44     public I18nAction() {
45         putValue("noIconInMenu", Boolean.TRUE);
46     }
47     
48     /**
49      * Actually performs the action. Implements superclass abstract method.
50      * @param activatedNodes Currently activated nodes.
51      */

52     protected void performAction(final Node[] activatedNodes) {
53         if (activatedNodes.length != 1)
54             return;
55
56         final Node node = activatedNodes[0];
57         DataObject dataObject = (DataObject) node.getCookie(DataObject.class);
58         if (dataObject == null)
59             return;
60
61         EditorCookie editorCookie = (EditorCookie) node.getCookie(EditorCookie.class);
62         if (editorCookie == null) {
63             editorCookie = (EditorCookie) dataObject.getCookie(EditorCookie.class);
64             if (editorCookie == null)
65                 return;
66         }
67
68         editorCookie.open();
69         I18nManager.getDefault().internationalize(dataObject);
70     }
71
72     protected boolean asynchronous() {
73         return false;
74     }
75
76     /** Overrides superclass method. Adds additional test if i18n module has registered factory
77      * for this data object to be able to perform i18n action. */

78     protected boolean enable(Node[] activatedNodes) {
79         if (activatedNodes.length != 1)
80             return false;
81
82         final Node node = activatedNodes[0];
83         DataObject dataObject = (DataObject) node.getCookie(DataObject.class);
84         if (dataObject == null || dataObject.getPrimaryFile() == null)
85             return false;
86
87         EditorCookie editorCookie = (EditorCookie) node.getCookie(EditorCookie.class);
88         if (editorCookie == null) {
89             editorCookie = (EditorCookie) dataObject.getCookie(EditorCookie.class);
90             if (editorCookie == null)
91                 return false;
92         }
93
94         if (!FactoryRegistry.hasFactory(dataObject.getClass()))
95             return false;
96
97     // check that the node has project
98
if (FileOwnerQuery.getOwner(dataObject.getPrimaryFile()) == null)
99             return false;
100
101     return true;
102     }
103
104     /** Gets localized name of action. Overrides superclass method. */
105     public String JavaDoc getName() {
106         return I18nUtil.getBundle().getString("CTL_I18nAction");
107     }
108
109     /** Gets the action's help context. Implemenst superclass abstract method. */
110     public HelpCtx getHelpCtx() {
111         return new HelpCtx(I18nUtil.HELP_ID_AUTOINSERT);
112     }
113 }
114
Popular Tags