Refresh XPath results on changes to properties

This commit is contained in:
Clément Fournier
2019-02-23 12:03:44 +01:00
parent 6616927445
commit 44573f225a
3 changed files with 28 additions and 7 deletions

View File

@ -71,7 +71,6 @@ import javafx.scene.control.ToggleGroup;
import javafx.scene.input.MouseButton;
import javafx.scene.input.MouseEvent;
import javafx.scene.layout.HBox;
import javafx.scene.layout.Priority;
import javafx.scene.layout.VBox;
import javafx.scene.text.Text;
import javafx.stage.Modality;
@ -136,12 +135,9 @@ public class XPathPanelController extends AbstractController<MainDesignerControl
exportXpathToRuleButton.setOnAction(e -> showExportXPathToRuleWizard());
xpathExpressionArea.richChanges()
.filter(t -> !t.isIdentity())
.successionEnds(XPATH_REFRESH_DELAY)
// Reevaluate XPath anytime the expression or the XPath version changes
.or(xpathVersionProperty().changes())
.subscribe(tick -> parent.refreshXPathResults());
getRuleBuilder().modificationsTicks()
.successionEnds(XPATH_REFRESH_DELAY)
.subscribe(tick -> parent.refreshXPathResults());
selectionEvents = EventStreams.valuesOf(xpathResultListView.getSelectionModel().selectedItemProperty()).suppressible();

View File

@ -4,6 +4,8 @@
package net.sourceforge.pmd.util.fxdesigner.model;
import org.reactfx.EventStream;
import org.reactfx.collection.LiveList;
import org.reactfx.value.Var;
import net.sourceforge.pmd.util.fxdesigner.util.DesignerUtil;
@ -54,6 +56,17 @@ public class ObservableXPathRuleBuilder extends ObservableRuleBuilder {
return xpathExpression;
}
/**
* Pushes an event every time the rule needs to be re-evaluated.
*/
public EventStream<?> modificationsTicks() {
return nameProperty().values()
.or(xpathVersion.values())
.or(xpathExpression.values())
.or(LiveList.changesOf(rulePropertiesProperty()));
}
// TODO: Once the xpath expression changes, we'll need to rebuild the rule
// @Override
// public Optional<Rule> build() throws IllegalArgumentException {

View File

@ -8,6 +8,7 @@ package net.sourceforge.pmd.util.fxdesigner.model;
import java.util.HashMap;
import java.util.Map;
import org.reactfx.EventStream;
import org.reactfx.value.Val;
import org.reactfx.value.Var;
@ -200,4 +201,15 @@ public class PropertyDescriptorSpec implements SettingsOwner {
public static ObservableList<PropertyDescriptorSpec> observableList() {
return FXCollections.observableArrayList(extractor());
}
/**
* Pushes an event every time the rule owning this property needs to be re-evaluated.
*/
public EventStream<?> modificationTicks() {
return nameProperty().values()
.or(valueProperty().values())
.or(typeIdProperty().values());
}
}