]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.browsing.ui.nattable/src/org/simantics/browsing/ui/nattable/override/TreeExpandToLevelCommandHandler.java
Sync git svn branch with SVN repository r33144.
[simantics/platform.git] / bundles / org.simantics.browsing.ui.nattable / src / org / simantics / browsing / ui / nattable / override / TreeExpandToLevelCommandHandler.java
diff --git a/bundles/org.simantics.browsing.ui.nattable/src/org/simantics/browsing/ui/nattable/override/TreeExpandToLevelCommandHandler.java b/bundles/org.simantics.browsing.ui.nattable/src/org/simantics/browsing/ui/nattable/override/TreeExpandToLevelCommandHandler.java
new file mode 100644 (file)
index 0000000..b7fa972
--- /dev/null
@@ -0,0 +1,60 @@
+/*******************************************************************************
+ * Copyright (c) 2014 Dirk Fauth and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *    Dirk Fauth <dirk.fauth@ggooglemail.com> - initial API and implementation
+ *******************************************************************************/
+package org.simantics.browsing.ui.nattable.override;
+
+import org.eclipse.nebula.widgets.nattable.command.AbstractLayerCommandHandler;
+import org.eclipse.nebula.widgets.nattable.tree.TreeLayer;
+import org.eclipse.nebula.widgets.nattable.tree.command.TreeExpandToLevelCommand;
+
+/**
+ * Command handler for the TreeExpandLevelCommand.
+ * <p>
+ * Will search over the whole tree structure in the associated TreeLayer to
+ * identify expandable nodes and expand them one after the other.
+ *
+ * @see TreeLayer
+ * @see TreeExpandToLevelCommand
+ *
+ */
+public class TreeExpandToLevelCommandHandler extends AbstractLayerCommandHandler<TreeExpandToLevelCommand> {
+
+    /**
+     * The TreeLayer to which this command handler is connected.
+     */
+    private final TreeLayer2 treeLayer;
+
+    /**
+     *
+     * @param treeLayer
+     *            The TreeLayer to which this command handler should be
+     *            connected.
+     */
+    public TreeExpandToLevelCommandHandler(TreeLayer2 treeLayer) {
+        this.treeLayer = treeLayer;
+    }
+
+    @Override
+    public boolean doCommand(TreeExpandToLevelCommand command) {
+        if (command.getParentIndex() == null) {
+            this.treeLayer.expandAllToLevel(command.getLevel());
+        }
+        else {
+            this.treeLayer.expandTreeRowToLevel(command.getParentIndex(), command.getLevel());
+        }
+        return true;
+    }
+
+    @Override
+    public Class<TreeExpandToLevelCommand> getCommandClass() {
+        return TreeExpandToLevelCommand.class;
+    }
+
+}