Changeset 8873
- Timestamp:
- 2004-12-22T09:18:23+13:00 (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gli/src/org/greenstone/gatherer/gems/GEMS.java
r8864 r8873 102 102 static final public String METADATA_SET_TEMPLATE = "xml/template.mds"; 103 103 static final public String METADATA_VALUE_TEMPLATE = "xml/template.mdv"; 104 105 //all of our popup menu items 106 static final public int T_COLLECTION = 0; 107 static final public int T_ELEMENT = 1; 108 static final public int T_PROFILER = 2; 109 static final public int T_ROOT = 3; 110 static final public int T_SET = 4; 104 111 105 112 // static final public String MAX_LOADED_SETS = 64; … … 165 172 //event was performed 166 173 private PopupListener popupListener = new PopupListener(this); 174 175 /**KeyPressedListener is a centralized manager for all key pressed action */ 176 // private KeyPressedListener keyPressedListener = new KeyPressedListener(); 177 167 178 /** A tree that represents the current metadata sets associated with this collection. */ 168 179 private SmarterTree mds_tree = null; … … 275 286 276 287 mds_tree.addMouseListener(popupListener); 288 mds_tree.addKeyListener(new KeyPressedHandler()); 277 289 details_pane = new JPanel(); 278 290 details_pane.setOpaque(false); … … 307 319 set_attributes.getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_SELECTION); 308 320 set_attributes.addMouseListener(popupListener); 321 set_attributes.addKeyListener(new RemoveAttributeActionListener()); //Listen for DELETE key 309 322 JPanel element_details_pane = new JPanel(); 310 323 element_details_pane.setOpaque(false); … … 337 350 element_attributes.getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_SELECTION); 338 351 element_attributes.addMouseListener(popupListener); 352 element_attributes.addKeyListener(new RemoveAttributeActionListener()); //For the DELETE key 339 353 340 354 element_values_layout = new CardLayout(); 341 355 element_values_pane = new JPanel(); 342 356 element_values_pane.setOpaque(false); … … 598 612 599 613 614 600 615 private class GEMSMenuBar 601 616 extends JMenuBar … … 1460 1475 String name_str = name.getSelectedItem().toString(); 1461 1476 String value_str = Codec.transform(Codec.transformUnicode(value.getText()), Codec.TEXT_TO_DOM); 1477 boolean cont = false; 1462 1478 1463 1479 // Remove the existing attribute if this is an edit … … 1472 1488 // Update the attribute table 1473 1489 model.add(new Attribute(name_str, value_str)); 1474 booleancont = true;1490 cont = true; 1475 1491 1476 /* // Check that there isn't already an entry for this attribute 1477 * 1478 1492 /* 1493 // Check that there isn't already an entry for this attribute 1479 1494 if (!model.contains(name_str, 0)) { 1480 1495 // Add the new attribute … … 1482 1497 // Update the attribute table 1483 1498 model.add(new Attribute(name_str, value_str)); 1499 cont = true; 1484 1500 } 1485 1501 // Otherwise show an error message and do not proceed … … 1487 1503 cont = false; 1488 1504 JOptionPane.showMessageDialog(self, Dictionary.get("GEMS.Attribute_Already_Exists"), Dictionary.get("General.Error"), JOptionPane.ERROR_MESSAGE); 1489 }*/ 1505 } 1506 */ 1490 1507 1491 1508 value_str = null; … … 2508 2525 2509 2526 private class RemoveAttributeActionListener 2510 implements ActionListener { 2527 implements ActionListener, KeyListener { 2528 2529 /** 2530 Any implementation of KeyListener must include these mothods. 2531 When the DELETE key is pressed, fire the actionPerformed event. 2532 */ 2533 public void keyTyped(KeyEvent e){ 2534 //Do nothing 2535 } 2536 public void keyPressed(KeyEvent e) 2537 { 2538 if(e.getKeyCode() == java.awt.event.KeyEvent.VK_DELETE) 2539 { 2540 //DELETE key pressed 2541 actionPerformed((ActionEvent)null); 2542 } 2543 } 2544 public void keyReleased(KeyEvent e) { 2545 //Do nothing 2546 } 2547 2511 2548 /** Any implementation of ActionListener must include this method so that we can be informed when an action as occured on our registered component, allowing us to 2512 2549 * @param event An <strong>ActionEvent</strong> containing information about the event. … … 2559 2596 private class RemoveElementActionListener 2560 2597 implements ActionListener { 2598 2561 2599 /** Any implementation of ActionListener must include this method so that we can be informed when an action as occured on our registered component, allowing us to provide an editing prompt. 2562 2600 * @param event An <strong>ActionEvent</strong> containing information about the event. … … 2573 2611 // Clear selection 2574 2612 mds_tree.clearSelection(); 2575 model.remove(current_element.toString(), GEMSNode.ELEMENT); 2613 model.remove(current_element.getName(), GEMSNode.ELEMENT); //Need to use .getName() not .toString!! 2614 2576 2615 // Meanwhile disable/enable controls given we had an element selected, but no longer do. 2577 2616 remove_element.setEnabled(false); … … 2588 2627 } 2589 2628 } 2629 2630 2631 2590 2632 2591 2633 private class RemoveFileActionListener … … 2614 2656 } 2615 2657 2658 /** 2659 Class to handle DELETE key presses on the tree. 2660 The class then fires the appropriate event to remove that element/set. 2661 Attributes in the table are handled directly by the RemoveAttributeActionListener 2662 2663 Author: Matthew Whyte 2664 Date last modified: 21/12/04 2665 */ 2666 private class KeyPressedHandler implements KeyListener { 2667 2668 // All implementations of KeyListener requires these methods 2669 public void keyTyped(KeyEvent e){ 2670 //Do nothing 2671 } 2672 public void keyPressed(KeyEvent e) 2673 { 2674 2675 if(e.getKeyCode() == java.awt.event.KeyEvent.VK_DELETE) //DELETE key pressed 2676 { 2677 boolean cont = true; 2678 2679 /** 2680 Check to see if more than one tree node/leaf is selected. If so don't continue. 2681 2682 This could be updated to delete multiple nodes/leaves in the futere. 2683 But not me and not today!! 2684 */ 2685 TreePath[] multiSelectionCheck = mds_tree.getSelectionPaths(); 2686 if(multiSelectionCheck.length > 1) 2687 { 2688 cont = false; 2689 Toolkit.getDefaultToolkit().beep(); 2690 } 2691 2692 if(cont) 2693 { 2694 //Check to see if pressed on Set or Element. 2695 TreePath selPath = mds_tree.getSelectionPath(); 2696 GEMSNode t = (GEMSNode)selPath.getLastPathComponent(); 2697 2698 if(t.type == T_ELEMENT) //Remove the element 2699 { 2700 //System.err.println("element"); 2701 RemoveElementActionListener removeElement = new RemoveElementActionListener(); 2702 removeElement.actionPerformed((ActionEvent)null); 2703 } 2704 2705 else if(t.type == T_ROOT) 2706 { 2707 //Do nothing 2708 System.err.println("Tree type of ROOT: this should not happen!"); 2709 } 2710 else if(t.type == T_SET) //Remove the whole set 2711 { 2712 //System.err.println("set"); 2713 RemoveSetActionListener removeSet = new RemoveSetActionListener(); 2714 removeSet.actionPerformed((ActionEvent)null); 2715 } 2716 } 2717 } 2718 } 2719 public void keyReleased(KeyEvent e) { 2720 //Do nothing 2721 } 2722 } 2723 2724 2616 2725 private class RemoveSetActionListener 2617 2726 implements ActionListener { 2727 2618 2728 /** Any implementation of ActionListener must include this method so that we can be informed when an action as occured on our registered component, allowing us to 2619 2729 * @param event An <strong>ActionEvent</strong> containing information about the event. … … 2625 2735 //not let anyone remove them --Attila 2626 2736 // System.out.println(current_set.getName()); 2627 //2628 2737 2629 2738 File current_set_filename = current_set.getFile(); … … 2930 3039 2931 3040 JMenuItem menuRemoveSet; 2932 //all of our popup menu items above2933 static final public int COLLECTION = 0;2934 static final public int ELEMENT = 1;2935 static final public int PROFILER = 2;2936 static final public int ROOT = 3;2937 static final public int SET = 4;2938 3041 2939 3042 GEMS GEMSRef = null; … … 2969 3072 2970 3073 menuRemoveSet = new JMenuItem(); 2971 3074 //Dictionary.setText(menuRemoveSet,"GEMS.Popup.menuRemoveSet"); 2972 3075 Dictionary.setText(menuRemoveSet,"GEMS.Remove_Set_Tooltip"); 2973 3076 … … 3015 3118 //start Associate the menu items with the appropriate popups: 3016 3119 //setPopup.add(menuRenameSet); 3017 3120 //setPopup.add(menuAddSet); 3018 3121 setPopup.add(menuAddAttributeSet); 3019 3122 setPopup.add(menuAddElement); … … 3036 3139 3037 3140 menuRemoveSet.addActionListener(new RemoveSetActionListener()); 3038 menuAddSet.addActionListener(new AddSetActionListener());3141 //menuAddSet.addActionListener(new AddSetActionListener()); 3039 3142 menuAddElement.addActionListener(new AddElementActionListener()); 3040 3143 menuAddAttributeSet.addActionListener(new AddOrEditAttributeActionListener()); … … 3102 3205 mds_tree.setSelectionPath(selPath); //Select node right-clicked on 3103 3206 3104 if(t.type == ELEMENT){3207 if(t.type == T_ELEMENT){ 3105 3208 3106 3209 elementPopup.show(e.getComponent(), 3107 3210 e.getX(), e.getY()); 3108 3211 } 3109 else if(t.type == ELEMENT){ 3212 3213 /* else if(t.type == T_ELEMENT){ 3110 3214 3111 3215 subfieldPopup.show(e.getComponent(), 3112 3216 e.getX(), e.getY()); 3113 } 3114 else if(t.type == ROOT){ 3217 } 3218 */ 3219 else if(t.type == T_ROOT){ 3115 3220 3116 3221 setPopup.show(e.getComponent(), 3117 3222 e.getX(), e.getY()); 3118 3223 } 3119 else if(t.type == SET){3224 else if(t.type == T_SET){ 3120 3225 3121 3226 setPopup.show(e.getComponent(),
Note:
See TracChangeset
for help on using the changeset viewer.