Changeset 4675 for trunk/gli/src/org/greenstone/gatherer/collection
- Timestamp:
- 2003-06-16T10:47:06+12:00 (21 years ago)
- Location:
- trunk/gli/src/org/greenstone/gatherer/collection
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gli/src/org/greenstone/gatherer/collection/CollectionConfiguration.java
r4366 r4675 14 14 private Element maintainer_element; 15 15 private Element name_element; 16 private File file; 16 17 private String creator; 17 18 private String description; … … 20 21 21 22 public CollectionConfiguration(File file) { 23 this.file = file; 22 24 try { 23 25 String filename = file.getName().toLowerCase(); 24 26 if(filename.endsWith(".xml")) { 25 27 26 28 } 27 29 else if(filename.endsWith(".cfg")) { … … 56 58 String language = temp.substring(temp.indexOf("=") + 1, temp.length() - 1); 57 59 if(name == null || language.equalsIgnoreCase(Gatherer.dictionary.getLanguage())) { 58 name = Utility.decodeGreenstone(tokenizer.nextToken()); 60 name = Utility.decodeGreenstone(tokenizer.nextToken()); 59 61 } 60 62 } … … 101 103 ///ystem.err.println("creator = " + creator); 102 104 ///ystem.err.println("maintainer = " + maintainer); 103 ///ystem.err.println("description = " + description); 105 ///ystem.err.println("description = " + description); 104 106 } 105 107 catch(Exception error) { … … 131 133 } 132 134 135 public File getFile() { 136 return file; 137 } 138 133 139 public String getMaintainer() { 134 140 String result = ""; … … 153 159 } 154 160 161 /** Retrieve the short name for this collection which, given this current file is in <col_name>/etc/collect.cfg, is the name of this file's parent file's parent. 162 * @return the short name of this collection as a String 163 */ 164 public String getShortName() { 165 return file.getParentFile().getParentFile().getName(); 166 } 167 155 168 public void setName(String name) { 156 169 /** @todo */ 157 170 } 171 172 /** Display the title for this collection. */ 173 public String toString() { 174 return getName(); 175 } 158 176 } -
trunk/gli/src/org/greenstone/gatherer/collection/CollectionManager.java
r4673 r4675 103 103 104 104 private int special_case = -1; 105 /** Holds a reference to the thread responsible for closing the collection. If non-null then only calls from the given thread will see the collection is non-ready. All other threads will have to wait until closing thread, and all of it consequential calls, are completely finished. */ 106 private Thread closing_thread = null; 107 105 108 /** The name of the standard lock file. */ 106 109 static final public String LOCK_FILE = "gatherer.lck"; … … 142 145 */ 143 146 public void buildCollection() { 144 Gatherer.println(" Building collection");147 Gatherer.println("CollectionManager.buildCollection()"); 145 148 building = true; 146 149 … … 162 165 shell.addGShellListener(Gatherer.g_man.create_pane); 163 166 shell.start(); 167 Gatherer.println("CollectionManager.buildCollection().return"); 164 168 } 165 169 /** Used to determine whether the currently active collection has been built. … … 178 182 */ 179 183 public void closeCollection() { 184 Gatherer.println("Close collection: " + collection.getName()); 185 // We set the closing thread, as it should be the only one who can actually see the collection is closed, at least until the closing thread expires. 186 closing_thread = Thread.currentThread(); 180 187 // System.err.println("Closing collection..."); 181 188 // Remove the lock on this file, then remove the collection. … … 190 197 Gatherer.g_man.collectionChanged(false); 191 198 // System.err.println("Closed collection."); 199 // All of the consequences of a close should have been processed by now, so others should now see the collection as non-ready. 200 closing_thread = null; 192 201 } 193 202 … … 199 208 } 200 209 201 /** Used to set the current collection to the given collection. Note that this call should -always- be proceeded by a ready call, and if the colection is ready and the saved flag is unset then the user should be prompted to save. Also note that this method creates yet another GShell to run buildcol.pl. 210 /** Used to set the current collection to the given collection. Note that this call should -always- be proceeded by a ready call, and if the colection is ready and the saved flag is unset then the user should be prompted to save. Also note that this method creates yet another GShell to run buildcol.pl. 202 211 * @param description a description of the collection as a String 203 212 * @param email the email address of the author/maintainer as a String … … 243 252 progress.setNote(get("Log_Created")); 244 253 } 245 254 246 255 progress.setProgress(2); 247 256 … … 707 716 */ 708 717 public void importCollection() { 718 Gatherer.println("CollectionManager.importCollection()"); 709 719 if(!saved()) { 710 720 // Force save. … … 742 752 shell.start(); 743 753 } 754 Gatherer.println("CollectionManager.importCollection().return"); 744 755 } 745 756 /** Attempts to load the given collection. Currently uses simple serialization of the collection class. … … 890 901 */ 891 902 public synchronized void processBegun(GShellEvent event) { 903 Gatherer.println("CollectionManager.processBegun(" + event.getType() + ")"); 892 904 ///ystem.err.println("ProcessBegun " + event.getType()); 893 905 // If this is one of the types where we wish to lock user control … … 901 913 */ 902 914 public synchronized void processComplete(GShellEvent event) { 915 Gatherer.println("CollectionManager.processComplete(" + event.getType() + ")"); 903 916 ///ystem.err.println("ProcessComplete " + event.getType()); 904 917 Gatherer.g_man.lockCollection((event.getType() == GShell.IMPORT), false); … … 936 949 * @return A <i>boolean</i> which is <i>true</i> to indicate a collection has been loaded and thus the collection is ready for editing, <i>false</i> otherwise. 937 950 */ 938 public boolean ready() { 939 if(collection != null) { 940 return true; 941 } 942 return false; 943 } 951 952 public synchronized boolean ready() { 953 if(collection != null) { 954 return true; 955 } 956 else { 957 return false; 958 } 959 } 960 961 public synchronized boolean reallyReady() { 962 if(collection == null) { 963 Gatherer.println("Called reallyReady() when collection was null."); 964 Gatherer.println("Closing thread = " + closing_thread); 965 Gatherer.println("This thread = " + Thread.currentThread()); 966 Gatherer.println("Thus we return: " + (closing_thread == null || closing_thread == Thread.currentThread() ? "not ready" : "ready")); 967 } 968 // If the closing thread is non-null we should only allow that thread to see the collection as closed. 969 if(closing_thread != null) { 970 // Only the closing thread sees the truth 971 if(Thread.currentThread() == closing_thread) { 972 return (collection == null); 973 } 974 // All other threads are told a lie. 975 else { 976 return true; 977 } 978 } 979 else { 980 if(collection != null) { 981 return true; 982 } 983 else { 984 return false; 985 } 986 } 987 } 944 988 /** Called to refresh the models upon which the trees are based. 945 989 * @see org.greenstone.gatherer.collection.Collection … … 1001 1045 */ 1002 1046 public void saveCollection(boolean close_after, boolean exit_after) { 1047 Gatherer.println("Save collection: " + collection.getName()); 1003 1048 try { 1004 1049 SaveCollectionTask save_task = new SaveCollectionTask(collection, close_after, exit_after); 1050 save_task.start(); 1005 1051 // Run this in the same thread 1006 save_task.run();1052 //save_task.run(); 1007 1053 } 1008 1054 catch(Exception error) { … … 1088 1134 1089 1135 try { 1090 // We have to ensure that the local library 1136 // We have to ensure that the local library 1091 1137 if(Gatherer.config.exec_file != null) { 1092 1138 ///ystem.err.println("Local Library Found!"); -
trunk/gli/src/org/greenstone/gatherer/collection/DeleteCollectionPrompt.java
r4660 r4675 43 43 import org.greenstone.gatherer.Gatherer; 44 44 import org.greenstone.gatherer.collection.Collection; 45 import org.greenstone.gatherer.gui.ModalDialog;46 import org.greenstone.gatherer.gui.SimpleMenuBar;47 45 import org.greenstone.gatherer.util.ArrayTools; 48 import org.greenstone.gatherer.util.GSDLSiteConfig;49 46 import org.greenstone.gatherer.util.Utility; 50 47 /** 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. … … 53 50 */ 54 51 public class DeleteCollectionPrompt 55 extends ModalDialog {52 extends JDialog { 56 53 /** The currently selected collection for deletion. */ 57 private Collection Entrycollection = null;54 private CollectionConfiguration collection = null; 58 55 /** The model behind the list. */ 59 56 private DefaultListModel list_model = null; … … 76 73 /** A string array used to pass arguments to the phrase retrieval method. */ 77 74 private String args[] = null; 78 79 private boolean current_coll_deleted = false;80 75 /** The size of the delete prompt screen. */ 81 76 public static final Dimension SIZE = new Dimension(500, 500); … … 87 82 */ 88 83 public DeleteCollectionPrompt() { 89 super( Gatherer.g_man);84 super(); 90 85 this.close_button = new JButton(get("General.Close", null)); 91 86 this.confirmation = new JCheckBox(get("Confirm_Delete", null)); … … 100 95 this.setSize(SIZE); 101 96 this.setTitle(get("Title", null)); 102 this.setJMenuBar(new SimpleMenuBar("0")); // need to find an appropriate help page to open at103 97 close_button.addActionListener(new CloseButtonListener()); 104 98 confirmation.addActionListener(new ConfirmationCheckBoxListener()); … … 127 121 prompt = null; 128 122 } 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() { 123 /** This method causes the modal prompt to be displayed. */ 124 public void display() { 132 125 // Central pane 133 126 JPanel list_pane = new JPanel(new BorderLayout()); … … 170 163 Dimension screen_size = Gatherer.config.screen_size; 171 164 this.setLocation((screen_size.width - SIZE.width) / 2, (screen_size.height - SIZE.height) / 2); 172 this.setVisible(true); // blocks until the dialog is killed 173 return current_coll_deleted; 174 175 } 176 /** Shows a delete complete prompt. 165 this.show(); 166 } 167 168 /** Shows a delete complete prompt. 177 169 * @param success A <strong>boolean</strong> indicating if the collection was successfully deleted. 178 170 * @see org.greenstone.gatherer.collection.Collection … … 188 180 } 189 181 } 182 190 183 /** Retrieves a phrase from the <strong>Dictionary</strong> in <strong>Gatherer</strong>. 191 184 * @param key A <strong>String</strong> used to match against a specific phrase in the dictionary. … … 199 192 return Gatherer.dictionary.get(key, args); 200 193 } 201 /** Attempts to load the given collection. Currently uses simple 202 * serialization of the collection class. 203 * @param location The path to the serialized collection. 204 */ 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 // } 194 224 195 /** Method to scan the collect directory retrieving and reloading each collection it finds, while building the list of known collections. 225 196 * @see org.greenstone.gatherer.Configuration … … 233 204 File collect_directory = new File(collect_directory_name); 234 205 if(collect_directory.exists()) { 235 // Now for each child directory see if it contains a .col file and 236 // if so try to load it.. 206 // Now for each child directory see if it contains a .col file and if so try to load it.. 237 207 File collections[] = collect_directory.listFiles(); 238 208 ArrayTools.sort(collections); 239 209 for(int i = 0; collections != null && i < collections.length; i++) { 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); 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])); 246 214 } 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 loaded253 //if(col != null) {254 // list_model.addElement(col);255 //}256 //}257 215 } 258 216 } … … 261 219 } 262 220 /** A button listener implementation, which listens for actions on the close button and disposes of the dialog when detected. */ 263 private class CloseButtonListener 221 private class CloseButtonListener 264 222 implements ActionListener { 265 223 /** Any implementation of ActionListener must include this method so we can be informed when the button is actioned. … … 272 230 /** This private class listens for selection events in from the list and then displays the appropriate details for that collection. 273 231 */ 274 private class CollectionListListener 232 private class CollectionListListener 275 233 implements ListSelectionListener { 276 234 /** Any implementation of ListSelectionListener must include this method so we can be informed when the list selection changes. … … 280 238 if(!list.isSelectionEmpty()) { 281 239 confirmation.setEnabled(true); 282 collection = (Collection Entry) list.getSelectedValue();283 args = new String[ 4];284 args[0] = collection.get Title();285 args[1] = collection.get Name();240 collection = (CollectionConfiguration) list.getSelectedValue(); 241 args = new String[5]; 242 args[0] = collection.getName(); 243 args[1] = collection.getShortName(); 286 244 args[2] = collection.getCreator(); 287 args[3] = collection.getDescription(); 245 args[3] = collection.getMaintainer(); 246 args[4] = collection.getDescription(); 288 247 details.setText(get("Details", args)); 289 details.setCaretPosition(0);290 248 } 291 249 else { … … 309 267 } 310 268 } 311 } 269 } 312 270 /** The OK button listener implementation. */ 313 private class OKButtonListener 271 private class OKButtonListener 314 272 implements ActionListener { 315 273 /** Any implementation of ActionListener must include this method so we can be informed when the button is actioned. … … 320 278 */ 321 279 public void actionPerformed(ActionEvent event) { 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 330 File delete_me = new File(Utility.getCollectionDir(Gatherer.config.gsdl_path) + collection.getName() + File.separator); 280 // Delete the selected collection. 281 File delete_me = collection.getFile().getParentFile().getParentFile(); 331 282 if(Utility.delete(delete_me)) { 332 if (collection.getName().equals(Gatherer.c_man.getCollection().getName())) {333 current_coll_deleted = true;334 }335 336 283 resultPrompt(true); 337 284 list_model.removeElement(collection); … … 347 294 } 348 295 } 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 }381 296 } 382 297
Note:
See TracChangeset
for help on using the changeset viewer.