Coverage Report - org.argouml.cognitive.ui.ToDoByGoal
 
Classes in this File Line Coverage Branch Coverage Complexity
ToDoByGoal
6%
4/65
0%
0/32
4.2
 
 1  
 /* $Id: ToDoByGoal.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 org.apache.log4j.Logger;
 42  
 import org.argouml.cognitive.Designer;
 43  
 import org.argouml.cognitive.Goal;
 44  
 import org.argouml.cognitive.ToDoItem;
 45  
 import org.argouml.cognitive.ToDoListEvent;
 46  
 import org.argouml.cognitive.ToDoListListener;
 47  
 
 48  
 /**
 49  
  * Represents a perspective for ToDo items: grouping by goal type.
 50  
  *
 51  
  */
 52  
 public class ToDoByGoal extends ToDoPerspective
 53  
     implements ToDoListListener {
 54  900
     private static final Logger LOG =
 55  
         Logger.getLogger(ToDoByGoal.class);
 56  
 
 57  
 
 58  
     /**
 59  
      * The constructor.
 60  
      *
 61  
      */
 62  
     public ToDoByGoal() {
 63  900
         super("combobox.todo-perspective-goal");
 64  900
         addSubTreeModel(new GoListToGoalsToItems());
 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("toDoItemsChanged");
 75  0
         Object[] path = new Object[2];
 76  0
         path[0] = Designer.theDesigner().getToDoList();
 77  
 
 78  0
         for (Goal g : Designer.theDesigner().getGoalList()) {
 79  0
             path[1] = g;
 80  0
             int nMatchingItems = 0;
 81  0
             for (ToDoItem item : tde.getToDoItemList()) {
 82  0
                 if (!item.supports(g)) {
 83  0
                     continue;
 84  
                 }
 85  0
                 nMatchingItems++;
 86  
             }
 87  0
             if (nMatchingItems == 0) continue;
 88  0
             int[] childIndices = new int[nMatchingItems];
 89  0
             Object[] children = new Object[nMatchingItems];
 90  0
             nMatchingItems = 0;
 91  0
             for (ToDoItem item : tde.getToDoItemList()) {
 92  0
                 if (!item.supports(g)) {
 93  0
                     continue;
 94  
                 }
 95  0
                 childIndices[nMatchingItems] = getIndexOfChild(g, item);
 96  0
                 children[nMatchingItems] = item;
 97  0
                 nMatchingItems++;
 98  
             }
 99  0
             fireTreeNodesChanged(this, path, childIndices, children);
 100  0
         }
 101  0
     }
 102  
 
 103  
     /*
 104  
      * @see org.argouml.cognitive.ToDoListListener#toDoItemsAdded(org.argouml.cognitive.ToDoListEvent)
 105  
      */
 106  
     public void toDoItemsAdded(ToDoListEvent tde) {
 107  0
         LOG.debug("toDoItemAdded");
 108  0
         Object[] path = new Object[2];
 109  0
         path[0] = Designer.theDesigner().getToDoList();
 110  
 
 111  0
         for (Goal g : Designer.theDesigner().getGoalList()) {
 112  0
             path[1] = g;
 113  0
             int nMatchingItems = 0;
 114  0
             for (ToDoItem item : tde.getToDoItemList()) {
 115  0
                 if (!item.supports(g)) {
 116  0
                     continue;
 117  
                 }
 118  0
                 nMatchingItems++;
 119  
             }
 120  0
             if (nMatchingItems == 0) {
 121  0
                 continue;
 122  
             }
 123  0
             int[] childIndices = new int[nMatchingItems];
 124  0
             Object[] children = new Object[nMatchingItems];
 125  0
             nMatchingItems = 0;
 126  
             // TODO: This shouldn't require two passes through the list - tfm
 127  0
             for (ToDoItem item : tde.getToDoItemList()) {
 128  0
                 if (!item.supports(g)) {
 129  0
                     continue;
 130  
                 }
 131  0
                 childIndices[nMatchingItems] = getIndexOfChild(g, item);
 132  0
                 children[nMatchingItems] = item;
 133  0
                 nMatchingItems++;
 134  
             }
 135  0
             fireTreeNodesInserted(this, path, childIndices, children);
 136  0
         }
 137  0
     }
 138  
 
 139  
     /*
 140  
      * @see org.argouml.cognitive.ToDoListListener#toDoItemsRemoved(org.argouml.cognitive.ToDoListEvent)
 141  
      */
 142  
     public void toDoItemsRemoved(ToDoListEvent tde) {
 143  0
         LOG.debug("toDoItemAdded");
 144  0
         Object[] path = new Object[2];
 145  0
         path[0] = Designer.theDesigner().getToDoList();
 146  
 
 147  0
         for (Goal g : Designer.theDesigner().getGoalList()) {
 148  0
             LOG.debug("toDoItemRemoved updating decision node!");
 149  0
             boolean anyInGoal = false;
 150  0
             for (ToDoItem item : tde.getToDoItemList()) {
 151  0
                 if (item.supports(g)) anyInGoal = true;
 152  
             }
 153  0
             if (!anyInGoal) continue;
 154  0
             path[1] = g;
 155  
             //fireTreeNodesChanged(this, path, childIndices, children);
 156  0
             fireTreeStructureChanged(path);
 157  0
         }
 158  0
     }
 159  
 
 160  
     /*
 161  
      * @see org.argouml.cognitive.ToDoListListener#toDoListChanged(org.argouml.cognitive.ToDoListEvent)
 162  
      */
 163  0
     public void toDoListChanged(ToDoListEvent tde) { }
 164  
 
 165  
 
 166  
 }
 167  
 
 168