Changeset 7485
- Timestamp:
- 2004-05-28T15:04:47+12:00 (20 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gli/src/org/greenstone/gatherer/gui/GatherPane.java
r7484 r7485 521 521 } 522 522 523 /** When a user right-clicks within the trees on the collection pane view they are presented with a small popup menu of context based options. This class provides such functionality. 523 524 /** When a user right-clicks within the workspace and collection trees they are presented with a small popup menu of context based options. This class provides such functionality. 524 525 */ 525 526 private class GPopupMenu … … 527 528 implements ActionListener { 528 529 529 /** The tree over which the right click action occur ed. */530 /** The tree over which the right click action occurred. */ 530 531 private DragTree tree = null; 531 /** The file record over which the right click action occured, if any. */ 532 /** The tree nodes selected when the right click action occurred. */ 533 private TreePath[] selection_paths = null; 534 /** The file record over which the right click action occurred, if any. */ 532 535 private FileNode node = null; 533 private JMenuItem collapse_expand_folder_menuitem; 534 /** A menu item enabled if a delete action is appropriate in the menus current context. */ 536 537 private JMenuItem create_shortcut = null; 538 private JMenuItem delete_shortcut = null; 539 private JMenuItem collapse_folder = null; 540 private JMenuItem expand_folder = null; 535 541 private JMenuItem delete = null; 536 /** A menu item enabled if a special directory mapping is appropriate in the menus current context. */ 537 private JMenuItem map = null; 538 /** A menu item enabled if a new folder action is appropriate in the menus current context. */ 542 private JMenuItem metaaudit = null; 539 543 private JMenuItem new_folder = null; 540 /** A menu item enabled if a show meta-audit dialog action is appropriate in the menus current context. */ 541 private JMenuItem show_metaaudit = null; 542 /** A menu item allowing a user to unmap a special directory, if and only if a special directory is selected. */ 543 private JMenuItem unmap = null; 544 private TreePath path = null; 545 /** Constructor. */ 546 public GPopupMenu(DragTree tree, MouseEvent event) { 544 545 546 public GPopupMenu(DragTree tree, MouseEvent event) 547 { 547 548 super(); 548 549 this.tree = tree; 549 this.path = tree.getClosestPathForLocation(event.getX(), event.getY()); 550 if(path != null) { 551 node = (FileNode)path.getLastPathComponent(); 552 // Any folder node gets a menu item allowing you to collapse or expand it depending on its current status 553 if(!node.isLeaf()) { 554 // Collapse 555 if(tree.isExpanded(path)) { 556 collapse_expand_folder_menuitem = new JMenuItem(Dictionary.get("Menu.Collapse"), KeyEvent.VK_C); 557 } 558 // Expand 559 else { 560 collapse_expand_folder_menuitem = new JMenuItem(Dictionary.get("Menu.Expand"), KeyEvent.VK_O); 561 } 562 collapse_expand_folder_menuitem.addActionListener(this); 563 add(collapse_expand_folder_menuitem); 564 } 565 // Set Options based on selection and tree 566 if(tree.getSelectionCount() != 0 && tree == collection_tree) { 567 String[] args = new String[1]; 568 args[0] = collection_tree.getSelectionDetails(); 569 show_metaaudit = new JMenuItem(Dictionary.get("Menu.Metadata_View", args), KeyEvent.VK_A); 570 show_metaaudit.addActionListener(this); 571 add(show_metaaudit); 572 } 573 if(tree == collection_tree && node != null && node.getFile() != null && node.getFile().isDirectory() && !node.isReadOnly()) { 574 new_folder = new JMenuItem(Dictionary.get("CollectionPopupMenu.New_Folder"), KeyEvent.VK_N); 575 new_folder.addActionListener(this); 576 add(new_folder); 577 add(new JSeparator()); 578 } 579 if(tree == collection_tree && tree.getSelectionCount() != 0 && node != null && !node.isReadOnly()) { 580 delete = new JMenuItem(Dictionary.get("CollectionPopupMenu.Delete"), KeyEvent.VK_D); 581 delete.addActionListener(this); 582 add(delete); 583 } 584 if(tree == workspace_tree && node != null && !node.isLeaf()) { 585 String node_name = node.toString(); 586 FileNode root = (FileNode) tree.getModel().getRoot(); 587 if(!node_name.equals(Dictionary.get("Tree.World")) && !node_name.equals(Dictionary.get("Tree.Root")) && !node_name.equals(Dictionary.get("Tree.Public")) && !node_name.equals(Dictionary.get("Tree.Private"))) { 588 // You can unmap 1st level nodes. 589 if(root.getIndex(node) != -1) { 590 unmap = new JMenuItem(Dictionary.get("MappingPrompt.Unmap"), KeyEvent.VK_R); 591 unmap.addActionListener(this); 592 add(unmap); 593 } 594 // Or map any other level directories. 595 else { 596 map = new JMenuItem(Dictionary.get("MappingPrompt.Map"), KeyEvent.VK_S); 597 map.addActionListener(this); 598 add(map); 599 } 600 } 601 } 602 show(tree, event.getX(), event.getY()); 603 } 604 } 550 551 // Get the paths currently selected in the tree 552 selection_paths = tree.getSelectionPaths(); 553 554 // Create an appropriate context menu, based on what is selected 555 buildContextMenu(selection_paths); 556 557 // Show the popup menu on screen 558 show(tree, event.getX(), event.getY()); 559 } 560 561 562 private void buildContextMenu(TreePath[] selection_paths) 563 { 564 // If nothing is selected, only the new folder option is available 565 if (selection_paths == null) { 566 new_folder = new JMenuItem(Dictionary.get("CollectionPopupMenu.New_Folder"), KeyEvent.VK_N); 567 new_folder.addActionListener(this); 568 add(new_folder); 569 570 node = (FileNode) tree.getModel().getRoot(); 571 return; 572 } 573 574 Gatherer.println("Number of files/folders selected: " + selection_paths.length); 575 576 // Collection tree: display meta-audit option and delete options 577 if (tree == collection_tree) { 578 String[] args = new String[1]; 579 args[0] = collection_tree.getSelectionDetails(); 580 metaaudit = new JMenuItem(Dictionary.get("Menu.Metadata_View", args), KeyEvent.VK_A); 581 metaaudit.addActionListener(this); 582 add(metaaudit); 583 584 delete = new JMenuItem(Dictionary.get("CollectionPopupMenu.Delete"), KeyEvent.VK_D); 585 delete.addActionListener(this); 586 add(delete); 587 } 588 589 // Only meta-audit and delete are available if multiple items are selected... 590 if (selection_paths.length > 1) { 591 return; 592 } 593 594 TreePath path = selection_paths[0]; 595 node = (FileNode) path.getLastPathComponent(); 596 597 // There are currently no options for plain files 598 if (node.isLeaf()) { 599 return; 600 } 601 602 // ---- Options for folder nodes ---- 603 // Collapse or expand, depending on current status 604 if (tree.isExpanded(path)) { 605 collapse_folder = new JMenuItem(Dictionary.get("Menu.Collapse"), KeyEvent.VK_C); 606 collapse_folder.addActionListener(this); 607 add(collapse_folder); 608 } 609 else { 610 expand_folder = new JMenuItem(Dictionary.get("Menu.Expand"), KeyEvent.VK_O); 611 expand_folder.addActionListener(this); 612 add(expand_folder); 613 } 614 615 // New folder option, for collection tree only 616 if (tree == collection_tree && !node.isReadOnly()) { 617 new_folder = new JMenuItem(Dictionary.get("CollectionPopupMenu.New_Folder"), KeyEvent.VK_N); 618 new_folder.addActionListener(this); 619 add(new_folder); 620 } 621 622 // Create/remove shortcut option, for workspace tree only 623 if (tree == workspace_tree) { 624 // The "built-in" folders can't be modified 625 String node_name = node.toString(); 626 if (node_name.equals(Dictionary.get("Tree.World")) || node_name.equals(Dictionary.get("Tree.Root")) || node_name.equals(Dictionary.get("Tree.Public")) || node_name.equals(Dictionary.get("Tree.Private"))) { 627 return; 628 } 629 630 // You can unmap 1st level nodes 631 FileNode root = (FileNode) tree.getModel().getRoot(); 632 if (root.getIndex(node) != -1) { 633 delete_shortcut = new JMenuItem(Dictionary.get("MappingPrompt.Unmap"), KeyEvent.VK_R); 634 delete_shortcut.addActionListener(this); 635 add(delete_shortcut); 636 } 637 // Or map any other level directories 638 else { 639 create_shortcut = new JMenuItem(Dictionary.get("MappingPrompt.Map"), KeyEvent.VK_S); 640 create_shortcut.addActionListener(this); 641 add(create_shortcut); 642 } 643 } 644 } 645 605 646 606 647 /** Called whenever one of the menu items is actioned apon, this method then causes the appropriate effect. */ 607 public void actionPerformed(ActionEvent event) { 608 Object source = event.getSource(); 609 if(source == delete) { 610 // Retrieve the selection. Of course this gets a bit tricky as the user may have right clicked over a node not in the current selection, in which case we remove only that node. 611 TreePath[] selection_paths = tree.getSelectionPaths(); 612 if(selection_paths != null) { 613 FileNode[] source_nodes = new FileNode[selection_paths.length]; 614 boolean found = false; 615 for(int i = 0; i < selection_paths.length; i++) { 616 source_nodes[i] = (FileNode) selection_paths[i].getLastPathComponent(); 617 if(node != null) { 618 found = found || source_nodes[i].equals(node); 619 } 620 } 621 if(node != null && !found) { 622 source_nodes = null; 623 source_nodes = new FileNode[1]; 624 source_nodes[0] = node; 625 } 626 // Fire a delete action 627 Gatherer.f_man.action(tree, source_nodes, bin_button, null); 628 source_nodes = null; 629 } 630 selection_paths = null; 631 } 632 else if(source == map && node != null) { 633 MappingPrompt mp = new MappingPrompt(node.getFile()); 634 mp.destroy(); 635 mp = null; 636 } 637 else if(source == new_folder && node != null) { 638 Gatherer.f_man.newFolder(tree, node); 639 } 640 else if(source == show_metaaudit) { 641 Gatherer.g_man.showMetaAuditBox(); 642 } 643 else if(source == unmap && node != null) { 644 Gatherer.c_man.removeDirectoryMapping(node); 645 } 646 else if(source == collapse_expand_folder_menuitem && path != null && node != null && !node.isLeaf()) { 647 // Collapse 648 if(tree.isExpanded(path)) { 649 tree.collapsePath(path); 650 } 651 // Expand 652 else { 653 tree.expandPath(path); 654 } 655 } 656 } 657 } 648 public void actionPerformed(ActionEvent event) 649 { 650 Object source = event.getSource(); 651 652 // Create shortcut 653 if (source == create_shortcut) { 654 MappingPrompt mp = new MappingPrompt(node.getFile()); 655 mp.destroy(); 656 } 657 658 // Delete shortcut 659 else if (source == delete_shortcut) { 660 Gatherer.c_man.removeDirectoryMapping(node); 661 } 662 663 // Collapse folder 664 else if (source == collapse_folder) { 665 tree.collapsePath(selection_paths[0]); 666 } 667 668 // Expand folder 669 else if (source == expand_folder) { 670 tree.expandPath(selection_paths[0]); 671 } 672 673 // Delete 674 else if (source == delete) { 675 FileNode[] source_nodes = new FileNode[selection_paths.length]; 676 for (int i = 0; i < selection_paths.length; i++) { 677 source_nodes[i] = (FileNode) selection_paths[i].getLastPathComponent(); 678 } 679 680 // Fire a delete action 681 Gatherer.f_man.action(tree, source_nodes, bin_button, null); 682 } 683 684 // Meta-audit 685 else if (source == metaaudit) { 686 Gatherer.g_man.showMetaAuditBox(); 687 } 688 689 // New folder 690 else if (source == new_folder) { 691 Gatherer.f_man.newFolder(tree, node); 692 } 693 } 694 } 695 658 696 659 697 /** This class listens for certain key presses, such as [Enter] or [Delete], and responds appropriately. */
Note:
See TracChangeset
for help on using the changeset viewer.