Coverage Report - org.xmlhammer.gui.overview.ComboBoxNode
 
Classes in this File Line Coverage Branch Coverage Complexity
ComboBoxNode
88% 
100% 
0
 
 1  
 /*
 2  
  * $Id: ComboBoxNode.java,v 1.7 2006/09/07 14:03:04 edankert Exp $
 3  
  *
 4  
  * The contents of this file are subject to the Mozilla Public License 
 5  
  * Version 1.1 (the "License"); you may not use this file except in 
 6  
  * compliance with the License. You may obtain a copy of the License at 
 7  
  * http://www.mozilla.org/MPL/ 
 8  
  *
 9  
  * Software distributed under the License is distributed on an "AS IS" basis, 
 10  
  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License 
 11  
  * for the specific language governing rights and limitations under the License.
 12  
  *
 13  
  * The Original Code is XML Hammer code. (org.xmlhammer.*)
 14  
  *
 15  
  * The Initial Developer of the Original Code is Edwin Dankert. Portions created 
 16  
  * by the Initial Developer are Copyright (C) 2005 - 2006 the Initial Developer. 
 17  
  * All Rights Reserved.
 18  
  *
 19  
  * Contributor(s): Edwin Dankert <edankert@gmail.com>
 20  
  */
 21  
 
 22  
 
 23  
 package org.xmlhammer.gui.overview;
 24  
 
 25  
 import java.awt.event.ItemEvent;
 26  
 import java.awt.event.ItemListener;
 27  
 import java.util.ArrayList;
 28  
 
 29  
 import javax.swing.Icon;
 30  
 import javax.swing.ImageIcon;
 31  
 import javax.swing.JComboBox;
 32  
 import javax.swing.JTextField;
 33  
 import javax.swing.event.DocumentEvent;
 34  
 import javax.swing.event.DocumentListener;
 35  
 
 36  
 import org.bounce.image.ImageLoader;
 37  
 
 38  
 
 39  
 public class ComboBoxNode implements OverviewNode, DocumentListener, ItemListener {
 40  22
     private static final ImageIcon TEXT_FIELD_ICON = ImageLoader.get().getImage( "/org/xmlhammer/gui/icons/elcl16/textfield_obj.gif");
 41  22
     private static final ImageIcon COMBO_ICON = ImageLoader.get().getImage( "/org/xmlhammer/gui/icons/elcl16/view_menu.gif");
 42  
 
 43  5280
         private ArrayList<OverviewNode> empty = new ArrayList<OverviewNode>();
 44  5280
         private JComboBox combo = null;
 45  5280
         private OverviewNode parent = null;
 46  5280
     private String label = null;
 47  5280
     private String error = null;
 48  
 
 49  5280
     public ComboBoxNode( OverviewNode parent, JComboBox combo, String label) {
 50  5280
         this.parent = parent;
 51  5280
         this.combo = combo;
 52  5280
         this.label = label;
 53  
         
 54  5280
         if ( combo.isEditable()) {
 55  4290
             ((JTextField)combo.getEditor().getEditorComponent()).getDocument().addDocumentListener( this);
 56  4290
         } else {
 57  990
             combo.addItemListener( this);
 58  
         }
 59  5280
     }
 60  
 
 61  
     public String getNodeName() {
 62  4664
         if ( combo.isEditable()) {
 63  2728
             return (String)combo.getEditor().getItem()+ " ("+label+")";
 64  
         }
 65  
         
 66  1936
         return (String)combo.getSelectedItem()+ " ("+label+")";
 67  
     }
 68  
 
 69  
     public ArrayList<OverviewNode> getChildNodes() {
 70  128014
         return empty;
 71  
     }
 72  
 
 73  
     public OverviewNode getParentNode() {
 74  10670
         return parent;
 75  
     }
 76  
 
 77  
     public Icon getNodeIcon() {
 78  4664
         if ( combo.isEditable()) {
 79  2728
             return TEXT_FIELD_ICON;
 80  
         }
 81  
         
 82  1936
         return COMBO_ICON;
 83  
     }
 84  
     
 85  
     private void nodeChanged() {
 86  1708
         OverviewNode node = parent;
 87  
         
 88  1708
         while ( node != null && !(node.getParentNode() instanceof OverviewTreeModel)) {
 89  0
             node = node.getParentNode();
 90  0
         }
 91  
         
 92  1708
         if ( node != null) {
 93  1452
             ((OverviewTreeModel)node.getParentNode()).nodeChanged( this);
 94  
         }
 95  1708
     }
 96  
 
 97  
     public void itemStateChanged(ItemEvent arg0) {
 98  1056
         nodeChanged();
 99  1056
     }
 100  
     
 101  
     public void setError(String error) {
 102  0
         this.error = error;
 103  0
     }
 104  
     
 105  
     public String getError() {
 106  106498
         return error;
 107  
     }
 108  
 
 109  
     public void insertUpdate(DocumentEvent arg0) {
 110  392
         nodeChanged();
 111  392
     }
 112  
 
 113  
     public void removeUpdate(DocumentEvent arg0) {
 114  260
         nodeChanged();
 115  260
     }
 116  
 
 117  0
     public void changedUpdate(DocumentEvent arg0) {}
 118  
 }