KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tc > admin > common > XList


1 /*
2  * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
3  */

4 package com.tc.admin.common;
5
6 import org.dijon.List;
7
8 import java.awt.event.ActionEvent JavaDoc;
9
10 import javax.swing.DefaultListModel JavaDoc;
11 import javax.swing.JPopupMenu JavaDoc;
12 import javax.swing.ListModel JavaDoc;
13 import javax.swing.event.ListSelectionEvent JavaDoc;
14 import javax.swing.event.ListSelectionListener JavaDoc;
15
16 public class XList extends List implements ListSelectionListener JavaDoc {
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 JavaDoc createPopup() {
28     JPopupMenu JavaDoc popup = new JPopupMenu JavaDoc("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 JavaDoc ae) {
45       ListModel JavaDoc model = getModel();
46       
47       if(model instanceof DefaultListModel JavaDoc) {
48         int[] rows = getSelectedIndices();
49       
50         for(int i = rows.length-1; i >= 0; i--) {
51           ((DefaultListModel JavaDoc)model).remove(rows[i]);
52         }
53       }
54     }
55   }
56
57   public void valueChanged(ListSelectionEvent JavaDoc e) {
58     m_deleteAction.setEnabled(!isSelectionEmpty());
59   }
60 }
61
Popular Tags