KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > i18n > wizard > I18nWizardAction


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.wizard;
22
23 import java.awt.Dialog JavaDoc;
24 import java.lang.ref.WeakReference JavaDoc;
25 import java.text.MessageFormat JavaDoc;
26 import java.util.ArrayList JavaDoc;
27
28 import org.netbeans.modules.i18n.I18nUtil;
29
30 import org.openide.nodes.Node;
31 import org.openide.util.actions.NodeAction;
32 import org.openide.util.HelpCtx;
33 import org.openide.util.NbBundle;
34 import org.openide.WizardDescriptor;
35 import org.openide.DialogDisplayer;
36 import org.openide.cookies.EditorCookie;
37 import org.openide.loaders.DataObject;
38 import org.netbeans.api.project.Project;
39 import org.netbeans.api.project.FileOwnerQuery;
40
41 /**
42  * Action which runs i18n wizard.
43  *
44  * @author Peter Zavadsky
45  * @author Petr Kuzel
46  */

47 public class I18nWizardAction extends NodeAction {
48
49     public I18nWizardAction() {
50         putValue("noIconInMenu", Boolean.TRUE);
51     }
52     
53     /** Generated serial version UID. */
54     static final long serialVersionUID = 6965968608028644524L;
55
56     /** Weak reference to dialog. */
57     private static WeakReference JavaDoc dialogWRef = new WeakReference JavaDoc(null);
58
59     
60     /**
61      * We create non-modal but not rentrant dialog. Wait until
62      * previous one is closed.
63      */

64     protected boolean enable(Node[] activatedNodes) {
65
66         if (Util.wizardEnabled(activatedNodes) == false) {
67             return false;
68         }
69         
70         Dialog JavaDoc previous = (Dialog JavaDoc) dialogWRef.get();
71         if (previous == null) return true;
72         return previous.isVisible() == false;
73     }
74     
75     /**
76      * Popup non modal wizard.
77      */

78     protected void performAction(Node[] activatedNodes) {
79         Dialog JavaDoc dialog = (Dialog JavaDoc) dialogWRef.get();
80         
81         if(dialog != null) {
82             dialog.setVisible(false);
83             dialog.dispose();
84         }
85
86     /* find out the current project from activated nodes */
87     Project project = org.netbeans.modules.i18n.Util.getProjectFor(activatedNodes);
88     if (project == null) return;
89       
90         WizardDescriptor wizardDesc = I18nWizardDescriptor.createI18nWizardDescriptor(
91             getWizardIterator(),
92             new I18nWizardDescriptor.Settings(Util.createWizardSourceMap(activatedNodes), project)
93         );
94
95         initWizard(wizardDesc);
96         
97         dialog = DialogDisplayer.getDefault().createDialog(wizardDesc);
98         dialogWRef = new WeakReference JavaDoc(dialog);
99         dialog.setVisible(true);
100     }
101
102     /** Gets wizard iterator thru panels used in wizard invoked by this action,
103      * i.e I18N wizard. */

104     private WizardDescriptor.Iterator getWizardIterator() {
105         ArrayList JavaDoc panels = new ArrayList JavaDoc(4);
106         
107         panels.add(new SourceWizardPanel.Panel());
108         panels.add(new ResourceWizardPanel.Panel());
109         
110         if(I18nUtil.getOptions().isAdvancedWizard())
111             panels.add(new AdditionalWizardPanel.Panel());
112         
113         panels.add(new HardStringWizardPanel.Panel());
114         
115         return new WizardDescriptor.ArrayIterator((WizardDescriptor.Panel[])
116             panels.toArray(new WizardDescriptor.Panel[panels.size()])
117         );
118     }
119
120     /** Initializes wizard descriptor. */
121     private void initWizard(WizardDescriptor wizardDesc) {
122         // Init properties.
123
wizardDesc.putProperty("WizardPanel_autoWizardStyle", Boolean.TRUE); // NOI18N
124
wizardDesc.putProperty("WizardPanel_contentDisplayed", Boolean.TRUE); // NOI18N
125
wizardDesc.putProperty("WizardPanel_contentNumbered", Boolean.TRUE); // NOI18N
126

127         ArrayList JavaDoc contents = new ArrayList JavaDoc(4);
128         contents.add(Util.getString("TXT_SelectSourcesHelp"));
129         contents.add(Util.getString("TXT_SelectResourceHelp"));
130         
131         if(I18nUtil.getOptions().isAdvancedWizard())
132             contents.add(Util.getString("TXT_AdditionalHelp"));
133         
134         contents.add(Util.getString("TXT_FoundStringsHelp"));
135         
136         wizardDesc.putProperty(
137             "WizardPanel_contentData", // NOI18N
138
(String JavaDoc[])contents.toArray(new String JavaDoc[contents.size()])
139         );
140         
141         wizardDesc.setTitle(Util.getString("LBL_WizardTitle"));
142         wizardDesc.setTitleFormat(new MessageFormat JavaDoc("{0} ({1})")); // NOI18N
143

144         wizardDesc.setModal(false);
145     }
146
147     /** Gets localized name of action. Overrides superclass method. */
148     public String JavaDoc getName() {
149         return Util.getString("LBL_WizardActionName");
150     }
151     
152     /** Gets the action's help context. Implemenst superclass abstract method. */
153     public HelpCtx getHelpCtx() {
154         return new HelpCtx(I18nUtil.HELP_ID_WIZARD);
155     }
156
157     protected boolean asynchronous() {
158       return false;
159     }
160     
161 }
162
Popular Tags