99import com .microsoft .azure .toolkit .ide .common .component .NodeView ;
1010import com .microsoft .azure .toolkit .lib .appservice .AppServiceAppBase ;
1111import com .microsoft .azure .toolkit .lib .appservice .model .AppServiceFile ;
12+ import com .microsoft .azure .toolkit .lib .common .bundle .AzureString ;
1213import com .microsoft .azure .toolkit .lib .common .event .AzureEvent ;
1314import com .microsoft .azure .toolkit .lib .common .event .AzureEventBus ;
15+ import com .microsoft .azure .toolkit .lib .common .messager .AzureMessager ;
1416import com .microsoft .azure .toolkit .lib .common .task .AzureTaskManager ;
1517import lombok .Getter ;
1618import lombok .Setter ;
@@ -68,26 +70,31 @@ public AppServiceFileNode(@Nonnull AppServiceFile data) {
6870
6971 @ Override
7072 public boolean hasChildren () {
71- return file .getType () == AppServiceFile .Type .DIRECTORY && appService . getFormalStatus (). isRunning () ;
73+ return file .getType () == AppServiceFile .Type .DIRECTORY ;
7274 }
7375
7476 @ Override
7577 public List <Node <?>> getChildren () {
76- return file .getType () != AppServiceFile .Type .DIRECTORY ? Collections .emptyList () :
77- appService .getFilesInDirectory (file .getPath ()).stream ()
78- .sorted ((first , second ) -> first .getType () == second .getType () ?
79- StringUtils .compare (first .getName (), second .getName ()) :
80- first .getType () == AppServiceFile .Type .DIRECTORY ? -1 : 1 )
81- .map (AppServiceFileNode ::new )
82- .collect (Collectors .toList ());
78+ if (file .getType () != AppServiceFile .Type .DIRECTORY ) {
79+ return Collections .emptyList ();
80+ }
81+ if (!appService .getFormalStatus ().isRunning ()) {
82+ AzureMessager .getMessager ().warning (AzureString .format ("Can not list files for app service with status %s" , appService .getStatus ()));
83+ return Collections .emptyList ();
84+ }
85+ return appService .getFilesInDirectory (file .getPath ()).stream ()
86+ .sorted ((first , second ) -> first .getType () == second .getType () ?
87+ StringUtils .compare (first .getName (), second .getName ()) :
88+ first .getType () == AppServiceFile .Type .DIRECTORY ? -1 : 1 )
89+ .map (AppServiceFileNode ::new )
90+ .collect (Collectors .toList ());
8391 }
8492
8593 static class AppServiceFileLabelView implements NodeView {
8694 @ Nonnull
8795 @ Getter
8896 private final AppServiceFile file ;
8997 private final AzureEventBus .EventListener listener ;
90- private final AzureEventBus .EventListener appStatusListener ;
9198
9299 @ Nullable
93100 @ Setter
@@ -97,19 +104,10 @@ static class AppServiceFileLabelView implements NodeView {
97104 public AppServiceFileLabelView (@ Nonnull AppServiceFile file ) {
98105 this .file = file ;
99106 this .listener = new AzureEventBus .EventListener (this ::onEvent );
100- this .appStatusListener = new AzureEventBus .EventListener (this ::onAppStatusChanged );
101107 AzureEventBus .on ("resource.refreshed.resource" , listener );
102- AzureEventBus .on ("resource.status_changed.resource" , appStatusListener );
103108 this .refreshView ();
104109 }
105110
106- private void onAppStatusChanged (AzureEvent event ) {
107- final Object source = event .getSource ();
108- if ((source instanceof AppServiceAppBase && StringUtils .equalsIgnoreCase (((AppServiceAppBase <?, ?, ?>) source ).getId (), this .file .getApp ().getId ()))) {
109- AzureTaskManager .getInstance ().runLater (this ::refreshChildren );
110- }
111- }
112-
113111 private void onEvent (AzureEvent event ) {
114112 final String type = event .getType ();
115113 final Object source = event .getSource ();
@@ -150,7 +148,6 @@ private static String formatDateTime(@Nullable final String dateTime) {
150148 @ Override
151149 public void dispose () {
152150 AzureEventBus .off ("resource.refreshed.resource" , listener );
153- AzureEventBus .off ("resource.status_changed.resource" , appStatusListener );
154151 this .refresher = null ;
155152 }
156153 }
0 commit comments