1 19 20 package org.netbeans.modules.web.wizards; 21 22 import java.awt.Component ; 23 24 import javax.swing.event.ChangeListener ; 25 import org.netbeans.api.java.project.JavaProjectConstants; 26 import org.netbeans.api.project.Project; 27 import org.netbeans.api.project.ProjectUtils; 28 29 import org.openide.WizardDescriptor; 30 import org.openide.loaders.TemplateWizard; 31 import org.openide.util.HelpCtx; 32 import org.netbeans.spi.project.ui.templates.support.Templates; 33 import org.netbeans.modules.web.api.webmodule.WebModule; 34 import org.netbeans.api.project.SourceGroup; 35 import org.netbeans.api.project.Sources; 36 import org.openide.filesystems.FileObject; 37 38 43 public class ServletPanel implements WizardDescriptor.FinishPanel { 44 45 49 private transient BaseWizardPanel wizardPanel; 50 private transient TemplateWizard wizard; 51 52 private ChangeListener listener; 53 private DeployData deployData; 54 private transient TargetEvaluator evaluator; 55 56 57 private ServletPanel(TargetEvaluator evaluator, TemplateWizard wizard, 58 boolean first) { 59 this.evaluator=evaluator; 60 this.wizard = wizard; 61 this.deployData = evaluator.getDeployData(); 62 if(first) 63 this.wizardPanel = new DeployDataPanel(evaluator); 64 else 65 this.wizardPanel = new DeployDataExtraPanel(evaluator); 66 } 67 68 69 public static ServletPanel createServletPanel(TargetEvaluator evaluator, 70 TemplateWizard wizard) { 71 return new ServletPanel(evaluator, wizard, true); 72 } 73 74 75 public static ServletPanel createFilterPanel(TargetEvaluator evaluator, 76 TemplateWizard wizard) { 77 return new ServletPanel(evaluator, wizard, false); 78 } 79 80 public Component getComponent () { 81 return wizardPanel; 82 } 83 84 public boolean isValid() { 85 if(deployData.isValid()) { 86 wizard.putProperty("WizardPanel_errorMessage", ""); return true; 88 } 89 wizard.putProperty("WizardPanel_errorMessage", deployData.getErrorMessage()); 91 return false; 92 } 93 94 public HelpCtx getHelp() { 95 return null; 96 } 98 99 103 public void addChangeListener (ChangeListener l) { 104 if (listener != null) throw new IllegalStateException (); 105 if (wizardPanel != null) 106 wizardPanel.addChangeListener (l); 107 listener = l; 108 } 109 110 113 public void removeChangeListener (ChangeListener l) { 114 listener = null; 115 if (wizardPanel != null) 116 wizardPanel.removeChangeListener (l); 117 } 118 119 public void readSettings (Object settings) { 120 if(settings instanceof TemplateWizard) { 121 TemplateWizard w = (TemplateWizard)settings; 122 String targetName = w.getTargetName(); 124 org.openide.filesystems.FileObject targetFolder = Templates.getTargetFolder(w); 125 Project project = Templates.getProject( w ); 126 Sources sources = ProjectUtils.getSources(project); 127 SourceGroup[] groups = sources.getSourceGroups(JavaProjectConstants.SOURCES_TYPE_JAVA); 128 String packageName = null; 129 for (int i = 0; i < groups.length && packageName == null; i++) { 130 if (WebModule.getWebModule (groups [i].getRootFolder ()) != null) { 131 packageName = org.openide.filesystems.FileUtil.getRelativePath (groups [i].getRootFolder (), targetFolder); 132 } 133 } 134 if (packageName!=null) 135 packageName = packageName.replace('/','.'); 136 else packageName=""; 137 if (targetName==null) 138 evaluator.setClassName(w.getTemplate().getName(),packageName); 139 else 140 evaluator.setClassName(targetName,packageName); 141 } 142 wizardPanel.setData(); 143 } 144 145 public void storeSettings (Object settings) { 146 } 148 } | Popular Tags |