View Javadoc

1   /*
2    *  File: JaretTimeBarsActionFactory.java 
3    *  Copyright (c) 2004-2007  Peter Kliem (Peter.Kliem@jaret.de)
4    *  A commercial license is available, see http://www.jaret.de.
5    *
6    *  This program is free software; you can redistribute it and/or modify
7    *  it under the terms of the GNU General Public License as published by
8    *  the Free Software Foundation; either version 2 of the License, or
9    *  (at your option) any later version.
10   *
11   *  This program is distributed in the hope that it will be useful,
12   *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13   *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14   *  GNU General Public License for more details.
15   *
16   *  You should have received a copy of the GNU General Public License
17   *  along with this program; if not, write to the Free Software
18   *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19   */
20  package de.jaret.util.ui.timebars.swt.util.actions;
21  
22  import java.util.HashMap;
23  import java.util.Map;
24  
25  import org.eclipse.jface.action.Action;
26  
27  import de.jaret.util.ui.timebars.TimeBarViewerDelegate;
28  import de.jaret.util.ui.timebars.swt.TimeBarViewer;
29  
30  /**
31   * Factory producing some actions that are useful when using the timebar viewer.
32   * 
33   * @author Peter Kliem
34   * @version $Id: JaretTimeBarsActionFactory.java 160 2007-01-02 22:02:40Z olk $
35   */
36  public class JaretTimeBarsActionFactory {
37      public static final String ACTION_SCALETOWEEK = ScaleWeekAction.class.getCanonicalName();
38      public static final String ACTION_SCALETOMONTH = ScaleMonthAction.class.getCanonicalName();
39      public static final String ACTION_SCALETOYEAR = ScaleYearAction.class.getCanonicalName();
40      public static final String ACTION_CENTERSCALE = CenterScaleAction.class.getCanonicalName();
41      public static final String ACTION_EXPANDALL = ExpandAllAction.class.getCanonicalName();
42      public static final String ACTION_COLLAPSEALL = CollapseAllAction.class.getCanonicalName();
43      public static final String ACTION_EXPANDNODE = ExpandNodeAction.class.getCanonicalName();
44      public static final String ACTION_COLLAPSENODE = CollapseNodeAction.class.getCanonicalName();
45  
46      private final TimeBarViewer _viewer;
47      private final TimeBarViewerDelegate _delegate;
48      private Map<String, Action> _actionMap;
49  
50      public JaretTimeBarsActionFactory(TimeBarViewer viewer, TimeBarViewerDelegate delegate) {
51          _viewer = viewer;
52          _delegate = delegate;
53      }
54  
55      /**
56       * Create or return action denoted by constant.
57       * 
58       * @param name name of the action as one of the constants defined herin.
59       * @return action or null if there is no action for the name
60       */
61      public Action createStdAction(String name) {
62          if (_actionMap == null) {
63              _actionMap = new HashMap<String, Action>();
64          }
65          Action result = _actionMap.get(name);
66          if (result != null) {
67              return result;
68          }
69          if (name.equals(ACTION_SCALETOWEEK)) {
70              result = new ScaleWeekAction(_viewer, _delegate);
71          } else if (name.equals(ACTION_SCALETOMONTH)) {
72              result = new ScaleMonthAction(_viewer, _delegate);
73          } else if (name.equals(ACTION_SCALETOYEAR)) {
74              result = new ScaleYearAction(_viewer, _delegate);
75          } else if (name.equals(ACTION_CENTERSCALE)) {
76              result = new CenterScaleAction(_viewer, _delegate);
77          } else if (name.equals(ACTION_COLLAPSEALL)) {
78              result = new CollapseAllAction(_viewer, _delegate);
79          } else if (name.equals(ACTION_EXPANDALL)) {
80              result = new ExpandAllAction(_viewer, _delegate);
81          } else if (name.equals(ACTION_COLLAPSENODE)) {
82              result = new CollapseNodeAction(_viewer, _delegate);
83          } else if (name.equals(ACTION_EXPANDNODE)) {
84              result = new ExpandNodeAction(_viewer, _delegate);
85          }
86          if (result != null) {
87              _actionMap.put(name, result);
88          }
89          return result;
90      }
91  
92  }