package org.fxmisc.cssfx.impl;

/*
 * #%L
 * CSSFX
 * %%
 * Copyright (C) 2014 CSSFX by Matthieu Brouillard
 * %%
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * #L%
 */


import static org.fxmisc.cssfx.impl.log.CSSFXLogger.logger;

import java.lang.reflect.Method;

import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.stage.Stage;

public class ApplicationStages {
    public static ObservableList<Stage> monitoredStages(Stage ...restrictedTo) {
        try {
            Class<?> sh = Class.forName("com.sun.javafx.stage.StageHelper");
            Method m = sh.getMethod("getStages");
            ObservableList<Stage> stages = (ObservableList<Stage>) m.invoke(null, new Object[0]);
            logger(ApplicationStages.class).debug("successfully retrieved JavaFX stages from com.sun.javafx.stage.StageHelper");
            return stages;
        } catch (Exception e) {
            logger(ApplicationStages.class).error("cannot observe stages changes by calling com.sun.javafx.stage.StageHelper.getStages()", e);
        }
        return FXCollections.emptyObservableList();
    }
}

@@ -678,16 +678,66 @@
 %25%0A */%0A%0A%0A
+import static java.util.stream.Collectors.toList;%0A
 import s
@@ -805,29 +805,31 @@
 ava.
-lang.reflect.Method;%0A
+util.stream.Collectors;
 %0Aimp
@@ -934,16 +934,44 @@
 e.Stage;
+%0Aimport javafx.stage.Window;
 %0A%0Apublic
@@ -1108,218 +1108,245 @@
     
-Class%3C?%3E sh = Class.forName(%22com.sun.javafx.stage.StageHelper%22);%0A            Method m = sh.getMethod(%22getStages%22);%0A            ObservableList%3CStage%3E stages = (ObservableList%3CStage%3E) m.invoke(null, new Object%5B0%5D
+ObservableList%3CStage%3E stages = Window.getWindows().stream()%0A                .map(Stage.class::cast)%0A                .collect(%0A                    Collectors.collectingAndThen(toList(), FXCollections::observableArrayList)%0A                
 );%0A 
@@ -1436,45 +1436,51 @@
 ges 
-from com.sun.javafx.stage.StageHelper
+by calling javafx.stage.Window.getWindows()
 %22);%0A
@@ -1634,16 +1634,8 @@
 ing 
-com.sun.
 java
@@ -1647,28 +1647,24 @@
 age.
-StageHelper.getStage
+Window.getWindow
 s()%22

Replace call to com.sun.javafx.stage.StageHelper.getStages() (non-existent in Java 9) with call to Window.getWindows()