KickJava   Java API By Example, From Geeks To Geeks.

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


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.netbeans.api.project.Project;
37
38 /**
39  * Action which runs i18n test wizard.
40  *
41  * @author Peter Zavadsky
42  * @author Petr Kuzel
43  */

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

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

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

103     private WizardDescriptor.Iterator getWizardIterator() {
104         WizardDescriptor.Panel[] panels = new WizardDescriptor.Panel[3];
105         
106         panels[0] = new SourceWizardPanel.Panel(true);
107         panels[1] = new ResourceWizardPanel.Panel(true);
108         panels[2] = new TestStringWizardPanel.Panel();
109         
110         return new WizardDescriptor.ArrayIterator(panels);
111             
112     }
113     
114     /** Initializes wizard descriptor. */
115     private void initWizard(WizardDescriptor wizardDesc) {
116         // Init properties.
117
wizardDesc.putProperty("WizardPanel_autoWizardStyle", Boolean.TRUE); // NOI18N
118
wizardDesc.putProperty("WizardPanel_contentDisplayed", Boolean.TRUE); // NOI18N
119
wizardDesc.putProperty("WizardPanel_contentNumbered", Boolean.TRUE); // NOI18N
120

121         ArrayList JavaDoc contents = new ArrayList JavaDoc(3);
122         contents.add(Util.getString("TXT_SelectTestSources"));
123         contents.add(Util.getString("TXT_SelectTestResources"));
124         contents.add(Util.getString("TXT_FoundMissingResources"));
125         
126         wizardDesc.putProperty("WizardPanel_contentData", (String JavaDoc[])contents.toArray(new String JavaDoc[contents.size()])); // NOI18N
127

128         wizardDesc.setTitle(Util.getString("LBL_TestWizardTitle"));
129         wizardDesc.setTitleFormat(new MessageFormat JavaDoc("{0} ({1})")); // NOI18N
130

131         wizardDesc.setModal(false);
132     }
133     
134     /** Gets localized name of action. Overrides superclass method. */
135     public String JavaDoc getName() {
136         return Util.getString("LBL_TestWizardActionName");
137     }
138     
139     /** Gets the action's help context. Implemenst superclass abstract method. */
140     public HelpCtx getHelpCtx() {
141         return new HelpCtx(I18nUtil.HELP_ID_TESTING);
142     }
143
144     protected boolean asynchronous() {
145       return false;
146     }
147     
148
149 }
150
Popular Tags