1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26 package org.ximtec.igesture.tool.view.admin;
27
28 import java.beans.PropertyChangeEvent;
29 import java.util.logging.Logger;
30
31 import javax.swing.tree.TreePath;
32
33 import org.ximtec.igesture.core.GestureClass;
34 import org.ximtec.igesture.core.GestureSet;
35 import org.ximtec.igesture.tool.core.Command;
36 import org.ximtec.igesture.tool.core.Controller;
37 import org.ximtec.igesture.tool.core.DefaultController;
38 import org.ximtec.igesture.tool.core.ExecCmd;
39 import org.ximtec.igesture.tool.core.TabbedView;
40 import org.ximtec.igesture.tool.core.TreePathAction;
41 import org.ximtec.igesture.tool.explorer.ExplorerTreeController;
42 import org.ximtec.igesture.tool.explorer.ExplorerTreeModel;
43 import org.ximtec.igesture.tool.util.NodeInfoFactory;
44 import org.ximtec.igesture.tool.view.MainModel;
45
46 public class AdminController extends DefaultController {
47
48
49
50 private static final Logger LOGGER = Logger.getLogger(AdminController.class.getName());
51
52 private static final String NEW_GESTURE_CLASS = "New Gesture Class";
53
54 public static final String ADD_GESTURE_CLASS_CMD = "addGestureClassCmd";
55
56
57
58
59 private AdminView adminView;
60
61
62
63
64 private MainModel mainModel;
65
66
67
68
69 private ExplorerTreeController explorerTreeController;
70
71
72 public AdminController(Controller parentController) {
73 super(parentController);
74 mainModel = getLocator().getService(MainModel.IDENTIFIER, MainModel.class);
75
76 initController();
77
78 }
79
80
81
82
83 private void initController() {
84 adminView = new AdminView(this);
85
86 ExplorerTreeModel explorerModel = new ExplorerTreeModel(mainModel.getGestureSetList(), NodeInfoFactory
87 .createAdminNodeInfo(this));
88 explorerTreeController = new ExplorerTreeController(this, adminView, explorerModel);
89
90 addController(explorerTreeController);
91 }
92
93 @Override
94 public TabbedView getView() {
95 return adminView;
96 }
97
98 @Override
99 public void propertyChange(PropertyChangeEvent evt) {
100 LOGGER.info("PropertyChange");
101 super.propertyChange(evt);
102
103 explorerTreeController.getExplorerTreeView().refresh();
104 }
105
106 @ExecCmd(name = ADD_GESTURE_CLASS_CMD, executeInEDT=false)
107 public void cmdAddGestureClass(Command command) {
108
109 GestureSet gestureSet = (GestureSet) getTreePath(command).getLastPathComponent();
110
111
112 String gestureClassName = NEW_GESTURE_CLASS;
113 int counter = 2;
114 while (gestureSet.getGestureClass(gestureClassName) != null) {
115 gestureClassName = NEW_GESTURE_CLASS + counter;
116 counter++;
117 }
118
119
120 GestureClass gestureClass = new GestureClass(gestureClassName);
121 gestureSet.addGestureClass(gestureClass);
122 }
123
124 private TreePath getTreePath(Command command) {
125
126 TreePathAction tpa = (TreePathAction) command.getSender();
127 return tpa.getTreePath();
128 }
129 }