View Javadoc

1   /*
2    * $Id: InputPage.java,v 1.13 2007/05/29 21:02:55 edankert Exp $
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.input;
23  
24  import java.awt.event.ItemEvent;
25  import java.net.URI;
26  import java.util.ArrayList;
27  import java.util.List;
28  
29  import javax.swing.JPanel;
30  
31  import org.xmlhammer.gui.ProjectView;
32  import org.xmlhammer.gui.overview.OverviewNode;
33  import org.xmlhammer.gui.util.SelectionPage;
34  import org.xmlhammer.model.project.Document;
35  import org.xmlhammer.model.project.Input;
36  
37  /***
38   * Input Panel.
39   * 
40   * Allows to select either one URI, multiple URIs or 
41   * a range of files.
42   * 
43   * @version $Revision: 1.13 $, $Date: 2007/05/29 21:02:55 $
44   * @author Edwin Dankert <edankert@gmail.com>
45   */
46  
47  public class InputPage extends SelectionPage implements OverviewNode {
48  	private static final long serialVersionUID = 3257852090755134776L;
49  
50  	private FilterFilesPanel filterFilesPanel	= null;
51  	private InputURIsPanel selectURIsPanel		= null;
52      private boolean initialised = false;
53  
54      public InputPage( ProjectView view) {
55          this(view, false);
56      }
57  
58      /***
59  	 * Constructs a new Input Panel.
60  	 */
61  	public InputPage( ProjectView view, boolean resultEnabled) {
62  		super( view, "Input:", false);
63  		
64  		filterFilesPanel = new FilterFilesPanel( this, resultEnabled);
65  		selectURIsPanel = new InputURIsPanel( this, resultEnabled);
66  		
67  		addPanel( "Select URI(s)", selectURIsPanel);
68  		addPanel( "Filter Files", filterFilesPanel);
69  		
70          initialised = true;
71  	}
72  
73  	/***
74  	 * Sets the input model.
75  	 * Null resets current values.
76  	 * 
77  	 * @param input the input model.
78  	 */
79  	public void setInput(URI base, Input input) {
80  		if ( input != null) {
81  			filterFilesPanel.setFilter(base, input.getFilter());
82  			selectURIsPanel.setURIs(base, input.getSourceOrSourceAndResult());
83  		} else {
84  			filterFilesPanel.setFilter(base, null);
85  			selectURIsPanel.setURIs(base, null);
86  		}
87  
88  		if ( input == null || input.getFilter() != null) {
89              setSelectedPanel(filterFilesPanel);
90  		} else {
91              setSelectedPanel(selectURIsPanel);
92  		}
93  	}
94  	
95  	public Input getInput(URI base) {
96          Input input = new Input();
97  		JPanel panel = getSelectedPanel();
98  		
99  		if ( panel instanceof FilterFilesPanel) {
100 			input.setFilter( ((FilterFilesPanel)panel).getFilter(base));
101 		} else {
102 			List<Document> uris = ((InputURIsPanel)panel).getURIs(base);
103 			
104 			for ( int i = 0; i < uris.size(); i++) {
105 				input.getSourceOrSourceAndResult().add(uris.get(i));
106 			}
107 		}
108 		
109 		return input;
110 	}
111 
112     public String getShortName() {
113         return "Input";
114     }
115 
116     /* (non-Javadoc)
117 	 * @see org.xmlhammer.gui.overview.OverviewNode#getNodeName()
118 	 */
119 	public String getNodeName() {
120 		JPanel panel = getSelectedPanel();
121 		
122 		if ( panel instanceof FilterFilesPanel) {
123 			return "Input (Filter Files)";
124 		}
125 		
126         return "Input (Specify URIs)";
127 	}
128 
129 	/* (non-Javadoc)
130 	 * @see org.xmlhammer.gui.overview.OverviewNode#getChildNodes()
131 	 */
132 	public ArrayList<OverviewNode> getChildNodes() {
133         JPanel panel = getSelectedPanel();
134         
135         if ( panel instanceof FilterFilesPanel) {
136             return ((FilterFilesPanel)panel).getNodes();
137         }
138         
139         return ((InputURIsPanel)panel).getNodes();
140 	}
141 
142 	public OverviewNode getParentNode() {
143 		if ( initialised) {
144 			return getProjectView().getOverviewPanel().getModel().getRoot();
145 		}
146         
147 		return null;
148 	}
149     
150     public String getError() {
151         return null;
152     }
153 
154     public void itemStateChanged( ItemEvent e) {
155         super.itemStateChanged( e);
156         
157         if ( initialised) {
158             ProjectView view = getProjectView();
159 
160             // Need to stay here, otherwise the children are not de-selected.
161             view.getOverviewPanel().selectNode( this);
162             view.getOverviewPanel().getModel().structureChanged( this);
163             view.getOverviewPanel().expandAll();
164         }
165     }
166     
167     public void dispose() {
168         
169     }
170 
171     @Override
172     public String getHelpID() {
173         return getProjectView().getHelpID()+".input";
174     }
175 }