Ignore:
Timestamp:
2010-08-11T21:28:34+12:00 (14 years ago)
Author:
ak19
Message:

Ticket #152: Allowing different paths to collect dir so that GLI can work with collect dirs on pen drives. NONE OF THESE CHANGES ARE FOR Client-GLI AS YET. 1. Preferences (Connection tab), Open and New Collection dialogs allow one to change the current collect directory containing the collections to select from. 2. New Collection dialog allows one to base a new collection on an existing collection in a collect dir other than the current collect dir. 3. Collections in the Documents in Greenstone Collections Workspace Tree Node now have two additional rightclick options: to move and copy these collections to another location.

Location:
main/trunk/gli/src/org/greenstone/gatherer/file
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • main/trunk/gli/src/org/greenstone/gatherer/file/FileManager.java

    r22410 r22605  
    6262    static private FileQueue file_queue = null;
    6363
    64     public static int FILE_TYPE = 0;
    65     public static int FOLDER_TYPE = 1;
     64    public static final int COPY = 0;
     65    public static final int MOVE = 1;
     66
     67    public static final int FILE_TYPE = 0;
     68    public static final int FOLDER_TYPE = 1;
    6669    protected static File startup_directory = null;
    6770
     
    129132    }
    130133
     134    /** For moving and copying of folders. */
     135    public void action(File sourceFolder, File targetFolder, int operation) {
     136    (new SimpleFileTask(sourceFolder, targetFolder, operation)).start();
     137    }
     138   
    131139
    132140    /** Retrieves the file queue object. */
     
    136144    }
    137145
     146    /** Performs the simple file task of moving or copying folders. */
     147    private class SimpleFileTask
     148    extends Thread
     149    {
     150    private File sourceFolder;
     151    private File targetFolder;
     152    int operation; // MOVE or COPY
     153
     154    public SimpleFileTask(File sourceFolder, File targetFolder, int operation)
     155    {
     156        this.sourceFolder = sourceFolder;       
     157        this.targetFolder = targetFolder;
     158        this.operation = operation;
     159    }
     160
     161
     162    public void run()
     163    {
     164        // check if we're moving or overwriting the current collection
     165        String currentColPath = Gatherer.getCollectDirectoryPath()+CollectionManager.getLoadedCollectionName();
     166        if(currentColPath.equals(sourceFolder.getAbsolutePath())
     167           || currentColPath.equals(targetFolder.getAbsolutePath())) {
     168        Gatherer.g_man.saveThenCloseCurrentCollection();
     169        }
     170       
     171        // if moving, try a simple move operation (if it works, it
     172        // shouldn't take long at all and doesn't need a progress bar)
     173        if(operation == MOVE && sourceFolder.renameTo(targetFolder)) {
     174        //System.err.println("**** A simple renameTo() worked.");
     175        WorkspaceTreeModel.refreshGreenstoneCollectionsNode();
     176        return;
     177        }
     178
     179        // Reset the progress bar and set it to indeterminate while calculating its size
     180        GProgressBar progress_bar = file_queue.getProgressBar();
     181        progress_bar.reset();
     182        progress_bar.setIndeterminate(true);
     183
     184        String status = "FileActions.Moving";
     185        if(operation == COPY) {
     186        status = "FileActions.Copying";     
     187        }
     188        progress_bar.setString(Dictionary.get(status));
     189        file_queue.getFileStatus().setText(Dictionary.get(status,
     190                                  file_queue.formatPath(status,
     191                                     sourceFolder.getAbsolutePath(),
     192                                     file_queue.getFileStatus().getSize().width)));
     193
     194        // do the move or copy operation
     195        try {
     196        //System.err.println("**** Copying " + sourceFolder + " to: " + targetFolder);
     197        file_queue.copyDirectoryContents(sourceFolder, targetFolder);       
     198        } catch(Exception e) {
     199        JOptionPane.showMessageDialog(Gatherer.g_man, e.getMessage(),
     200                          "Can't perform file operation", JOptionPane.ERROR_MESSAGE);
     201
     202        progress_bar.setIndeterminate(false);
     203        progress_bar.clear();
     204        return;
     205        }
     206       
     207        // if moving, delete the original source folder and
     208        // update the docs in GS collections node in the workspace tree
     209       
     210        if(operation == MOVE) {
     211        Utility.delete(sourceFolder);
     212        WorkspaceTreeModel.refreshGreenstoneCollectionsNode();
     213        }
     214
     215
     216        progress_bar.setIndeterminate(false);
     217        progress_bar.clear();
     218        file_queue.getFileStatus().setText(Dictionary.get("FileActions.No_Activity"));
     219        progress_bar.setString(Dictionary.get("FileActions.No_Activity"));
     220    }
     221    }
    138222
    139223    private class FileTask
  • main/trunk/gli/src/org/greenstone/gatherer/file/FileQueue.java

    r12115 r22605  
    162162     * @return A path <strong>String</strong> no longer than width.
    163163     */
    164     private String formatPath(String key, String raw, int width)
     164    String formatPath(String key, String raw, int width) // package access
    165165    {
    166166    JLabel label = new JLabel(Dictionary.get(key, raw));
  • main/trunk/gli/src/org/greenstone/gatherer/file/WorkspaceTree.java

    r22410 r22605  
    3939import org.greenstone.gatherer.gui.CreateShortcutPrompt;
    4040import org.greenstone.gatherer.gui.tree.DragTree;
     41import org.greenstone.gatherer.util.Utility;
    4142
    4243
     
    217218    private JMenuItem rename = null;
    218219    private JMenuItem replace = null;
     220    private JMenuItem copy_collection = null;
     221    private JMenuItem move_collection = null;
    219222
    220223
     
    343346        // Or map any other level directories
    344347        else {
     348            // --- Options for Documents In Greenstone Collections (greenstone_collections_node) ---
     349            // all subfolder of Documents In Greenstone Collections can be copied and moved
     350            WorkspaceTreeNode secondLevelNode = (WorkspaceTreeNode) path.getPathComponent(1);
     351
     352            if (secondLevelNode.toString().equals(Dictionary.get("Tree.World"))) {
     353            // Can move and copy the collection folders across
     354            copy_collection = new JMenuItem(Dictionary.get("Menu.Copy_Collection"), KeyEvent.VK_P);
     355            copy_collection.addActionListener(this);
     356            add(copy_collection);
     357           
     358            move_collection = new JMenuItem(Dictionary.get("Menu.Move_Collection"), KeyEvent.VK_M);
     359            move_collection.addActionListener(this);
     360            add(move_collection);           
     361            }
     362
    345363            create_shortcut = new JMenuItem(Dictionary.get("MappingPrompt.Map"), KeyEvent.VK_S);
    346364            create_shortcut.addActionListener(this);
     
    386404        Gatherer.f_man.openFileInExternalApplication(node.getFile());
    387405        }
     406       
     407        // Copy or move a collection from Documents in Greenstone Collections
     408        else if (source == move_collection || source == copy_collection) {
     409
     410        JFileChooser chooser = new JFileChooser(Gatherer.getCollectDirectoryPath());
     411        chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);       
     412        chooser.setDialogTitle(Dictionary.get("FileActions.ChooseDestinationDirectory"));
     413        int returnVal = chooser.showOpenDialog(Gatherer.g_man.gather_pane);
     414
     415        if(returnVal == JFileChooser.APPROVE_OPTION) {         
     416
     417            // the node that the user rightclicked on ends up
     418            // being the col's import folder
     419            File sourceFolder = node.getFile();
     420            if(sourceFolder.getName().equals("import")) {
     421            sourceFolder = sourceFolder.getParentFile();
     422            }
     423            String target = chooser.getSelectedFile().getAbsolutePath();
     424            File targetFolder = new File(target+File.separator+sourceFolder.getName());
     425           
     426            // some sanity checks
     427            if(targetFolder.equals(sourceFolder)) { // directory has not changed. No copy/move performed
     428            JOptionPane.showMessageDialog(Gatherer.g_man,
     429                              "Can't move " + sourceFolder + " " + "to itself\n(" + targetFolder + ").",
     430                              "Source and destination directories are the same",
     431                              JOptionPane.ERROR_MESSAGE);
     432            return;
     433            } else if(targetFolder.exists()) { // option to overwrite or not
     434            if(JOptionPane.showConfirmDialog(Gatherer.g_man,
     435                             "Directory " + targetFolder + " already exists. Overwrite?",
     436                             "Destination directory already exists",
     437                             JOptionPane.YES_NO_OPTION) == JOptionPane.NO_OPTION) {
     438                return;
     439            }
     440            // else can overwrite: delete the existing targetfolder before copying/moving
     441            Utility.delete(targetFolder);
     442            }
     443           
     444            int operation = (source == move_collection) ? FileManager.MOVE : FileManager.COPY;
     445            Gatherer.f_man.action(sourceFolder, targetFolder, operation);
     446        }
     447        }
    388448    }
    389449    }
Note: See TracChangeset for help on using the changeset viewer.