KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > java > actions > GoToTypeAction


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.java.actions;
21
22 import java.awt.BorderLayout JavaDoc;
23 import java.awt.Component JavaDoc;
24 import java.awt.Color JavaDoc;
25 import java.awt.Container JavaDoc;
26 import java.awt.Dialog JavaDoc;
27 import java.awt.Dimension JavaDoc;
28 import java.awt.Rectangle JavaDoc;
29 import java.awt.event.ActionEvent JavaDoc;
30 import java.awt.event.ActionListener JavaDoc;
31 import java.awt.event.WindowAdapter JavaDoc;
32 import java.awt.event.WindowEvent JavaDoc;
33 import java.io.IOException JavaDoc;
34 import java.util.ArrayList JavaDoc;
35 import java.util.ArrayList JavaDoc;
36 import java.util.Collections JavaDoc;
37 import java.util.EnumSet JavaDoc;
38 import java.util.HashSet JavaDoc;
39 import java.util.List JavaDoc;
40 import java.util.Set JavaDoc;
41 import java.util.logging.Level JavaDoc;
42 import java.util.logging.Logger JavaDoc;
43 import javax.lang.model.element.ElementKind;
44 import javax.lang.model.element.TypeElement;
45 import javax.swing.AbstractAction JavaDoc;
46 import javax.swing.DefaultListModel JavaDoc;
47 import javax.swing.JButton JavaDoc;
48 import javax.swing.ListCellRenderer JavaDoc;
49 import javax.swing.DefaultListCellRenderer JavaDoc;
50 import javax.swing.Icon JavaDoc;
51 import javax.swing.JEditorPane JavaDoc;
52 import javax.swing.JLabel JavaDoc;
53 import javax.swing.JList JavaDoc;
54 import javax.swing.JList JavaDoc;
55 import javax.swing.JPanel JavaDoc;
56 import javax.swing.JViewport JavaDoc;
57 import javax.swing.ListModel JavaDoc;
58 import javax.swing.SwingUtilities JavaDoc;
59 import javax.swing.event.ChangeEvent JavaDoc;
60 import javax.swing.event.ChangeListener JavaDoc;
61 import org.netbeans.api.java.classpath.ClassPath;
62 import org.netbeans.api.java.queries.SourceForBinaryQuery;
63 import org.netbeans.api.java.source.ClassIndex;
64 import org.netbeans.api.java.source.ClassIndex.NameKind;
65 import org.netbeans.api.java.source.ClasspathInfo;
66 import org.netbeans.api.java.source.ElementHandle;
67 import org.netbeans.api.java.source.UiUtils;
68 import org.netbeans.api.project.FileOwnerQuery;
69 import org.netbeans.api.project.Project;
70 import org.netbeans.api.project.ProjectInformation;
71 import org.netbeans.api.project.ProjectInformation;
72 import org.netbeans.api.project.ProjectUtils;
73 import org.netbeans.modules.java.source.usages.RepositoryUpdater;
74 import org.netbeans.modules.java.source.util.Models;
75 import org.netbeans.spi.java.classpath.support.ClassPathSupport;
76 import org.openide.DialogDescriptor;
77 import org.openide.DialogDisplayer;
78 import org.openide.ErrorManager;
79 import org.openide.cookies.EditorCookie;
80 import org.openide.filesystems.FileObject;
81 import org.openide.filesystems.FileStateInvalidException;
82 import org.openide.filesystems.FileUtil;
83 import org.openide.nodes.Node;
84 import org.openide.util.HelpCtx;
85 import org.openide.util.NbBundle;
86 import org.openide.util.RequestProcessor;
87 import org.openide.util.Utilities;
88 import org.openide.windows.TopComponent;
89
90 /** XXX Icons
91  * XXX Don't look for all projects (do it lazy in filter or renderer)
92  * @author Petr Hrebejk
93  */

