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

(-)a/api.debugger/apichanges.xml (+19 lines)
Lines 345-350 Link Here
345
        <issue number="158907"/>
345
        <issue number="158907"/>
346
    </change>
346
    </change>
347
347
348
     <change id="WatchesReordering">
349
        <api name="DebuggerCoreAPI"/>
350
        <summary>Support for changing the order of watches.</summary>
351
        <version major="1" minor="22"/>
352
        <date day="15" month="12" year="2009"/>
353
        <author login="mentlicher"/>
354
        <compatibility binary="compatible" source="compatible" addition="yes"/>
355
        <description>
356
             <p>
357
             createWatch(int index, String expr) and reorderWatches(int[] permutation)
358
             methods added to DebuggerManager class.<br/>
359
             These methods are going to be called from WatchesTreeModel when
360
             watches are reordered.
361
             </p>
362
        </description>
363
        <class package="org.netbeans.api.debugger" name="DebuggerManager" />
364
        <issue number="158907"/>
365
    </change>
366
348
</changes>
367
</changes>
349
368
350
  <!-- Now the surrounding HTML text and document structure: -->
369
  <!-- Now the surrounding HTML text and document structure: -->
(-)a/api.debugger/manifest.mf (-1 / +1 lines)
Lines 1-5 Link Here
1
Manifest-Version: 1.0
1
Manifest-Version: 1.0
2
OpenIDE-Module: org.netbeans.api.debugger/1
2
OpenIDE-Module: org.netbeans.api.debugger/1
3
OpenIDE-Module-Localizing-Bundle: org/netbeans/api/debugger/Bundle.properties
3
OpenIDE-Module-Localizing-Bundle: org/netbeans/api/debugger/Bundle.properties
4
OpenIDE-Module-Specification-Version: 1.21
4
OpenIDE-Module-Specification-Version: 1.22
5
OpenIDE-Module-Layer: org/netbeans/api/debugger/layer.xml
5
OpenIDE-Module-Layer: org/netbeans/api/debugger/layer.xml
(-)a/api.debugger/src/org/netbeans/api/debugger/DebuggerManager.java (+57 lines)
Lines 625-630 Link Here
625
    }
625
    }
626
626
627
    /**
627
    /**
628
     * Creates a watch with its expression set to an initial value
629
     * and add it at the specific position
630
     *
631
     * @param index the position at which the specified watch is to be inserted
632
     * @param expr expression to watch for (the format is the responsibility
633
     *    of the debugger plug-in implementation, but it is typically
634
     *    a variable name).
635
     * @return the new watch
636
     * @throws ArrayIndexOutOfBoundsException if the index is out of range
637
     *         <code>(index < 0 || index > getWatches().length)</code>
638
     * @since 1.22
639
     */
640
    public Watch createWatch (int index, String expr) {
641
        initWatches ();
642
        Watch w = new Watch (expr);
643
        watches.add (index, w);
644
        fireWatchCreated (w);
645
        return w;
646
    }
647
648
    /**
628
    * Gets all shared watches in the system.
649
    * Gets all shared watches in the system.
629
    *
650
    *
630
    * @return all watches
651
    * @return all watches
Lines 656-661 Link Here
656
        fireWatchRemoved (w);
677
        fireWatchRemoved (w);
657
    }
678
    }
658
679
680
    /**
681
     * Reorders watches with given permutation.
682
     * @param permutation The permutation with the length of current watches list
683
     * @throws IllegalArgumentException if the permutation is not valid permutation
684
     * @since 1.22
685
     */
686
    public void reorderWatches(final int[] permutation) throws IllegalArgumentException {
687
        synchronized (watches) {
688
            if (permutation.length != watches.size()) {
689
                throw new IllegalArgumentException("Permutation of length "+permutation.length+", but have "+watches.size()+" watches.");
690
            }
691
            checkPermutation(permutation);
692
            Vector v = (Vector) watches.clone ();
693
            for (int i = 0; i < v.size(); i++) {
694
                watches.set(permutation[i], v.get(i));
695
            }
696
        }
697
    }
