< prev index next >
apps/toys/Hello/src/main/java/hello/dialog/wizard/ImplUtils.java
Print this page
*** 1,7 ****
/*
! * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
--- 1,7 ----
/*
! * Copyright (c) 2014, 2016, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
*** 22,32 ****
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package hello.dialog.wizard;
- import java.lang.reflect.Method;
import java.util.Collections;
import java.util.List;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
--- 22,31 ----
*** 42,57 ****
private ImplUtils() {
// no-op
}
! public static List<Node> getChildren(Node n, boolean useReflection) {
! return n instanceof Parent ? getChildren((Parent)n, useReflection) : Collections.emptyList();
}
@SuppressWarnings("unchecked")
! public static ObservableList<Node> getChildren(Parent p, boolean useReflection) {
ObservableList<Node> children = null;
// previously we used reflection immediately, now we try to avoid reflection
// by checking the type of the Parent. Still not great...
if (p instanceof Pane) {
--- 41,56 ----
private ImplUtils() {
// no-op
}
! public static List<Node> getChildren(Node n) {
! return n instanceof Parent ? getChildren((Parent)n) : Collections.emptyList();
}
@SuppressWarnings("unchecked")
! public static ObservableList<Node> getChildren(Parent p) {
ObservableList<Node> children = null;
// previously we used reflection immediately, now we try to avoid reflection
// by checking the type of the Parent. Still not great...
if (p instanceof Pane) {
*** 62,92 ****
children = ((Group)p).getChildren();
} else if (p instanceof Control) {
Control c = (Control) p;
Skin<?> s = c.getSkin();
children = s instanceof SkinBase ? ((SkinBase<?>)s).getChildren() : null;
- } else if (useReflection) {
- // we really want to avoid using this!!!!
- try {
- Method getChildrenMethod = Parent.class.getDeclaredMethod("getChildren"); //$NON-NLS-1$
-
- if (getChildrenMethod != null) {
- if (! getChildrenMethod.isAccessible()) {
- getChildrenMethod.setAccessible(true);
}
- children = (ObservableList<Node>) getChildrenMethod.invoke(p);
- } else {
- // uh oh, trouble
- }
- } catch (ReflectiveOperationException | IllegalArgumentException e) {
- throw new RuntimeException("Unable to get children for Parent of type " + p.getClass(), e);
- }
- }
-
- if (useReflection && children == null) {
- throw new RuntimeException("Unable to get children for Parent of type " + p.getClass() +
- ". useReflection is set to true");
- }
-
return children == null ? FXCollections.emptyObservableList() : children;
}
}
--- 61,69 ----
< prev index next >