Skip to content

Commit

Permalink
Added button to invert exchange rate value
Browse files Browse the repository at this point in the history
When entering data, users might only have the inverted exchange rate
at hand. This button simply divides 1 by the current exchange rate value
to invert the rate.
  • Loading branch information
buchen committed Sep 29, 2019
1 parent af2baaa commit d05192d
Show file tree
Hide file tree
Showing 12 changed files with 62 additions and 4 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ public enum Images
CHEVRON("chevron.png"), //$NON-NLS-1$
INTERVAL("interval.png"), //$NON-NLS-1$
NEW_TRANSACTION("new_transaction.png"), //$NON-NLS-1$
INVERT_EXCHANGE_RATE("invert_exchange_rate.png"), //$NON-NLS-1$

CATEGORY("category.png"), //$NON-NLS-1$
UNASSIGNED_CATEGORY("unassigned.png"), //$NON-NLS-1$
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public class Messages extends NLS
public static String BtnLabelOpenInvestmentPlanView;
public static String BtnLabelRestartLater;
public static String BtnLabelRestartNow;
public static String BtnTooltipInvertExchangeRate;
public static String CellEditor_NotANumber;
public static String ChartBringForward;
public static String ChartBringToFront;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,39 @@ public void linkActivated(HyperlinkEvent e)
}
}

public class ExchangeRateInput extends Input
{
public final ImageHyperlink buttonInvertExchangeRate;

public ExchangeRateInput(Composite editArea, String text)
{
super(editArea, text);

buttonInvertExchangeRate = new ImageHyperlink(editArea, SWT.NONE);
buttonInvertExchangeRate.setImage(Images.INVERT_EXCHANGE_RATE.image());
buttonInvertExchangeRate.setToolTipText(Messages.BtnTooltipInvertExchangeRate);
}

public void bindInvertAction(Runnable invertAction)
{
buttonInvertExchangeRate.addHyperlinkListener(new HyperlinkAdapter()
{
@Override
public void linkActivated(HyperlinkEvent e)
{
invertAction.run();
}
});
}

@Override
public void setVisible(boolean visible)
{
super.setVisible(visible);
buttonInvertExchangeRate.setVisible(visible);
}
}

