Coverage Report - org.argouml.uml.TMResults
 
Classes in this File Line Coverage Branch Coverage Complexity
TMResults
0%
0/63
0%
0/53
5.727
 
 1  
 /* $Id: TMResults.java 17846 2010-01-12 19:37:12Z 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  
  *    tfmorris
 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.uml;
 40  
 
 41  
 import java.util.List;
 42  
 
 43  
 import javax.swing.table.AbstractTableModel;
 44  
 
 45  
 import org.argouml.i18n.Translator;
 46  
 import org.argouml.model.Model;
 47  
 import org.argouml.uml.diagram.ui.UMLDiagram;
 48  
 import org.tigris.gef.base.Diagram;
 49  
 
 50  
 /**
 51  
  * TMResults (Table Model Results) implements a default table model
 52  
  * which is used by Find and Goto Operations in order to display search
 53  
  * results. It defines a default table model with columns and can
 54  
  * resolve found objects to strings.
 55  
  */
 56  
 public class TMResults extends AbstractTableModel {
 57  
 
 58  
     private List rowObjects;
 59  
     private List<UMLDiagram> diagrams;
 60  
     private boolean showInDiagramColumn;
 61  
 
 62  
     /**
 63  
      * The constructor.
 64  
      *
 65  
      */
 66  0
     public TMResults() {
 67  0
         showInDiagramColumn = true;
 68  0
     }
 69  
 
 70  
     /**
 71  
      * The constructor.
 72  
      *
 73  
      * @param showTheInDiagramColumn true if the "In Diagram" column
 74  
      *                               should be shown
 75  
      */
 76  0
     public TMResults(boolean showTheInDiagramColumn) {
 77  0
         showInDiagramColumn = showTheInDiagramColumn;
 78  0
     }
 79  
 
 80  
     /**
 81  
      * @param results the row objects
 82  
      * @param theDiagrams the diagrams
 83  
      */
 84  
     public void setTarget(List results, List theDiagrams) {
 85  0
         rowObjects = results;
 86  0
         diagrams = theDiagrams;
 87  0
         fireTableStructureChanged();
 88  0
     }
 89  
     
 90  
     ////////////////
 91  
     // TableModel implementation
 92  
 
 93  
     /*
 94  
      * @see javax.swing.table.TableModel#getColumnCount()
 95  
      */
 96  
     public int getColumnCount() {
 97  0
         return showInDiagramColumn ? 4 : 3;
 98  
     }
 99  
 
 100  
     /*
 101  
      * @see javax.swing.table.TableModel#getRowCount()
 102  
      */
 103  
     public int getRowCount() {
 104  0
         if (rowObjects == null) {
 105  0
             return 0;
 106  
         }
 107  0
         return rowObjects.size();
 108  
     }
 109  
 
 110  
     /*
 111  
      * @see javax.swing.table.TableModel#getColumnName(int)
 112  
      */
 113  
     public String getColumnName(int c) {
 114  0
         if (c == 0) {
 115  0
             return Translator.localize("dialog.find.column-name.type");
 116  
         }
 117  0
         if (c == 1) {
 118  0
             return Translator.localize("dialog.find.column-name.name");
 119  
         }
 120  0
         if (c == 2) {
 121  0
             return Translator.localize(showInDiagramColumn
 122  
                     ? "dialog.find.column-name.in-diagram"
 123  
                     : "dialog.find.column-name.description");
 124  
         }
 125  0
         if (c == 3) {
 126  0
             return Translator.localize("dialog.find.column-name.description");
 127  
         }
 128  0
         return "XXX";
 129  
     }
 130  
 
 131  
     /*
 132  
      * @see javax.swing.table.TableModel#getColumnClass(int)
 133  
      */
 134  
     public Class getColumnClass(int c) {
 135  0
         return String.class;
 136  
     }
 137  
 
 138  
     /*
 139  
      * @see javax.swing.table.TableModel#isCellEditable(int, int)
 140  
      */
 141  
     public boolean isCellEditable(int row, int col) {
 142  0
         return false;
 143  
     }
 144  
 
 145  
     /*
 146  
      * @see javax.swing.table.TableModel#getValueAt(int, int)
 147  
      */
 148  
     public Object getValueAt(int row, int col) {
 149  0
         if (row < 0 || row >= rowObjects.size()) {
 150  0
             return "bad row!";
 151  
         }
 152  0
         if (col < 0 || col >= (showInDiagramColumn ? 4 : 3)) {
 153  0
             return "bad col!";
 154  
         }
 155  0
         Object rowObj = rowObjects.get(row);
 156  0
         if (rowObj instanceof Diagram) {
 157  0
             Diagram d = (Diagram) rowObj;
 158  0
             switch (col) {
 159  
             case 0 : // the name of this type of diagram
 160  0
                 if (d instanceof UMLDiagram) {
 161  0
                     return ((UMLDiagram) d).getLabelName();
 162  
                 }
 163  0
                 return null;
 164  
             case 1 : // the name of this instance of diagram
 165  0
                 return d.getName();
 166  
             case 2 : // "N/A" or "x nodes and x edges"
 167  0
                 return showInDiagramColumn
 168  
                     ? Translator.localize("dialog.find.not-applicable")
 169  
                     : countNodesAndEdges(d);
 170  
             case 3 : // "x nodes and x edges"
 171  0
                 return countNodesAndEdges(d);
 172  
             default:
 173  
             }
 174  
         }
 175  0
         if (Model.getFacade().isAModelElement(rowObj)) {
 176  0
             Diagram d = null;
 177  0
             if (diagrams != null) {
 178  0
                 d = diagrams.get(row);
 179  
             }
 180  0
             switch (col) {
 181  
             case 0 : // the name of this type of ModelElement
 182  0
                 return Model.getFacade().getUMLClassName(rowObj);
 183  
             case 1 : // the name of this instance of ModelElement
 184  0
                 return Model.getFacade().getName(rowObj);
 185  
             case 2 : // the name of the parent diagram instance
 186  0
                 return (d == null)
 187  
                     ? Translator.localize("dialog.find.not-applicable")
 188  
                     : d.getName();
 189  
             case 3 : // TODO: implement this - show some documentation?
 190  0
                 return "docs";
 191  
             default:
 192  
             }
 193  
         }
 194  0
         switch (col) {
 195  
         case 0 : // the name of this type of Object
 196  0
             if (rowObj == null) {
 197  0
                 return "";
 198  
             }
 199  0
             String clsName = rowObj.getClass().getName();
 200  0
             int lastDot = clsName.lastIndexOf(".");
 201  0
             return clsName.substring(lastDot + 1);
 202  
         case 1 :
 203  0
             return "";
 204  
         case 2 :
 205  0
             return "??";
 206  
         case 3 :
 207  0
             return "docs";
 208  
         default:
 209  
         }
 210  0
         return "unknown!";
 211  
     }
 212  
 
 213  
     /**
 214  
      * @param d the diagram to count the nodes and edges of
 215  
      * @return a string which says it all
 216  
      */
 217  
     private Object countNodesAndEdges(Diagram d) {
 218  0
         int numNodes = d.getNodes().size();
 219  0
         int numEdges = d.getEdges().size();
 220  0
         Object[] msgArgs = {Integer.valueOf(numNodes),
 221  
                             Integer.valueOf(numEdges),
 222  
         };
 223  0
         return Translator.messageFormat("dialog.nodes-and-edges", msgArgs);
 224  
     }
 225  
 
 226  
     /*
 227  
      * @see javax.swing.table.TableModel#setValueAt(java.lang.Object, int, int)
 228  
      */
 229  
     @Override
 230  
     public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
 231  0
     }
 232  
 
 233  
     /**
 234  
      * The UID.
 235  
      */
 236  
     private static final long serialVersionUID = -1444599676429024575L;
 237  
 }