Coverage Report - org.argouml.cognitive.ui.ToDoByType
 
Classes in this File Line Coverage Branch Coverage Complexity
ToDoByType
5%
4/74
0%
0/32
4.2
 
 1  
 /* $Id: ToDoByType.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 type.
 51  
  *
 52  
  */
 53  
 public class ToDoByType extends ToDoPerspective
 54  
     implements ToDoListListener {
 55  900
     private static final Logger LOG =
 56  
         Logger.getLogger(ToDoByType.class);
 57  
 
 58  
     /**
 59  
      * The constructor.
 60  
      *
 61  
      */
 62  
     public ToDoByType() {
 63  900
         super("combobox.todo-perspective-type");
 64  900
         addSubTreeModel(new GoListToTypeToItem());
 65  900
     }
 66  
 
 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
         for (KnowledgeTypeNode ktn : KnowledgeTypeNode.getTypeList()) {
 81  0
             String kt = ktn.getName();
 82  0
             path[1] = ktn;
 83  0
             int nMatchingItems = 0;
 84  0
             for (ToDoItem item : items) {
 85  0
                 if (!item.containsKnowledgeType(kt)) {
 86  0
                     continue;
 87  
                 }
 88  0
                 nMatchingItems++;
 89  
             }
 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
             for (ToDoItem item : items) {
 97  0
                 if (!item.containsKnowledgeType(kt)) {
 98  0
                     continue;
 99  
                 }
 100  0
                 childIndices[nMatchingItems] = getIndexOfChild(ktn, item);
 101  0
                 children[nMatchingItems] = item;
 102  0
                 nMatchingItems++;
 103  
             }
 104  0
             fireTreeNodesChanged(this, path, childIndices, children);
 105  0
         }
 106  0
     }
 107  
 
 108  
     /*
 109  
      * @see org.argouml.cognitive.ToDoListListener#toDoItemsAdded(org.argouml.cognitive.ToDoListEvent)
 110  
      */
 111  
     public void toDoItemsAdded(ToDoListEvent tde) {
 112  0
         LOG.debug("toDoItemAdded");
 113  0
         List<ToDoItem> items = tde.getToDoItemList();
 114  0
         Object[] path = new Object[2];
 115  0
         path[0] = Designer.theDesigner().getToDoList();
 116  
 
 117  0
         for (KnowledgeTypeNode ktn : KnowledgeTypeNode.getTypeList()) {
 118  0
             String kt = ktn.getName();
 119  0
             path[1] = ktn;
 120  0
             int nMatchingItems = 0;
 121  0
             for (ToDoItem item : items) {
 122  0
                 if (!item.containsKnowledgeType(kt)) {
 123  0
                     continue;
 124  
                 }
 125  0
                 nMatchingItems++;
 126  
             }
 127  0
             if (nMatchingItems == 0) {
 128  0
                 continue;
 129  
             }
 130  0
             int[] childIndices = new int[nMatchingItems];
 131  0
             Object[] children = new Object[nMatchingItems];
 132  0
             nMatchingItems = 0;
 133  0
             for (ToDoItem item : items) {
 134  0
                 if (!item.containsKnowledgeType(kt)) {
 135  0
                     continue;
 136  
                 }
 137  0
                 childIndices[nMatchingItems] = getIndexOfChild(ktn, item);
 138  0
                 children[nMatchingItems] = item;
 139  0
                 nMatchingItems++;
 140  
             }
 141  0
             fireTreeNodesInserted(this, path, childIndices, children);
 142  0
         }
 143  0
     }
 144  
 
 145  
     /*
 146  
      * @see org.argouml.cognitive.ToDoListListener#toDoItemsRemoved(org.argouml.cognitive.ToDoListEvent)
 147  
      */
 148  
     public void toDoItemsRemoved(ToDoListEvent tde) {
 149  0
         LOG.debug("toDoItemRemoved");
 150  0
         List<ToDoItem> items = tde.getToDoItemList();
 151  0
         Object[] path = new Object[2];
 152  0
         path[0] = Designer.theDesigner().getToDoList();
 153  
 
 154  0
         for (KnowledgeTypeNode ktn : KnowledgeTypeNode.getTypeList()) {
 155  0
             boolean anyInKT = false;
 156  0
             String kt = ktn.getName();
 157  0
             for (ToDoItem item : items) {
 158  0
                 if (item.containsKnowledgeType(kt)) {
 159  0
                     anyInKT = true;
 160  
                 }
 161  
             }
 162  0
             if (!anyInKT) {
 163  0
                 continue;
 164  
             }
 165  0
             LOG.debug("toDoItemRemoved updating PriorityNode");
 166  0
             path[1] = ktn;
 167  
             //fireTreeNodesChanged(this, path, childIndices, children);
 168  0
             fireTreeStructureChanged(path);
 169  0
         }
 170  0
     }
 171  
 
 172  
     /*
 173  
      * @see org.argouml.cognitive.ToDoListListener#toDoListChanged(org.argouml.cognitive.ToDoListEvent)
 174  
      */
 175  0
     public void toDoListChanged(ToDoListEvent tde) { }
 176  
 
 177  
 }
 178  
 
 179