]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.browsing.ui.nattable/src/org/simantics/browsing/ui/nattable/override/TreeCollapseAllCommandHandler.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 / TreeCollapseAllCommandHandler.java
diff --git a/bundles/org.simantics.browsing.ui.nattable/src/org/simantics/browsing/ui/nattable/override/TreeCollapseAllCommandHandler.java b/bundles/org.simantics.browsing.ui.nattable/src/org/simantics/browsing/ui/nattable/override/TreeCollapseAllCommandHandler.java
new file mode 100644 (file)
index 0000000..3060f55
--- /dev/null
@@ -0,0 +1,58 @@
+/*******************************************************************************
+ * Copyright (c) 2013 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@gmail.com> - initial API and implementation
+ *******************************************************************************/
+package org.simantics.browsing.ui.nattable.override;
+
+import org.eclipse.nebula.widgets.nattable.command.ILayerCommandHandler;
+import org.eclipse.nebula.widgets.nattable.layer.ILayer;
+import org.eclipse.nebula.widgets.nattable.tree.TreeLayer;
+import org.eclipse.nebula.widgets.nattable.tree.command.TreeCollapseAllCommand;
+
+/**
+ * Command handler for the TreeCollapseAllCommand.
+ * <p>
+ * Will search over the whole tree structure in the associated TreeLayer to
+ * identify collapsible nodes and collapse them one after the other.
+ *
+ * @author Dirk Fauth
+ *
+ * @see TreeLayer
+ * @see TreeCollapseAllCommand
+ */
+public class TreeCollapseAllCommandHandler implements
+        ILayerCommandHandler<TreeCollapseAllCommand> {
+
+    /**
+     * 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 TreeCollapseAllCommandHandler(TreeLayer2 treeLayer) {
+        this.treeLayer = treeLayer;
+    }
+
+    @Override
+    public boolean doCommand(ILayer targetLayer, TreeCollapseAllCommand command) {
+        this.treeLayer.collapseAll();
+        return true;
+    }
+
+    @Override
+    public Class<TreeCollapseAllCommand> getCommandClass() {
+        return TreeCollapseAllCommand.class;
+    }
+
+}