Changeset 4677


Ignore:
Timestamp:
2003-06-16T11:10:16+12:00 (21 years ago)
Author:
kjdon
Message:

added back in all my changes that Johns cvs didn't recognise and so he consequently clobbered.

File:
1 edited

Legend:

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

    r4675 r4677  
    4343import org.greenstone.gatherer.Gatherer;
    4444import org.greenstone.gatherer.collection.Collection;
     45import org.greenstone.gatherer.gui.ModalDialog;
     46import org.greenstone.gatherer.gui.SimpleMenuBar;
    4547import org.greenstone.gatherer.util.ArrayTools;
     48import org.greenstone.gatherer.util.GSDLSiteConfig;
    4649import org.greenstone.gatherer.util.Utility;
    4750/** This class provides the functionality to delete current collections from the GSDLHOME/collect/ directory. The user chooses the collection from a list, where each entry also displays details about itself, confirms the delete of a collection by checking a checkbox then presses the ok button to actually delete the collection.
     
    5053 */
    5154public class DeleteCollectionPrompt
    52     extends JDialog {
     55    extends ModalDialog {
    5356    /** The currently selected collection for deletion. */
    54     private CollectionConfiguration collection = null;
     57    private CollectionEntry collection = null;
    5558    /** The model behind the list. */
    5659    private DefaultListModel list_model = null;
     
    7376    /** A string array used to pass arguments to the phrase retrieval method. */
    7477    private String args[] = null;
     78
     79    private boolean current_coll_deleted = false;
    7580    /** The size of the delete prompt screen. */
    7681    public static final Dimension SIZE = new Dimension(500, 500);
     
    8287     */
    8388    public DeleteCollectionPrompt() {
    84     super();
     89    super(Gatherer.g_man);
    8590    this.close_button = new JButton(get("General.Close", null));
    8691    this.confirmation = new JCheckBox(get("Confirm_Delete", null));
     
    95100    this.setSize(SIZE);
    96101    this.setTitle(get("Title", null));
     102    this.setJMenuBar(new SimpleMenuBar("0")); // need to find an appropriate help page to open at
    97103    close_button.addActionListener(new CloseButtonListener());
    98104    confirmation.addActionListener(new ConfirmationCheckBoxListener());
     
    121127    prompt = null;
    122128    }
    123     /** This method causes the modal prompt to be displayed. */
    124     public void display() {
     129    /** This method causes the modal prompt to be displayed.
     130     * returns true if it has deleted the collection that is currently open*/
     131    public boolean display() {
    125132    // Central pane
    126133    JPanel list_pane = new JPanel(new BorderLayout());
     
    163170    Dimension screen_size = Gatherer.config.screen_size;
    164171    this.setLocation((screen_size.width - SIZE.width) / 2, (screen_size.height - SIZE.height) / 2);
    165     this.show();
    166     }
    167 
    168     /** Shows a delete complete prompt.
     172    this.setVisible(true); // blocks until the dialog is killed
     173    return current_coll_deleted;
     174   
     175    }
     176    /** Shows a delete complete prompt.
    169177      * @param success A <strong>boolean</strong> indicating if the collection was successfully deleted.
    170178      * @see org.greenstone.gatherer.collection.Collection
     
    180188    }
    181189    }
    182 
    183190    /** Retrieves a phrase from the <strong>Dictionary</strong> in <strong>Gatherer</strong>.
    184191      * @param key A <strong>String</strong> used to match against a specific phrase in the dictionary.
     
    204211    File collect_directory = new File(collect_directory_name);
    205212    if(collect_directory.exists()) {
    206         // Now for each child directory see if it contains a .col file and if so try to load it..
     213        // Now for each child directory see if it contains a .col file and
     214        // if so try to load it..
    207215        File collections[] = collect_directory.listFiles();
    208216        ArrayTools.sort(collections);
    209217        for(int i = 0; collections != null && i < collections.length; i++) {
    210         File children[] = collections[i].listFiles();
    211         for(int j = 0; children != null && j < children.length; j++) {
    212             if(children[j].getAbsolutePath().endsWith(".col")) {
    213             list_model.addElement(new CollectionConfiguration(children[j]));
    214             }
     218        File config_file = Utility.findConfigFile(collections[i]);
     219        if (config_file != null) {
     220            CollectionConfiguration config = new CollectionConfiguration(config_file);
     221            if (config != null) {
     222            CollectionEntry col = new CollectionEntry(collections[i].getName(), config);
     223            list_model.addElement(col);
     224            }   
    215225        }
    216226        }
     
    219229    }
    220230    /** A button listener implementation, which listens for actions on the close button and disposes of the dialog when detected. */
    221     private class CloseButtonListener
     231    private class CloseButtonListener 
    222232    implements ActionListener {
    223233    /** Any implementation of ActionListener must include this method so we can be informed when the button is actioned.
     
    230240    /** This private class listens for selection events in from the list and then displays the appropriate details for that collection.
    231241      */
    232     private class CollectionListListener
     242    private class CollectionListListener 
    233243    implements ListSelectionListener {
    234244    /** Any implementation of ListSelectionListener must include this method so we can be informed when the list selection changes.
     
    238248        if(!list.isSelectionEmpty()) {
    239249        confirmation.setEnabled(true);
    240         collection = (CollectionConfiguration) list.getSelectedValue();
    241         args = new String[5];
    242         args[0] = collection.getName();
    243         args[1] = collection.getShortName();
     250        collection = (CollectionEntry) list.getSelectedValue();
     251        args = new String[4];
     252        args[0] = collection.getTitle();
     253        args[1] = collection.getName();
    244254        args[2] = collection.getCreator();
    245255        args[3] = collection.getMaintainer();
    246256        args[4] = collection.getDescription();
    247257        details.setText(get("Details", args));
     258        details.setCaretPosition(0);
    248259        }
    249260        else {
     
    267278        }
    268279    }
    269     }
     280    }         
    270281    /** The OK button listener implementation. */
    271     private class OKButtonListener
     282    private class OKButtonListener 
    272283    implements ActionListener {
    273284    /** Any implementation of ActionListener must include this method so we can be informed when the button is actioned.
     
    278289     */
    279290    public void actionPerformed(ActionEvent event) {
    280                 // Delete the selected collection.
    281         File delete_me = collection.getFile().getParentFile().getParentFile();
     291        // Delete the selected collection.
     292
     293        // first of all we must release it from the local library
     294        if(Gatherer.config.exec_file != null) {
     295        ///ystem.err.println("Local Library Found!");
     296        Gatherer.g_man.preview_pane.configServer(GSDLSiteConfig.RELEASE_COMMAND + collection.getName());
     297        }
     298
     299        File delete_me = new File(Utility.getCollectionDir(Gatherer.config.gsdl_path) + collection.getName() + File.separator);
    282300        if(Utility.delete(delete_me)) {
     301        if (Gatherer.c_man.getCollection()!=null && collection.getName().equals(Gatherer.c_man.getCollection().getName())) {
     302            current_coll_deleted = true;
     303        }
     304
    283305        resultPrompt(true);
    284306        list_model.removeElement(collection);
     
    294316    }
    295317    }
     318
     319    private class CollectionEntry {
     320
     321    private String name = null;
     322    private CollectionConfiguration config = null;
     323
     324    public CollectionEntry(String name, CollectionConfiguration config) {
     325        this.name = name;
     326        this.config = config;
     327    }
     328
     329    public String getName() {
     330        return name;
     331    }
     332
     333    public String getTitle() {
     334        return config.getName();
     335    }
     336
     337    public String getCreator() {
     338        return config.getCreator();
     339    }
     340
     341    public String getDescription() {
     342        return config.getDescription();
     343    }
     344   
     345    public String getMaintainer() {
     346        return config.getMaintainer();
     347    }
     348    public String toString() {
     349        return config.getName();
     350       
     351    }
     352    }
    296353}
    297354
Note: See TracChangeset for help on using the changeset viewer.