List can be reordered , I'll update the UI by day's end.
I need to still test the classPathLoader @jsotuyod some guidance needed here.
This commit is contained in:
@ -6,10 +6,13 @@
|
||||
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 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;
|
||||
|
||||
@ -27,29 +30,43 @@ import javafx.stage.Stage;
|
||||
public class AuxClassPathController implements Initializable, SettingsOwner {
|
||||
|
||||
private final DesignerRoot designerRoot;
|
||||
|
||||
@FXML
|
||||
private Button removeFiles;
|
||||
@FXML
|
||||
private Button selectFile;
|
||||
@FXML
|
||||
private ListView<File> fileList;
|
||||
@FXML
|
||||
private final MainDesignerController parent;
|
||||
private ClassLoader classLoader = getClass().getClassLoader();
|
||||
|
||||
|
||||
public AuxClassPathController(DesignerRoot designerRoot, MainDesignerController parent) {
|
||||
|
||||
@FXML
|
||||
private Button removeFileButton;
|
||||
@FXML
|
||||
private Button selectFilesButton;
|
||||
@FXML
|
||||
private ListView<File> fileListView;
|
||||
@FXML
|
||||
private Button moveItemUpButton;
|
||||
@FXML
|
||||
private Button moveItemDownButton;
|
||||
@FXML
|
||||
private Button setClassPathButton;
|
||||
|
||||
|
||||
public AuxClassPathController(DesignerRoot designerRoot) {
|
||||
this.designerRoot = designerRoot;
|
||||
this.parent = parent;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void initialize(URL location, ResourceBundle resources) {
|
||||
|
||||
selectFile.setOnAction(e -> onSelectFileClicked());
|
||||
removeFiles.setOnAction(e -> onRemoveFileClicked());
|
||||
|
||||
selectFilesButton.setOnAction(e -> onSelectFileClicked());
|
||||
removeFileButton.setOnAction(e -> onRemoveFileClicked());
|
||||
setClassPathButton.setOnAction(e -> {
|
||||
try {
|
||||
setClassPath(classPathGenerator());
|
||||
} catch (IOException e1) {
|
||||
e1.printStackTrace();
|
||||
}
|
||||
});
|
||||
moveItemUpButton.setOnAction(e -> moveUp());
|
||||
moveItemDownButton.setOnAction(e -> moveDown());
|
||||
}
|
||||
|
||||
|
||||
@ -62,19 +79,86 @@ public class AuxClassPathController implements Initializable, SettingsOwner {
|
||||
new FileChooser.ExtensionFilter("Java EARs", "*.ear"),
|
||||
new FileChooser.ExtensionFilter("Java class files", "*.class")
|
||||
);
|
||||
List<File> file = chooser.showOpenMultipleDialog((designerRoot.getMainStage()));
|
||||
List<File> file = chooser.showOpenMultipleDialog(designerRoot.getMainStage());
|
||||
for (File f : file) {
|
||||
fileList.getItems().add(f);
|
||||
fileListView.getItems().add(f);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void onRemoveFileClicked() {
|
||||
File f = fileList.getSelectionModel().getSelectedItem();
|
||||
fileList.getItems().remove(f);
|
||||
File f = fileListView.getSelectionModel().getSelectedItem();
|
||||
fileListView.getItems().remove(f);
|
||||
}
|
||||
|
||||
|
||||
private void moveUp() {
|
||||
moveItem(-1);
|
||||
}
|
||||
|
||||
|
||||
private void moveDown() {
|
||||
moveItem(1);
|
||||
}
|
||||
|
||||
|
||||
public void moveItem(int direction) {
|
||||
// Checking selected item
|
||||
if (fileListView.getSelectionModel().getSelectedItem() == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Calculate new index using move direction
|
||||
int newIndex = fileListView.getSelectionModel().getSelectedIndex() + direction;
|
||||
|
||||
if (newIndex < 0 || newIndex >= fileListView.getItems().size()) {
|
||||
return;
|
||||
}
|
||||
|
||||
File selected = fileListView.getSelectionModel().getSelectedItem();
|
||||
|
||||
// Removing removable element
|
||||
fileListView.getItems().remove(selected);
|
||||
// Insert it in new position
|
||||
fileListView.getItems().add(newIndex, selected);
|
||||
//Restore Selection
|
||||
fileListView.scrollTo(newIndex);
|
||||
fileListView.getSelectionModel().select(newIndex);
|
||||
|
||||
}
|
||||
|
||||
|
||||
private String classPathGenerator() throws IOException {
|
||||
|
||||
String classPath = "";
|
||||
|
||||
for (File f : fileListView.getItems()) {
|
||||
classPath = classPath + ";" + 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);
|
||||
}
|
||||
|
||||
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"));
|
||||
|
@ -126,7 +126,7 @@ public class MainDesignerController implements Initializable, SettingsOwner {
|
||||
|
||||
public MainDesignerController(DesignerRoot owner) {
|
||||
this.designerRoot = owner;
|
||||
this.auxClassPathController = new AuxClassPathController(designerRoot, this);
|
||||
this.auxClassPathController = new AuxClassPathController(designerRoot);
|
||||
}
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user