001: /*
002: * The contents of this file are subject to the terms of the Common Development
003: * and Distribution License (the License). You may not use this file except in
004: * compliance with the License.
005: *
006: * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
007: * or http://www.netbeans.org/cddl.txt.
008: *
009: * When distributing Covered Code, include this CDDL Header Notice in each file
010: * and include the License file at http://www.netbeans.org/cddl.txt.
011: * If applicable, add the following below the CDDL Header, with the fields
012: * enclosed by brackets [] replaced by your own identifying information:
013: * "Portions Copyrighted [year] [name of copyright owner]"
014: *
015: * The Original Software is NetBeans. The Initial Developer of the Original
016: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
017: * Microsystems, Inc. All Rights Reserved.
018: */
019:
020: package org.netbeans.modules.bpel.mapper.tree;
021:
022: import java.util.LinkedList;
023: import java.util.List;
024: import javax.swing.Icon;
025: import javax.swing.tree.TreePath;
026:
027: /**
028: * The unified tree node for the MapperSwingTreeModel. This node
029: * is used for any kind of tree item. It uses caching of a data object,
030: * icon and display name.
031: *
032: * @author nk160297
033: */
034: public final class MapperTreeNode<DataObject> {
035:
036: private DataObject mDataObject;
037: private String mDisplayName;
038: private Icon mIcon;
039: private MapperTreeNode mParent;
040: private List<MapperTreeNode> mChildren;
041: private Boolean mIsLeaf;
042:
043: public MapperTreeNode(MapperTreeNode parent, DataObject dataObject) {
044: assert dataObject != null;
045: mParent = parent;
046: mDataObject = dataObject;
047: }
048:
049: public DataObject getDataObject() {
050: return mDataObject;
051: }
052:
053: /**
054: * Force the node to reload
055: */
056: public void discardCachedData() {
057: mDisplayName = null;
058: mIcon = null;
059: // mChildren = null;
060: mIsLeaf = null;
061: }
062:
063: public MapperTreeNode getParent() {
064: return mParent;
065: }
066:
067: /**
068: * This method is intended to be used only by the tree model.
069: * Use the method treeModel.getDisplayName(node) instead.
070: * @return
071: */
072: public String getDisplayName() {
073: return mDisplayName;
074: }
075:
076: public void setDisplayName(String newName) {
077: mDisplayName = newName;
078: }
079:
080: /**
081: * This method is intended to be used only by the tree model.
082: * Use the method treeModel.getChildren(node) instead.
083: * @return
084: */
085: public List<MapperTreeNode> getChildren() {
086: return mChildren;
087: }
088:
089: public boolean removeChild(Object child) {
090: if (mChildren != null) {
091: return mChildren.remove(child);
092: }
093: return false;
094: }
095:
096: public void setChildren(List<MapperTreeNode> newChildren) {
097: mChildren = newChildren;
098: }
099:
100: /**
101: * This method is intended to be used only by the tree model.
102: * Use the method treeModel.getIcon(node) instead.
103: * @return
104: */
105: public Icon getIcon() {
106: return mIcon;
107: }
108:
109: public void setIcon(Icon newIcon) {
110: mIcon = newIcon;
111: }
112:
113: /**
114: * This method is intended to be used only by the tree model.
115: * Use the method treeModel.getIcon(node) instead.
116: * @return
117: */
118: public Boolean isLeaf() {
119: return mIsLeaf;
120: }
121:
122: public void setIsLeaf(Boolean newIsLeaf) {
123: mIsLeaf = newIsLeaf;
124: }
125:
126: @Override
127: public String toString() {
128: Object dataObject = getDataObject();
129: if (dataObject != null) {
130: return "TreeNode[" + dataObject.toString() + "]";
131: } else {
132: return super .toString();
133: }
134: }
135:
136: public TreePath getTreePath() {
137: TreePath result = null;
138: MapperTreeNode parentNode = getParent();
139: if (parentNode == null) {
140: result = new TreePath(this );
141: } else {
142: TreePath parentPath = parentNode.getTreePath();
143: assert parentPath != null;
144: result = parentPath.pathByAddingChild(this);
145: }
146: return result;
147: }
148: }
|