1
0
mirror of https://github.com/DanilaFe/abacus synced 2024-12-22 07:20:09 -08:00

Add UI to add definition files.

This commit is contained in:
Danila Fedorin 2017-11-23 20:15:39 -08:00
parent 9bdf188ca7
commit 8f682e96af
2 changed files with 43 additions and 4 deletions

View File

@ -8,6 +8,7 @@ import javafx.fxml.FXML;
import javafx.scene.control.*; import javafx.scene.control.*;
import javafx.scene.control.cell.CheckBoxListCell; import javafx.scene.control.cell.CheckBoxListCell;
import javafx.scene.text.Text; import javafx.scene.text.Text;
import javafx.stage.FileChooser;
import javafx.util.Callback; import javafx.util.Callback;
import javafx.util.StringConverter; import javafx.util.StringConverter;
import org.nwapw.abacus.Abacus; import org.nwapw.abacus.Abacus;
@ -107,6 +108,8 @@ public class AbacusController implements PluginListener {
private ListView<Documentation> functionListView; private ListView<Documentation> functionListView;
@FXML @FXML
private TextField functionListSearchField; private TextField functionListSearchField;
@FXML
private ListView<String> definitionFilesView;
/** /**
* The list of history entries, created by the users. * The list of history entries, created by the users.
@ -132,6 +135,10 @@ public class AbacusController implements PluginListener {
* The filtered list displayed to the user. * The filtered list displayed to the user.
*/ */
private FilteredList<Documentation> functionFilter; private FilteredList<Documentation> functionFilter;
/**
* The list of definition files to be loaded.
*/
private ObservableList<String> definitionFiles;
/** /**
* The abacus instance used for changing the plugin configuration. * The abacus instance used for changing the plugin configuration.
@ -255,6 +262,9 @@ public class AbacusController implements PluginListener {
if (oldValue.equals(settingsTab)) alertIfApplyNeeded(true); if (oldValue.equals(settingsTab)) alertIfApplyNeeded(true);
}); });
definitionFiles = FXCollections.observableArrayList();
definitionFilesView.setItems(definitionFiles);
abacus = new Abacus(new ExtendedConfiguration(CONFIG_FILE)); abacus = new Abacus(new ExtendedConfiguration(CONFIG_FILE));
PluginManager abacusPluginManager = abacus.getPluginManager(); PluginManager abacusPluginManager = abacus.getPluginManager();
abacusPluginManager.addListener(this); abacusPluginManager.addListener(this);
@ -353,23 +363,42 @@ public class AbacusController implements PluginListener {
@FXML @FXML
public void performSave() { public void performSave() {
Configuration configuration = abacus.getConfiguration(); ExtendedConfiguration configuration = (ExtendedConfiguration) abacus.getConfiguration();
configuration.setNumberImplementation(numberImplementationBox.getSelectionModel().getSelectedItem()); configuration.setNumberImplementation(numberImplementationBox.getSelectionModel().getSelectedItem());
Set<String> disabledPlugins = configuration.getDisabledPlugins(); Set<String> disabledPlugins = configuration.getDisabledPlugins();
disabledPlugins.clear(); disabledPlugins.clear();
for (ToggleablePlugin pluginEntry : enabledPlugins) { for (ToggleablePlugin pluginEntry : enabledPlugins) {
if (!pluginEntry.isEnabled()) disabledPlugins.add(pluginEntry.getClassName()); if (!pluginEntry.isEnabled()) disabledPlugins.add(pluginEntry.getClassName());
} }
Set<String> abacusDefinitionFiles = configuration.getDefinitionFiles();
abacusDefinitionFiles.clear();
abacusDefinitionFiles.addAll(definitionFiles);
if (computationLimitField.getText().matches("\\d*(\\.\\d+)?") && computationLimitField.getText().length() != 0) if (computationLimitField.getText().matches("\\d*(\\.\\d+)?") && computationLimitField.getText().length() != 0)
((ExtendedConfiguration) configuration).setComputationDelay(Double.parseDouble(computationLimitField.getText())); configuration.setComputationDelay(Double.parseDouble(computationLimitField.getText()));
((ExtendedConfiguration) configuration).saveTo(CONFIG_FILE); configuration.saveTo(CONFIG_FILE);
changesMade = false; changesMade = false;
reloadAlertShown = false; reloadAlertShown = false;
} }
@FXML
public void performAddDefinitionFile(){
FileChooser fileChooser = new FileChooser();
fileChooser.setTitle("Add definition file");
File selectedFile = fileChooser.showOpenDialog(null);
if(selectedFile == null) return;
String absolutePath = selectedFile.getAbsolutePath();
if(!definitionFiles.contains(absolutePath)) definitionFiles.add(absolutePath);
}
@FXML
public void performRemoveDefinitionFile(){
String selectedItem = definitionFilesView.getSelectionModel().getSelectedItem();
if(selectedItem != null) definitionFiles.remove(selectedItem);
}
@Override @Override
public void onLoad(PluginManager manager) { public void onLoad(PluginManager manager) {
Configuration configuration = abacus.getConfiguration(); ExtendedConfiguration configuration = (ExtendedConfiguration) abacus.getConfiguration();
Set<String> disabledPlugins = configuration.getDisabledPlugins(); Set<String> disabledPlugins = configuration.getDisabledPlugins();
numberImplementationOptions.addAll(abacus.getPluginManager().getAllNumberImplementations()); numberImplementationOptions.addAll(abacus.getPluginManager().getAllNumberImplementations());
String actualImplementation = configuration.getNumberImplementation(); String actualImplementation = configuration.getNumberImplementation();
@ -395,6 +424,7 @@ public class AbacusController implements PluginListener {
return documentationInstance; return documentationInstance;
}).collect(Collectors.toCollection(ArrayList::new))); }).collect(Collectors.toCollection(ArrayList::new)));
functionList.sort(Comparator.comparing(Documentation::getCodeName)); functionList.sort(Comparator.comparing(Documentation::getCodeName));
definitionFiles.addAll(configuration.getDefinitionFiles());
} }
@Override @Override
@ -402,6 +432,7 @@ public class AbacusController implements PluginListener {
functionList.clear(); functionList.clear();
enabledPlugins.clear(); enabledPlugins.clear();
numberImplementationOptions.clear(); numberImplementationOptions.clear();
definitionFiles.clear();
} }
} }

View File

@ -59,6 +59,14 @@
<Button text="Apply and Reload" onAction="#performSaveAndReload"/> <Button text="Apply and Reload" onAction="#performSaveAndReload"/>
<Button text="Scan Plugins" onAction="#performScan"/> <Button text="Scan Plugins" onAction="#performScan"/>
</FlowPane> </FlowPane>
<ListView fx:id="definitionFilesView"
GridPane.columnIndex="0" GridPane.columnSpan="2"
GridPane.rowIndex="4" maxHeight="100"/>
<FlowPane GridPane.columnIndex="0" GridPane.columnSpan="2" GridPane.rowIndex="5" hgap="10"
vgap="10">
<Button text="Add" onAction="#performAddDefinitionFile"/>
<Button text="Remove" onAction="#performRemoveDefinitionFile"/>
</FlowPane>
</GridPane> </GridPane>
</Tab> </Tab>
<Tab fx:id="functionListTab" text="Functions" closable="false"> <Tab fx:id="functionListTab" text="Functions" closable="false">