Ignore:
Timestamp:
2006-08-18T09:39:54+12:00 (18 years ago)
Author:
shaoqun
Message:

new download pane gui

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/gli/src/org/greenstone/gatherer/gui/DownloadPane.java

    r12119 r12470  
    3939import java.awt.*;
    4040import java.awt.event.*;
    41 import java.io.File;
     41import java.io.*;
    4242import java.net.*;
    4343import java.util.*;
     
    4949import org.greenstone.gatherer.Dictionary;
    5050import org.greenstone.gatherer.Gatherer;
    51 import org.greenstone.gatherer.WGet;
    5251import org.greenstone.gatherer.file.WorkspaceTree;
    5352import org.greenstone.gatherer.util.StaticStrings;
    5453import org.greenstone.gatherer.util.Utility;
     54import org.greenstone.gatherer.cdm.download.*;
     55import org.greenstone.gatherer.util.XMLTools;
     56import org.greenstone.gatherer.cdm.download.DownloadScrollPane;
     57import org.greenstone.gatherer.cdm.download.ServerInfoDialog;
     58import org.greenstone.gatherer.cdm.*;
     59import org.greenstone.gatherer.gui.*;
     60import org.w3c.dom.*;
     61import org.xml.sax.*;
     62import org.greenstone.gatherer.GAuthenticator;
    5563
    5664/**
     
    6371    /** The threshold for when the advanced options get added */
    6472    static private final int THRESHOLD = Configuration.SYSTEMS_MODE;
    65 
     73    static final private Dimension LABEL_SIZE = new Dimension(225, 25);
     74    static final private Dimension TREE_SIZE = new Dimension(150, 500);
     75    static final private String CONTENTS[] = { "DOWNLOAD.MODE.WebDownload", "DOWNLOAD.MODE.OAIDownload", "DOWNLOAD.MODE.ZDownload" , "DOWNLOAD.MODE.SRWDownload"};
     76
     77    private DOMProxyListModel model;
    6678    private boolean download_button_enabled = false;
    6779    private boolean ready = false;
    6880    private int current_mode;
    69     private JButton clear_cache_button;
    70     private JButton download_button;
    71     private JCheckBox higher_checkbox;
    72     private JCheckBox requisite_checkbox;
    73     private JCheckBox same_host_checkbox;
     81
     82    private JPanel options_pane;
     83    // TODO should use Vector to store all loaded downloads!!
     84
     85    private DesignTree tree;
     86    private HashMap download_map;
     87    private ServerInfoDialog server_info;
    7488    private JScrollPane list_scroll;
    75     private JComboBox depth_combobox;
    76     private JPanel options_pane;
    77     private JTextField url_field;
    78     private Vector depth_model;
    79     private WGet getter;
    80 
     89    private DownloadScrollPane getter;
     90    private String mode = null;
     91    private TreePath previous_path;
     92    private String proxy_url = "";
     93       
     94    /** Main System code */
    8195    public DownloadPane() {
    8296    super();
    83     // Create a new wget thread
    84         getter = new WGet();
     97
     98    // TODO: Download the WDownload and the download panel fixed!!
     99        getter = new DownloadScrollPane();
    85100        getter.start();
    86     // And retrieve its list of pending jobs
    87101    list_scroll = getter.getDownloadJobList();
    88102
    89     current_mode = Configuration.getMode();
    90     // String user_dir = System.getProperty("user.dir"); // ****
    91     // System.err.println("**** user dir = "+user_dir);
    92     // Create
    93     JPanel edit_pane = new JPanel();
    94     JPanel details_pane = new JPanel();
     103    // TODO should use Vector to store all loaded downloads!!
     104    String lang = Configuration.getLanguage();
     105    download_map = new HashMap();
     106    download_map.put("Web", loadDownload("WebDownload",lang));
     107    download_map.put("OAI", loadDownload("OAIDownload",lang));
     108    download_map.put("Z3950", loadDownload("Z3950Download",lang));
     109    download_map.put("SRW", loadDownload("SRWDownload",lang));
     110
     111    // Creation
     112    tree = new DesignTree();
    95113    options_pane = new JPanel();
    96114
    97     JPanel url_pane = new JPanel();
    98     JLabel url_label = new JLabel(Dictionary.get("Mirroring.Source_URL"));
    99     url_field = new JTextField();
    100     url_field.setToolTipText(Dictionary.get("Mirroring.Source_URL_Tooltip"));
    101115   
    102     depth_model = new Vector();
    103     depth_model.add(new DepthEntry(0, Dictionary.get("Mirroring.Download_Depth.Zero")));
    104     /* @todo - add to dictionary */
    105     depth_model.add(new DepthEntry(1, String.valueOf(1)));
    106     /* @todo - add to dictionary */
    107     depth_model.add(new DepthEntry(2, String.valueOf(2)));
    108     /* @todo - add to dictionary */
    109     depth_model.add(new DepthEntry(3, String.valueOf(3)));
    110     /* @todo - add to dictionary */
    111     depth_model.add(new DepthEntry(4, String.valueOf(4)));
    112     /* @todo - add to dictionary */
    113     depth_model.add(new DepthEntry(5, String.valueOf(5)));
    114     depth_model.add(new DepthEntry(-1, Dictionary.get("Mirroring.Download_Depth.Unlimited")));
    115     JPanel depth_pane = new JPanel();
    116     JLabel depth_label = new JLabel(Dictionary.get("Mirroring.Download_Depth"));
    117     depth_combobox = new JComboBox(depth_model);
    118     depth_combobox.setToolTipText(Dictionary.get("Mirroring.Download_Depth_Tooltip"));
    119    
    120     requisite_checkbox = new JCheckBox(Dictionary.get("Mirroring.Download_OnlyHTML"));
    121    
    122     higher_checkbox = new JCheckBox(Dictionary.get("Mirroring.Higher_Directories"));
    123     higher_checkbox.addActionListener(new CheckboxClickListener());
    124    
    125     same_host_checkbox = new JCheckBox(Dictionary.get("Mirroring.Same_Host"));
    126     same_host_checkbox.setSelected(true);
    127    
    128     JPanel button_pane = new JPanel();
    129 
    130     JButton preferences_button = new GLIButton(Dictionary.get("Mirroring.Preferences"), Dictionary.get("Mirroring.Preferences_Tooltip"));
     116    JButton clear_cache_button = new GLIButton(Dictionary.get("Mirroring.ClearCache"), Dictionary.get("Mirroring.ClearCache_Tooltip"));
     117    clear_cache_button.setEnabled(true);
     118    clear_cache_button.setMnemonic(KeyEvent.VK_C);
     119
     120    JButton download_button = new GLIButton(Dictionary.get("Mirroring.Download"), Dictionary.get("Mirroring.Download_Tooltip"));
     121    download_button.setEnabled(true);
     122    download_button.setMnemonic(KeyEvent.VK_D);
     123
     124    JButton information_button =  new GLIButton(Dictionary.get("Download.ServerInformation"), Dictionary.get("Download.ServerInformation_Tooltip"));
     125    information_button.setEnabled(true);
     126    information_button.setMnemonic(KeyEvent.VK_S);
     127
     128
     129        JButton preferences_button =  new GLIButton(Dictionary.get("Mirroring.Preferences"), Dictionary.get("Mirroring.Preferences_Tooltip"));
    131130    preferences_button.setEnabled(true);
    132        
    133     clear_cache_button = new GLIButton(Dictionary.get("Mirroring.ClearCache"), Dictionary.get("Mirroring.ClearCache_Tooltip"));
    134     clear_cache_button.setEnabled(true);
    135    
    136     download_button = new GLIButton(Dictionary.get("Mirroring.Download"), Dictionary.get("Mirroring.Download_Tooltip"));
    137     download_button.setEnabled(true);
    138    
     131    preferences_button.setMnemonic(KeyEvent.VK_P);
     132
    139133    // Connect
    140134    clear_cache_button.addActionListener(new ClearCacheListener());
    141135    download_button.addActionListener(new DownloadButtonListener());
    142136    preferences_button.addActionListener(new PreferencesButtonActionListener());
    143 
    144     // Layout
    145     url_pane.setLayout(new BorderLayout(5,0));
    146     url_pane.add(url_label, BorderLayout.WEST);
    147     url_pane.add(url_field, BorderLayout.CENTER);
    148 
    149     depth_pane.setLayout(new GridLayout(1,3));
    150     depth_pane.add(depth_label);
    151     depth_pane.add(new JPanel());
    152     depth_pane.add(depth_combobox);
    153 
    154     details_pane.setLayout(new GridLayout(2,1,0,5));
    155     details_pane.setBorder(BorderFactory.createEmptyBorder(2,2,5,2));
    156     details_pane.add(url_pane);
    157     details_pane.add(depth_pane);
    158 
    159     options_pane.setLayout(new GridLayout(3,1,0,5));
    160    
    161     options_pane.add(higher_checkbox);
    162     options_pane.add(same_host_checkbox);
    163     //if (current_mode >= THRESHOLD) {
    164     options_pane.add(requisite_checkbox);
    165         //}
    166 
    167     button_pane.setLayout(new GridLayout(3,1));
    168     button_pane.add(preferences_button);
     137    information_button.addActionListener(new InformationButtonActionListener());
     138    tree.addTreeSelectionListener(new TreeListener());
     139
     140    // Add to Panel
     141    JPanel button_pane = new JPanel();
     142    button_pane.setLayout(new FlowLayout(FlowLayout.CENTER,20,5));
     143    button_pane.setBorder(BorderFactory.createEtchedBorder());
    169144    button_pane.add(clear_cache_button);
    170145    button_pane.add(download_button);
    171 
    172     edit_pane.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createEmptyBorder(2,0,0,0), BorderFactory.createCompoundBorder(BorderFactory.createTitledBorder(Dictionary.get("Mirroring.Download_Controls")), BorderFactory.createEmptyBorder(2,2,2,2))));
     146    button_pane.add(information_button);
     147    button_pane.add(preferences_button);
     148
     149    JPanel tree_pane = new JPanel();
     150    tree_pane.setLayout(new BorderLayout());
     151        tree_pane.add(new JScrollPane(tree), BorderLayout.CENTER);
     152    tree_pane.setPreferredSize(TREE_SIZE);
     153 
     154
     155    Color colour_two = Configuration.getColor("coloring.collection_tree_background", false);
     156    options_pane.setBackground(colour_two);
     157    options_pane.setBorder(BorderFactory.createEtchedBorder());
     158
     159
     160    JScrollPane options_scroll_pane = new JScrollPane(options_pane);
     161    JSplitPane mode_pane = new JSplitPane();
     162    mode_pane.setBorder(BorderFactory.createEmptyBorder(0,0,0,0));
     163    mode_pane.add(tree_pane,JSplitPane.LEFT);
     164    mode_pane.add(options_scroll_pane,JSplitPane.RIGHT);
     165    mode_pane.setDividerLocation(TREE_SIZE.width);
     166   
     167    JPanel edit_pane = new JPanel();
     168    edit_pane.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createEmptyBorder(2,0,0,0), BorderFactory.createCompoundBorder(BorderFactory.createTitledBorder("Download Setting"), BorderFactory.createEmptyBorder(2,2,2,2))));
    173169    edit_pane.setLayout(new BorderLayout());
    174     edit_pane.add(details_pane, BorderLayout.NORTH);
    175     edit_pane.add(button_pane, BorderLayout.EAST);
    176     edit_pane.add(options_pane, BorderLayout.CENTER);
    177 
     170    edit_pane.add(mode_pane,BorderLayout.CENTER);
     171    edit_pane.add(button_pane,BorderLayout.PAGE_END);
     172
     173    // Add to "this"
    178174    setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
    179     setLayout(new BorderLayout());
    180     add(edit_pane, BorderLayout.NORTH);
    181     add(list_scroll, BorderLayout.CENTER);
    182     }
    183 
     175    setLayout(new GridLayout(2,1));
     176    add(edit_pane);
     177    add(list_scroll);
     178
     179    mode = "Web";
     180    generateOptions(options_pane,(Download)download_map.get(mode));
     181    previous_path = tree.getSelectionPath();
     182    }
     183
     184    /** System Utilities */
     185    public void modeChanged(int mode) {
     186    int old_mode = current_mode;
     187    current_mode = mode;
     188    if (old_mode >= THRESHOLD && current_mode >= THRESHOLD) {
     189        return;
     190    }
     191    if (old_mode < THRESHOLD && current_mode < THRESHOLD) {
     192        return;
     193    }
     194    if (current_mode >= THRESHOLD) {
     195        System.out.println("current mode is greater then Threshold!!");
     196    }
     197    else {
     198        System.out.println("current mode is smaller then Threshold!!");
     199    }
     200    }
     201
     202    private void addHeader(String name, Color color, JPanel target_pane) {
     203    JPanel header = new JPanel();
     204    header.setBackground(color);
     205    JPanel inner_pane = new JPanel();
     206    inner_pane.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createEmptyBorder(5,5,5,5), BorderFactory.createRaisedBevelBorder()));
     207    inner_pane.setBackground(color);
     208    JLabel header_label = new JLabel("<html><strong>" + name + "</strong></html>");
     209    header_label.setBackground(Configuration.getColor("coloring.collection_heading_background", false));
     210    header_label.setHorizontalAlignment(JLabel.CENTER);
     211    header_label.setOpaque(true);
     212
     213    // Layout
     214    inner_pane.setLayout(new BorderLayout());
     215    inner_pane.add(header_label, BorderLayout.CENTER);
     216
     217    header.setLayout(new BorderLayout());
     218    header.add(inner_pane, BorderLayout.CENTER);
     219    target_pane.add(header);
     220    }
     221
     222    /** Supporting Functions */
     223    private Download loadDownload(String download_name, String lang) {
     224    Document document = null;
     225    InputStream input_stream = null;
     226   
     227    try {
     228        if (Gatherer.isGsdlRemote) {
     229        String launch  = Gatherer.cgiBase + "launch";
     230        launch += "?cmd=downloadinfo.pl";
     231        launch += "&xml=&language="+lang;
     232        launch += "&plug=" + download_name;
     233       
     234        System.err.println("*** launch = " + launch);
     235       
     236        URL launch_url = new URL(launch);
     237        URLConnection launch_connection = launch_url.openConnection();
     238        input_stream = launch_connection.getInputStream();
     239        }
     240        else {
     241        String args[] = null;
     242        if(Utility.isWindows()) {
     243            args = new String[6];
     244            if(Configuration.perl_path != null) {
     245            args[0] = Configuration.perl_path;
     246            }
     247            else {
     248            args[0] = "Perl.exe";
     249            }
     250            args[1] = Configuration.gsdl_path + "bin" + File.separator + "script" + File.separator + "downloadinfo.pl";
     251            args[2] = "-xml";
     252            args[3] = "-language";
     253            args[4] = lang;
     254            args[5] = download_name;
     255        }
     256        else {
     257            args = new String[5];
     258            args[0] = "downloadinfo.pl";
     259            args[1] = "-xml";
     260            args[2] = "-language";
     261            args[3] = lang;
     262            args[4] = download_name;
     263        }
     264
     265        // Create the process.
     266
     267        Runtime runtime = Runtime.getRuntime();
     268        Process process = runtime.exec(args);
     269       
     270        input_stream = process.getErrorStream();
     271        }
     272
     273        StringBuffer xml = Utility.readXMLStream(input_stream);
     274            document = CollectionDesignManager.XMLStringToDOM(xml,download_name);
     275    }
     276    catch (Exception error) {
     277        System.err.println("Failed when trying to parse: " + download_name);
     278        error.printStackTrace();
     279    }
     280
     281    if(document != null) {
     282        return parseXML(document.getDocumentElement());
     283    }
     284
     285    return null;
     286    }
     287
     288    private Download parseXML(Node root) {
     289    Download download = new Download();
     290    String node_name = null;
     291    for (Node node = root.getFirstChild(); node != null; node = node.getNextSibling()) {
     292        node_name = node.getNodeName();
     293        if(node_name.equalsIgnoreCase("Name")) {
     294        String name = XMLTools.getValue(node);
     295        download.setName(name);
     296        }
     297        else if (node_name.equalsIgnoreCase("Desc")) {
     298        download.setDescription(XMLTools.getValue(node));
     299        }
     300        else if (node_name.equalsIgnoreCase("Abstract")) {
     301        download.setIsAbstract(XMLTools.getValue(node).equalsIgnoreCase(StaticStrings.YES_STR));
     302        }
     303        else if(node_name.equalsIgnoreCase("Arguments")) {
     304        for(Node arg = node.getFirstChild(); arg != null; arg = arg.getNextSibling()) {
     305            node_name = arg.getNodeName();
     306                     if(node_name.equalsIgnoreCase("Option")) {
     307            Argument argument = new Argument((Element)arg);
     308            argument.parseXML((Element)arg);
     309            argument.setValue(argument.getDefaultValue());
     310            download.addArgument(argument);
     311             }
     312           
     313        }
     314        }
     315            else if(node_name.equalsIgnoreCase("DownloadInfo")) {
     316                Download super_download = parseXML(node);
     317        download.setSuper(super_download);
     318        }
     319    }
     320
     321    if(download.getName() != null) {
     322        return download;
     323    }
     324    return null;
     325    }
     326
     327    /** Update the previous setup */
     328    private boolean updateArguments(boolean checkRequired)
     329    {
     330    boolean cont = true;
     331    for(int i = 0; i < options_pane.getComponentCount(); i++) {
     332       
     333        Component component = options_pane.getComponent(i);
     334        if(component instanceof ArgumentControl) {
     335        cont = cont && ((ArgumentControl)component).updateArgument(checkRequired);
     336        }
     337    }
     338
     339    if(cont){return true; }
     340
     341    return false;
     342    }
     343   
     344    /** Generate Controls for Options */
     345    private void generateOptions(JPanel options_pane, ArgumentContainer data) {
     346    options_pane.removeAll();
     347    /** Create the current option panel */
     348
     349    ArrayList arguments = data.getArguments(true, false);
     350        int mode = Configuration.getMode();
     351        ArrayList added_arguments = new ArrayList();
     352     
     353    for(int i = 0; i < arguments.size(); i++) {
     354        Argument argument = (Argument) arguments.get(i);
     355
     356        if (argument.isHiddenGLI()) continue;
     357        if(mode > Configuration.LIBRARIAN_MODE || !(argument.getType() == Argument.REGEXP)) {
     358        ArgumentControl argument_control = new ArgumentControl(argument,false,null);
     359        added_arguments.add(argument_control);
     360        }
     361    }
     362
     363        options_pane.setLayout(new GridLayout(added_arguments.size(),1));
     364        for(int i = 0; i <  added_arguments.size(); i++) {
     365        options_pane.add((ArgumentControl)added_arguments.get(i));
     366       
     367    }
     368    }
     369
     370    /** Behaviour Functions */
    184371    public void afterDisplay() {
    185372    ready = true;
     
    187374
    188375
    189     /** This method is called whenever the Download pane is brought into focus and is a good time to display a warning message if WGet is not available or of an older, problematic, version.
    190      */
    191376    public void gainFocus() {
    192377    if(!ready) {
     
    199384        download_button_enabled = false;
    200385        // And we tell the user why.
    201         Gatherer.missingWGET();
     386      Gatherer.missingWGET();
    202387    }
    203388    else if(wget_version_str.equals(StaticStrings.WGET_OLD_STR)) {
     
    212397    }
    213398    // It is also a good time to determine if the download should be enabled - ie if its allowed to be enabled and a valid URL is present in the field.
    214     download_button.setEnabled(download_button_enabled);
    215     }
    216 
    217     public void modeChanged(int mode) {
    218     int old_mode = current_mode;
    219     current_mode = mode;
    220     if (old_mode >= THRESHOLD && current_mode >= THRESHOLD) {
    221         return;
    222     }
    223     if (old_mode < THRESHOLD && current_mode < THRESHOLD) {
    224         return;
    225     }
    226 
    227     //if (current_mode >= THRESHOLD) {
    228     //    options_pane.add(requisite_checkbox);
    229     //}
    230     //else {
    231     //   options_pane.remove(requisite_checkbox);
    232     //   requisite_checkbox.setSelected(false);
    233     //}
    234     return;
    235     }
     399    //download_button.setEnabled(download_button_enabled);
     400    }
     401
    236402
    237403
     
    240406    }
    241407
    242 
    243     /** A DepthEntry contains a depth value, as an int, and a representitive text string. This allows for a more meaningful appearance than '0' for instance. */
    244     private class DepthEntry
    245     implements Comparable {
    246     private int value;
    247     private String text;
    248     /** Default constructor.
    249      * @param value the depth value as an int
    250      * @param text how this entry show represent itself as a String
     408    /** Private classes */
     409    /** This tree provides a 'table of contents' for the various components of the design process (collection configuration in more technical terms). */
     410    private class DesignTree extends JTree {
     411
     412    private DesignNode root = null;
     413    /** Constructor. Automatically generates all of the nodes, in the order of CONTENTS. */
     414    public DesignTree() {
     415        super();
     416        resetModel(Configuration.getMode());
     417        expandRow(0);
     418        setRootVisible(false);
     419        setSelectionRow(0);
     420    }
     421
     422    /** Reset the model used by the design page contents tree. This is necessary to hide the partitions entry when in lower detail modes
     423     * @param mode the current detail mode as an int
    251424     */
    252     public DepthEntry(int value, String text) {
    253         this.text = text;
    254         this.value = value;
    255     }
    256     /** Determines the natural ordering of this DepthEntry and some other object
    257      * @param object the Object to test for ordering
    258      * @return >0 if the object is before this one, 0 if they are equal, or <0 if the object is after this one
     425    public void resetModel(int mode) {
     426        root = new DesignNode("DOWNLOAD.MODE.Root");
     427        // Now add the design categories.
     428        for(int i = 0; i < CONTENTS.length; i++) {
     429        root.add(new DesignNode(CONTENTS[i]));
     430        }
     431        this.setModel(new DefaultTreeModel(root));
     432        updateUI();
     433    }
     434    /** Set the current view to the one specified.
     435     * @param type the name of the desired view as a String
    259436     */
    260     public int compareTo(Object object) {
    261         // If the object is a DepthEntry then this is easy pesy.
    262         if(object instanceof DepthEntry) {
    263         int target_value = ((DepthEntry) object).getValue();
    264         return value - target_value;
    265         }
    266         // If the object is a String, then we should try parsing an int from it
    267         if(object instanceof String) {
    268         try {
    269             int target_value = Integer.parseInt((String)object);
    270             return value - target_value;
    271         }
    272         catch(Exception exception) {
    273         }
    274         }
    275         // Otherwise we'll try a string comparison between our text and the toString of the object
    276         return text.compareTo(object.toString());
    277     }
    278 
    279     /** Determine if this DepthEntry is equal to some other object. Given that there is significant processing involved we push the resposiblility for this onto compareTo, so we only have the complex code once.
    280      * @param object the Object to test for equality
    281      * @return true if the object is equal to this depth entry, false otherwise
     437    public void setSelectedView(String type) {
     438        type = Dictionary.get(type);
     439        for(int i = 0; i < root.getChildCount(); i++) {
     440        DesignNode child = (DesignNode) root.getChildAt(i);
     441        if(child.toString().equals(type)) {
     442            TreePath path = new TreePath(child.getPath());
     443            setSelectionPath(path);
     444        }
     445        }
     446    }
     447    }
     448
     449    /** A tree node that retains a reference to one of the possible design sub-views relating to the different sub-managers. */
     450    private class DesignNode extends DefaultMutableTreeNode {
     451    /** Constructor.
     452     * @param object The <strong>Object</strong> assigned to this node.
    282453     */
    283     public boolean equals(Object object) {
    284         return (compareTo(object) == 0);
    285     }
    286 
    287     public int getValue() {
    288         return value;
    289     }
    290 
     454    public DesignNode(String object) {
     455        super(object);
     456    }
     457    /** Retrieve a textual representation of the object.
     458     * @return a String
     459     */
    291460    public String toString() {
    292         return text;
     461        // return Dictionary.get("CDM.GUI." + (String)getUserObject());
     462        return Dictionary.get((String) getUserObject());
     463    }
     464    }
     465
     466    /** Listens for selection changes in the 'contents' tree, and switches to the appropriate view. */
     467    private class TreeListener
     468    implements TreeSelectionListener {
     469    /** Called whenever the selection changes, we must update the view so it matches the node selected.
     470     * @param event A <strong>TreeSelectionEvent</strong> containing more information about the tree selection.
     471     * @see org.greenstone.gatherer.cdm.ClassifierManager
     472     * @see org.greenstone.gatherer.cdm.CollectionDesignManager
     473     * @see org.greenstone.gatherer.cdm.CollectionMetaManager
     474     * @see org.greenstone.gatherer.cdm.FormatManager
     475     * @see org.greenstone.gatherer.cdm.LanguageManager
     476     * @see org.greenstone.gatherer.cdm.MetadataSetView
     477     * @see org.greenstone.gatherer.cdm.SubcollectionManager
     478     * @see org.greenstone.gatherer.cdm.TranslationView
     479     * @see org.greenstone.gatherer.cdm.PlugInManager
     480     */
     481    public void valueChanged(TreeSelectionEvent event) {
     482        if(!tree.isSelectionEmpty()) {
     483        TreePath path = tree.getSelectionPath();
     484
     485        DesignNode node = (DesignNode)path.getLastPathComponent();
     486        String type = (String)node.getUserObject();
     487        Gatherer.g_man.wait(true);
     488        if(type == CONTENTS[0]) {
     489            mode = "Web";
     490            generateOptions(options_pane,(Download)download_map.get(mode));
     491        }
     492        else if(type == CONTENTS[1]) {
     493            mode = "OAI";
     494            generateOptions(options_pane,(Download)download_map.get(mode));
     495        }
     496        else if(type == CONTENTS[2]) {
     497            mode = "Z3950";
     498            generateOptions(options_pane,(Download)download_map.get(mode));
     499        }
     500        else if(type == CONTENTS[3]) {
     501            mode = "SRW";
     502            generateOptions(options_pane,(Download)download_map.get(mode));
     503        }
     504        tree.setSelectionPath(path);
     505        previous_path = path;
     506        repaint();
     507
     508        Gatherer.g_man.wait(false);
     509        }
    293510    }
    294511    }
     
    298515    public void actionPerformed(ActionEvent event) {
    299516        // Retrieve the cache folder and delete it.
    300         Utility.delete(Gatherer.getGLIUserCacheDirectoryPath());
     517        Utility.delete(Utility.getCacheDir());
    301518        // ...and refresh the node in the workspace tree to show it's all gone
    302519        Gatherer.g_man.refreshWorkspaceTree(WorkspaceTree.DOWNLOADED_FILES_CHANGED);
     
    304521    }
    305522
    306     private class CheckboxClickListener
     523    private class DownloadButtonListener
    307524    implements ActionListener {
    308525    public void actionPerformed(ActionEvent event) {
    309         if (higher_checkbox.isSelected()) {
    310         same_host_checkbox.setEnabled(false);
    311         } else {
    312         same_host_checkbox.setEnabled(true);
    313         }
     526       
     527        if(checkURL(true) && checkProxy() == true)
     528        {
     529             getter.newDownloadJob((Download)download_map.get(mode) ,mode,proxy_url);
     530        }
    314531    }
    315532    }
    316533   
    317     private class DownloadButtonListener
     534
     535    private boolean checkURL(boolean checkRequired){
     536   
     537    if (!updateArguments(checkRequired)){
     538        return false;
     539    }
     540
     541    Download current_download = (Download)download_map.get(mode);
     542    Argument arg_url = current_download.getArgument("url");
     543   
     544        if (arg_url == null) return true;
     545 
     546    String url_str = arg_url.getValue();
     547    URL url = null;
     548    try {
     549        url = new URL(url_str);
     550    }
     551    catch(MalformedURLException error) {
     552        JOptionPane.showMessageDialog(Gatherer.g_man, Dictionary.get("Mirroring.Invalid_URL"), Dictionary.get("Mirroring.Invalid_URL_Title"), JOptionPane.ERROR_MESSAGE);
     553        return false;
     554    }
     555
     556    return true;
     557    }
     558
     559   
     560    private boolean checkProxy(){
     561     
     562    proxy_url = null;
     563
     564    Download current_download = (Download)download_map.get(mode);
     565   
     566        Argument arg = current_download.getArgument("proxy_on");
     567 
     568    if (arg == null) return true;
     569   
     570    // Determine if we have to use a proxy.
     571    if(Configuration.get("general.use_proxy", true)) {
     572         
     573        String proxy_host = Configuration.getString("general.proxy_host", true);
     574        String proxy_port = Configuration.getString("general.proxy_port", true);
     575        // Find out whether the user has already authenticated themselves
     576        String user_pass = "";
     577        String address = proxy_host + ":" + proxy_port;
     578       
     579            int count = 0;
     580        while(count < 3 && (user_pass = (String) GAuthenticator.authentications.get(address)) == null) {
     581        Authenticator.requestPasswordAuthentication(proxy_host, null, Integer.parseInt(proxy_port), "http://", Dictionary.get("WGet.Prompt"), "HTTP");
     582        count++;
     583        }
     584
     585        if(count >= 3) {
     586        return false;
     587        }
     588
     589        if(user_pass.indexOf("@") != -1) {
     590           
     591        // Write the use proxy command - we don't do this anymore, instead we set environment variables - hopefully these can't be spied on like the follwoing can (using ps) - actually the environment stuff didn't work for windows, so lets go back to this
     592        if (Utility.isWindows()) {
     593             
     594           arg.setValue("true");
     595           arg.setAssigned(true);
     596
     597           arg = current_download.getArgument("proxy_host");
     598           arg.setValue(proxy_host);
     599           arg.setAssigned(true);
     600
     601           arg = current_download.getArgument("proxy_port");
     602           arg.setValue(proxy_port);
     603           arg.setAssigned(true);
     604
     605           arg = current_download.getArgument("user_name");
     606           arg.setValue(user_pass.substring(0, user_pass.indexOf("@")));
     607           arg.setAssigned(true);
     608
     609           arg = current_download.getArgument("user_password");
     610           arg.setValue(user_pass.substring(user_pass.indexOf("@") + 1));
     611           arg.setAssigned(true);
     612          }
     613           else{
     614            String user_name = user_pass.substring(0, user_pass.indexOf("@"));
     615            String user_pwd = user_pass.substring(user_pass.indexOf("@") + 1);
     616            proxy_url = user_name+":"+user_pwd+"@"+proxy_host+":"+proxy_port+"/";
     617           
     618           }
     619
     620           return true;
     621        }
     622        else{
     623        return false;
     624        }
     625
     626    }
     627
     628    return true;
     629    }
     630
     631    /*
     632    private class PreferencesButtonActionListener
     633    implements ActionListener {
     634    public void actionPerformed(ActionEvent event) {
     635    new Preferences(Preferences.CONNECTION_PREFS);
     636    }
     637    }*/
     638   
     639    private class InformationButtonActionListener
    318640    implements ActionListener {
    319 
    320641    public void actionPerformed(ActionEvent event) {
    321         // Retrieve the current url and confirm it is valid
    322         String url_str = url_field.getText();
    323         URL url = null;
    324         try {
    325         url = new URL(url_str);
    326         }
    327         catch(MalformedURLException error) {
    328         JOptionPane.showMessageDialog(Gatherer.g_man, Dictionary.get("Mirroring.Invalid_URL"), Dictionary.get("Mirroring.Invalid_URL_Title"), JOptionPane.ERROR_MESSAGE);
    329         }
    330 
    331         // Otherwise construct a new download job
    332         Object depth_object = depth_combobox.getSelectedItem();
    333         int depth_value = 0;
    334         if(depth_object instanceof DepthEntry) {
    335         depth_value = ((DepthEntry)depth_object).getValue();
    336         }
    337         else if(depth_object instanceof String) {
    338         String depth_string = (String) depth_object;
    339         try {
    340             depth_value = Integer.parseInt(depth_string);
    341             // Create a new entry for the purposes of comparison, and if needs be, addition
    342             DepthEntry new_entry = new DepthEntry(depth_value, depth_string);
    343             // Try to select the correct item from the combobox
    344             depth_combobox.setSelectedItem(null);
    345             depth_combobox.setSelectedItem(new_entry);
    346             // We can see if that worked, and if it didn't add the entry
    347             if(depth_combobox.getSelectedItem() == null) {
    348             depth_combobox.addItem(new_entry);
    349             depth_combobox.setSelectedItem(new_entry);
    350             }
    351             new_entry = null;
    352         }
    353         catch(Exception exception) {
    354             /* @todo - add to dictionary */
    355             JOptionPane.showMessageDialog(Gatherer.g_man, "Mirroring.Mirror_Depth.Invalid_Depth", "Mirroring.Mirror_Depth.Invalid_Depth_Title", JOptionPane.ERROR_MESSAGE);
    356             return;
    357         }
    358         depth_string = null;
    359         }
    360         depth_object = null;
    361    
    362         String destination_file_path = Gatherer.getGLIUserCacheDirectoryPath();
    363         (new File(destination_file_path)).mkdirs(); // If they aren't already
    364 
    365         if(url != null) {
    366         getter.newDownloadJob(higher_checkbox.isSelected(), (higher_checkbox.isSelected()? false : !same_host_checkbox.isSelected()), !requisite_checkbox.isSelected(), url, depth_value, destination_file_path);
    367         }
    368     }
    369     }
    370 
    371     private class PreferencesButtonActionListener
     642        //turn off the check for find argument
     643        Download current_download = (Download)download_map.get(mode);
     644
     645            if (!checkProxy() || !checkURL(false) )return;
     646
     647
     648        if(server_info != null)
     649        {
     650            server_info.dispose();
     651        }
     652
     653       
     654        Argument arg_url = current_download.getArgument("url");
     655        String str_url = "";
     656
     657        if( arg_url!= null && arg_url.isAssigned())
     658        {       
     659            str_url = arg_url.getValue();
     660        }
     661
     662           
     663        server_info = new ServerInfoDialog(str_url ,proxy_url, mode,(Download)download_map.get(mode));
     664        server_info.setVisible(true);                     
     665    }
     666    }
     667
     668     private class PreferencesButtonActionListener
    372669    implements ActionListener {
    373670    public void actionPerformed(ActionEvent event) {
Note: See TracChangeset for help on using the changeset viewer.