1 19 20 21 package org.netbeans.modules.i18n.wizard; 22 23 import java.awt.Dialog ; 24 import java.lang.ref.WeakReference ; 25 import java.text.MessageFormat ; 26 import java.util.ArrayList ; 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 47 public class I18nWizardAction extends NodeAction { 48 49 public I18nWizardAction() { 50 putValue("noIconInMenu", Boolean.TRUE); 51 } 52 53 54 static final long serialVersionUID = 6965968608028644524L; 55 56 57 private static WeakReference dialogWRef = new WeakReference (null); 58 59 60 64 protected boolean enable(Node[] activatedNodes) { 65 66 if (Util.wizardEnabled(activatedNodes) == false) { 67 return false; 68 } 69 70 Dialog previous = (Dialog ) dialogWRef.get(); 71 if (previous == null) return true; 72 return previous.isVisible() == false; 73 } 74 75 78 protected void performAction(Node[] activatedNodes) { 79 Dialog dialog = (Dialog ) dialogWRef.get(); 80 81 if(dialog != null) { 82 dialog.setVisible(false); 83 dialog.dispose(); 84 } 85 86 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 (dialog); 99 dialog.setVisible(true); 100 } 101 102 104 private WizardDescriptor.Iterator getWizardIterator() { 105 ArrayList panels = new ArrayList (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 121 private void initWizard(WizardDescriptor wizardDesc) { 122 wizardDesc.putProperty("WizardPanel_autoWizardStyle", Boolean.TRUE); wizardDesc.putProperty("WizardPanel_contentDisplayed", Boolean.TRUE); wizardDesc.putProperty("WizardPanel_contentNumbered", Boolean.TRUE); 127 ArrayList contents = new ArrayList (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", (String [])contents.toArray(new String [contents.size()]) 139 ); 140 141 wizardDesc.setTitle(Util.getString("LBL_WizardTitle")); 142 wizardDesc.setTitleFormat(new MessageFormat ("{0} ({1})")); 144 wizardDesc.setModal(false); 145 } 146 147 148 public String getName() { 149 return Util.getString("LBL_WizardActionName"); 150 } 151 152 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 |