@@ -126,23 +126,33 @@ public IView.Label getInlineActionView() {
126126
127127 @ Override
128128 public void refreshView () {
129- if (this .getParent () != null ) {
130- ((DefaultTreeModel ) this .tree .getModel ()).nodeChanged (this );
129+ synchronized (this .tree ) {
130+ final DefaultTreeModel model = (DefaultTreeModel ) this .tree .getModel ();
131+ if (Objects .nonNull (this .getParent ()) && Objects .nonNull (model )) {
132+ model .nodeChanged (this );
133+ }
134+ }
135+ }
136+
137+ private void refreshChildrenView () {
138+ synchronized (this .tree ) {
139+ final DefaultTreeModel model = (DefaultTreeModel ) this .tree .getModel ();
140+ if (Objects .nonNull (this .getParent ()) && Objects .nonNull (model )) {
141+ model .nodeStructureChanged (this );
142+ }
131143 }
132144 }
133145
134146 @ Override
135147 public synchronized void refreshChildren (boolean ... incremental ) {
136148 if (this .getAllowsChildren () && BooleanUtils .isNotFalse (this .loaded )) {
137149 final DefaultTreeModel model = (DefaultTreeModel ) this .tree .getModel ();
138- if (incremental .length > 0 && incremental [0 ]) {
150+ if (incremental .length > 0 && incremental [0 ] && Objects . nonNull ( model ) ) {
139151 model .insertNodeInto (new LoadingNode (), this , 0 );
140152 } else {
141153 this .removeAllChildren ();
142154 this .add (new LoadingNode ());
143- if (Objects .nonNull (this .getParent ())) {
144- ((DefaultTreeModel ) this .tree .getModel ()).nodeStructureChanged (this );
145- }
155+ this .refreshChildrenView ();
146156 }
147157 this .loaded = null ;
148158 this .loadChildren (incremental );
@@ -169,9 +179,7 @@ private synchronized void setChildren(List<Node<?>> children) {
169179 this .removeAllChildren ();
170180 children .stream ().map (c -> new TreeNode <>(c , this .tree )).forEach (this ::add );
171181 this .loaded = true ;
172- if (Objects .nonNull (this .getParent ())) {
173- ((DefaultTreeModel ) this .tree .getModel ()).nodeStructureChanged (this );
174- }
182+ this .refreshChildrenView ();
175183 }
176184
177185 private synchronized void updateChildren (List <Node <?>> children ) {
@@ -195,22 +203,20 @@ private synchronized void updateChildren(List<Node<?>> children) {
195203 }
196204 }
197205 this .remove (0 );
198- if (Objects .nonNull (this .getParent ())) {
199- ((DefaultTreeModel ) this .tree .getModel ()).nodeStructureChanged (this );
200- }
206+ this .refreshChildrenView ();
201207 Optional .ofNullable (toSelect ).ifPresent (p -> TreeUtil .selectPath (this .tree , p , false ));
202208 this .loaded = true ;
203209 }
204210
205- public synchronized void clearChildren () {
206- this .removeAllChildren ();
207- this . loaded = null ;
208- if ( this .getAllowsChildren ()) {
209- this .add ( new LoadingNode ());
210- this .tree . collapsePath (new TreePath ( this . getPath () ));
211- }
212- if ( Objects . nonNull ( this . getParent ())) {
213- (( DefaultTreeModel ) this .tree . getModel ()). nodeStructureChanged ( this );
211+ public void clearChildren () {
212+ synchronized ( this .tree ) {
213+ this . removeAllChildren () ;
214+ this .loaded = null ;
215+ if ( this .getAllowsChildren ()) {
216+ this .add (new LoadingNode ( ));
217+ this . tree . collapsePath ( new TreePath ( this . getPath ()));
218+ }
219+ this .refreshChildrenView ( );
214220 }
215221 }
216222
0 commit comments