Data flow is working properly thanks to @oowekyala for helping me out.
UI is upgraded to make sure buttons are active only when needed (will make a small addition to moveitem up and moveitem down button as discussed) About the ClassLoader I am a bit confused about how to use `ClasspathClassLoader` I think will be able to merge it today before evening IST.
This commit is contained in:
@ -6,35 +6,28 @@
|
||||
package net.sourceforge.pmd.util.fxdesigner;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
import java.util.List;
|
||||
import java.util.ResourceBundle;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import org.controlsfx.validation.ValidationSupport;
|
||||
import org.reactfx.value.Var;
|
||||
|
||||
import net.sourceforge.pmd.PMDConfiguration;
|
||||
import net.sourceforge.pmd.util.ClasspathClassLoader;
|
||||
import net.sourceforge.pmd.util.fxdesigner.util.DesignerUtil;
|
||||
import net.sourceforge.pmd.util.fxdesigner.util.beans.SettingsOwner;
|
||||
|
||||
import javafx.collections.ObservableList;
|
||||
import javafx.collections.FXCollections;
|
||||
import javafx.fxml.FXML;
|
||||
import javafx.fxml.FXMLLoader;
|
||||
import javafx.fxml.Initializable;
|
||||
import javafx.scene.Parent;
|
||||
import javafx.scene.Scene;
|
||||
import javafx.scene.control.Button;
|
||||
import javafx.scene.control.ListView;
|
||||
import javafx.stage.FileChooser;
|
||||
import javafx.stage.Modality;
|
||||
import javafx.stage.Stage;
|
||||
|
||||
public class AuxClassPathController implements Initializable, SettingsOwner {
|
||||
|
||||
private final DesignerRoot designerRoot;
|
||||
private ClassLoader classLoader = getClass().getClassLoader();
|
||||
private ValidationSupport validationSupport = new ValidationSupport();
|
||||
|
||||
private final Var<Runnable> onCancel = Var.newSimpleVar(() -> {});
|
||||
private final Var<Consumer<List<File>>> onApply = Var.newSimpleVar(l -> {});
|
||||
|
||||
|
||||
@FXML
|
||||
@ -53,38 +46,27 @@ public class AuxClassPathController implements Initializable, SettingsOwner {
|
||||
private Button cancelButton;
|
||||
|
||||
|
||||
public AuxClassPathController(ObservableList<File> auxClassPathFiles, DesignerRoot designerRoot) {
|
||||
public AuxClassPathController(DesignerRoot designerRoot) {
|
||||
this.designerRoot = designerRoot;
|
||||
|
||||
if (auxClassPathFiles != null) {
|
||||
fileListView.setItems(auxClassPathFiles);
|
||||
}
|
||||
|
||||
try {
|
||||
showAuxPathWizard();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initialize(URL location, ResourceBundle resources) {
|
||||
|
||||
|
||||
removeFileButton.disableProperty().bind(fileListView.getSelectionModel().selectedItemProperty().isNull());
|
||||
moveItemUpButton.disableProperty().bind(fileListView.getSelectionModel().selectedItemProperty().isNull());
|
||||
moveItemDownButton.disableProperty().bind(fileListView.getSelectionModel().selectedItemProperty().isNull());
|
||||
setClassPathButton.disableProperty().bind(fileListView.getSelectionModel().selectedItemProperty().isNull());
|
||||
|
||||
|
||||
selectFilesButton.setOnAction(e -> onSelectFileClicked());
|
||||
removeFileButton.setOnAction(e -> onRemoveFileClicked());
|
||||
setClassPathButton.setOnAction(e -> {
|
||||
try {
|
||||
setClassPath(classPathGenerator());
|
||||
} catch (IOException e1) {
|
||||
e1.printStackTrace();
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
setClassPathButton.setOnAction(e -> onApply.ifPresent(f -> f.accept(fileListView.getItems())));
|
||||
moveItemUpButton.setOnAction(e -> moveUp());
|
||||
moveItemDownButton.setOnAction(e -> moveDown());
|
||||
cancelButton.setOnAction(e -> closePopup());
|
||||
cancelButton.setOnAction(e -> onCancel.ifPresent(Runnable::run));
|
||||
|
||||
}
|
||||
|
||||
|
||||
@ -108,6 +90,21 @@ public class AuxClassPathController implements Initializable, SettingsOwner {
|
||||
}
|
||||
|
||||
|
||||
public void setAuxclasspathFiles(List<File> lst) {
|
||||
fileListView.setItems(FXCollections.observableArrayList(lst));
|
||||
}
|
||||
|
||||
|
||||
public void setOnCancel(Runnable run) {
|
||||
onCancel.setValue(run);
|
||||
}
|
||||
|
||||
|
||||
public void setOnApply(Consumer<List<File>> onApply) {
|
||||
this.onApply.setValue(onApply);
|
||||
}
|
||||
|
||||
|
||||
private void moveUp() {
|
||||
moveItem(-1);
|
||||
}
|
||||
@ -144,61 +141,8 @@ public class AuxClassPathController implements Initializable, SettingsOwner {
|
||||
}
|
||||
|
||||
|
||||
private void setValidationSupport() {
|
||||
|
||||
}
|
||||
|
||||
private String classPathGenerator() throws IOException {
|
||||
|
||||
String classPath = "";
|
||||
|
||||
for (File f : fileListView.getItems()) {
|
||||
classPath = classPath + File.pathSeparator + f.getAbsolutePath();
|
||||
}
|
||||
|
||||
setClassPath(classPath);
|
||||
return classPath;
|
||||
}
|
||||
|
||||
|
||||
public void setClassPath(String classPath) throws IOException {
|
||||
|
||||
if (classLoader == null) {
|
||||
classLoader = PMDConfiguration.class.getClassLoader();
|
||||
}
|
||||
if (classPath != null) {
|
||||
classLoader = new ClasspathClassLoader(classPath, classLoader);
|
||||
}
|
||||
SourceEditorController.auxclasspathFiles = fileListView.getItems();
|
||||
|
||||
closePopup();
|
||||
}
|
||||
|
||||
|
||||
private void closePopup() {
|
||||
Stage stage = (Stage) setClassPathButton.getScene().getWindow();
|
||||
stage.close();
|
||||
}
|
||||
|
||||
public void showAuxPathWizard() throws Exception {
|
||||
|
||||
FXMLLoader fxmlLoader = new FXMLLoader(DesignerUtil.getFxml("auxclasspath-setup-popup.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.initOwner(designerRoot.getMainStage());
|
||||
stage.initModality(Modality.WINDOW_MODAL);
|
||||
stage.setScene(new Scene(root1));
|
||||
stage.show();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -5,14 +5,18 @@
|
||||
package net.sourceforge.pmd.util.fxdesigner;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
import java.time.Duration;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import java.util.ResourceBundle;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.fxmisc.richtext.LineNumberFactory;
|
||||
@ -25,6 +29,7 @@ import net.sourceforge.pmd.lang.LanguageVersion;
|
||||
import net.sourceforge.pmd.lang.ast.Node;
|
||||
import net.sourceforge.pmd.util.fxdesigner.model.ASTManager;
|
||||
import net.sourceforge.pmd.util.fxdesigner.model.ParseAbortedException;
|
||||
import net.sourceforge.pmd.util.fxdesigner.util.DesignerUtil;
|
||||
import net.sourceforge.pmd.util.fxdesigner.util.beans.SettingsOwner;
|
||||
import net.sourceforge.pmd.util.fxdesigner.util.beans.SettingsPersistenceUtil.PersistentProperty;
|
||||
import net.sourceforge.pmd.util.fxdesigner.util.codearea.AvailableSyntaxHighlighters;
|
||||
@ -34,13 +39,17 @@ import net.sourceforge.pmd.util.fxdesigner.util.controls.ASTTreeCell;
|
||||
import net.sourceforge.pmd.util.fxdesigner.util.controls.ASTTreeItem;
|
||||
import net.sourceforge.pmd.util.fxdesigner.util.controls.TreeViewWrapper;
|
||||
|
||||
import javafx.collections.ObservableList;
|
||||
import javafx.fxml.FXML;
|
||||
import javafx.fxml.FXMLLoader;
|
||||
import javafx.fxml.Initializable;
|
||||
import javafx.scene.Parent;
|
||||
import javafx.scene.Scene;
|
||||
import javafx.scene.control.Label;
|
||||
import javafx.scene.control.SelectionModel;
|
||||
import javafx.scene.control.TreeItem;
|
||||
import javafx.scene.control.TreeView;
|
||||
import javafx.stage.Modality;
|
||||
import javafx.stage.Stage;
|
||||
|
||||
|
||||
/**
|
||||
@ -52,6 +61,7 @@ import javafx.scene.control.TreeView;
|
||||
public class SourceEditorController implements Initializable, SettingsOwner {
|
||||
private final MainDesignerController parent;
|
||||
|
||||
|
||||
@FXML
|
||||
private Label astTitleLabel;
|
||||
@FXML
|
||||
@ -64,8 +74,8 @@ public class SourceEditorController implements Initializable, SettingsOwner {
|
||||
private ASTTreeItem selectedTreeItem;
|
||||
private static final Duration AST_REFRESH_DELAY = Duration.ofMillis(100);
|
||||
|
||||
public static ObservableList<File> auxclasspathFiles;
|
||||
private Var<ClassLoader> auxclasspathClassLoader;
|
||||
private Var<List<File>> auxclasspathFiles = Var.newSimpleVar(Collections.emptyList());
|
||||
private Val<ClassLoader> auxclasspathClassLoader;
|
||||
|
||||
public SourceEditorController(DesignerRoot owner, MainDesignerController mainController) {
|
||||
parent = mainController;
|
||||
@ -73,8 +83,6 @@ public class SourceEditorController implements Initializable, SettingsOwner {
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public void initialize(URL location, ResourceBundle resources) {
|
||||
|
||||
@ -132,20 +140,59 @@ public class SourceEditorController implements Initializable, SettingsOwner {
|
||||
|
||||
|
||||
public void showAuxClassPathController(DesignerRoot root) {
|
||||
AuxClassPathController auxClassPathController = new AuxClassPathController(auxclasspathFiles, root);
|
||||
AuxClassPathController auxClassPathController = new AuxClassPathController(root);
|
||||
|
||||
FXMLLoader fxmlLoader = new FXMLLoader(DesignerUtil.getFxml("auxclasspath-setup-popup.fxml"));
|
||||
|
||||
fxmlLoader.setControllerFactory(type -> {
|
||||
if (type == AuxClassPathController.class) {
|
||||
return auxClassPathController;
|
||||
} else {
|
||||
throw new IllegalStateException("Wrong controller!");
|
||||
}
|
||||
});
|
||||
try {
|
||||
Parent root1 = fxmlLoader.load();
|
||||
|
||||
auxClassPathController.setAuxclasspathFiles(auxclasspathFiles.getValue());
|
||||
|
||||
Stage stage = new Stage();
|
||||
stage.initOwner(root.getMainStage());
|
||||
stage.initModality(Modality.WINDOW_MODAL);
|
||||
stage.setScene(new Scene(root1));
|
||||
stage.show();
|
||||
|
||||
auxClassPathController.setOnApply(files -> {
|
||||
stage.close();
|
||||
auxclasspathFiles.setValue(files);
|
||||
});
|
||||
|
||||
auxClassPathController.setOnCancel(stage::close);
|
||||
|
||||
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@PersistentProperty
|
||||
public ObservableList<File> getAuxclasspathFiles() {
|
||||
return auxclasspathFiles;
|
||||
public String getAuxclasspathFiles() {
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
for (File f : auxclasspathFiles.getValue()) {
|
||||
sb.append(';').append(f.getAbsolutePath());
|
||||
}
|
||||
return sb.length() > 0 ? sb.substring(1) : "";
|
||||
}
|
||||
|
||||
|
||||
public void setAuxClassPathFiles(ObservableList<File> auxclasspathFiles) {
|
||||
this.auxclasspathFiles = auxclasspathFiles;
|
||||
public void setAuxClassPathFiles(String files) {
|
||||
List<File> newVal = Arrays.asList(files.split(";")).stream().map(File::new).collect(Collectors.toList());
|
||||
auxclasspathFiles.setValue(newVal);
|
||||
}
|
||||
|
||||
|
||||
@ -205,7 +252,7 @@ public class SourceEditorController implements Initializable, SettingsOwner {
|
||||
|
||||
// node is different from the old one
|
||||
if (selectedTreeItem == null && node != null
|
||||
|| selectedTreeItem != null && !Objects.equals(node, selectedTreeItem.getValue())) {
|
||||
|| selectedTreeItem != null && !Objects.equals(node, selectedTreeItem.getValue())) {
|
||||
ASTTreeItem found = ((ASTTreeItem) astTreeView.getRoot()).findItem(node);
|
||||
if (found != null) {
|
||||
selectionModel.select(found);
|
||||
|
Reference in New Issue
Block a user