]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.browsing.ui.nattable/src/org/simantics/browsing/ui/nattable/override/TreeExpandToLevelCommandHandler.java
Merge "Testing SonarQube with Simantics Platform SDK"
[simantics/platform.git] / bundles / org.simantics.browsing.ui.nattable / src / org / simantics / browsing / ui / nattable / override / TreeExpandToLevelCommandHandler.java
1 /*******************************************************************************
2  * Copyright (c) 2014 Dirk Fauth and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  *    Dirk Fauth <dirk.fauth@ggooglemail.com> - initial API and implementation
10  *******************************************************************************/
11 package org.simantics.browsing.ui.nattable.override;
12
13 import org.eclipse.nebula.widgets.nattable.command.AbstractLayerCommandHandler;
14 import org.eclipse.nebula.widgets.nattable.tree.TreeLayer;
15 import org.eclipse.nebula.widgets.nattable.tree.command.TreeExpandToLevelCommand;
16
17 /**
18  * Command handler for the TreeExpandLevelCommand.
19  * <p>
20  * Will search over the whole tree structure in the associated TreeLayer to
21  * identify expandable nodes and expand them one after the other.
22  *
23  * @see TreeLayer
24  * @see TreeExpandToLevelCommand
25  *
26  */
27 public class TreeExpandToLevelCommandHandler extends AbstractLayerCommandHandler<TreeExpandToLevelCommand> {
28
29     /**
30      * The TreeLayer to which this command handler is connected.
31      */
32     private final TreeLayer2 treeLayer;
33
34     /**
35      *
36      * @param treeLayer
37      *            The TreeLayer to which this command handler should be
38      *            connected.
39      */
40     public TreeExpandToLevelCommandHandler(TreeLayer2 treeLayer) {
41         this.treeLayer = treeLayer;
42     }
43
44     @Override
45     public boolean doCommand(TreeExpandToLevelCommand command) {
46         if (command.getParentIndex() == null) {
47             this.treeLayer.expandAllToLevel(command.getLevel());
48         }
49         else {
50             this.treeLayer.expandTreeRowToLevel(command.getParentIndex(), command.getLevel());
51         }
52         return true;
53     }
54
55     @Override
56     public Class<TreeExpandToLevelCommand> getCommandClass() {
57         return TreeExpandToLevelCommand.class;
58     }
59
60 }