From 95ac9691d372b24bbc4ddbf3bb169bc2486137fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Fournier?= Date: Wed, 30 May 2018 18:29:48 +0200 Subject: [PATCH] Fix NPE, controller not found --- .../fxdesigner/MainDesignerController.java | 5 +++-- .../util/fxdesigner/XPathPanelController.java | 1 - .../util/AuxClassPathController.java | 19 +++++++++++-------- 3 files changed, 14 insertions(+), 11 deletions(-) diff --git a/pmd-ui/src/main/java/net/sourceforge/pmd/util/fxdesigner/MainDesignerController.java b/pmd-ui/src/main/java/net/sourceforge/pmd/util/fxdesigner/MainDesignerController.java index 02dcc65964..f1900ca2a4 100644 --- a/pmd-ui/src/main/java/net/sourceforge/pmd/util/fxdesigner/MainDesignerController.java +++ b/pmd-ui/src/main/java/net/sourceforge/pmd/util/fxdesigner/MainDesignerController.java @@ -115,8 +115,8 @@ public class MainDesignerController implements Initializable, SettingsOwner { private SourceEditorController sourceEditorController; @FXML private EventLogController eventLogPanelController; - @FXML - private AuxClassPathController auxClassPathController; + + private final AuxClassPathController auxClassPathController; // Other fields private Stack recentFiles = new LimitedSizeStack<>(5); @@ -127,6 +127,7 @@ public class MainDesignerController implements Initializable, SettingsOwner { public MainDesignerController(DesignerRoot owner) { this.designerRoot = owner; + this.auxClassPathController = new AuxClassPathController(designerRoot, this); } diff --git a/pmd-ui/src/main/java/net/sourceforge/pmd/util/fxdesigner/XPathPanelController.java b/pmd-ui/src/main/java/net/sourceforge/pmd/util/fxdesigner/XPathPanelController.java index ebbca055ea..ae9a85a18c 100644 --- a/pmd-ui/src/main/java/net/sourceforge/pmd/util/fxdesigner/XPathPanelController.java +++ b/pmd-ui/src/main/java/net/sourceforge/pmd/util/fxdesigner/XPathPanelController.java @@ -226,7 +226,6 @@ public class XPathPanelController implements Initializable, SettingsOwner { public void showExportXPathToRuleWizard() throws IOException { - // doesn't work for some reason ExportXPathWizardController wizard = new ExportXPathWizardController(xpathExpressionProperty()); diff --git a/pmd-ui/src/main/java/net/sourceforge/pmd/util/fxdesigner/util/AuxClassPathController.java b/pmd-ui/src/main/java/net/sourceforge/pmd/util/fxdesigner/util/AuxClassPathController.java index 79dd157ac5..0a83366557 100644 --- a/pmd-ui/src/main/java/net/sourceforge/pmd/util/fxdesigner/util/AuxClassPathController.java +++ b/pmd-ui/src/main/java/net/sourceforge/pmd/util/fxdesigner/util/AuxClassPathController.java @@ -30,19 +30,14 @@ public class AuxClassPathController implements Initializable, SettingsOwner { @FXML private Button removeFiles; - @FXML private TableView fileTable; - @FXML private Button selectFile; - @FXML private TableColumn fileList; - @FXML private TableColumn fileAdd; - @FXML private final MainDesignerController parent; @@ -71,12 +66,20 @@ public class AuxClassPathController implements Initializable, SettingsOwner { public void showAuxPathWizard() throws Exception { - FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("fxml/aux-controller.fxml")); - Parent root1 = (Parent) fxmlLoader.load(); + FXMLLoader fxmlLoader = new FXMLLoader(DesignerUtil.getFxml("aux-controller.fxml")); + + fxmlLoader.setControllerFactory(type -> { + if (type == AuxClassPathController.class) { + return this; + } else { + throw new IllegalStateException("Wrong controller!"); + } + }); + + Parent root1 = fxmlLoader.load(); Stage stage = new Stage(); stage.setScene(new Scene(root1)); stage.show(); - }