/* * Software Name : ATK * * Copyright (C) 2007 - 2012 France Télécom * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * * ------------------------------------------------------------------ * File Name : ExpandAllAction.java * * Created : 05/06/2013 * Author(s) : D'ALMEIDA Joana */ package com.android.uiautomator.actions; import java.util.Enumeration; import javax.swing.JTree; import javax.swing.tree.TreeNode; import javax.swing.tree.TreePath; public class ExpandAllAction { public void expandTree(JTree tree) { TreeNode root = (TreeNode) tree.getModel().getRoot(); expandAll(tree, new TreePath(root)); } private void expandAll(JTree tree, TreePath path) { TreeNode node = (TreeNode) path.getLastPathComponent(); if (node.getChildCount() >= 0) { Enumeration enumeration = node.children(); while (enumeration.hasMoreElements()) { TreeNode n = (TreeNode) enumeration.nextElement(); TreePath p = path.pathByAddingChild(n); expandAll(tree, p); } } tree.expandPath(path); } }