Handle occurrences in files that are not available locally gracefully.
authorJan Lahoda <jlahoda@netbeans.org>
Mon, 16 Jan 2012 18:48:12 +0100
changeset 726c32594fdc412
parent 725 4695734d3cde
child 727 8d768d51c409
Handle occurrences in files that are not available locally gracefully.
remoting/ide/usages/src/org/netbeans/modules/jackpot30/ide/usages/Nodes.java
remoting/ide/usages/src/org/netbeans/modules/jackpot30/ide/usages/RemoteUsages.java
     1.1 --- a/remoting/ide/usages/src/org/netbeans/modules/jackpot30/ide/usages/Nodes.java	Sun Jan 15 16:24:22 2012 +0100
     1.2 +++ b/remoting/ide/usages/src/org/netbeans/modules/jackpot30/ide/usages/Nodes.java	Mon Jan 16 18:48:12 2012 +0100
     1.3 @@ -61,6 +61,7 @@
     1.4  import java.util.LinkedList;
     1.5  import java.util.List;
     1.6  import java.util.Map;
     1.7 +import java.util.Map.Entry;
     1.8  import java.util.Set;
     1.9  import java.util.concurrent.atomic.AtomicBoolean;
    1.10  import java.util.logging.Level;
    1.11 @@ -87,6 +88,7 @@
    1.12  import org.netbeans.api.project.FileOwnerQuery;
    1.13  import org.netbeans.api.project.Project;
    1.14  import org.netbeans.api.project.ProjectUtils;
    1.15 +import org.netbeans.modules.jackpot30.remoting.api.RemoteIndex;
    1.16  import org.netbeans.spi.project.ui.LogicalViewProvider;
    1.17  import org.openide.actions.OpenAction;
    1.18  import org.openide.cookies.EditorCookie;
    1.19 @@ -115,7 +117,7 @@
    1.20   */
    1.21  public class Nodes {
    1.22  
    1.23 -    public static Node constructSemiLogicalView(Iterable<? extends FileObject> filesWithOccurrences, ElementHandle<?> eh, Set<RemoteUsages.SearchOptions> options) {
    1.24 +    public static Node constructSemiLogicalView(Iterable<? extends FileObject> filesWithOccurrences, Map<RemoteIndex, List<String>> unmappable, ElementHandle<?> eh, Set<RemoteUsages.SearchOptions> options) {
    1.25          Map<Project, Collection<FileObject>> projects = new HashMap<Project, Collection<FileObject>>();
    1.26  
    1.27          for (FileObject file : filesWithOccurrences) {
    1.28 @@ -137,7 +139,7 @@
    1.29              ClassPath.getClassPath(file, ClassPath.COMPILE).getRoots();
    1.30          }
    1.31  
    1.32 -        projects.remove(null);//XXX!!!XXX
    1.33 +        final Collection<FileObject> outsideProjects = projects.remove(null);
    1.34  
    1.35          List<Node> nodes = new ArrayList<Node>(projects.size());
    1.36  
    1.37 @@ -150,7 +152,56 @@
    1.38                  return o1.getDisplayName().compareToIgnoreCase(o2.getDisplayName());
    1.39              }
    1.40          });
    1.41 +
    1.42 +        if (outsideProjects != null) {
    1.43 +            AbstractNode outsideProjectsNode = new AbstractNode(Children.create(new ChildFactory<FileObject>() {
    1.44 +                @Override protected boolean createKeys(List<FileObject> toPopulate) {
    1.45 +                    toPopulate.addAll(outsideProjects);
    1.46 +                    return true;
    1.47 +                }
    1.48 +                @Override protected Node createNodeForKey(FileObject file) {
    1.49 +                    try {
    1.50 +                        DataObject od = DataObject.find(file);
    1.51 +                        return od.getNodeDelegate();
    1.52 +                    } catch (DataObjectNotFoundException ex) {
    1.53 +                        Exceptions.printStackTrace(ex);
    1.54 +                        return null;
    1.55 +                    }
    1.56 +                }
    1.57 +            }, true));
    1.58 +
    1.59 +            outsideProjectsNode.setDisplayName("Occurrences outside locally recognized projects");
    1.60 +            nodes.add(outsideProjectsNode);
    1.61 +        }
    1.62          
    1.63 +        if (!unmappable.isEmpty()) {
    1.64 +            List<Node> localNodes = new ArrayList<Node>(unmappable.size());
    1.65 +
    1.66 +            for (final Entry<RemoteIndex, List<String>> e : unmappable.entrySet()) {
    1.67 +                AbstractNode localNode = new AbstractNode(Children.create(new ChildFactory<String>() {
    1.68 +                    @Override protected boolean createKeys(List<String> toPopulate) {
    1.69 +                        Collections.sort(e.getValue());
    1.70 +                        toPopulate.addAll(e.getValue());
    1.71 +                        return true;
    1.72 +                    }
    1.73 +                    @Override protected Node createNodeForKey(String rel) {
    1.74 +                        AbstractNode fileNode = new AbstractNode(Children.LEAF);
    1.75 +
    1.76 +                        fileNode.setDisplayName(rel);
    1.77 +                        return fileNode;
    1.78 +                    }
    1.79 +                }, true));
    1.80 +
    1.81 +                localNode.setDisplayName("Index: " + e.getKey().remote.toExternalForm() + ", segment: " + e.getKey().remoteSegment);
    1.82 +                localNodes.add(localNode);
    1.83 +            }
    1.84 +
    1.85 +            AbstractNode notExisting = new AbstractNode(new DirectChildren(localNodes));
    1.86 +
    1.87 +            notExisting.setDisplayName("Occurrences in files that are not locally available");
    1.88 +            nodes.add(notExisting);
    1.89 +        }
    1.90 +
    1.91          return new AbstractNode(new DirectChildren(nodes));
    1.92      }
    1.93  
     2.1 --- a/remoting/ide/usages/src/org/netbeans/modules/jackpot30/ide/usages/RemoteUsages.java	Sun Jan 15 16:24:22 2012 +0100
     2.2 +++ b/remoting/ide/usages/src/org/netbeans/modules/jackpot30/ide/usages/RemoteUsages.java	Mon Jan 16 18:48:12 2012 +0100
     2.3 @@ -54,6 +54,7 @@
     2.4  import java.util.ArrayList;
     2.5  import java.util.Collection;
     2.6  import java.util.EnumSet;
     2.7 +import java.util.HashMap;
     2.8  import java.util.HashSet;
     2.9  import java.util.LinkedHashMap;
    2.10  import java.util.List;
    2.11 @@ -294,6 +295,7 @@
    2.12  
    2.13                  Set<FileObject> resultSet = new HashSet<FileObject>();
    2.14                  List<FileObject> result = new ArrayList<FileObject>();
    2.15 +                Map<RemoteIndex, List<String>> unmappable = new HashMap<RemoteIndex, List<String>>();
    2.16  
    2.17                  for (RemoteIndex idx : RemoteIndex.loadIndices()) {
    2.18                      FileObject localFolder = URLMapper.findFileObject(idx.getLocalFolder());
    2.19 @@ -308,8 +310,18 @@
    2.20                          for (String path : response) {
    2.21                              FileObject file = localFolder.getFileObject(path);
    2.22  
    2.23 -                            if (resultSet.add(file)) {
    2.24 -                                result.add(file);
    2.25 +                            if (file != null) {
    2.26 +                                if (resultSet.add(file)) {
    2.27 +                                    result.add(file);
    2.28 +                                }
    2.29 +                            } else {
    2.30 +                                List<String> um = unmappable.get(idx);
    2.31 +
    2.32 +                                if (um == null) {
    2.33 +                                    unmappable.put(idx, um = new ArrayList<String>());
    2.34 +                                }
    2.35 +
    2.36 +                                um.add(path);
    2.37                              }
    2.38                          }
    2.39                      }
    2.40 @@ -332,17 +344,28 @@
    2.41  
    2.42                          for (Entry<String, List<Map<String, String>>> e : formattedResponse.entrySet()) {
    2.43                              for (Map<String, String> p : e.getValue()) {
    2.44 -                                FileObject file = localFolder.getFileObject(p.get("file"));
    2.45 +                                String path = p.get("file");
    2.46 +                                FileObject file = localFolder.getFileObject(path);
    2.47  
    2.48 -                                if (resultSet.add(file)) {
    2.49 -                                    result.add(file);
    2.50 +                                if (file != null) {
    2.51 +                                    if (resultSet.add(file)) {
    2.52 +                                        result.add(file);
    2.53 +                                    }
    2.54 +                                } else {
    2.55 +                                    List<String> um = unmappable.get(idx);
    2.56 +
    2.57 +                                    if (um == null) {
    2.58 +                                        unmappable.put(idx, um = new ArrayList<String>());
    2.59 +                                    }
    2.60 +
    2.61 +                                    um.add(path);
    2.62                                  }
    2.63                              }
    2.64                          }
    2.65                      }
    2.66                  }
    2.67  
    2.68 -                final Node view = Nodes.constructSemiLogicalView(result, toSearch, options);
    2.69 +                final Node view = Nodes.constructSemiLogicalView(result, unmappable, toSearch, options);
    2.70  
    2.71                  if (!cancel.get()) {
    2.72                      SwingUtilities.invokeLater(new Runnable() {