@FXML public void initialize() { // Needed to support tri-state capability reconciledButton.setAllowIndeterminate(true); // Number combo needs to know the account in order to determine the next transaction number numberComboBox.accountProperty().bind(accountProperty()); AutoCompleteFactory.setMemoModel(memoTextField); accountProperty.addListener( (observable, oldValue, newValue) -> { // Set the number of fixed decimal places for entry amountField.scaleProperty().set(newValue.getCurrencyNode().getScale()); // Enabled auto completion for the payee field if (payeeTextField != null) { // transfer slips do not use the payee field AutoCompleteFactory.setPayeeModel(payeeTextField, newValue); } }); // If focus is lost, check and load the form with an existing transaction if (payeeTextField != null) { // transfer slips do not use the payee field payeeTextField .focusedProperty() .addListener( (observable, oldValue, newValue) -> { if (!newValue) { handlePayeeFocusChange(); } }); } // Install an event handler when the parent has been set via injection parentProperty.addListener( (observable, oldValue, newValue) -> { newValue.addEventHandler( KeyEvent.KEY_PRESSED, event -> { if (JavaFXUtils.ESCAPE_KEY.match( event)) { // clear the form if an escape key is detected clearForm(); } else if (JavaFXUtils.ENTER_KEY.match(event)) { // handle an enter key if detected if (validateForm()) { Platform.runLater(AbstractSlipController.this::handleEnterAction); } else { Platform.runLater( () -> { if (event.getSource() instanceof Node) { JavaFXUtils.focusNext((Node) event.getSource()); } }); } } }); }); }
@FXML @Override public void handleCancelAction() { clearForm(); if (payeeTextField != null) { payeeTextField.requestFocus(); } else { memoTextField.requestFocus(); } }
@FXML @Override public void handleEnterAction() { if (validateForm()) { if (modTrans == null) { // new transaction Transaction newTrans = buildTransaction(); ReconcileManager.reconcileTransaction( accountProperty.get(), newTrans, getReconciledState()); newTrans = attachmentPane.buildTransaction(newTrans); // chain the transaction build final Engine engine = EngineFactory.getEngine(EngineFactory.DEFAULT); if (engine != null) { engine.addTransaction(newTrans); } } else { Transaction newTrans = buildTransaction(); newTrans.setDateEntered(modTrans.getDateEntered()); // restore the reconciled state of the previous old transaction for (final Account a : modTrans.getAccounts()) { if (!a.equals(accountProperty.get())) { ReconcileManager.reconcileTransaction(a, newTrans, modTrans.getReconciled(a)); } } /* * Reconcile the modified transaction for this account. * This must be performed last to ensure consistent results per the ReconcileManager rules */ ReconcileManager.reconcileTransaction( accountProperty.get(), newTrans, getReconciledState()); newTrans = attachmentPane.buildTransaction(newTrans); // chain the transaction build final Engine engine = EngineFactory.getEngine(EngineFactory.DEFAULT); if (engine != null && engine.removeTransaction(modTrans)) { engine.addTransaction(newTrans); } } clearForm(); if (payeeTextField != null) { payeeTextField.requestFocus(); } else { memoTextField.requestFocus(); } } }
@Override public void clearForm() { super.clearForm(); convertButton.setDisable(true); }