Changeset 11613
- Timestamp:
- 2006-04-06T17:15:07+12:00 (18 years ago)
- Location:
- trunk/gli/src/org/greenstone/gatherer
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gli/src/org/greenstone/gatherer/file/WorkspaceTree.java
r10345 r11613 27 27 package org.greenstone.gatherer.file; 28 28 29 import java.awt.event.*; 29 30 import java.io.File; 30 31 import java.util.Enumeration; 32 import javax.swing.*; 31 33 import javax.swing.tree.TreePath; 32 34 import org.greenstone.gatherer.Configuration; 33 35 import org.greenstone.gatherer.DebugStream; 36 import org.greenstone.gatherer.Dictionary; 34 37 import org.greenstone.gatherer.Gatherer; 38 import org.greenstone.gatherer.gui.CreateShortcutPrompt; 39 import org.greenstone.gatherer.gui.GLIButton; 35 40 import org.greenstone.gatherer.gui.tree.DragTree; 36 41 … … 38 43 public class WorkspaceTree 39 44 extends DragTree 45 implements MouseListener 40 46 { 41 47 static public final int LIBRARY_CONTENTS_CHANGED = 10; … … 47 53 { 48 54 super(name, WorkspaceTreeModel.getWorkspaceTreeModel(), true); 55 addMouseListener(this); 49 56 } 50 57 … … 58 65 refresh(FOLDER_SHORTCUTS_CHANGED); 59 66 } 67 68 69 public void mouseClicked(MouseEvent event) 70 { 71 if (SwingUtilities.isRightMouseButton(event)) { 72 new WorkspaceTreeRightClickMenu(this, event); 73 } 74 } 75 76 public void mouseEntered(MouseEvent event) { } 77 78 public void mouseExited(MouseEvent event) { } 79 80 public void mousePressed(MouseEvent event) { } 81 82 public void mouseReleased(MouseEvent event) { } 60 83 61 84 … … 141 164 refresh(FOLDER_SHORTCUTS_CHANGED); 142 165 } 166 167 168 /** 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. 169 */ 170 private class WorkspaceTreeRightClickMenu 171 extends JPopupMenu 172 implements ActionListener 173 { 174 /** The tree over which the right click action occurred. */ 175 private WorkspaceTree workspace_tree = null; 176 /** The tree nodes selected when the right click action occurred. */ 177 private TreePath[] selection_paths = null; 178 /** The file record over which the right click action occurred. */ 179 private WorkspaceTreeNode node = null; 180 181 private JMenuItem create_shortcut = null; 182 private JMenuItem delete_shortcut = null; 183 private JMenuItem collapse_folder = null; 184 private JMenuItem expand_folder = null; 185 private JMenuItem explode_metadata_database = null; 186 private JMenuItem delete = null; 187 private JMenuItem metaaudit = null; 188 private JMenuItem new_folder = null; 189 private JMenuItem new_dummy_doc = null; 190 private JMenuItem open_externally = null; 191 private JMenuItem rename = null; 192 private JMenuItem replace = null; 193 194 195 private WorkspaceTreeRightClickMenu(WorkspaceTree workspace_tree, MouseEvent event) 196 { 197 super(); 198 this.workspace_tree = workspace_tree; 199 200 // Note we have to use setImmediate() with the set selction paths 201 // otherwise the selection doesn't get updated until after the 202 // popup comes up. 203 204 // the right click position 205 TreePath right_click_path = workspace_tree.getPathForLocation(event.getX(), event.getY()); 206 if (right_click_path == null) { 207 // user has clicked outside of the tree, clear the selection 208 selection_paths = null; 209 workspace_tree.setImmediate(true); 210 workspace_tree.clearSelection(); 211 workspace_tree.setImmediate(false); 212 } 213 else { 214 // Get the paths currently selected in the tree 215 selection_paths = workspace_tree.getSelectionPaths(); 216 if (selection_paths == null) { 217 // nothing currently selected - we shift the selection to 218 // the node that was right clicked on 219 selection_paths = new TreePath[1]; 220 selection_paths[0] = right_click_path; 221 workspace_tree.setImmediate(true); 222 workspace_tree.setSelectionPath(right_click_path); 223 workspace_tree.setImmediate(false); 224 } 225 else if (selection_paths.length == 1 && ! selection_paths[0].equals( right_click_path)) { 226 workspace_tree.setImmediate(true); 227 workspace_tree.clearSelection(); 228 workspace_tree.setSelectionPath(right_click_path); 229 workspace_tree.setImmediate(false); 230 selection_paths[0] = right_click_path; 231 } 232 else { 233 // we had multiply selected paths in the tree. 234 // if we clicked on one of those paths, then use all the 235 // current selection, otherwise clear the selection and 236 // select the one we right clicked on 237 boolean clicked_in_selection = false; 238 for (int i = 0; i < selection_paths.length; i++) { 239 if (selection_paths[i].equals(right_click_path)) { 240 clicked_in_selection = true; 241 break; 242 } 243 } 244 if (!clicked_in_selection) { 245 // want the tree to update right away 246 workspace_tree.setImmediate(true); 247 workspace_tree.clearSelection(); 248 workspace_tree.setSelectionPath(right_click_path); 249 workspace_tree.setImmediate(false); 250 selection_paths = new TreePath[1]; 251 selection_paths[0] = right_click_path; 252 } 253 } 254 } 255 256 // Create an appropriate context menu, based on what is selected 257 buildContextMenu(selection_paths); 258 259 // Show the popup menu on screen 260 show(workspace_tree, event.getX(), event.getY()); 261 } 262 263 264 private void buildContextMenu(TreePath[] selection_paths) 265 { 266 // If nothing is selected, no options are available... 267 if (selection_paths == null) { 268 return; 269 } 270 271 DebugStream.println("Number of files/folders selected: " + selection_paths.length); 272 273 // Only meta-audit and delete are available if multiple items are selected... 274 if (selection_paths.length > 1) { 275 return; 276 } 277 278 TreePath path = selection_paths[0]; 279 node = (WorkspaceTreeNode) path.getLastPathComponent(); 280 281 // ---- Options for file nodes ---- 282 if (node.isLeaf()) { 283 // Open the file in an external program 284 open_externally = new JMenuItem(Dictionary.get("Menu.Open_Externally"), KeyEvent.VK_O); 285 open_externally.addActionListener(this); 286 add(open_externally); 287 288 return; 289 } 290 291 // ---- Options for folder nodes ---- 292 // Collapse or expand, depending on current status 293 if (workspace_tree.isExpanded(path)) { 294 collapse_folder = new JMenuItem(Dictionary.get("Menu.Collapse"), KeyEvent.VK_C); 295 collapse_folder.addActionListener(this); 296 add(collapse_folder); 297 } 298 else { 299 expand_folder = new JMenuItem(Dictionary.get("Menu.Expand"), KeyEvent.VK_O); 300 expand_folder.addActionListener(this); 301 add(expand_folder); 302 } 303 304 // Create/remove shortcut option, for workspace tree only 305 if (workspace_tree == workspace_tree) { 306 // The "built-in" folders can't be modified 307 String node_name = node.toString(); 308 if (node_name.equals(Dictionary.get("Tree.World")) || node_name.equals(Dictionary.get("Tree.Root")) || node_name.equals(Dictionary.get("Tree.DownloadedFiles"))) { 309 return; 310 } 311 312 // You can unmap 1st level nodes 313 WorkspaceTreeNode root = (WorkspaceTreeNode) workspace_tree.getModel().getRoot(); 314 if (root.getIndex(node) != -1) { 315 delete_shortcut = new JMenuItem(Dictionary.get("MappingPrompt.Unmap"), KeyEvent.VK_R); 316 delete_shortcut.addActionListener(this); 317 add(delete_shortcut); 318 } 319 // Or map any other level directories 320 else { 321 create_shortcut = new JMenuItem(Dictionary.get("MappingPrompt.Map"), KeyEvent.VK_S); 322 create_shortcut.addActionListener(this); 323 add(create_shortcut); 324 } 325 } 326 } 327 328 329 /** Called whenever one of the menu items is clicked, this method then causes the appropriate effect. */ 330 public void actionPerformed(ActionEvent event) 331 { 332 Object source = event.getSource(); 333 334 // Create shortcut 335 if (source == create_shortcut) { 336 CreateShortcutPrompt mp = new CreateShortcutPrompt(workspace_tree, node.getFile()); 337 mp.destroy(); 338 } 339 340 // Delete shortcut 341 else if (source == delete_shortcut) { 342 workspace_tree.removeDirectoryMapping(node); 343 } 344 345 // Collapse folder 346 else if (source == collapse_folder) { 347 workspace_tree.collapsePath(selection_paths[0]); 348 } 349 350 // Expand folder 351 else if (source == expand_folder) { 352 workspace_tree.expandPath(selection_paths[0]); 353 } 354 355 // Open in external program 356 else if (source == open_externally) { 357 Gatherer.f_man.openFileInExternalApplication(node.getFile()); 358 } 359 } 360 } 143 361 } -
trunk/gli/src/org/greenstone/gatherer/gui/GatherPane.java
r11612 r11613 107 107 /** A split pane seperating the two trees, allowing for the screen real-estate for each to be changed. */ 108 108 private JSplitPane tree_pane = null; 109 /** Text fragment arguments used to fill in phrases returned from the dictionary. */110 private String args[] = null;111 109 /** Ensures that expansion and selection events between collection trees based on the same model are synchronized. */ 112 110 private TreeSynchronizer collection_tree_sync = null; … … 207 205 208 206 /** Generates the pane on controls used to 'collect' files into the collection. Resposible for creating, connecting and laying out these controls. */ 209 public void display() { 210 // Create Components. 211 MouseListenerImpl mouse_listener = new MouseListenerImpl(); 212 207 public void display() 208 { 213 209 // Workspace Tree 214 210 workspace_pane = new JPanel(); … … 225 221 workspace_tree = new WorkspaceTree(Utility.WORKSPACE_TREE); 226 222 group.add(workspace_tree); 227 workspace_tree.addMouseListener(mouse_listener);228 223 workspace_tree.addMouseListener(Gatherer.g_man.foa_listener); 229 224 workspace_tree.addTreeExpansionListener(Gatherer.g_man.foa_listener); … … 426 421 workspace_tree.refresh(refresh_reason); 427 422 } 428 429 430 /** 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.431 */432 private class RightClickMenu433 extends JPopupMenu434 implements ActionListener {435 436 /** The tree over which the right click action occurred. */437 private DragTree tree = null;438 /** The tree nodes selected when the right click action occurred. */439 private TreePath[] selection_paths = null;440 /** The file record over which the right click action occurred. */441 private FileNode node = null;442 443 private JMenuItem create_shortcut = null;444 private JMenuItem delete_shortcut = null;445 private JMenuItem collapse_folder = null;446 private JMenuItem expand_folder = null;447 private JMenuItem explode_metadata_database = null;448 private JMenuItem delete = null;449 private JMenuItem metaaudit = null;450 private JMenuItem new_folder = null;451 private JMenuItem new_dummy_doc = null;452 private JMenuItem open_externally = null;453 private JMenuItem rename = null;454 private JMenuItem replace = null;455 456 457 private RightClickMenu(DragTree tree, MouseEvent event)458 {459 super();460 this.tree = tree;461 462 // Note we have to use setImmediate() with the set selction paths463 // otherwise the selection doesn't get updated until after the464 // popup comes up.465 466 // the right click position467 TreePath right_click_path = tree.getPathForLocation(event.getX(), event.getY());468 if (right_click_path == null) {469 // user has clicked outside of the tree, clear the selection470 selection_paths = null;471 tree.setImmediate(true);472 tree.clearSelection();473 tree.setImmediate(false);474 } else {475 // Get the paths currently selected in the tree476 selection_paths = tree.getSelectionPaths();477 if (selection_paths == null) {478 // nothing currently selected - we shift the selection to479 // the node that was right clicked on480 selection_paths = new TreePath[1];481 selection_paths[0] = right_click_path;482 tree.setImmediate(true);483 tree.setSelectionPath(right_click_path);484 tree.setImmediate(false);485 } else if (selection_paths.length == 1 && ! selection_paths[0].equals( right_click_path)) {486 tree.setImmediate(true);487 tree.clearSelection();488 tree.setSelectionPath(right_click_path);489 tree.setImmediate(false);490 selection_paths[0] = right_click_path;491 } else {492 // we had multiply selected paths in the tree.493 // if we clicked on one of those paths, then use all the494 // current selection, otherwise clear the selection and495 // select the one we right clicked on496 boolean clicked_in_selection = false;497 for (int i=0; i<selection_paths.length; i++) {498 if (selection_paths[i].equals(right_click_path)) {499 clicked_in_selection = true;500 break;501 }502 }503 if (!clicked_in_selection) {504 // want the tree to update right away505 tree.setImmediate(true);506 tree.clearSelection();507 tree.setSelectionPath(right_click_path);508 tree.setImmediate(false);509 selection_paths = new TreePath[1];510 selection_paths[0] = right_click_path;511 }512 }513 }514 // finally we have the correct selection paths!515 516 // Create an appropriate context menu, based on what is selected517 buildContextMenu(selection_paths);518 519 // Show the popup menu on screen520 show(tree, event.getX(), event.getY());521 }522 523 524 private void buildContextMenu(TreePath[] selection_paths)525 {526 // If nothing is selected, only the new folder/dummy doc options are available...527 if (selection_paths == null) {528 // ... but only in the collection tree!529 if (tree == collection_tree) {530 new_folder = new JMenuItem(Dictionary.get("CollectionPopupMenu.New_Folder"), KeyEvent.VK_N);531 new_folder.addActionListener(this);532 add(new_folder);533 534 new_dummy_doc = new JMenuItem(Dictionary.get("CollectionPopupMenu.New_Dummy_Doc"));535 new_dummy_doc.addActionListener(this);536 add(new_dummy_doc);537 538 node = (CollectionTreeNode) tree.getModel().getRoot();539 }540 541 return;542 }543 544 DebugStream.println("Number of files/folders selected: " + selection_paths.length);545 546 // Collection tree: display meta-audit option and delete options547 if (tree == collection_tree) {548 String[] args = new String[1];549 args[0] = collection_tree.getSelectionDetails();550 metaaudit = new JMenuItem(Dictionary.get("Menu.Metadata_View", args), KeyEvent.VK_A);551 metaaudit.addActionListener(this);552 add(metaaudit);553 554 delete = new JMenuItem(Dictionary.get("CollectionPopupMenu.Delete"), KeyEvent.VK_D);555 delete.addActionListener(this);556 add(delete);557 558 }559 560 // Only meta-audit and delete are available if multiple items are selected...561 if (selection_paths.length > 1) {562 return;563 }564 565 // collection tree gets rename option566 // but not for remote gli (until we make it work properly)567 if (tree == collection_tree) {568 if (!Gatherer.isGsdlRemote) {569 rename = new JMenuItem(Dictionary.get("CollectionPopupMenu.Rename"), KeyEvent.VK_R);570 rename.addActionListener(this);571 add(rename);572 }573 }574 575 TreePath path = selection_paths[0];576 node = (FileNode) path.getLastPathComponent();577 578 // ---- Options for file nodes ----579 if (node.isLeaf()) {580 if (tree == collection_tree) {581 // Explode metadata databases, for explodable files only582 if (((CollectionTreeNode) node).isExplodable()) {583 explode_metadata_database = new JMenuItem(Dictionary.get("Menu.Explode_Metadata_Database"), KeyEvent.VK_E);584 explode_metadata_database.addActionListener(this);585 explode_metadata_database.setEnabled(!Gatherer.isGsdlRemote);586 add(explode_metadata_database);587 }588 // replace file589 // but not for remote gli (until we make it work properly)590 if (!Gatherer.isGsdlRemote) {591 replace = new JMenuItem(Dictionary.get("CollectionPopupMenu.Replace"), KeyEvent.VK_P);592 replace.addActionListener(this);593 add(replace);594 }595 }596 597 // Open the file in an external program598 open_externally = new JMenuItem(Dictionary.get("Menu.Open_Externally"), KeyEvent.VK_O);599 open_externally.addActionListener(this);600 add(open_externally);601 602 return;603 }604 605 // ---- Options for folder nodes ----606 // Collapse or expand, depending on current status607 if (tree.isExpanded(path)) {608 collapse_folder = new JMenuItem(Dictionary.get("Menu.Collapse"), KeyEvent.VK_C);609 collapse_folder.addActionListener(this);610 add(collapse_folder);611 }612 else {613 expand_folder = new JMenuItem(Dictionary.get("Menu.Expand"), KeyEvent.VK_O);614 expand_folder.addActionListener(this);615 add(expand_folder);616 }617 618 // New folder/dummy doc options, for collection tree only619 if (tree == collection_tree && !node.isReadOnly()) {620 new_folder = new JMenuItem(Dictionary.get("CollectionPopupMenu.New_Folder"), KeyEvent.VK_N);621 new_folder.addActionListener(this);622 add(new_folder);623 new_dummy_doc = new JMenuItem(Dictionary.get("CollectionPopupMenu.New_Dummy_Doc"));624 new_dummy_doc.addActionListener(this);625 add(new_dummy_doc);626 }627 628 // Create/remove shortcut option, for workspace tree only629 if (tree == workspace_tree) {630 // The "built-in" folders can't be modified631 String node_name = node.toString();632 if (node_name.equals(Dictionary.get("Tree.World")) || node_name.equals(Dictionary.get("Tree.Root")) || node_name.equals(Dictionary.get("Tree.DownloadedFiles"))) {633 return;634 }635 636 // You can unmap 1st level nodes637 WorkspaceTreeNode root = (WorkspaceTreeNode) tree.getModel().getRoot();638 if (root.getIndex(node) != -1) {639 delete_shortcut = new JMenuItem(Dictionary.get("MappingPrompt.Unmap"), KeyEvent.VK_R);640 delete_shortcut.addActionListener(this);641 add(delete_shortcut);642 }643 // Or map any other level directories644 else {645 create_shortcut = new JMenuItem(Dictionary.get("MappingPrompt.Map"), KeyEvent.VK_S);646 create_shortcut.addActionListener(this);647 add(create_shortcut);648 }649 }650 }651 652 653 /** Called whenever one of the menu items is clicked, this method then causes the appropriate effect. */654 public void actionPerformed(ActionEvent event)655 {656 Object source = event.getSource();657 658 // Create shortcut659 if (source == create_shortcut) {660 CreateShortcutPrompt csp = new CreateShortcutPrompt(workspace_tree, node.getFile());661 csp.destroy();662 }663 664 // Delete shortcut665 else if (source == delete_shortcut) {666 workspace_tree.removeDirectoryMapping((WorkspaceTreeNode) node);667 }668 669 // Collapse folder670 else if (source == collapse_folder) {671 tree.collapsePath(selection_paths[0]);672 }673 674 // Expand folder675 else if (source == expand_folder) {676 tree.expandPath(selection_paths[0]);677 }678 679 // Explode metadata database680 else if (source == explode_metadata_database) {681 ExplodeMetadataPrompt emp = new ExplodeMetadataPrompt(node.getFile());682 //emp.destroy();683 }684 685 // Delete686 else if (source == delete) {687 FileNode[] source_nodes = new FileNode[selection_paths.length];688 for (int i = 0; i < selection_paths.length; i++) {689 source_nodes[i] = (FileNode) selection_paths[i].getLastPathComponent();690 }691 692 // Fire a delete action693 Gatherer.f_man.action(tree, source_nodes, Gatherer.recycle_bin, null);694 }695 696 // Meta-audit697 else if (source == metaaudit) {698 Gatherer.g_man.showMetaAuditBox();699 }700 701 // New folder702 else if (source == new_folder) {703 Gatherer.f_man.newFolder(tree, (CollectionTreeNode) node);704 }705 706 // New dummy doc707 else if (source == new_dummy_doc) {708 Gatherer.f_man.newDummyDoc(tree, (CollectionTreeNode) node);709 }710 711 // Open in external program712 else if (source == open_externally) {713 Gatherer.f_man.openFileInExternalApplication(node.getFile());714 }715 716 // Rename717 else if (source == rename) {718 Gatherer.f_man.renameCollectionFile(collection_tree, (CollectionTreeNode) node);719 }720 721 // Replace722 else if (source == replace) {723 Gatherer.f_man.replaceCollectionFile(collection_tree, (CollectionTreeNode) node);724 }725 }726 }727 728 729 /** This class listens for mouse clicks and responds right mouse button clicks (popup menu). */730 private class MouseListenerImpl731 extends MouseAdapter {732 /** Any subclass of MouseAdapter can override this method to respond to mouse click events. In this case we want to open a pop-up menu if we detect a right mouse click over one of our registered components, and start an external application if someone double clicks on a certain file record. */733 public void mouseClicked(MouseEvent event) {734 if (SwingUtilities.isRightMouseButton(event)) {735 new RightClickMenu((DragTree) event.getSource(), event);736 }737 }738 }739 423 }
Note:
See TracChangeset
for help on using the changeset viewer.