Coverage Report - org.argouml.uml.ui.SourcePathTableModel
 
Classes in this File Line Coverage Branch Coverage Complexity
SourcePathTableModel
0%
0/38
0%
0/18
2.333
 
 1  
 /* $Id: SourcePathTableModel.java 17881 2010-01-12 21:09:28Z 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  
  *    mvw
 11  
  *****************************************************************************
 12  
  *
 13  
  * Some portions of this file was previously release using the BSD License:
 14  
  */
 15  
 
 16  
 // Copyright (c) 2004-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.ui;
 40  
 
 41  
 import java.io.File;
 42  
 import java.util.Collection;
 43  
 import java.util.Iterator;
 44  
 
 45  
 import javax.swing.table.DefaultTableModel;
 46  
 
 47  
 import org.apache.log4j.Logger;
 48  
 import org.argouml.i18n.Translator;
 49  
 import org.argouml.model.Model;
 50  
 
 51  
 /**
 52  
  * The table model for source path settings. This class contains functionality
 53  
  * to load the source path settings from the model.
 54  
  */
 55  
 class SourcePathTableModel extends DefaultTableModel {
 56  
 
 57  
     /**
 58  
      * Index of the column where model element objects are placed.
 59  
      */
 60  
     static final int MODEL_ELEMENT_COLUMN = 0;
 61  
     /**
 62  
      * Index of the column where the model element names are placed.
 63  
      */
 64  
     static final int NAME_COLUMN = 1;
 65  
     /**
 66  
      * Index of the column where the types of the model elements are placed.
 67  
      */
 68  
     static final int TYPE_COLUMN = 2;
 69  
     /**
 70  
      * Index of the column where the source paths for the model elements are
 71  
      * placed.
 72  
      */
 73  
     static final int SOURCE_PATH_COLUMN = 3;
 74  
 
 75  
     /**
 76  
      * Logger.
 77  
      */
 78  0
     private static final Logger LOG =
 79  
         Logger.getLogger(SourcePathTableModel.class);
 80  
 
 81  
     /**
 82  
      * Creates a new instance of SourcePathTableModel.
 83  
      */
 84  
     public SourcePathTableModel(SourcePathController srcPathCtrl) {
 85  0
         super(new Object[][] {
 86  
         }, new String[] {
 87  
             " ", Translator.localize("misc.name"),
 88  
             Translator.localize("misc.type"),
 89  
             Translator.localize("misc.source-path"),
 90  
         });
 91  0
         String strModel = Translator.localize("misc.model");
 92  0
         String strPackage = Translator.localize("misc.package");
 93  0
         String strClass = Translator.localize("misc.class");
 94  0
         String strInterface = Translator.localize("misc.interface");
 95  
 
 96  0
         Collection elems = srcPathCtrl.getAllModelElementsWithSourcePath();
 97  
 
 98  0
         Iterator iter = elems.iterator();
 99  0
         while (iter.hasNext()) {
 100  0
             Object me = iter.next();
 101  0
             File path = srcPathCtrl.getSourcePath(me);
 102  0
             if (path != null) {
 103  0
                 String type = "";
 104  0
                 String name = Model.getFacade().getName(me);
 105  0
                 if (Model.getFacade().isAModel(me)) {
 106  0
                     type = strModel;
 107  0
                 } else if (Model.getFacade().isAPackage(me)) {
 108  0
                     type = strPackage;
 109  0
                     Object parent = Model.getFacade().getNamespace(me);
 110  0
                     while (parent != null) {
 111  
                         // ommit root package name; it's the model's root
 112  0
                         if (Model.getFacade().getNamespace(parent) != null) {
 113  0
                             name =
 114  
                                 Model.getFacade().getName(parent) + "." + name;
 115  
                         }
 116  0
                         parent = Model.getFacade().getNamespace(parent);
 117  
                     }
 118  0
                 } else if (Model.getFacade().isAClass(me)) {
 119  0
                     type = strClass;
 120  0
                 } else if (Model.getFacade().isAInterface(me)) {
 121  0
                     type = strInterface;
 122  
                 } else {
 123  0
                     LOG.warn("Can't assign a type to this model element: "
 124  
                             + me);
 125  
                 }
 126  0
                 addRow(new Object[] {
 127  
                     me, name, type, path.toString(),
 128  
                 });
 129  0
             } else {
 130  0
                 LOG.warn("Unexpected: the source path for " + me + " is null!");
 131  
             }
 132  0
         }
 133  0
     }
 134  
 
 135  
     /**
 136  
      * The only editable cells are the ones in the source path column.
 137  
      * @see javax.swing.table.DefaultTableModel#isCellEditable(int, int)
 138  
      */
 139  
     public boolean isCellEditable(int rowIndex, int columnIndex) {
 140  0
         return columnIndex == SOURCE_PATH_COLUMN;
 141  
     }
 142  
 
 143  
     /**
 144  
      * For the specified row, get the model element (ME).
 145  
      * @param rowIndex the row index where the ME data is located
 146  
      * @return the ME
 147  
      */
 148  
     public Object getModelElement(int rowIndex) {
 149  0
         return getValueAt(rowIndex, MODEL_ELEMENT_COLUMN);
 150  
     }
 151  
 
 152  
     /**
 153  
      * For the specified row, get the model element (ME) name.
 154  
      * @param rowIndex the row index where the ME data is located
 155  
      * @return the ME name
 156  
      */
 157  
     public String getMEName(int rowIndex) {
 158  0
         return (String) getValueAt(rowIndex, NAME_COLUMN);
 159  
     }
 160  
 
 161  
     /**
 162  
      * For the specified row, get the ME type.
 163  
      * @param rowIndex the row index where the ME data is located
 164  
      * @return the String representation of the ME type
 165  
      */
 166  
     public String getMEType(int rowIndex) {
 167  0
         return (String) getValueAt(rowIndex, TYPE_COLUMN);
 168  
     }
 169  
 
 170  
     /**
 171  
      * For the specified row get the, get the source path.
 172  
      * @param rowIndex the row index where the ME data is located
 173  
      * @return the String representation of the ME source path
 174  
      */
 175  
     public String getMESourcePath(int rowIndex) {
 176  0
         return (String) getValueAt(rowIndex, SOURCE_PATH_COLUMN);
 177  
     }
 178  
 }