From 099453e08ec1e2aff1ab8a665de7989801e90d44 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Fournier?= Date: Sun, 13 Jan 2019 20:49:10 +0100 Subject: [PATCH 1/2] Fix XPath expression not persisted --- .../fxdesigner/MainDesignerController.java | 12 ++++---- .../util/fxdesigner/XPathPanelController.java | 30 ++++++++++--------- .../model/ObservableXPathRuleBuilder.java | 2 +- .../fxdesigner/util/AbstractController.java | 20 ++++++++++--- 4 files changed, 40 insertions(+), 24 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 b842c9b421..9cfe0d0789 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 @@ -134,14 +134,16 @@ public class MainDesignerController extends AbstractController { fileMenu.setOnShowing(e -> onFileMenuShowing()); setupAuxclasspathMenuItem.setOnAction(e -> sourceEditorController.showAuxclasspathSetupPopup(designerRoot)); - - Platform.runLater(this::updateRecentFilesMenu); - Platform.runLater(this::refreshAST); // initial refreshing - - Platform.runLater(() -> sourceEditorController.moveCaret(0, 0)); } + @Override + protected void afterChildrenInit() { + updateRecentFilesMenu(); + refreshAST(); // initial refreshing + sourceEditorController.moveCaret(0, 0); + } + private void initializeViewAnimation() { 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 ca85c51388..ed8df4804d 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 @@ -137,9 +137,6 @@ public class XPathPanelController extends AbstractController { .or(xpathVersionProperty().changes()) .subscribe(tick -> parent.refreshXPathResults()); - // init autocompletion - Supplier suggestionMaker = () -> XPathCompletionSource.forLanguage(parent.getLanguageVersion().getLanguage()); - new XPathAutocompleteProvider(xpathExpressionArea, suggestionMaker).initialiseAutoCompletion(); } @@ -147,9 +144,25 @@ public class XPathPanelController extends AbstractController { @Override protected void afterParentInit() { bindToParent(); + + // init autocompletion only after binding to parent and settings restore + // otherwise the popup shows + Supplier suggestionMaker = () -> XPathCompletionSource.forLanguage(parent.getLanguageVersion().getLanguage()); + new XPathAutocompleteProvider(xpathExpressionArea, suggestionMaker).initialiseAutoCompletion(); } + // Binds the underlying rule parameters to the parent UI, disconnecting it from the wizard if need be + private void bindToParent() { + DesignerUtil.rewire(getRuleBuilder().languageProperty(), Val.map(parent.languageVersionProperty(), LanguageVersion::getLanguage)); + + DesignerUtil.rewireInit(getRuleBuilder().xpathVersionProperty(), xpathVersionProperty()); + DesignerUtil.rewireInit(getRuleBuilder().xpathExpressionProperty(), xpathExpressionProperty()); + + DesignerUtil.rewireInit(getRuleBuilder().rulePropertiesProperty(), + propertyTableView.rulePropertiesProperty(), propertyTableView::setRuleProperties); + } + private void initialiseVersionSelection() { ToggleGroup xpathVersionToggleGroup = new ToggleGroup(); @@ -214,17 +227,6 @@ public class XPathPanelController extends AbstractController { } - // Binds the underlying rule parameters to the parent UI, disconnecting it from the wizard if need be - private void bindToParent() { - DesignerUtil.rewire(getRuleBuilder().languageProperty(), - Val.map(parent.languageVersionProperty(), LanguageVersion::getLanguage)); - - DesignerUtil.rewire(getRuleBuilder().xpathVersionProperty(), xpathVersionProperty()); - DesignerUtil.rewire(getRuleBuilder().xpathExpressionProperty(), xpathExpressionProperty()); - - DesignerUtil.rewireInit(getRuleBuilder().rulePropertiesProperty(), - propertyTableView.rulePropertiesProperty(), propertyTableView::setRuleProperties); - } /** diff --git a/pmd-ui/src/main/java/net/sourceforge/pmd/util/fxdesigner/model/ObservableXPathRuleBuilder.java b/pmd-ui/src/main/java/net/sourceforge/pmd/util/fxdesigner/model/ObservableXPathRuleBuilder.java index dc6543c603..d3c67424c7 100644 --- a/pmd-ui/src/main/java/net/sourceforge/pmd/util/fxdesigner/model/ObservableXPathRuleBuilder.java +++ b/pmd-ui/src/main/java/net/sourceforge/pmd/util/fxdesigner/model/ObservableXPathRuleBuilder.java @@ -34,12 +34,12 @@ public class ObservableXPathRuleBuilder extends ObservableRuleBuilder { } - @PersistentProperty public Var xpathVersionProperty() { return xpathVersion; } + @PersistentProperty public String getXpathExpression() { return xpathExpression.getValue(); } diff --git a/pmd-ui/src/main/java/net/sourceforge/pmd/util/fxdesigner/util/AbstractController.java b/pmd-ui/src/main/java/net/sourceforge/pmd/util/fxdesigner/util/AbstractController.java index a7bdf92336..8ca7882542 100644 --- a/pmd-ui/src/main/java/net/sourceforge/pmd/util/fxdesigner/util/AbstractController.java +++ b/pmd-ui/src/main/java/net/sourceforge/pmd/util/fxdesigner/util/AbstractController.java @@ -34,14 +34,16 @@ public class AbstractController implements Initializable, SettingsOwner { public final void initialize(URL url, ResourceBundle resourceBundle) { beforeParentInit(); for (AbstractController child : getChildren()) { - Platform.runLater(child::afterParentInit); + child.afterParentInit(); } + afterChildrenInit(); } /** * Executed before the parent's initialization. - * Always executed once. + * Always executed once at the start of the initialization + * of this controller. */ protected void beforeParentInit() { // by default do nothing @@ -49,8 +51,8 @@ public class AbstractController implements Initializable, SettingsOwner { /** - * Executed after the parent's initialization. This also means, - * after persistent settings restoration. If this node has no + * Executed after the parent's initialization (so after {@link #afterChildrenInit()}). + * This also means, after persistent settings restoration. If this node has no * parent, then this is never executed. */ protected void afterParentInit() { @@ -58,6 +60,16 @@ public class AbstractController implements Initializable, SettingsOwner { } + /** + * Runs once after every child has finished their initialization. + * This will be run in all cases. It's only useful if the children + * do something useful in their {@link #afterParentInit()}. + */ + protected void afterChildrenInit() { + // by default do nothing + } + + @Override public List getChildrenSettingsNodes() { return getChildren(); From 72b0cb1450bd254b84b7d1155760d7d6b3e0f11a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Fournier?= Date: Sun, 13 Jan 2019 21:45:07 +0100 Subject: [PATCH 2/2] Comment --- .../sourceforge/pmd/util/fxdesigner/XPathPanelController.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 ed8df4804d..f719df56af 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 @@ -146,7 +146,7 @@ public class XPathPanelController extends AbstractController { bindToParent(); // init autocompletion only after binding to parent and settings restore - // otherwise the popup shows + // otherwise the popup is shown on startup Supplier suggestionMaker = () -> XPathCompletionSource.forLanguage(parent.getLanguageVersion().getLanguage()); new XPathAutocompleteProvider(xpathExpressionArea, suggestionMaker).initialiseAutoCompletion(); }