Changeset 4660


Ignore:
Timestamp:
2003-06-13T16:58:59+12:00 (21 years ago)
Author:
kjdon
Message:

revamped the delete collection stuff so that it no longer uses serialised collections, but uses the config file to display stuff to teh user

File:
1 edited

Legend:

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

    r4366 r4660  
    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 Collection 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();
     172    this.setVisible(true); // blocks until the dialog is killed
     173    return current_coll_deleted;
     174   
    166175    }
    167176    /** Shows a delete complete prompt.
     
    194203      * @param location The path to the serialized collection.
    195204      */
    196     public Collection loadCollection(File file) {
    197     Collection col = null;
    198     try {
    199         FileInputStream fis = new FileInputStream(file);
    200         BufferedInputStream bin = new BufferedInputStream(fis);
    201         ObjectInputStream input = new ObjectInputStream(bin);
    202         col = (Collection) input.readObject();
    203         input.close();
    204         input = null;
    205         bin.close();
    206         bin = null;
    207         fis.close();
    208         fis = null;
    209     }
    210     catch (Exception error) {
    211         error.printStackTrace();
    212     }
    213     return col;
    214     }
     205//      public Collection loadCollection(File file) {
     206//      Collection col = null;
     207//      try {
     208//          FileInputStream fis = new FileInputStream(file);
     209//          BufferedInputStream bin = new BufferedInputStream(fis);
     210//          ObjectInputStream input = new ObjectInputStream(bin);
     211//          col = (Collection) input.readObject();
     212//          input.close();
     213//          input = null;
     214//          bin.close();
     215//          bin = null;
     216//          fis.close();
     217//          fis = null;
     218//      }
     219//      catch (Exception error) {
     220//          error.printStackTrace();
     221//      }
     222//      return col;
     223//      }
    215224    /** Method to scan the collect directory retrieving and reloading each collection it finds, while building the list of known collections.
    216225      * @see org.greenstone.gatherer.Configuration
     
    224233    File collect_directory = new File(collect_directory_name);
    225234    if(collect_directory.exists()) {
    226                 // Now for each child directory see if it contains a .col file and
    227                 // if so try to load it..
     235        // Now for each child directory see if it contains a .col file and
     236        // if so try to load it..
    228237        File collections[] = collect_directory.listFiles();
    229238        ArrayTools.sort(collections);
    230239        for(int i = 0; collections != null && i < collections.length; i++) {
    231         File children[] = collections[i].listFiles();
    232         for(int j = 0; children != null && j < children.length; j++) {
    233             if(children[j].getAbsolutePath().endsWith(".col")) {
    234             Collection col = loadCollection(children[j]);
    235             // If we've actually loaded
    236             if(col != null) {
    237                 list_model.addElement(col);
    238             }
     240        File config_file = Utility.findConfigFile(collections[i]);
     241        if (config_file != null) {
     242            CollectionConfiguration config = new CollectionConfiguration(config_file);
     243            if (config != null) {
     244            CollectionEntry col = new CollectionEntry(collections[i].getName(), config);
     245            list_model.addElement(col);
    239246            }
     247           
     248            //File children[] = collections[i].listFiles();
     249            //for(int j = 0; children != null && j < children.length; j++) {
     250            //if(children[j].getAbsolutePath().endsWith(".col")) {
     251            //Collection col = loadCollection(children[j]);
     252            // If we've actually loaded
     253            //if(col != null) {
     254            //   list_model.addElement(col);
     255            //}
     256            //}
    240257        }
    241258        }
     
    263280        if(!list.isSelectionEmpty()) {
    264281        confirmation.setEnabled(true);
    265         collection = (Collection) list.getSelectedValue();
     282        collection = (CollectionEntry) list.getSelectedValue();
    266283        args = new String[4];
    267284        args[0] = collection.getTitle();
    268285        args[1] = collection.getName();
    269         args[2] = collection.getEmail();
     286        args[2] = collection.getCreator();
    270287        args[3] = collection.getDescription();
    271288        details.setText(get("Details", args));
     289        details.setCaretPosition(0);
    272290        }
    273291        else {
     
    302320     */
    303321    public void actionPerformed(ActionEvent event) {
    304                 // Delete the selected collection.
     322        // Delete the selected collection.
     323
     324        // first of all we must release it from the local library
     325        if(Gatherer.config.exec_file != null) {
     326        ///ystem.err.println("Local Library Found!");
     327        Gatherer.g_man.preview_pane.configServer(GSDLSiteConfig.RELEASE_COMMAND + collection.getName());
     328        }
     329
    305330        File delete_me = new File(Utility.getCollectionDir(Gatherer.config.gsdl_path) + collection.getName() + File.separator);
    306331        if(Utility.delete(delete_me)) {
     332        if (collection.getName().equals(Gatherer.c_man.getCollection().getName())) {
     333            current_coll_deleted = true;
     334        }
     335
    307336        resultPrompt(true);
    308337        list_model.removeElement(collection);
     
    318347    }
    319348    }
     349
     350    private class CollectionEntry {
     351
     352    private String name = null;
     353    private CollectionConfiguration config = null;
     354
     355    public CollectionEntry(String name, CollectionConfiguration config) {
     356        this.name = name;
     357        this.config = config;
     358    }
     359
     360    public String getName() {
     361        return name;
     362    }
     363
     364    public String getTitle() {
     365        return config.getName();
     366    }
     367
     368    public String getCreator() {
     369        return config.getCreator();
     370    }
     371
     372    public String getDescription() {
     373        return config.getDescription();
     374    }
     375   
     376    public String toString() {
     377        return config.getName();
     378       
     379    }
     380    }
    320381}
    321382
Note: See TracChangeset for help on using the changeset viewer.