From: Hannu Niemistö Date: Tue, 13 Jun 2017 12:08:33 +0000 (+0300) Subject: (refs #7296) Improvements to SCL module tree X-Git-Tag: v1.31.0~324 X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=834c0385eca07bde8e4ce7888b814e41f5e302ee;p=simantics%2Fplatform.git (refs #7296) Improvements to SCL module tree Separate folder for StandardLibrary. Handling of module names starting with http://. Change-Id: I695e6ca75a06b636c33e63cab259334ea989a429 --- 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 4c3bf1a2c..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 @@ -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 { + 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,7 +48,15 @@ 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); }