Author: bobtarling Date: 2008-10-04 06:06:21-0700 New Revision: 15881 Modified: trunk/src/argouml-app/src/org/argouml/cognitive/ToDoList.java trunk/src/argouml-app/src/org/argouml/cognitive/ui/ToDoByDecision.java trunk/src/argouml-app/src/org/argouml/cognitive/ui/ToDoByGoal.java trunk/src/argouml-app/src/org/argouml/cognitive/ui/ToDoByOffender.java trunk/src/argouml-app/src/org/argouml/cognitive/ui/ToDoByPoster.java trunk/src/argouml-app/src/org/argouml/cognitive/ui/ToDoByPriority.java trunk/src/argouml-app/src/org/argouml/cognitive/ui/ToDoByType.java trunk/src/argouml-app/src/org/argouml/cognitive/ui/ToDoPane.java trunk/src/argouml-app/src/org/argouml/cognitive/ui/ToDoPerspective.java
Log: Defect 5420: Reduce the processing of todo items within the AWT thread. Required for 0.26.1 branch also. Modified: trunk/src/argouml-app/src/org/argouml/cognitive/ToDoList.java Url: http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-app/src/org/argouml/cognitive/ToDoList.java?view=diff&rev=15881&p1=trunk/src/argouml-app/src/org/argouml/cognitive/ToDoList.java&p2=trunk/src/argouml-app/src/org/argouml/cognitive/ToDoList.java&r1=15880&r2=15881 ============================================================================== --- trunk/src/argouml-app/src/org/argouml/cognitive/ToDoList.java (original) +++ trunk/src/argouml-app/src/org/argouml/cognitive/ToDoList.java 2008-10-04 06:06:21-0700 @@ -765,6 +765,9 @@ * @param theItems the todo items */ protected void fireToDoItemsAdded(List<ToDoItem> theItems) { + if (theItems.isEmpty()) { + return; + } // Guaranteed to return a non-null array Object[] listeners = listenerList.getListenerList(); ToDoListEvent e = null; @@ -794,6 +797,9 @@ * @param theItems the todo items */ protected void fireToDoItemsRemoved(List<ToDoItem> theItems) { + if (theItems.isEmpty()) { + return; + } // Guaranteed to return a non-null array Object[] listeners = listenerList.getListenerList(); ToDoListEvent e = null; Modified: trunk/src/argouml-app/src/org/argouml/cognitive/ui/ToDoByDecision.java Url: http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-app/src/org/argouml/cognitive/ui/ToDoByDecision.java?view=diff&rev=15881&p1=trunk/src/argouml-app/src/org/argouml/cognitive/ui/ToDoByDecision.java&p2=trunk/src/argouml-app/src/org/argouml/cognitive/ui/ToDoByDecision.java&r1=15880&r2=15881 ============================================================================== --- trunk/src/argouml-app/src/org/argouml/cognitive/ui/ToDoByDecision.java (original) +++ trunk/src/argouml-app/src/org/argouml/cognitive/ui/ToDoByDecision.java 2008-10-04 06:06:21-0700 @@ -87,7 +87,7 @@ children[nMatchingItems] = item; nMatchingItems++; } - fireTreeNodesChanged(this, path, childIndices, children); + fireNodesChanged(path, childIndices, children); } } @@ -124,7 +124,7 @@ children[nMatchingItems] = item; nMatchingItems++; } - fireTreeNodesInserted(this, path, childIndices, children); + fireNodesInserted(path, childIndices, children); } } @@ -151,7 +151,7 @@ } path[1] = dec; //fireTreeNodesChanged(this, path, childIndices, children); - fireTreeStructureChanged(path); + fireStructureChanged(path); } } Modified: trunk/src/argouml-app/src/org/argouml/cognitive/ui/ToDoByGoal.java Url: http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-app/src/org/argouml/cognitive/ui/ToDoByGoal.java?view=diff&rev=15881&p1=trunk/src/argouml-app/src/org/argouml/cognitive/ui/ToDoByGoal.java&p2=trunk/src/argouml-app/src/org/argouml/cognitive/ui/ToDoByGoal.java&r1=15880&r2=15881 ============================================================================== --- trunk/src/argouml-app/src/org/argouml/cognitive/ui/ToDoByGoal.java (original) +++ trunk/src/argouml-app/src/org/argouml/cognitive/ui/ToDoByGoal.java 2008-10-04 06:06:21-0700 @@ -70,7 +70,9 @@ } nMatchingItems++; } - if (nMatchingItems == 0) continue; + if (nMatchingItems == 0) { + continue; + } int[] childIndices = new int[nMatchingItems]; Object[] children = new Object[nMatchingItems]; nMatchingItems = 0; @@ -82,7 +84,7 @@ children[nMatchingItems] = item; nMatchingItems++; } - fireTreeNodesChanged(this, path, childIndices, children); + fireNodesChanged(path, childIndices, children); } } @@ -118,7 +120,7 @@ children[nMatchingItems] = item; nMatchingItems++; } - fireTreeNodesInserted(this, path, childIndices, children); + fireNodesInserted(path, childIndices, children); } } @@ -134,12 +136,16 @@ LOG.debug("toDoItemRemoved updating decision node!"); boolean anyInGoal = false; for (ToDoItem item : tde.getToDoItemList()) { - if (item.supports(g)) anyInGoal = true; + if (item.supports(g)) { + anyInGoal = true; + } + } + if (!anyInGoal) { + continue; } - if (!anyInGoal) continue; path[1] = g; //fireTreeNodesChanged(this, path, childIndices, children); - fireTreeStructureChanged(path); + fireStructureChanged(path); } } Modified: trunk/src/argouml-app/src/org/argouml/cognitive/ui/ToDoByOffender.java Url: http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-app/src/org/argouml/cognitive/ui/ToDoByOffender.java?view=diff&rev=15881&p1=trunk/src/argouml-app/src/org/argouml/cognitive/ui/ToDoByOffender.java&p2=trunk/src/argouml-app/src/org/argouml/cognitive/ui/ToDoByOffender.java&r1=15880&r2=15881 ============================================================================== --- trunk/src/argouml-app/src/org/argouml/cognitive/ui/ToDoByOffender.java (original) +++ trunk/src/argouml-app/src/org/argouml/cognitive/ui/ToDoByOffender.java 2008-10-04 06:06:21-0700 @@ -96,7 +96,7 @@ nMatchingItems++; } } - fireTreeNodesChanged(this, path, childIndices, children); + fireNodesChanged(path, childIndices, children); } } } @@ -145,7 +145,7 @@ nMatchingItems++; } } - fireTreeNodesInserted(this, path, childIndices, children); + fireNodesInserted(path, childIndices, children); } } } @@ -181,7 +181,7 @@ LOG.debug("toDoItemRemoved updating PriorityNode"); path[1] = off; // fireTreeNodesChanged(this, path, childIndices, children); - fireTreeStructureChanged(path); + fireStructureChanged(path); } } } Modified: trunk/src/argouml-app/src/org/argouml/cognitive/ui/ToDoByPoster.java Url: http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-app/src/org/argouml/cognitive/ui/ToDoByPoster.java?view=diff&rev=15881&p1=trunk/src/argouml-app/src/org/argouml/cognitive/ui/ToDoByPoster.java&p2=trunk/src/argouml-app/src/org/argouml/cognitive/ui/ToDoByPoster.java&r1=15880&r2=15881 ============================================================================== --- trunk/src/argouml-app/src/org/argouml/cognitive/ui/ToDoByPoster.java (original) +++ trunk/src/argouml-app/src/org/argouml/cognitive/ui/ToDoByPoster.java 2008-10-04 06:06:21-0700 @@ -92,7 +92,7 @@ children[nMatchingItems] = item; nMatchingItems++; } - fireTreeNodesChanged(this, path, childIndices, children); + fireNodesChanged(path, childIndices, children); } } } @@ -134,7 +134,7 @@ children[nMatchingItems] = item; nMatchingItems++; } - fireTreeNodesInserted(this, path, childIndices, children); + fireNodesInserted(path, childIndices, children); } } } @@ -165,7 +165,7 @@ continue; } path[1] = p; - fireTreeStructureChanged(path); + fireStructureChanged(path); } } } Modified: trunk/src/argouml-app/src/org/argouml/cognitive/ui/ToDoByPriority.java Url: http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-app/src/org/argouml/cognitive/ui/ToDoByPriority.java?view=diff&rev=15881&p1=trunk/src/argouml-app/src/org/argouml/cognitive/ui/ToDoByPriority.java&p2=trunk/src/argouml-app/src/org/argouml/cognitive/ui/ToDoByPriority.java&r1=15880&r2=15881 ============================================================================== --- trunk/src/argouml-app/src/org/argouml/cognitive/ui/ToDoByPriority.java (original) +++ trunk/src/argouml-app/src/org/argouml/cognitive/ui/ToDoByPriority.java 2008-10-04 06:06:21-0700 @@ -59,7 +59,7 @@ public void toDoItemsChanged(ToDoListEvent tde) { LOG.debug("toDoItemChanged"); List<ToDoItem> items = tde.getToDoItemList(); - Object[] path = new Object[2]; + final Object[] path = new Object[2]; path[0] = Designer.theDesigner().getToDoList(); for (PriorityNode pn : PriorityNode.getPriorityList()) { @@ -76,8 +76,8 @@ if (nMatchingItems == 0) { continue; } - int[] childIndices = new int[nMatchingItems]; - Object[] children = new Object[nMatchingItems]; + final int[] childIndices = new int[nMatchingItems]; + final Object[] children = new Object[nMatchingItems]; nMatchingItems = 0; synchronized (items) { for (ToDoItem item : items) { @@ -89,7 +89,7 @@ nMatchingItems++; } } - fireTreeNodesChanged(this, path, childIndices, children); + fireTreeNodesChanged(this, path, childIndices, children); } } @@ -99,7 +99,7 @@ public void toDoItemsAdded(ToDoListEvent tde) { LOG.debug("toDoItemAdded"); List<ToDoItem> items = tde.getToDoItemList(); - Object[] path = new Object[2]; + final Object[] path = new Object[2]; path[0] = Designer.theDesigner().getToDoList(); for (PriorityNode pn : PriorityNode.getPriorityList()) { @@ -116,8 +116,8 @@ if (nMatchingItems == 0) { continue; } - int[] childIndices = new int[nMatchingItems]; - Object[] children = new Object[nMatchingItems]; + final int[] childIndices = new int[nMatchingItems]; + final Object[] children = new Object[nMatchingItems]; nMatchingItems = 0; synchronized (items) { for (ToDoItem item : items) { @@ -129,7 +129,7 @@ nMatchingItems++; } } - fireTreeNodesInserted(this, path, childIndices, children); + fireNodesInserted(path, childIndices, children); } } @@ -139,7 +139,7 @@ public void toDoItemsRemoved(ToDoListEvent tde) { LOG.debug("toDoItemRemoved"); List<ToDoItem> items = tde.getToDoItemList(); - Object[] path = new Object[2]; + final Object[] path = new Object[2]; path[0] = Designer.theDesigner().getToDoList(); for (PriorityNode pn : PriorityNode.getPriorityList()) { @@ -159,7 +159,7 @@ LOG.debug("toDoItemRemoved updating PriorityNode"); path[1] = pn; //fireTreeNodesChanged(this, path, childIndices, children); - fireTreeStructureChanged(path); + fireStructureChanged(path); } } Modified: trunk/src/argouml-app/src/org/argouml/cognitive/ui/ToDoByType.java Url: http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-app/src/org/argouml/cognitive/ui/ToDoByType.java?view=diff&rev=15881&p1=trunk/src/argouml-app/src/org/argouml/cognitive/ui/ToDoByType.java&p2=trunk/src/argouml-app/src/org/argouml/cognitive/ui/ToDoByType.java&r1=15880&r2=15881 ============================================================================== --- trunk/src/argouml-app/src/org/argouml/cognitive/ui/ToDoByType.java (original) +++ trunk/src/argouml-app/src/org/argouml/cognitive/ui/ToDoByType.java 2008-10-04 06:06:21-0700 @@ -87,7 +87,7 @@ children[nMatchingItems] = item; nMatchingItems++; } - fireTreeNodesChanged(this, path, childIndices, children); + fireNodesChanged(path, childIndices, children); } } @@ -124,7 +124,7 @@ children[nMatchingItems] = item; nMatchingItems++; } - fireTreeNodesInserted(this, path, childIndices, children); + fireNodesInserted(path, childIndices, children); } } @@ -151,7 +151,7 @@ LOG.debug("toDoItemRemoved updating PriorityNode"); path[1] = ktn; //fireTreeNodesChanged(this, path, childIndices, children); - fireTreeStructureChanged(path); + fireStructureChanged(path); } } Modified: trunk/src/argouml-app/src/org/argouml/cognitive/ui/ToDoPane.java Url: http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-app/src/org/argouml/cognitive/ui/ToDoPane.java?view=diff&rev=15881&p1=trunk/src/argouml-app/src/org/argouml/cognitive/ui/ToDoPane.java&p2=trunk/src/argouml-app/src/org/argouml/cognitive/ui/ToDoPane.java&r1=15880&r2=15881 ============================================================================== --- trunk/src/argouml-app/src/org/argouml/cognitive/ui/ToDoPane.java (original) +++ trunk/src/argouml-app/src/org/argouml/cognitive/ui/ToDoPane.java 2008-10-04 06:06:21-0700 @@ -383,13 +383,13 @@ * @see org.argouml.cognitive.ToDoListListener#toDoItemsChanged(org.argouml.cognitive.ToDoListEvent) */ public void toDoItemsChanged(final ToDoListEvent tde) { - swingInvoke(new Runnable() { - public void run() { +// swingInvoke(new Runnable() { +// public void run() { if (curPerspective instanceof ToDoListListener) { ((ToDoListListener) curPerspective).toDoItemsChanged(tde); } - } - }); +// } +// }); } @@ -397,8 +397,8 @@ * @see org.argouml.cognitive.ToDoListListener#toDoItemsAdded(org.argouml.cognitive.ToDoListEvent) */ public void toDoItemsAdded(final ToDoListEvent tde) { - swingInvoke(new Runnable() { - public void run() { +// swingInvoke(new Runnable() { +// public void run() { if (curPerspective instanceof ToDoListListener) { ((ToDoListListener) curPerspective).toDoItemsAdded(tde); } @@ -413,36 +413,37 @@ } } updateCountLabel(); - } - }); +// } +// }); } /* * @see org.argouml.cognitive.ToDoListListener#toDoItemsRemoved(org.argouml.cognitive.ToDoListEvent) */ public void toDoItemsRemoved(final ToDoListEvent tde) { - swingInvoke(new Runnable() { - public void run() { +// swingInvoke(new Runnable() { +// public void run() { if (curPerspective instanceof ToDoListListener) { + LOG.warn("todo removed " + tde.getToDoItemList().size()); ((ToDoListListener) curPerspective).toDoItemsRemoved(tde); } updateCountLabel(); - } - }); +// } +// }); } /* * @see org.argouml.cognitive.ToDoListListener#toDoListChanged(org.argouml.cognitive.ToDoListEvent) */ public void toDoListChanged(final ToDoListEvent tde) { - swingInvoke(new Runnable() { - public void run() { +// swingInvoke(new Runnable() { +// public void run() { if (curPerspective instanceof ToDoListListener) { ((ToDoListListener) curPerspective).toDoListChanged(tde); } updateCountLabel(); - } - }); +// } +// }); } /* TODO: Indicate the direction! */ Modified: trunk/src/argouml-app/src/org/argouml/cognitive/ui/ToDoPerspective.java Url: http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-app/src/org/argouml/cognitive/ui/ToDoPerspective.java?view=diff&rev=15881&p1=trunk/src/argouml-app/src/org/argouml/cognitive/ui/ToDoPerspective.java&p2=trunk/src/argouml-app/src/org/argouml/cognitive/ui/ToDoPerspective.java&r1=15880&r2=15881 ============================================================================== --- trunk/src/argouml-app/src/org/argouml/cognitive/ui/ToDoPerspective.java (original) +++ trunk/src/argouml-app/src/org/argouml/cognitive/ui/ToDoPerspective.java 2008-10-04 06:06:21-0700 @@ -27,6 +27,8 @@ import java.util.ArrayList; import java.util.List; +import javax.swing.SwingUtilities; + import org.apache.log4j.Logger; import org.argouml.cognitive.ToDoItem; import org.argouml.ui.TreeModelComposite; @@ -161,5 +163,55 @@ addFlatChildren(getChild(node, i)); } } - + + /** + * Invoke a task on the Swing thread. If we are running on the Swing thread, + * this happens immediately. Otherwise the task is queued for later + * execution using SwingUtilities.invokeLater. + * <p> + * This is necessary because event notification of ToDoListener events is + * likely to be coming from the ToDo Validity Checker thread running in the + * background. + * + * @param task a Runnable task who's run() method will be invoked + */ + protected void swingInvoke(Runnable task) { + if (SwingUtilities.isEventDispatchThread()) { + task.run(); + } else { + SwingUtilities.invokeLater(task); + } + } + + protected void fireNodesInserted( + final Object[] path, + final int[] childIndices, + final Object[] children) { + swingInvoke(new Runnable() { + public void run() { + fireTreeNodesInserted(this, path, childIndices, children); + } + }); + } + + protected void fireStructureChanged( + final Object[] path) { + swingInvoke(new Runnable() { + public void run() { + + fireTreeStructureChanged(path); + } + }); + } + + protected void fireNodesChanged( + final Object[] path, + final int[] childIndices, + final Object[] children) { + swingInvoke(new Runnable() { + public void run() { + fireTreeNodesChanged(this, path, childIndices, children); + } + }); + } } --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
