Focus from violation results to ast -> inefficient for large files

This commit is contained in:
Clément Fournier
2017-09-24 17:42:54 +02:00
parent 27addb5014
commit 8a05e36196
3 changed files with 33 additions and 16 deletions

View File

@@ -6,6 +6,7 @@ package net.sourceforge.pmd.util.fxdesigner;
import net.sourceforge.pmd.lang.ast.Node;
import javafx.collections.ObservableList;
import javafx.scene.control.TreeItem;
/**
@@ -19,12 +20,25 @@ public class ASTTreeItem extends TreeItem<Node> {
private ASTTreeItem(Node n) {
super(n);
setExpanded(true);
}
/** Sets this item and all its children to the expanded state. */
void expandAll() {
expandAllHelper(this);
public ASTTreeItem findItem(Node node) {
if (this.getValue().equals(node)) {
return this;
}
ObservableList<TreeItem<Node>> children = this.getChildren();
ASTTreeItem found;
for (TreeItem<Node> child : children) {
found = ((ASTTreeItem) child).findItem(node);
if (found != null) {
return found;
}
}
return null;
}
@@ -40,12 +54,4 @@ public class ASTTreeItem extends TreeItem<Node> {
}
private static void expandAllHelper(TreeItem<Node> item) {
item.setExpanded(true);
if (item.getChildren().size() > 0) {
for (TreeItem<Node> child : item.getChildren()) {
expandAllHelper(child);
}
}
}
}

View File

@@ -49,6 +49,7 @@ import javafx.scene.control.Label;
import javafx.scene.control.ListView;
import javafx.scene.control.MenuItem;
import javafx.scene.control.ScrollPane;
import javafx.scene.control.SelectionModel;
import javafx.scene.control.SeparatorMenuItem;
import javafx.scene.control.TextArea;
import javafx.scene.control.Tooltip;
@@ -169,6 +170,7 @@ public class DesignerWindowPresenter {
.addListener((observable, oldValue, newValue) -> {
if (newValue != null) {
onNodeItemSelected(newValue);
focusNodeInASTTreeView(newValue);
}
});
}
@@ -224,6 +226,18 @@ public class DesignerWindowPresenter {
}
private void focusNodeInASTTreeView(Node node) {
TreeView<Node> astTreeView = view.getAstTreeView();
ASTTreeItem found = ((ASTTreeItem) astTreeView.getRoot()).findItem(node);
if (found != null) {
SelectionModel<TreeItem<Node>> selectionModel = astTreeView.getSelectionModel();
selectionModel.select(found);
astTreeView.getFocusModel().focus(selectionModel.getSelectedIndex());
// astTreeView.scrollTo(selectionModel.getSelectedIndex());
}
}
private void initializeLanguageVersionMenu() {
LanguageVersion[] supported = DesignerUtil.getSupportedLanguageVersions();
ObservableList<LanguageVersion> items = view.getLanguageChoiceBox().getItems();
@@ -295,7 +309,6 @@ public class DesignerWindowPresenter {
if (n != null) {
view.acknowledgeUpdatedAST();
ASTTreeItem root = ASTTreeItem.getRoot(n);
root.expandAll();
view.getAstTreeView().setRoot(root);
}
}
@@ -532,9 +545,7 @@ public class DesignerWindowPresenter {
Collections.reverse(fileNames);
for (String fileName : fileNames) {
File f = new File(fileName);
if (f.exists()) {
recentFiles.push(f);
}
recentFiles.push(f);
}
}

View File

@@ -154,7 +154,7 @@ public class DesignerWindow implements Initializable {
}
if (keyValue != null) {
Timeline timeline = new Timeline(new KeyFrame(Duration.millis(350), keyValue));
Timeline timeline = new Timeline(new KeyFrame(Duration.millis(200), keyValue));
timeline.setOnFinished(e -> {
if (isNowExpanded) {
if (Designer.getMainStage().isMaximized()) {