Coverage Report - org.argouml.cognitive.ui.GoListToPriorityToItem
 
Classes in this File Line Coverage Branch Coverage Complexity
GoListToPriorityToItem
63%
31/49
55%
19/34
4.714
 
 1  
 /* $Id: GoListToPriorityToItem.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  
  *    linus
 11  
  *****************************************************************************
 12  
  *
 13  
  * Some portions of this file was previously release using the BSD License:
 14  
  */
 15  
 
 16  
 // Copyright (c) 1996-2008 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 javax.swing.event.TreeModelListener;
 44  
 import javax.swing.tree.TreePath;
 45  
 
 46  
 import org.argouml.cognitive.Designer;
 47  
 import org.argouml.cognitive.ToDoItem;
 48  
 import org.argouml.cognitive.ToDoList;
 49  
 
 50  
 
 51  
 /**
 52  
  * Rule for sorting the ToDo list: Priority -> Item.
 53  
  *
 54  
  */
 55  1800
 public class GoListToPriorityToItem extends AbstractGoList2 {
 56  
 
 57  
     ////////////////////////////////////////////////////////////////
 58  
     // TreeModel implementation
 59  
 
 60  
     /*
 61  
      * @see javax.swing.tree.TreeModel#getChild(java.lang.Object, int)
 62  
      */
 63  
     public Object getChild(Object parent, int index) {
 64  6791
         if (parent instanceof ToDoList) {
 65  6791
             return PriorityNode.getPriorityList().get(index);
 66  
         }
 67  0
         if (parent instanceof PriorityNode) {
 68  0
             PriorityNode pn = (PriorityNode) parent;
 69  0
             List<ToDoItem> itemList = 
 70  
                 Designer.theDesigner().getToDoList().getToDoItemList();
 71  0
             synchronized (itemList) {
 72  0
                 for (ToDoItem item : itemList) {
 73  0
                     if (item.getPriority() == pn.getPriority()) {
 74  0
                         if (index == 0) {
 75  0
                             return item;
 76  
                         }
 77  0
                         index--;
 78  
                     }
 79  
                 }
 80  0
             }
 81  
         }
 82  0
         throw new IndexOutOfBoundsException("getChild shouldnt get here "
 83  
                                             + "GoListToPriorityToItem");
 84  
     }
 85  
 
 86  
     /*
 87  
      * @see javax.swing.tree.TreeModel#getChildCount(java.lang.Object)
 88  
      */
 89  
     public int getChildCount(Object parent) {
 90  26680
         if (parent instanceof ToDoList) {
 91  13080
             return PriorityNode.getPriorityList().size();
 92  
         }
 93  13600
         if (parent instanceof PriorityNode) {
 94  13600
             PriorityNode pn = (PriorityNode) parent;
 95  13600
             int count = 0;
 96  13600
             List<ToDoItem> itemList = Designer.theDesigner().getToDoList()
 97  
                     .getToDoItemList();
 98  13600
             synchronized (itemList) {
 99  13600
                 for (ToDoItem item : itemList) {
 100  11496
                     if (item.getPriority() == pn.getPriority()) {
 101  8664
                         count++;
 102  
                     }
 103  
                 }
 104  13600
             }
 105  13600
             return count;
 106  
         }
 107  0
         return 0;
 108  
     }
 109  
    
 110  
     
 111  
     /*
 112  
      * @see javax.swing.tree.TreeModel#getIndexOfChild(java.lang.Object, java.lang.Object)
 113  
      */
 114  
     public int getIndexOfChild(Object parent, Object child) {
 115  1967
         if (parent instanceof ToDoList) {
 116  0
             return PriorityNode.getPriorityList().indexOf(child);
 117  
         }
 118  1967
         if (parent instanceof PriorityNode) {
 119  1967
             int index = 0;
 120  1967
             PriorityNode pn = (PriorityNode) parent;
 121  1967
             List<ToDoItem> itemList = Designer.theDesigner().getToDoList()
 122  
                     .getToDoItemList();
 123  1967
             synchronized (itemList) {
 124  1967
                 for (ToDoItem item : itemList) {
 125  3020
                     if (item.getPriority() == pn.getPriority()) {
 126  3020
                         if (item == child) {
 127  1967
                             return index;
 128  
                         }
 129  1053
                         index++;
 130  
                     }
 131  
                 }
 132  0
             }
 133  
         }
 134  0
         return -1;
 135  
     }
 136  
 
 137  
     /*
 138  
      * @see javax.swing.tree.TreeModel#isLeaf(java.lang.Object)
 139  
      */
 140  
     public boolean isLeaf(Object node) {
 141  15966
         if (node instanceof ToDoList) {
 142  6300
             return false;
 143  
         }
 144  9666
         if (node instanceof PriorityNode && getChildCount(node) > 0) {
 145  2005
             return false;
 146  
         }
 147  7661
         return true;
 148  
     }
 149  
 
 150  
     /*
 151  
      * @see javax.swing.tree.TreeModel#valueForPathChanged(
 152  
      * javax.swing.tree.TreePath, java.lang.Object)
 153  
      */
 154  0
     public void valueForPathChanged(TreePath path, Object newValue) { }
 155  
 
 156  
     /*
 157  
      * @see javax.swing.tree.TreeModel#addTreeModelListener(javax.swing.event.TreeModelListener)
 158  
      */
 159  0
     public void addTreeModelListener(TreeModelListener l) { }
 160  
 
 161  
     /*
 162  
      * @see javax.swing.tree.TreeModel#removeTreeModelListener(javax.swing.event.TreeModelListener)
 163  
      */
 164  0
     public void removeTreeModelListener(TreeModelListener l) { }
 165  
 
 166  
 }