1 19 20 package org.netbeans.modules.tasklist.i18n; 21 22 import java.text.MessageFormat ; 23 import java.util.List ; 24 import java.util.ArrayList ; 25 import java.util.Arrays ; 26 import java.util.logging.*; 27 import javax.swing.text.BadLocationException ; 28 import javax.swing.text.Document ; 29 import javax.swing.text.StyledDocument ; 30 import org.netbeans.api.mdr.MDRepository; 31 import org.netbeans.jmi.javamodel.Element; 32 import org.netbeans.jmi.javamodel.Resource; 33 import org.netbeans.jmi.javamodel.StringLiteral; 34 import org.netbeans.modules.javacore.api.JavaModel; 35 36 import org.openide.ErrorManager; 37 import org.openide.filesystems.FileObject; 38 import org.openide.loaders.DataObject; 39 import org.openide.loaders.DataObjectNotFoundException; 40 import org.openide.util.NbBundle; 41 42 import org.netbeans.modules.tasklist.client.*; 43 import org.netbeans.modules.tasklist.providers.DocumentSuggestionProvider; 44 import org.netbeans.modules.tasklist.providers.SuggestionContext; 45 import org.netbeans.modules.tasklist.core.TLUtils; 46 import org.netbeans.modules.tasklist.core.util.TextPositionsMapper; 47 import org.openide.text.NbDocument; 48 49 50 55 public class TranslateSuggestionProvider extends DocumentSuggestionProvider { 56 public final static String TYPE = "nb-tasklist-i18n"; public static final Logger LOGGER = TLUtils.getLogger(TranslateSuggestionProvider.class); 58 private static final String TEXT = NbBundle.getMessage( 59 TranslateSuggestionProvider.class, "ProblemText"); 61 static { 62 LOGGER.setLevel(Level.FINE); 63 Thread t = new Thread (new TranslateOpenProjectsScanner()); 64 t.setPriority(Thread.MIN_PRIORITY); 65 t.setDaemon(true); 66 t.start(); 67 } 68 69 70 private List showingTasks = null; 71 72 public TranslateSuggestionProvider() { 73 } 74 75 public String getType() { 76 return TYPE; 77 } 78 79 public void rescan(SuggestionContext env, Object request) { 80 List newTasks = scan(env); 81 SuggestionManager manager = SuggestionManager.getDefault(); 82 83 if ((newTasks == null) && (showingTasks == null)) { 84 return; 85 } 86 manager.register(TYPE, newTasks, showingTasks); 87 showingTasks = newTasks; 88 } 89 90 public List scan(SuggestionContext env) { 91 SuggestionManager manager = SuggestionManager.getDefault(); 92 if (!manager.isEnabled(TYPE)) { 93 return null; 94 } 95 TranslateFileChecker c = new TranslateFileChecker(env.getFileObject()); 96 TranslateFileChecker.Error[] err = c.run(); 97 List tasks = new ArrayList (err.length); 98 99 for (int i = 0; i < err.length; i++) { 100 SuggestionPerformer action = new AddI18NCommentPerformer(); 101 String text = MessageFormat.format(TEXT, new Object [] { 102 err[i].constant 103 }); 104 SuggestionAgent problem = SuggestionManager.getDefault(). 105 createSuggestion(null, TYPE, text, action, null); 106 try { 107 DataObject dataObject = DataObject.find(env.getFileObject()); 108 problem.setLine(TLUtils.getLineByNumber(dataObject, 109 err[i].line + 1)); 110 } catch (DataObjectNotFoundException e) { 111 ErrorManager.getDefault().notify(e); 113 } 114 tasks.add(problem.getSuggestion()); 115 } 116 117 return tasks; 118 } 119 120 public void clear(SuggestionContext env, 121 Object request) { 122 if (showingTasks != null) { 124 SuggestionManager manager = SuggestionManager.getDefault(); 125 manager.register(TYPE, null, showingTasks); 126 showingTasks = null; 127 } 128 } 129 130 } 131 | Popular Tags |