X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;ds=sidebyside;f=bundles%2Forg.simantics.scl.ui%2Fsrc%2Forg%2Fsimantics%2Fscl%2Fui%2Fmodulebrowser%2FModuleNameTreeEntry.java;h=2461e5231e5535a504092acb15c0d132cb4b97c3;hb=1941a8f086ccdc3017c84dd149418114a499aee4;hp=6f657b35134859abc3b6285c468e906047fae908;hpb=e5b73a681e5035fae3b53825dceb3bbe48e921d3;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.scl.ui/src/org/simantics/scl/ui/modulebrowser/ModuleNameTreeEntry.java b/bundles/org.simantics.scl.ui/src/org/simantics/scl/ui/modulebrowser/ModuleNameTreeEntry.java index 6f657b351..2461e5231 100644 --- a/bundles/org.simantics.scl.ui/src/org/simantics/scl/ui/modulebrowser/ModuleNameTreeEntry.java +++ b/bundles/org.simantics.scl.ui/src/org/simantics/scl/ui/modulebrowser/ModuleNameTreeEntry.java @@ -1,12 +1,14 @@ package org.simantics.scl.ui.modulebrowser; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; +import java.util.Arrays; +import java.util.Iterator; import gnu.trove.map.hash.THashMap; public class ModuleNameTreeEntry implements Comparable { + 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 { 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,17 +48,31 @@ public class ModuleNameTreeEntry implements Comparable { 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); } return entry; } - public Collection children() { - ArrayList children = new ArrayList(childMap.values()); - Collections.sort(children); - return children; + public Object[] children() { + Object[] result = childMap.values().toArray(); + Arrays.sort(result); + return result; + } + + public void clearModuleFlags() { + isModule = false; + for(ModuleNameTreeEntry child : childMap.values()) + child.clearModuleFlags(); } @Override @@ -55,8 +80,13 @@ public class ModuleNameTreeEntry implements Comparable { return name.compareTo(o.name); } - @Override - public String toString() { - return name; + public boolean prune() { + Iterator it = childMap.values().iterator(); + while(it.hasNext()) { + ModuleNameTreeEntry entry = it.next(); + if(!entry.prune()) + it.remove(); + } + return isModule || !childMap.isEmpty(); } }