Vector<Class<?>> hardwaresType = Hardware.getHardwares();
Vector<Class<?>> hardwaresInstalled = new Vector<Class<?>>();
// Searching all unique hardware installed
for (Container ghost: cultureViewer.culture.getHardwares()) {
Hardware hardware;
try{
hardware=(Hardware)ghost.getData();
}catch(IOException e){
Messages.showException(e);
hardware=null;
}catch(ClassNotFoundException e){
Messages.showException(e);
hardware=null;
}
if(hardware!=null){
if (hardware.isInstalled()) {
if (hardware.isUnique()) {
hardwaresInstalled.add(hardware.getClass());
}
}
}
}
for (Class<?> hardwareType : hardwaresType) {
// Checking if hardware type unique and installed.
if (!hardwaresInstalled.contains(hardwareType)) {
// Adding jMenu
JMenuItem jMenuItem = new JMenuItem();
jMenuItem.setText(Messages.getMessage(Hardware.class
.getSimpleName().toLowerCase()
+ "." + hardwareType.getSimpleName().toLowerCase()));
jMenuItem.setIcon(Hardware.getIcon(hardwareType));
jMenuItem.setName(hardwareType.getName());
jMenuItem
.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(
java.awt.event.ActionEvent e) {
JMenuItem jMenuItem = (JMenuItem) e.getSource();
try {
Hardware hardware=(Hardware) Class.forName(jMenuItem.getName()).newInstance();
cultureViewer.culture.getHardwares().store(hardware);
cultureViewer.getJListHardwares().setSelectedValue(hardware, true);
} catch (Exception ex) {
Messages.showException(ex);
}