Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
ExplorerTreeNode |
|
| 2.375;2.375 |
1 | /* $Id: ExplorerTreeNode.java 17843 2010-01-12 19:23:29Z linus $ | |
2 | ***************************************************************************** | |
3 | * Copyright (c) 2009 Contributors - see below | |
4 | * All rights reserved. This program and the accompanying materials | |
5 | * are made available under the terms of the Eclipse Public License v1.0 | |
6 | * which accompanies this distribution, and is available at | |
7 | * http://www.eclipse.org/legal/epl-v10.html | |
8 | * | |
9 | * Contributors: | |
10 | * mvw | |
11 | ***************************************************************************** | |
12 | * | |
13 | * Some portions of this file was previously release using the BSD License: | |
14 | */ | |
15 | ||
16 | // Copyright (c) 1996-2007 The Regents of the University of California. All | |
17 | // Rights Reserved. Permission to use, copy, modify, and distribute this | |
18 | // software and its documentation without fee, and without a written | |
19 | // agreement is hereby granted, provided that the above copyright notice | |
20 | // and this paragraph appear in all copies. This software program and | |
21 | // documentation are copyrighted by The Regents of the University of | |
22 | // California. The software program and documentation are supplied "AS | |
23 | // IS", without any accompanying services from The Regents. The Regents | |
24 | // does not warrant that the operation of the program will be | |
25 | // uninterrupted or error-free. The end-user understands that the program | |
26 | // was developed for research purposes and is advised not to rely | |
27 | // exclusively on the program for any reason. IN NO EVENT SHALL THE | |
28 | // UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, | |
29 | // SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS, | |
30 | // ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF | |
31 | // THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF | |
32 | // SUCH DAMAGE. THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY | |
33 | // WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF | |
34 | // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE | |
35 | // PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY OF | |
36 | // CALIFORNIA HAS NO OBLIGATIONS TO PROVIDE MAINTENANCE, SUPPORT, | |
37 | // UPDATES, ENHANCEMENTS, OR MODIFICATIONS. | |
38 | ||
39 | package org.argouml.ui.explorer; | |
40 | ||
41 | import java.beans.PropertyChangeEvent; | |
42 | import java.beans.PropertyChangeListener; | |
43 | import java.util.Collections; | |
44 | import java.util.Iterator; | |
45 | import java.util.Set; | |
46 | ||
47 | import javax.swing.tree.DefaultMutableTreeNode; | |
48 | import javax.swing.tree.TreePath; | |
49 | ||
50 | import org.tigris.gef.base.Diagram; | |
51 | ||
52 | /** | |
53 | * TreeNode implementation for Explorer. Ensures that explorer tree nodes have a | |
54 | * default ordering. | |
55 | * | |
56 | * @author alexb | |
57 | * @since 0.15.2, Created on 27 September 2003, 17:40 | |
58 | */ | |
59 | public class ExplorerTreeNode extends DefaultMutableTreeNode implements | |
60 | PropertyChangeListener { | |
61 | ||
62 | private static final long serialVersionUID = -6766504350537675845L; | |
63 | private ExplorerTreeModel model; | |
64 | private boolean expanded; | |
65 | private boolean pending; | |
66 | 35410 | private Set modifySet = Collections.EMPTY_SET; |
67 | ||
68 | /** | |
69 | * Creates a new instance of ExplorerTreeNode. | |
70 | * | |
71 | * @param userObj the object in the tree | |
72 | * @param m the tree model | |
73 | */ | |
74 | public ExplorerTreeNode(Object userObj, ExplorerTreeModel m) { | |
75 | 35410 | super(userObj); |
76 | 35410 | this.model = m; |
77 | 35410 | if (userObj instanceof Diagram) |
78 | 7562 | ((Diagram) userObj).addPropertyChangeListener(this); |
79 | 35410 | } |
80 | ||
81 | /* | |
82 | * @see javax.swing.tree.TreeNode#isLeaf() | |
83 | */ | |
84 | @Override | |
85 | public boolean isLeaf() { | |
86 | 52762 | if (!expanded) { |
87 | 27638 | model.updateChildren(new TreePath(model.getPathToRoot(this))); |
88 | 27638 | expanded = true; |
89 | } | |
90 | 52762 | return super.isLeaf(); |
91 | } | |
92 | ||
93 | boolean getPending() { | |
94 | 814 | return pending; |
95 | } | |
96 | ||
97 | void setPending(boolean value) { | |
98 | 850 | pending = value; |
99 | 850 | } |
100 | ||
101 | /** | |
102 | * @param set the given set | |
103 | */ | |
104 | public void setModifySet(Set set) { | |
105 | 15633 | if (set == null || set.size() == 0) |
106 | 3656 | modifySet = Collections.EMPTY_SET; |
107 | else | |
108 | 11977 | modifySet = set; |
109 | 15633 | } |
110 | ||
111 | /** | |
112 | * @param node the modified node in the tree | |
113 | */ | |
114 | public void nodeModified(Object node) { | |
115 | 13372 | if (modifySet.contains(node)) { |
116 | 814 | model.getNodeUpdater().schedule(this); |
117 | } | |
118 | 13372 | if (node == getUserObject()) { |
119 | 388 | model.nodeChanged(this); |
120 | } | |
121 | 13372 | } |
122 | ||
123 | /** | |
124 | * cleans up for gc. | |
125 | */ | |
126 | public void remove() { | |
127 | 28096 | this.userObject = null; |
128 | ||
129 | 28096 | if (children != null) { |
130 | 8854 | Iterator childrenIt = children.iterator(); |
131 | 29396 | while (childrenIt.hasNext()) { |
132 | 20542 | ((ExplorerTreeNode) childrenIt.next()).remove(); |
133 | } | |
134 | ||
135 | 8854 | children.clear(); |
136 | 8854 | children = null; |
137 | } | |
138 | 28096 | } |
139 | ||
140 | /* | |
141 | * @see java.beans.PropertyChangeListener#propertyChange(java.beans.PropertyChangeEvent) | |
142 | */ | |
143 | public void propertyChange(PropertyChangeEvent evt) { | |
144 | 686 | if (evt.getSource() instanceof Diagram) { |
145 | 686 | if ("name".equals(evt.getPropertyName())) { |
146 | /* The name of the UMLDiagram | |
147 | * represented by this node has changed. */ | |
148 | 0 | model.nodeChanged(this); |
149 | } | |
150 | 686 | if ( "namespace".equals(evt.getPropertyName())) { |
151 | /* TODO: Update the old and new node above this! | |
152 | * This is issue 5079. | |
153 | * The old and new UML namespaces are in the event, but | |
154 | * how do we know which nodes to refresh? | |
155 | * And how to refresh? | |
156 | * Not necessarily the namespaces, | |
157 | * depending on the perspective. */ | |
158 | } | |
159 | } | |
160 | 686 | } |
161 | } |