1 19 20 package org.netbeans.modules.tasklist.javaparser; 21 22 import javax.swing.text.*; 23 import javax.swing.event.*; 24 import java.awt.*; 25 import java.awt.event.*; 26 import javax.swing.*; 27 import java.util.List ; 28 import java.util.ArrayList ; 29 import java.util.Arrays ; 30 import java.util.Collections ; 31 import java.util.Comparator ; 32 import java.util.Iterator ; 33 import org.openide.ErrorManager; 34 import org.openide.cookies.SourceCookie; 35 import org.openide.explorer.view.*; 36 import org.openide.nodes.*; 37 import org.netbeans.modules.java.*; 38 39 40 41 import org.openide.src.Identifier; 42 import org.openide.src.Import; 43 import org.openide.src.SourceElement; 44 import org.openide.src.SourceException; 45 import org.openide.util.NbBundle; 46 import org.openide.util.Utilities; 47 48 import org.openide.cookies.LineCookie; 49 import org.openide.loaders.DataObject; 50 import org.openide.text.Line; 51 import org.openide.ErrorManager; 52 53 import java.util.TreeSet ; 54 import java.lang.reflect.Modifier ; 55 import org.netbeans.editor.ext.java.*; 56 import org.netbeans.modules.editor.java.*; 57 58 import org.netbeans.modules.tasklist.core.ConfPanel; 59 import org.netbeans.modules.tasklist.core.TLUtils; 60 import org.netbeans.modules.tasklist.client.Suggestion; 61 import org.netbeans.modules.tasklist.client.SuggestionPerformer; 62 63 64 69 class ImportPerformer implements SuggestionPerformer { 70 71 private DataObject dobj; 72 private Document doc; 73 private String beforeDesc; 74 private JCClass importClass; 75 private int lineno; 76 77 ImportPerformer(int lineno, DataObject dobj, 78 Document doc, JCClass importClass) { 79 this.lineno = lineno; 80 this.dobj = dobj; 81 this.doc = doc; 82 this.importClass = importClass; 83 84 } 85 86 public void perform(Suggestion s) { 88 importClass(doc, importClass); 89 } 90 91 public boolean hasConfirmation() { 92 return true; 93 } 94 95 public Object getConfirmation(Suggestion s) { 96 String filename = 97 dobj.getPrimaryFile().getNameExt(); 98 String beforeDesc = 99 NbBundle.getMessage(ImportPerformer.class, 100 "ImportClassConfirmation"); String beforeContents = 102 "<html><b>import " + importClass.toString() + 104 "</b></html>"; return new ConfPanel(beforeDesc, 106 beforeContents, null, 107 null, 108 filename, lineno, 109 null); 110 } 111 112 113 114 static void importClass(Document doc, Object item) { 115 if (item instanceof JCClass || item instanceof JCPackage) { 116 Object o = doc.getProperty(Document.StreamDescriptionProperty); 117 if (o instanceof DataObject) { 118 DataObject dob = (DataObject)o; 119 SourceCookie sc = (SourceCookie)dob.getCookie(SourceCookie.class); 120 if (sc != null) { 121 SourceElement se = sc.getSource(); 122 if (se != null) { 123 try { 124 if (item instanceof JCClass){ 125 JCClass cls = (JCClass)item; 126 se.addImport(new Import(Identifier.create(cls.getFullName()), false)); 127 }else if (item instanceof JCPackage){ 128 JCPackage pkg = (JCPackage)item; 129 se.addImport(new Import(Identifier.create(pkg.getName()), true)); 130 } 131 } catch (SourceException e) { 132 } 133 } 134 } 135 } 136 } 137 } 138 139 140 } 141 142 | Popular Tags |