Changeset 11608
- Timestamp:
- 2006-04-06T16:39:37+12:00 (18 years ago)
- Location:
- trunk/gli/src/org/greenstone/gatherer
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gli/src/org/greenstone/gatherer/collection/CollectionTree.java
r9026 r11608 28 28 29 29 import java.awt.*; 30 import java.awt.event.*; 30 31 import javax.swing.*; 32 import javax.swing.tree.*; 33 import org.greenstone.gatherer.gui.ExplodeMetadataPrompt; 31 34 import org.greenstone.gatherer.gui.tree.DragTree; 32 35 import org.greenstone.gatherer.gui.tree.DragTreeCellRenderer; 36 import org.greenstone.gatherer.Dictionary; 37 import org.greenstone.gatherer.Gatherer; 33 38 34 39 35 40 public class CollectionTree 36 41 extends DragTree 42 implements MouseListener 37 43 { 38 44 public CollectionTree(String name, CollectionTreeModel collection_tree_model, boolean mixed_selection) … … 40 46 super(name, collection_tree_model, mixed_selection); 41 47 setCellRenderer(new CollectionTreeCellRenderer()); 48 addMouseListener(this); 42 49 } 50 51 52 public void mouseClicked(MouseEvent event) 53 { 54 if (SwingUtilities.isRightMouseButton(event)) { 55 new CollectionTreeRightClickMenu(this, event); 56 } 57 } 58 59 public void mouseEntered(MouseEvent event) { } 60 61 public void mouseExited(MouseEvent event) { } 62 63 public void mousePressed(MouseEvent event) { } 64 65 public void mouseReleased(MouseEvent event) { } 43 66 44 67 … … 58 81 } 59 82 } 83 84 85 /** 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. 86 */ 87 private class CollectionTreeRightClickMenu 88 extends JPopupMenu 89 implements ActionListener 90 { 91 /** The tree over which the right click action occurred. */ 92 private CollectionTree collection_tree = null; 93 /** The tree nodes selected when the right click action occurred. */ 94 private TreePath[] selection_paths = null; 95 /** The file record over which the right click action occurred. */ 96 private CollectionTreeNode node = null; 97 98 private JMenuItem collapse_folder = null; 99 private JMenuItem expand_folder = null; 100 private JMenuItem explode_metadata_database = null; 101 private JMenuItem delete = null; 102 private JMenuItem metaaudit = null; 103 private JMenuItem new_folder = null; 104 private JMenuItem new_dummy_doc = null; 105 private JMenuItem open_externally = null; 106 private JMenuItem rename = null; 107 private JMenuItem replace = null; 108 109 110 private CollectionTreeRightClickMenu(CollectionTree collection_tree, MouseEvent event) 111 { 112 super(); 113 this.collection_tree = collection_tree; 114 115 // Note we have to use setImmediate() with the set selction paths 116 // otherwise the selection doesn't get updated until after the 117 // popup comes up. 118 119 // the right click position 120 TreePath right_click_path = collection_tree.getPathForLocation(event.getX(), event.getY()); 121 if (right_click_path == null) { 122 // user has clicked outside of the tree, clear the selection 123 selection_paths = null; 124 collection_tree.setImmediate(true); 125 collection_tree.clearSelection(); 126 collection_tree.setImmediate(false); 127 } 128 else { 129 // Get the paths currently selected in the tree 130 selection_paths = collection_tree.getSelectionPaths(); 131 if (selection_paths == null) { 132 // nothing currently selected - we shift the selection to 133 // the node that was right clicked on 134 selection_paths = new TreePath[1]; 135 selection_paths[0] = right_click_path; 136 collection_tree.setImmediate(true); 137 collection_tree.setSelectionPath(right_click_path); 138 collection_tree.setImmediate(false); 139 } 140 else if (selection_paths.length == 1 && ! selection_paths[0].equals( right_click_path)) { 141 collection_tree.setImmediate(true); 142 collection_tree.clearSelection(); 143 collection_tree.setSelectionPath(right_click_path); 144 collection_tree.setImmediate(false); 145 selection_paths[0] = right_click_path; 146 } 147 else { 148 // we had multiply selected paths in the tree. 149 // if we clicked on one of those paths, then use all the 150 // current selection, otherwise clear the selection and 151 // select the one we right clicked on 152 boolean clicked_in_selection = false; 153 for (int i = 0; i < selection_paths.length; i++) { 154 if (selection_paths[i].equals(right_click_path)) { 155 clicked_in_selection = true; 156 break; 157 } 158 } 159 if (!clicked_in_selection) { 160 // want the tree to update right away 161 collection_tree.setImmediate(true); 162 collection_tree.clearSelection(); 163 collection_tree.setSelectionPath(right_click_path); 164 collection_tree.setImmediate(false); 165 selection_paths = new TreePath[1]; 166 selection_paths[0] = right_click_path; 167 } 168 } 169 } 170 171 // Create an appropriate context menu, based on what is selected 172 buildContextMenu(selection_paths); 173 174 // Show the popup menu on screen 175 show(collection_tree, event.getX(), event.getY()); 176 } 177 178 179 private void buildContextMenu(TreePath[] selection_paths) 180 { 181 // If nothing is selected, only the new folder/dummy doc options are available... 182 if (selection_paths == null) { 183 new_folder = new JMenuItem(Dictionary.get("CollectionPopupMenu.New_Folder"), KeyEvent.VK_N); 184 new_folder.addActionListener(this); 185 add(new_folder); 186 187 new_dummy_doc = new JMenuItem(Dictionary.get("CollectionPopupMenu.New_Dummy_Doc")); 188 new_dummy_doc.addActionListener(this); 189 add(new_dummy_doc); 190 191 node = (CollectionTreeNode) collection_tree.getModel().getRoot(); 192 return; 193 } 194 195 // Meta-audit and delete options 196 metaaudit = new JMenuItem(Dictionary.get("Menu.Metadata_View", collection_tree.getSelectionDetails()), KeyEvent.VK_A); 197 metaaudit.addActionListener(this); 198 add(metaaudit); 199 200 delete = new JMenuItem(Dictionary.get("CollectionPopupMenu.Delete"), KeyEvent.VK_D); 201 delete.addActionListener(this); 202 add(delete); 203 204 // Only meta-audit and delete are available if multiple items are selected... 205 if (selection_paths.length > 1) { 206 return; 207 } 208 209 // Rename option 210 // !! TO DO: Remote building 211 if (!Gatherer.isGsdlRemote) { 212 rename = new JMenuItem(Dictionary.get("CollectionPopupMenu.Rename"), KeyEvent.VK_R); 213 rename.addActionListener(this); 214 add(rename); 215 } 216 217 TreePath path = selection_paths[0]; 218 node = (CollectionTreeNode) path.getLastPathComponent(); 219 220 // ---- Options for file nodes ---- 221 if (node.isLeaf()) { 222 // Explode metadata databases, for explodable files only 223 if (node.isExplodable()) { 224 explode_metadata_database = new JMenuItem(Dictionary.get("Menu.Explode_Metadata_Database"), KeyEvent.VK_E); 225 explode_metadata_database.addActionListener(this); 226 explode_metadata_database.setEnabled(!Gatherer.isGsdlRemote); 227 add(explode_metadata_database); 228 } 229 // Replace file 230 // !! TO DO: Remote building 231 if (!Gatherer.isGsdlRemote) { 232 replace = new JMenuItem(Dictionary.get("CollectionPopupMenu.Replace"), KeyEvent.VK_P); 233 replace.addActionListener(this); 234 add(replace); 235 } 236 237 // Open the file in an external program 238 open_externally = new JMenuItem(Dictionary.get("Menu.Open_Externally"), KeyEvent.VK_O); 239 open_externally.addActionListener(this); 240 add(open_externally); 241 242 return; 243 } 244 245 // ---- Options for folder nodes ---- 246 // Collapse or expand, depending on current status 247 if (collection_tree.isExpanded(path)) { 248 collapse_folder = new JMenuItem(Dictionary.get("Menu.Collapse"), KeyEvent.VK_C); 249 collapse_folder.addActionListener(this); 250 add(collapse_folder); 251 } 252 else { 253 expand_folder = new JMenuItem(Dictionary.get("Menu.Expand"), KeyEvent.VK_O); 254 expand_folder.addActionListener(this); 255 add(expand_folder); 256 } 257 258 // New folder/dummy doc options 259 if (!node.isReadOnly()) { 260 new_folder = new JMenuItem(Dictionary.get("CollectionPopupMenu.New_Folder"), KeyEvent.VK_N); 261 new_folder.addActionListener(this); 262 add(new_folder); 263 264 new_dummy_doc = new JMenuItem(Dictionary.get("CollectionPopupMenu.New_Dummy_Doc")); 265 new_dummy_doc.addActionListener(this); 266 add(new_dummy_doc); 267 } 268 } 269 270 271 /** Called whenever one of the menu items is clicked, this method then causes the appropriate effect. */ 272 public void actionPerformed(ActionEvent event) 273 { 274 Object source = event.getSource(); 275 276 // Collapse folder 277 if (source == collapse_folder) { 278 collection_tree.collapsePath(selection_paths[0]); 279 } 280 281 // Expand folder 282 else if (source == expand_folder) { 283 collection_tree.expandPath(selection_paths[0]); 284 } 285 286 // Explode metadata database 287 else if (source == explode_metadata_database) { 288 ExplodeMetadataPrompt emp = new ExplodeMetadataPrompt(node.getFile()); 289 //emp.destroy(); 290 } 291 292 // Delete 293 else if (source == delete) { 294 CollectionTreeNode[] source_nodes = new CollectionTreeNode[selection_paths.length]; 295 for (int i = 0; i < selection_paths.length; i++) { 296 source_nodes[i] = (CollectionTreeNode) selection_paths[i].getLastPathComponent(); 297 } 298 299 // Fire a delete action 300 Gatherer.f_man.action(collection_tree, source_nodes, Gatherer.recycle_bin, null); 301 } 302 303 // Meta-audit 304 else if (source == metaaudit) { 305 Gatherer.g_man.showMetaAuditBox(); 306 } 307 308 // New folder 309 else if (source == new_folder) { 310 Gatherer.f_man.newFolder(collection_tree, node); 311 } 312 313 // New dummy doc 314 else if (source == new_dummy_doc) { 315 Gatherer.f_man.newDummyDoc(collection_tree, node); 316 } 317 318 // Open in external program 319 else if (source == open_externally) { 320 Gatherer.f_man.openFileInExternalApplication(node.getFile()); 321 } 322 323 // Rename 324 else if (source == rename) { 325 Gatherer.f_man.renameCollectionFile(collection_tree, node); 326 } 327 328 // Replace 329 else if (source == replace) { 330 Gatherer.f_man.replaceCollectionFile(collection_tree, node); 331 } 332 } 333 } 60 334 } -
trunk/gli/src/org/greenstone/gatherer/gui/EnrichPane.java
r11601 r11608 132 132 collection_tree.putClientProperty("JTree.lineStyle", "Angled"); 133 133 collection_tree.addMouseListener(Gatherer.g_man.foa_listener); 134 collection_tree.addMouseListener(new RightButtonListener());135 134 collection_tree.addTreeSelectionListener(this); 136 135 collection_tree.addTreeExpansionListener(Gatherer.g_man.foa_listener); … … 389 388 } 390 389 } 391 392 393 /** A listener for right mouse button clicks over the collection tree. */394 private class RightButtonListener395 extends MouseAdapter {396 /** Called whenever a mouse click occurs (right or left) over a target component.397 * @param event A <strong>MouseEvent</strong> containing further information about the mouse click action.398 * @see org.greenstone.gatherer.gui.EnrichPane.RightButtonMenu399 */400 public void mouseClicked(MouseEvent event) {401 if (SwingUtilities.isRightMouseButton(event)) {402 new RightButtonMenu(event);403 }404 }405 }406 407 408 /** When a user right-clicks within the collection tree they are presented with a small popup menu of context based options. This class provides such functionality.409 */410 private class RightButtonMenu411 extends JPopupMenu412 implements ActionListener {413 414 /** The tree over which the right click action occurred. */415 private DragTree tree = null;416 /** The tree nodes selected when the right click action occurred. */417 private TreePath[] selection_paths = null;418 /** The file record over which the right click action occurred. */419 private CollectionTreeNode node = null;420 421 private JMenuItem collapse_folder = null;422 private JMenuItem expand_folder = null;423 private JMenuItem metaaudit = null;424 private JMenuItem open_externally = null;425 426 427 private RightButtonMenu(MouseEvent event)428 {429 super();430 this.tree = collection_tree;431 432 // Note we have to use setImmediate() with the set selction paths433 // otherwise the selection doesn't get updated until after the434 // popup comes up.435 436 // the right click position437 TreePath right_click_path = tree.getPathForLocation(event.getX(), event.getY());438 if (right_click_path == null) {439 // user has clicked outside of the tree, clear the selection440 selection_paths = null;441 tree.setImmediate(true);442 tree.clearSelection();443 tree.setImmediate(false);444 } else {445 // Get the paths currently selected in the tree446 selection_paths = tree.getSelectionPaths();447 if (selection_paths == null) {448 // nothing currently selected - we shift the selection to449 // the node that was right clicked on450 selection_paths = new TreePath[1];451 selection_paths[0] = right_click_path;452 tree.setImmediate(true);453 tree.setSelectionPath(right_click_path);454 tree.setImmediate(false);455 } else if (selection_paths.length == 1 && ! selection_paths[0].equals( right_click_path)) {456 tree.setImmediate(true);457 tree.clearSelection();458 tree.setSelectionPath(right_click_path);459 tree.setImmediate(false);460 selection_paths[0] = right_click_path;461 } else {462 // we had multiply selected paths in the tree.463 // if we clicked on one of those paths, then use all the464 // current selection, otherwise clear the selection and465 // select the one we right clicked on466 boolean clicked_in_selection = false;467 for (int i=0; i<selection_paths.length; i++) {468 if (selection_paths[i].equals(right_click_path)) {469 clicked_in_selection = true;470 break;471 }472 }473 if (!clicked_in_selection) {474 // want the tree to update right away475 tree.setImmediate(true);476 tree.clearSelection();477 tree.setSelectionPath(right_click_path);478 tree.setImmediate(false);479 selection_paths = new TreePath[1];480 selection_paths[0] = right_click_path;481 }482 }483 }484 // finally we have the correct selection paths!485 486 // Create an appropriate context menu, based on what is selected487 buildContextMenu(selection_paths);488 489 // Show the popup menu on screen490 show(tree, event.getX(), event.getY());491 }492 493 494 private void buildContextMenu(TreePath[] selection_paths)495 {496 // If nothing is selected, no options are available497 if (selection_paths == null) {498 return;499 }500 501 DebugStream.println("Number of files/folders selected: " + selection_paths.length);502 503 // Always have meta-audit option504 metaaudit = new JMenuItem(Dictionary.get("Menu.Metadata_View", collection_tree.getSelectionDetails()), KeyEvent.VK_A);505 metaaudit.addActionListener(this);506 add(metaaudit);507 508 // Only meta-audit is available if multiple items are selected...509 if (selection_paths.length > 1) {510 return;511 }512 513 TreePath path = selection_paths[0];514 node = (CollectionTreeNode) path.getLastPathComponent();515 516 // ---- Options for file nodes ----517 if (node.isLeaf()) {518 // Open the file in an external program519 open_externally = new JMenuItem(Dictionary.get("Menu.Open_Externally"), KeyEvent.VK_O);520 open_externally.addActionListener(this);521 add(open_externally);522 return;523 }524 525 // ---- Options for folder nodes ----526 // Collapse or expand, depending on current status527 if (tree.isExpanded(path)) {528 collapse_folder = new JMenuItem(Dictionary.get("Menu.Collapse"), KeyEvent.VK_C);529 collapse_folder.addActionListener(this);530 add(collapse_folder);531 }532 else {533 expand_folder = new JMenuItem(Dictionary.get("Menu.Expand"), KeyEvent.VK_O);534 expand_folder.addActionListener(this);535 add(expand_folder);536 }537 }538 539 540 /** Called whenever one of the menu items is clicked, this method then causes the appropriate effect. */541 public void actionPerformed(ActionEvent event)542 {543 Object source = event.getSource();544 545 // Collapse folder546 if (source == collapse_folder) {547 tree.collapsePath(selection_paths[0]);548 }549 550 // Expand folder551 else if (source == expand_folder) {552 tree.expandPath(selection_paths[0]);553 }554 555 // Meta-audit556 else if (source == metaaudit) {557 Gatherer.g_man.showMetaAuditBox();558 }559 560 // Open in external program561 else if (source == open_externally) {562 Gatherer.f_man.openFileInExternalApplication(node.getFile());563 }564 }565 }566 390 } -
trunk/gli/src/org/greenstone/gatherer/gui/GatherPane.java
r11603 r11608 257 257 collection_tree.setEnabled(Gatherer.c_man.getCollectionTreeModel() != null); 258 258 group.add(collection_tree); 259 collection_tree.addMouseListener(mouse_listener);260 259 collection_tree.addMouseListener(Gatherer.g_man.foa_listener); 261 260 collection_tree.addTreeExpansionListener(Gatherer.g_man.foa_listener);
Note:
See TracChangeset
for help on using the changeset viewer.