Coverage Report - org.xmlhammer.gui.input.InputPage
 
Classes in this File Line Coverage Branch Coverage Complexity
InputPage
94% 
100% 
0
 
 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  572
         private FilterFilesPanel filterFilesPanel        = null;
 51  572
         private InputURIsPanel selectURIsPanel                = null;
 52  572
     private boolean initialised = false;
 53  
 
 54  
     public InputPage( ProjectView view) {
 55  330
         this(view, false);
 56  330
     }
 57  
 
 58  
     /**
 59  
          * Constructs a new Input Panel.
 60  
          */
 61  
         public InputPage( ProjectView view, boolean resultEnabled) {
 62  572
                 super( view, "Input:", false);
 63  
                 
 64  572
                 filterFilesPanel = new FilterFilesPanel( this, resultEnabled);
 65  572
                 selectURIsPanel = new InputURIsPanel( this, resultEnabled);
 66  
                 
 67  572
                 addPanel( "Select URI(s)", selectURIsPanel);
 68  572
                 addPanel( "Filter Files", filterFilesPanel);
 69  
                 
 70  572
         initialised = true;
 71  572
         }
 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  572
                 if ( input != null) {
 81  572
                         filterFilesPanel.setFilter(base, input.getFilter());
 82  572
                         selectURIsPanel.setURIs(base, input.getSourceOrSourceAndResult());
 83  572
                 } else {
 84  0
                         filterFilesPanel.setFilter(base, null);
 85  0
                         selectURIsPanel.setURIs(base, null);
 86  
                 }
 87  
 
 88  572
                 if ( input == null || input.getFilter() != null) {
 89  132
             setSelectedPanel(filterFilesPanel);
 90  132
                 } else {
 91  440
             setSelectedPanel(selectURIsPanel);
 92  
                 }
 93  572
         }
 94  
         
 95  
         public Input getInput(URI base) {
 96  1914
         Input input = new Input();
 97  1914
                 JPanel panel = getSelectedPanel();
 98  
                 
 99  1914
                 if ( panel instanceof FilterFilesPanel) {
 100  198
                         input.setFilter( ((FilterFilesPanel)panel).getFilter(base));
 101  198
                 } else {
 102  1716
                         List<Document> uris = ((InputURIsPanel)panel).getURIs(base);
 103  
                         
 104  4268
                         for ( int i = 0; i < uris.size(); i++) {
 105  2552
                                 input.getSourceOrSourceAndResult().add(uris.get(i));
 106  
                         }
 107  
                 }
 108  
                 
 109  1914
                 return input;
 110  
         }
 111  
 
 112  
     public String getShortName() {
 113  3124
         return "Input";
 114  
     }
 115  
 
 116  
     /* (non-Javadoc)
 117  
          * @see org.xmlhammer.gui.overview.OverviewNode#getNodeName()
 118  
          */
 119  
         public String getNodeName() {
 120  6464
                 JPanel panel = getSelectedPanel();
 121  
                 
 122  6464
                 if ( panel instanceof FilterFilesPanel) {
 123  528
                         return "Input (Filter Files)";
 124  
                 }
 125  
                 
 126  5936
         return "Input (Specify URIs)";
 127  
         }
 128  
 
 129  
         /* (non-Javadoc)
 130  
          * @see org.xmlhammer.gui.overview.OverviewNode#getChildNodes()
 131  
          */
 132  
         public ArrayList<OverviewNode> getChildNodes() {
 133  50015
         JPanel panel = getSelectedPanel();
 134  
         
 135  50015
         if ( panel instanceof FilterFilesPanel) {
 136  5292
             return ((FilterFilesPanel)panel).getNodes();
 137  
         }
 138  
         
 139  44723
         return ((InputURIsPanel)panel).getNodes();
 140  
         }
 141  
 
 142  
         public OverviewNode getParentNode() {
 143  23622
                 if ( initialised) {
 144  23622
                         return getProjectView().getOverviewPanel().getModel().getRoot();
 145  
                 }
 146  
         
 147  0
                 return null;
 148  
         }
 149  
     
 150  
     public String getError() {
 151  28101
         return null;
 152  
     }
 153  
 
 154  
     public void itemStateChanged( ItemEvent e) {
 155  836
         super.itemStateChanged( e);
 156  
         
 157  836
         if ( initialised) {
 158  264
             ProjectView view = getProjectView();
 159  
 
 160  
             // Need to stay here, otherwise the children are not de-selected.
 161  264
             view.getOverviewPanel().selectNode( this);
 162  264
             view.getOverviewPanel().getModel().structureChanged( this);
 163  264
             view.getOverviewPanel().expandAll();
 164  
         }
 165  836
     }
 166  
     
 167  
     public void dispose() {
 168  
         
 169  572
     }
 170  
 
 171  
     @Override
 172  
     public String getHelpID() {
 173  1364
         return getProjectView().getHelpID()+".input";
 174  
     }
 175  
 }