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 30150
Collapse All | Expand All

(-)src/org/openide/explorer/view/VisualizerChildren.java (-16 / +24 lines)
Lines 81-103 Link Here
81
    * and fires info to all listeners.
81
    * and fires info to all listeners.
82
    */
82
    */
83
    public void removed (VisualizerEvent.Removed ev) {
83
    public void removed (VisualizerEvent.Removed ev) {
84
        ListIterator it = list.listIterator ();
84
        List remList = Arrays.asList (ev.getRemovedNodes ());
85
        int[] indxs = ev.getArray ();
85
        
86
        Iterator it = list.iterator ();
87
        
88
        VisualizerNode vis;
89
        
90
        int[] indx = new int[remList.size ()];
91
        int count = 0, remSize = 0;
92
        while (it.hasNext ()) {
93
            // take visualizer node
94
            vis = (VisualizerNode)it.next ();
95
            
96
            // check if it will removed
97
            if (remList.contains (vis.node)) {
98
                indx[remSize++] = count;
86
99
87
        int current = 0;
100
                // remove this VisualizerNode from children
88
        int inIndxs = 0;
101
                it.remove ();
89
        while (inIndxs < indxs.length) {
102
            }
90
            Object last;
103
            count++;
91
            do {
92
                last = it.next ();
93
            } while (current++ < indxs[inIndxs]);
94
95
            ev.removed.add (last);
96
            it.remove ();
97
98
            inIndxs++;
99
        }
104
        }
100
105
        
106
        // notify event about changed indexes
107
        ev.setRemovedIndicies (indx);
108
        
101
        VisualizerNode parent = this.parent;
109
        VisualizerNode parent = this.parent;
102
        while (parent != null) {
110
        while (parent != null) {
103
            Object[] listeners = parent.getListenerList ();
111
            Object[] listeners = parent.getListenerList ();
Lines 112-118 Link Here
112
            this.parent.notifyVisualizerChildrenChange (0, this);
120
            this.parent.notifyVisualizerChildrenChange (0, this);
113
        }
121
        }
114
    }
122
    }
115
123
    
116
    /** Notification that children has been reordered. Modifies the list of nodes
124
    /** Notification that children has been reordered. Modifies the list of nodes
117
    * and fires info to all listeners.
125
    * and fires info to all listeners.
118
    */
126
    */
(-)src/org/openide/explorer/view/VisualizerEvent.java (-27 / +38 lines)
Lines 91-96 Link Here
91
        /** linked list of removed nodes, that is filled in getChildren ().removed () method
91
        /** linked list of removed nodes, that is filled in getChildren ().removed () method
92
        */
92
        */
93
        public LinkedList removed = new LinkedList ();
93
        public LinkedList removed = new LinkedList ();
94
        
95
        private Node[]removedNodes;
94
96
95
        static final long serialVersionUID =5102881916407672392L;
97
        static final long serialVersionUID =5102881916407672392L;
96
        /** Constructor for add of nodes notification.
98
        /** Constructor for add of nodes notification.
Lines 100-108 Link Here
100
        */
102
        */
101
        public Removed (
103
        public Removed (
102
            VisualizerChildren ch,
104
            VisualizerChildren ch,
103
            int[] indx
105
            Node[] removedNodes
104
        ) {
106
        ) {
105
            super (ch, indx);
107
            super (ch, null);
108
            this.removedNodes = removedNodes;
109
        }
110
        
111
        public Node[] getRemovedNodes () {
112
            return removedNodes;
113
        }
114
        
115
        public void setRemovedIndicies (int[] arr) {
116
            super.array = arr;
106
        }
117
        }
107
118
108
        /** Process the event
119
        /** Process the event
Lines 132-162 Link Here
132
            super (ch, indx);
143
            super (ch, indx);
133
        }
144
        }
134
145
135
        /** Prepares list of changed indices for use in tree model.
146
//        /** Prepares list of changed indices for use in tree model.
136
        */
147
//        */
137
        public int[] getChangedIndices () {
148
//        public int[] getChangedIndices () {
138
            if (changedIndices == null) {
149
//            if (changedIndices == null) {
139
                int[] permutation = super.getArray ();
150
//                int[] permutation = super.getArray ();
140
                int size = permutation.length;
151
//                int size = permutation.length;
141
                int changes = 0;
152
//                int changes = 0;
142
                for (int i = 0; i < size; i++) {
153
//                for (int i = 0; i < size; i++) {
143
                    if (permutation[i] != i)
154
//                    if (permutation[i] != i)
144
                        changes++;
155
//                        changes++;
145
                }
156
//                }
146
157
//
147
                int[] indices = new int[changes];
158
//                int[] indices = new int[changes];
148
159
//
149
                int current = 0;
160
//                int current = 0;
150
                for (int i = 0; i < size; i++) {
161
//                for (int i = 0; i < size; i++) {
151
                    if (permutation[i] != i) {
162
//                    if (permutation[i] != i) {
152
                        indices[current++] = i;
163
//                        indices[current++] = i;
153
                    }
164
//                    }
154
                }
165
//                }
155
166
//
156
                changedIndices = indices;
167
//                changedIndices = indices;
157
            }
168
//            }
158
            return changedIndices;
169
//            return changedIndices;
159
        }
170
//        }
160
171
161
        /** Process the event
172
        /** Process the event
162
        */
173
        */
(-)src/org/openide/explorer/view/VisualizerNode.java (-25 / +1 lines)
Lines 254-282 Link Here
254
        ));
254
        ));
255
    }
255
    }
256
256
257
    // bugfix #30150, helper method tranforms an array the child's indices of removed nodes by actually sorting
258
    private void tranformIndices (VisualizerChildren children, int[] indices, Node[] removedNodes) {
259
        if (indices == null || indices.length == 0) {
260
            return;
261
        }
262
        java.util.List list = children.list;
263
        for (int i = 0; i < indices.length; i++) {
264
            int idx = list.indexOf (getVisualizer ( children, removedNodes[i] ));
265
            // debug check
266
            if (idx == -1) {
267
                ErrorManager.getDefault ().log (ErrorManager.INFORMATIONAL, "VisualizerNode: Node " + removedNodes[i] // NOI18N
268
                    + " wasn't found in children of " // NOI18N
269
                    + children.parent + "."); // NOI18N
270
                idx = indices[i];
271
            }
272
            // end of debug
273
            indices[i] = idx;
274
        }
275
        // by sure the indices are in ascending order
276
        Arrays.sort (indices);
277
        return;
278
    }
279
280
    /** Fired when a set of children is removed.
257
    /** Fired when a set of children is removed.
281
    * @param ev event describing the action
258
    * @param ev event describing the action
282
    */
259
    */
Lines 284-291 Link Here
284
        VisualizerChildren ch = (VisualizerChildren)children.get ();
261
        VisualizerChildren ch = (VisualizerChildren)children.get ();
285
        if (ch == null) return;
262
        if (ch == null) return;
286
        
263
        
287
        tranformIndices (ch, ev.getDeltaIndices (), ev.getDelta ());
264
        QUEUE.runSafe (new VisualizerEvent.Removed (ch,  ev.getDelta ()) );
288
        QUEUE.runSafe (new VisualizerEvent.Removed (ch,  ev.getDeltaIndices ()) );
289
    }
265
    }
290
266
291
    /** Fired when the order of children is changed.
267
    /** Fired when the order of children is changed.

Return to bug 30150