Changeset 5164
- Timestamp:
- 2003-08-18T14:10:31+12:00 (21 years ago)
- Location:
- trunk/gli/src/org/greenstone/gatherer
- Files:
-
- 22 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gli/src/org/greenstone/gatherer/Configuration.java
r5045 r5164 56 56 public class Configuration 57 57 extends Hashtable { 58 59 static final public boolean COLLECTION_SPECIFIC = true; 60 static final public boolean GENERAL_SETTING = true; 61 62 /** The string identifying an argument's name attribute. */ 63 static final private String ARGUMENT_NAME = "name"; 64 /** The name of the general Gatherer configuration file. */ 65 static final private String CONFIG_XML = "config.xml"; 66 /** The name of the root element of the subtree containing gatherer configuration options. This is required as the document itself may contain several other subtrees of settings (such as in the case of a '.col' file). */ 67 static final private String GATHERER_CONFIG = "GathererConfig"; 68 /** The string identifying an argument element. */ 69 static final private String GATHERER_CONFIG_ARGUMENT = "Argument"; 70 /** The name of a Name Element. */ 71 static final private String NAME = "Name"; 72 /** The name of the other arguments element. */ 73 static final private String OTHER = "Other"; 74 /** The name of an information Element within the Other subtree. */ 75 static final private String OTHER_INFO = "Info"; 76 /** The name of the general Gatherer configuration template. */ 77 static final private String TEMPLATE_CONFIG_XML = "xml/config.xml"; 78 /** The first of two patterns used during tokenization, this pattern handles a comma separated list. */ 79 static final private String TOKENIZER_PATTERN1 = " ,\n\t"; 80 /** The second of two patterns used during tokenization, this pattern handles an underscore separated list. */ 81 static final private String TOKENIZER_PATTERN2 = "_\n\t"; 82 58 83 public File exec_file; 59 84 /** The path (or url) to the webserver which is serving the Greenstone collection. */ … … 78 103 private int cache_miss = 0; 79 104 public URL exec_address = null; 80 /** The string identifying an argument's name attribute. */ 81 static final private String ARGUMENT_NAME = "name"; 82 /** The name of the general Gatherer configuration file. */ 83 static final private String CONFIG_XML = "config.xml"; 84 /** The name of the root element of the subtree containing gatherer configuration options. This is required as the document itself may contain several other subtrees of settings (such as in the case of a '.col' file). */ 85 static final private String GATHERER_CONFIG = "GathererConfig"; 86 /** The string identifying an argument element. */ 87 static final private String GATHERER_CONFIG_ARGUMENT = "Argument"; 88 /** The name of a Name Element. */ 89 static final private String NAME = "Name"; 90 /** The name of the other arguments element. */ 91 static final private String OTHER = "Other"; 92 /** The name of an information Element within the Other subtree. */ 93 static final private String OTHER_INFO = "Info"; 94 /** The name of the general Gatherer configuration template. */ 95 static final private String TEMPLATE_CONFIG_XML = "xml/config.xml"; 96 /** The first of two patterns used during tokenization, this pattern handles a comma separated list. */ 97 static final private String TOKENIZER_PATTERN1 = " ,\n\t"; 98 /** The second of two patterns used during tokenization, this pattern handles an underscore separated list. */ 99 static final private String TOKENIZER_PATTERN2 = "_\n\t"; 105 100 106 /** Constructor. 101 107 * @param gsdl_path The path to the Greenstone directory as a <strong>String</strong>. … … 356 362 try { 357 363 String raw = getString(property, general); 358 364 // Locale is a underscore separated code. 359 365 StringTokenizer tokenizer = new StringTokenizer(raw, TOKENIZER_PATTERN2); 360 366 String language = tokenizer.nextToken(); 361 String country = tokenizer.nextToken(); 362 result = new Locale(language, country); 367 if(tokenizer.hasMoreTokens()) { 368 String country = tokenizer.nextToken(); 369 result = new Locale(language, country); 370 } 371 else { 372 result = new Locale(language); 373 } 363 374 } 364 375 catch(Exception error) { … … 433 444 /** Set the named property, from the specified configuration, using the given boolean value. */ 434 445 public void set(String property, boolean general, boolean value) { 446 if(property.startsWith("workflow")) { 447 System.err.println("Set property: " + property + ", general=" + general + ", value=" + value); 448 } 435 449 setString(property, general, (value ? "true" : "false")); 436 450 } … … 537 551 StringBuffer text = new StringBuffer(""); 538 552 text.append(value.getLanguage()); 539 text.append("_"); 540 text.append(value.getCountry()); 553 String country = value.getCountry(); 554 if(country != null && country.length() > 0) { 555 text.append("_"); 556 text.append(country); 557 } 558 country = null; 541 559 setString(property, general, text.toString()); 542 560 } … … 544 562 /** Sets the value of the named property argument using the given string. */ 545 563 public void setString(String property, boolean general, String value) { 546 ///atherer.println("Set configuration property: " + property + " = " + value + (general ? "" : " [Collection]"));564 Gatherer.println("Set configuration property: " + property + " = " + value + (general ? "" : " [Collection]")); 547 565 try { 548 566 Document document = null; … … 615 633 UIManager.put("CheckBox.background", new ColorUIResource(getColor("coloring.collection_heading_background", false))); 616 634 635 617 636 // Editable coloring 618 637 UIManager.put("ComboBox.background", new ColorUIResource(getColor("coloring.collection_tree_background", false))); // Indicate clickable … … 624 643 UIManager.put("Table.background", new ColorUIResource(getColor("coloring.collection_tree_background", false))); 625 644 UIManager.put("List.background", new ColorUIResource(getColor("coloring.collection_tree_background", false))); 645 UIManager.put("RadioButton.background", new ColorUIResource(getColor("coloring.collection_tree_background", false))); 646 626 647 // Selection color 627 648 UIManager.put("TabbedPane.selected", new ColorUIResource(getColor("coloring.collection_selection_background", false))); -
trunk/gli/src/org/greenstone/gatherer/Dictionary.java
r4928 r5164 103 103 // Load new dictionary 104 104 dictionary = ResourceBundle.getBundle(Utility.DICTIONARY, locale); 105 language = dictionary.getString("Language"); 106 System.err.println("Having loaded new dictionary: " + language); 105 107 // Refresh all registered component 108 System.err.println("Updating components"); 106 109 for(Iterator keys = keySet().iterator(); keys.hasNext(); ) { 107 110 Object component = keys.next(); -
trunk/gli/src/org/greenstone/gatherer/Gatherer.java
r5083 r5164 54 54 import org.greenstone.gatherer.gui.GUIManager; 55 55 import org.greenstone.gatherer.gui.Splash; 56 import org.greenstone.gatherer.gui.URLField; 56 57 import org.greenstone.gatherer.gui.WarningDialog; 57 58 import org.greenstone.gatherer.msm.MetadataSetManager; … … 81 82 public class Gatherer { 82 83 83 84 static final private String SKIN_DEFINITION_FILE = "lib/greenaqua/greenaqua.xml"; 84 85 85 86 /** Has the exit flag been set? <i>true</i> if so, <i>false</i> otherwise. */ … … 128 129 map.removeKeyStrokeBinding(enter); 129 130 } 130 131 132 131 133 132 /** Constructor. Make the three main modules, c_man, f_man and g_man, and any other necessary classes such as Dictionary. … … 597 596 WarningDialog dialog = new WarningDialog("warning.MissingEXEC", "general.exec_address", dictionary); 598 597 //NoSettingDialog dialog = new NoSettingDialog("warning.MissingEXEC", "NoSettingEXEC.Message", false, dictionary); 598 dialog.setValueField(new URLField(Gatherer.config.getColor("coloring.editable_foreground", false), Gatherer.config.getColor("coloring.editable_background", false), Gatherer.config.getColor("coloring.error_foreground", false), Gatherer.config.getColor("coloring.error_background", false))); 599 599 dialog.display(); 600 600 dialog.dispose(); -
trunk/gli/src/org/greenstone/gatherer/cdm/Argument.java
r4932 r5164 205 205 ElementWrapper element_wrapper = Gatherer.c_man.getCollection().msm.getElement(value); 206 206 if(element_wrapper != null) { 207 value = element_wrapper. toString();207 value = element_wrapper.getName(); 208 208 } 209 209 } -
trunk/gli/src/org/greenstone/gatherer/cdm/ArgumentConfiguration.java
r4932 r5164 587 587 return true; 588 588 case Argument.METADATUM: 589 argument.setValue(((ElementWrapper)((JComboBox)value).getSelectedItem()).getName()); 590 // Kinda lucked out here. Its impossible not to choose an entry from these comboboxes as they are restricted. 591 return true; 589 592 case Argument.HIERARCHY: 590 593 argument.setValue(((JComboBox)value).getSelectedItem().toString()); -
trunk/gli/src/org/greenstone/gatherer/cdm/CollectionConfiguration.java
r5087 r5164 349 349 public Element getBeta() { 350 350 Element element = getOrCreateElementByTagName(COLLECTIONMETADATA_BETA_ELEMENT, null, null); 351 element.setAttribute(NAME_ATTRIBUTE, COLLECTIONMETADATA_BETA_STR); 351 352 element.setAttribute(SPECIAL_ATTRIBUTE, TRUE_STR); 352 353 return element; … … 355 356 public Element getCreator() { 356 357 Element element = getOrCreateElementByTagName(COLLECTIONMETADATA_CREATOR_ELEMENT, null, null); 358 element.setAttribute(NAME_ATTRIBUTE, COLLECTIONMETADATA_CREATOR_STR); 357 359 element.setAttribute(SPECIAL_ATTRIBUTE, TRUE_STR); 358 360 return element; … … 378 380 public Element getMaintainer() { 379 381 Element element = getOrCreateElementByTagName(COLLECTIONMETADATA_MAINTAINER_ELEMENT, null, null); 382 element.setAttribute(NAME_ATTRIBUTE, COLLECTIONMETADATA_MAINTAINER_STR); 380 383 element.setAttribute(SPECIAL_ATTRIBUTE, TRUE_STR); 381 384 return element; … … 393 396 public Element getPublic() { 394 397 Element element = getOrCreateElementByTagName(COLLECTIONMETADATA_PUBLIC_ELEMENT, null, null); 398 element.setAttribute(NAME_ATTRIBUTE, COLLECTIONMETADATA_PUBLIC_STR); 395 399 element.setAttribute(SPECIAL_ATTRIBUTE, TRUE_STR); 396 400 return element; … … 581 585 // Create the element 582 586 Element element = document.createElement(name); 587 // If there was a property set it 588 if(conditional_attribute != null) { 589 element.setAttribute(conditional_attribute, required_value); 590 } 583 591 Node target_node = findInsertionPoint(element); 584 592 if(target_node != null) { … … 743 751 text.append(name_str); 744 752 text.append(SPACE_CHARACTER); 745 }746 String language_str = command_element.getAttribute(LANGUAGE_ATTRIBUTE);747 // If this is element is in english, and it is the first one found, we don't need to write the language argument.748 if(!language_str.equals(ENGLISH_LANGUAGE_STR) || known_metadata == null || known_metadata.contains(name_str)) {749 text.append(LBRACKET_CHARACTER);750 text.append(LANGUAGE_ARGUMENT);751 text.append(language_str);752 text.append(RBRACKET_CHARACTER);753 text.append(SPACE_CHARACTER);754 }755 if(known_metadata != null) {756 known_metadata.add(name_str);757 }758 language_str = null;753 String language_str = command_element.getAttribute(LANGUAGE_ATTRIBUTE); 754 // If this is element is in english, and it is the first one found, we don't need to write the language argument. 755 if(!language_str.equals(ENGLISH_LANGUAGE_STR) || known_metadata == null || known_metadata.contains(name_str)) { 756 text.append(LBRACKET_CHARACTER); 757 text.append(LANGUAGE_ARGUMENT); 758 text.append(language_str); 759 text.append(RBRACKET_CHARACTER); 760 text.append(SPACE_CHARACTER); 761 } 762 if(known_metadata != null) { 763 known_metadata.add(name_str); 764 } 765 language_str = null; 766 } 759 767 name_str = null; 760 768 // We don't wrap the email addresses in quotes, nor any string without spaces … … 1129 1137 command_element.setAttribute(NAME_ATTRIBUTE, name_str); 1130 1138 command_element.setAttribute(LANGUAGE_ATTRIBUTE, language_str); 1131 MSMUtils.setValue(command_element, value_str);1139 MSMUtils.setValue(command_element, Utility.encodeXML(value_str)); 1132 1140 } 1133 1141 else { … … 1182 1190 private Element parsePlugIn(String command_str) { 1183 1191 Element command_element = null; 1192 boolean use_metadata_files = false; 1184 1193 try { 1185 1194 CommandTokenizer tokenizer = new CommandTokenizer(command_str); … … 1190 1199 tokenizer.nextToken(); 1191 1200 // The next token is the type 1192 command_element.setAttribute(TYPE_ATTRIBUTE, tokenizer.nextToken()); 1201 String type = tokenizer.nextToken(); 1202 command_element.setAttribute(TYPE_ATTRIBUTE, type); 1193 1203 // Now we parse out the remaining arguments into a hashmapping from name to value 1194 1204 HashMap arguments = parseArguments(tokenizer); … … 1199 1209 String value = (String) arguments.get(name); // Can be null 1200 1210 Element option_element = document.createElement(OPTION_ELEMENT); 1211 if(name.substring(1).equals(USE_METADATA_FILES_ARGUMENT)) { 1212 use_metadata_files = true; 1213 } 1201 1214 option_element.setAttribute(NAME_ATTRIBUTE, name.substring(1)); 1202 1215 option_element.setAttribute(ASSIGNED_ATTRIBUTE, TRUE_STR); … … 1216 1229 value = null; 1217 1230 } 1231 // Finally if the type happened to be a RecPlug we ensure that the use metadata files argument is set 1232 if(type.equals(RECPLUG_STR) && !use_metadata_files) { 1233 Element option_element = document.createElement(OPTION_ELEMENT); 1234 option_element.setAttribute(NAME_ATTRIBUTE, USE_METADATA_FILES_ARGUMENT); 1235 option_element.setAttribute(ASSIGNED_ATTRIBUTE, TRUE_STR); 1236 option_element.setAttribute(CUSTOM_ATTRIBUTE, TRUE_STR); 1237 command_element.appendChild(option_element); 1238 option_element = null; 1239 } 1240 type = null; 1218 1241 names = null; 1219 1242 arguments = null; -
trunk/gli/src/org/greenstone/gatherer/cdm/CollectionMetaManager.java
r4932 r5164 106 106 107 107 public CollectionMeta getMetadatum(String name, boolean add_if_not_found) { 108 // /atherer.println("Get the metadata for " + name + " in the default language.");108 //Gatherer.println("Get the metadata for " + name + " in the default language."); 109 109 int size = getSize(); 110 110 for(int i = 0; i < size; i++) { 111 111 CollectionMeta metadatum = (CollectionMeta) getElementAt(i); 112 112 if(metadatum.getName().equals(name) && metadatum.getLanguage().equals(Gatherer.config.interface_language)) { 113 // /atherer.println("Found '" + metadatum + "'");113 //Gatherer.println("Found '" + metadatum + "'"); 114 114 return metadatum; 115 115 } 116 116 else { 117 // /atherer.println("No match with: " + metadatum.getName() + " [l=" + metadatum.getLanguage() + "] \"" + metadatum.getValue() + "\"");117 //Gatherer.println("No match with: " + metadatum.getName() + " [l=" + metadatum.getLanguage() + "] \"" + metadatum.getValue() + "\""); 118 118 } 119 119 metadatum = null; … … 122 122 CollectionMeta result = new CollectionMeta(name); 123 123 addMetadatum(result); 124 // /atherer.println("Added new metadata.");124 //Gatherer.println("Added new metadata."); 125 125 return result; 126 126 } -
trunk/gli/src/org/greenstone/gatherer/cdm/FormatManager.java
r5090 r5164 216 216 Vector elements = Gatherer.c_man.getCollection().msm.getAssignedElements(); 217 217 for(int i = 0; i < elements.size(); i++) { 218 special_model.add("[" + ((ElementWrapper)elements.get(i)). toString() + "]");218 special_model.add("[" + ((ElementWrapper)elements.get(i)).getName() + "]"); 219 219 } 220 220 Collections.sort(special_model); -
trunk/gli/src/org/greenstone/gatherer/collection/Collection.java
r4675 r5164 128 128 mapping_element = null; 129 129 } 130 130 // Otherwise add the mapping. 131 131 if(!found) { 132 132 Element mapping_element = document.createElement(MAPPING); -
trunk/gli/src/org/greenstone/gatherer/collection/CollectionManager.java
r5076 r5164 70 70 import org.greenstone.gatherer.util.GSDLSiteConfig; 71 71 import org.greenstone.gatherer.util.MetadataXML; 72 import org.greenstone.gatherer.util.StaticStrings; 72 73 import org.greenstone.gatherer.util.SynchronizedTreeModelTools; 73 74 import org.greenstone.gatherer.util.Utility; … … 197 198 Gatherer.g_man.collectionChanged(false); 198 199 ///ystem.err.println("Closed collection."); 199 200 200 // All of the consequences of a close should have been processed by now, so others should now see the collection as non-ready. 201 closing_thread = null; 201 202 } 202 203 … … 226 227 progress.setProgress(1); 227 228 228 // ACTIVE_DIR/gimport/229 229 String a_dir = Utility.getCollectionDir(Gatherer.config.gsdl_path) + name + File.separator; 230 231 // Has to be done before creating greenstone directory metadata manager.232 File gimport_dir_temp = new File(Utility.getImportDir(a_dir)+"temp.dat");233 File gimport_dir = gimport_dir_temp.getParentFile();234 gimport_dir.mkdirs();235 if(progress != null) {236 progress.setNote(get("Gimport_Created"));237 }238 230 239 231 // ACTIVE_DIR/gcache/ … … 260 252 msm = collection.msm; // Legacy 261 253 collection.msm.load(); 254 // Always import the extracted metadata set 255 collection.msm.importMDS(new File(Utility.METADATA_DIR + Utility.EXTRACTED_METADATA_NAMESPACE + StaticStrings.METADATA_SET_EXTENSION), false); 262 256 // Import default metadata sets if any. 263 257 for(int i = 0; metadata_sets != null && i < metadata_sets.size(); i++) { … … 360 354 // Find the import directory 361 355 File base_import = new File(base_collection_directory, Utility.IMPORT_DIR); 362 if(!base_import.exists()) {363 base_import = new File(base_collection_directory, Utility.OLD_IMPORT_DIR);364 }365 356 if(base_import.exists()) { 366 357 searchForMetadata(base_import); … … 536 527 return Utility.getCollectionDir(Gatherer.config.gsdl_path) + collection.getName() + File.separator + collection.getName() + ".col"; 537 528 } 538 /** Constructs the absolute filename of the collection import directory, which should resemble "$GSDLHOME/collect/<col_name>/ gimport/"529 /** Constructs the absolute filename of the collection import directory, which should resemble "$GSDLHOME/collect/<col_name>/import/" 539 530 * @return A <strong>String</strong> containing the filename. 540 531 * @see org.greenstone.gatherer.Configuration … … 577 568 } 578 569 579 public String getCollectionOldImport() {580 return Utility.getCollectionDir(Gatherer.config.gsdl_path) + collection.getName() + File.separator + Utility.OLD_IMPORT_DIR;581 }582 583 570 /** This method either returns the title of the current collection, or a placeholder string of 'No Collection'. 584 571 * @return A <strong>String</strong> which represents what we wish to display for a collection title. … … 595 582 public TreeModel getRecordSet() { 596 583 if(collection_model == null && collection != null) { 597 // Check if the gimport directory exists, and if so use it. 598 File gimport_directory = new File(getCollectionImport()); 599 if(gimport_directory.exists()) { 600 // Generate a new FileSystemModel based on the collection gimport directory. 601 collection_model = new FileSystemModel(new FileNode(gimport_directory, false)); 602 } 603 else { 604 ///ystem.err.println("No gimport directory exists."); 605 // Otherwise default to the import directory. If it doesn't exist, there aint much more I can do. 606 // Generate a new FileSystemModel based on the collection import directory. 607 collection_model = new FileSystemModel(new FileNode(new File(getCollectionOldImport()), false)); 608 } 584 // Use the import directory to generate a new FileSystemModel 585 collection_model = new FileSystemModel(new FileNode(new File(getCollectionImport()), false)); 609 586 // Ensure that the manager is a change listener for the tree. 610 587 if(fm_tree_model_listener == null) { … … 661 638 // If mirroring is enabled show the public and private caches. 662 639 if(Gatherer.config.get("workflow.mirror", false)) { 663 640 // Add Public workspace 664 641 FileNode public_root = new FileNode(new File(Utility.CACHE_DIR), get("Tree.Public")); 665 642 workspace_root.insert(public_root); 666 643 // Add Private workspace if a collection has been loaded. 667 644 if(ready()) { 668 645 FileNode private_root = new FileNode(new File(getCollectionCache()), get("Tree.Private")); … … 973 950 } 974 951 } 952 953 /** Refresh the Greenstone Collections special mapping in the workspace tree to account for collections being added/removed 954 */ 955 public void refreshGreenstoneCollections() { 956 FileNode root = (FileNode) workspace_model.getRoot(); 957 FileNode greenstone_collections_node = null; 958 int root_child_count = root.getChildCount(); 959 String greenstone_collections_str = get("Tree.World"); 960 for(int i = 0; greenstone_collections_node == null && i < root_child_count; i++) { 961 TreeNode child = root.getChildAt(i); 962 if(child.toString().equals(greenstone_collections_str)) { 963 greenstone_collections_node = (FileNode) child; 964 } 965 child = null; 966 } 967 greenstone_collections_str = null; 968 root = null; 969 if(greenstone_collections_node != null) { 970 TreePath greenstone_collections_path = new TreePath(greenstone_collections_node.getPath()); 971 workspace_model.refresh(greenstone_collections_path); 972 greenstone_collections_path = null; 973 greenstone_collections_node = null; 974 } 975 } 976 975 977 /** Called to refresh the models upon which the trees are based. 976 978 * @see org.greenstone.gatherer.collection.Collection -
trunk/gli/src/org/greenstone/gatherer/file/FileNode.java
r4851 r5164 10 10 import org.greenstone.gatherer.file.FileSystemModel; 11 11 import org.greenstone.gatherer.util.ArrayTools; 12 import org.greenstone.gatherer.util.StaticStrings; 12 13 import org.greenstone.gatherer.util.Utility; 13 14 … … 242 243 File cols[] = start.listFiles(); 243 244 ArrayTools.sort(cols); 244 // We add their import and gimport directories, but only if its not our currentcollection.245 // We add their import directories, but only if its not our current collection, nor the model collection. 245 246 for(int i = 0; cols != null && i < cols.length; i++) { 246 if(!cols[i].getName().equals( "modelcol") && (!Gatherer.c_man.ready() || !Gatherer.c_man.getCollectionDirectory().equals(cols[i].getAbsolutePath()))) {247 if(!cols[i].getName().equals(StaticStrings.MODEL_COLLECTION_NAME) && (!Gatherer.c_man.ready() || !Gatherer.c_man.getCollectionDirectory().equals(cols[i].getAbsolutePath()))) { 247 248 File dirs[] = cols[i].listFiles(); 248 249 ArrayTools.sort(dirs); 249 File import_dir = new File(cols[i], "gimport"); 250 if(!import_dir.exists()) { 251 import_dir = new File(cols[i], "import"); 252 } 250 File import_dir = new File(cols[i], StaticStrings.IMPORT_FOLDER); 253 251 if(import_dir.exists()) { 254 252 FileNode collection_root = new FileNode(import_dir, cols[i].getName(), true); … … 290 288 } 291 289 // Finally remove any files whose canonical path do not match their absolute one (ie symbolic links). We only do this test under linux, because under windows there is no such thing as a symbolic link, and instead we suffer difficulties with the 16bit truncated file paths not being the same as the canonical ones (i.e Program Files => Progra~1). 290 /* This test to eliminate infinite recursions causes more problems than it solves 292 291 if(!Utility.isWindows()) { 293 292 for(int k = files.length; k != 0; k--) { … … 305 304 } 306 305 } 306 */ 307 307 // Sort the remaining files. 308 308 tools.sort(files, true); -
trunk/gli/src/org/greenstone/gatherer/file/FileSystemModel.java
r5057 r5164 100 100 // If no path is set, take the path to the root node (ie update the whole tree) 101 101 if(path == null) { 102 ///ystem.err.println("Refresh entire tree.");102 System.err.println("Refresh entire tree."); 103 103 path = new TreePath(((FileNode)root).getPath()); 104 104 } 105 105 else { 106 ///ystem.err.println("Refresh: " + path.getLastPathComponent());106 System.err.println("Refresh: " + path.getLastPathComponent()); 107 107 } 108 108 // Only a valid action if this model is currently being displayed in a tree. 109 109 if(tree != null) { 110 110 // Retrieve the error node. 111 111 FileNode node = (FileNode) path.getLastPathComponent(); 112 // If this error node is a dummy node (ie has no associated file) we can't unmap it, so we iterate through its children refreshing each in turn.113 if(node.getFile() == null ) {112 // If this error node is a dummy node (ie has no associated file) we can't unmap it, so we iterate through its children refreshing each in turn. The exception being Greenstone Collections, as it is a dummy node but we can map/unmap it 113 if(node.getFile() == null && !node.toString().equals(Gatherer.dictionary.get("Tree.World"))) { 114 114 for(int i = 0; i < node.getChildCount(); i++) { 115 115 FileNode child = (FileNode) node.getChildAt(i); … … 118 118 } 119 119 } 120 120 // Otherwise we refresh this node. 121 121 else { 122 122 // Record all of the expanded paths under this node. How come getExpandedDescendants returns more results each time. … … 181 181 } 182 182 else { 183 183 ///ystem.err.println("No Tree!"); 184 184 } 185 185 } -
trunk/gli/src/org/greenstone/gatherer/gui/CreatePane.java
r5033 r5164 54 54 import org.greenstone.gatherer.shell.GShellListener; 55 55 import org.greenstone.gatherer.shell.GShellProgressMonitor; 56 import org.greenstone.gatherer.util.AppendLineOnlyFileDocument; 56 57 /** This class provides a GUI view showing some statistics on your current collection, and options for building it. As the collection is built this initial view is replaced with one showing progress bars and a message log of the creation process. This log can be later accessed via the options tree located in the center of the initial pane. This class is also responsible for creating the GShellProgressMonitors that are then attatched to external shell processes, and calling the methods in the CollectionManager for actually importing and building the collection. <br><BR> 57 58 * <center><table width=80% border=2 cellspacing=0 cellpadding=2><tr><td align=center colspan=4> … … 88 89 /** The options pane generates all the various option sheet configuations. */ 89 90 public OptionsPane options_pane = null; 91 private AppendLineOnlyFileDocument document; 90 92 /** A card layout is used to store the separate configuration and progress panes. */ 91 93 private CardLayout card_layout = null; … … 121 123 private JScrollPane scroll_pane; 122 124 /** The message log for the entire session. */ 123 private JTextArea message_log;125 private JTextArea log_textarea; 124 126 /** A tree used to display the currently available option views. */ 125 127 private OptionTree tree = null; … … 148 150 public CreatePane() { 149 151 Collection collection = Gatherer.c_man.getCollection(); 150 message_log= new JTextArea();152 log_textarea = new JTextArea(); 151 153 152 154 // Create components … … 210 212 ///ystem.err.println("Collection changed... "); 211 213 if(Gatherer.c_man != null && ready) { 212 ///ystem.out.println("create coll changed");213 if (!processing && this.options_pane != null) {214 // we only do this if we are not processing - if we are processing, then we haven't added the new entry yet, and it will be added by another method215 this.options_pane.resetLogList(); // saves any residual message216 }217 214 Collection current_collection = Gatherer.c_man.getCollection(); 218 215 if (current_collection != previous_collection) { 219 message_log.setText(null); 220 this.options_pane = new OptionsPane(message_log, current_collection.build_options); 216 this.options_pane = new OptionsPane(current_collection.build_options); 221 217 previous_collection = current_collection; 222 218 } … … 280 276 progress_pane.setLayout(new BorderLayout()); 281 277 progress_pane.add(bar_area, BorderLayout.NORTH); 282 progress_pane.add(new JScrollPane( message_log), BorderLayout.CENTER);278 progress_pane.add(new JScrollPane(log_textarea), BorderLayout.CENTER); 283 279 284 280 // Main pane … … 340 336 */ 341 337 public synchronized void message(GShellEvent event) { 342 final String text = event.getMessage(); 343 ///ystem.err.println("Recieved message: " + event.getMessage()); 344 SwingUtilities.invokeLater(new Runnable() { 345 public void run() { 346 message_log.append(text); 347 } 348 }); 349 } 338 document.appendLine(event.getMessage()); 339 } 340 350 341 /** All implementation of GShellListener must include this method so the listener can be informed when a GShell begins its task. Implementation side-effect, not actually used. 351 342 * @param event A <strong>GShellEvent</strong> that contains details of the initial state of the <strong>GShell</strong> before task comencement. … … 364 355 int status = event.getStatus(); 365 356 if (status == GShell.OK) { 366 options_pane.addNewLog(OptionsPane.SUCCESSFUL);357 document.setSpecialCharacter(OptionsPane.SUCCESSFUL); 367 358 } else { 368 options_pane.addNewLog(OptionsPane.UNSUCCESSFUL); 369 } 359 document.setSpecialCharacter(OptionsPane.UNSUCCESSFUL); 360 } 361 options_pane.resetFileEntry(); 370 362 card_layout.show(main_pane, CONTROL); 371 363 } … … 407 399 build_button.setEnabled(false); 408 400 cancel_button.setEnabled(true); 409 // clear the log list and message_log 410 options_pane.resetLogList(); 401 // Create a new log document and assign it to the two textareas 402 document = options_pane.createNewLogDocument(); 403 log_textarea.setDocument(document); 404 options_pane.log_textarea.setDocument(document); 411 405 // Change the view. 412 406 processing = true; … … 438 432 cancel_button.setEnabled(false); 439 433 processing = false; 440 options_pane.addNewLog(OptionsPane.CANCELLED);434 document.setSpecialCharacter(OptionsPane.CANCELLED); 441 435 card_layout.show(main_pane, CONTROL); 442 436 // Set the stop flag in all the process monitor. 443 437 build_monitor.setStop(true); 444 438 copy_monitor.setStop(true); 445 439 import_monitor.setStop(true); 446 440 // Set removeold automatically. 447 441 Gatherer.c_man.getCollection().build_options.setImportValue("removeold", true, null); 448 442 // Remove the collection lock. 449 443 //Gatherer.g_man.lockCollection(false, false); 450 444 } -
trunk/gli/src/org/greenstone/gatherer/gui/NewCollectionDetailsPrompt.java
r4803 r5164 21 21 private JComboBox base_collection; 22 22 private JDialog self; 23 private JRadioButton hide_extracted_metadata_radio_button; 24 private JRadioButton view_extracted_metadata_radio_button; 23 25 private JTextArea description; 24 26 private JTextField address; … … 59 61 String collection_name = collect_cfg.getName(); 60 62 // Even if there is no metadata directory we add it if its one of the 'big five + 1' that we know how to handle. 61 if(metadata_directory.exists() || collection_name.equals(Utility.COLLECTION_DLS) || collection_name.equals(Utility.COLLECTION_DEMO)) { /** @todo - the other big five */63 if(metadata_directory.exists() || collection_name.equals(Utility.COLLECTION_DLS) || collection_name.equals(Utility.COLLECTION_DEMO)) { 62 64 // Add to model. 63 65 Item item = new Item(possible_collections[i], collection_name); … … 123 125 JButton base_collection_browse = new JButton(get("General.Browse")); 124 126 127 JPanel extracted_metadata_pane = new JPanel(); 128 ButtonGroup extracted_metadata_button_group = new ButtonGroup(); 129 view_extracted_metadata_radio_button = new JRadioButton(get("View_Extracted_Metadata")); 130 view_extracted_metadata_radio_button.setOpaque(false); 131 extracted_metadata_button_group.add(view_extracted_metadata_radio_button); 132 hide_extracted_metadata_radio_button = new JRadioButton(get("Hide_Extracted_Metadata")); 133 hide_extracted_metadata_radio_button.setOpaque(false); 134 extracted_metadata_button_group.add(hide_extracted_metadata_radio_button); 135 view_extracted_metadata_radio_button.setSelected(true); 136 125 137 JPanel button_pane = new JPanel(); 126 138 button_pane.setOpaque(false); … … 182 194 description_pane.add(new JScrollPane(description), BorderLayout.CENTER); 183 195 196 extracted_metadata_pane.setLayout(new GridLayout(1,2,5,0)); 197 extracted_metadata_pane.add(view_extracted_metadata_radio_button); 198 extracted_metadata_pane.add(hide_extracted_metadata_radio_button); 199 200 base_collection_pane.setBorder(BorderFactory.createEmptyBorder(5,0,0,0)); 184 201 base_collection_pane.setLayout(new BorderLayout()); 185 202 base_collection_pane.add(base_collection_label, BorderLayout.NORTH); … … 192 209 193 210 bottom_pane.setLayout(new BorderLayout()); 211 bottom_pane.add(extracted_metadata_pane, BorderLayout.NORTH); 194 212 bottom_pane.add(base_collection_pane, BorderLayout.CENTER); 195 213 bottom_pane.add(button_pane, BorderLayout.SOUTH); … … 233 251 public String getTitle() { 234 252 return title_final; 253 } 254 255 public boolean viewExtractedMetadata() { 256 return view_extracted_metadata_radio_button.isSelected(); 235 257 } 236 258 … … 302 324 implements ActionListener { 303 325 public void actionPerformed(ActionEvent event) { 304 326 // Validate. 305 327 title_final = title.getText(); 306 328 if(title_final.length() == 0) { … … 362 384 } 363 385 description_final = Utility.encodeGreenstone(description_final); 364 386 // If we got this far there are no errors. 365 387 Item item_final = (Item) base_collection.getSelectedItem(); 366 388 base_final = item_final.getFile(); -
trunk/gli/src/org/greenstone/gatherer/gui/OpenCollectionDialog.java
r4686 r5164 216 216 // Retrieve the files usually returned by the platform specific file system view. 217 217 File[] files = default_system_view.getFiles(dir, useFileHiding); 218 // Determine if the current dir actually contains a valid greenstone collection. To do this we check for the presence of the file <dir>/etc/collect.cfg and a directory named import or gimport.218 // Determine if the current dir actually contains a valid greenstone collection. To do this we check for the presence of the file <dir>/etc/collect.cfg and a directory named import. 219 219 File collect_cfg_file = new File(dir, Utility.CONFIG_DIR); 220 File import_dir_file = new File(dir, Utility.OLD_IMPORT_DIR); 221 File gimport_dir_file = new File(dir, Utility.IMPORT_DIR); 222 if(collect_cfg_file.exists() && (gimport_dir_file.exists() || import_dir_file.exists())) { 220 File import_dir_file = new File(dir, Utility.IMPORT_DIR); 221 if(collect_cfg_file.exists() && import_dir_file.exists()) { 223 222 // Create a new dummy collection file. 224 223 String name = dir.getName(); … … 235 234 name = null; 236 235 } 237 gimport_dir_file = null;238 236 import_dir_file = null; 239 237 collect_cfg_file = null; -
trunk/gli/src/org/greenstone/gatherer/gui/OptionsPane.java
r5033 r5164 42 42 import javax.swing.*; 43 43 import javax.swing.event.*; 44 import javax.swing.text.*; 44 45 import org.greenstone.gatherer.Gatherer; 45 46 import org.greenstone.gatherer.cdm.Argument; … … 49 50 import org.greenstone.gatherer.collection.CollectionManager; 50 51 import org.greenstone.gatherer.msm.ElementWrapper; 52 import org.greenstone.gatherer.util.AppendLineOnlyFileDocument; 53 import org.greenstone.gatherer.util.AppendLineOnlyFileDocumentOwner; 51 54 import org.greenstone.gatherer.util.Utility; 52 55 //import org.w3c.dom.*; … … 55 58 * @version 2.2 56 59 */ 57 final public class OptionsPane 58 extends JPanel { 60 public class OptionsPane 61 extends JPanel 62 implements AppendLineOnlyFileDocumentOwner { 63 64 static final public char SUCCESSFUL = 's'; 65 static final public char UNSUCCESSFUL = 'u'; 66 static final public char CANCELLED = 'c'; 67 static final public char UNKNOWN = 'x'; 68 69 /** All process messages are written to this log text area. */ 70 public JTextArea log_textarea = null; 71 59 72 /** The <strong>BuildOptions</strong> data object contains all the option settings we wish to persist between Gatherer sessions (and thus is stored in <strong>Collection</strong>). */ 60 73 private BuildOptions build_options = null; 74 75 private FileEntry file_entry = null; 61 76 /** the log pane - we only create it once now, not each time */ 62 77 private JPanel log_pane = null; 63 78 /** the list of previous log messages */ 64 79 private JList log_list = null; 65 /** whether that currently showing log is changed or not */ 66 private boolean is_log_changed = false; 67 /** the list entry that is currently displayed */ 68 private FileEntry displayed_log = null; 69 /** a listener for changes in the log text */ 70 private LogChangeListener log_change_listener = null; 71 /** All process messages are written to this log text area. */ 72 private JTextArea log_display = null; 73 74 static final public char SUCCESSFUL = 's'; 75 static final public char UNSUCCESSFUL = 'u'; 76 static final public char CANCELLED = 'c'; 80 private Vector writing_documents; 77 81 78 82 static private int BUILD = 0; … … 88 92 89 93 /** The default constructor creates the few session length options, but either retrieves the rest from the current collection, or creates a default set of options. */ 90 public OptionsPane(JTextArea message_log, BuildOptions build_options) { 91 this.log_display = new JTextArea(message_log.getDocument()); 94 public OptionsPane(BuildOptions build_options) { 92 95 this.build_options = build_options; 93 this.log_change_listener = new LogChangeListener(); 94 //this.target_pane = target_pane; 95 } 96 97 /** creates a new log from the text in log. The new file is named 98 * build_log.<current time>.txt. A new FileEntry is added to teh log list 99 * and made selected. A fresh listener is added to teh document */ 100 public void addNewLog(char success) { 101 ///ystem.out.println("add new log"); 102 103 // create the file name 104 long time = System.currentTimeMillis(); 105 StringBuffer name = new StringBuffer(); 106 name.append("build_log."); 107 name.append(time); 108 name.append(success); 109 name.append(".txt"); 110 File f = new File(Gatherer.c_man.getCollectionLog()+name.toString()); 111 // just in case there is no log directory 112 File parent_file = f.getParentFile(); 113 parent_file.mkdirs(); 114 115 // save the log text to the file 116 saveLogFile(f); 117 is_log_changed=false; 118 log_display.getDocument().addDocumentListener(log_change_listener); 119 120 // create the file entry and add it to the list at pos 0 - it will always be the newest one created 121 FileEntry fe = new FileEntry(f); 122 ((DefaultListModel)log_list.getModel()).add(0, fe); 123 log_list.setSelectedIndex(0); 124 displayed_log = fe; 125 96 this.writing_documents = new Vector(); 97 98 // Have to do this here, not in display, as the message log view may not have been displayed yet. 99 log_textarea = new JTextArea(); 100 log_textarea.setEditable(false); 126 101 } 127 102 … … 134 109 pane.setBorder(BorderFactory.createEmptyBorder(5,5,5,5)); 135 110 int build_argument_count = build_options.getBuildArgumentCount(); 136 pane.setLayout(new GridLayout(build_argument_count, 1, 0, 0)); 137 int total_height = PANE_SIZE.height; 111 pane.setPreferredSize(new Dimension(ROW_SIZE.width, ROW_SIZE.height * build_argument_count)); 138 112 for(int i = 0; i < build_argument_count; i++) { 139 113 // Retrieve the argument so we know how to format the control. … … 143 117 String value = build_options.getBuildValue(argument.getName()); 144 118 ArgumentControl argument_control = new ArgumentControl(BUILD, argument, enabled, value); 145 total_height = total_height - argument_control.getPreferredSize().height;146 119 pane.add(argument_control); 147 }148 if(total_height > 0) {149 JPanel filler = new JPanel();150 filler.setPreferredSize(new Dimension(100, total_height));151 filler.setSize(filler.getPreferredSize());152 pane.add(filler);153 120 } 154 121 return pane; … … 162 129 pane.setBorder(BorderFactory.createEmptyBorder(5,5,5,5)); 163 130 int import_argument_count = build_options.getImportArgumentCount(); 164 pane.setLayout(new GridLayout(import_argument_count, 1, 0, 0)); 165 int total_height = PANE_SIZE.height; 131 pane.setPreferredSize(new Dimension(ROW_SIZE.width, ROW_SIZE.height * import_argument_count)); 166 132 for(int i = 0; i < import_argument_count; i++) { 167 133 // Retrieve the argument so we know how to format the control. … … 171 137 String value = build_options.getImportValue(argument.getName()); 172 138 ArgumentControl argument_control = new ArgumentControl(IMPORT, argument, enabled, value); 173 total_height = total_height - argument_control.getPreferredSize().height;174 139 pane.add(argument_control); 175 }176 if(total_height > 0) {177 JPanel filler = new JPanel();178 filler.setPreferredSize(new Dimension(100, total_height));179 filler.setSize(filler.getPreferredSize());180 pane.add(filler);181 140 } 182 141 return pane; … … 195 154 File children[] = log_directory.listFiles(); 196 155 for(int i = 0; children != null && i < children.length; i++) { 197 if(children[i].getName().startsWith("build_log") &&children[i].getName().endsWith(".txt") ) {198 FileEntry entry = new FileEntry(children[i] );156 if(children[i].getName().startsWith("build_log") && children[i].getName().endsWith(".txt") ) { 157 FileEntry entry = new FileEntry(children[i].getName(), children[i].getAbsolutePath()); 199 158 // We are about to insert it. But where. 200 159 boolean found = false; 201 for(int j = 0; j < contents.size(); j++) {160 for(int j = 0; !found && j < contents.size(); j++) { 202 161 FileEntry sibling = (FileEntry) contents.getElementAt(j); 203 162 int order = entry.compareTo(sibling); … … 205 164 contents.insertElementAt(entry, j); 206 165 found = true; 207 break;208 166 } 209 167 } … … 217 175 log_list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); 218 176 log_list.setLayoutOrientation(JList.VERTICAL); 177 log_list.setPreferredSize(new Dimension(600, 100)); 219 178 log_list.setVisibleRowCount(3); 220 179 log_list.addListSelectionListener(new LogListListener()); 221 180 222 JScrollPane list_scroller = new JScrollPane(log_list);223 224 // If log is not empty and we have something in displayed_log - make that element selected225 if (log_display.getText().length()>0 && displayed_log != null) {226 int index = contents.indexOf(displayed_log);227 if (index != -1) {228 log_list.setSelectedIndex(index);229 }230 231 }232 233 log_pane.add(new JScrollPane(log_display), BorderLayout.CENTER);234 181 JLabel log_history_label = new JLabel(get("LogHistory")); 235 182 JPanel log_history_pane = new JPanel(); 236 183 log_history_pane.setPreferredSize(new Dimension(600, 100)); 237 184 log_history_pane.setLayout(new BorderLayout()); 238 185 log_history_pane.add(log_history_label, BorderLayout.NORTH); 239 log_history_pane.add( list_scroller, BorderLayout.SOUTH);186 log_history_pane.add(new JScrollPane(log_list), BorderLayout.CENTER); 240 187 188 log_pane.add(new JScrollPane(log_textarea), BorderLayout.CENTER); 241 189 log_pane.add(log_history_pane, BorderLayout.SOUTH); 242 190 } 243 191 return log_pane; 192 } 193 194 public AppendLineOnlyFileDocument createNewLogDocument() { 195 long time = System.currentTimeMillis(); 196 StringBuffer name = new StringBuffer(); 197 name.append("build_log."); 198 name.append(time); 199 name.append(".txt"); 200 // just in case there is no log directory 201 File file = new File(Gatherer.c_man.getCollectionLog() + name.toString()); 202 File parent_file = file.getParentFile(); 203 parent_file.mkdirs(); 204 parent_file = null; 205 // create the file entry and add it to the list at pos 0 - it will always be the newest one created 206 file_entry = new FileEntry(name.toString(), file.getAbsolutePath()); 207 ((DefaultListModel)log_list.getModel()).add(0, file_entry); 208 log_list.setSelectedIndex(0); 209 // Finally retrieve and return the document associated with this file entry 210 return file_entry.getDocument(); 244 211 } 245 212 … … 265 232 } 266 233 /** Attempts to discover the latest document count. 267 268 234 * @return An <strong>int</strong> detailing the number of documents in this collection. 235 */ 269 236 public int getDocumentCount() { 270 237 if(Gatherer.c_man.ready()) { … … 277 244 } 278 245 279 /** Loads a new log into the log text - saves the currently showing one, 280 * and loads the new one, adding a fresh listener to the document 281 * Note, we need to remove any listener before making the changes, then 282 * add a listener back in 283 */ 284 public void loadSelectedLog(FileEntry fe) { 285 ///ystem.out.println("load selected log"); 286 if(displayed_log != null) { 287 if (is_log_changed) { 288 saveLogFile(displayed_log.getFile()); 289 } else { 290 log_display.getDocument().removeDocumentListener(log_change_listener); 291 } 292 } 293 294 displayed_log = fe; 295 if (fe != null) { 296 log_display.setText(fe.getFileText()); 297 } else { 298 log_display.setText(""); 299 } 300 is_log_changed=false; 301 log_display.getDocument().addDocumentListener(log_change_listener); 302 303 } 304 305 /** Neutralizes the log list - saves any unsaved changes to the current log 306 * clears the log text, unselects the log list, and adds a fresh listener 307 * to the log's document 308 * Note, we need to remove any listener before making the changes, then 309 * add a listener back in */ 310 public void resetLogList() { 311 ///ystem.out.println("reset log"); 312 if (is_log_changed) { 313 saveLogFile(displayed_log.getFile()); 314 } else { 315 log_display.getDocument().removeDocumentListener(log_change_listener); 316 } 317 log_display.setText(""); 318 displayed_log = null; 319 if (log_list != null) { 320 log_list.clearSelection(); 321 } 322 is_log_changed=false; 323 log_display.getDocument().addDocumentListener(log_change_listener); 324 325 } 326 327 /** saves the current text in log to the File specified */ 328 public void saveLogFile(File file) { 329 330 try { 331 BufferedWriter out = new BufferedWriter(new FileWriter(file)); // uses the default encoding 332 String log_text = log_display.getText(); 333 // set teh return delims to true, then swap them for newLine() (platform dependent) - having return delims set to false seemed to not get empty strings so that empty lines were not preserved. 334 StringTokenizer t = new StringTokenizer(log_text, "\n", true); 335 while (t.hasMoreTokens()) { 336 String token = t.nextToken(); 337 if (token.equals("\n")) { 338 out.newLine(); 339 } else { 340 out.write(token, 0, token.length()); 341 } 342 343 } 344 out.close(); 345 346 } catch(Exception e) { 347 System.out.println("Error in saving log file: "+file.toString()); 348 e.printStackTrace(); 349 } 350 351 352 } 353 246 /** Called by our magic log documents after they have finished writing themselves to file, whereapon it is no longer necessary to hold a reference to them. */ 247 public void remove(AppendLineOnlyFileDocument document) { 248 writing_documents.remove(document); 249 } 250 251 public void resetFileEntry() { 252 if(file_entry != null) { 253 file_entry.reset(); 254 } 255 } 354 256 355 257 /** Given a panel containing ArgumentControls, update the values associated with them. */ … … 591 493 } 592 494 593 /** holds a File which has a particular naming convention 594 * build_log.date.txt 595 * also keeps a Date corresponding to the date in its name*/ 495 /** Holds a File which has a particular naming convention build_log.date.txt also keeps a Date corresponding to the date in its name*/ 596 496 private class FileEntry { 597 497 598 private Date date=null; 599 private File file=null; 600 private String display=null; 601 public FileEntry(File f) { 602 this.file=f; 603 this.date = getDateFromFileName(); 604 this.display = createDisplayText(); 605 498 private Date date; 499 private long last_modified; 500 private String display; 501 private String filename; 502 private String filepath; 503 504 public FileEntry(String filename, String filepath) { 505 this.date = null; 506 this.display = null; 507 this.filename = filename; 508 this.filepath = filepath; 509 this.last_modified = 0L; 606 510 } 607 511 608 512 /** returns 0 if the dates are the same, -ve number if the current FileEntry is earlier than the fe FileEntry ...*/ 609 public int compareTo(FileEntry fe) { 610 Date d = fe.getDate(); 611 return date.compareTo(d); 513 public int compareTo(FileEntry file_entry) { 514 Date our_date = getDate(); 515 Date other_date = file_entry.getDate(); 516 return our_date.compareTo(other_date); 612 517 } 613 518 614 519 public Date getDate() { 615 return this.date; 616 } 617 public File getFile() { 618 return this.file; 619 } 620 /** returns the contents of the file */ 621 public String getFileText() { 622 if (!this.file.exists()) { 623 return ""; 624 } 625 StringBuffer contents = new StringBuffer(); 626 try { 627 BufferedReader in = new BufferedReader(new FileReader(this.file)); 628 String line; 629 630 while ((line = in.readLine()) != null) { 631 contents.append(line); 632 contents.append("\n"); 633 } 634 } catch (FileNotFoundException fnfe) { 635 Gatherer.println("Error: log file not found: "+ this.file.toString()); 636 return ""; 637 } catch (IOException ioe) { 638 Gatherer.println("Error: exception occurred when trying to read in file "+this.file.toString()+", "+ioe.getMessage()); 639 640 } 641 642 return contents.toString(); 643 } 520 if(date == null) { 521 // Need to exclude first '.' 522 int first_index = filename.indexOf(".") + 1; 523 // Need to exclude the last '.' 524 int last_index = filename.lastIndexOf("."); 525 if(first_index > 0 && last_index > 0 && first_index < last_index) { 526 String date_string = filename.substring(first_index, last_index); 527 date = new Date(Long.parseLong(date_string)); 528 } 529 else { 530 date = new Date(); // Current date 531 } 532 } 533 return date; 534 } 535 536 public AppendLineOnlyFileDocument getDocument() { 537 return new AppendLineOnlyFileDocument(filepath); 538 } 539 540 public void reset() { 541 display = null; 542 } 543 644 544 /** we only want the date out of the file name, not the whole path */ 645 545 public String toString() { 646 return this.display; 647 } 648 /** creates the display text for the list */ 649 private String createDisplayText() { 650 StringBuffer d = new StringBuffer(); 651 d.append(date.toString()); 652 //char success= this.file.getName().charAt(23); 653 String filename = this.file.getName(); 654 int index = filename.lastIndexOf(".") - 1; 655 if(index >= 0) { 656 char success = filename.charAt(index); 657 switch (success) { 658 case OptionsPane.SUCCESSFUL: 659 d.append(get("Successful")); 660 break; 661 case OptionsPane.UNSUCCESSFUL: 662 d.append(get("Unsuccessful")); 663 break; 664 case OptionsPane.CANCELLED: 665 d.append(get("Cancelled")); 666 break; 667 } 668 } 669 return d.toString(); 670 } 671 /** extracts the date from the file name, which is of the form 'build_log.'<long>[scu]'.txt' */ 672 private Date getDateFromFileName() { 673 String name = this.file.getName(); 674 // Need to exclude first '.' 675 int first_index = name.indexOf(".") + 1; 676 // Need to exclude state letter before last '.' 677 int last_index = name.lastIndexOf(".") - 1; 678 if(first_index > 0 && last_index > 0 && first_index < last_index) { 679 String date_string = name.substring(first_index, last_index); 680 return new Date(Long.parseLong(date_string)); 681 } 682 else { 683 return new Date(); // Current date 684 } 685 } 686 687 688 } 689 690 /** A DocumentListener that listens for changes in the log_display document 691 * if a change is registered, the flag is_log_changed is set to true, 692 * and the listener removes itself from log_display 693 * Because we only want to register user's changes, the listener must be removed before the system makes any changes, and then put back. For example, each time we switchlogs to display, a remove event and an insert event are sent. We dont want to register these as changes to the document, so the listener must be removed before the switch, and added back afterwards */ 694 private class LogChangeListener implements DocumentListener { 695 696 public void changedUpdate(DocumentEvent e) { 697 ///ystem.out.println("changed update"); 698 registerChange(); 699 } 700 public void insertUpdate(DocumentEvent e) { 701 ///ystem.out.println("insert update"); 702 registerChange(); 703 } 704 public void removeUpdate(DocumentEvent e) { 705 ///ystem.out.println("remove update"); 706 registerChange(); 707 } 708 709 private void registerChange() { 710 ///ystem.err.println("a change in the doc occurred, removing the listener"); 711 is_log_changed = true; 712 log_display.getDocument().removeDocumentListener(this); 713 } 714 } 715 716 /** a ListSelectionListener that triggers the load of a newly selected 717 log */ 546 File file = new File(filename); 547 if(display == null) { 548 last_modified = file.lastModified(); 549 StringBuffer d = new StringBuffer(); 550 Date date = getDate(); 551 d.append(date.toString()); 552 char success = UNKNOWN; 553 try { 554 FileInputStream in = new FileInputStream(new File(filepath)); 555 success = (char) in.read(); 556 in.close(); 557 in = null; 558 } 559 catch(Exception error) { 560 error.printStackTrace(); 561 } 562 switch (success) { 563 case SUCCESSFUL: 564 d.append(get("Successful")); 565 break; 566 case UNSUCCESSFUL: 567 d.append(get("Unsuccessful")); 568 break; 569 case CANCELLED: 570 d.append(get("Cancelled")); 571 break; 572 default: 573 d.append(get("Unknown")); 574 } 575 display = d.toString(); 576 } 577 return display; 578 } 579 } 580 581 /** a ListSelectionListener that triggers the load of a newly selected log */ 718 582 private class LogListListener implements ListSelectionListener { 719 583 … … 721 585 if (!e.getValueIsAdjusting()) { // we get two events for one change in list selection - use the false one ( the second one) 722 586 JList source = (JList)e.getSource(); 723 FileEntry fe = (FileEntry) source.getSelectedValue(); 724 loadSelectedLog(fe); 587 file_entry = (FileEntry) source.getSelectedValue(); 588 // First we determine if the old log has been completely written to file 589 Document document = log_textarea.getDocument(); 590 if(document instanceof AppendLineOnlyFileDocument) { 591 AppendLineOnlyFileDocument append_line_only_file_document = (AppendLineOnlyFileDocument) document; 592 if(append_line_only_file_document.isStillWriting()) { 593 writing_documents.add(append_line_only_file_document); // We have to maintain a reference until they are all done. 594 append_line_only_file_document.setOwner(OptionsPane.this); 595 append_line_only_file_document.setExit(); 596 } 597 } 598 // Load the new log 599 log_textarea.setDocument(file_entry.getDocument()); 725 600 } 726 601 } -
trunk/gli/src/org/greenstone/gatherer/gui/Preferences.java
r5042 r5164 3 3 import java.awt.*; 4 4 import java.awt.event.*; 5 import java.io.*; 5 6 import java.net.*; 6 7 import java.util.*; 7 8 import javax.swing.*; 9 import javax.swing.event.*; 10 import org.greenstone.gatherer.Configuration; 8 11 import org.greenstone.gatherer.Gatherer; 9 12 import org.greenstone.gatherer.checklist.CheckList; … … 13 16 import org.greenstone.gatherer.gui.NumberField; 14 17 import org.greenstone.gatherer.gui.SimpleMenuBar; 18 import org.greenstone.gatherer.util.StaticStrings; 15 19 import org.greenstone.gatherer.util.Utility; 16 20 import org.greenstone.gatherer.util.XORToggleButtonGroup; … … 33 37 private JCheckBox workflow_export; 34 38 private JCheckBox workflow_preview; 39 private JComboBox language_combobox; 40 private JLabel extracted_metadata_label; 41 private JLabel file_size_label; 42 private JLabel language_label; 43 private JLabel library_path_label; 44 private JLabel predefined_label; 45 private JLabel proxy_host_label; 46 private JLabel proxy_port_label; 47 private JLabel title_label; 48 private JRadioButton hide_extracted_metadata_radio_button; 49 private JRadioButton hide_file_size_radio_button; 50 private JRadioButton show_file_size_radio_button; 51 private JRadioButton view_extracted_metadata_radio_button; 35 52 private JTabbedPane tab_pane; 36 53 private JTextField library_path_field; … … 39 56 private Preferences self; 40 57 41 static final Dimension LABEL_SIZE = new Dimension(1 00, 25);42 static final Dimension ROW_SIZE = new Dimension( 380, 25);43 static final Dimension SIZE = new Dimension(4 00, 345);58 static final Dimension LABEL_SIZE = new Dimension(150, 25); 59 static final Dimension ROW_SIZE = new Dimension(450, 25); 60 static final Dimension SIZE = new Dimension(450, 345); 44 61 static final String TRUE = "true"; 45 62 … … 54 71 JPanel content_pane = (JPanel) getContentPane(); 55 72 tab_pane = new JTabbedPane(); 73 tab_pane.add("Preferences.General", createGeneralPreferences()); 56 74 tab_pane.add("Preferences.Workflow", createWorkflowPreferences()); 57 75 tab_pane.add("Preferences.Connection", createConnectionPreferences()); … … 101 119 JPanel library_path_pane = new JPanel(); 102 120 library_path_pane.setPreferredSize(ROW_SIZE); 103 JLabellibrary_path_label = new JLabel("Preferences.Connection.Library_Path");121 library_path_label = new JLabel("Preferences.Connection.Library_Path"); 104 122 library_path_label.setPreferredSize(LABEL_SIZE); 105 123 library_path_field = new JTextField(Gatherer.config.getString("general.exec_address", true)); … … 113 131 JPanel proxy_host_pane = new JPanel(); 114 132 proxy_host_pane.setPreferredSize(ROW_SIZE); 115 JLabelproxy_host_label = new JLabel("Preferences.Connection.Proxy_Host");133 proxy_host_label = new JLabel("Preferences.Connection.Proxy_Host"); 116 134 proxy_host_label.setPreferredSize(LABEL_SIZE); 117 135 proxy_host_field = new JTextField(Gatherer.config.getString("general.proxy_host", true)); … … 119 137 JPanel proxy_port_pane = new JPanel(); 120 138 proxy_port_pane.setPreferredSize(ROW_SIZE); 121 JLabelproxy_port_label = new JLabel("Preferences.Connection.Proxy_Port");139 proxy_port_label = new JLabel("Preferences.Connection.Proxy_Port"); 122 140 proxy_port_label.setPreferredSize(LABEL_SIZE); 123 141 proxy_port_field = new NumberField(Gatherer.config.getString("general.proxy_port", true)); … … 152 170 } 153 171 172 private JPanel createGeneralPreferences() { 173 JPanel general_pane = new JPanel(); 174 175 // Build the model of available languages 176 ArrayList dictionary_model = new ArrayList(); 177 178 Locale french = new Locale("fr","FR"); 179 System.err.println("French locale: " + french); 180 181 182 dictionary_model.add(new DictionaryEntry(Locale.ENGLISH)); 183 File classes_folder = new File(Utility.BASE_DIR + StaticStrings.CLASSES_FOLDER); 184 File[] possible_dictionaries = classes_folder.listFiles(); 185 for(int i = 0; i < possible_dictionaries.length; i++) { 186 String filename = possible_dictionaries[i].getName(); 187 if(filename.endsWith(StaticStrings.PROPERTIES_FILE_EXTENSION) && filename.indexOf(StaticStrings.UNDERSCORE_CHARACTER) != -1) { 188 StringTokenizer tokenizer = new StringTokenizer(filename.substring(filename.indexOf(StaticStrings.UNDERSCORE_CHARACTER) + 1, filename.indexOf(StaticStrings.STOP_CHARACTER)), StaticStrings.UNDERSCORE_CHARACTER); 189 Locale locale = null; 190 switch(tokenizer.countTokens()) { 191 case 1: 192 locale = new Locale(tokenizer.nextToken().toLowerCase()); 193 break; 194 case 2: 195 locale = new Locale(tokenizer.nextToken().toLowerCase(), tokenizer.nextToken().toUpperCase()); 196 break; 197 } 198 tokenizer = null; 199 // Open the file and read the first line 200 String description = null; 201 try { 202 BufferedReader br = new BufferedReader(new FileReader(possible_dictionaries[i])); 203 String first_line = br.readLine(); 204 br.close(); 205 description = first_line.substring(first_line.indexOf(StaticStrings.COLON_CHARACTER) + 1); 206 } 207 catch(Exception error) { 208 } 209 DictionaryEntry entry = new DictionaryEntry(description, locale); 210 description = null; 211 locale = null; 212 if(!dictionary_model.contains(entry)) { 213 dictionary_model.add(entry); 214 } 215 entry = null; 216 } 217 filename = null; 218 } 219 possible_dictionaries = null; 220 classes_folder = null; 221 222 // Extracted metadata 223 JPanel extracted_metadata_pane = new JPanel(); 224 extracted_metadata_label = new JLabel("NewCollectionPrompt.Extracted_Metadata"); 225 ButtonGroup extracted_metadata_button_group = new ButtonGroup(); 226 view_extracted_metadata_radio_button = new JRadioButton("NewCollectionPrompt.View_Extracted_Metadata"); 227 view_extracted_metadata_radio_button.setEnabled(Gatherer.c_man.ready()); 228 view_extracted_metadata_radio_button.setOpaque(false); 229 extracted_metadata_button_group.add(view_extracted_metadata_radio_button); 230 hide_extracted_metadata_radio_button = new JRadioButton("NewCollectionPrompt.Hide_Extracted_Metadata"); 231 hide_extracted_metadata_radio_button.setEnabled(Gatherer.c_man.ready()); 232 hide_extracted_metadata_radio_button.setOpaque(false); 233 extracted_metadata_button_group.add(hide_extracted_metadata_radio_button); 234 if(Gatherer.config.get("general.view_extracted_metadata", Configuration.COLLECTION_SPECIFIC)) { 235 view_extracted_metadata_radio_button.setSelected(true); 236 } 237 else { 238 hide_extracted_metadata_radio_button.setSelected(true); 239 } 240 241 // Show file sizes 242 JPanel file_size_pane = new JPanel(); 243 file_size_label = new JLabel("Prefereces.General.File_Size"); 244 ButtonGroup file_size_button_group = new ButtonGroup(); 245 show_file_size_radio_button = new JRadioButton("Prefereces.General.Show_File_Size"); 246 show_file_size_radio_button.setEnabled(Gatherer.c_man.ready()); 247 show_file_size_radio_button.setOpaque(false); 248 file_size_button_group.add(show_file_size_radio_button); 249 hide_file_size_radio_button = new JRadioButton("Prefereces.General.Hide_File_Size"); 250 hide_file_size_radio_button.setEnabled(Gatherer.c_man.ready()); 251 hide_file_size_radio_button.setOpaque(false); 252 file_size_button_group.add(hide_file_size_radio_button); 253 if(Gatherer.config.get("general.show_file_size", Configuration.COLLECTION_SPECIFIC)) { 254 show_file_size_radio_button.setSelected(true); 255 } 256 else { 257 hide_file_size_radio_button.setSelected(true); 258 } 259 260 // Language 261 JPanel language_pane = new JPanel(); 262 language_label = new JLabel("Preferences.General.Interface_Language"); 263 language_label.setPreferredSize(LABEL_SIZE); 264 language_combobox = new JComboBox(dictionary_model.toArray()); 265 266 // Connect 267 Gatherer.dictionary.register(file_size_label, null, false); 268 Gatherer.dictionary.register(show_file_size_radio_button, null, false); 269 Gatherer.dictionary.register(hide_file_size_radio_button, null, false); 270 Gatherer.dictionary.register(view_extracted_metadata_radio_button, null, false); 271 Gatherer.dictionary.register(hide_extracted_metadata_radio_button, null, false); 272 Gatherer.dictionary.register(language_label, null, false); 273 language_combobox.addActionListener(new LanguageComboboxListener()); 274 // Layout 275 276 file_size_pane.setLayout(new GridLayout(1,3,5,0)); 277 file_size_pane.add(show_file_size_radio_button); 278 file_size_pane.add(hide_file_size_radio_button); 279 280 extracted_metadata_pane.setLayout(new GridLayout(1,3,5,0)); 281 extracted_metadata_pane.add(view_extracted_metadata_radio_button); 282 extracted_metadata_pane.add(hide_extracted_metadata_radio_button); 283 284 language_pane.setLayout(new BorderLayout()); 285 language_pane.add(language_label, BorderLayout.WEST); 286 language_pane.add(language_combobox, BorderLayout.CENTER); 287 288 general_pane.setBorder(BorderFactory.createEmptyBorder(5,5,5,5)); 289 general_pane.setLayout(new GridLayout(5,1,0,5)); 290 general_pane.add(extracted_metadata_pane); 291 general_pane.add(file_size_pane); 292 general_pane.add(language_pane); 293 294 return general_pane; 295 } 296 154 297 /** The warning preferences are controlled through a checklist. */ 155 298 private JPanel createWarningPreferences() { 156 299 // Retrieve all of the warning preferences settings. 157 300 HashMap warning_preferences = Gatherer.config.getAll("warning\\..*", true); 158 warning_preferences_check_list = new CheckList( );301 warning_preferences_check_list = new CheckList(false); 159 302 for(Iterator keys = warning_preferences.keySet().iterator(); keys.hasNext(); ) { 160 303 String property = (String) keys.next(); … … 189 332 JPanel workflow_preferences_pane = new JPanel(); 190 333 JPanel checklist_pane = new JPanel(); 191 JLabeltitle_label = new JLabel("Preferences.Workflow.Title");334 title_label = new JLabel("Preferences.Workflow.Title"); 192 335 title_label.setPreferredSize(ROW_SIZE); 193 336 XORToggleButtonGroup checkbox_group = new XORToggleButtonGroup(); … … 209 352 workflow_preview.setPreferredSize(ROW_SIZE); 210 353 JPanel predefined_pane = new JPanel(); 211 JLabelpredefined_label = new JLabel("Preferences.Workflow.Predefined.Label");354 predefined_label = new JLabel("Preferences.Workflow.Predefined.Label"); 212 355 predefined_label.setPreferredSize(new Dimension(150,25)); 213 356 JComboBox predefined_combobox = new JComboBox(predefined); … … 272 415 public void dispose() { 273 416 // Deregister dictionary components 417 418 // Connection 419 Gatherer.dictionary.deregister(library_path_label); 420 Gatherer.dictionary.deregister(use_proxy_checkbox); 421 Gatherer.dictionary.deregister(proxy_host_label); 422 Gatherer.dictionary.deregister(proxy_port_label); 423 424 // General 425 Gatherer.dictionary.deregister(file_size_label); 426 Gatherer.dictionary.deregister(show_file_size_radio_button); 427 Gatherer.dictionary.deregister(hide_file_size_radio_button); 428 Gatherer.dictionary.deregister(extracted_metadata_label); 429 Gatherer.dictionary.deregister(view_extracted_metadata_radio_button); 430 Gatherer.dictionary.deregister(hide_extracted_metadata_radio_button); 431 Gatherer.dictionary.deregister(language_label); 432 433 // Workflow 434 Gatherer.dictionary.deregister(title_label); 435 Gatherer.dictionary.deregister(workflow_browse); 436 Gatherer.dictionary.deregister(workflow_mirror); 437 Gatherer.dictionary.deregister(workflow_gather); 438 Gatherer.dictionary.deregister(workflow_enrich); 439 Gatherer.dictionary.deregister(workflow_design); 440 Gatherer.dictionary.deregister(workflow_export); 441 Gatherer.dictionary.deregister(workflow_create); 442 Gatherer.dictionary.deregister(workflow_preview); 443 Gatherer.dictionary.deregister(predefined_label); 444 445 // Dialog 274 446 Gatherer.dictionary.deregister(this); 275 447 Gatherer.dictionary.deregister(tab_pane); … … 288 460 } 289 461 public void actionPerformed(ActionEvent event) { 290 291 462 // Submit the various changes. 463 // Connection preferences 292 464 String library_path_string = library_path_field.getText(); 293 465 Gatherer.config.setString("general.exec_address", true, library_path_string); … … 300 472 } 301 473 } 302 303 474 Gatherer.config.set("general.use_proxy", true, use_proxy_checkbox.isSelected()); 304 475 Gatherer.config.setString("general.proxy_host", true, proxy_host_field.getText()); 305 476 Gatherer.config.setString("general.proxy_port", true, proxy_port_field.getText()); 306 477 Gatherer.setProxy(); 307 // Warning preferences 478 479 // General preferences 480 Gatherer.config.set("general.show_file_size", Configuration.COLLECTION_SPECIFIC, show_file_size_radio_button.isSelected()); 481 if(Gatherer.g_man.mirror_pane != null) { 482 Gatherer.g_man.mirror_pane.refreshTrees(); 483 } 484 Gatherer.g_man.collection_pane.refreshTrees(); 485 Gatherer.g_man.metaedit_pane.refreshTrees(); 486 487 Gatherer.config.set("general.view_extracted_metadata", Configuration.COLLECTION_SPECIFIC, view_extracted_metadata_radio_button.isSelected()); 488 Gatherer.g_man.metaedit_pane.valueChanged((TreeSelectionEvent) null); // Refresh metadata table 489 490 Gatherer.config.setLocale("general.locale", Configuration.GENERAL_SETTING, ((DictionaryEntry)language_combobox.getSelectedItem()).getLocale()); 491 492 // Warning preferences 308 493 for(int i = 0; i < warning_preferences_check_list.getEntryCount(); i++) { 309 494 Entry entry = warning_preferences_check_list.get(i); 310 495 Gatherer.config.set(entry.getProperty(), true, entry.isSelected()); 311 496 } 312 497 // Workflow preferences 313 498 Gatherer.config.set("workflow.browse", false, workflow_browse.isSelected()); 314 499 Gatherer.config.set("workflow.mirror", false, workflow_mirror.isSelected()); … … 327 512 Gatherer.g_man.workflowUpdate("Create", workflow_create.isSelected()); 328 513 Gatherer.g_man.workflowUpdate("Preview", workflow_preview.isSelected()); 329 514 // Hide dialog 330 515 if(close) { 331 516 self.dispose(); … … 338 523 public void actionPerformed(ActionEvent event) { 339 524 self.dispose(); 525 } 526 } 527 528 private class DictionaryEntry 529 implements Comparable { 530 private Locale locale; 531 private String description; 532 public DictionaryEntry(Locale locale) { 533 this.description = null; 534 this.locale = locale; 535 } 536 public DictionaryEntry(String description, Locale locale) { 537 this.description = description; 538 this.locale = locale; 539 } 540 public int compareTo(Object object) { 541 return toString().compareTo(object.toString()); 542 } 543 public boolean equals(Object object) { 544 return toString().equals(object.toString()); 545 } 546 public Locale getLocale() { 547 return locale; 548 } 549 public String toString() { 550 if(description != null) { 551 return description; 552 } 553 else { 554 return locale.getDisplayName(); 555 } 340 556 } 341 557 } … … 369 585 } 370 586 587 private class LanguageComboboxListener 588 implements ActionListener { 589 public void actionPerformed(ActionEvent event) { 590 // Retrieve the entry 591 DictionaryEntry entry = (DictionaryEntry) language_combobox.getSelectedItem(); 592 if(entry != null) { 593 Gatherer.dictionary.changeDictionary(entry.getLocale()); 594 // Display message 595 JOptionPane.showMessageDialog(Gatherer.g_man, Gatherer.dictionary.get("Preferences.General.Restart_Required"), Gatherer.dictionary.get("Preferences.General.Restart_Required"), JOptionPane.WARNING_MESSAGE); 596 } 597 } 598 } 599 371 600 private class UseProxyListener 372 601 implements ActionListener { -
trunk/gli/src/org/greenstone/gatherer/gui/WarningDialog.java
r5058 r5164 8 8 import org.greenstone.gatherer.Gatherer; 9 9 import org.greenstone.gatherer.gui.SmarterTextArea; 10 import org.greenstone.gatherer.util.FocusChangerTask; 10 11 import org.greenstone.gatherer.util.Utility; 11 12 … … 25 26 private JCheckBox show_check; 26 27 private JTextField value_field; 28 private JPanel value_panel; 27 29 private String affected_property; 28 30 private String full_property; … … 76 78 text_area.setLineWrap(true); 77 79 text_area.setWrapStyleWord(true); 78 JPanelvalue_panel = new JPanel();80 value_panel = new JPanel(); 79 81 JLabel value_label = new JLabel(get("WarningDialog.Value")); 80 82 value_label.setPreferredSize(LABEL_SIZE); … … 137 139 138 140 public void actionPerformed(ActionEvent event) { 141 boolean bad_value = false; 139 142 if(event.getSource() == ok_button) { 140 result = JOptionPane.OK_OPTION; 143 if(affected_property != null && Gatherer.config != null) { 144 String value = value_field.getText(); 145 if(value.length() == 0) { 146 bad_value = true; 147 } 148 else if(value_field instanceof URLField) { 149 bad_value = !((URLField)value_field).validateURL(); 150 } 151 if(!bad_value) { 152 // Store the value of the property 153 Gatherer.config.setString(affected_property, true, value_field.getText()); 154 } 155 } 156 if(!bad_value) { 157 result = JOptionPane.OK_OPTION; 158 } 159 } 160 if(!bad_value) { 141 161 if(Gatherer.config != null) { 142 // Store the value of the property 143 Gatherer.config.setString(affected_property, true, value_field.getText()); 144 } 145 } 146 if(Gatherer.config != null) { 147 // Store the state of the show message checkbox. 148 Gatherer.config.set(full_property, true, !show_check.isSelected()); 149 } 150 // Done. 151 dispose(); 162 // Store the state of the show message checkbox. 163 Gatherer.config.set(full_property, true, !show_check.isSelected()); 164 } 165 // Done. 166 dispose(); 167 } 168 else { 169 JOptionPane.showMessageDialog(Gatherer.g_man, get("WarningDialog.Invalid_Value"), get("General.Error"), JOptionPane.ERROR_MESSAGE); 170 } 152 171 } 153 172 … … 155 174 ///ystem.err.println("Show " + full_property + ": " + Gatherer.config.get(full_property, false)); 156 175 if(Gatherer.config == null || Gatherer.config.get(full_property, false)) { 157 // We only show if the warning has not been disabled. 176 // Create and run the shortlived move focus thread 177 FocusChangerTask task = null; 178 if(affected_property != null) { 179 task = new FocusChangerTask(value_field); 180 } 181 else { 182 task = new FocusChangerTask(ok_button); 183 } 184 task.start(); 158 185 show(); 159 186 } … … 163 190 } 164 191 return result; 192 } 193 194 /** Allows you to replace the generic text field control with a JTextField subclass with further functionality. For instance you might provide a URLField to allow only valid URLs to be accepted. 195 * @param control the JTextField subclass you want to use for the control 196 */ 197 public void setValueField(JTextField control) { 198 // Remove the current control 199 value_panel.remove(value_field); 200 // Replace with the new one 201 value_field = control; 202 // Re-add 203 value_panel.add(value_field, BorderLayout.CENTER); 165 204 } 166 205 -
trunk/gli/src/org/greenstone/gatherer/msm/GDMDocument.java
r4674 r5164 32 32 import org.greenstone.gatherer.msm.MSMUtils; 33 33 import org.greenstone.gatherer.util.HashMap3D; 34 import org.greenstone.gatherer.util.StaticStrings; 34 35 import org.greenstone.gatherer.util.Utility; 35 36 import org.greenstone.gatherer.valuetree.GValueModel; … … 138 139 filename_element = null; 139 140 } 140 141 // Now, finally, we can add the metadata. 141 142 Element metadata_element = base_document.createElement(METADATA_ELEMENT); 142 metadata_element.setAttribute(NAME_ATTRIBUTE, metadata.getElement().getName()); 143 144 // To determine if this metadata entry should overwrite or accumulate we check if there are other entries with the same element in this fileset. 143 String name = metadata.getElement().getName(); 144 if(name.startsWith(Utility.EXTRACTED_METADATA_NAMESPACE)) { 145 name = name.substring(Utility.EXTRACTED_METADATA_NAMESPACE.length() + 1); 146 } 147 metadata_element.setAttribute(NAME_ATTRIBUTE, name); 148 149 // To determine if this metadata entry should overwrite or accumulate we check if there are other entries with the same element in this fileset. 145 150 boolean will_accumulate = false; 146 151 NodeList sibling_description_elements = fileset_element.getElementsByTagName(DESCRIPTION_ELEMENT); … … 180 185 } 181 186 metadata_element.appendChild(base_document.createTextNode(metadata.getAbsoluteValue())); 182 187 // Retrieve the first description element for this fileset (there should only be one, but I'll play it safe). 183 188 NodeList description_elements = fileset_element.getElementsByTagName("Description"); 184 189 Element description_element = (Element) description_elements.item(0); … … 194 199 Gatherer.printStackTrace(error); 195 200 } 201 } 202 203 public int countMetadata() { 204 int count = 0; 205 try { 206 // Retrieve the document element. 207 Element directorymetadata_element = base_document.getDocumentElement(); 208 // Iterate through the filesets, checking the FileName child element against the target file's name using regular expression matching. 209 NodeList fileset_elements = directorymetadata_element.getElementsByTagName(FILESET_ELEMENT); 210 for(int i = 0; i < fileset_elements.getLength(); i++) { 211 Element fileset_element = (Element) fileset_elements.item(i); 212 NodeList description_elements = fileset_element.getElementsByTagName(DESCRIPTION_ELEMENT); 213 for(int k = 0; k < description_elements.getLength(); k++) { 214 Element description_element = (Element) description_elements.item(k); 215 NodeList metadata_elements = description_element.getElementsByTagName(METADATA_ELEMENT); 216 count = count + metadata_elements.getLength(); 217 metadata_elements = null; 218 description_element = null; 219 } 220 description_elements = null; 221 fileset_element = null; 222 } 223 fileset_elements = null; 224 directorymetadata_element = null; 225 } 226 catch (Exception error) { 227 Gatherer.printStackTrace(error); 228 } 229 return count; 196 230 } 197 231 … … 240 274 raw_value = MSMUtils.getValue(metadata_element); 241 275 } 276 // ***** LEGACY SUPPORT ***** 277 // If this raw_value contains a '\' character, but no '\\', '[' or ']' characters, then replace the '\' with a '\\' 278 if(raw_value.indexOf(StaticStrings.ESCAPE_STR) != -1 && raw_value.indexOf(StaticStrings.ESCAPE_STR + StaticStrings.ESCAPE_STR) == -1 && raw_value.indexOf(StaticStrings.RBRACKET_CHARACTER) == -1 && raw_value.indexOf(StaticStrings.LBRACKET_CHARACTER) == -1) { 279 Gatherer.println("Detected Legacy Path: " + raw_value); 280 raw_value = raw_value.replaceAll(StaticStrings.ESCAPE_PATTERN, StaticStrings.ESCAPE_PATTERN + StaticStrings.ESCAPE_PATTERN); 281 Gatherer.println("Updated Path To: " + raw_value); 282 metadata_element.setAttribute(HVALUE_ATTRIBUTE, raw_value); 283 } 284 // ************************** 242 285 // Using the element string and value, retrieve a matching Metadata object from the cache 243 286 Metadata metadata = null; -
trunk/gli/src/org/greenstone/gatherer/msm/GDMManager.java
r4674 r5164 319 319 // First purge any old references. 320 320 document.getMetadata(null, false, null, null, true); 321 // Now write the xml 322 Utility.export(document.getDocument(), file); 323 document.setUpToDate(true); 321 // If there is no metadata in this document then don't write out a file. In fact delete any file that already exists. 322 int count = document.countMetadata(); 323 if(count > 0) { 324 // Now write the xml 325 Utility.export(document.getDocument(), file); 326 document.setUpToDate(true); 327 } 328 else if(file.exists()) { 329 file.delete(); 330 } 324 331 } 325 332 } -
trunk/gli/src/org/greenstone/gatherer/msm/GreenstoneArchiveParser.java
r5047 r5164 80 80 args[0] = document_directories[i].getName(); 81 81 args[1] = String.valueOf(count); 82 shell. message(GShell.IMPORT, shell.typeAsString(GShell.IMPORT) + "> " + Gatherer.dictionary.get("GShell.Extracted", args), GShell.OK);82 shell.fireMessage(GShell.IMPORT, shell.typeAsString(GShell.IMPORT) + "> " + Gatherer.dictionary.get("GShell.Extracted", args), GShell.OK); 83 83 args = null; 84 84 progress.increment(); -
trunk/gli/src/org/greenstone/gatherer/msm/Metadata.java
r4674 r5164 44 44 import org.greenstone.gatherer.valuetree.GValueModel; 45 45 import org.greenstone.gatherer.valuetree.GValueNode; 46 import org.greenstone.gatherer.util.StaticStrings; 46 47 import org.w3c.dom.Element; 47 48 /** Stores a mapping between a particular metadata element, and a certain value node. … … 124 125 if(model != null && model.isHierarchy()) { 125 126 if(value != null) { 126 GValueNode node = (GValueNode)value.getParent(); 127 while(node != null) { 128 GValueNode next = (GValueNode)node.getParent(); 129 if(next != null) { 130 abs_value = node.toString() + "\\" + abs_value; 131 } 132 node = next; 133 } 127 abs_value = value.getFullPath(); 134 128 } 135 129 abs_value = model.getHIndex(abs_value); 130 } 131 else { 132 abs_value = abs_value.replaceAll(StaticStrings.LBRACKET_PATTERN, StaticStrings.ESCAPE_PATTERN + StaticStrings.LBRACKET_PATTERN); 133 abs_value = abs_value.replaceAll(StaticStrings.RBRACKET_PATTERN, StaticStrings.ESCAPE_PATTERN + StaticStrings.RBRACKET_PATTERN); 136 134 } 137 135 // Return the result
Note:
See TracChangeset
for help on using the changeset viewer.