Improved indication of built-in modules vs. third-party ones, better sorting and pruning of libraries
1.1 --- a/nodejs/manifest.mf Sat Jun 30 03:03:57 2012 -0400
1.2 +++ b/nodejs/manifest.mf Sat Jun 30 04:04:12 2012 -0400
1.3 @@ -3,5 +3,5 @@
1.4 OpenIDE-Module-Layer: org/netbeans/modules/nodejs/layer.xml
1.5 OpenIDE-Module-Localizing-Bundle: org/netbeans/modules/nodejs/Bundle.properties
1.6 OpenIDE-Module-Requires: org.openide.modules.os.Unix
1.7 -OpenIDE-Module-Specification-Version: 1.17
1.8 +OpenIDE-Module-Specification-Version: 1.18
1.9
2.1 --- a/nodejs/src/org/netbeans/modules/nodejs/NodeProjectSourceNodeFactory.java Sat Jun 30 03:03:57 2012 -0400
2.2 +++ b/nodejs/src/org/netbeans/modules/nodejs/NodeProjectSourceNodeFactory.java Sat Jun 30 04:04:12 2012 -0400
2.3 @@ -131,13 +131,16 @@
2.4 FileObject[] files = this.project.getProjectDirectory().getChildren();
2.5 Arrays.sort(files, new FOComparator());
2.6 List<FileObject> flds = new LinkedList();
2.7 +
2.8 + List<Key> sources = new ArrayList<Key>();
2.9 +
2.10 for (FileObject fo : files) {
2.11 if (fo.equals(libFolder)) {
2.12 continue;
2.13 }
2.14 if (q.isVisible(fo)) {
2.15 if (fo.isData()) {
2.16 - keys.add(new Key(KeyTypes.SOURCE, fo));
2.17 + sources.add(new Key(KeyTypes.SOURCE, fo));
2.18 } else if (fo.isFolder()) {
2.19 if (fo.getName().equals("package.json") || fo.equals(libFolder)) {
2.20 continue;
2.21 @@ -200,7 +203,7 @@
2.22 if (libDir != null) {
2.23 File f = new File(libDir, lib + ".js");
2.24 if ((f.exists()) && (f.isFile()) && (f.canRead())) {
2.25 - Key key = new Key(KeyTypes.LIBRARY, FileUtil.toFileObject(FileUtil.normalizeFile(f)));
2.26 + Key key = new Key(KeyTypes.BUILT_IN_LIBRARY, FileUtil.toFileObject(FileUtil.normalizeFile(f)));
2.27 keys.add(key);
2.28 continue;
2.29 }
2.30 @@ -230,7 +233,27 @@
2.31 key.references = paths;
2.32 keys.add(key);
2.33 }
2.34 -
2.35 + Collections.sort(keys);
2.36 + keys.addAll(0, sources);
2.37 + for (Iterator<Key> it=keys.iterator(); it.hasNext();) {
2.38 + Key k = it.next();
2.39 + if (k.type == KeyTypes.MISSING_LIBRARY) {
2.40 + for (Key k1 : new LinkedList<Key>(keys)) {
2.41 + if (k == k1) {
2.42 + continue;
2.43 + }
2.44 + if (k.toString().equals(k1.toString()) && k1.type != KeyTypes.MISSING_LIBRARY) {
2.45 + it.remove();
2.46 + } else if (k.type == k1.type && k.toString().equals(k1.toString())) {
2.47 + it.remove();
2.48 + }
2.49 + if (k.fld != null && k1.fld != null && k.fld.equals(k1.fld)) {
2.50 + it.remove();
2.51 + }
2.52 + }
2.53 + }
2.54 + }
2.55 +
2.56 for (FileObject fo : flds) {
2.57 if (fo.getName().equals("node_modules")) {
2.58 continue;
2.59 @@ -312,32 +335,45 @@
2.60 case SOURCE:
2.61 return new FilterNode(nodeFromKey(key));
2.62 case BUILT_IN_LIBRARY:
2.63 - AbstractNode li = new AbstractNode(Children.LEAF);
2.64 - li.setName(key.toString());
2.65 - li.setDisplayName(key.toString());
2.66 - li.setShortDescription("Built-in library '" + key + "'");
2.67 - li.setIconBaseWithExtension("org/netbeans/modules/nodejs/resources/libs.png"); //NOI18N
2.68 - return li;
2.69 + if (key.fld != null) {
2.70 + return new LibraryFilterNode(key);
2.71 + } else {
2.72 + AbstractNode li = new AbstractNode(Children.LEAF) {
2.73 + @Override
2.74 + public String getHtmlDisplayName() {
2.75 + return "<font color=\"#22AA22\">" + key; //NOI18N
2.76 + }
2.77 + };
2.78 + li.setName(key.toString());
2.79 + li.setDisplayName(key.toString());
2.80 + li.setShortDescription("Built-in library '" + key + "'");
2.81 + li.setIconBaseWithExtension("org/netbeans/modules/nodejs/resources/libs.png"); //NOI18N
2.82 + return li;
2.83 + }
2.84 case MISSING_LIBRARY:
2.85 - AbstractNode an = new AbstractNode(Children.LEAF) {
2.86 - @Override
2.87 - public String getHtmlDisplayName() {
2.88 - return "<font color=\"#EE0000\">" + key; //NOI18N
2.89 + if (key.fld != null) {
2.90 + return new LibraryFilterNode(key);
2.91 + } else {
2.92 + AbstractNode an = new AbstractNode(Children.LEAF) {
2.93 + @Override
2.94 + public String getHtmlDisplayName() {
2.95 + return "<font color=\"#CC0000\">" + key; //NOI18N
2.96 + }
2.97 + };
2.98 + an.setName(key.toString());
2.99 + an.setDisplayName(key.toString());
2.100 + StringBuilder sb = new StringBuilder("<html>Missing library <b><i>" + key + "</i></b>");
2.101 + if (key instanceof Key.MissingLibrary && ((Key.MissingLibrary) key).references != null && !((Key.MissingLibrary) key).references.isEmpty()) {
2.102 + sb.append("<p>Referenced By<br><ul>");
2.103 + for (String path : ((Key.MissingLibrary) key).references) {
2.104 + sb.append("<li>").append(path).append("</li>\n");
2.105 + }
2.106 + sb.append("</ul></pre></blockquote></html>");
2.107 }
2.108 - };
2.109 - an.setName(key.toString());
2.110 - an.setDisplayName(key.toString());
2.111 - StringBuilder sb = new StringBuilder("<html>Missing library <b><i>" + key + "</i></b>");
2.112 - if (key instanceof Key.MissingLibrary && ((Key.MissingLibrary) key).references != null && !((Key.MissingLibrary) key).references.isEmpty()) {
2.113 - sb.append("<p>Referenced By<br><ul>");
2.114 - for (String path : ((Key.MissingLibrary) key).references) {
2.115 - sb.append("<li>").append(path).append("</li>\n");
2.116 - }
2.117 - sb.append("</ul></pre></blockquote></html>");
2.118 + an.setShortDescription(sb.toString());
2.119 + an.setIconBaseWithExtension("org/netbeans/modules/nodejs/resources/libs.png");
2.120 + return an;
2.121 }
2.122 - an.setShortDescription(sb.toString());
2.123 - an.setIconBaseWithExtension("org/netbeans/modules/nodejs/resources/libs.png");
2.124 - return an;
2.125 default:
2.126 throw new AssertionError();
2.127 }
2.128 @@ -383,7 +419,7 @@
2.129 //do nothing
2.130 }
2.131
2.132 - static class Key {
2.133 + static class Key implements Comparable<Key> {
2.134
2.135 private final KeyTypes type;
2.136 private final FileObject fld;
2.137 @@ -395,7 +431,15 @@
2.138 }
2.139
2.140 public String toString() {
2.141 - return type + " " + fld.getName() + (direct ? " direct" : " indirect"); //NOI18N
2.142 + return fld.getName();
2.143 + }
2.144 +
2.145 + @Override
2.146 + public int compareTo(Key o) {
2.147 + if (o.direct != direct) {
2.148 + return direct ? 1 : -1;
2.149 + }
2.150 + return toString().compareToIgnoreCase(o.toString());
2.151 }
2.152
2.153 static class BuiltInLibrary extends Key {
2.154 @@ -456,10 +500,20 @@
2.155 public LibraryFilterNode(Key key) {
2.156 this(nodeFromKey(key), key);
2.157 }
2.158 +
2.159 + static boolean isFileNode(Node n) {
2.160 + FileObject fo = n.getLookup().lookup(FileObject.class);
2.161 + if (fo == null) {
2.162 + DataObject dob = n.getLookup().lookup(DataObject.class);
2.163 + if (dob != null) {
2.164 + fo = dob.getPrimaryFile();
2.165 + }
2.166 + }
2.167 + return fo == null ? false : fo.isData();
2.168 + }
2.169
2.170 private LibraryFilterNode(Node original, final Key key) {
2.171 - super(nodeFromKey(key), Children.create(new LibraryNodeChildren(original.getLookup().lookup(DataObject.class)), true));
2.172 - assert key.type == KeyTypes.LIBRARY;
2.173 + super(nodeFromKey(key), isFileNode(original) ? Children.LEAF : Children.create(new LibraryNodeChildren(original.getLookup().lookup(DataObject.class)), true));
2.174 this.key = key;
2.175 jsonReader.post(new Runnable() {
2.176
2.177 @@ -595,10 +649,16 @@
2.178
2.179 @Override
2.180 public Image getIcon(int type) {
2.181 - Image result = ImageUtilities.loadImage("org/netbeans/modules/nodejs/resources/libs.png");
2.182 - if (!key.direct) {
2.183 + Image result = ImageUtilities.loadImage(key.type == KeyTypes.BUILT_IN_LIBRARY ?
2.184 + "org/netbeans/modules/nodejs/resources/libs.png" :
2.185 + "org/netbeans/modules/nodejs/resources/libs.png"); //NOI18N
2.186 + if (!key.direct && key.type != KeyTypes.BUILT_IN_LIBRARY) {
2.187 result = ImageUtilities.createDisabledImage(result);
2.188 }
2.189 + if (key.type == KeyTypes.BUILT_IN_LIBRARY) {
2.190 + Image badge = ImageUtilities.loadImage("org/netbeans/modules/nodejs/resources/logoBadge.png"); //NOI18N
2.191 + result = ImageUtilities.mergeImages(result, badge, 8, 8);
2.192 + }
2.193 return result;
2.194 }
2.195
2.196 @@ -610,17 +670,27 @@
2.197 @Override
2.198 public String getHtmlDisplayName() {
2.199 StringBuilder sb = new StringBuilder();
2.200 - if (!key.direct) {
2.201 + if (key.type == KeyTypes.BUILT_IN_LIBRARY) {
2.202 + sb.append ("<font color='#22AA22'><i>");
2.203 + } else if (!key.direct) {
2.204 sb.append("<font color='!controlDkShadow'>");
2.205 }
2.206 - sb.append(getDisplayName());
2.207 + if (isFileNode(getOriginal())) {
2.208 + DataObject dob = getOriginal().getLookup().lookup(DataObject.class);
2.209 + sb.append (dob.getName());
2.210 + } else {
2.211 + sb.append(getDisplayName());
2.212 + }
2.213 + if (key.type == KeyTypes.BUILT_IN_LIBRARY) {
2.214 + sb.append ("</i>");
2.215 + }
2.216 if (version != null) {
2.217 sb.append(" <i><font color='#9999AA'> ").append(version).append("</i>");
2.218 if (!key.direct) {
2.219 sb.append("<font color='!controlDkShadow'>");
2.220 }
2.221 }
2.222 - if (!key.direct) {
2.223 + if (!key.direct && key.type != KeyTypes.BUILT_IN_LIBRARY) {
2.224 sb.append(" (<-").append(key.fld.getParent().getParent().getName()).append(")");
2.225 }
2.226 return sb.toString();
3.1 Binary file nodejs/src/org/netbeans/modules/nodejs/resources/libs.png has changed
4.1 Binary file nodejs/src/org/netbeans/modules/nodejs/resources/logoBadge.png has changed