View Javadoc

1   /*
2    * $Id: FeaturesPanel.java,v 1.14 2007/06/19 19:29:03 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) 2002 - 2006 the Initial Developer. 
17   * All Rights Reserved.
18   *
19   * Contributor(s): Edwin Dankert <edankert@gmail.com>
20   */
21  
22  package org.xmlhammer.gui.preferences;
23  
24  import java.util.ArrayList;
25  import java.util.List;
26  
27  import javax.swing.JFrame;
28  import javax.swing.table.DefaultTableModel;
29  
30  import org.xmlhammer.model.jaxp.Feature;
31  
32  /***
33   * The Features Panel ...
34   *
35   * @version $Revision: 1.14 $, $Date: 2007/06/19 19:29:03 $
36   * @author Edwin Dankert <edankert@gmail.com>
37   */
38  public class FeaturesPanel extends PreferencesTablePanel {
39  	private static final long serialVersionUID = -1094787963319902492L;
40  
41  	public FeaturesPanel(JFrame parent, String name, String helpID) {
42  		this(parent, name, helpID, false);
43  	}
44  	
45  	public FeaturesPanel(JFrame parent, String name, String helpID, boolean project) {
46  		super(parent, name, helpID, project);
47  	}
48  	
49      protected DefaultTableModel getModel() {
50          if ( model == null) {
51              model = new FeatureTableModel();
52              model.setColumnCount(3);
53              model.setColumnIdentifiers(new String[] {" ", "Name", "Value"});
54          } 
55          
56          return model;
57      }
58  	
59  	public void setFeatures( List<Feature> features) {
60  		while ( getModel().getRowCount() > 0) {
61              getModel().removeRow( 0);
62  		}
63  		
64  		for ( Feature feature : features) {
65              getModel().addRow(new Object[] {feature.isActive(), feature.getName(), Boolean.toString(feature.isEnabled())});
66  		}
67  	}
68  	
69  	public List<Feature> getFeatures() {
70  		List<Feature> features = new ArrayList<Feature>();
71  
72  		for ( int i = 0; i < getModel().getRowCount(); i++) {
73  			Feature feature = new Feature();
74  			feature.setName((String)getModel().getValueAt(i, 1));
75  			feature.setEnabled(Boolean.parseBoolean((String)getModel().getValueAt(i, 2)));
76              feature.setActive((Boolean)getModel().getValueAt( i, 0));
77  			
78  			features.add( feature);
79  		}
80  		
81  		return features;
82  	}
83  
84      protected int[] getColumnWidths() {
85          return new int[] {25, 975, 50};
86      }
87  
88      protected Object[] getDefaultRowContent() {
89          return new Object[] {Boolean.TRUE, "New Feature", Boolean.toString(false)};
90      }
91  
92      public class FeatureTableModel extends ActivatableTableModel {
93          private static final long serialVersionUID = 6052327715881857553L;
94  
95          @SuppressWarnings("unchecked")
96          public Class getColumnClass(int col) {
97              if (col == 2) {
98                  return Object.class;
99              }
100             
101             return super.getColumnClass(col);
102 		}
103 	}
104     
105     @Override
106     protected String getName(int row) {
107         return getModel().getValueAt(row, 1).toString();
108     }
109 }