Author: penyaskito Date: 2008-11-05 01:52:33-0800 New Revision: 15967 Modified: branches/BRANCH_0_26_x/src/argouml-app/src/org/argouml/cognitive/ToDoList.java branches/BRANCH_0_26_x/src/argouml-app/src/org/argouml/cognitive/ToDoListEvent.java branches/BRANCH_0_26_x/src/argouml-app/src/org/argouml/cognitive/ui/ToDoPane.java
Log: Issue 5420: ToDo items created by critics do not vanish when fixing the model. Fixed by Bob Tarling. Modified: branches/BRANCH_0_26_x/src/argouml-app/src/org/argouml/cognitive/ToDoList.java Url: http://argouml.tigris.org/source/browse/argouml/branches/BRANCH_0_26_x/src/argouml-app/src/org/argouml/cognitive/ToDoList.java?view=diff&rev=15967&p1=branches/BRANCH_0_26_x/src/argouml-app/src/org/argouml/cognitive/ToDoList.java&p2=branches/BRANCH_0_26_x/src/argouml-app/src/org/argouml/cognitive/ToDoList.java&r1=15966&r2=15967 ============================================================================== --- branches/BRANCH_0_26_x/src/argouml-app/src/org/argouml/cognitive/ToDoList.java (original) +++ branches/BRANCH_0_26_x/src/argouml-app/src/org/argouml/cognitive/ToDoList.java 2008-11-05 01:52:33-0800 @@ -39,6 +39,7 @@ import org.apache.log4j.Logger; import org.argouml.i18n.Translator; +import org.argouml.model.InvalidElementException; /** * Implements a list of ToDoItem's. @@ -217,6 +218,9 @@ boolean valid; try { valid = item.stillValid(designer); + } catch (InvalidElementException ex) { + // If element has been deleted, it's no longer valid + valid = false; } catch (Exception ex) { valid = false; StringBuffer buf = new StringBuffer( @@ -765,18 +769,20 @@ * @param theItems the todo items */ protected void fireToDoItemsAdded(List<ToDoItem> theItems) { - // Guaranteed to return a non-null array - Object[] listeners = listenerList.getListenerList(); - ToDoListEvent e = null; - // Process the listeners last to first, notifying - // those that are interested in this event - for (int i = listeners.length - 2; i >= 0; i -= 2) { - if (listeners[i] == ToDoListListener.class) { - // Lazily create the event: - if (e == null) { - e = new ToDoListEvent(theItems); + if (theItems.size() > 0) { + // Guaranteed to return a non-null array + final Object[] listeners = listenerList.getListenerList(); + ToDoListEvent e = null; + // Process the listeners last to first, notifying + // those that are interested in this event + for (int i = listeners.length - 2; i >= 0; i -= 2) { + if (listeners[i] == ToDoListListener.class) { + // Lazily create the event: + if (e == null) { + e = new ToDoListEvent(theItems); + } + ((ToDoListListener) listeners[i + 1]).toDoItemsAdded(e); } - ((ToDoListListener) listeners[i + 1]).toDoItemsAdded(e); } } } @@ -793,19 +799,21 @@ /** * @param theItems the todo items */ - protected void fireToDoItemsRemoved(List<ToDoItem> theItems) { - // Guaranteed to return a non-null array - Object[] listeners = listenerList.getListenerList(); - ToDoListEvent e = null; - // Process the listeners last to first, notifying - // those that are interested in this event - for (int i = listeners.length - 2; i >= 0; i -= 2) { - if (listeners[i] == ToDoListListener.class) { - // Lazily create the event: - if (e == null) { - e = new ToDoListEvent(theItems); + protected void fireToDoItemsRemoved(final List<ToDoItem> theItems) { + if (theItems.size() > 0) { + // Guaranteed to return a non-null array + final Object[] listeners = listenerList.getListenerList(); + ToDoListEvent e = null; + // Process the listeners last to first, notifying + // those that are interested in this event + for (int i = listeners.length - 2; i >= 0; i -= 2) { + if (listeners[i] == ToDoListListener.class) { + // Lazily create the event: + if (e == null) { + e = new ToDoListEvent(theItems); + } + ((ToDoListListener) listeners[i + 1]).toDoItemsRemoved(e); } - ((ToDoListListener) listeners[i + 1]).toDoItemsRemoved(e); } } } Modified: branches/BRANCH_0_26_x/src/argouml-app/src/org/argouml/cognitive/ToDoListEvent.java Url: http://argouml.tigris.org/source/browse/argouml/branches/BRANCH_0_26_x/src/argouml-app/src/org/argouml/cognitive/ToDoListEvent.java?view=diff&rev=15967&p1=branches/BRANCH_0_26_x/src/argouml-app/src/org/argouml/cognitive/ToDoListEvent.java&p2=branches/BRANCH_0_26_x/src/argouml-app/src/org/argouml/cognitive/ToDoListEvent.java&r1=15966&r2=15967 ============================================================================== --- branches/BRANCH_0_26_x/src/argouml-app/src/org/argouml/cognitive/ToDoListEvent.java (original) +++ branches/BRANCH_0_26_x/src/argouml-app/src/org/argouml/cognitive/ToDoListEvent.java 2008-11-05 01:52:33-0800 @@ -25,6 +25,7 @@ package org.argouml.cognitive; +import java.util.Collections; import java.util.List; import java.util.Vector; @@ -34,7 +35,7 @@ */ public class ToDoListEvent { - private List<ToDoItem> items; + private final List<ToDoItem> items; /** * The constructor. @@ -45,12 +46,14 @@ } /** - * The constructor. + * The constructor. + * Make a copy of the list to guarantee that it remains + * stable throughout the lifetime of this event. * - * @param i the List of ToDoItems that were changed/added/removed + * @param toDoItems the List of ToDoItems that were changed/added/removed */ - public ToDoListEvent(List<ToDoItem> i) { - items = i; + public ToDoListEvent(final List<ToDoItem> toDoItems) { + items = Collections.unmodifiableList(toDoItems); } /** @@ -68,5 +71,4 @@ public List<ToDoItem> getToDoItemList() { return items; } - } Modified: branches/BRANCH_0_26_x/src/argouml-app/src/org/argouml/cognitive/ui/ToDoPane.java Url: http://argouml.tigris.org/source/browse/argouml/branches/BRANCH_0_26_x/src/argouml-app/src/org/argouml/cognitive/ui/ToDoPane.java?view=diff&rev=15967&p1=branches/BRANCH_0_26_x/src/argouml-app/src/org/argouml/cognitive/ui/ToDoPane.java&p2=branches/BRANCH_0_26_x/src/argouml-app/src/org/argouml/cognitive/ui/ToDoPane.java&r1=15966&r2=15967 ============================================================================== --- branches/BRANCH_0_26_x/src/argouml-app/src/org/argouml/cognitive/ui/ToDoPane.java (original) +++ branches/BRANCH_0_26_x/src/argouml-app/src/org/argouml/cognitive/ui/ToDoPane.java 2008-11-05 01:52:33-0800 @@ -31,6 +31,7 @@ import java.awt.event.ItemListener; import java.awt.event.MouseEvent; import java.awt.event.MouseListener; +import java.lang.reflect.InvocationTargetException; import java.text.MessageFormat; import java.util.ArrayList; import java.util.List; @@ -154,7 +155,7 @@ if (splash != null) { splash.getStatusBar().showStatus( - Translator.localize("statusmsg.bar.making-todopane")); + Translator.localize("statusmsg.bar.making-todopane")); splash.getStatusBar().showProgress(25); } @@ -236,8 +237,8 @@ */ public void setCurPerspective(TreeModel per) { if (perspectives == null || !perspectives.contains(per)) { - return; - } + return; + } combo.setSelectedItem(per); toDoPerspectivesChanged++; } @@ -262,11 +263,11 @@ category = curPerspective.getChild(root, i); if (curPerspective.getIndexOfChild(category, item) != -1) { break; - } + } } if (category == null) { - return; - } + return; + } path[0] = root; path[1] = category; path[2] = item; @@ -285,8 +286,8 @@ */ public void itemStateChanged(ItemEvent e) { if (e.getSource() == combo) { - updateTree(); - } + updateTree(); + } } // -------------TreeSelectionListener implementation ----------- @@ -301,13 +302,13 @@ Object sel = getSelectedObject(); ProjectBrowser.getInstance().setToDoItem(sel); LOG.debug("lastselection: " + lastSel); - LOG.debug("sel: " + sel); + LOG.debug("sel: " + sel); if (lastSel instanceof ToDoItem) { - ((ToDoItem) lastSel).deselect(); - } + ((ToDoItem) lastSel).deselect(); + } if (sel instanceof ToDoItem) { - ((ToDoItem) sel).select(); - } + ((ToDoItem) sel).select(); + } lastSel = sel; } @@ -361,9 +362,10 @@ // ToDoListListener implementation /** - * 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. + * 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 (actually for the moment + * invokeAndWait but this should be resolved in future). * <p> * This is necessary because event notification of ToDoListener events is * likely to be coming from the ToDo Validity Checker thread running in the @@ -375,7 +377,20 @@ if (SwingUtilities.isEventDispatchThread()) { task.run(); } else { - SwingUtilities.invokeLater(task); + // TODO: We really want to use invokeLater here but there is some + // threading problem with doing so. I assume we have some problem + // with the GUI querying the todo list as a reaction to a todo + // event instead of only using the information contained within + // that event. + // With the current invokeAndWait solution we are blocking the GUI + // in the todo thread - Bob. + try { + SwingUtilities.invokeAndWait(task); + } catch (InterruptedException e) { + LOG.error("Exception", e); + } catch (InvocationTargetException e) { + LOG.error("Exception", e); + } } } @@ -448,20 +463,20 @@ /* TODO: Indicate the direction! */ private static String formatCountLabel(int size) { switch (size) { - case 0: - return Translator.localize("label.todopane.no-items"); - case 1: - return MessageFormat. - format(Translator.localize("label.todopane.item"), - new Object[] { - Integer.valueOf(size), - }); - default: - return MessageFormat. - format(Translator.localize("label.todopane.items"), - new Object[] { - Integer.valueOf(size), - }); + case 0: + return Translator.localize("label.todopane.no-items"); + case 1: + return MessageFormat. + format(Translator.localize("label.todopane.item"), + new Object[] { + Integer.valueOf(size), + }); + default: + return MessageFormat. + format(Translator.localize("label.todopane.items"), + new Object[] { + Integer.valueOf(size), + }); } } @@ -473,7 +488,7 @@ countLabel.setText(formatCountLabel(size)); countLabel.setOpaque(size > WARN_THRESHOLD); countLabel.setBackground((size >= ALARM_THRESHOLD) ? ALARM_COLOR - : WARN_COLOR); + : WARN_COLOR); } /** @@ -484,7 +499,7 @@ curPerspective = tm; if (curPerspective == null) { tree.setVisible(false); - } else { + } else { LOG.debug("ToDoPane setting tree model"); curPerspective.setRoot(root); tree.setShowsRootHandles(true); @@ -528,8 +543,8 @@ @SuppressWarnings("unused") TreePath path) { dblClicksInToDoPane++; if (getSelectedObject() == null) { - return; - } + return; + } Object sel = getSelectedObject(); if (sel instanceof ToDoItem) { ((ToDoItem) sel).action(); --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
