diff --git a/api.debugger/apichanges.xml b/api.debugger/apichanges.xml --- a/api.debugger/apichanges.xml +++ b/api.debugger/apichanges.xml @@ -345,6 +345,25 @@ + + + Support for changing the order of watches. + + + + + +

+ createWatch(int index, String expr) and reorderWatches(int[] permutation) + methods added to DebuggerManager class.
+ These methods are going to be called from WatchesTreeModel when + watches are reordered. +

+
+ + +
+ diff --git a/api.debugger/manifest.mf b/api.debugger/manifest.mf --- a/api.debugger/manifest.mf +++ b/api.debugger/manifest.mf @@ -1,5 +1,5 @@ Manifest-Version: 1.0 OpenIDE-Module: org.netbeans.api.debugger/1 OpenIDE-Module-Localizing-Bundle: org/netbeans/api/debugger/Bundle.properties -OpenIDE-Module-Specification-Version: 1.21 +OpenIDE-Module-Specification-Version: 1.22 OpenIDE-Module-Layer: org/netbeans/api/debugger/layer.xml diff --git a/api.debugger/src/org/netbeans/api/debugger/DebuggerManager.java b/api.debugger/src/org/netbeans/api/debugger/DebuggerManager.java --- a/api.debugger/src/org/netbeans/api/debugger/DebuggerManager.java +++ b/api.debugger/src/org/netbeans/api/debugger/DebuggerManager.java @@ -625,6 +625,27 @@ } /** + * Creates a watch with its expression set to an initial value + * and add it at the specific position + * + * @param index the position at which the specified watch is to be inserted + * @param expr expression to watch for (the format is the responsibility + * of the debugger plug-in implementation, but it is typically + * a variable name). + * @return the new watch + * @throws ArrayIndexOutOfBoundsException if the index is out of range + * (index < 0 || index > getWatches().length) + * @since 1.22 + */ + public Watch createWatch (int index, String expr) { + initWatches (); + Watch w = new Watch (expr); + watches.add (index, w); + fireWatchCreated (w); + return w; + } + + /** * Gets all shared watches in the system. * * @return all watches @@ -656,6 +677,42 @@ fireWatchRemoved (w); } + /** + * Reorders watches with given permutation. + * @param permutation The permutation with the length of current watches list + * @throws IllegalArgumentException if the permutation is not valid permutation + * @since 1.22 + */ + public void reorderWatches(final int[] permutation) throws IllegalArgumentException { + synchronized (watches) { + if (permutation.length != watches.size()) { + throw new IllegalArgumentException("Permutation of length "+permutation.length+", but have "+watches.size()+" watches."); + } + checkPermutation(permutation); + Vector v = (Vector) watches.clone (); + for (int i = 0; i < v.size(); i++) { + watches.set(permutation[i], v.get(i)); + } + } + } + + private static void checkPermutation(int[] permutation) throws IllegalArgumentException { + int max = permutation.length; + int[] check = new int[max]; + for (int i = 0; i < max; i++) { + int p = permutation[i]; + if (p >= max) { + 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."); + } + if (p < 0) { + throw new IllegalArgumentException("Permutation "+Arrays.toString(permutation)+" is not a valid permutation, it contains element "+p+", which is negative."); + } + if (check[p] != 0) { + throw new IllegalArgumentException("Permutation "+Arrays.toString(permutation)+" is not a valid permutation, it contains element "+p+" twice or more times."); + } + check[p] = 1; + } + } // listenersMap ............................................................... diff --git a/spi.debugger.ui/nbproject/project.xml b/spi.debugger.ui/nbproject/project.xml --- a/spi.debugger.ui/nbproject/project.xml +++ b/spi.debugger.ui/nbproject/project.xml @@ -52,7 +52,7 @@ 1 - 1.16 + 1.22 diff --git a/spi.debugger.ui/test/unit/src/org/netbeans/api/debugger/WatchesTest.java b/spi.debugger.ui/test/unit/src/org/netbeans/api/debugger/WatchesTest.java --- a/spi.debugger.ui/test/unit/src/org/netbeans/api/debugger/WatchesTest.java +++ b/spi.debugger.ui/test/unit/src/org/netbeans/api/debugger/WatchesTest.java @@ -43,6 +43,7 @@ import org.netbeans.api.debugger.test.TestDebuggerManagerListener; import java.beans.PropertyChangeEvent; +import java.util.Arrays; import java.util.List; /** @@ -126,4 +127,57 @@ return newWatch; } + public void testWatchesReorder() throws Exception { + DebuggerManager dm = DebuggerManager.getDebuggerManager(); + dm.createWatch("w1"); + dm.createWatch(0, "w0"); + + Watch[] watches = dm.getWatches(); + assertEquals("w0", watches[0].getExpression()); + + boolean exThrown = false; + try { + dm.createWatch(100, "w100"); + } catch (ArrayIndexOutOfBoundsException aioobex) { + exThrown = true; + } + assertTrue(exThrown); + dm.removeAllWatches(); + + for (int i = 0; i < 5; i++) { + dm.createWatch(i, "w"+(i+1)); + } + dm.reorderWatches(new int[] { 2, 0, 1, 4, 3 }); + String[] reorderedWatches = new String[] { "w2", "w3", "w1", "w5", "w4" }; + watches = dm.getWatches(); + String watchesStr = Arrays.toString(watches); + for (int i = 0; i < 5; i++) { + assertEquals(watchesStr, reorderedWatches[i], watches[i].getExpression()); + } + + exThrown = false; + try { + dm.reorderWatches(new int[] { 2, 0, 1, 4, 3, 5 }); + } catch (IllegalArgumentException iaex) { + exThrown = true; + } + assertTrue(exThrown); + + exThrown = false; + try { + dm.reorderWatches(new int[] { 2, 0, 1 }); + } catch (IllegalArgumentException iaex) { + exThrown = true; + } + assertTrue(exThrown); + + exThrown = false; + try { + dm.reorderWatches(new int[] { 2, 0, 1, 0, 3 }); + } catch (IllegalArgumentException iaex) { + exThrown = true; + } + assertTrue(exThrown); + } + }