# This patch file was generated by NetBeans IDE # This patch can be applied using context Tools: Apply Diff Patch action on respective folder. # It uses platform neutral UTF-8 encoding. # Above lines and this line are ignored by the patching process. Index: utilities/jumpto/nbproject/project.xml --- utilities/jumpto/nbproject/project.xml Base (1.3) +++ utilities/jumpto/nbproject/project.xml Locally Modified (Based On 1.3) @@ -127,11 +127,13 @@ + org.netbeans.modules.j2ee.common org.netbeans.modules.java.sourceui org.netbeans.modules.ruby org.netbeans.modules.gsf org.netbeans.api.gsf org.netbeans.modules.cnd.gotodeclaration + org.netbeans.api.jumpto.type org.netbeans.spi.jumpto.type Index: utilities/jumpto/src/org/netbeans/api/jumpto/type/TypeBrowser.java --- utilities/jumpto/src/org/netbeans/api/jumpto/type/TypeBrowser.java No Base Revision +++ utilities/jumpto/src/org/netbeans/api/jumpto/type/TypeBrowser.java Locally New @@ -0,0 +1,57 @@ +/* + * The contents of this file are subject to the terms of the Common Development + * and Distribution License (the License). You may not use this file except in + * compliance with the License. + * + * You can obtain a copy of the License at http://www.netbeans.org/cddl.html + * or http://www.netbeans.org/cddl.txt. + * + * When distributing Covered Code, include this CDDL Header Notice in each file + * and include the License file at http://www.netbeans.org/cddl.txt. + * If applicable, add the following below the CDDL Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * The Original Software is NetBeans. The Initial Developer of the Original + * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun + * Microsystems, Inc. All Rights Reserved. + */ + +package org.netbeans.api.jumpto.type; + +import org.netbeans.modules.jumpto.type.GoToTypeAction; +import org.netbeans.spi.jumpto.type.TypeDescriptor; +import org.netbeans.spi.jumpto.type.TypeProvider; + +/** + * Support for browsing of the types. Opens search dialog for the type name + * with possibility to filter the results. + * + * @author Martin Adamek + */ +public final class TypeBrowser { + + /** + * Blocking call for opening modal search dialog + * + * @param title title of the dialog + * @param filter optional filter of the results; can be null + * @param typeProviders type providers defining the scope of the search; + * if none specified, all type providers from default lookup will be used + * @return selected type or null if dialog was canceled + */ + public static TypeDescriptor browse(String title, Filter filter, TypeProvider... typeProviders) { + GoToTypeAction goToTypeAction = new GoToTypeAction(title, filter, typeProviders); + return goToTypeAction.getSelectedType(); + } + + /** + * Filtering support + */ + public static interface Filter { + + boolean accept(TypeDescriptor typeDescriptor); + + } + +} Index: utilities/jumpto/src/org/netbeans/modules/jumpto/type/Bundle.properties --- utilities/jumpto/src/org/netbeans/modules/jumpto/type/Bundle.properties Base (1.2) +++ utilities/jumpto/src/org/netbeans/modules/jumpto/type/Bundle.properties Locally Modified (Based On 1.2) @@ -29,8 +29,8 @@ editor-popup-TXT_GoToType=Type... DLG_GoToType=Go to Type -AN_GoToType=Go To Type Dialog -AD_GoToType=Opens Dialog, which permits for quick opening of Types +AN_GoToType=Browse Type Dialog +AD_GoToType=Opens Dialog, which permits for quick browsing of Types TXT_Searching=Searching... TXT_NoTypesFound= Index: utilities/jumpto/src/org/netbeans/modules/jumpto/type/GoToPanel.form --- utilities/jumpto/src/org/netbeans/modules/jumpto/type/GoToPanel.form Base (1.2) +++ utilities/jumpto/src/org/netbeans/modules/jumpto/type/GoToPanel.form Locally Modified (Based On 1.2) @@ -55,9 +55,9 @@ + - Index: utilities/jumpto/src/org/netbeans/modules/jumpto/type/GoToPanel.java --- utilities/jumpto/src/org/netbeans/modules/jumpto/type/GoToPanel.java Base (1.4) +++ utilities/jumpto/src/org/netbeans/modules/jumpto/type/GoToPanel.java Locally Modified (Based On 1.4) @@ -40,6 +40,7 @@ import javax.swing.event.ListSelectionEvent; import javax.swing.event.ListSelectionListener; import javax.swing.text.BadLocationException; +import org.netbeans.api.jumpto.type.TypeBrowser; import org.netbeans.spi.jumpto.type.TypeDescriptor; import org.openide.filesystems.FileObject; import org.openide.filesystems.FileUtil; @@ -55,6 +56,7 @@ private ContentProvider contentProvider; private boolean containsScrollPane; private JLabel messageLabel; + private TypeDescriptor selectedType; // Time when the serach stared (for debugging purposes) long time = -1; @@ -133,12 +135,12 @@ }); } - public void openSelectedItem() { - TypeDescriptor selectedValue = ((TypeDescriptor) matchesList.getSelectedValue()); - if ( selectedValue != null ) { - // TODO - use TypeDescriptor.getOffset instead? - ((TypeDescriptor) matchesList.getSelectedValue()).open(); + public void setSelectedType() { + selectedType = ((TypeDescriptor) matchesList.getSelectedValue()); } + + public TypeDescriptor getSelectedType() { + return selectedType; } /** This method is called from within the constructor to @@ -286,7 +288,7 @@ private void nameFieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_nameFieldActionPerformed if (contentProvider.hasValidContent()) { contentProvider.closeDialog(); - openSelectedItem(); + setSelectedType(); } }//GEN-LAST:event_nameFieldActionPerformed @@ -423,7 +425,12 @@ // ListSelectionListener ----------------------------------------------- public void valueChanged(ListSelectionEvent ev) { - TypeDescriptor selectedValue = ((TypeDescriptor) dialog.matchesList.getSelectedValue()); + + // got "Not computed yet" text sometimes + Object obj = dialog.matchesList.getSelectedValue(); + + if (obj instanceof TypeDescriptor) { + TypeDescriptor selectedValue = ((TypeDescriptor) obj); if ( selectedValue != null ) { String fileName = ""; FileObject fo = selectedValue.getFileObject(); @@ -435,7 +442,10 @@ else { dialog.jTextFieldLocation.setText(""); } + } else { + dialog.jTextFieldLocation.setText(""); } + } private void update() { dialog.time = System.currentTimeMillis(); Index: utilities/jumpto/src/org/netbeans/modules/jumpto/type/GoToTypeAction.java --- utilities/jumpto/src/org/netbeans/modules/jumpto/type/GoToTypeAction.java Base (1.6) +++ utilities/jumpto/src/org/netbeans/modules/jumpto/type/GoToTypeAction.java Locally Modified (Based On 1.6) @@ -36,6 +36,7 @@ import java.io.IOException; import java.util.ArrayList; import java.util.ArrayList; +import java.util.Arrays; import java.util.Collection; import java.util.Collections; import java.util.Comparator; @@ -57,7 +58,9 @@ import javax.swing.SwingUtilities; import javax.swing.event.ChangeEvent; import javax.swing.event.ChangeListener; +import org.netbeans.api.jumpto.type.TypeBrowser; import org.netbeans.api.project.ui.OpenProjects; +import org.netbeans.modules.jumpto.file.LazyListModel; import org.openide.DialogDescriptor; import org.openide.DialogDisplayer; import org.openide.ErrorManager; @@ -72,11 +75,13 @@ import org.openide.util.Utilities; import org.openide.windows.TopComponent; -/** XXX Icons +/** + * XXX split into action and support class, left this just to minimize diff + * XXX Icons * XXX Don't look for all projects (do it lazy in filter or renderer) * @author Petr Hrebejk */ -public class GoToTypeAction extends AbstractAction implements GoToPanel.ContentProvider { +public class GoToTypeAction extends AbstractAction implements GoToPanel.ContentProvider, LazyListModel.Filter { static final Logger LOGGER = Logger.getLogger(GoToTypeAction.class.getName()); // Used from the panel as well @@ -88,26 +93,39 @@ private GoToPanel panel; private Dialog dialog; private JButton okButton; - private Collection typeProviders; + private final Collection typeProviders; + private final TypeBrowser.Filter typeFilter; + private final String title; - /** Creates a new instance of OpenTypeAction */ public GoToTypeAction() { + this( + NbBundle.getMessage( GoToTypeAction.class, "DLG_GoToType" ), + null, + Lookup.getDefault().lookupAll(TypeProvider.class).toArray(new TypeProvider[0]) + ); + } + + public GoToTypeAction(String title, TypeBrowser.Filter typeFilter, TypeProvider... typeProviders) { super( NbBundle.getMessage( GoToTypeAction.class,"TXT_GoToType") ); putValue("PopupMenuText", NbBundle.getBundle(GoToTypeAction.class).getString("editor-popup-TXT_GoToType")); // NOI18N + this.title = title; + this.typeFilter = typeFilter; + this.typeProviders = Arrays.asList(typeProviders); } public void actionPerformed( ActionEvent e ) { - try { - typeProviders = Lookup.getDefault().lookupAll(TypeProvider.class); + TypeDescriptor typeDescriptor = getSelectedType(); + if (typeDescriptor != null) { + typeDescriptor.open(); + } + } - panel = new GoToPanel( this ); + public TypeDescriptor getSelectedType() { + TypeDescriptor result = null; + try { + panel = new GoToPanel(this); dialog = createDialog(panel); - SwingUtilities.invokeLater( new Runnable() { - public void run() { - dialog.setVisible(true); - } - } ); Node[] arr = TopComponent.getRegistry ().getActivatedNodes(); String initSearchText = null; @@ -124,9 +142,13 @@ } } + dialog.setVisible(true); + result = panel.getSelectedType(); + } catch (IOException ex) { ErrorManager.getDefault().notify(ex); } + return result; } @Override @@ -134,7 +156,13 @@ return OpenProjects.getDefault().getOpenProjects().length>0; } + public boolean accept(Object obj) { + return typeFilter == null ? true : typeFilter.accept((TypeDescriptor) obj); + } + public void scheduleUpdate(Runnable run) { + SwingUtilities.invokeLater(run); + } // Implementation of content provider -------------------------------------- @@ -236,7 +264,7 @@ DialogDescriptor dialogDescriptor = new DialogDescriptor( panel, // innerPane - NbBundle.getMessage( GoToTypeAction.class, "DLG_GoToType" ), // NOI18N // displayName + title, // displayName true, new Object[] {okButton, DialogDescriptor.CANCEL_OPTION}, okButton, @@ -323,6 +351,9 @@ return; } ListModel model = Models.fromList(types); + if (typeFilter != null) { + model = LazyListModel.create(model, GoToTypeAction.this, 0.1, "Not computed yet");; + } if ( isCanceled ) { LOGGER.fine( "Worker for " + text + " exited after cancel " + ( System.currentTimeMillis() - createTime ) + " ms." ); return; @@ -554,7 +585,7 @@ public void actionPerformed(ActionEvent e) { if ( e.getSource() == okButton) { - panel.openSelectedItem(); + panel.setSelectedType(); } }