This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

View | Details | Raw Unified | Return to bug 24893
Collapse All | Expand All

(-)view/NodeTableModel.java (-14 / +87 lines)
Lines 247-281 Link Here
247
        return -1;
247
        return -1;
248
    }
248
    }
249
    
249
    
250
    /* If true, column property should be comparable - allows sorting
250
    /** 
251
     * If true, column property should be comparable - allows sorting
252
     * @param column Index of a visible column
251
     */
253
     */
252
    boolean isComparableColumn(int column) {
254
    boolean isComparableColumn(int column) {
253
        Property p = allPropertyColumns[propertyColumns[column]].getProperty();
255
        return isComparableColumnEx( propertyColumns[column] );
256
    }
257
258
    /** 
259
     * If true, column property should be comparable - allows sorting
260
     * @param column Index to the array of all properties
261
     */
262
    boolean isComparableColumnEx(int column) {
263
        Property p = allPropertyColumns[column].getProperty();
254
        Object o = p.getValue( ATTR_COMPARABLE_COLUMN );
264
        Object o = p.getValue( ATTR_COMPARABLE_COLUMN );
255
        if ( o != null && o instanceof Boolean )
265
        if ( o != null && o instanceof Boolean )
256
            return ((Boolean)o).booleanValue();
266
            return ((Boolean)o).booleanValue();
257
        return false;
267
        return false;
258
    }
268
    }
259
    
269
    
270
    /**
271
     * @param column Index to the array of all properties
272
     * @return True if the property at the given index is visible
273
     */
274
    boolean isVisibleColumnEx( int column ) {
275
        for( int i=0; i<propertyColumns.length; i++ ) {
276
            if( column == propertyColumns[i] )
277
                return true;
278
        }
279
        return false;
280
    }
281
260
    /* If true, at least one column is comparable
282
    /* If true, at least one column is comparable
261
     */
283
     */
262
    boolean existsComparableColumn() {
284
    boolean existsComparableColumn() {
263
        return existsComparableColumn;
285
        return existsComparableColumn;
264
    }
286
    }
265
    
287
    
266
    /* If true, column is currently used for sorting
288
    /**
289
     * If true, column is currently used for sorting
290
     * @param Index to the array of all properties (the column may not be visible)
267
     */
291
     */
268
    boolean isSortingColumn(int column) {
292
    boolean isSortingColumnEx(int column) {
269
        Property p = allPropertyColumns[propertyColumns[column]].getProperty();
293
        Property p = allPropertyColumns[column].getProperty();
270
        Object o = p.getValue( ATTR_SORTING_COLUMN );
294
        Object o = p.getValue( ATTR_SORTING_COLUMN );
271
        if ( o != null && o instanceof Boolean )
295
        if ( o != null && o instanceof Boolean )
272
            return ((Boolean)o).booleanValue();
296
            return ((Boolean)o).booleanValue();
273
        return false;
297
        return false;
274
    }
298
    }
275
    
299
    
276
    /* Sets column to be currently used for sorting
300
    /**
301
     * Sets column to be currently used for sorting
302
     *@param Index to the array of all properties (the column may not by visible)
277
     */
303
     */
278
    void setSortingColumn(int column) {
304
    void setSortingColumnEx(int column) {
279
        if ( sortColumn != -1 ) {
305
        if ( sortColumn != -1 ) {
280
            Property p = allPropertyColumns[ sortColumn ].getProperty();
306
            Property p = allPropertyColumns[ sortColumn ].getProperty();
281
            p.setValue( ATTR_SORTING_COLUMN, Boolean.FALSE );
307
            p.setValue( ATTR_SORTING_COLUMN, Boolean.FALSE );
Lines 283-289 Link Here
283
        }
309
        }
284
        
310
        
285
        if ( column != -1 ) {
311
        if ( column != -1 ) {
286
            sortColumn = propertyColumns[column];
312
            sortColumn = column; //propertyColumns[column];
287
            Property p = allPropertyColumns[ sortColumn ].getProperty();
313
            Property p = allPropertyColumns[ sortColumn ].getProperty();
288
            p.setValue( ATTR_SORTING_COLUMN, Boolean.TRUE );
314
            p.setValue( ATTR_SORTING_COLUMN, Boolean.TRUE );
289
        }
315
        }
Lines 291-303 Link Here
291
            sortColumn = -1;
317
            sortColumn = -1;
292
    }
318
    }
293
    
319
    
320
    int translateVisibleColumnIndex( int index ) {
321
        if( index < 0 )
322
            return index;
323
        return propertyColumns[index];
324
    }
325
    
294
    /* Gets column index of sorting column, if it's visible.
326
    /* Gets column index of sorting column, if it's visible.
295
     * Otherwise returns -1.
327
     * Otherwise returns -1.
296
     */
328
     */
