1
2
3
4
5
6
7
8
9
10
11
12
13 package de.mindcrimeilab.xsanalyzer;
14
15 import java.util.LinkedList;
16 import java.util.List;
17 import java.util.Set;
18
19 import javax.swing.JComponent;
20
21 import org.apache.xerces.impl.xs.XSGroupDecl;
22 import org.apache.xerces.xs.XSElementDeclaration;
23 import org.apache.xerces.xs.XSModel;
24 import org.apache.xerces.xs.XSNamespaceItem;
25 import org.apache.xerces.xs.XSTypeDefinition;
26 import org.jfree.chart.ChartFactory;
27 import org.jfree.chart.ChartPanel;
28 import org.jfree.chart.JFreeChart;
29 import org.springframework.binding.value.ValueModel;
30 import org.springframework.binding.value.support.ValueHolder;
31 import org.springframework.context.ApplicationEvent;
32 import org.springframework.context.ApplicationListener;
33 import org.springframework.richclient.application.support.AbstractView;
34 import org.springframework.richclient.factory.ComponentFactory;
35 import org.springframework.richclient.layout.GridBagLayoutBuilder;
36
37 import de.mindcrimeilab.xsanalyzer.actions.XsAnalyzerApplicationEvent;
38 import de.mindcrimeilab.xsanalyzer.model.PieDatasetValueModel;
39 import de.mindcrimeilab.xsanalyzer.model.XsAnalyzerApplicationModel;
40 import de.mindcrimeilab.xsanalyzer.util.XSModelHelper;
41
42
43
44
45
46
47
48
49 public class SchemaInfoView extends AbstractView implements ApplicationListener {
50
51 private XsAnalyzerApplicationModel model;
52
53 private final ValueModel numComplexTypes = new ValueHolder(0);
54
55 private final ValueModel numSimpleTypes = new ValueHolder(0);
56
57 private final ValueModel numElements = new ValueHolder(0);
58
59 private final ValueModel numGroups = new ValueHolder(0);
60
61 private final ValueModel targetNamespace = new ValueHolder(getMessage("No schema loaded."));
62
63 private JFreeChart schemaElementsChart;
64
65 private ChartPanel cpSchemaElements;
66
67
68
69
70 public XsAnalyzerApplicationModel getModel() {
71 return model;
72 }
73
74
75
76
77
78 public void setModel(XsAnalyzerApplicationModel model) {
79 this.model = model;
80 if (null != this.model.getSchemaModel()) {
81 update();
82 }
83 }
84
85
86
87
88 private void update() {
89 XSModel xsModel = model.getSchemaModel();
90 if (null != xsModel) {
91 final List<XSNamespaceItem> namespaces = new LinkedList<XSNamespaceItem>();
92 final XSNamespaceItem tns = model.getTargetNamespace();
93 org.springframework.util.Assert.notNull(tns);
94 namespaces.add(tns);
95 targetNamespace.setValue(tns.getSchemaNamespace());
96 Set<? extends XSTypeDefinition> ctypes = XSModelHelper.getComponents(xsModel, namespaces, new short[] { XSTypeDefinition.COMPLEX_TYPE});
97 numComplexTypes.setValue(ctypes.size());
98 Set<? extends XSTypeDefinition> stypes = XSModelHelper.getComponents(xsModel, namespaces, new short[] { XSTypeDefinition.SIMPLE_TYPE});
99 numSimpleTypes.setValue(stypes.size());
100 List<XSElementDeclaration> elements = XSModelHelper.getElements(xsModel, namespaces);
101 numElements.setValue(elements.size());
102 List<? extends XSGroupDecl> groups = XSModelHelper.getGroups(xsModel, namespaces);
103 numGroups.setValue(groups.size());
104 }
105 }
106
107
108
109
110
111 @Override
112 protected JComponent createControl() {
113 createSchemaElementsChart();
114 GridBagLayoutBuilder builder = new GridBagLayoutBuilder();
115
116 final ComponentFactory cf = getComponentFactory();
117 builder.append(cf.createTitleLabel("schemaInfoView.titleLabel"), 1, 1, true, false).nextLine();
118 builder.append(cf.createLabel("schemaInfoView.schema.targetNamespace", new ValueModel[] { targetNamespace}), 1, 1, true, false).nextLine();
119
120 builder.append(cpSchemaElements, 1, 1, true, true);
121 return builder.getPanel();
122 }
123
124 public void onApplicationEvent(ApplicationEvent event) {
125 if (event instanceof XsAnalyzerApplicationEvent) {
126 switch (((XsAnalyzerApplicationEvent) event).getEventType()) {
127 case OPEN:
128 update();
129 break;
130 }
131 }
132 }
133
134 private void createSchemaElementsChart() {
135 PieDatasetValueModel<String> pieDataset = new PieDatasetValueModel<String>();
136 pieDataset.setValue(getMessage("schemaInfoView.schema.numberOfComplexTypes"), numComplexTypes);
137 pieDataset.setValue(getMessage("schemaInfoView.schema.numberOfSimpleTypes"), numSimpleTypes);
138 pieDataset.setValue(getMessage("schemaInfoView.schema.numberOfGroups"), numGroups);
139 pieDataset.setValue(getMessage("schemaInfoView.schema.numberOfElements"), numElements);
140
141 schemaElementsChart = ChartFactory.createPieChart(getMessage("schemaInfoView.sectionLabel"), pieDataset, false, true, false);
142 cpSchemaElements = new ChartPanel(schemaElementsChart, true);
143 }
144 }