View Javadoc

1   package org.xmlhammer.gui.wizard;
2   
3   import java.awt.event.ItemEvent;
4   import java.awt.event.ItemListener;
5   import java.util.ArrayList;
6   import java.util.List;
7   
8   import javax.swing.ButtonGroup;
9   import javax.swing.JRadioButton;
10  import javax.swing.border.EmptyBorder;
11  
12  import org.bounce.FormLayout;
13  import org.bounce.wizard.WizardPage;
14  import org.xmlhammer.gui.util.wizard.HelpEnabledWizardPage;
15  import org.xmlhammer.model.project.Document;
16  
17  public class ValidationSelectionPage extends HelpEnabledWizardPage implements ItemListener {
18  
19      private static final long serialVersionUID = -1909903213579390495L;
20      
21      private static final String WELLFORMEDNESS   = "Checking wellformed-ness";
22      private static final String VALIDATE_INTERNAL_DTD = "Validate using internal DTD (DOCTYPE)";
23      private static final String VALIDATE_INTERNAL_XSD = "Validate using internal XSD (schemaLocation)";
24      private static final String VALIDATE_EXTERNAL_SCHEMA = "Validate using external Schema(s)";
25      private static final String VALIDATE_INTERNAL_DTD_EXTERNAL_SCHEMA = "Validate using internal DTD and external Schema(s)";
26      
27      private SchemaURIsPage schemaPage = null;
28  
29      private JRadioButton wellformednessCheck            = null;
30      private JRadioButton internalDTDCheck               = null;
31      private JRadioButton internalXSDCheck               = null;
32      private JRadioButton externalSchemaCheck            = null;
33      private JRadioButton internalDTDExternalSchemaCheck = null;
34  
35      public ValidationSelectionPage(String helpID, SchemaURIsPage schemaPage) {
36          super(new FormLayout(0, 5), helpID);
37          
38          this.schemaPage = schemaPage;
39          
40          setBorder(new EmptyBorder(20, 50, 10, 10));
41          
42          ButtonGroup group = new ButtonGroup();
43  
44          wellformednessCheck = new JRadioButton(WELLFORMEDNESS);
45          wellformednessCheck.addItemListener(this);
46          add(wellformednessCheck, FormLayout.FULL);
47          group.add(wellformednessCheck);
48  
49          internalDTDCheck = new JRadioButton(VALIDATE_INTERNAL_DTD);
50          internalDTDCheck.addItemListener(this);
51          add(internalDTDCheck, FormLayout.FULL);
52          group.add(internalDTDCheck);
53  
54          internalXSDCheck = new JRadioButton(VALIDATE_INTERNAL_XSD);
55          internalXSDCheck.addItemListener(this);
56          add(internalXSDCheck, FormLayout.FULL);
57          group.add(internalXSDCheck);
58  
59          externalSchemaCheck = new JRadioButton(VALIDATE_EXTERNAL_SCHEMA);
60          externalSchemaCheck.addItemListener(this);
61          add(externalSchemaCheck, FormLayout.FULL);
62          group.add(externalSchemaCheck);
63  
64          internalDTDExternalSchemaCheck = new JRadioButton(VALIDATE_INTERNAL_DTD_EXTERNAL_SCHEMA);
65          internalDTDExternalSchemaCheck.addItemListener(this);
66          add(internalDTDExternalSchemaCheck, FormLayout.FULL);
67          group.add(internalDTDExternalSchemaCheck);
68          
69          wellformednessCheck.setSelected(true);
70      }
71      
72      @Override
73      public String getTitle() {
74          return "Select the Validation";
75      }
76  
77      @Override
78      public String getDescription() {
79          return "Specify which type of validation should be used.";
80      }
81  
82      @Override
83      public WizardPage getNext() {
84          if (externalSchemaCheck.isSelected() || internalDTDExternalSchemaCheck.isSelected()) {
85              return schemaPage;
86          }
87          
88          return schemaPage.getNext();
89      }
90      
91      public void selectWellformedness() {
92          wellformednessCheck.setSelected(true);
93      }
94      
95      public void selectInternalDTD() {
96          internalDTDCheck.setSelected(true);
97      }
98  
99      public void selectInternalXSD() {
100         internalXSDCheck.setSelected(true);
101     }
102 
103     public void selectExternalSchema() {
104         externalSchemaCheck.setSelected(true);
105     }
106 
107     public void selectInternalDTDExternalSchema() {
108         internalDTDExternalSchemaCheck.setSelected(true);
109     }
110 
111     public String getSchemaLanguage() {
112         if (externalSchemaCheck.isSelected() || internalDTDExternalSchemaCheck.isSelected()) {
113             return schemaPage.getSchemaLanguage();
114         } else if (internalXSDCheck.isSelected()) {
115             return "http://www.w3.org/2001/XMLSchema";
116         }
117         
118         return null;
119     }
120 
121     public List<Document> getURIs() {
122         if (externalSchemaCheck.isSelected() || internalDTDExternalSchemaCheck.isSelected()) {
123             return schemaPage.getURIs();
124         }
125         
126         return new ArrayList<Document>();
127     }
128 
129     public boolean isValidating() {
130         return internalDTDCheck.isSelected() || internalXSDCheck.isSelected() || internalDTDExternalSchemaCheck.isSelected();
131     }
132 
133     public void itemStateChanged(ItemEvent arg0) {
134         super.firePageChanged();
135     }
136 }