View Javadoc

1   /*
2    * $Id$
3    *
4    * The contents of this file are subject to the Mozilla Public License 
5    * Version 1.1 (the "License"); you may not use this file except in 
6    * compliance with the License. You may obtain a copy of the License at 
7    * http://www.mozilla.org/MPL/ 
8    *
9    * Software distributed under the License is distributed on an "AS IS" basis, 
10   * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License 
11   * for the specific language governing rights and limitations under the License.
12   *
13   * The Original Code is XML Hammer code. (org.xmlhammer.*)
14   *
15   * The Initial Developer of the Original Code is Edwin Dankert. Portions created 
16   * by the Initial Developer are Copyright (C) 2005 - 2006 the Initial Developer. 
17   * All Rights Reserved.
18   *
19   * Contributor(s): Edwin Dankert <edankert@gmail.com>
20   */
21  
22  package org.xmlhammer.gui.schemavalidator;
23  
24  import java.awt.BorderLayout;
25  import java.net.URISyntaxException;
26  import java.util.ArrayList;
27  import java.util.List;
28  
29  import javax.swing.JPanel;
30  import javax.swing.border.EmptyBorder;
31  
32  import org.xmlhammer.gui.Page;
33  import org.xmlhammer.gui.ProjectView;
34  import org.xmlhammer.gui.actions.PagePropertiesAction;
35  import org.xmlhammer.gui.overview.OverviewNode;
36  import org.xmlhammer.gui.preferences.PropertiesDialog;
37  import org.xmlhammer.gui.util.TitleBar;
38  import org.xmlhammer.model.jaxp.Settings;
39  import org.xmlhammer.model.project.SchemaValidator;
40  
41  /***
42   * Input Panel.
43   * 
44   * Allows to select either one URI, multiple URIs or 
45   * a range of files.
46   * 
47   * @version $Revision$, $Date$
48   * @author Edwin Dankert <edankert@gmail.com>
49   */
50  
51  public class SchemaPage extends Page implements OverviewNode {
52  	private static final long serialVersionUID = 3257852090755134776L;
53      
54      private PropertiesDialog propertiesDialog   = null;
55      private SchemaPanel schemaPanel             = null;
56  
57  	/***
58  	 * Constructs a new Input Panel.
59  	 */
60  	public SchemaPage(ProjectView view) {
61  		super( view);
62          
63          schemaPanel = new SchemaPanel(this);
64  		
65          JPanel center = new JPanel(new BorderLayout( 0, 5));
66          center.setBorder( new EmptyBorder( 10, 10, 20, 10));
67          center.add(schemaPanel, BorderLayout.NORTH);
68          
69          TitleBar titleBar = new TitleBar("Schema", null);
70  		titleBar.add(new PagePropertiesAction(this));
71  		
72  		setTitleBar(titleBar);
73  		setCenterPanel(center);
74  	}
75  	
76      public void setSchemaLanguage(String schemaLanguage) {
77          schemaPanel.setSchemaLanguage(schemaLanguage);
78     }
79  
80      public void setSchemaLanguages(List<String> languages) {
81          getProjectView().getFieldManager().setIgnoreChanges(true);
82  
83          schemaPanel.setSchemaLanguages(languages);
84  
85          getProjectView().getFieldManager().setIgnoreChanges(false);
86     }
87  
88      public String getSchemaLanguage() {
89          return schemaPanel.getSchemaLanguage();
90      }
91  
92      /***
93  	 * Sets the input model.
94  	 * Null resets current values.
95  	 * 
96  	 * @param parser the parser settings.
97  	 * @throws URISyntaxException
98  	 */
99  	public void setSchemaValidator(SchemaValidator validator) {
100         schemaPanel.setSchemaValidator(validator);
101 	}
102     
103 	/***
104 	 * Shows the properties dialog.
105 	 */
106 	public void showPropertiesDialog() {
107 		Settings settings = getProjectView().getProject(null).getJAXPSettings();
108 
109 		if ( propertiesDialog == null) {
110 			propertiesDialog = new PropertiesDialog(getProjectView().getProjectsView().getRoot(), false, false, false, false, true);
111 		}
112 		
113 		propertiesDialog.setSchemaFactory(settings.getJAXPSchemaFactory());
114 
115 		if (propertiesDialog.open() == PropertiesDialog.OK_OPTION) {
116  			settings.setJAXPSchemaFactory(propertiesDialog.getSchemaFactory());
117  			getProjectView().getFieldManager().setPropertiesChanged(true);
118  		}
119 	}
120 
121 	public SchemaValidator getSchemaValidator() {
122         return schemaPanel.getSchemaValidator();
123 	}
124     
125     public String getShortName() {
126         return "Schema";
127     }
128 
129 	/* (non-Javadoc)
130 	 * @see org.xmlhammer.gui.overview.OverviewNode#getNodeName()
131 	 */
132 	public String getNodeName() {
133 		return "Schema Language";
134 	}
135     
136     /* (non-Javadoc)
137      * @see org.xmlhammer.gui.overview.OverviewNode#getChildNodes()
138      */
139     public ArrayList<OverviewNode> getChildNodes() {
140         return schemaPanel.getChildNodes();
141     }
142     
143     public String getError() {
144         return null;
145     }
146 
147     public void dispose() {
148     }
149     
150     @Override
151     public String getHelpID() {
152         return getProjectView().getHelpID()+".language";
153     }
154 }