View Javadoc
1 /* 2 * ==================================================================== 3 * 4 * This code is subject to the freebxml License, Version 1.1 5 * 6 * Copyright (c) 2003 freebxml.org. All rights reserved. 7 * 8 * ==================================================================== 9 */ 10 11 package com.sun.xml.registry.client.browser; 12 13 import com.sun.xml.registry.client.browser.graph.*; 14 15 import java.awt.*; 16 import java.awt.event.*; 17 18 import java.util.*; 19 20 import javax.swing.*; 21 import javax.swing.event.*; 22 import javax.swing.table.*; 23 24 import javax.xml.registry.*; 25 import javax.xml.registry.infomodel.*; 26 27 import com.sun.xml.registry.client.browser.JAXRClient; 28 import com.sun.xml.registry.client.browser.RegistryBrowser; 29 import com.sun.xml.registry.ebxml.ConnectionImpl; 30 import com.sun.xml.registry.ebxml.util.ProviderProperties; 31 import com.sun.xml.registry.ebxml.infomodel.InternationalStringImpl; 32 33 import java.net.URL; 34 import javax.xml.registry.JAXRException; 35 36 import org.apache.commons.logging.Log; 37 import org.apache.commons.logging.LogFactory; 38 39 /*** 40 * A JTable that lists 41 * 42 * @author Jim Glennon 43 * @author <a href="mailto:Farrukh.Najmi@Sun.COM">Farrukh S. Najmi</a> 44 */ 45 public class RegistryObjectsTable extends JTable implements java.beans.PropertyChangeListener { 46 47 private static final Log log = 48 LogFactory.getLog(RegistryObjectsTableModel.class); 49 50 /*** DOCUMENT ME! */ 51 public static final String SELECTED_ROW_PROP = "selectedRow"; 52 53 //Hack to not keep setting columnWidth which prevented user from resing teh column manually 54 private static final int maxColWidth = 1000000; 55 56 57 /*** DOCUMENT ME! */ 58 int selectedRow = -1; 59 60 /*** DOCUMENT ME! */ 61 JPopupMenu popup; 62 63 /*** DOCUMENT ME! */ 64 JMenuItem editMenuItem = null; 65 66 /*** DOCUMENT ME! */ 67 JMenuItem removeMenuItem = null; 68 69 /*** DOCUMENT ME! */ 70 JMenuItem saveMenuItem = null; 71 72 /*** DOCUMENT ME! */ 73 JMenuItem browseMenuItem = null; 74 75 /*** DOCUMENT ME! */ 76 JMenuItem auditTrailMenuItem = null; 77 78 /*** DOCUMENT ME! */ 79 JMenuItem retrieveMenuItem = null; 80 81 /*** DOCUMENT ME! */ 82 MouseListener popupListener; 83 84 private boolean editable=false; 85 86 /*** DOCUMENT ME! */ 87 final RegistryObjectsTableModel tableModel; 88 89 int stdRowHeight = 0; 90 91 /*** 92 * Class Constructor. 93 * 94 * @param model 95 * 96 * @see 97 */ 98 public RegistryObjectsTable(TableModel model) { 99 super(model); 100 101 this.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); 102 103 if (model instanceof RegistryObjectsTableModel) { 104 tableModel = (RegistryObjectsTableModel)model; 105 } 106 else if (model instanceof TableSorter) { 107 tableModel = (RegistryObjectsTableModel)(((TableSorter)model).getModel()); 108 } 109 else { 110 throw new IllegalArgumentException("Error. Expected RegistryObjectsTableModel or TableSorter, got " + model); 111 } 112 setToolTipText("Use right mouse button to perform actions (e.g. edit, save, browse, show audit trail)"); 113 setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); 114 115 ListSelectionModel rowSM = getSelectionModel(); 116 stdRowHeight = getRowHeight(); 117 setRowHeight(stdRowHeight * 3); 118 119 rowSM.addListSelectionListener(new ListSelectionListener() { 120 public void valueChanged(ListSelectionEvent e) { 121 122 ListSelectionModel lsm = 123 (ListSelectionModel)e.getSource(); 124 125 if (!lsm.isSelectionEmpty()) { 126 setSelectedRow(lsm.getMinSelectionIndex()); 127 } else { 128 setSelectedRow(-1); 129 } 130 } 131 }); 132 133 createPopup(); 134 135 addRenderers(); 136 137 // Add listener to self so that I can bring up popup menus on right mouse click 138 popupListener = new PopupListener(); 139 addMouseListener(popupListener); 140 141 //add lister authenticated bound property 142 RegistryBrowser.getInstance().addPropertyChangeListener(RegistryBrowser.PROPERTY_AUTHENTICATED, this); 143 } 144 145 private void addRenderers() { 146 try { 147 setDefaultRenderer(Class.forName("java.lang.Object"), new JBDefaultTableCellRenderer()); 148 setDefaultRenderer(Class.forName("java.util.Collection"), new CollectionRenderer()); 149 150 final JList list = new JList(); 151 list.setVisibleRowCount(3); 152 list.setOpaque(true); 153 list.setCellRenderer(new ListDefaultRenderer()); 154 155 list.addListSelectionListener(new ListSelectionListener() { 156 public void valueChanged(javax.swing.event.ListSelectionEvent e) { 157 if (!e.getValueIsAdjusting()) { 158 Object obj = list.getSelectedValue(); 159 obj = RegistryObjectsTable.this.convertValue(obj); 160 if (obj instanceof URL) { 161 HyperLinker.displayURL(obj.toString()); 162 } 163 else if (obj instanceof String) { 164 //Check if URL is valid 165 URL _url = null; 166 try { 167 _url = new URL(obj.toString()); 168 HyperLinker.displayURL(obj.toString()); 169 } 170 catch (java.net.MalformedURLException exc) { 171 //No need to do anything. It is normal for text to not be a URL 172 } 173 174 } 175 } 176 } 177 }); 178 JScrollPane listPane = new JScrollPane(list); 179 setDefaultEditor(Class.forName("java.util.Collection"), new JBDefaultCellEditor(listPane)); 180 181 HyperLinkLabel hyperLinkLabel = new HyperLinkLabel(); 182 hyperLinkLabel.setHorizontalAlignment(SwingConstants.LEFT); 183 setDefaultEditor(Class.forName("java.lang.Object"), new JBDefaultCellEditor(hyperLinkLabel)); 184 } 185 catch (ClassNotFoundException e) { 186 } 187 } 188 189 public Class getColumnClass(int column) { 190 setColumnWidth(column); 191 192 Class clazz = tableModel.getColumnClass(column); 193 194 return clazz; 195 } 196 197 public TableCellRenderer getCellRenderer(int row, int column) { 198 TableCellRenderer renderer = null; 199 String columnName = tableModel.getColumnName(column); 200 Class clazz = null; 201 202 try { 203 clazz = tableModel.getColumnClass(column); 204 renderer = super.getCellRenderer(row, column); 205 206 if (renderer == null) { 207 RegistryBrowser.displayError("Configuration error for column: " + columnName + ". Unsupported columnClass:" + clazz); 208 } 209 } 210 catch (Exception e) { 211 RegistryBrowser.displayError("Configuration error for column: " + columnName + ". Unsupported columnClass:" + clazz, e); 212 } 213 214 return renderer; 215 } 216 217 private void createPopup() { 218 try { 219 220 JAXRClient client = RegistryBrowser.getInstance().getClient(); 221 ConnectionImpl connection = (ConnectionImpl)client.getConnection(); 222 boolean authenticated = connection.isAuthenticated(); 223 224 // Create popup menu for table 225 popup = new JPopupMenu(); 226 227 if (editable) { 228 editMenuItem = new JMenuItem("Edit"); 229 } 230 else { 231 editMenuItem = new JMenuItem("Show Details"); 232 } 233 popup.add(editMenuItem); 234 removeMenuItem = new JMenuItem("Remove"); 235 popup.add(removeMenuItem); 236 saveMenuItem = new JMenuItem("Save"); 237 popup.add(saveMenuItem); 238 browseMenuItem = new JMenuItem("Browse"); 239 popup.add(browseMenuItem); 240 auditTrailMenuItem = new JMenuItem("Show Audit Trail"); 241 popup.add(auditTrailMenuItem); 242 retrieveMenuItem = new JMenuItem("Retrieve Item"); 243 retrieveMenuItem.setVisible(false); 244 popup.add(retrieveMenuItem); 245 246 editMenuItem.addActionListener(new ActionListener() { 247 public void actionPerformed(ActionEvent ae) { 248 editAction(); 249 } 250 }); 251 252 removeMenuItem.addActionListener(new ActionListener() { 253 public void actionPerformed(ActionEvent ae) { 254 removeAction(); 255 } 256 }); 257 258 saveMenuItem.addActionListener(new ActionListener() { 259 public void actionPerformed(ActionEvent ae) { 260 saveAction(); 261 } 262 }); 263 264 browseMenuItem.addActionListener(new ActionListener() { 265 public void actionPerformed(ActionEvent ae) { 266 browseAction(); 267 } 268 }); 269 270 auditTrailMenuItem.addActionListener(new ActionListener() { 271 public void actionPerformed(ActionEvent ae) { 272 auditTrailAction(); 273 } 274 }); 275 276 retrieveMenuItem.addActionListener(new ActionListener() { 277 public void actionPerformed(ActionEvent ae) { 278 retrieveAction(); 279 } 280 }); 281 282 removeMenuItem.setVisible(authenticated); 283 saveMenuItem.setVisible(authenticated); 284 285 } catch (JAXRException e) { 286 RegistryBrowser.displayError(e); 287 } 288 289 } 290 291 /*** 292 * DOCUMENT ME! 293 */ 294 protected void editAction() { 295 RegistryBrowser.setWaitCursor(); 296 297 int[] selectedIndices = getSelectedRows(); 298 299 if (selectedIndices.length == 1) { 300 showSelectedObjectDetails(); 301 } else { 302 RegistryBrowser.displayError("Exactly one object must be selected in list for Show Details/Edit action."); 303 } 304 305 RegistryBrowser.setDefaultCursor(); 306 } 307 308 /*** 309 * DOCUMENT ME! 310 * 311 * @return DOCUMENT ME! 312 */ 313 ArrayList getSelectedRegistryObjects() { 314 315 ArrayList selectedObjects = new ArrayList(); 316 int[] selectedIndices = getSelectedRows(); 317 318 for (int i = 0; i < selectedIndices.length; i++) { 319 RegistryObject ro = (RegistryObject)dataModel.getValueAt(selectedIndices[i], -1); 320 selectedObjects.add(ro); 321 } 322 323 return selectedObjects; 324 } 325 326 /*** 327 * DOCUMENT ME! 328 */ 329 protected void removeAction() { 330 RegistryBrowser.setWaitCursor(); 331 332 int[] selectedIndices = getSelectedRows(); 333 334 if (selectedIndices.length >= 1) { 335 336 try { 337 338 ArrayList selectedObjects = 339 getSelectedRegistryObjects(); 340 ArrayList removeKeys = new ArrayList(); 341 342 int size = selectedObjects.size(); 343 344 for (int i = size - 1; i >= 0; i--) { 345 346 RegistryObject obj = 347 (RegistryObject)selectedObjects.get(i); 348 Key key = obj.getKey(); 349 removeKeys.add(key); 350 } 351 352 // Confirm the remove 353 boolean confirmRemoves = true; 354 String confirmRemovesStr = ProviderProperties.getInstance().getProperty 355 ("jaxr-ebxml.registryBrowser.confirmRemoves", "true"); 356 if (confirmRemovesStr.toLowerCase().equals("false") || 357 confirmRemovesStr.toLowerCase().equals("off")) 358 { 359 confirmRemoves = false; 360 } 361 if (confirmRemoves) { 362 int option = JOptionPane.showConfirmDialog(null, 363 "Are you sure you want to remove the selected " + 364 "items from the system?", "Confirm Remove", 365 JOptionPane.YES_NO_OPTION); 366 if (option == JOptionPane.NO_OPTION) { 367 RegistryBrowser.setDefaultCursor(); 368 return; 369 } 370 } 371 372 JAXRClient client = 373 RegistryBrowser.getInstance().getClient(); 374 BusinessLifeCycleManager lcm = 375 client.getBusinessLifeCycleManager(); 376 BulkResponse resp = 377 lcm.deleteObjects(removeKeys); 378 client.checkBulkResponse(resp); 379 380 if (resp.getStatus() == JAXRResponse.STATUS_SUCCESS) { 381 382 //Remove from UI model 383 ArrayList objects = 384 (ArrayList)((tableModel.getRegistryObjects()) 385 .clone()); 386 size = selectedIndices.length; 387 388 for (int i = size - 1; i >= 0; i--) { 389 390 RegistryObject ro = (RegistryObject)dataModel.getValueAt(selectedIndices[i], -1); 391 objects.remove(ro); 392 } 393 394 tableModel.setRegistryObjects(objects); 395 } 396 } catch (JAXRException e) { 397 RegistryBrowser.displayError(e); 398 } 399 } else { 400 RegistryBrowser.displayError("One or more objects must be selected in list for Remove action."); 401 } 402 403 RegistryBrowser.setDefaultCursor(); 404 } 405 406 /*** 407 * DOCUMENT ME! 408 */ 409 protected void saveAction() { 410 RegistryBrowser.setWaitCursor(); 411 412 int[] selectedIndices = getSelectedRows(); 413 414 if (selectedIndices.length >= 1) { 415 416 ArrayList selectedObjects = getSelectedRegistryObjects(); 417 418 try { 419 420 JAXRClient client = 421 RegistryBrowser.getInstance().getClient(); 422 client.saveObjects(selectedObjects); 423 } catch (JAXRException e) { 424 RegistryBrowser.displayError(e); 425 } 426 } else { 427 RegistryBrowser.displayError("One or more objects must be selected in list for Save action."); 428 } 429 430 RegistryBrowser.setDefaultCursor(); 431 } 432 433 /*** 434 * DOCUMENT ME! 435 */ 436 protected void browseAction() { 437 RegistryBrowser.setWaitCursor(); 438 439 int[] selectedIndices = getSelectedRows(); 440 441 if (selectedIndices.length >= 1) { 442 443 ArrayList selectedObjects = getSelectedRegistryObjects(); 444 Component parent = 445 SwingUtilities.getRoot(RegistryObjectsTable.this); 446 447 if (parent instanceof JFrame) { 448 JBGraphPanel.browseObjects((JFrame)parent, selectedObjects, editable); 449 } else if (parent instanceof JDialog) { 450 JBGraphPanel.browseObjects((JDialog)parent, 451 selectedObjects, editable); 452 } 453 } else { 454 RegistryBrowser.displayError("One or more objects must be selected in list for Browse action."); 455 } 456 457 RegistryBrowser.setDefaultCursor(); 458 } 459 460 /*** 461 * DOCUMENT ME! 462 */ 463 protected void auditTrailAction() { 464 RegistryBrowser.setWaitCursor(); 465 466 int[] selectedIndices = getSelectedRows(); 467 468 if (selectedIndices.length == 1) { 469 RegistryObject ro = (RegistryObject)dataModel.getValueAt(selectedRow, -1); 470 RegistryBrowser.showAuditTrail(ro); 471 } else { 472 RegistryBrowser.displayError("Exactly one object must be selected in list for Show Audit Trail action."); 473 } 474 475 RegistryBrowser.setDefaultCursor(); 476 } 477 478 /*** 479 * DOCUMENT ME! 480 */ 481 protected void retrieveAction() { 482 RegistryBrowser.setWaitCursor(); 483 484 int[] selectedIndices = getSelectedRows(); 485 486 if (selectedIndices.length == 1) { 487 488 RegistryObject ro = (RegistryObject)dataModel.getValueAt(selectedIndices[0], -1); 489 Component parent = 490 SwingUtilities.getRoot(RegistryObjectsTable.this); 491 RegistryBrowser.retrieveItem(ro); 492 } else { 493 RegistryBrowser.displayError("Exactly one object must be selected in list for Retrieve action."); 494 } 495 496 RegistryBrowser.setDefaultCursor(); 497 } 498 499 private void setColumnWidth(int col) { 500 TableColumnModel colModel = getColumnModel(); 501 TableColumn tcol = colModel.getColumn(col); 502 Component parent = getParent(); 503 504 if ((tcol.getMaxWidth() > maxColWidth) && (parent != null)) { 505 int parentWidth = parent.getWidth(); 506 507 if (tableModel != null) { 508 int width = tableModel.getColumnWidth(col); 509 510 int cols = tableModel.getColumnCount(); 511 if (width == 0 ) { 512 width = parentWidth / cols; 513 } 514 else { 515 //Width is a % of the viewport width 516 width = (width * parentWidth) / 100; 517 } 518 tcol.setPreferredWidth(width); 519 520 //Hack to not keep setting columnWidth which prevented user from resing teh column manually 521 tcol.setMaxWidth(maxColWidth); 522 } 523 } 524 525 } 526 527 /*** 528 * Overrides base class behaviour by setting selection when first 529 * row (destination) is added to model 530 * 531 * @param e DOCUMENT ME! 532 */ 533 public void tableChanged(TableModelEvent e) { 534 super.tableChanged(e); 535 536 // If no selectedRow, set selectedRow to firstRow 537 if ((selectedRow == -1) 538 && (e.getType() == TableModelEvent.INSERT)) { 539 540 // Following will result in a software initiated selection 541 // of the first row in table 542 ListSelectionModel rowSM = getSelectionModel(); 543 544 rowSM.setSelectionInterval(0, 0); 545 } 546 } 547 548 /*** 549 * Sets the currently selected row in table Also does 550 * firePropertyChange on property "selectedRow" 551 * 552 * @param index DOCUMENT ME! 553 */ 554 private void setSelectedRow(int index) { 555 556 Integer oldIndex = new Integer(selectedRow); 557 558 selectedRow = index; 559 firePropertyChange(SELECTED_ROW_PROP, oldIndex, 560 new Integer(index)); 561 } 562 563 /*** 564 * Method Declaration. 565 * 566 * @param makeVisible 567 * 568 * @see 569 */ 570 public void setVisible(boolean makeVisible) { 571 572 //jimbog Log.print(Log.TRACE,1,"Destination table visible:" + makeVisible); 573 if (makeVisible) { 574 } 575 576 super.setVisible(makeVisible); 577 } 578 579 /*** 580 * DOCUMENT ME! 581 */ 582 private void showSelectedObjectDetails() { 583 584 if (selectedRow >= 0) { 585 RegistryObject ro = (RegistryObject)dataModel.getValueAt(selectedRow, -1); 586 JBEditorDialog.showObjectDetails(this, ro, false, editable); 587 } 588 } 589 590 /*** 591 * Listens to property changes in the bound property RegistryBrowser.PROPERTY_AUTHENTICATED. 592 * Hides certain menuItems when user is unAuthenticated. 593 */ 594 public void propertyChange(java.beans.PropertyChangeEvent ev) { 595 if (ev.getPropertyName().equals(RegistryBrowser.PROPERTY_AUTHENTICATED)) { 596 597 boolean authenticated = ((Boolean)ev.getNewValue()).booleanValue(); 598 599 setEditable(authenticated); 600 } 601 } 602 603 /*** 604 * Converts an Object value to a format suitable for display in JTable. 605 */ 606 protected static Object convertValue(Object value) 607 { 608 Object finalValue = null; 609 Locale selectedLocale = RegistryBrowser.getInstance().getSelectedLocale(); 610 611 try { 612 613 if (value instanceof InternationalString) 614 { 615 finalValue = ((InternationalStringImpl)value).getClosestValue(selectedLocale); 616 } 617 else if (value instanceof ExternalLink) 618 { 619 finalValue = ((ExternalLink)value).getExternalURI(); 620 try { 621 URL url = new URL(((ExternalLink)value).getExternalURI()); 622 finalValue = url; 623 } 624 catch (java.net.MalformedURLException e) { 625 } 626 } 627 else if (value instanceof Collection) 628 { 629 //Converts elements of Collection 630 Collection c1 = (Collection)value; 631 Collection c2 = new ArrayList(); 632 java.util.Iterator iter = c1.iterator(); 633 while (iter.hasNext()) { 634 c2.add(convertValue(iter.next())); 635 } 636 finalValue = c2; 637 } 638 else if (value instanceof Slot) 639 { 640 Collection c = ((Slot)value).getValues(); 641 finalValue = c; 642 } 643 else if (value instanceof Concept) 644 { 645 finalValue = ((Concept)value).getValue(); 646 } 647 else 648 { 649 finalValue = value; 650 } 651 } 652 catch (JAXRException e) { 653 log.error(e); 654 } 655 return finalValue; 656 } 657 658 /*** 659 * Renderer used to render all Collection types. 660 * Uses a JList to display the Collection. 661 */ 662 class CollectionRenderer extends JScrollPane implements TableCellRenderer { 663 664 JList list; 665 public CollectionRenderer() { 666 list = new JList(); 667 Font font = RegistryObjectsTable.this.getFont(); 668 list.setFont(font); 669 list.setVisibleRowCount(3); 670 list.setOpaque(true); 671 ListDefaultRenderer renderer = new ListDefaultRenderer(); 672 renderer.setHorizontalAlignment(SwingConstants.LEFT); 673 list.setCellRenderer(renderer); 674 list.setBorder(BorderFactory.createEmptyBorder()); 675 this.setBorder(BorderFactory.createEmptyBorder()); 676 677 this.setViewportView(list); 678 //setHorizontalAlignment(CENTER); 679 //setVerticalAlignment(CENTER); 680 681 } 682 683 public Component getTableCellRendererComponent( 684 JTable table, 685 Object value, 686 boolean isSelected, 687 boolean hasFocus, 688 int row, 689 int column) 690 { 691 value = RegistryObjectsTable.this.convertValue(value); 692 693 if (isSelected) { 694 list.setBackground(table.getSelectionBackground()); 695 list.setForeground(table.getSelectionForeground()); 696 } 697 else { 698 list.setBackground(table.getBackground()); 699 list.setForeground(table.getForeground()); 700 } 701 702 DefaultListModel model = new DefaultListModel(); 703 Collection c = (Collection)value; 704 if (c != null) { 705 java.util.Iterator iter = c.iterator(); 706 while (iter.hasNext()) { 707 model.addElement(iter.next()); 708 } 709 } 710 list.setModel(model); 711 712 return this; 713 } 714 } 715 716 /*** 717 * Editor used to edit all types. 718 * Adds support for Collection and URL types to DefaultCellEditor 719 */ 720 class JBDefaultCellEditor extends DefaultCellEditor { 721 722 /*** 723 * Constructs a <code>JBDefaultCellEditor</code> that uses a JList field. 724 * 725 * @param x a <code>JList</code> object 726 */ 727 public JBDefaultCellEditor(final JScrollPane scrollPane) { 728 super(new JTextField()); 729 editorComponent = scrollPane; 730 731 this.clickCountToStart = 1; 732 final Component comp = scrollPane.getViewport().getView(); 733 delegate = new EditorDelegate() { 734 public void setValue(Object value) { 735 736 value = convertValue(value); 737 if (comp instanceof JList) { 738 JList list = (JList)comp; 739 DefaultListModel model = new DefaultListModel(); 740 741 if (value instanceof Collection) { 742 Collection c = (Collection)value; 743 java.util.Iterator iter = c.iterator(); 744 while (iter.hasNext()) { 745 Object obj = iter.next(); 746 model.addElement(obj); 747 } 748 } 749 list.setModel(model); 750 } 751 } 752 753 public Object getCellEditorValue() { 754 Object value = null; 755 if (comp instanceof JList) { 756 Collection c = new ArrayList(); 757 JList list = (JList)comp; 758 ListModel model = (ListModel)list.getModel(); 759 for (int i=0; i<model.getSize(); i++) { 760 c.add(model.getElementAt(i)); 761 } 762 value = c; 763 } 764 return value; 765 } 766 }; 767 //list.addActionListener(delegate); 768 } 769 770 /*** 771 * Constructs a <code>JBDefaultCellEditor</code> that uses a JList field. 772 * 773 * @param x a <code>JList</code> object 774 */ 775 public JBDefaultCellEditor(final HyperLinkLabel label) { 776 super(new JTextField()); 777 //list.setDefaultRenderer(Class.forName("java.net.URL"), new URLRenderer()); 778 779 editorComponent = label; 780 this.clickCountToStart = 1; 781 delegate = new EditorDelegate() { 782 public void setValue(Object value) { 783 try { 784 label.setURL(null); 785 } 786 catch (java.net.MalformedURLException e) { 787 //Do nothing as this will never be thrown here. 788 } 789 label.setText(value.toString()); 790 } 791 792 public Object getCellEditorValue() { 793 return label.getText(); 794 } 795 }; 796 //list.addActionListener(delegate); 797 } 798 } 799 800 class ListDefaultRenderer extends HyperLinkLabel implements ListCellRenderer { 801 public ListDefaultRenderer() { 802 setOpaque(true); 803 //setHorizontalAlignment(CENTER); 804 //setVerticalAlignment(CENTER); 805 } 806 807 public Component getListCellRendererComponent( 808 JList list, 809 Object value, 810 int index, 811 boolean isSelected, 812 boolean cellHasFocus) { 813 814 Font font = RegistryObjectsTable.this.getFont(); 815 setFont(font); 816 list.setFont(font); 817 818 if (isSelected) { 819 setBackground(list.getSelectionBackground()); 820 setForeground(list.getSelectionForeground()); 821 } 822 else { 823 setBackground(list.getBackground()); 824 setForeground(list.getForeground()); 825 } 826 827 value = RegistryObjectsTable.this.convertValue(value); 828 setText(value.toString()); 829 830 return this; 831 } 832 } 833 834 835 /*** 836 * Class Declaration. 837 * 838 * @author 839 * @version 1.9, 03/29/00 840 * 841 * @see 842 */ 843 class PopupListener extends MouseAdapter { 844 845 /*** 846 * DOCUMENT ME! 847 * 848 * @param e DOCUMENT ME! 849 */ 850 public void mousePressed(MouseEvent e) { 851 852 Point p = new Point(e.getX(), e.getY()); 853 int index = rowAtPoint(p); 854 855 Object ro = dataModel.getValueAt(index, -1); 856 if (ro instanceof ExtrinsicObject) { 857 retrieveMenuItem.setVisible(true); 858 } else { 859 retrieveMenuItem.setVisible(false); 860 } 861 862 maybeShowPopup(e); 863 864 if (e.getClickCount() > 1) { 865 //showSelectedObjectDetails(); 866 } 867 } 868 869 /*** 870 * DOCUMENT ME! 871 * 872 * @param e DOCUMENT ME! 873 */ 874 public void mouseReleased(MouseEvent e) { 875 maybeShowPopup(e); 876 } 877 878 /*** 879 * DOCUMENT ME! 880 * 881 * @param e DOCUMENT ME! 882 */ 883 private void maybeShowPopup(MouseEvent e) { 884 885 if (e.isPopupTrigger()) { 886 887 int[] selectedIndices = getSelectedRows(); 888 popup.show(e.getComponent(), e.getX(), e.getY()); 889 } 890 } 891 } 892 893 /*** 894 * Sets whether this dialog is read-only or editable. 895 */ 896 public void setEditable(boolean editable) { 897 this.editable = editable; 898 createPopup(); 899 } 900 901 /*** 902 * Tells whether this dialog is read-only or editable. 903 */ 904 public boolean isEditable() { 905 return editable; 906 } 907 908 }

This page was automatically generated by Maven