View Javadoc

1   // $Id: NamespaceToolWindow.java 165 2009-05-28 21:46:38Z agony $
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;
19  
20  import java.awt.BorderLayout;
21  
22  import javax.swing.JComponent;
23  import javax.swing.JList;
24  import javax.swing.JPanel;
25  import javax.swing.ScrollPaneConstants;
26  
27  import org.springframework.context.ApplicationEvent;
28  import org.springframework.context.ApplicationListener;
29  import org.springframework.richclient.application.support.AbstractView;
30  
31  import de.mindcrimeilab.xsanalyzer.actions.XsAnalyzerApplicationEvent;
32  import de.mindcrimeilab.xsanalyzer.model.NamespacesListModel;
33  import de.mindcrimeilab.xsanalyzer.model.XsAnalyzerApplicationModel;
34  import de.mindcrimeilab.xsanalyzer.ui.renderer.NamespaceItemRenderer;
35  
36  /**
37   * @author Michael Engelhardt<me@mindcrime-ilab.de>
38   * @author $Author: agony $
39   * @version $Revision: 165 $
40   * 
41   */
42  public class NamespaceToolWindow extends AbstractView implements ApplicationListener {
43  
44      private JList jlNamespaces;
45  
46      private XsAnalyzerApplicationModel model;
47  
48      /**
49       * @return the model
50       */
51      public XsAnalyzerApplicationModel getModel() {
52          return model;
53      }
54  
55      /**
56       * @param model
57       *            the model to set
58       */
59      public void setModel(XsAnalyzerApplicationModel model) {
60          this.model = model;
61          if (null != this.model && null != jlNamespaces) {
62              jlNamespaces.setModel(new NamespacesListModel(model.getSchemaModel()));
63          }
64      }
65  
66      /*
67       * (non-Javadoc)
68       * 
69       * @see org.springframework.richclient.application.support.AbstractView#createControl ()
70       */
71      @Override
72      protected JComponent createControl() {
73          createList();
74          JPanel jpNamespaces = getComponentFactory().createPanel(new BorderLayout());
75          jpNamespaces.add(getComponentFactory().createScrollPane(jlNamespaces, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED), BorderLayout.CENTER);
76          return jpNamespaces;
77      }
78  
79      @Override
80      public void onApplicationEvent(ApplicationEvent event) {
81          logger.debug(event);
82          if (event instanceof XsAnalyzerApplicationEvent) {
83              switch (((XsAnalyzerApplicationEvent) event).getEventType()) {
84                  case OPEN:
85                      jlNamespaces.setModel(new NamespacesListModel(model.getSchemaModel()));
86                      break;
87              }
88          }
89  
90      }
91  
92      private void createList() {
93          jlNamespaces = getComponentFactory().createList();
94          jlNamespaces.setCellRenderer(new NamespaceItemRenderer());
95      }
96  }