Changeset 9114


Ignore:
Timestamp:
2005-02-18T16:09:11+13:00 (19 years ago)
Author:
kjdon
Message:

added new dummy doc creation functionality

File:
1 edited

Legend:

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

    r8783 r9114  
    4343import org.greenstone.gatherer.collection.CollectionTreeNode;
    4444import org.greenstone.gatherer.gui.LongProgressBar;
    45 import org.greenstone.gatherer.gui.NewFolderPrompt;
     45import org.greenstone.gatherer.gui.NewFolderOrFilePrompt;
    4646import org.greenstone.gatherer.gui.tree.DragTree;
    4747import org.greenstone.gatherer.util.DragComponent;
     
    5353 */
    5454public class FileManager {
     55
     56    public static int FILE_TYPE = 0;
     57    public static int FOLDER_TYPE = 1;
    5558
    5659    static public int countFolderDepth(File file) {
     
    125128    }
    126129
     130    public void newDummyDoc(DragTree tree, CollectionTreeNode parent_node){
     131    newFolderOrDummyDoc(tree, parent_node, FILE_TYPE);
     132    }
     133
    127134    public void newFolder(DragTree tree, CollectionTreeNode parent_node) {
     135    newFolderOrDummyDoc(tree, parent_node, FOLDER_TYPE);
     136    }
     137    protected void newFolderOrDummyDoc(DragTree tree, CollectionTreeNode parent_node, int type) {
    128138    // Ask the user for the directories name.
    129     NewFolderPrompt new_folder_prompt = new NewFolderPrompt(parent_node);
     139    String extension = "";
     140    if (type == FILE_TYPE) {
     141        extension = ".nul";
     142    }
     143    NewFolderOrFilePrompt new_folder_prompt = new NewFolderOrFilePrompt(parent_node, type, extension);
    130144    String name = new_folder_prompt.display();
    131145    new_folder_prompt.dispose();
     
    136150        File folder_file = new File(parent_node.getFile(), name);
    137151        //... check if it already exists.
    138         if(folder_file.exists()) {
    139         JOptionPane.showMessageDialog(Gatherer.g_man, Dictionary.get("FileActions.Folder_Already_Exists", name), Dictionary.get("General.Error"), JOptionPane.ERROR_MESSAGE);
     152        if(folder_file.exists()) {
     153        if (type == FILE_TYPE) {
     154            JOptionPane.showMessageDialog(Gatherer.g_man, Dictionary.get("FileActions.File_Already_Exists_No_Create", name), Dictionary.get("General.Error"), JOptionPane.ERROR_MESSAGE);
     155        } else {
     156            JOptionPane.showMessageDialog(Gatherer.g_man, Dictionary.get("FileActions.Folder_Already_Exists", name), Dictionary.get("General.Error"), JOptionPane.ERROR_MESSAGE);
     157        }
    140158        }
    141159        // Otherwise create it.
    142160        else {
    143         folder_file.mkdirs();
    144 
    145         // Update the parent node to show the new folder
    146         parent_node.refresh();
    147 
    148         // Refresh workspace tree (collection tree is done automatically)
    149         Gatherer.g_man.refreshWorkspaceTree(DragTree.COLLECTION_CONTENTS_CHANGED);
    150         }
     161        try {
     162            if (type == FILE_TYPE) {
     163            folder_file.createNewFile();
     164            } else {
     165            folder_file.mkdirs();
     166            }
     167            // Update the parent node to show the new folder
     168            parent_node.refresh();
     169           
     170            // Refresh workspace tree (collection tree is done automatically)
     171            Gatherer.g_man.refreshWorkspaceTree(DragTree.COLLECTION_CONTENTS_CHANGED);
     172        } catch (Exception e) {
     173            if (type == FILE_TYPE) {
     174            JOptionPane.showMessageDialog(Gatherer.g_man, Dictionary.get("FileActions.File_Create_Error", name), Dictionary.get("General.Error"), JOptionPane.ERROR_MESSAGE);
     175            } else {
     176            JOptionPane.showMessageDialog(Gatherer.g_man, Dictionary.get("FileActions.Folder_Create_Error", name), Dictionary.get("General.Error"), JOptionPane.ERROR_MESSAGE);
     177            }
     178        }
     179        }
     180       
    151181        folder_file = null;
    152182        model = null;
Note: See TracChangeset for help on using the changeset viewer.