297
    int getVisibleSortingColumn() {        
329
    int getVisibleSortingColumn() {        
298
        if ( sortColumn == -1 ) {
330
        if ( sortColumn == -1 ) {
299
            for (int i = 0; i < propertyColumns.length; i++) {
331
            for (int i = 0; i < propertyColumns.length; i++) {
300
                if ( isSortingColumn( i ) ) {
332
                if ( isSortingColumnEx( propertyColumns[i] ) ) {
301
                    sortColumn = propertyColumns[i];
333
                    sortColumn = propertyColumns[i];
302
                    return i;
334
                    return i;
303
                }
335
                }
Lines 306-316 Link Here
306
        else {
338
        else {
307
            if ( isVisible( allPropertyColumns[ sortColumn ].getProperty() ) )
339
            if ( isVisible( allPropertyColumns[ sortColumn ].getProperty() ) )
308
                return getVisibleIndex( sortColumn );
340
                return getVisibleIndex( sortColumn );
309
            sortColumn = -1;
310
        }
341
        }
311
        return -1;
342
        return -1;
312
    }
343
    }
313
    
344
    
345
    
346
    /* Gets column index of sorting column, if it's visible.
347
     * Otherwise returns -1.
348
     */
349
    int getSortingColumn() {        
350
        if ( sortColumn == -1 ) {
351
            for (int i = 0; i < allPropertyColumns.length; i++) {
352
                if ( isSortingColumnEx( i ) ) {
353
                    sortColumn = i;
354
                    return i;
355
                }
356
            }
357
        }
358
        else {
359
            return sortColumn;
360
        }
361
        return -1;
362
    }
363
314
    /* If true, current sorting uses descending order.
364
    /* If true, current sorting uses descending order.
315
     */
365
     */
316
    boolean isSortOrderDescending() {
366
    boolean isSortOrderDescending() {
Lines 357-372 Link Here
357
        return nodeRows[row];
407
        return nodeRows[row];
358
    }
408
    }
359
    
409
    
360
    /** Helper method to ask for a property representant of column.
410
    /** 
411
     * Helper method to ask for a property representant of column.
412
     * @param Index of a visible column
361
     */
413
     */
362
    Property propertyForColumn(int column) {
414
    Property propertyForColumn(int column) {
415
        if( column >= 0 )
416
            column = propertyColumns[column];
417
        return propertyForColumnEx( column );
418
    }
419
    
420
    /** 
421
     * Helper method to ask for a property representant of column.
422
     * @param Index to the array of all properties.
423
     */
424
    Property propertyForColumnEx(int column) {
363
        if ( column == -1 )
425
        if ( column == -1 )
364
            return treeColumnProperty;
426
            return treeColumnProperty;
365
        else
427
        else
366
            return allPropertyColumns[propertyColumns[column]].getProperty();
428
            return allPropertyColumns[column].getProperty();
367
    }
429
    }
368
    
430
    
369
    int getArrayColumnCount() {
431
    /**
432
     * @return The count of all properties (includes invisible columns)
433
     */
434
    int getColumnCountEx() {
370
        return allPropertyColumns.length;
435
        return allPropertyColumns.length;
371
    }
436
    }
372
    
437
    
Lines 451-457 Link Here
451
     * @return display name of property which represents column
516
     * @return display name of property which represents column
452
     */
517
     */
453
    public String getColumnName(int column) {
518
    public String getColumnName(int column) {
454
        return allPropertyColumns[propertyColumns[column]].getProperty().getDisplayName();
519
        return getColumnNameEx( propertyColumns[column] );
520
    }
521
    
522
    /** Getter for column name
523
     * @param column table column index
524
     * @return display name of property which represents column
525
     */
526
    String getColumnNameEx(int column) {
527
        return allPropertyColumns[column].getProperty().getDisplayName();
455
    }
528
    }
456
    
529
    
457
    /* display panel to set/unset set of visible columns
530
    /* display panel to set/unset set of visible columns
458
        
531
        
(-)view/TreeTableView.java (-9 / +28 lines)
Lines 206-216 Link Here
206
                    }
206
                    }
207
                }
207
                }
208
                else {
208
                else {
209
                    int realIndex = tableModel.translateVisibleColumnIndex( index );
209
                    setSortingColumn( index );
210
                    setSortingColumn( index );
210
                    setSortingOrder( true );
211
                    setSortingOrder( true );
211
                }
212
                }
212
        } else if ( tableModel.isComparableColumn( index ) ) {
213
        } else if ( tableModel.isComparableColumn( index ) ) {
213
            if ( tableModel.isSortingColumn( index ) ) {
214
            if ( tableModel.isSortingColumnEx( tableModel.translateVisibleColumnIndex( index ) ) ) {
214
                if (!tableModel.isSortOrderDescending())
215
                if (!tableModel.isSortOrderDescending())
215
                    setSortingOrder(false);
216
                    setSortingOrder(false);
216
                else {
217
                else {
Lines 218-224 Link Here
218
                }
219
                }
219
            }
220
            }
220
            else {
221
            else {
221
                setSortingColumn( index );
222
                int realIndex = tableModel.translateVisibleColumnIndex( index );
223
                setSortingColumn( realIndex );
222
                setSortingOrder( true );
224
                setSortingOrder( true );
223
            }
225
            }
224
        }
226
        }
Lines 231-237 Link Here
231
            viewName = getParent().getName();
233
            viewName = getParent().getName();
232
        if ( tableModel.selectVisibleColumns( viewName, treeTable.getColumnName(0),
234
        if ( tableModel.selectVisibleColumns( viewName, treeTable.getColumnName(0),
233
                                              getSortedNodeTreeModel ().getRootDescription() ) ) {
235
                                              getSortedNodeTreeModel ().getRootDescription() ) ) {
234
            if ( tableModel.getVisibleSortingColumn() == -1 )
236
            if ( tableModel.getSortingColumn() == -1 )
235
                getSortedNodeTreeModel ().setSortedByProperty( null );
237
                getSortedNodeTreeModel ().setSortedByProperty( null );
236
            setTreePreferredWidth( treeColumnWidth );
238
            setTreePreferredWidth( treeColumnWidth );
237
            for (int i=0; i < tableModel.getColumnCount(); i++) {
239
            for (int i=0; i < tableModel.getColumnCount(); i++) {
Lines 450-458 Link Here
450
                                        !treeColumnProperty.isSortOrderDescending() );
452
                                        !treeColumnProperty.isSortOrderDescending() );
451
            }
453
            }
452
            else {
454
            else {
453
                int index = tableModel.getVisibleSortingColumn();
455
                int index = tableModel.getSortingColumn();
454
                if ( index != -1 ) {
456
                if ( index != -1 ) {
455
                    getSortedNodeTreeModel ().setSortedByProperty( tableModel.propertyForColumn( index ), 
457
                    getSortedNodeTreeModel ().setSortedByProperty( tableModel.propertyForColumnEx( index ), 
456
                                            !tableModel.isSortOrderDescending() );
458
                                            !tableModel.isSortOrderDescending() );
457
                }
459
                }
458
            }
460
            }
Lines 670-676 Link Here
670
                    visibleComparable++;
672
                    visibleComparable++;
671
                    colItem = new JRadioButtonMenuItem( 
673
                    colItem = new JRadioButtonMenuItem( 
672
                            tableModel.getColumnName( i ), 
674
                            tableModel.getColumnName( i ), 
673
                            tableModel.isSortingColumn( i ) );
675
                            tableModel.isSortingColumnEx( tableModel.translateVisibleColumnIndex( i ) ) );
676
                    colItem.setHorizontalTextPosition( SwingConstants.LEFT );
677
                    final int index = tableModel.translateVisibleColumnIndex( i );            
678
                    colItem.addActionListener( new ActionListener() {
679
                        public void actionPerformed(java.awt.event.ActionEvent actionEvent) {
680
                            setSortingColumn( index );
681
                        }
682
                    });
683
                    sortItem.add( colItem );
684
                }
685
            }
686
            //add invisible columns
687
            for (int i=0; i < tableModel.getColumnCountEx(); i++) {
688
                if ( tableModel.isComparableColumnEx( i ) && !tableModel.isVisibleColumnEx( i ) ) {
689
                    visibleComparable++;
690
                    colItem = new JRadioButtonMenuItem( 
691
                            tableModel.getColumnNameEx( i ), 
692
                            tableModel.isSortingColumnEx( i ) );
674
                    colItem.setHorizontalTextPosition( SwingConstants.LEFT );
693
                    colItem.setHorizontalTextPosition( SwingConstants.LEFT );
675
                    final int index = i;            
694
                    final int index = i;            
676
                    colItem.addActionListener( new ActionListener() {
695
                    colItem.addActionListener( new ActionListener() {
Lines 736-744 Link Here
736
    /* Sets column to be currently used for sorting
755
    /* Sets column to be currently used for sorting
737
     */
756
     */
738
    private void setSortingColumn(int index) {
757
    private void setSortingColumn(int index) {
739
        tableModel.setSortingColumn( index );
758
        tableModel.setSortingColumnEx( index );
740
        if ( index != -1 ) {
759
        if ( index != -1 ) {
741
            getSortedNodeTreeModel ().setSortedByProperty( tableModel.propertyForColumn( index ),
760
            getSortedNodeTreeModel ().setSortedByProperty( tableModel.propertyForColumnEx( index ),
742
                    !tableModel.isSortOrderDescending());
761
                    !tableModel.isSortOrderDescending());
743
            treeColumnProperty.setSortingColumn( false );
762
            treeColumnProperty.setSortingColumn( false );
744
        }
763
        }
Lines 751-757 Link Here
751
    }
770
    }
752
    
771
    
753
    private void noSorting() {
772
    private void noSorting() {
754
        tableModel.setSortingColumn( -1 );
773
        tableModel.setSortingColumnEx( -1 );
755
        getSortedNodeTreeModel ().setNoSorting();
774
        getSortedNodeTreeModel ().setNoSorting();
756
        treeColumnProperty.setSortingColumn( false );
775
        treeColumnProperty.setSortingColumn( false );
757
        // to change sort icon
776
        // to change sort icon

Return to bug 24893