Search in sources :

Example 1 with ConfigureIoExpanderDialog

use of com.thecoderscorner.menu.editorui.dialog.ConfigureIoExpanderDialog in project tcMenu by davetcc.

the class ChooseIoExpanderController method initialise.

public void initialise(Optional<IoExpanderDefinition> current, CurrentEditorProject project) {
    this.project = project;
    if (current.isEmpty()) {
        selectButton.setDisable(true);
        selectButton.setVisible(false);
        selectButton.setManaged(false);
        closeButton.setText("Close");
    }
    tableNameCol.setCellValueFactory(cell -> new ReadOnlyObjectWrapper<>(cell.getValue().getId()));
    tableDescCol.setCellValueFactory(cell -> new ReadOnlyObjectWrapper<>(cell.getValue().getNicePrintableName()));
    tableInUseCol.setCellValueFactory(cell -> new ReadOnlyObjectWrapper<>(isExpanderInUse(cell.getValue().getId()) ? "Yes" : "No"));
    ioItems.addAll(project.getGeneratorOptions().getExpanderDefinitions().getAllExpanders());
    mainTable.setItems(ioItems);
    current.ifPresent(io -> mainTable.getSelectionModel().select(io));
    mainTable.getSelectionModel().selectedIndexProperty().addListener((ov, oldVal, newVal) -> {
        int selection = (newVal != null) ? newVal.intValue() : -1;
        selectButton.setDisable(selection < 0 || current.isEmpty());
        removeButton.setDisable(selection < 0 || isExpanderInUse(ioItems.get(selection).getId()) || ioItems.get(selection).getId().equals(InternalDeviceExpander.DEVICE_ID));
    });
    mainTable.setRowFactory(tv -> {
        TableRow<IoExpanderDefinition> row = new TableRow<>();
        row.setOnMouseClicked(event -> {
            if (event.getClickCount() == 2 && (!row.isEmpty())) {
                // is the row both available and not internal IO,
                IoExpanderDefinition existing = row.getItem();
                int idxExisting = ioItems.indexOf(existing);
                if (idxExisting < 0 || existing instanceof InternalDeviceExpander)
                    return;
                var dialog = new ConfigureIoExpanderDialog((Stage) mainTable.getScene().getWindow(), existing, allExistingNames(), true);
                dialog.getResultOrEmpty().ifPresent(newItem -> ioItems.set(idxExisting, newItem));
            }
        });
        return row;
    });
}
Also used : IoExpanderDefinition(com.thecoderscorner.menu.editorui.generator.parameters.IoExpanderDefinition) InternalDeviceExpander(com.thecoderscorner.menu.editorui.generator.parameters.expander.InternalDeviceExpander) ConfigureIoExpanderDialog(com.thecoderscorner.menu.editorui.dialog.ConfigureIoExpanderDialog)

Aggregations

ConfigureIoExpanderDialog (com.thecoderscorner.menu.editorui.dialog.ConfigureIoExpanderDialog)1 IoExpanderDefinition (com.thecoderscorner.menu.editorui.generator.parameters.IoExpanderDefinition)1 InternalDeviceExpander (com.thecoderscorner.menu.editorui.generator.parameters.expander.InternalDeviceExpander)1