try{variety=(Variety)ghost.getData();}
catch(ClassNotFoundException e){Messages.showException(e);variety=null;}
catch(IOException e){Messages.showException(e);variety=null;}
// Checking if variety type is added.
Plants plants=(Plants)panel.getEvent();
if (!plants.getVarieties().contains(variety)) {
// Adding jMenu
JMenuItem jMenuItem = new JMenuItem();
jMenuItem.setText(variety.getName());
jMenuItem.setName(variety.toString());
jMenuItem
.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(
java.awt.event.ActionEvent e) {
JMenuItem jMenuItem = (JMenuItem) e.getSource();
ContainerVector varietiesAvaible = Resources.getResources().getVarieties();
java.util.Iterator<Container> iterator=varietiesAvaible.iterator();
while(iterator.hasNext()){
Container ghost=(Container)iterator.next();
Variety variety;
try{variety=(Variety)ghost.getData();}
catch(ClassNotFoundException ex){Messages.showException(ex);variety=null;}
catch(IOException ex){Messages.showException(ex);variety=null;}
if(variety.toString().equals(jMenuItem.getName())){
Plants plants=(Plants)panel.getEvent();
plants.setPlants(variety,1);
// Refresh
panel.setEvent(panel.getEvent());
}
}
}