View Javadoc

1   // %2153978627:hoplugins.teamAnalyzer.ui.component%
2   package hoplugins.teamAnalyzer.ui.component;
3   
4   import hoplugins.Commons;
5   
6   import hoplugins.commons.utils.PluginProperty;
7   
8   import hoplugins.teamAnalyzer.SystemManager;
9   import hoplugins.teamAnalyzer.dao.FavoritesDAO;
10  import hoplugins.teamAnalyzer.ui.controller.FavoriteItemListener;
11  import hoplugins.teamAnalyzer.vo.Team;
12  
13  import java.awt.event.ActionEvent;
14  import java.awt.event.ActionListener;
15  
16  import java.util.ArrayList;
17  import java.util.Iterator;
18  import java.util.List;
19  
20  import javax.swing.JMenu;
21  import javax.swing.JMenuItem;
22  import javax.swing.JOptionPane;
23  import javax.swing.JSeparator;
24  
25  
26  /***
27   * A Favourite Menu
28   *
29   * @author <a href=mailto:draghetto@users.sourceforge.net>Massimiliano Amato</a>
30   */
31  public class FavouriteMenu extends JMenu {
32      //~ Instance fields ----------------------------------------------------------------------------
33  
34      /*** The DB Access object */
35      public FavoritesDAO dao = new FavoritesDAO();
36  
37      /*** Add menu item */
38      public JMenuItem itemAdd = new JMenuItem(Commons.getModel().getResource().getProperty("Hinzufuegen"));
39  
40      /*** Delete menu item */
41      public JMenuItem itemDelete = new JMenuItem(Commons.getModel().getResource().getProperty("loeschen"));
42  
43      /*** List of favourite team menu items */
44      public List items;
45  
46      /*** List of favourite team objects */
47      public List teams;
48  
49      /*** Reference to itself */
50      private FavouriteMenu me;
51  
52      //~ Constructors -------------------------------------------------------------------------------
53  
54      /***
55       * Creates a new FavouriteMenu object.
56       */
57      public FavouriteMenu() {
58          super(PluginProperty.getString("Favourite"));
59          jbInit();
60          me = this;
61      }
62  
63      //~ Methods ------------------------------------------------------------------------------------
64  
65      /***
66       * Initiates the gui
67       */
68      private void jbInit() {
69          teams = dao.getTeams();
70          items = new ArrayList();
71  
72          for (Iterator iter = teams.iterator(); iter.hasNext();) {
73              Team element = (Team) iter.next();
74              JMenuItem item = new JMenuItem(element.getName());
75  
76              item.addActionListener(new FavoriteItemListener(element));
77              add(item);
78              items.add(item);
79          }
80  
81          add(new JSeparator());
82          add(itemAdd);
83          add(itemDelete);
84  
85          if (teams.size() == 0) {
86              itemDelete.setVisible(false);
87          }
88  
89          itemDelete.addActionListener(new ActionListener() {
90                  public void actionPerformed(ActionEvent arg0) {
91                      JOptionPane.showMessageDialog(SystemManager.getPlugin().getPluginPanel(),
92                                                    new DeletePanel(me),
93                                                    Commons.getModel().getResource().getProperty("loeschen")
94                                                    + " "
95                                                    + Commons.getModel().getResource().getProperty("Verein"),
96                                                    JOptionPane.PLAIN_MESSAGE);
97                      ;
98                  }
99              });
100 
101         itemAdd.addActionListener(new ActionListener() {
102                 public void actionPerformed(ActionEvent arg0) {
103                     JOptionPane.showMessageDialog(SystemManager.getPlugin().getPluginPanel(),
104                                                   new AddPanel(me),
105                                                   Commons.getModel().getResource().getProperty("Hinzufuegen")
106                                                   + " "
107                                                   + Commons.getModel().getResource().getProperty("Verein"),
108                                                   JOptionPane.PLAIN_MESSAGE);
109                     ;
110                 }
111             });
112     }
113 }