1
2
3
4
5
6
7
8
9
10
11
12
13
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
39
40
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
53
54
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
94 e.printStackTrace();
95 }
96 catch (ExecutionException e) {
97
98 e.printStackTrace();
99 }
100 finally {
101
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 }