(refs #7296) Improvements to SCL module tree 21/621/1
authorHannu Niemistö <hannu.niemisto@semantum.fi>
Tue, 13 Jun 2017 12:08:33 +0000 (15:08 +0300)
committerHannu Niemistö <hannu.niemisto@semantum.fi>
Tue, 13 Jun 2017 12:08:33 +0000 (15:08 +0300)
Separate folder for StandardLibrary. Handling of module names starting
with http://.

Change-Id: I695e6ca75a06b636c33e63cab259334ea989a429

bundles/org.simantics.scl.ui/src/org/simantics/scl/ui/modulebrowser/ModuleNameTreeEntry.java

index 4c3bf1a2c9df1495da8bc101922c957f6fea9003..2461e5231e5535a504092acb15c0d132cb4b97c3 100644 (file)
@@ -2,11 +2,13 @@ package org.simantics.scl.ui.modulebrowser;
 
 import java.util.Arrays;
 import java.util.Iterator;
-import java.util.Map.Entry;
 
 import gnu.trove.map.hash.THashMap;
 
 public class ModuleNameTreeEntry implements Comparable<ModuleNameTreeEntry> {
+    public static final String STANDARD_LIBRARY = "StandardLibrary";
+    public static final String HTTP_PREFIX = "http://";
+    
     public final ModuleNameTreeEntry parent;
     public final String fullName;
     public final String name;
@@ -21,11 +23,20 @@ public class ModuleNameTreeEntry implements Comparable<ModuleNameTreeEntry> {
     
     public void addModule(String moduleFullName) {
         int startingPos = fullName.isEmpty() ? 0 : fullName.length()+1;
-        int p = moduleFullName.indexOf('/', startingPos);
+        int p;
+        if(parent == null && moduleFullName.startsWith(HTTP_PREFIX))
+            p = moduleFullName.indexOf('/', HTTP_PREFIX.length());
+        else
+            p = moduleFullName.indexOf('/', startingPos);
         if(p == -1) {
-            String name = moduleFullName.substring(startingPos);
-            ModuleNameTreeEntry entry = getOrCreateChildMapEntry(name);
-            entry.isModule = true;
+            if(parent == null) {
+                getOrCreateChildMapEntry(STANDARD_LIBRARY).addModule(name);
+            }
+            else {
+                String name = moduleFullName.substring(startingPos);
+                ModuleNameTreeEntry entry = getOrCreateChildMapEntry(name);
+                entry.isModule = true;
+            }
         }
         else {
             String name = moduleFullName.substring(startingPos, p);
@@ -37,7 +48,15 @@ public class ModuleNameTreeEntry implements Comparable<ModuleNameTreeEntry> {
     private ModuleNameTreeEntry getOrCreateChildMapEntry(String name) {
         ModuleNameTreeEntry entry = childMap.get(name);
         if(entry == null) {
-            String newFullName = fullName.isEmpty() ? name : fullName + "/" + name;
+            String newFullName;
+            if(parent == null) {
+                if(name.equals(STANDARD_LIBRARY))
+                    newFullName = "";
+                else
+                    newFullName = name;
+            }
+            else
+                newFullName = fullName + "/" + name;
             entry = new ModuleNameTreeEntry(this, newFullName, name);
             childMap.put(name, entry);
         }