Coverage Report - org.argouml.cognitive.ui.ToDoByPriority
 
Classes in this File Line Coverage Branch Coverage Complexity
ToDoByPriority
63%
53/84
59%
19/32
4.2
 
 1  
 /* $Id: ToDoByPriority.java 17818 2010-01-12 18:39:46Z linus $
 2  
  *****************************************************************************
 3  
  * Copyright (c) 2009 Contributors - see below
 4  
  * All rights reserved. This program and the accompanying materials
 5  
  * are made available under the terms of the Eclipse Public License v1.0
 6  
  * which accompanies this distribution, and is available at
 7  
  * http://www.eclipse.org/legal/epl-v10.html
 8  
  *
 9  
  * Contributors:
 10  
  *    bobtarling
 11  
  *****************************************************************************
 12  
  *
 13  
  * Some portions of this file was previously release using the BSD License:
 14  
  */
 15  
 
 16  
 // Copyright (c) 1996-2006 The Regents of the University of California. All
 17  
 // Rights Reserved. Permission to use, copy, modify, and distribute this
 18  
 // software and its documentation without fee, and without a written
 19  
 // agreement is hereby granted, provided that the above copyright notice
 20  
 // and this paragraph appear in all copies.  This software program and
 21  
 // documentation are copyrighted by The Regents of the University of
 22  
 // California. The software program and documentation are supplied "AS
 23  
 // IS", without any accompanying services from The Regents. The Regents
 24  
 // does not warrant that the operation of the program will be
 25  
 // uninterrupted or error-free. The end-user understands that the program
 26  
 // was developed for research purposes and is advised not to rely
 27  
 // exclusively on the program for any reason.  IN NO EVENT SHALL THE
 28  
 // UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT,
 29  
 // SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS,
 30  
 // ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF
 31  
 // THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF
 32  
 // SUCH DAMAGE. THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY
 33  
 // WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
 34  
 // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE
 35  
 // PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY OF
 36  
 // CALIFORNIA HAS NO OBLIGATIONS TO PROVIDE MAINTENANCE, SUPPORT,
 37  
 // UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
 38  
 
 39  
 package org.argouml.cognitive.ui;
 40  
 
 41  
 import java.util.List;
 42  
 
 43  
 import org.apache.log4j.Logger;
 44  
 import org.argouml.cognitive.Designer;
 45  
 import org.argouml.cognitive.ToDoItem;
 46  
 import org.argouml.cognitive.ToDoListEvent;
 47  
 import org.argouml.cognitive.ToDoListListener;
 48  
 
 49  
 /**
 50  
  * Represents a perspective for ToDo items: grouping by priority.
 51  
  *
 52  
  */
 53  
 public class ToDoByPriority extends ToDoPerspective
 54  
     implements ToDoListListener {
 55  900
     private static final Logger LOG =
 56  
         Logger.getLogger(ToDoByPriority.class);
 57  
 
 58  
     /**
 59  
      * The constructor.
 60  
      *
 61  
      */
 62  
     public ToDoByPriority() {
 63  900
         super("combobox.todo-perspective-priority");
 64  900
         addSubTreeModel(new GoListToPriorityToItem());
 65  900
     }
 66  
 
 67  
     ////////////////////////////////////////////////////////////////
 68  
     // ToDoListListener implementation
 69  
 
 70  
     /*
 71  
      * @see org.argouml.cognitive.ToDoListListener#toDoItemsChanged(org.argouml.cognitive.ToDoListEvent)
 72  
      */
 73  
     public void toDoItemsChanged(ToDoListEvent tde) {
 74  0
         LOG.debug("toDoItemChanged");
 75  0
         List<ToDoItem> items = tde.getToDoItemList();
 76  0
         Object[] path = new Object[2];
 77  0
         path[0] = Designer.theDesigner().getToDoList();
 78  
 
 79  0
         for (PriorityNode pn : PriorityNode.getPriorityList()) {
 80  0
             path[1] = pn;
 81  0
             int nMatchingItems = 0;
 82  0
             synchronized (items) {
 83  0
                 for (ToDoItem item : items) {
 84  0
                     if (item.getPriority() != pn.getPriority()) {
 85  0
                         continue;
 86  
                     }
 87  0
                     nMatchingItems++;
 88  
                 }
 89  0
             }
 90  0
             if (nMatchingItems == 0) {
 91  0
                 continue;
 92  
             }
 93  0
             int[] childIndices = new int[nMatchingItems];
 94  0
             Object[] children = new Object[nMatchingItems];
 95  0
             nMatchingItems = 0;
 96  0
             synchronized (items) {
 97  0
                 for (ToDoItem item : items) {
 98  0
                     if (item.getPriority() != pn.getPriority()) {
 99  0
                         continue;
 100  
                     }
 101  0
                     childIndices[nMatchingItems] = getIndexOfChild(pn, item);
 102  0
                     children[nMatchingItems] = item;
 103  0
                     nMatchingItems++;
 104  
                 }
 105  0
             }
 106  0
             fireTreeNodesChanged(this, path, childIndices, children);
 107  0
         }
 108  0
     }
 109  
 
 110  
     /*
 111  
      * @see org.argouml.cognitive.ToDoListListener#toDoItemsAdded(org.argouml.cognitive.ToDoListEvent)
 112  
      */
 113  
     public void toDoItemsAdded(ToDoListEvent tde) {
 114  1967
         LOG.debug("toDoItemAdded");
 115  1967
         List<ToDoItem> items = tde.getToDoItemList();
 116  1967
         Object[] path = new Object[2];
 117  1967
         path[0] = Designer.theDesigner().getToDoList();
 118  
 
 119  1967
         for (PriorityNode pn : PriorityNode.getPriorityList()) {
 120  5901
             path[1] = pn;
 121  5901
             int nMatchingItems = 0;
 122  5901
             synchronized (items) {
 123  5901
                 for (ToDoItem item : items) {
 124  5901
                     if (item.getPriority() != pn.getPriority()) {
 125  3934
                         continue;
 126  
                     }
 127  1967
                     nMatchingItems++;
 128  
                 }
 129  5901
             }
 130  5901
             if (nMatchingItems == 0) {
 131  3934
                 continue;
 132  
             }
 133  1967
             int[] childIndices = new int[nMatchingItems];
 134  1967
             Object[] children = new Object[nMatchingItems];
 135  1967
             nMatchingItems = 0;
 136  1967
             synchronized (items) {
 137  1967
                 for (ToDoItem item : items) {
 138  1967
                     if (item.getPriority() != pn.getPriority()) {
 139  0
                         continue;
 140  
                     }
 141  1967
                     childIndices[nMatchingItems] = getIndexOfChild(pn, item);
 142  1967
                     children[nMatchingItems] = item;
 143  1967
                     nMatchingItems++;
 144  
                 }
 145  1967
             }
 146  1967
             fireTreeNodesInserted(this, path, childIndices, children);
 147  1967
         }
 148  1967
     }
 149  
 
 150  
     /*
 151  
      * @see org.argouml.cognitive.ToDoListListener#toDoItemsRemoved(org.argouml.cognitive.ToDoListEvent)
 152  
      */
 153  
     public void toDoItemsRemoved(ToDoListEvent tde) {
 154  159
         LOG.debug("toDoItemRemoved");
 155  159
         List<ToDoItem> items = tde.getToDoItemList();
 156  159
         Object[] path = new Object[2];
 157  159
         path[0] = Designer.theDesigner().getToDoList();
 158  
 
 159  159
         for (PriorityNode pn : PriorityNode.getPriorityList()) {
 160  477
             int nodePriority = pn.getPriority();
 161  477
             boolean anyInPri = false;
 162  477
             synchronized (items) {
 163  477
                 for (ToDoItem item : items) {
 164  681
                     int pri = item.getPriority();
 165  681
                     if (pri == nodePriority) {
 166  227
                         anyInPri = true;
 167  
                     }
 168  681
                 }
 169  477
             }
 170  477
             if (!anyInPri) {
 171  318
                 continue;
 172  
             }
 173  159
             LOG.debug("toDoItemRemoved updating PriorityNode");
 174  159
             path[1] = pn;
 175  
             //fireTreeNodesChanged(this, path, childIndices, children);
 176  159
             fireTreeStructureChanged(path);
 177  159
         }
 178  159
     }
 179  
 
 180  
     /*
 181  
      * @see org.argouml.cognitive.ToDoListListener#toDoListChanged(org.argouml.cognitive.ToDoListEvent)
 182  
      */
 183  0
     public void toDoListChanged(ToDoListEvent tde) { }
 184  
 
 185  
 }
 186  
 
 187  
 
 188