1 19 20 package org.netbeans.modules.gsf; 21 22 import java.io.IOException ; 23 import java.util.ArrayList ; 24 import java.util.List ; 25 import javax.swing.Action ; 26 import org.netbeans.api.gsf.Completable; 27 import org.netbeans.api.gsf.BracketCompletion; 28 import org.netbeans.api.gsf.DeclarationFinder; 29 import org.netbeans.api.gsf.Formatter; 30 import org.netbeans.api.gsf.InstantRenamer; 31 import org.netbeans.api.gsf.Indexer; 32 import org.netbeans.modules.gsf.Language; 33 import org.netbeans.api.gsf.Parser; 34 import org.netbeans.api.gsf.GsfLanguage; 35 import org.netbeans.api.gsf.StructureScanner; 36 import org.netbeans.spi.palette.PaletteController; 37 import org.openide.ErrorManager; 38 import org.openide.cookies.InstanceCookie; 39 import org.openide.filesystems.FileObject; 40 import org.openide.loaders.DataObject; 41 import org.openide.loaders.DataObjectNotFoundException; 42 43 47 public class DefaultLanguage implements Language { 48 private String displayName; 49 private String iconBase; 50 private String mime; 51 private List <String > extensions; 52 private List <Action > actions; 53 private GsfLanguage language; 54 private Parser parser; 55 private Completable completionProvider; 56 private InstantRenamer renamer; 57 private DeclarationFinder declarationFinder; 58 private Formatter formatter; 59 private BracketCompletion bracketCompletion; 60 private Indexer indexer; 61 private StructureScanner structure; 62 private PaletteController palette; 63 private FileObject parserFile; 64 private FileObject languageFile; 65 private FileObject navigationFilterFile; 66 private FileObject completionProviderFile; 67 private FileObject renamerFile; 68 private FileObject declarationFinderFile; 69 private FileObject formatterFile; 70 private FileObject bracketCompletionFile; 71 private FileObject indexerFile; 72 private FileObject structureFile; 73 private FileObject paletteFile; 74 75 76 public DefaultLanguage(String mime) { 77 this.mime = mime; 78 } 79 80 public String getDisplayName() { 81 return displayName; 82 } 83 84 public void setDisplayName(String displayName) { 85 this.displayName = displayName; 86 } 87 88 public String getIconBase() { 89 return iconBase; 90 } 91 92 public void setIconBase(String iconBase) { 93 this.iconBase = iconBase; 94 } 95 96 public String getMimeType() { 97 return mime; 98 } 99 100 public void setMimeType(String mime) { 101 this.mime = mime; 102 } 103 104 public String [] getExtensions() { 105 if (extensions != null) { 106 return extensions.toArray(new String [extensions.size()]); 107 } else { 108 return new String [0]; 109 } 110 } 111 112 public Action [] getEditorActions() { 113 if (actions != null) { 114 return actions.toArray(new Action [actions.size()]); 115 } else { 116 return new Action [0]; 117 } 118 } 119 120 public GsfLanguage getGsfLanguage() { 121 if (language == null && languageFile != null) { 122 language = (GsfLanguage)createInstance(languageFile); 124 if (language == null) { 125 languageFile = null; 127 } 128 } 129 return language; 130 } 131 132 136 public void setGsfLanguageFile(FileObject languageFile) { 137 this.languageFile = languageFile; 138 } 139 140 public Parser getParser() { 141 if (parser == null && parserFile != null) { 142 parser = (Parser)createInstance(parserFile); 144 if (parser == null) { 145 parserFile = null; 147 } 148 } 149 return parser; 150 } 151 152 public void setParser(Parser parser) { 153 this.parser = parser; 154 } 155 156 public void setParserFile(FileObject parserFile) { 157 this.parserFile = parserFile; 158 } 159 160 public void addAction(Action action) { 161 if (actions == null) { 162 actions = new ArrayList <Action >(); 163 } 164 actions.add(action); 165 } 166 167 public void addExtension(String extension) { 168 if (extension == null || extension.length() == 0 || extension.startsWith(".")) { 169 throw new IllegalArgumentException ("Extension should be a nonzero string not starting with a dot"); 170 } 171 172 if (extensions == null) { 173 extensions = new ArrayList <String >(); 174 } 175 176 assert extension.equals(extension.toLowerCase()); 177 178 extensions.add(extension); 179 } 180 181 private Object createInstance(FileObject file) { 183 assert file.getExt().equals("instance"); try { 186 DataObject dobj = DataObject.find(file); 187 InstanceCookie ic = (InstanceCookie) dobj.getCookie(InstanceCookie.class); 188 return ic.instanceCreate(); 189 } catch (ClassNotFoundException e) { 190 ErrorManager.getDefault().notify(e); 191 } catch (DataObjectNotFoundException e) { 192 ErrorManager.getDefault().notify(e); 193 } catch (IOException e) { 194 ErrorManager.getDefault().notify(e); 195 } 196 return null; 197 } 198 199 public String toString() { 200 return mime + ":" + displayName; 201 } 202 203 public Completable getCompletionProvider() { 204 if (completionProvider == null && completionProviderFile != null) { 205 completionProvider = (Completable)createInstance(completionProviderFile); 207 if (completionProvider == null) { 208 completionProviderFile = null; 210 } 211 } 212 return completionProvider; 213 } 214 215 public void setCompletionProvider(Completable completionProvider) { 216 this.completionProvider = completionProvider; 217 } 218 219 public void setCompletionProviderFile(FileObject completionProviderFile) { 220 this.completionProviderFile = completionProviderFile; 221 } 222 223 public InstantRenamer getInstantRenamer() { 224 if (renamer == null && renamerFile != null) { 225 renamer = (InstantRenamer)createInstance(renamerFile); 226 if (renamer == null) { 227 renamerFile = null; 229 } 230 } 231 return renamer; 232 } 233 234 public void setInstantRenamerFile(FileObject renamerFile) { 235 this.renamerFile = renamerFile; 236 } 237 238 public DeclarationFinder getDeclarationFinder() { 239 if (declarationFinder == null && declarationFinderFile != null) { 240 declarationFinder = (DeclarationFinder)createInstance(declarationFinderFile); 241 if (declarationFinder == null) { 242 declarationFinderFile = null; 244 } 245 } 246 return declarationFinder; 247 } 248 249 public void setDeclarationFinderFile(FileObject declarationFinderFile) { 250 this.declarationFinderFile = declarationFinderFile; 251 } 252 253 public Formatter getFormatter() { 254 if (formatter == null && formatterFile != null) { 255 formatter = (Formatter)createInstance(formatterFile); 256 if (formatter == null) { 257 formatterFile = null; 259 } 260 } 261 return formatter; 262 } 263 264 public void setFormatterFile(FileObject formatterFile) { 265 this.formatterFile = formatterFile; 266 } 267 268 public BracketCompletion getBracketCompletion() { 269 if (bracketCompletion == null && bracketCompletionFile != null) { 270 bracketCompletion = (BracketCompletion)createInstance(bracketCompletionFile); 271 if (bracketCompletion == null) { 272 bracketCompletionFile = null; 274 } 275 } 276 return bracketCompletion; 277 } 278 279 public void setBracketCompletionFile(FileObject bracketCompletionFile) { 280 this.bracketCompletionFile = bracketCompletionFile; 281 } 282 283 public Indexer getIndexer() { 284 if (indexer == null && indexerFile != null) { 285 indexer = (Indexer)createInstance(indexerFile); 286 if (indexer == null) { 287 indexerFile = null; 289 } 290 } 291 return indexer; 292 } 293 294 public void setIndexerFile(FileObject indexerFile) { 295 this.indexerFile = indexerFile; 296 } 297 298 public StructureScanner getStructure() { 299 if (structure == null && structureFile != null) { 300 structure = (StructureScanner)createInstance(structureFile); 301 if (structure == null) { 302 structureFile = null; 304 } 305 } 306 return structure; 307 } 308 309 public void setStructureFile(FileObject structureFile) { 310 this.structureFile = structureFile; 311 } 312 313 314 315 public PaletteController getPalette() { 316 if (palette == null && paletteFile != null) { 317 palette = (PaletteController)createInstance(paletteFile); 318 if (palette == null) { 319 paletteFile = null; 321 } 322 } 323 return palette; 324 } 325 326 public void setPaletteFile(FileObject paletteFile) { 327 this.paletteFile = paletteFile; 328 } 329 } 330 | Popular Tags |