Coverage Report - org.argouml.cognitive.ui.ToDoByDecision
 
Classes in this File Line Coverage Branch Coverage Complexity
ToDoByDecision
5%
4/71
0%
0/32
4.2
 
 1  
 /* $Id: ToDoByDecision.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.Decision;
 45  
 import org.argouml.cognitive.Designer;
 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 decision type.
 52  
  */
 53  
 public class ToDoByDecision extends ToDoPerspective
 54  
     implements ToDoListListener {
 55  900
     private static final Logger LOG =
 56  
         Logger.getLogger(ToDoByDecision.class);
 57  
 
 58  
 
 59  
     /**
 60  
      * The constructor.
 61  
      *
 62  
      */
 63  
     public ToDoByDecision() {
 64  900
         super("combobox.todo-perspective-decision");
 65  900
         addSubTreeModel(new GoListToDecisionsToItems());
 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("toDoItemChanged");
 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 (Decision dec : Designer.theDesigner().getDecisionModel()
 81  
                 .getDecisionList()) {
 82  0
             int nMatchingItems = 0;
 83  0
             path[1] = dec;
 84  0
             for (ToDoItem item : items) {
 85  0
                 if (!item.supports(dec)) {
 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.supports(dec)) {
 98  0
                     continue;
 99  
                 }
 100  0
                 childIndices[nMatchingItems] = getIndexOfChild(dec, 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 (Decision dec : Designer.theDesigner().getDecisionModel()
 118  
                 .getDecisionList()) {
 119  0
             int nMatchingItems = 0;
 120  0
             path[1] = dec;
 121  0
             for (ToDoItem item : items) {
 122  0
                 if (!item.supports(dec)) {
 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.supports(dec)) {
 135  0
                     continue;
 136  
                 }
 137  0
                 childIndices[nMatchingItems] = getIndexOfChild(dec, 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 (Decision dec : Designer.theDesigner().getDecisionModel()
 155  
                 .getDecisionList()) {
 156  0
             LOG.debug("toDoItemRemoved updating decision node!");
 157  0
             boolean anyInDec = false;
 158  0
             for (ToDoItem item : items) {
 159  0
                 if (item.supports(dec)) {
 160  0
                     anyInDec = true;
 161  
                 }
 162  
             }
 163  0
             if (!anyInDec) {
 164  0
                 continue;
 165  
             }
 166  0
             path[1] = dec;
 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  
     //   public static Decision decisionUNCATEGORIZED =
 179  
     //   new Decision("Uncategorized", 1);
 180  
 
 181  
     //   protected boolean isNeeded(ToDoPseudoNode node) {
 182  
     //     PredicateDecision pd = (PredicateDecision) node.getPredicate();
 183  
     //     Decision d = pd.getDecision();
 184  
     //     Enumeration items = _root.elements();
 185  
     //     while (items.hasMoreElements()) {
 186  
     //       ToDoItem item = (ToDoItem) items.nextElement();
 187  
     //       if (item.getPoster().supports(d)) return true;
 188  
     //     }
 189  
     //     return false;
 190  
     //   }
 191  
 
 192  
     //   protected Vector addNewPseudoNodes(ToDoItem item) {
 193  
     //     Vector newNodes = new Vector();
 194  
     //     Vector decs = item.getPoster().getSupportedDecisions();
 195  
     //     if (decs == null) {
 196  
     //       addNodeIfNeeded(Decision.UNSPEC, newNodes);
 197  
     //     }
 198  
     //     else {
 199  
     //       Enumeration elems = decs.elements();
 200  
     //       while (elems.hasMoreElements()) {
 201  
     //         Decision itemDec = (Decision) elems.nextElement();
 202  
     //         addNodeIfNeeded(itemDec, newNodes);
 203  
     //       }
 204  
     //     }
 205  
     //     return newNodes;
 206  
     //   }
 207  
 
 208  
 
 209  
     //   protected void addNodeIfNeeded(Decision itemDec, Vector newNodes) {
 210  
     //     Enumeration elems = _pseudoNodes.elements();
 211  
     //     while (elems.hasMoreElements()) {
 212  
     //       ToDoPseudoNode node = (ToDoPseudoNode) elems.nextElement();
 213  
     //       PredicateDecision pd = (PredicateDecision) node.getPredicate();
 214  
     //       Decision nodeDec = pd.getDecision();
 215  
     //       //if (nodeDec.getName().equals(itemDec.getName())) return;
 216  
     //       if (nodeDec == itemDec) return;
 217  
     //     }
 218  
     //     PredicateDecision pred = new PredicateDecision(itemDec);
 219  
     //     ToDoPseudoNode newNode = new ToDoPseudoNode(_root, pred);
 220  
     //     newNode.setLabel(itemDec.getName());
 221  
     //     _pseudoNodes.addElement(newNode);
 222  
     //     newNodes.addElement(newNode);
 223  
     //   }
 224  
 
 225  
 } /* end class ToDoByDecision */
 226  
 
 227