1 package org.ximtec.igesture.tool.view.devicemanager.action;
2
3 import java.awt.event.ActionEvent;
4
5 import javax.swing.event.ListSelectionEvent;
6 import javax.swing.event.ListSelectionListener;
7
8 import org.sigtec.graphix.widget.BasicAction;
9 import org.ximtec.igesture.io.DeviceUserAssociation;
10 import org.ximtec.igesture.tool.GestureConstants;
11 import org.ximtec.igesture.tool.service.GuiBundleService;
12 import org.ximtec.igesture.tool.view.devicemanager.DeviceManagerController;
13 import org.ximtec.igesture.tool.view.devicemanager.DeviceManagerView;
14
15
16
17
18
19
20 public class RemoveDeviceAction extends BasicAction implements ListSelectionListener{
21
22 private DeviceManagerController controller;
23 private DeviceManagerView view;
24
25 public RemoveDeviceAction(DeviceManagerController controller, DeviceManagerView view)
26 {
27 this(controller,view,false);
28 }
29
30 public RemoveDeviceAction(DeviceManagerController controller, DeviceManagerView view, boolean enabled)
31 {
32 super(GestureConstants.REMOVE_DEVICE, controller.getLocator().getService(
33 GuiBundleService.IDENTIFIER, GuiBundleService.class));
34 this.controller = controller;
35 this.view = view;
36 setEnabled(enabled);
37 }
38
39 @Override
40 public void actionPerformed(ActionEvent e) {
41 DeviceUserAssociation device = view.getSelectedDevice();
42 device.getDeviceItem().disconnect();
43 controller.removeDevice(device.getDeviceItem());
44 }
45
46 @Override
47 public void valueChanged(ListSelectionEvent e) {
48 DeviceUserAssociation ass = view.getSelectedDevice();
49
50 if((ass != null) && (!ass.isDefaultDevice()))
51 setEnabled(true);
52 else
53 setEnabled(false);
54
55 }
56
57 }