698
699
    private static void checkPermutation(int[] permutation) throws IllegalArgumentException {
700
        int max = permutation.length;
701
        int[] check = new int[max];
702
        for (int i = 0; i < max; i++) {
703
            int p = permutation[i];
704
            if (p >= max) {
705
                throw new IllegalArgumentException("Permutation "+Arrays.toString(permutation)+" is not a valid permutation, it contains element "+p+", which is bigger than the length of the permutation.");
706
            }
707
            if (p < 0) {
708
                throw new IllegalArgumentException("Permutation "+Arrays.toString(permutation)+" is not a valid permutation, it contains element "+p+", which is negative.");
709
            }
710
            if (check[p] != 0) {
711
                throw new IllegalArgumentException("Permutation "+Arrays.toString(permutation)+" is not a valid permutation, it contains element "+p+" twice or more times.");
712
            }
713
            check[p] = 1;
714
        }
715
    }
659
    
716
    
660
    // listenersMap ...............................................................
717
    // listenersMap ...............................................................
661
718
(-)a/spi.debugger.ui/nbproject/project.xml (-1 / +1 lines)
Lines 52-58 Link Here
52
                    <compile-dependency/>
52
                    <compile-dependency/>
53
                    <run-dependency>
53
                    <run-dependency>
54
                        <release-version>1</release-version>
54
                        <release-version>1</release-version>
55
                        <specification-version>1.16</specification-version>
55
                        <specification-version>1.22</specification-version>
56
                    </run-dependency>
56
                    </run-dependency>
57
                </dependency>
57
                </dependency>
58
                <dependency>
58
                <dependency>
(-)a/spi.debugger.ui/test/unit/src/org/netbeans/api/debugger/WatchesTest.java (+54 lines)
Lines 43-48 Link Here
43
43
44
import org.netbeans.api.debugger.test.TestDebuggerManagerListener;
44
import org.netbeans.api.debugger.test.TestDebuggerManagerListener;
45
import java.beans.PropertyChangeEvent;
45
import java.beans.PropertyChangeEvent;
46
import java.util.Arrays;
46
import java.util.List;
47
import java.util.List;
47
48
48
/**
49
/**
Lines 126-129 Link Here
126
        return newWatch;
127
        return newWatch;
127
    }
128
    }
128
129
130
    public void testWatchesReorder() throws Exception {
131
        DebuggerManager dm = DebuggerManager.getDebuggerManager();
132
        dm.createWatch("w1");
133
        dm.createWatch(0, "w0");
134
135
        Watch[] watches = dm.getWatches();
136
        assertEquals("w0", watches[0].getExpression());
137
138
        boolean exThrown = false;
139
        try {
140
            dm.createWatch(100, "w100");
141
        } catch (ArrayIndexOutOfBoundsException aioobex) {
142
            exThrown = true;
143
        }
144
        assertTrue(exThrown);
145
        dm.removeAllWatches();
146
147
        for (int i = 0; i < 5; i++) {
148
            dm.createWatch(i, "w"+(i+1));
149
        }
150
        dm.reorderWatches(new int[] { 2, 0, 1, 4, 3 });
151
        String[] reorderedWatches = new String[] { "w2", "w3", "w1", "w5", "w4" };
152
        watches = dm.getWatches();
153
        String watchesStr = Arrays.toString(watches);
154
        for (int i = 0; i < 5; i++) {
155
            assertEquals(watchesStr, reorderedWatches[i], watches[i].getExpression());
156
        }
157
158
        exThrown = false;
159
        try {
160
            dm.reorderWatches(new int[] { 2, 0, 1, 4, 3, 5 });
161
        } catch (IllegalArgumentException iaex) {
162
            exThrown = true;
163
        }
164
        assertTrue(exThrown);
165
166
        exThrown = false;
167
        try {
168
            dm.reorderWatches(new int[] { 2, 0, 1 });
169
        } catch (IllegalArgumentException iaex) {
170
            exThrown = true;
171
        }
172
        assertTrue(exThrown);
173
174
        exThrown = false;
175
        try {
176
            dm.reorderWatches(new int[] { 2, 0, 1, 0, 3 });
177
        } catch (IllegalArgumentException iaex) {
178
            exThrown = true;
179
        }
180
        assertTrue(exThrown);
181
    }
182
129
}
183
}

Return to bug 178301