View Javadoc

1   package org.xmlhammer.gui.wizard;
2   
3   import javax.swing.ButtonGroup;
4   import javax.swing.JRadioButton;
5   import javax.swing.border.EmptyBorder;
6   
7   import org.bounce.FormLayout;
8   import org.bounce.wizard.WizardPage;
9   import org.xmlhammer.gui.util.wizard.HelpEnabledWizardPage;
10  import org.xmlhammer.model.project.Document;
11  import org.xmlhammer.model.project.ParameterisedSource;
12  import org.xmlhammer.model.tools.xslt.Stylesheets;
13  import org.xmlhammer.model.tools.xslt.XSLT.Transform;
14  
15  public class StylesheetSelectionPage extends HelpEnabledWizardPage {
16  
17      private static final long serialVersionUID = -1909903213579390495L;
18      
19      private StylesheetURIsPage stylesheetURIsPage = null;
20      private AssociatedStylesheetPage associatedStylesheetPage = null;
21      private OutputPropertiesSelectionPage ouputPropertiesSelectionPage = null;
22  
23      private JRadioButton selectDefaultStylesheet = null;
24      private JRadioButton selectStylesheets = null;
25      private JRadioButton selectAssociatedStylesheet = null;
26  
27      public StylesheetSelectionPage(String helpID, StylesheetURIsPage stylesheetURIsPage, AssociatedStylesheetPage associatedStylesheetPage, OutputPropertiesSelectionPage ouputPropertiesSelectionPage) {
28          super(new FormLayout(11, 5), helpID);
29          
30          setBorder(new EmptyBorder(20, 50, 10, 10));
31  
32          this.stylesheetURIsPage = stylesheetURIsPage;
33          this.associatedStylesheetPage = associatedStylesheetPage;
34          this.ouputPropertiesSelectionPage = ouputPropertiesSelectionPage;
35          
36          selectDefaultStylesheet = new JRadioButton("Use the default Stylesheet");
37          selectStylesheets = new JRadioButton("Specify individual Stylesheet URIs");
38          selectAssociatedStylesheet = new JRadioButton("Use the Stylesheet associated with the XML input");
39          
40          ButtonGroup group = new ButtonGroup();
41          group.add(selectDefaultStylesheet);
42          group.add(selectStylesheets);
43          group.add(selectAssociatedStylesheet);
44          
45          selectDefaultStylesheet.setSelected(true);
46          
47          add(selectDefaultStylesheet, FormLayout.FULL);
48          add(selectStylesheets, FormLayout.FULL);
49          add(selectAssociatedStylesheet, FormLayout.FULL);
50      }
51      
52      public boolean isDefaultStylesheetSelected() {
53          return selectDefaultStylesheet.isSelected();
54      }
55      
56      // @unittest
57      public void selectDefaultStylesheet() {
58          selectDefaultStylesheet.setSelected(true);
59      }
60      
61      // @unittest
62      public void selectStylesheetURIs() {
63          selectStylesheets.setSelected(true);
64      }
65  
66      // @unittest
67      public boolean isStylesheetURIsSelected() {
68          return selectStylesheets.isSelected();
69      }
70  
71      // @unittest
72      public void selectAssociatedStylesheet() {
73          selectAssociatedStylesheet.setSelected(true);
74      }
75  
76      // @unittest
77      public boolean isAssociatedStylesheetSelected() {
78          return selectAssociatedStylesheet.isSelected();
79      }
80  
81      public Transform getTransform() { 
82          Transform transform = new Transform();
83          
84          if (isStylesheetURIsSelected()) {
85              Stylesheets stylesheets = new Stylesheets();
86              transform.setStylesheets(stylesheets);
87              for (Document source : stylesheetURIsPage.getURIs()) {
88                  stylesheets.getParameterisedSource().add((ParameterisedSource)source);
89              }
90          } else if (isAssociatedStylesheetSelected()) {
91              transform.setAssociated(associatedStylesheetPage.getAssociated());
92          }
93  
94          return transform;
95      }
96  
97      @Override
98      public String getTitle() {
99          return "Select Stylesheet Mechanism";
100     }
101 
102     @Override
103     public String getDescription() {
104         return "Define the Stylesheet mechanism to use";
105     }
106 
107     @Override
108     public WizardPage getNext() {
109         if (isAssociatedStylesheetSelected()) {
110             return associatedStylesheetPage;
111         } else if (isStylesheetURIsSelected()){
112             return stylesheetURIsPage;
113         } else {
114             return ouputPropertiesSelectionPage;
115         }
116     }
117 }