1 4 package com.tc.admin.common; 5 6 import org.dijon.List; 7 8 import java.awt.event.ActionEvent ; 9 10 import javax.swing.DefaultListModel ; 11 import javax.swing.JPopupMenu ; 12 import javax.swing.ListModel ; 13 import javax.swing.event.ListSelectionEvent ; 14 import javax.swing.event.ListSelectionListener ; 15 16 public class XList extends List implements ListSelectionListener { 17 protected XPopupListener m_popupListener; 18 protected DeleteAction m_deleteAction; 19 20 public XList() { 21 super(); 22 m_popupListener = new XPopupListener(this); 23 m_popupListener.setPopupMenu(createPopup()); 24 addListSelectionListener(this); 25 } 26 27 public JPopupMenu createPopup() { 28 JPopupMenu popup = new JPopupMenu ("List Actions"); 29 30 popup.add(m_deleteAction = createDeleteAction()); 31 32 return popup; 33 } 34 35 protected DeleteAction createDeleteAction() { 36 return new DeleteAction(); 37 } 38 39 protected class DeleteAction extends XAbstractAction { 40 protected DeleteAction() { 41 super("Delete"); 42 } 43 44 public void actionPerformed(ActionEvent ae) { 45 ListModel model = getModel(); 46 47 if(model instanceof DefaultListModel ) { 48 int[] rows = getSelectedIndices(); 49 50 for(int i = rows.length-1; i >= 0; i--) { 51 ((DefaultListModel )model).remove(rows[i]); 52 } 53 } 54 } 55 } 56 57 public void valueChanged(ListSelectionEvent e) { 58 m_deleteAction.setEnabled(!isSelectionEmpty()); 59 } 60 } 61 | Popular Tags |