- Timestamp:
- 2008-03-20T20:19:09+13:00 (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
gli/trunk/src/org/greenstone/gatherer/collection/CollectionTree.java
r13604 r15107 99 99 JLabel tree_cell = (JLabel) super.getTreeCellRendererComponent(tree, value, sel, expanded, leaf, row, hasFocus); 100 100 101 // Mark explodable files with a different icon 102 if (value instanceof CollectionTreeNode && ((CollectionTreeNode) value).isExplodable()) { 103 tree_cell.setIcon(CollectionTreeNode.GREEN_FILE_ICON); 104 } 105 101 // Mark explodable files and SrcReplaceable files with a different icon (Green file icon) 102 if(value instanceof CollectionTreeNode) { 103 if(((CollectionTreeNode) value).isExplodable() || ((CollectionTreeNode) value).isSrcReplaceable()) { 104 tree_cell.setIcon(CollectionTreeNode.GREEN_FILE_ICON); 105 } 106 } 107 106 108 return tree_cell; 107 109 } … … 125 127 private JMenuItem expand_folder = null; 126 128 private JMenuItem explode_metadata_database = null; 129 private JMenuItem replace_srcdoc_with_html = null; 127 130 private JMenuItem delete = null; 128 131 private JMenuItem metaaudit = null; 129 132 private JMenuItem new_folder = null; 130 133 private JMenuItem new_dummy_doc = null; 134 private JMenuItem refresh = null; // for refreshing folder view 131 135 private JMenuItem open_externally = null; 132 136 private JMenuItem rename = null; … … 202 206 } 203 207 208 /** Checks whether the files selected are of the same filetype (have the same extension). 209 * @param selectedFilePaths - the full file paths to the treenodes selected in the 210 * collection fileview. 211 * @return true if the file extensions of all the selected files are the same. False is 212 * returned if the file extension of any selected file is different (this means that if 213 * a folder was selected, false would be returned). False is also returned if nothing was 214 * selected. 215 * For use with replace_srcdoc_with_html.pl 216 */ 217 private boolean selectedFilesOfSameType(TreePath[] selectedFilePaths) { 218 if(selectedFilePaths == null || selectedFilePaths.length <= 0) 219 return false; 220 221 boolean sameExtension = true; 222 223 // get just the filename from the path and extract its extension 224 String firstFile = selectedFilePaths[0].getLastPathComponent().toString(); 225 int period = firstFile.lastIndexOf('.'); 226 if(period == -1) { // someone could have selected a folder 227 return false; 228 } 229 String extension = firstFile.substring(period); // includes period 230 231 // compare with the other selected files' extensions: 232 for(int i = 1; i < selectedFilePaths.length && sameExtension; i++) { 233 String otherFile = selectedFilePaths[i].getLastPathComponent().toString(); 234 String otherFileExt = otherFile.substring(otherFile.lastIndexOf('.')); 235 if(!extension.equals(otherFileExt)) 236 sameExtension = false; 237 } 238 return sameExtension; 239 } 204 240 205 241 private void buildContextMenu(TreePath[] selection_paths) … … 215 251 add(new_dummy_doc); 216 252 253 refresh = new JMenuItem(Dictionary.get("CollectionPopupMenu.Refresh")); 254 refresh.addActionListener(this); 255 add(refresh); 256 217 257 node = (CollectionTreeNode) collection_tree.getModel().getRoot(); 218 258 return; … … 228 268 add(delete); 229 269 230 // Only meta-audit and delete are available if multiple items are selected... 270 // The src doc replaceable (with html file) option is only available when all files selected are of the 271 // same type (same extension). For srcreplaceable files only. Works with replace_srcdoc_with_html.pl 272 CollectionTreeNode firstSelectedNode = (CollectionTreeNode)selection_paths[0].getLastPathComponent(); 273 if(firstSelectedNode.isSrcReplaceable()) { // test the first selected node 274 replace_srcdoc_with_html = new JMenuItem(Dictionary.get("Menu.Replace_SrcDoc_With_HTML"), KeyEvent.VK_H); 275 replace_srcdoc_with_html.addActionListener(this); 276 add(replace_srcdoc_with_html); 277 278 // Now the menu is there, grey it out if not all the files are of the same type 279 if(!selectedFilesOfSameType(selection_paths)) { 280 replace_srcdoc_with_html.setEnabled(false); 281 } 282 } 283 284 // Only meta-audit and delete (and possibly replace_srcdoc) are available if multiple items are selected... 231 285 if (selection_paths.length > 1) { 232 286 return; … … 249 303 add(explode_metadata_database); 250 304 } 251 305 252 306 // Replace file 253 307 // !! TO DO: Remote building … … 294 348 /** Called whenever one of the menu items is clicked, this method then causes the appropriate effect. */ 295 349 public void actionPerformed(ActionEvent event) 296 { 297 350 { 351 Object source = event.getSource(); 298 352 299 353 // Collapse folder … … 310 364 else if (source == explode_metadata_database) { 311 365 Gatherer.f_man.explodeMetadataDatabase(node.getFile()); 366 } 367 368 // Replace source document with generated html (works with replace_srcdoc_with_html.pl) 369 else if (source == replace_srcdoc_with_html) { 370 java.io.File[] source_files = new java.io.File[selection_paths.length]; 371 for (int i = 0; i < selection_paths.length; i++) { 372 CollectionTreeNode node = (CollectionTreeNode) selection_paths[i].getLastPathComponent(); 373 source_files[i] = node.getFile(); 374 } 375 Gatherer.f_man.replaceSrcDocWithHtml(source_files); // passing the selected files 312 376 } 313 377 … … 338 402 } 339 403 404 // Refresh action to reload folder view 405 else if (source == refresh) { // Refresh collection tree 406 Gatherer.g_man.refreshCollectionTree(DragTree.COLLECTION_CONTENTS_CHANGED); 407 } 408 340 409 // Open in external program 341 410 else if (source == open_externally) {
Note:
See TracChangeset
for help on using the changeset viewer.