001    /******************************************************************************
002     * Copyright (C) MActor Developers. All rights reserved.                        *
003     * ---------------------------------------------------------------------------*
004     * This file is part of MActor.                                               *
005     *                                                                            *
006     * MActor is free software; you can redistribute it and/or modify             *
007     * it under the terms of the GNU General Public License as published by       *
008     * the Free Software Foundation; either version 2 of the License, or          *
009     * (at your option) any later version.                                        *
010     *                                                                            *
011     * MActor is distributed in the hope that it will be useful,                  *
012     * but WITHOUT ANY WARRANTY; without even the implied warranty of             *
013     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the              *
014     * GNU General Public License for more details.                               *
015     *                                                                            *
016     * You should have received a copy of the GNU General Public License          *
017     * along with MActor; if not, write to the Free Software                      *
018     * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA *
019     ******************************************************************************/
020    package org.mactor.ui.gui.project;
021    
022    import java.util.Iterator;
023    
024    public class ProjectTreeUtil {
025            public static ProjectTreeNode navigateToFirstFileNodeOfType(ProjectNodeType type, ProjectTreeNode fromNode) {
026                    if (fromNode == null)
027                            return null;
028                    ProjectTreeNode root = navigateToRoot(fromNode);
029                    Iterator<ProjectTreeNode> orgNodeIt = root.getChildNodes().iterator();
030                    while (orgNodeIt.hasNext()) {
031                            ProjectTreeNode node = orgNodeIt.next();
032                            if (node.getChildCount() > 0) {
033                                    if (node.getChildNode(0).getNodeType().equals(type))
034                                            return node.getChildNode(0);
035                            }
036                    }
037                    return null;
038            }
039            public static ProjectTreeNode navigateToOrganizationNode(ProjectTreeNode fromNode) {
040                    if (fromNode == null)
041                            return null;
042                    if (fromNode instanceof OrganizationProjectTreeNode)
043                            return fromNode;
044                    ProjectTreeNode parent = fromNode.getParentNode();
045                    while (parent.getParentNode() != null) {
046                            if (parent instanceof OrganizationProjectTreeNode)
047                                    return parent;
048                            parent = parent.getParentNode();
049                    }
050                    return null;
051            }
052            public static ProjectTreeNode navigateToRoot(ProjectTreeNode fromNode) {
053                    if (fromNode == null)
054                            return null;
055                    if (fromNode.getParentNode() == null)
056                            return fromNode;
057                    ProjectTreeNode parent = fromNode.getParentNode();
058                    while (parent.getParentNode() != null) {
059                            parent = parent.getParentNode();
060                    }
061                    return parent;
062            }
063    }