Changeset 5912


Ignore:
Timestamp:
2003-11-20T10:55:48+13:00 (20 years ago)
Author:
kjdon
Message:

now can export multiple collections to a single cdrom

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/gli/src/org/greenstone/gatherer/collection/ExportCollectionPrompt.java

    r5843 r5912  
    4040import java.awt.event.*;
    4141import java.io.*;
     42import java.util.ArrayList;
    4243import javax.swing.*;
    4344import javax.swing.event.*;
     45import org.greenstone.gatherer.checklist.CheckList;
     46import org.greenstone.gatherer.checklist.Entry;
    4447import org.greenstone.gatherer.Dictionary;
    4548import org.greenstone.gatherer.Gatherer;
     
    6366    extends ModalDialog
    6467    implements GShellListener {
     68    private ArrayList all_collections = null;
     69    private ArrayList selected_collections = null;
     70    /** The list of collections to export */
     71    private CheckList list = null;
    6572    /** The currently selected collection for deletion. */
    6673    private CollectionEntry collection = null;
     
    7885    private JLabel list_label = null;
    7986    /** The list of available collections. */
    80     private JList list = null;
     87    //private JList list = null;
    8188    /** The text area used to display details about the collection selected. */
    8289    private JTextArea details_textarea = null;
     
    8491    private JTextArea instructions_textarea;
    8592    /** A string array used to pass arguments to the phrase retrieval method. */
     93    private JTextField title_field = null;
     94    private JLabel title_label = null;
    8695    private String args[] = null;
    87    
     96    private String cd_title = null;
    8897    /** whether the exporting was successful or not */
    8998    private boolean successful = false;
     
    120129    Dictionary.registerText(instructions_textarea, "ExportCollectionPrompt.Instructions");
    121130
    122     list = new JList();
     131    //list = new JList();
     132    //list_model = new DefaultListModel();
     133    all_collections = new ArrayList();
     134    list = new CheckList(true);
    123135    list_label = new JLabel();
    124136    Dictionary.setText(list_label, "DeleteCollectionPrompt.Collection_List");
    125     list_model = new DefaultListModel();
    126137    ok_button = new JButton();
    127138    ok_button.setMnemonic(KeyEvent.VK_D);
    128139    Dictionary.setBoth(ok_button, "ExportCollectionPrompt.Export", "ExportCollectionPrompt.Export_Tooltip");
     140
     141    title_field = new JTextField();
     142    Dictionary.setTooltip(title_field, "ExportCollectionPrompt.CD_Name_Tooltip");
     143    title_label = new JLabel();
     144    Dictionary.setText(title_label, "ExportCollectionPrompt.CD_Name");
     145    //title_label.setPreferredSize(new Dimension(100, 40));
     146    scanForCollections();
     147    list.setListData(all_collections.toArray());
     148
    129149    prompt = this;
    130150    setModal(true);
     
    137157    list.clearSelection();
    138158    list.getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    139     list.setModel(list_model);
    140159    ok_button.addActionListener(new OKButtonListener());
    141160    ok_button.setEnabled(false);
    142     scanForCollections();
     161    //title.getDocument().addDocumentListener(new DocumentListener());
    143162    }
    144163
    145164    /** Destructor. */
    146165    public void destroy() {
    147     list_model.clear();
    148     list_model = null;
     166    all_collections.clear();
     167    all_collections = null;
    149168    cancel_button = null;
    150169    details_textarea = null;
     
    153172    ok_button = null;
    154173    prompt = null;
     174    if (selected_collections!=null) {
     175        selected_collections.clear();
     176        selected_collections = null;
     177    }
     178    title_field = null;
     179    title_label = null;
    155180    }
    156181
    157182    /** This method causes the modal prompt to be displayed.
    158      * returns true if it has deleted the collection that is currently open */
     183     * returns true if it has exported the collections that are currently selected */
    159184    public boolean display() {
    160185    // Top pane
     
    163188    instructions_pane.add(new JScrollPane(instructions_textarea), BorderLayout.CENTER);
    164189   
     190    title_label.setBorder(BorderFactory.createEmptyBorder(0,5,0,15));
     191
     192    JPanel title_pane = new JPanel(new BorderLayout());
     193    title_pane.add(title_label, BorderLayout.WEST);
     194    title_pane.add(title_field, BorderLayout.CENTER);
     195    instructions_pane.add(title_pane, BorderLayout.SOUTH);
     196
    165197    // Central pane
    166198    JPanel list_pane = new JPanel(new BorderLayout());
     
    216248     * @see org.greenstone.gatherer.util.Utility
    217249     */
    218     public void exportCollection() {
     250    public void exportCollections() {
    219251    Gatherer.println("ExportCollectionPrompt.exportCollection()");
    220252
     253    int num_collections = selected_collections.size();
     254    if (num_collections == 0) return;
     255    cd_title = title_field.getText();
     256    cd_title = cd_title.trim();
     257    cd_title = cd_title.replaceAll("\"","");
     258    int num_args = num_collections + 1;
     259    boolean has_title = false;
     260    if (!cd_title.equals("")) {
     261        num_args += 2;
     262        has_title = true;
     263    }
    221264    String args[];
     265    int next_arg = 0;
    222266    if(Utility.isWindows()) {
    223         args = new String[4];
     267        args = new String[num_args+2];
    224268        args[0] = Gatherer.config.perl_path;
    225269        args[1] = "-S";
    226         args[2] = Gatherer.config.getScriptPath() + "exportcol.pl";
    227         args[3] = collection.getName();
    228     }
    229     else {
    230         args = new String[2];
    231         args[0] = Gatherer.config.getScriptPath() + "exportcol.pl";
    232         args[1] = collection.getName();
     270        next_arg = 2;
     271    } else {
     272        args = new String[num_args];
    233273    }
    234274   
     275    args[next_arg] = Gatherer.config.getScriptPath() + "exportcol.pl";
     276    next_arg++;
     277    if (has_title) {
     278        args[next_arg] = "-cdname"; next_arg++;
     279        args[next_arg] = cd_title; next_arg++;
     280    }
     281    for (int i=0; i<num_collections;i++,next_arg++) {
     282        args[next_arg] = ((CollectionEntry)selected_collections.get(i)).getName();
     283    }
     284   
     285    Gatherer.print("export command = ");
     286    for (int i=0; i<args.length; i++) {
     287        Gatherer.print(args[i]+" ");
     288    }
     289    Gatherer.println("");
    235290    GShell process = new GShell(args, GShell.EXPORT, 3, this, null, GShell.GSHELL_EXPORT);
    236     //process.addGShellListener(this);
     291    process.addGShellListener(this);
    237292    process.run(); // Don't bother threading this... yet
    238293    Gatherer.println("ExportCollectionPrompt.exportCollection().return");
     
    244299     */
    245300    public void resultPrompt(boolean success, String extra) {
     301    success = true;
    246302    args = new String[2];
    247     args[0] = collection.getName();
    248     args[1] = "export_"+collection.getName();
     303    StringBuffer coll_names = new StringBuffer();
     304    for (int i=0; i<selected_collections.size();i++) {
     305        if (i>0) {
     306        coll_names.append(", ");
     307        }
     308        coll_names.append(((CollectionEntry)selected_collections.get(i)).getName());
     309    }
     310   
     311    args[0] = coll_names.toString();
     312    if(cd_title.equals("")) {
     313        args[1] = "exported_collections";
     314    } else {
     315        args[1] = "exported_"+cd_title.replaceAll("\\s","");
     316    }
    249317    if (success) {
    250318        JOptionPane.showMessageDialog(prompt,Dictionary.get("ExportCollectionPrompt.Successful_Export", args)+"\n"+extra, Dictionary.get("ExportCollectionPrompt.Successful_Title"),JOptionPane.INFORMATION_MESSAGE);
     
    277345            if (config != null) {
    278346                CollectionEntry col = new CollectionEntry(collections[i].getName(), config);
    279                 list_model.addElement(col);
     347                //list_model.addElement(col);
     348                all_collections.add(col);
    280349            }   
    281350            }
     
    295364    if (message.startsWith("exportcol.pl>")) {
    296365        message = message.substring(13);
    297         System.err.println("message = "+event.getMessage());
     366        Gatherer.println("message = "+event.getMessage());
    298367        error_message.append(message);
    299368        error_message.append("\n");
     
    342411        ok_button.setEnabled(false);
    343412        if(!list.isSelectionEmpty()) {
    344         collection = (CollectionEntry) list.getSelectedValue();
     413        collection = (CollectionEntry) ((Entry)list.getSelectedValue()).getObject();
    345414        args = new String[5];
    346415        args[0] = collection.getTitle();
     
    370439     */
    371440    public void actionPerformed(ActionEvent event) {
     441        // make sure there are some colls specified
     442        selected_collections = list.getSelected();
    372443        error_message = new StringBuffer();
    373444       
     
    380451
    381452        // Export the selected collection.
    382         exportCollection();
     453        exportCollections();
    383454       
    384455        // unset the cursor
Note: See TracChangeset for help on using the changeset viewer.