1 19 20 package org.netbeans.modules.websvc.core.dev.wizard; 21 22 import java.io.IOException ; 23 import java.util.Collections ; 24 import java.util.NoSuchElementException ; 25 import java.util.Set ; 26 import javax.swing.JComponent ; 27 import org.netbeans.api.project.Project; 28 import org.netbeans.api.project.SourceGroup; 29 import org.netbeans.modules.websvc.core.CreatorProvider; 30 import org.netbeans.modules.websvc.core.HandlerCreator; 31 import org.netbeans.spi.java.project.support.ui.templates.JavaTemplates; 32 import org.netbeans.spi.project.ui.templates.support.Templates; 33 import org.openide.WizardDescriptor; 34 import javax.swing.event.ChangeListener ; 35 import org.openide.util.HelpCtx; 36 import org.openide.util.NbBundle; 37 import org.netbeans.modules.j2ee.common.Util; 38 39 public class LogicalHandlerWizard implements WizardDescriptor.InstantiatingIterator { 40 public int currentPanel = 0; 41 private WizardDescriptor.Panel [] wizardPanels; 42 private WizardDescriptor.Panel firstPanel; private WizardDescriptor wiz; 44 private Project project; 45 private String handlerName; 46 public static final String JAVAC_CLASSPATH = "javac.classpath"; 48 public static LogicalHandlerWizard create() { 49 return new LogicalHandlerWizard(); 50 } 51 52 private static final String [] HANDLER_STEPS = 53 new String [] { 54 NbBundle.getMessage(LogicalHandlerWizard.class, "LBL_SpecifyLogicalHandlerInfo") }; 56 57 public void initialize(WizardDescriptor wizard) { 58 59 wiz = wizard; 60 project = Templates.getProject(wiz); 61 SourceGroup[] sourceGroups = Util.getJavaSourceGroups(project); 62 63 66 if (sourceGroups.length == 0) 67 firstPanel = new FinishableProxyWizardPanel(Templates.createSimpleTargetChooser(project, sourceGroups, new BottomPanel())); 68 else 69 firstPanel = new FinishableProxyWizardPanel(JavaTemplates.createPackageChooser(project, sourceGroups, new BottomPanel(), true)); 70 71 JComponent c = (JComponent ) firstPanel.getComponent(); 72 Util.changeLabelInComponent(c, NbBundle.getMessage(LogicalHandlerWizard.class, "LBL_JavaTargetChooserPanelGUI_ClassName_Label"), NbBundle.getMessage(LogicalHandlerWizard.class, "LBL_LogicalHandler_Name") ); c.putClientProperty("WizardPanel_contentData", HANDLER_STEPS); 76 c.putClientProperty("WizardPanel_contentSelectedIndex", new Integer (0)); 78 c.getAccessibleContext().setAccessibleDescription 79 (HANDLER_STEPS[0]); 80 wizardPanels = new WizardDescriptor.Panel[] {firstPanel}; 81 } 82 83 public void uninitialize(WizardDescriptor wizard) { 84 } 85 86 public Set instantiate() throws IOException { 87 HandlerCreator creator = CreatorProvider.getHandlerCreator(project, wiz); 89 if (creator!=null) creator.createLogicalHandler(); 90 return Collections.EMPTY_SET; 91 } 92 93 94 public WizardDescriptor.Panel current() { 95 return wizardPanels[currentPanel]; 96 } 97 98 public boolean hasNext() { 99 return currentPanel < wizardPanels.length -1; 100 } 101 102 public boolean hasPrevious() { 103 return currentPanel > 0; 104 } 105 106 public String name() { 107 return NbBundle.getMessage(LogicalHandlerWizard.class, "LBL_Create_LogicalHandler_Title"); } 109 110 public void nextPanel() { 111 if(!hasNext()){ 112 throw new NoSuchElementException (); 113 } 114 currentPanel++; 115 } 116 117 public void previousPanel() { 118 if(!hasPrevious()){ 119 throw new NoSuchElementException (); 120 } 121 currentPanel--; 122 } 123 124 public void addChangeListener(javax.swing.event.ChangeListener l) { 125 } 126 127 public void removeChangeListener(ChangeListener l) { 128 } 129 130 131 protected int getCurrentPanelIndex() { 132 return currentPanel; 133 } 134 135 137 private class BottomPanel implements WizardDescriptor.Panel { 138 139 public void storeSettings(Object settings) { 140 } 141 142 public void readSettings(Object settings) { 143 } 144 145 public java.awt.Component getComponent() { 146 return new javax.swing.JPanel (); 147 } 148 149 public void addChangeListener(ChangeListener l) { 150 } 151 152 public void removeChangeListener(ChangeListener l) { 153 } 154 155 public boolean isValid() { 156 ProjectInfo creator = new ProjectInfo(project); 157 int projectType = creator.getProjectType(); 158 159 if (projectType == ProjectInfo.JSE_PROJECT_TYPE && Util.isSourceLevel16orHigher(project)) 160 return true; 161 162 if (projectType == ProjectInfo.JSE_PROJECT_TYPE && Util.getSourceLevel(project).equals("1.5")) { if (!PlatformUtil.hasJAXWSLibrary(project)) { 165 wiz.putProperty("WizardPanel_errorMessage", NbBundle.getMessage(BottomPanel.class, "LBL_LogicalHandlerWarning")); return false; 167 } else 168 return true; 169 } 170 171 if (Util.isJavaEE5orHigher(project) && (projectType == ProjectInfo.WEB_PROJECT_TYPE || projectType == ProjectInfo.EJB_PROJECT_TYPE)) { return true; 173 } 174 175 if(!Util.isJavaEE5orHigher(project) && projectType == ProjectInfo.WEB_PROJECT_TYPE 177 && !PlatformUtil.isJsr109Supported(project) 178 && !PlatformUtil.isJsr109OldSupported(project) ){ 179 if (Util.isSourceLevel14orLower(project)) { 181 wiz.putProperty("WizardPanel_errorMessage", 182 NbBundle.getMessage(LogicalHandlerWizard.class, "ERR_HandlerNeedProperSourceLevel")); return false; 184 } 185 if (!PlatformUtil.hasJAXWSLibrary(project)) { wiz.putProperty("WizardPanel_errorMessage", NbBundle.getMessage(BottomPanel.class, "LBL_LogicalHandlerWarning")); return false; 188 } else 189 return true; 190 } 191 192 wiz.putProperty("WizardPanel_errorMessage", NbBundle.getMessage(BottomPanel.class, "LBL_LogicalHandlerWarning")); 194 return false; 195 } 196 197 public HelpCtx getHelp() { 198 return new HelpCtx(LogicalHandlerWizard.class); 199 } 200 } 201 } 202 | Popular Tags |