mbien commented on code in PR #9602:
URL: https://github.com/apache/netbeans/pull/9602#discussion_r3939317214
##########
ide/projectui/src/org/netbeans/modules/project/ui/ProjectTab.java:
##########
@@ -417,6 +421,34 @@ public void writeExternal (ObjectOutput out) throws
IOException {
}
}
+ private static class DepthRespectingRenderer extends NodeRenderer {
+ DepthRespectingRenderer() {
+ }
+
+ @Override
+ protected int findIndent(Object model, TreeNode vis) {
+ var node = Visualizer.findNode(vis);
+ while (node != null) {
+ if (node instanceof ProjectsRootNode.BadgingNode) {
+ var badge = (ProjectsRootNode.BadgingNode) node;
+ return badge.pair.depth;
Review Comment:
nitpick: we could bump the language level to 21 to use the instanceof
pattern.
```java
if (node instanceof ProjectsRootNode.BadgingNode badge) {
return badge.pair.depth;
}
```
pet peeve: I am personally not a fan of using var everywhere since it
obfuscates code and is in many cases not necessary when the type is already
concise. But I am not going to argue against it, its more about code style and
mostly non technical.
Its just a bit unfortunate that the trend of overusing var made IDEs render
the type next to it which entirely defeated the purpose of it in the first
place since it now uses more space than before and breaks formatting:
<img width="484" height="55" alt="Image"
src="https://github.com/user-attachments/assets/ff2cafba-bdec-4f3e-a109-bfbcf5cb9f77"
/>
but that is just my "pet peeve" - feel free to ignore it ;)
##########
ide/projectui/src/org/netbeans/modules/project/ui/OpenProjectList.java:
##########
@@ -1965,6 +1969,21 @@ public int compare(Project p1, Project p2) {
}
}
+ private static class ProjectByPathComparator implements
Comparator<Project> {
+ @Override
+ public int compare(Project p1, Project p2) {
+ if (p1 == null && p2 == null) {
+ return 0;
+ }
+ if (p1 == null) {
+ return -1;
+ }
+ if (p2 == null) {
+ return 1;
+ }
+ return
p1.getProjectDirectory().getPath().compareTo(p2.getProjectDirectory().getPath());
Review Comment:
Alphabetical String comparison with paths seems to be indeed working well
for this. My instinct told me that this will probably break with edge cases but
it is always making sure that parent dir ends up before child dir. This is good
for this purpose (I think) and also fast.
Path comparison has the limitation that the projects do actually have to be
a tree structure on disk since it shows the filesystem hierarchy, not the
actual project parent which could be anywhere. It correlates location with
relationship between projects. This might be fine still - curious what others
think.
##########
platform/openide.explorer/src/org/openide/explorer/view/NodeRenderer.java:
##########
@@ -196,6 +200,23 @@ public Component getListCellRendererComponent(
return result;
}
+ /** Finds the indentation level of a node.
+ *
+ * @param model the model (either {@link ListModel} or {@link TreeModel})
that's currently being rendered
+ * @param visualizer the visualizer to find indentation for
+ * @return the indentation level for the renderer of the given {@code
visualizer};
+ * return {@code 0} for no indentation or positive number to indent the
rendering to right
+ * @see Visualizer#findNode(java.lang.Object)
+ * @sincet 6.97
+ */
+ protected int findIndent(Object model, TreeNode visualizer) {
+ if (model instanceof ListModel) {
+ return NodeListModel.findVisualizerDepth((ListModel) model,
visualizer);
Review Comment:
nit: instanceof pattern
##########
platform/openide.explorer/src/org/openide/explorer/view/NodeRenderer.java:
##########
@@ -187,7 +191,7 @@ public Component getListCellRendererComponent(
//in the node tree. Only does anything if you've subclassed and
//overridden createModel(). Does anybody do that?
if (list.getModel() instanceof NodeListModel && (((NodeListModel)
list.getModel()).getDepth() > 1)) {
- int indent = iconWidth *
NodeListModel.findVisualizerDepth(list.getModel(), vis);
+ int indent = iconWidth * findIndent(list.getModel(), vis);
Review Comment:
nit: instanceof pattern would clean this up too
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists