View Javadoc

1   // $Id:UnusedTypesListModelAdapter.java 12 2008-02-18 23:04:22Z Michael Engelhardt $
2   /*
3    * xsAnalyzer - XML schema analyzing tool. Copyright (C) 2008 Michael Engelhardt
4    * 
5    * This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public
6    * License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later
7    * version.
8    * 
9    * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
10   * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
11   * 
12   * You should have received a copy of the GNU General Public License along with this program; if not, write to the Free
13   * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
14   */
15  /**
16   * 
17   */
18  package de.mindcrimeilab.xsanalyzer.model;
19  
20  import java.util.ArrayList;
21  import java.util.Collections;
22  import java.util.List;
23  import java.util.Set;
24  
25  import javax.swing.AbstractListModel;
26  import javax.swing.ListModel;
27  
28  import org.apache.xerces.xs.XSTypeDefinition;
29  
30  import de.mindcrimeilab.util.CollectionsHelper;
31  import de.mindcrimeilab.xsanalyzer.util.NameComparator;
32  
33  /**
34   * @author Michael Engelhardt<me@mindcrime-ilab.de>
35   * @author $Author:Michael Engelhardt $
36   * @version $Revision:12 $
37   * 
38   */
39  public class UnusedTypesListModelAdapter extends AbstractListModel implements ListModel {
40  
41      private final List<XSTypeDefinition> unusedTypes;
42  
43      public UnusedTypesListModelAdapter(Set<XSTypeDefinition> unusedTypes) {
44          this.unusedTypes = new ArrayList<XSTypeDefinition>(unusedTypes);
45          NamespaceFilter filter = new NamespaceFilter();
46          filter.addNamespace("http://www.w3.org/2001/XMLSchema");
47          CollectionsHelper.filterCollection(this.unusedTypes, filter);
48          Collections.sort(this.unusedTypes, new NameComparator());
49      }
50  
51      /*
52       * (non-Javadoc)
53       * 
54       * @see javax.swing.ListModel#getElementAt(int)
55       */
56      @Override
57      public Object getElementAt(int index) {
58          return unusedTypes.get(index);
59      }
60  
61      /*
62       * (non-Javadoc)
63       * 
64       * @see javax.swing.ListModel#getSize()
65       */
66      @Override
67      public int getSize() {
68          return unusedTypes.size();
69      }
70  
71  }