View Javadoc

1   // $Id: SimilarTypeFinderCommand.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.actions;
19  
20  import java.beans.PropertyChangeEvent;
21  import java.beans.PropertyChangeListener;
22  import java.util.Map;
23  import java.util.concurrent.ExecutionException;
24  
25  import javax.swing.JFrame;
26  
27  import org.apache.xerces.xs.XSModel;
28  import org.apache.xerces.xs.XSObjectList;
29  import org.springframework.richclient.application.Application;
30  import org.springframework.richclient.command.support.ApplicationWindowAwareCommand;
31  
32  import de.mindcrimeilab.swing.util.VisualProgressWorker;
33  import de.mindcrimeilab.xsanalyzer.SimilarTypeFinderWorker;
34  import de.mindcrimeilab.xsanalyzer.XsModelWalker;
35  import de.mindcrimeilab.xsanalyzer.model.XsAnalyzerApplicationModel;
36  
37  /**
38   * @author Michael Engelhardt<me@mindcrime-ilab.de>
39   * @author $Author: agony $
40   * @version $Revision: 165 $
41   * 
42   */
43  public class SimilarTypeFinderCommand extends ApplicationWindowAwareCommand {
44  
45      private static final String ID = "similarTypeFinderCommand";
46  
47      public SimilarTypeFinderCommand() {
48          super(SimilarTypeFinderCommand.ID);
49      }
50  
51      /*
52       * (non-Javadoc)
53       * 
54       * @see org.springframework.richclient.command.ActionCommand#doExecuteCommand()
55       */
56      @Override
57      protected void doExecuteCommand() {
58          final XsAnalyzerApplicationModel model = (XsAnalyzerApplicationModel) Application.instance().getApplicationContext().getBean("applicationModel");
59          final JFrame parent = Application.instance().getActiveWindow().getControl();
60          final VisualProgressWorker<Map<String, ? extends XSObjectList>, Map.Entry<String, ? extends XSObjectList>> worker = new VisualProgressWorker<Map<String, ? extends XSObjectList>, Map.Entry<String, ? extends XSObjectList>>(parent) {
61  
62              @Override
63              protected Map<String, ? extends XSObjectList> doInBackground() throws Exception {
64                  final XSModel xsmodel = model.getSchemaModel();
65  
66                  final PropertyChangeListener changeListener = new PropertyChangeListener() {
67  
68                      @Override
69                      public void propertyChange(PropertyChangeEvent evt) {
70                          setDetailMessage("Examining type:" + evt.getNewValue());
71                      }
72  
73                  };
74  
75                  final SimilarTypeFinderWorker similarTypeFinder = new SimilarTypeFinderWorker();
76                  final XsModelWalker walker = new XsModelWalker();
77                  walker.addPropertyChangeListener(changeListener);
78                  walker.addWorker(similarTypeFinder);
79                  walker.walkModel(xsmodel);
80  
81                  return similarTypeFinder.getSimilarTypes();
82              }
83  
84              @SuppressWarnings("unchecked")
85              @Override
86              protected void done() {
87                  try {
88                      model.setSimilarTypes((Map<String, XSObjectList>) get());
89                      Application.instance().getActiveWindow().getPage().showView("similarTypesView");
90                      Application.instance().getApplicationContext().publishEvent(new XsAnalyzerApplicationEvent(EventType.SIMILAR_TYPES, this));
91                  }
92                  catch (InterruptedException e) {
93                      // TODO Auto-generated catch block
94                      e.printStackTrace();
95                  }
96                  catch (ExecutionException e) {
97                      // TODO Auto-generated catch block
98                      e.printStackTrace();
99                  }
100                 finally {
101                     // parent.showSimilarTypePanel();
102                     super.done();
103                 }
104             }
105 
106         };
107         worker.setTitle("Operation in progress...");
108         worker.setActionText("Searching for similar type definitions");
109         worker.showProgressDialog();
110         worker.execute();
111 
112     }
113 }