Coverage Report - org.argouml.moduleloader.SettingsTabModules
 
Classes in this File Line Coverage Branch Coverage Complexity
SettingsTabModules
81%
31/38
37%
3/8
1.8
SettingsTabModules$ModuleTableModel
50%
10/20
18%
2/11
1.8
 
 1  
 /* $Id: SettingsTabModules.java 17824 2010-01-12 18:48:34Z 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-2007 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.moduleloader;
 40  
 
 41  
 import java.awt.BorderLayout;
 42  
 import java.util.Iterator;
 43  
 import java.util.List;
 44  
 
 45  
 import javax.swing.JLabel;
 46  
 import javax.swing.JPanel;
 47  
 import javax.swing.JScrollPane;
 48  
 import javax.swing.JTable;
 49  
 import javax.swing.JTextField;
 50  
 import javax.swing.table.AbstractTableModel;
 51  
 
 52  
 import org.argouml.application.api.GUISettingsTabInterface;
 53  
 import org.argouml.i18n.Translator;
 54  
 import org.tigris.swidgets.LabelledLayout;
 55  
 
 56  
 /**
 57  
  * Tab for the settings dialog that makes it possible to
 58  
  * select the modules that are to be enabled.
 59  
  *
 60  
  * TODO: Header for the table.
 61  
  *
 62  
  * @author Linus Tolke
 63  
  */
 64  1209
 class SettingsTabModules extends JPanel
 65  
     implements GUISettingsTabInterface {
 66  
 
 67  
     /**
 68  
      * The table of modules.
 69  
      */
 70  
     private JTable table;
 71  
     
 72  
     private JTextField fieldAllExtDirs;
 73  
 
 74  
     /**
 75  
      * The names of the columns in the table.
 76  
      */
 77  900
     private String[] columnNames = {
 78  
         Translator.localize("misc.column-name.module"), 
 79  
         Translator.localize("misc.column-name.enabled"),
 80  
     };
 81  
 
 82  
     /**
 83  
      * The objects representing the modules from the new module loader.
 84  
      */
 85  
     private Object[][] elements;
 86  
 
 87  
     /**
 88  
      * The constructor.
 89  
      */
 90  900
     SettingsTabModules() {
 91  
         // The creation of the actual GUI elements is deferred until
 92  
         // they are actually needed. Otherwize we have problems
 93  
         // with the initialization.
 94  900
     }
 95  
 
 96  
     /**
 97  
      * Table model for the table with modules.
 98  
      */
 99  
     class ModuleTableModel extends AbstractTableModel {
 100  
         /**
 101  
          * Constructor.
 102  
          */
 103  38
         public ModuleTableModel() {
 104  38
             Object[] arr = ModuleLoader2.allModules().toArray();
 105  
 
 106  38
             elements = new Object[arr.length][2];
 107  
 
 108  228
             for (int i = 0; i < elements.length; i++) {
 109  190
                 elements[i][0] = arr[i];
 110  190
                 elements[i][1] =
 111  
                     Boolean.valueOf(ModuleLoader2.isSelected((String) arr[i]));
 112  
             }
 113  38
         }
 114  
 
 115  
         /*
 116  
          * @see javax.swing.table.TableModel#getColumnCount()
 117  
          */
 118  
         public int getColumnCount() {
 119  114
             return columnNames.length;
 120  
         }
 121  
 
 122  
         /*
 123  
          * @see javax.swing.table.TableModel#getColumnName(int)
 124  
          */
 125  
         public String getColumnName(int col) {
 126  76
             return columnNames[col];
 127  
         }
 128  
 
 129  
         /*
 130  
          * @see javax.swing.table.TableModel#getRowCount()
 131  
          */
 132  
         public int getRowCount() {
 133  373
             return elements.length;
 134  
         }
 135  
 
 136  
         /*
 137  
          * @see javax.swing.table.TableModel#getValueAt(int, int)
 138  
          */
 139  
         public Object getValueAt(int row, int col) {
 140  0
             if (row < elements.length) {
 141  0
                 return elements[row][col];
 142  
             } else {
 143  0
                 return null;       
 144  
             }
 145  
         }
 146  
 
 147  
         /*
 148  
          * @see javax.swing.table.TableModel#setValueAt(
 149  
          *         java.lang.Object, int, int)
 150  
          */
 151  
         public void setValueAt(Object ob, int row, int col) {
 152  0
             elements[row][col] = ob;
 153  0
         }
 154  
 
 155  
         /*
 156  
          * @see javax.swing.table.TableModel#getColumnClass(int)
 157  
          */
 158  
         public Class getColumnClass(int col) {
 159  0
             switch (col) {
 160  
             case 0:
 161  0
                 return String.class;
 162  
             case 1:
 163  0
                 return Boolean.class;
 164  
             default:
 165  0
                 return null;
 166  
             }
 167  
         }
 168  
 
 169  
         /*
 170  
          * @see javax.swing.table.TableModel#isCellEditable(int, int)
 171  
          */
 172  
         public boolean isCellEditable(int row, int col) {
 173  0
             return col >= 1 && row < elements.length;
 174  
         }
 175  
 
 176  
         /**
 177  
          * The UID.
 178  
          */
 179  
         private static final long serialVersionUID = -5970280716477119863L;
 180  
     }
 181  
 
 182  
     /*
 183  
      * @see GUISettingsTabInterface#handleSettingsTabRefresh()
 184  
      */
 185  
     public void handleSettingsTabRefresh() {
 186  19
         table.setModel(new ModuleTableModel());
 187  
         
 188  19
         StringBuffer sb = new StringBuffer();
 189  19
         List locations = ModuleLoader2.getInstance().getExtensionLocations();
 190  19
         for (Iterator it = locations.iterator(); it.hasNext();) {
 191  19
             sb.append((String) it.next());
 192  19
             sb.append("\n");
 193  
         }
 194  19
         fieldAllExtDirs.setText(sb.substring(0, sb.length() - 1).toString());
 195  19
     }
 196  
 
 197  
     /*
 198  
      * @see GUISettingsTabInterface#handleSettingsTabSave()
 199  
      */
 200  
     public void handleSettingsTabSave() {
 201  0
         if (elements != null) {
 202  0
             for (int i = 0; i < elements.length; i++) {
 203  0
                 ModuleLoader2.setSelected(
 204  
                         (String) elements[i][0],
 205  
                         ((Boolean) elements[i][1]).booleanValue());
 206  
             }
 207  0
             ModuleLoader2.doLoad(false);
 208  
         }
 209  0
     }
 210  
 
 211  
     /*
 212  
      * @see GUISettingsTabInterface#handleSettingsTabCancel()
 213  
      */
 214  
     public void handleSettingsTabCancel() {
 215  
         // Do nothing!
 216  
         // The next time we refresh, we will fetch the values again.
 217  0
     }
 218  
 
 219  
     /*
 220  
      * @see GUISettingsTabInterface#getTabKey()
 221  
      */
 222  19
     public String getTabKey() { return "tab.modules"; }
 223  
 
 224  
     /*
 225  
      * @see GUISettingsTabInterface#getTabPanel()
 226  
      */
 227  
     public JPanel getTabPanel() {
 228  19
         if (table == null) {
 229  19
             setLayout(new BorderLayout());
 230  
 
 231  19
             table = new JTable(new ModuleTableModel());
 232  19
             table.setAutoResizeMode(JTable.AUTO_RESIZE_LAST_COLUMN);
 233  19
             table.setShowVerticalLines(true);
 234  19
             add(new JScrollPane(table), BorderLayout.CENTER);
 235  19
             int labelGap = 10;
 236  19
             int componentGap = 5;
 237  19
             JPanel top = new JPanel(new LabelledLayout(labelGap, componentGap));
 238  19
             JLabel label = new JLabel(
 239  
                     Translator.localize("label.extension-directories"));
 240  19
             JTextField j = new JTextField();
 241  19
             fieldAllExtDirs = j;
 242  19
             fieldAllExtDirs.setEnabled(false);
 243  19
             label.setLabelFor(fieldAllExtDirs);
 244  19
             top.add(label);
 245  19
             top.add(fieldAllExtDirs);
 246  19
             add(top, BorderLayout.NORTH);
 247  
         }
 248  
 
 249  19
         return this;
 250  
     }
 251  
 
 252  
     /**
 253  
      * The UID.
 254  
      */
 255  
     private static final long serialVersionUID = 8945027241102020504L;
 256  
 
 257  
     /*
 258  
      * @see org.argouml.ui.GUISettingsTabInterface#handleResetToDefault()
 259  
      */
 260  
     public void handleResetToDefault() {
 261  
         // Do nothing - these buttons are not shown.
 262  0
     }
 263  
 
 264  
 }