use of jgnash.engine.Tag in project jgnash by ccavanaugh.
the class SlipController method splitsAction.
@FXML
private void splitsAction() {
final SplitTransactionDialog splitsDialog = new SplitTransactionDialog();
splitsDialog.accountProperty().setValue(accountProperty().get());
splitsDialog.getTransactionEntries().setAll(transactionEntries);
final boolean wasSplit = transactionEntries.get().size() > 0;
// Show the dialog and process the transactions when it closes
splitsDialog.show(slipType, () -> {
transactionEntries.setAll(splitsDialog.getTransactionEntries());
if (transactionEntries.get().size() > 0) {
amountField.setDecimal(splitsDialog.getBalance().abs());
} else if (wasSplit) {
// spits were cleared out
amountField.setDecimal(BigDecimal.ZERO);
}
// If valid splits exist and the user has requested concatenation, show a preview of what will happen
concatenated.setValue(Options.concatenateMemosProperty().get() && !transactionEntries.isEmpty());
if (concatenated.get()) {
memoTextField.setText(Transaction.getMemo(transactionEntries));
}
if (transactionEntries.get().size() > 0) {
// process the tags from the split transaction
final Set<Tag> tags = new HashSet<>();
for (final TransactionEntry entry : transactionEntries.get()) {
tags.addAll(entry.getTags());
}
tagPane.setSelectedTags(tags);
tagPane.refreshTagView();
} else if (wasSplit) {
// clear out all the prior split entries
tagPane.clearSelectedTags();
}
});
}
use of jgnash.engine.Tag in project jgnash by ccavanaugh.
the class TransactionTagDialogController method loadTags.
private void loadTags() {
final Engine engine = EngineFactory.getEngine(EngineFactory.DEFAULT);
Objects.requireNonNull(engine);
final List<Tag> tagList = new ArrayList<>(engine.getTags());
Collections.sort(tagList);
for (final Tag tag : tagList) {
final CheckBox checkBox = new CheckBox(tag.getName());
checkBox.setGraphic(MaterialDesignLabel.fromInteger(tag.getShape(), MaterialDesignLabel.DEFAULT_SIZE * TransactionTagPane.ICON_SCALE, tag.getColor()));
checkBox.setUserData(tag);
TilePane.setAlignment(checkBox, Pos.BASELINE_LEFT);
tilePane.getChildren().add(checkBox);
}
tagsLoaded.set(true);
}
use of jgnash.engine.Tag in project jgnash by ccavanaugh.
the class TagManagerDialogController method handleDuplicateAction.
@FXML
private void handleDuplicateAction() {
final Engine engine = EngineFactory.getEngine(EngineFactory.DEFAULT);
Objects.requireNonNull(engine);
for (final Tag tag : tagListView.getSelectionModel().getSelectedItems()) {
try {
final Tag newTag = (Tag) tag.clone();
if (!engine.addTag(newTag)) {
StaticUIMethods.displayError(resources.getString("Message.Error.TagDuplicate"));
}
} catch (final CloneNotSupportedException e) {
Logger.getLogger(TagManagerDialogController.class.getName()).log(Level.SEVERE, e.toString(), e);
}
}
}
use of jgnash.engine.Tag in project jgnash by ccavanaugh.
the class TransactionTagPieChartDialogController method updateChart.
private void updateChart() {
final Engine engine = EngineFactory.getEngine(EngineFactory.DEFAULT);
Objects.requireNonNull(engine);
final Account a = accountComboBox.getValue();
if (a != null) {
final CurrencyNode defaultCurrency = a.getCurrencyNode();
final NumberFormat numberFormat = NumericFormats.getFullCommodityFormat(defaultCurrency);
final ObservableList<PieChart.Data> pieChartData = FXCollections.observableArrayList();
final Map<Tag, BigDecimal> balanceMap = new HashMap<>();
// Iterate through all the Tags in use
for (final Tag tag : engine.getTagsInUse()) {
BigDecimal balance = new BigDecimal(BigInteger.ZERO);
for (final Account child : a.getChildren()) {
balance = balance.add(getSumForTag(tag, child));
}
if (balance.compareTo(BigDecimal.ZERO) != 0) {
balanceMap.put(tag, balance);
}
}
// Sum of all the balances
final BigDecimal total = balanceMap.values().stream().reduce(BigDecimal.ZERO, BigDecimal::add);
// Iterate and crate each pie slice
for (final Map.Entry<Tag, BigDecimal> entry : balanceMap.entrySet()) {
final Tag tag = entry.getKey();
final BigDecimal balance = entry.getValue();
final String label = tag.getName() + " - " + numberFormat.format(balance.doubleValue());
// protect against a div by zero caused by net zero of income and expense
double value = total.compareTo(BigDecimal.ZERO) == 0 ? 0 : balance.divide(total, MathContext.DECIMAL64).multiply(ONE_HUNDRED).doubleValue();
final PieChart.Data data = new PieChart.Data(label, value);
// nodes are created lazily. Set the user data (Tag) after the node is created
data.nodeProperty().addListener((observable, oldValue, newValue) -> newValue.setUserData(tag));
pieChartData.add(data);
}
pieChart.setData(pieChartData);
final NumberFormat percentFormat = NumberFormat.getPercentInstance();
percentFormat.setMaximumFractionDigits(1);
percentFormat.setMinimumFractionDigits(1);
// Install tooltips on the data after it has been added to the chart
pieChart.getData().forEach(data -> Tooltip.install(data.getNode(), new Tooltip((((Tag) data.getNode().getUserData()).getName() + " - " + percentFormat.format(data.getPieValue() / 100d)))));
pieChart.setTitle(resources.getString("Title.TransactionTagPieChart"));
pieChart.centerTitleProperty().set(accountComboBox.getValue().getName());
pieChart.centerSubTitleProperty().set(numberFormat.format(total));
} else {
pieChart.setData(FXCollections.emptyObservableList());
pieChart.setTitle("No Data");
}
}
use of jgnash.engine.Tag in project jgnash by ccavanaugh.
the class TransactionTagDialogController method setSelectedTags.
void setSelectedTags(final Collection<Tag> tags) {
// create a copy of the old selection
originalTagSelection.addAll(tags);
JavaFXUtils.runLater(() -> {
while (!tagsLoaded.get()) {
Thread.onSpinWait();
}
for (final Node node : tilePane.getChildren()) {
for (final Tag tag : tags) {
if (tag.equals(node.getUserData())) {
JavaFXUtils.runLater(() -> ((CheckBox) node).setSelected(true));
}
}
}
});
}
Aggregations