rkeen-siemens opened a new issue, #9596:
URL: https://github.com/apache/netbeans/issues/9596

   ### Apache NetBeans version
   
   Apache NetBeans 32 latest daily build
   
   ### What happened
   
   When recreating columns from the model in `ETable`, column ordering, sort 
order, and (sometimes) width revert to their defaults. Add these unit tests to 
`ETableTest` and you'll see they both fail.
   
   ```java
   public void testRecreatingColumnsShouldMaintainOrder() {
       ETable t = createTestingTable(false);
       t.moveColumn(1, 0);
       t.createDefaultColumnsFromModel();
   
       assertEquals("BB", t.getColumnModel().getColumn(0).getIdentifier());
       assertEquals("AA", t.getColumnModel().getColumn(1).getIdentifier());
   }
   
   public void testRecreatingColumnsShouldMaintainSortAfterMoving() {
       ETable t = createTestingTable(false);
       t.setColumnSorted(0, true, 1);
       t.moveColumn(1, 0);
       t.createDefaultColumnsFromModel();
   
       var etc = (ETableColumn) t.getColumnModel().getColumn(1);
       assertTrue(etc.isAscending());
       assertEquals(1, etc.getSortRank());
   }
   ```
   
   There seems to be some mixup between model index and view index. I tried 
some simple changes to store the values in `sortedColumnIndexes` using the view 
index and setting the new columns' model index from the previous table column, 
but this messed up the hidden columns. The following unit test passes with the 
existing code, but failed with my updates so it may be worth adding as well to 
ensure no regression.
   
   ```java
   public void testHiddenColumnsCorrectAfterRecreatingColumns() {
       ETable t = createTestingTable(false);
       var etcm = (ETableColumnModel) t.getColumnModel();
       etcm.setColumnHidden(etcm.getColumn(0), true);
       t.createDefaultColumnsFromModel();
   
       assertEquals("BB", etcm.getColumn(0).getIdentifier());
   }
   ```
   
   Finally, although I haven't been able to reproduce a failure of the width, I 
have seen it periodically in the UI when using the `OutlineView`. As such, a 
test similar to the following may be worth adding as well.
   
   ```java
   public void testRecreatingColumnsShouldMaintainSizeAfterMoving() {
       ETable t = createTestingTable(false);
       final int width = 500;
       t.getColumnModel().getColumn(0).setWidth(width);
       t.moveColumn(1, 0);
       t.createDefaultColumnsFromModel();
   
       assertEquals(width, t.getColumnModel().getColumn(1).getWidth());
   }
   ```
   
   ### Language / Project Type / NetBeans Component
   
   _No response_
   
   ### How to reproduce
   
   1. Create an `OutlineView` instance
   2. Sort, reorder, and resize columns in the UI
   3. Trigger column recreation, typically by triggering a "tableChanged" as 
the result of adding or removing a node to/from the view
   
   ### Did this work correctly in an earlier version?
   
   No / Don't know
   
   ### Operating System
   
   All
   
   ### JDK
   
   Eclipse Adoptium 25.0.2
   
   ### Apache NetBeans packaging
   
   Apache NetBeans platform
   
   ### Anything else
   
   _No response_
   
   ### Are you willing to submit a pull request?
   
   No


-- 
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

Reply via email to