View Javadoc

1   /*
2    * @(#)$Id: AdminController.java 790 2010-03-28 11:03:45Z bpuype $
3    *
4    * Author   : Ueli Kurmann, igesture@uelikurmann.ch
5    *                                   
6    *                                   
7    * Purpose  : 
8    *
9    * -----------------------------------------------------------------------
10   *
11   * Revision Information:
12   *
13   * Date       Who     Reason
14   *
15   * 23.03.2008 ukurmann  Initial Release
16   *
17   * -----------------------------------------------------------------------
18   *
19   * Copyright 1999-2009 ETH Zurich. All Rights Reserved.
20   *
21   * This software is the proprietary information of ETH Zurich.
22   * Use is subject to license terms.
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     * the view of this controller
58     */
59    private AdminView adminView;
60  
61    /**
62     * Reference to the main model.
63     */
64    private MainModel mainModel;
65  
66    /**
67     * Explorer Tree Controller
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     * Initializes the controller.
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     // find a unique name for the new gesture class
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     // create the gesture class and add it to the gesture set
120     GestureClass gestureClass = new GestureClass(gestureClassName);
121     gestureSet.addGestureClass(gestureClass);
122   }
123 
124   private TreePath getTreePath(Command command) {
125     // FIXME null pointer checks, throw exceptions
126     TreePathAction tpa = (TreePathAction) command.getSender();
127     return tpa.getTreePath();
128   }
129 }