Commits

Jan Lahoda committed 1db6d70

Ability to search more than one project through web UI.

Comments (0)

Files changed (2)

remoting/server/web/web.ui/src/org/netbeans/modules/jackpot30/backend/ui/UI.java

     @GET
     @Path("/search")
     @Produces("text/html")
-    public String searchType(@QueryParam("path") String path, @QueryParam("prefix") String prefix) throws URISyntaxException, IOException, TemplateException {
+    public String searchType(@QueryParam("path") List<String> paths, @QueryParam("prefix") String prefix) throws URISyntaxException, IOException, TemplateException {
         Map<String, Object> configurationData = new HashMap<String, Object>();
+        Map<String,Map<String, String>> pathsList = list();
 
-        configurationData.put("paths", list());
-        configurationData.put("selectedPath", path);
+        configurationData.put("paths", pathsList.values());
+        configurationData.put("selectedPath", paths);
         configurationData.put("prefix", prefix);
 
-        if (prefix != null && path != null) {
-            URI u = new URI(URL_BASE + "/symbol/search?path=" + escapeForQuery(path) + "&prefix=" + escapeForQuery(prefix));
-            @SuppressWarnings("unchecked") //XXX: should not trust something got from the network!
-            Map<String, List<Map<String, Object>>> symbols = Pojson.load(LinkedHashMap.class, u);
+        if (prefix != null && paths != null) {
             List<Map<String, Object>> results = new LinkedList<Map<String, Object>>();
 
-            for (Entry<String, List<Map<String, Object>>> e : symbols.entrySet()) {
-                for (Map<String, Object> found : e.getValue()) {
-                    found.put("icon", getElementIcon((String) found.get("kind"), (Collection<String>) found.get("modifiers")));
-                    if ("METHOD".equals(found.get("kind")) || "CONSTRUCTOR".equals(found.get("kind"))) {
-                        found.put("displayName", found.get("simpleName") + decodeMethodSignature((String) found.get("signature")));
-                    } else {
-                        found.put("displayName", found.get("simpleName"));
+            for (String path : paths) {
+                URI u = new URI(URL_BASE + "/symbol/search?path=" + escapeForQuery(path) + "&prefix=" + escapeForQuery(prefix));
+                @SuppressWarnings("unchecked") //XXX: should not trust something got from the network!
+                Map<String, List<Map<String, Object>>> symbols = Pojson.load(LinkedHashMap.class, u);
+                Map<String, ?> segmentDescription = pathsList.get(path);
+
+                for (Entry<String, List<Map<String, Object>>> e : symbols.entrySet()) {
+                    for (Map<String, Object> found : e.getValue()) {
+                        found.put("icon", getElementIcon((String) found.get("kind"), (Collection<String>) found.get("modifiers")));
+                        if ("METHOD".equals(found.get("kind")) || "CONSTRUCTOR".equals(found.get("kind"))) {
+                            found.put("displayName", found.get("simpleName") + decodeMethodSignature((String) found.get("signature")));
+                        } else {
+                            found.put("displayName", found.get("simpleName"));
+                        }
+
+                        found.put("segment", segmentDescription);
+
+                        results.add(found);
                     }
+                }
 
-                    results.add(found);
+                URI typeSearch = new URI(URL_BASE + "/type/search?path=" + escapeForQuery(path) + "&prefix=" + escapeForQuery(prefix));
+                @SuppressWarnings("unchecked") //XXX: should not trust something got from the network!
+                Map<String, List<String>> types = Pojson.load(LinkedHashMap.class, typeSearch);
+
+                for (Entry<String, List<String>> e : types.entrySet()) {
+                    for (String fqn : e.getValue()) {
+                        Map<String, Object> result = new HashMap<String, Object>();
+
+                        result.put("icon", getElementIcon("CLASS", Collections.<String>emptyList()));
+                        result.put("kind", "CLASS");
+                        result.put("fqn", fqn);
+
+                        String displayName = fqn;
+                        String enclosingFQN = "";
+
+                        if (displayName.lastIndexOf('.') > 0) {
+                            displayName = displayName.substring(displayName.lastIndexOf('.') + 1);
+                            enclosingFQN = fqn.substring(0, fqn.lastIndexOf('.'));
+                        }
+
+                        if (displayName.lastIndexOf('$') > 0) {
+                            displayName = displayName.substring(displayName.lastIndexOf('$') + 1);
+                            enclosingFQN = fqn.substring(0, fqn.lastIndexOf('$'));
+                        }
+
+                        result.put("displayName", displayName);
+                        result.put("enclosingFQN", enclosingFQN);
+
+                        if (fqn.contains("$")) {
+                            fqn = fqn.substring(0, fqn.indexOf("$"));
+                        }
+
+                        result.put("file", e.getKey() + fqn.replace('.', '/') + ".java");
+
+                        result.put("segment", segmentDescription);
+
+                        results.add(result);
+                    }
                 }
+
+                Collections.sort(results, new Comparator<Map<String, Object>>() {
+                    @Override public int compare(Map<String, Object> o1, Map<String, Object> o2) {
+                        int r = ((String) o1.get("displayName")).compareTo((String) o2.get("displayName"));
+
+                        if (r == 0) {
+                            r = ((String) o1.get("enclosingFQN")).compareTo((String) o2.get("enclosingFQN"));
+                        }
+                        return r;
+                    }
+                });
+
             }
 
-            URI typeSearch = new URI(URL_BASE + "/type/search?path=" + escapeForQuery(path) + "&prefix=" + escapeForQuery(prefix));
-            @SuppressWarnings("unchecked") //XXX: should not trust something got from the network!
-            Map<String, List<String>> types = Pojson.load(LinkedHashMap.class, typeSearch);
-
-            for (Entry<String, List<String>> e : types.entrySet()) {
-                for (String fqn : e.getValue()) {
-                    Map<String, Object> result = new HashMap<String, Object>();
-
-                    result.put("icon", getElementIcon("CLASS", Collections.<String>emptyList()));
-                    result.put("kind", "CLASS");
-                    result.put("fqn", fqn);
-
-                    String displayName = fqn;
-                    String enclosingFQN = "";
-
-                    if (displayName.lastIndexOf('.') > 0) {
-                        displayName = displayName.substring(displayName.lastIndexOf('.') + 1);
-                        enclosingFQN = fqn.substring(0, fqn.lastIndexOf('.'));
-                    }
-
-                    if (displayName.lastIndexOf('$') > 0) {
-                        displayName = displayName.substring(displayName.lastIndexOf('$') + 1);
-                        enclosingFQN = fqn.substring(0, fqn.lastIndexOf('$'));
-                    }
-
-                    result.put("displayName", displayName);
-                    result.put("enclosingFQN", enclosingFQN);
-
-                    if (fqn.contains("$")) {
-                        fqn = fqn.substring(0, fqn.indexOf("$"));
-                    }
-
-                    result.put("file", e.getKey() + fqn.replace('.', '/') + ".java");
-
-                    results.add(result);
-                }
-            }
-
-            Collections.sort(results, new Comparator<Map<String, Object>>() {
-                @Override public int compare(Map<String, Object> o1, Map<String, Object> o2) {
-                    int r = ((String) o1.get("displayName")).compareTo((String) o2.get("displayName"));
-
-                    if (r == 0) {
-                        r = ((String) o1.get("enclosingFQN")).compareTo((String) o2.get("enclosingFQN"));
-                    }
-                    return r;
-                }
-            });
-
             configurationData.put("results", results);
         }
 

remoting/server/web/web.ui/src/org/netbeans/modules/jackpot30/backend/ui/ui-findType.html

     <script type="text/javascript">
         function methodPopup(relativePath, resultFile, signature) {
             $('#popup').html('<a href="/index/ui/show?path=' + relativePath + '&relative=' + resultFile + '">Source Code</a><br>' +
-                             '<a href="/index/ui/usages?path=' + relativePath + '&signatures=' + signature + '">Usages in the current project</a><br>' +
+                             '<a href="/index/ui/usages?path=' + relativePath + '&signatures=' + signature + '">Usages in the defining project</a><br>' +
                              '<a href="/index/ui/usages?signatures=' + signature + '">Usages in all known projects</a><br>' +
-                             '<a href="/index/ui/implements?path=' + relativePath + '&method=' + signature + '">Overriders in the current project</a><br>' +
+                             '<a href="/index/ui/implements?path=' + relativePath + '&method=' + signature + '">Overriders in the defining project</a><br>' +
                              '<a href="/index/ui/implements?method=' + signature + '">Overriders in all known projects</a><br>')
                             .dialog({
                                 title: 'Show',
         }
         function classPopup(relativePath, resultFile, signature) {
             $('#popup').html('<a href="/index/ui/show?path=' + relativePath + '&relative=' + resultFile + '">Source Code</a><br>' +
-                             '<a href="/index/ui/usages?path=' + relativePath + '&signatures=' + signature + '">Usages in the current project</a><br>' +
+                             '<a href="/index/ui/usages?path=' + relativePath + '&signatures=' + signature + '">Usages in the defining project</a><br>' +
                              '<a href="/index/ui/usages?signatures=' + signature + '">Usages in all known projects</a><br>' +
-                             '<a href="/index/ui/implements?path=' + relativePath + '&type=' + signature + '">Subtypes in the current project</a><br>' +
+                             '<a href="/index/ui/implements?path=' + relativePath + '&type=' + signature + '">Subtypes in the defining project</a><br>' +
                              '<a href="/index/ui/implements?type=' + signature + '">Subtypes in all known projects</a><br>')
                             .dialog({
                                 title: 'Show',
         }
         function otherPopup(relativePath, resultFile, signature) {
             $('#popup').html('<a href="/index/ui/show?path=' + relativePath + '&relative=' + resultFile + '">Source Code</a><br>' +
-                             '<a href="/index/ui/usages?path=' + relativePath + '&signatures=' + signature + '">Usages in the current project</a><br>' +
+                             '<a href="/index/ui/usages?path=' + relativePath + '&signatures=' + signature + '">Usages in the defining project</a><br>' +
                              '<a href="/index/ui/usages?signatures=' + signature + '">Usages in all known projects</a><br>')
                             .dialog({
                                 title: 'Show'
 </head>
 <body>
 <form method="get">
-<label for="path">Project:</label>
-<select size="1" name="path">");
-    <#list paths as path>
-        <option <#if selectedPath?? && path.segment == selectedPath>selected</#if> value="${path.segment}">
-            ${path.displayName}
-        </option>
-    </#list>
-</select>
+<label>Projects:</label>
+<#list paths as path>
+    <input type="checkbox" name="path" value="${path.segment}" <#if selectedPath?seq_contains(path.segment)> checked="yes"</#if>>${path.displayName}</input>
+</#list>
 <br>
 <label for="prefix">Symbol Prefix:</label><input type="text" name="prefix"<#if prefix??>value="${prefix}"</#if>/><br>
 <input type="submit" name="Find Candidates"/>
 
 <#if results??>
     Found symbols:<br>
+    <table>
         <#list results as result>
+        <tr>
+            <td>
+                <nobr>
                 <img src="/index/icons/${result.icon}" alt="${result.kind}"/>
                 <#if result.kind == "METHOD">
-                    <a href="javascript: methodPopup('${selectedPath}', '${result.file}', '${result.kind}:${result.enclosingFQN}:${result.simpleName}:${result.signature}')">
+                    <a href="javascript: methodPopup('${result.segment.segment}', '${result.file}', '${result.kind}:${result.enclosingFQN}:${result.simpleName}:${result.signature}')">
                 <#elseif result.kind == "CLASS" || result.kind == "INTERFACE" || result.kind == "ENUM" || result.kind == "ANNOTATION_TYPE">
-                    <a href="javascript: classPopup('${selectedPath}', '${result.file}', '${result.kind}:${result.fqn}')">
+                    <a href="javascript: classPopup('${result.segment.segment}', '${result.file}', '${result.kind}:${result.fqn}')">
                 <#else>
-                    <a href="javascript: otherPopup('${selectedPath}', '${result.file}', '${result.kind}:${result.enclosingFQN}:${result.simpleName}')">
+                    <a href="javascript: otherPopup('${result.segment.segment}', '${result.file}', '${result.kind}:${result.enclosingFQN}:${result.simpleName}')">
                 </#if>
                 ${result.displayName?replace("&", "&amp;")?replace("<", "&lt;")}</a> in ${result.enclosingFQN?replace("&", "&amp;")?replace("<", "&lt;")}
-                <br>
+                </nobr>
+            </td>
+            <td width="100%" align="right">${result.segment.displayName?replace("&", "&amp;")?replace("<", "&lt;")}</td>
+        </tr>
         </#list>
 </#if>