class ModelStatusListener
{
public void setStatus(IStatus status)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import static name.abuchen.portfolio.ui.util.SWTHelper.currencyWidth;
import static name.abuchen.portfolio.ui.util.SWTHelper.widest;

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.text.MessageFormat;
import java.time.LocalDate;
import java.util.ArrayList;
Expand Down Expand Up @@ -144,12 +146,14 @@ public void widgetSelected(SelectionEvent e)
fxGrossAmount.bindValue(Properties.fxGrossAmount.name(), totalLabel, Values.Amount, true);
fxGrossAmount.bindCurrency(Properties.fxCurrencyCode.name());

Input exchangeRate = new Input(editArea, useIndirectQuotation ? "/ " : "x "); //$NON-NLS-1$ //$NON-NLS-2$
ExchangeRateInput exchangeRate = new ExchangeRateInput(editArea, useIndirectQuotation ? "/ " : "x "); //$NON-NLS-1$ //$NON-NLS-2$
exchangeRate.bindBigDecimal(
useIndirectQuotation ? Properties.inverseExchangeRate.name() : Properties.exchangeRate.name(),
Values.ExchangeRate.pattern());
exchangeRate.bindCurrency(useIndirectQuotation ? Properties.inverseExchangeRateCurrencies.name()
: Properties.exchangeRateCurrencies.name());
exchangeRate.bindInvertAction(() -> model()
.setExchangeRate(BigDecimal.ONE.divide(model().getExchangeRate(), 10, RoundingMode.HALF_DOWN)));

model().addPropertyChangeListener(Properties.exchangeRate.name(),
e -> exchangeRate.value.setToolTipText(AbstractModel.createCurrencyToolTip(
Expand Down Expand Up @@ -231,6 +235,7 @@ public void widgetSelected(SelectionEvent e)
.thenRight(fxGrossAmount.currency).width(currencyWidth) //
.thenRight(exchangeRate.label) //
.thenRight(exchangeRate.value).width(amountWidth) //
.thenRight(exchangeRate.buttonInvertExchangeRate, 0) //
.thenRight(exchangeRate.currency).width(amountWidth) //
.thenRight(grossAmount.label) //
.thenRight(grossAmount.value).width(amountWidth) //
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import static name.abuchen.portfolio.ui.util.SWTHelper.currencyWidth;
import static name.abuchen.portfolio.ui.util.SWTHelper.widest;

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.time.LocalDate;

import javax.annotation.PostConstruct;
Expand Down Expand Up @@ -126,12 +128,14 @@ protected void createFormElements(Composite editArea)
fxAmount.bindValue(Properties.fxAmount.name(), Messages.ColumnAmount, Values.Amount, true);
fxAmount.bindCurrency(Properties.sourceAccountCurrency.name());

Input exchangeRate = new Input(editArea, useIndirectQuotation ? "/ " : "x "); //$NON-NLS-1$ //$NON-NLS-2$
ExchangeRateInput exchangeRate = new ExchangeRateInput(editArea, useIndirectQuotation ? "/ " : "x "); //$NON-NLS-1$ //$NON-NLS-2$
exchangeRate.bindBigDecimal(
useIndirectQuotation ? Properties.inverseExchangeRate.name() : Properties.exchangeRate.name(),
Values.ExchangeRate.pattern());
exchangeRate.bindCurrency(useIndirectQuotation ? Properties.inverseExchangeRateCurrencies.name()
: Properties.exchangeRateCurrencies.name());
exchangeRate.bindInvertAction(() -> model()
.setExchangeRate(BigDecimal.ONE.divide(model().getExchangeRate(), 10, RoundingMode.HALF_DOWN)));

model().addPropertyChangeListener(Properties.exchangeRate.name(),
e -> exchangeRate.value.setToolTipText(AbstractModel.createCurrencyToolTip(
Expand Down Expand Up @@ -169,6 +173,7 @@ protected void createFormElements(Composite editArea)
.thenRight(fxAmount.currency).width(currencyWidth) //
.thenRight(exchangeRate.label) //
.thenRight(exchangeRate.value).width(amountWidth) //
.thenRight(exchangeRate.buttonInvertExchangeRate, 0) //
.thenRight(exchangeRate.currency).width(amountWidth) //
.thenRight(amount.label) //
.thenRight(amount.value).width(amountWidth) //
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import static name.abuchen.portfolio.ui.util.SWTHelper.currencyWidth;
import static name.abuchen.portfolio.ui.util.SWTHelper.widest;

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.time.LocalDate;
import java.util.Collections;
import java.util.List;
Expand Down Expand Up @@ -133,12 +135,14 @@ protected void createFormElements(Composite editArea)
grossValue.bindValue(Properties.grossValue.name(), Messages.ColumnSubTotal, Values.Amount, true);
grossValue.bindCurrency(Properties.securityCurrencyCode.name());

Input exchangeRate = new Input(editArea, useIndirectQuotation ? "/ " : "x "); //$NON-NLS-1$ //$NON-NLS-2$
ExchangeRateInput exchangeRate = new ExchangeRateInput(editArea, useIndirectQuotation ? "/ " : "x "); //$NON-NLS-1$ //$NON-NLS-2$
exchangeRate.bindBigDecimal(
useIndirectQuotation ? Properties.inverseExchangeRate.name() : Properties.exchangeRate.name(),
Values.ExchangeRate.pattern());
exchangeRate.bindCurrency(useIndirectQuotation ? Properties.inverseExchangeRateCurrencies.name()
: Properties.exchangeRateCurrencies.name());
exchangeRate.bindInvertAction(() -> model()
.setExchangeRate(BigDecimal.ONE.divide(model().getExchangeRate(), 10, RoundingMode.HALF_DOWN)));

model().addPropertyChangeListener(Properties.exchangeRate.name(),
e -> exchangeRate.value.setToolTipText(AbstractModel.createCurrencyToolTip(
Expand Down Expand Up @@ -217,7 +221,8 @@ protected void createFormElements(Composite editArea)
.thenRight(grossValue.currency);

startingWith(quote.value).thenBelow(exchangeRate.value).width(width).label(exchangeRate.label)
.thenRight(exchangeRate.currency).width(width);
.thenRight(exchangeRate.buttonInvertExchangeRate, 0).thenRight(exchangeRate.currency)
.width(width);

startingWith(grossValue.value)
// converted gross value
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ BtnLabelRestartLater = Restart later

BtnLabelRestartNow = Restart now

BtnTooltipInvertExchangeRate = Invert the exchange rate value.\n\nPlease note: this operation does not change the notation of the exchange rate, but simply divids 1 by the current value.

CSVConfigCSVImportLabelFileJSON = JSON files (*.json)

CSVConfigDelete = Delete configuration
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ BtnLabelRestartLater = Sp\u00E4ter neustarten

BtnLabelRestartNow = Jetzt neustarten

BtnTooltipInvertExchangeRate = Den Wechselkurs umkehren.\n\nHinweis: Diese Operation \u00E4ndert nicht die Notation des Wechselkurses, sondern dividiert einfach 1 durch den aktuellen Wert.

CSVConfigCSVImportLabelFileJSON = JSON Dateien (*.json)

CSVConfigDelete = Konfiguration l\u00F6schen
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ BtnLabelRestartLater = Reiniciar m\u00E1s tarde

BtnLabelRestartNow = Reiniciar ahora

BtnTooltipInvertExchangeRate = Invierta el valor del tipo de cambio.\n\nTenga en cuenta: esta operaci\u00F3n no cambia la notaci\u00F3n del tipo de cambio, sino que simplemente divide 1 por el valor actual.

CSVImportErrorMissingFields = Campo(s) obligatorio no asignado(s): {0}\n\n

CSVImportInformationOptionalFields = Campo(s) opcionales no asignado(s): {0}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ BtnLabelRestartLater = Later opnieuw opstarten
BtnLabelRestartNow = Nu opnieuw opstarten
BtnTooltipInvertExchangeRate = Keer de wisselkoerswaarde om.\n\nLet op: deze bewerking wijzigt de notatie van de wisselkoers niet, maar deelt eenvoudig 1 door de huidige waarde.
CSVConfigCSVImportLabelFileJSON = JSON-bestanden (* .json)
CSVConfigDelete = Configuratie verwijderen
Expand Down

0 comments on commit d05192d

Please sign in to comment.