1 19 20 package org.netbeans.modules.web.wizards; 21 22 import java.awt.Component ; 23 import java.util.HashSet ; 24 import java.util.Iterator ; 25 import java.util.Set ; 26 import javax.swing.event.ChangeEvent ; 27 import javax.swing.event.ChangeListener ; 28 import org.netbeans.api.java.project.JavaProjectConstants; 29 30 import org.openide.WizardDescriptor; 31 import org.openide.util.HelpCtx; 32 import org.openide.loaders.TemplateWizard; 33 import org.openide.filesystems.FileObject; 34 35 import org.netbeans.api.project.Project; 36 import org.netbeans.api.project.ProjectUtils; 37 import org.netbeans.api.project.SourceGroup; 38 import org.netbeans.api.project.Sources; 39 import org.netbeans.spi.project.ui.templates.support.Templates; 40 41 46 public class TagInfoPanel implements WizardDescriptor.Panel { 47 48 52 private TagHandlerPanelGUI component; 53 private transient TemplateWizard wizard; 54 private transient Project proj; 55 private transient SourceGroup[] sourceGroups; 56 private String className; 57 58 59 public TagInfoPanel(TemplateWizard wizard, Project proj, SourceGroup[] sourceGroups) { 60 this.wizard=wizard; 61 this.proj=proj; 62 this.sourceGroups=sourceGroups; 63 } 64 65 public Component getComponent() { 70 if (component == null) { 71 component = new TagHandlerPanelGUI(wizard,this,proj,sourceGroups); 72 } 73 return component; 74 } 75 76 public HelpCtx getHelp() { 77 return HelpCtx.DEFAULT_HELP; 79 } 80 81 public boolean isValid() { 82 if (writeToTLD() && getTLDFile()==null) { 84 wizard.putProperty ("WizardPanel_errorMessage", org.openide.util.NbBundle.getMessage(TagInfoPanel.class, "MSG_noTldSelected")); return false; 86 } else if (!isValidTagName(getTagName())) { 87 wizard.putProperty ("WizardPanel_errorMessage", org.openide.util.NbBundle.getMessage(TagInfoPanel.class, "TXT_wrongTagName",getTagName())); return false; 89 } else if (tagNameExists(getTagName())) { 90 wizard.putProperty ("WizardPanel_errorMessage", org.openide.util.NbBundle.getMessage(TagInfoPanel.class, "TXT_tagNameExists",getTagName())); return false; 92 } else { 93 wizard.putProperty ("WizardPanel_errorMessage", ""); return true; 95 } 96 97 } 103 104 107 private final Set listeners = new HashSet (1); public final void addChangeListener (ChangeListener l) { 109 synchronized (listeners) { 110 listeners.add (l); 111 } 112 } 113 public final void removeChangeListener (ChangeListener l) { 114 synchronized (listeners) { 115 listeners.remove (l); 116 } 117 } 118 protected final void fireChangeEvent () { 119 Iterator it; 120 synchronized (listeners) { 121 it = new HashSet (listeners).iterator (); 122 } 123 ChangeEvent ev = new ChangeEvent (this); 124 while (it.hasNext ()) { 125 ((ChangeListener ) it.next ()).stateChanged (ev); 126 } 127 } 128 129 public void readSettings(Object settings) { 134 TemplateWizard w = (TemplateWizard)settings; 135 String targetName = w.getTargetName(); 137 org.openide.filesystems.FileObject targetFolder = Templates.getTargetFolder(w); 138 Project project = Templates.getProject( w ); 139 Sources sources = ProjectUtils.getSources(project); 140 SourceGroup[] groups = sources.getSourceGroups(JavaProjectConstants.SOURCES_TYPE_JAVA); 141 String packageName = null; 142 for (int i = 0; i < groups.length && packageName == null; i++) { 143 packageName = org.openide.filesystems.FileUtil.getRelativePath (groups [i].getRootFolder (), targetFolder); 144 } 145 if (packageName == null) 146 packageName = ""; packageName = packageName.replace('/','.'); 148 149 if (targetName!=null) { 150 if (packageName.length()>0) 151 className=packageName+"."+targetName; else 153 className=targetName; 154 component.setClassName(className); 155 if (component.getTagName().length()==0) 156 component.setTagName(targetName); 157 } 158 Boolean bodySupport = (Boolean )w.getProperty("BODY_SUPPORT"); if (bodySupport!=null && bodySupport.booleanValue()) 160 component.setBodySupport(true); 161 else component.setBodySupport(false); 162 } 163 public void storeSettings(Object settings) { 164 } 165 166 public String getClassName() { 167 return className; 168 } 169 public String getTagName() { 170 return component.getTagName(); 171 } 172 public FileObject getTLDFile() { 173 return component.getTLDFile(); 174 } 175 public boolean isEmpty() { 176 return component.isEmpty(); 177 } 178 public boolean isScriptless() { 179 return component.isScriptless(); 180 } 181 public boolean isTegdependent() { 182 return component.isTegdependent(); 183 } 184 public boolean writeToTLD() { 185 return component.writeToTLD(); 186 } 187 public Object [][] getAttributes() { 188 return component.getAttributes(); 189 } 190 191 private boolean isValidTagName(String name) { 192 return org.apache.xerces.util.XMLChar.isValidNCName(name); 193 } 194 195 private boolean tagNameExists(String name) { 196 java.util.Set tagValues = component.getTagValues(); 197 if (tagValues!=null && tagValues.contains(name)) return true; 198 else return false; 199 } 200 } 201 | Popular Tags |