1 /* 2 * $Id$ 3 * 4 * Copyright (c) 2009, 2013, Oracle and/or its affiliates. All rights reserved. 5 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 6 * 7 * This code is free software; you can redistribute it and/or modify it 8 * under the terms of the GNU General Public License version 2 only, as 9 * published by the Free Software Foundation. Oracle designates this 10 * particular file as subject to the "Classpath" exception as provided 11 * by Oracle in the LICENSE file that accompanied this code. 12 * 13 * This code is distributed in the hope that it will be useful, but WITHOUT 14 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 15 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 16 * version 2 for more details (a copy is included in the LICENSE file that 17 * accompanied this code). 18 * 19 * You should have received a copy of the GNU General Public License version 20 * 2 along with this work; if not, write to the Free Software Foundation, 21 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 22 * 23 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 24 * or visit www.oracle.com if you need additional information or have any 25 * questions. 26 */ 27 28 package com.sun.javatest.exec; 29 30 import java.util.LinkedList; 31 import javax.swing.tree.TreeNode; 32 33 /** 34 * Basic part of the onscreen model of the test tree. 35 */ 36 public abstract class TT_TreeNode implements TreeNode { 37 /** 38 * Short name that should be shown in user interfaces. 39 * @return Concise description of this node instance. 40 */ 41 abstract String getDisplayName(); 42 43 /** 44 * Description to be shown when needed. 45 * @return Verbose description of this node instance. 46 * @see TT_TreeNode#getDisplayName() 47 */ 48 abstract String getLongDescription(); 49 50 /** 51 * Get the long internal representation of this location. 52 * @return Null if the node is the root, else a forward slash separated 53 * path. 54 */ 55 abstract String getLongPath(); 56 57 /** 58 * String for use whenever you need a basic name for this node. You can 59 * assume that this name is unique within any node. 60 * @return Short name for this node, containing no forward slashes or 61 * spaces. 62 */ 63 abstract String getShortName(); 64 65 TT_TreeNode[] getNodePath() { 66 if (parent == null) 67 return new TT_TreeNode[] {this}; 68 69 LinkedList<TT_TreeNode> l = new LinkedList<>(); 70 l.add(this); 71 72 TT_TreeNode spot = parent; 73 do { 74 l.add(0, spot); 75 spot = spot.parent; 76 } while (spot != null); 77 78 return l.toArray(new TT_TreeNode[l.size()]); 79 } 80 81 abstract boolean isRoot(); 82 83 public String toString() { 84 return getShortName(); 85 } 86 87 protected TT_BasicNode parent; 88 }