94 public class GoToTypeAction extends AbstractAction JavaDoc implements GoToPanel.ContentProvider {
95     
96     private static final Logger JavaDoc LOGGER = Logger.getLogger(GoToTypeAction.class.getName());
97     private static final ClassPath EMPTY_CLASSPATH = ClassPathSupport.createClassPath( new FileObject[0] );
98     private ClassIndex.NameKind nameKind;
99     private static ListModel JavaDoc EMPTY_LIST_MODEL = new DefaultListModel JavaDoc();
100     private static final RequestProcessor rp = new RequestProcessor ("GoToTypeAction-RequestProcessor",1);
101     private Worker running;
102     private RequestProcessor.Task task;
103     private GoToPanel panel;
104     private Set JavaDoc<CacheItem> cache;
105     private Dialog JavaDoc dialog;
106     private JButton JavaDoc okButton;
107
108     
109     /** Creates a new instance of OpenTypeAction */
110     public GoToTypeAction() {
111         super( NbBundle.getMessage( GoToTypeAction.class,"TXT_GoToType") );
112         putValue("PopupMenuText", NbBundle.getBundle(GoToTypeAction.class).getString("editor-popup-TXT_GoToType")); // NOI18N
113
}
114     
115     public void actionPerformed( ActionEvent JavaDoc e ) {
116         try {
117             cache = null;
118                        
119             panel = new GoToPanel( this );
120             dialog = createDialog(panel);
121             SwingUtilities.invokeLater( new Runnable JavaDoc() {
122                 public void run() {
123                     dialog.setVisible(true);
124                 }
125             } );
126             
127             Node[] arr = TopComponent.getRegistry ().getActivatedNodes();
128             String JavaDoc initSearchText = null;
129             if (arr.length > 0) {
130                 EditorCookie ec = arr[0].getCookie (EditorCookie.class);
131                 if (ec != null) {
132                     JEditorPane JavaDoc[] openedPanes = ec.getOpenedPanes ();
133                     if (openedPanes != null) {
134                         initSearchText = org.netbeans.editor.Utilities.getSelectionOrIdentifier(openedPanes [0]);
135                         if (initSearchText != null && org.openide.util.Utilities.isJavaIdentifier(initSearchText)) {
136                             panel.setInitialText(initSearchText);
137                         }
138                     }
139                 }
140             }
141             
142         } catch (IOException JavaDoc ex) {
143             ErrorManager.getDefault().notify(ex);
144         }
145     }
146     
147     
148     
149     // Implementation of content provider --------------------------------------
150

151     
152     public ListCellRenderer JavaDoc getListCellRenderer( JList JavaDoc list ) {
153         return new Renderer JavaDoc( list );
154     }
155     
156     
157     public void setListModel( GoToPanel panel, String JavaDoc text ) {
158         if (okButton != null) {
159             okButton.setEnabled (false);
160         }
161         if ( running != null ) {
162             running.cancel();
163             task.cancel();
164             running = null;
165         }
166         
167         if ( text == null ) {
168             panel.setModel(EMPTY_LIST_MODEL);
169             return;
170         }
171         
172         text = text.trim();
173         
174         if ( text.length() == 0) {
175             panel.setModel(EMPTY_LIST_MODEL);
176             return;
177         }
178         
179         if (isAllUpper(text)) {
180             nameKind = NameKind.CAMEL_CASE;
181         }
182         else if (containsWildCard(text) != -1) {
183             if (Character.isJavaIdentifierStart(text.charAt(0))) {
184                 nameKind = panel.isCaseSensitive() ? NameKind.REGEXP : NameKind.CASE_INSENSITIVE_REGEXP;
185             }
186             else {
187                 panel.setModel(EMPTY_LIST_MODEL);
188                 return;
189             }
190                 
191         }
192         else {
193             nameKind = panel.isCaseSensitive() ? NameKind.PREFIX : NameKind.CASE_INSENSITIVE_PREFIX;
194         }
195         
196         // Compute in other thread
197

198         synchronized( this ) {
199             running = new Worker( text );
200             task = rp.post( running, 220);
201         }
202     }
203     
204     public void closeDialog() {
205         dialog.setVisible( false );
206         cleanup();
207     }
208     
209     public boolean hasValidContent () {
210         return this.okButton != null && this.okButton.isEnabled();
211     }
212     
213     // Private methods ---------------------------------------------------------
214

215     private static boolean isAllUpper( String JavaDoc text ) {
216         for( int i = 0; i < text.length(); i++ ) {
217             if ( !Character.isUpperCase( text.charAt( i ) ) ) {
218                 return false;
219             }
220         }
221         
222         return true;
223     }
224     
225     private static int containsWildCard( String JavaDoc text ) {
226         for( int i = 0; i < text.length(); i++ ) {
227             if ( text.charAt( i ) == '?' || text.charAt( i ) == '*' ) {
228                 return i;
229             }
230         }
231         return -1;
232     }
233     
234     
235     /** Creates the dialog to show
236      */

237    private Dialog JavaDoc createDialog( final GoToPanel panel) {
238        
239         okButton = new JButton JavaDoc (NbBundle.getMessage(GoToTypeAction.class, "CTL_OK"));
240         okButton.setEnabled (false);
241         panel.getAccessibleContext().setAccessibleName( NbBundle.getMessage( GoToTypeAction.class, "AN_GoToType") ); //NOI18N
242
panel.getAccessibleContext().setAccessibleDescription( NbBundle.getMessage( GoToTypeAction.class, "AD_GoToType") ); //NOI18N
243

244         DialogDescriptor dialogDescriptor = new DialogDescriptor(
245             panel, // innerPane
246
NbBundle.getMessage( GoToTypeAction.class, "DLG_GoToType" ), // NOI18N // displayName
247
true,
248             new Object JavaDoc[] {okButton, DialogDescriptor.CANCEL_OPTION},
249             okButton,
250             DialogDescriptor.DEFAULT_ALIGN,
251             HelpCtx.DEFAULT_HELP,
252             new DialogButtonListener( panel ) ); // Action listener
253

254          dialogDescriptor.setClosingOptions(new Object JavaDoc[] {okButton, DialogDescriptor.CANCEL_OPTION});
255             
256         // panel.addPropertyChangeListener( new HelpCtxChangeListener( dialogDescriptor, helpCtx ) );
257
// if ( panel instanceof HelpCtx.Provider ) {
258
// dialogDescriptor.setHelpCtx( ((HelpCtx.Provider)panel).getHelpCtx() );
259
// }
260

261         Dialog JavaDoc d = DialogDisplayer.getDefault().createDialog( dialogDescriptor );
262         
263         // Set size
264
d.setPreferredSize( new Dimension JavaDoc( UiOptions.GoToTypeDialog.getWidth(),
265                                    UiOptions.GoToTypeDialog.getHeight() ) );
266         
267         // Center the dialog after the size changed.
268
Rectangle JavaDoc r = Utilities.getUsableScreenBounds();
269         int maxW = (r.width * 9) / 10;
270         int maxH = (r.height * 9) / 10;
271         Dimension JavaDoc dim = d.getPreferredSize();
272         dim.width = Math.min(dim.width, maxW);
273         dim.height = Math.min(dim.height, maxH);
274         d.setBounds(Utilities.findCenterBounds(dim));
275         
276         d.addWindowListener(new WindowAdapter JavaDoc() {
277             public void windowClosed(WindowEvent JavaDoc e) {
278                 cleanup();
279             }
280         });
281         
282         return d;
283
284     }
285     
286     private void cleanup() {
287         //System.out.println("CLEANUP");
288
//Thread.dumpStack();
289

290         if ( GoToTypeAction.this.dialog != null ) { // Closing event for some reson sent twice
291

292             // Save dialog size
293
UiOptions.GoToTypeDialog.setHeight(dialog.getHeight());
294             UiOptions.GoToTypeDialog.setWidth(dialog.getWidth());
295             
296             // Clean caches
297
GoToTypeAction.this.dialog.dispose();
298             GoToTypeAction.this.dialog = null;
299             GoToTypeAction.this.cache = null;
300         }
301     }
302     
303     // Private classes ---------------------------------------------------------
304

305     
306     private class Worker implements Runnable JavaDoc {
307         
308         private volatile boolean isCanceled = false;
309         private final String JavaDoc text;
310         
311         public Worker( String JavaDoc text ) {
312             this.text = text;
313        }
314         
315         public void run() {
316             List JavaDoc<TypeDescription> types = getTypeNames( text );
317             if ( isCanceled ) {
318                 return;
319             }
320             ListModel JavaDoc model = Models.fromList( types );
321             if ( isCanceled ) {
322                 return;
323             }
324             
325             if ( !isCanceled && model != null ) {
326                 panel.setModel(model);
327                 if (okButton != null && !types.isEmpty()) {
328                     okButton.setEnabled (true);
329                 }
330             }
331         }
332         
333         public void cancel() {
334             isCanceled = true;
335         }
336         
337         private List JavaDoc<TypeDescription> getTypeNames( String JavaDoc text ) {
338         
339             long time;
340             
341             long cp, gss, gsb, sfb, gtn, add, sort;
342             cp = gss = gsb = sfb = gtn = add = sort = 0;
343             
344             if (cache == null) {
345                 LOGGER.fine("GoToTypeAction.getTypeNames recreates cache\n");
346                 // Sources
347
time = System.currentTimeMillis();
348                 ClassPath scp = RepositoryUpdater.getDefault().getScannedSources();
349                 FileObject roots[] = scp.getRoots();
350                 gss += System.currentTimeMillis() - time;
351                 FileObject root[] = new FileObject[1];
352                 Set JavaDoc<CacheItem> sources = new HashSet JavaDoc<CacheItem>( roots.length );
353                 for (int i = 0; i < roots.length; i++ ) {
354                     root[0] = roots[i];
355                     time = System.currentTimeMillis();
356                     ClasspathInfo ci = ClasspathInfo.create( EMPTY_CLASSPATH, EMPTY_CLASSPATH, ClassPathSupport.createClassPath(root)); //create(roots[i]);
357
LOGGER.fine("GoToTypeAction.getTypeNames created ClasspathInfo for source: " + FileUtil.getFileDisplayName(roots[i])+"\n");
358                     if ( isCanceled ) {
359                         return null;
360                     }
361                     else {
362                         sources.add( new CacheItem( roots[i], ci, false ) );
363                     }
364                     cp += System.currentTimeMillis() - time;
365                 }
366                      
367                 
368                 
369                 // Binaries
370
time = System.currentTimeMillis();
371                 scp = RepositoryUpdater.getDefault().getScannedBinaries();
372                 roots = scp.getRoots();
373                 gsb += System.currentTimeMillis() - time;
374                 root = new FileObject[1];
375                 for (int i = 0; i < roots.length; i++ ) {
376                     try {
377                         time = System.currentTimeMillis();
378                         SourceForBinaryQuery.Result result = SourceForBinaryQuery.findSourceRoots(roots[i].getURL());
379                         if ( result.getRoots().length == 0 ) {
380                             continue;
381                         }
382                         sfb += System.currentTimeMillis() - time;
383                         time = System.currentTimeMillis();
384                         root[0] = roots[i];
385                         ClasspathInfo ci = ClasspathInfo.create(ClassPathSupport.createClassPath(root), EMPTY_CLASSPATH, EMPTY_CLASSPATH );//create(roots[i]);
386
LOGGER.fine("GoToTypeAction.getTypeNames created ClasspathInfo for binary: " + FileUtil.getFileDisplayName(roots[i])+"\n");
387                         sources.add( new CacheItem( roots[i], ci, true ) );
388                         cp += System.currentTimeMillis() - time;
389                     }
390                     catch ( FileStateInvalidException e ) {
391                         continue;
392                     }
393                 }
394                 if ( !isCanceled ) {
395                     cache = sources;
396                 }
397                 else {
398                     return null;
399                 }
400                 
401             }
402             LOGGER.fine("GoToTypeAction.getTypeNames collected : " + cache.size() +" elements\n");
403             
404             ArrayList JavaDoc<TypeDescription> types = new ArrayList JavaDoc<TypeDescription>(cache.size() * 20);
405             
406             for( CacheItem ci : cache ) {
407                 time = System.currentTimeMillis();
408                 
409                 String JavaDoc textForQuery;
410                 switch( nameKind ) {
411                     case REGEXP:
412                     case CASE_INSENSITIVE_REGEXP:
413                         String JavaDoc pattern = text + "*"; // NOI18N
414
pattern = pattern.replace( "*", ".*" ).replace( '?', '.' );
415                         textForQuery = pattern;
416                         break;
417                     default:
418                         textForQuery = text;
419                 }
420                 LOGGER.fine("GoToTypeAction.getTypeNames queries usages of: " + ci.classpathInfo+"\n");
421                 Set JavaDoc<ElementHandle<TypeElement>> names = ci.classpathInfo.getClassIndex().getDeclaredTypes(textForQuery, nameKind, EnumSet.of( ci.isBinary ? ClassIndex.SearchScope.DEPENDENCIES : ClassIndex.SearchScope.SOURCE ));
422                 if ( isCanceled ) {
423                     return null;
424                 }
425                 
426                 gtn += System.currentTimeMillis() - time;
427                 time = System.currentTimeMillis();
428                 
429 // Removed because of bad performance To reenable see diff between 1.15 and 1.16
430
// ClassPath.Entry defEntry = ci.getDefiningEntry();
431
for (ElementHandle<TypeElement> name : names) {
432 // Removed because of bad performance To reenable see diff between 1.15 and 1.16
433
// if (defEntry.includes(convertToSourceName(name.getBinaryName()))) {
434
TypeDescription td = new TypeDescription(ci, name );
435                         types.add(td);
436 // }
437
if ( isCanceled ) {
438                         return null;
439                     }
440                 }
441                 add += System.currentTimeMillis() - time;
442             }
443             
444             if ( !isCanceled ) {
445                 time = System.currentTimeMillis();
446                 Collections.sort(types);
447                 sort += System.currentTimeMillis() - time;
448                 Logger.getLogger(GoToTypeAction.class.getName()).log(Level.INFO, "PERF - " + " GSS: " + gss + " GSB " + gsb + " CP: " + cp + " SFB: " + sfb + " GTN: " + gtn + " ADD: " + add + " SORT: " + sort );
449                  return types;
450             }
451             else {
452                 return null;
453             }
454         }
455         
456     }
457
458     
459 // Removed because of bad performance To reenable see diff between 1.15 and 1.16
460
//
461
// private static String convertToSourceName (String binaryName) {
462
// binaryName = binaryName.replace ('.','/'); //NOI18N
463
// int index = binaryName.lastIndexOf('/'); //NOI18N
464
// if (index < 0) {
465
// index = 0;
466
// }
467
// index = binaryName.indexOf(index,'$'); //NOI18N
468
// if (index > 0) {
469
// binaryName = binaryName.substring(0, index);
470
// }
471
// return binaryName + ".java"; //NOI18N
472
// }
473

474     private static class Renderer extends DefaultListCellRenderer JavaDoc implements ChangeListener JavaDoc {
475          
476         private JPanel JavaDoc rendererComponent;
477         private JLabel JavaDoc jlName = new JLabel JavaDoc();
478         private JLabel JavaDoc jlPkg = new JLabel JavaDoc();
479         private JLabel JavaDoc jlPrj = new JLabel JavaDoc();
480         private int DARKER_COLOR_COMPONENT = 5;
481         private int LIGHTER_COLOR_COMPONENT = 80;
482         private Color JavaDoc fgColor;
483         private Color JavaDoc fgColorLighter;
484         private Color JavaDoc bgColor;
485         private Color JavaDoc bgColorDarker;
486         private Color JavaDoc bgSelectionColor;
487         private Color JavaDoc fgSelectionColor;
488         
489         private JList JavaDoc jList;
490         
491         public Renderer( JList JavaDoc list ) {
492             
493             jList = list;
494             
495             Container JavaDoc container = list.getParent();
496             if ( container instanceof JViewport JavaDoc ) {
497                 ((JViewport JavaDoc)container).addChangeListener(this);
498                 stateChanged(new ChangeEvent JavaDoc(container));
499             }
500             
501             rendererComponent = new JPanel JavaDoc();
502             rendererComponent.setLayout(new BorderLayout JavaDoc());
503             rendererComponent.add( jlName, BorderLayout.WEST );
504             rendererComponent.add( jlPkg, BorderLayout.CENTER);
505             rendererComponent.add( jlPrj, BorderLayout.EAST );
506             
507             
508             jlName.setOpaque(false);
509             jlPkg.setOpaque(false);
510             jlPrj.setOpaque(false);
511             
512             jlName.setFont(list.getFont());
513             jlPkg.setFont(list.getFont());
514             jlPrj.setFont(list.getFont());
515             
516             
517             jlPrj.setHorizontalAlignment(RIGHT);
518             jlPrj.setHorizontalTextPosition(LEFT);
519             
520             // setFont( list.getFont() );
521
fgColor = list.getForeground();
522             fgColorLighter = new Color JavaDoc(
523                                    Math.min( 255, fgColor.getRed() + LIGHTER_COLOR_COMPONENT),
524                                    Math.min( 255, fgColor.getGreen() + LIGHTER_COLOR_COMPONENT),
525                                    Math.min( 255, fgColor.getBlue() + LIGHTER_COLOR_COMPONENT)
526                                   );
527                             
528             bgColor = list.getBackground();
529             bgColorDarker = new Color JavaDoc(
530                                     Math.abs(bgColor.getRed() - DARKER_COLOR_COMPONENT),
531                                     Math.abs(bgColor.getGreen() - DARKER_COLOR_COMPONENT),
532                                     Math.abs(bgColor.getBlue() - DARKER_COLOR_COMPONENT)
533                             );
534             bgSelectionColor = list.getSelectionBackground();
535             fgSelectionColor = list.getSelectionForeground();
536         }
537         
538         public Component JavaDoc getListCellRendererComponent( JList JavaDoc list,
539                                                        Object JavaDoc value,
540                                                        int index,
541                                                        boolean isSelected,
542                                                        boolean hasFocus) {
543             
544             // System.out.println("Renderer for index " + index );
545

546             int height = list.getFixedCellHeight();
547             int width = list.getFixedCellWidth() - 1;
548             
549             width = width < 200 ? 200 : width;
550             
551             // System.out.println("w, h " + width + ", " + height );
552

553             Dimension JavaDoc size = new Dimension JavaDoc( width, height );
554             rendererComponent.setMaximumSize(size);
555             rendererComponent.setPreferredSize(size);
556                         
557             if ( isSelected ) {
558                 jlName.setForeground(fgSelectionColor);
559                 jlPkg.setForeground(fgSelectionColor);
560                 jlPrj.setForeground(fgSelectionColor);
561                 rendererComponent.setBackground(bgSelectionColor);
562             }
563             else {
564                 jlName.setForeground(fgColor);
565                 jlPkg.setForeground(fgColorLighter);
566                 jlPrj.setForeground(fgColor);
567                 rendererComponent.setBackground( index % 2 == 0 ? bgColor : bgColorDarker );
568             }
569             
570             if ( value instanceof TypeDescription ) {
571                 TypeDescription td = (TypeDescription)value;
572                 jlName.setIcon(td.getIcon());
573                 jlName.setText(td.getTypeName());
574                 jlPkg.setText(td.getPackageName());
575                 jlPrj.setText(td.getProjectName());
576                 jlPrj.setIcon(td.getProjectIcon());
577                 rendererComponent.setToolTipText( FileUtil.getFileDisplayName(td.getFileObject()));
578             }
579             else {
580                 jlName.setText( value.toString() );
581             }
582             
583             return rendererComponent;
584         }
585         
586         public void stateChanged(ChangeEvent JavaDoc event) {
587             
588             JViewport JavaDoc jv = (JViewport JavaDoc)event.getSource();
589             
590             jlName.setText( "Sample" ); // NOI18N
591
jlName.setIcon(UiUtils.getElementIcon(ElementKind.CLASS, null));
592             
593             jList.setFixedCellHeight(jlName.getPreferredSize().height);
594             jList.setFixedCellWidth(jv.getExtentSize().width);
595         }
596
597      }
598     
599     static class CacheItem {
600
601         public final boolean isBinary;
602         public final FileObject fileObject;
603         public final ClasspathInfo classpathInfo;
604         public String JavaDoc projectName;
605         public Icon JavaDoc projectIcon;
606         private ClassPath.Entry defEntry;
607                 
608         public CacheItem ( FileObject fileObject, ClasspathInfo classpathInfo, boolean isBinary ) {
609             this.isBinary = isBinary;
610             this.fileObject = fileObject;
611             this.classpathInfo = classpathInfo;
612         }
613         
614 // Removed because of bad performance To reenable see diff between 1.15 and 1.16
615
//
616
// public ClassPath.Entry getDefiningEntry () {
617
// if (defEntry == null) {
618
// ClassPath defCp = ClassPath.getClassPath(fileObject, ClassPath.SOURCE);
619
// if (defCp != null) {
620
// for (ClassPath.Entry e : defCp.entries()) {
621
// if (fileObject.equals(e.getRoot())) {
622
// defEntry = e;
623
// break;
624
// }
625
// }
626
// }
627
// }
628
// return defEntry;
629
// }
630

631         @Override JavaDoc
632         public int hashCode () {
633             return this.fileObject == null ? 0 : this.fileObject.hashCode();
634         }
635         
636         @Override JavaDoc
637         public boolean equals (Object JavaDoc other) {
638             if (other instanceof CacheItem) {
639                 CacheItem otherItem = (CacheItem) other;
640                 return this.fileObject == null ? otherItem.fileObject == null : this.fileObject.equals(otherItem.fileObject);
641             }
642             return false;
643         }
644     
645         public FileObject getRoot() {
646             return fileObject;
647         }
648         
649         public boolean isBinary() {
650             return isBinary;
651         }
652         
653         public synchronized String JavaDoc getProjectName() {
654             if ( !isBinary && projectName == null) {
655                 initProjectInfo();
656             }
657             return projectName;
658         }
659         
660         public synchronized Icon JavaDoc getProjectIcon() {
661             if ( !isBinary && projectIcon == null ) {
662                 initProjectInfo();
663             }
664             return projectIcon;
665         }
666         
667         private void initProjectInfo() {
668             Project p = FileOwnerQuery.getOwner(fileObject);
669             if (p != null) {
670                 ProjectInformation pi = ProjectUtils.getInformation( p );
671                 projectName = pi.getDisplayName();
672                 projectIcon = pi.getIcon();
673             }
674         }
675         
676     }
677
678     
679     private class DialogButtonListener implements ActionListener JavaDoc {
680         
681         private GoToPanel panel;
682         
683         public DialogButtonListener( GoToPanel panel ) {
684             this.panel = panel;
685         }
686         
687         public void actionPerformed(ActionEvent JavaDoc e) {
688             if ( e.getSource() == okButton) {
689                 panel.openSelectedItem();
690             }
691         }
692         
693     }
694     
695 }
696
Popular Tags