View Javadoc

1   /*
2    *  File: CollapseAllAction.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 org.eclipse.jface.action.Action;
23  
24  import de.jaret.util.ui.timebars.TimeBarViewerDelegate;
25  import de.jaret.util.ui.timebars.model.TimeBarNode;
26  import de.jaret.util.ui.timebars.swt.TimeBarViewer;
27  
28  /**
29   * Action causing all nodes to collapse.
30   * 
31   * @author Peter Kliem
32   * @version $Id: CollapseAllAction.java 160 2007-01-02 22:02:40Z olk $
33   */
34  public class CollapseAllAction extends Action {
35      /** the timebarviewer th action has been constructed for. */
36      private final TimeBarViewer _viewer;
37      /** the delegate of the timebarviewer. */
38      private final TimeBarViewerDelegate _delegate;
39  
40      /**
41       * Constructor.
42       * 
43       * @param viewer timebar viewer
44       * @param delegate delegate of the viewer.
45       */
46      public CollapseAllAction(TimeBarViewer viewer, TimeBarViewerDelegate delegate) {
47          _viewer = viewer;
48          _delegate = delegate;
49      }
50  
51      /**
52       * {@inheritDoc}
53       */
54      public void run() {
55          if (_delegate.getHierarchicalViewState() != null) {
56              TimeBarNode root = _delegate.getHierarchicalModel().getRootNode();
57              _delegate.getHierarchicalViewState().setExpandedRecursive(root, false);
58          }
59      }
60  
61      /**
62       * {@inheritDoc}
63       */
64      public String getText() {
65          return "Collapse all";
66      }
67  }