Coverage Report - org.argouml.cognitive.ui.ToDoByOffender
 
Classes in this File Line Coverage Branch Coverage Complexity
ToDoByOffender
3%
4/101
0%
0/32
4.2
 
 1  
 /* $Id: ToDoByOffender.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.ListSet;
 46  
 import org.argouml.cognitive.ToDoItem;
 47  
 import org.argouml.cognitive.ToDoListEvent;
 48  
 import org.argouml.cognitive.ToDoListListener;
 49  
 
 50  
 /**
 51  
  * Represents a perspective for ToDo items: grouping by offender type.
 52  
  *
 53  
  */
 54  
 public class ToDoByOffender extends ToDoPerspective
 55  
         implements ToDoListListener {
 56  
 
 57  900
     private static final Logger LOG = Logger.getLogger(ToDoByOffender.class);
 58  
 
 59  
     /**
 60  
      * The constructor.
 61  
      *
 62  
      */
 63  
     public ToDoByOffender() {
 64  900
         super("combobox.todo-perspective-offender");
 65  900
         addSubTreeModel(new GoListToOffenderToItem());
 66  900
     }
 67  
 
 68  
     ////////////////////////////////////////////////////////////////
 69  
     // ToDoListListener implementation
 70  
 
 71  
     /*
 72  
      * @see org.argouml.cognitive.ToDoListListener#toDoItemsChanged(org.argouml.cognitive.ToDoListEvent)
 73  
      */
 74  
     public void toDoItemsChanged(ToDoListEvent tde) {
 75  0
         LOG.debug("toDoItemsChanged");
 76  0
         List<ToDoItem> items = tde.getToDoItemList();
 77  0
         Object[] path = new Object[2];
 78  0
         path[0] = Designer.theDesigner().getToDoList();
 79  
 
 80  0
         ListSet allOffenders = Designer.theDesigner().getToDoList()
 81  
                 .getOffenders();
 82  0
         synchronized (allOffenders) {
 83  0
             for (Object off : allOffenders) {
 84  0
                 path[1] = off;
 85  0
                 int nMatchingItems = 0;
 86  0
                 synchronized (items) {
 87  0
                     for (ToDoItem item : items) {
 88  0
                         ListSet offenders = item.getOffenders();
 89  0
                         if (!offenders.contains(off)) {
 90  0
                             continue;
 91  
                         }
 92  0
                         nMatchingItems++;
 93  0
                     }
 94  0
                 }
 95  0
                 if (nMatchingItems == 0) {
 96  0
                     continue;
 97  
                 }
 98  0
                 int[] childIndices = new int[nMatchingItems];
 99  0
                 Object[] children = new Object[nMatchingItems];
 100  0
                 nMatchingItems = 0;
 101  0
                 synchronized (items) {
 102  0
                     for (ToDoItem item : items) {
 103  0
                         ListSet offenders = item.getOffenders();
 104  0
                         if (!offenders.contains(off)) {
 105  0
                             continue;
 106  
                         }
 107  0
                         childIndices[nMatchingItems] = getIndexOfChild(off,
 108  
                                 item);
 109  0
                         children[nMatchingItems] = item;
 110  0
                         nMatchingItems++;
 111  0
                     }
 112  0
                 }
 113  0
                 fireTreeNodesChanged(this, path, childIndices, children);
 114  0
             }
 115  0
         }
 116  0
     }
 117  
 
 118  
     /*
 119  
      * @see org.argouml.cognitive.ToDoListListener#toDoItemsAdded(org.argouml.cognitive.ToDoListEvent)
 120  
      */
 121  
     public void toDoItemsAdded(ToDoListEvent tde) {
 122  0
         LOG.debug("toDoItemAdded");
 123  0
         List<ToDoItem> items = tde.getToDoItemList();
 124  0
         Object[] path = new Object[2];
 125  0
         path[0] = Designer.theDesigner().getToDoList();
 126  
 
 127  0
         ListSet allOffenders = Designer.theDesigner().getToDoList()
 128  
                 .getOffenders();
 129  0
         synchronized (allOffenders) {
 130  0
             for (Object off : allOffenders) {
 131  0
                 path[1] = off;
 132  0
                 int nMatchingItems = 0;
 133  
                 // TODO: This first loop just to count the items appears
 134  
                 // redundant to me - tfm 20070630
 135  0
                 synchronized (items) {
 136  0
                     for (ToDoItem item : items) {
 137  0
                         ListSet offenders = item.getOffenders();
 138  0
                         if (!offenders.contains(off)) {
 139  0
                             continue;
 140  
                         }
 141  0
                         nMatchingItems++;
 142  0
                     }
 143  0
                 }
 144  0
                 if (nMatchingItems == 0) {
 145  0
                     continue;
 146  
                 }
 147  0
                 int[] childIndices = new int[nMatchingItems];
 148  0
                 Object[] children = new Object[nMatchingItems];
 149  0
                 nMatchingItems = 0;
 150  0
                 synchronized (items) {
 151  0
                     for (ToDoItem item : items) {
 152  0
                         ListSet offenders = item.getOffenders();
 153  0
                         if (!offenders.contains(off)) {
 154  0
                             continue;
 155  
                         }
 156  0
                         childIndices[nMatchingItems] = getIndexOfChild(off,
 157  
                                 item);
 158  0
                         children[nMatchingItems] = item;
 159  0
                         nMatchingItems++;
 160  0
                     }
 161  0
                 }
 162  0
                 fireTreeNodesInserted(this, path, childIndices, children);
 163  0
             }
 164  0
         }
 165  0
     }
 166  
 
 167  
     /*
 168  
      * @see org.argouml.cognitive.ToDoListListener#toDoItemsRemoved(org.argouml.cognitive.ToDoListEvent)
 169  
      */
 170  
     public void toDoItemsRemoved(ToDoListEvent tde) {
 171  0
         LOG.debug("toDoItemRemoved");
 172  0
         List<ToDoItem> items = tde.getToDoItemList();
 173  0
         Object[] path = new Object[2];
 174  0
         path[0] = Designer.theDesigner().getToDoList();
 175  
 
 176  0
         ListSet allOffenders = Designer.theDesigner().getToDoList()
 177  
                 .getOffenders();
 178  0
         synchronized (allOffenders) {
 179  0
             for (Object off : allOffenders) {
 180  0
                 boolean anyInOff = false;
 181  0
                 synchronized (items) {
 182  0
                     for (ToDoItem item : items) {
 183  0
                         ListSet offenders = item.getOffenders();
 184  
                         // TODO: This looks O(n^2)
 185  0
                         if (offenders.contains(off)) {
 186  0
                             anyInOff = true;
 187  0
                             break;
 188  
                         }
 189  0
                     }
 190  0
                 }
 191  0
                 if (!anyInOff) {
 192  0
                     continue;
 193  
                 }
 194  
 
 195  0
                 LOG.debug("toDoItemRemoved updating PriorityNode");
 196  0
                 path[1] = off;
 197  
                 // fireTreeNodesChanged(this, path, childIndices, children);
 198  0
                 fireTreeStructureChanged(path);
 199  0
             }
 200  0
         }
 201  0
     }
 202  
 
 203  
     /*
 204  
      * @see org.argouml.cognitive.ToDoListListener#toDoListChanged(org.argouml.cognitive.ToDoListEvent)
 205  
      */
 206  
     public void toDoListChanged(ToDoListEvent tde) {
 207  0
     }
 208  
 
 209  
 } /* end class ToDoByOffender */
 210