Skip to content

Commit

Permalink
Infer the default currency based on the user's locale when creating a…
Browse files Browse the repository at this point in the history
… new portfolio file
  • Loading branch information
liuhaoXD committed Dec 13, 2024
1 parent aceddd4 commit e404ebd
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ workspace
.metadata/*
.recommenders/*
.DS_Store
.sonarlint

### IntelliJ IDEA ###
.idea
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,6 @@
import java.util.Collections;
import java.util.List;

import name.abuchen.portfolio.money.CurrencyUnit;
import name.abuchen.portfolio.ui.Messages;
import name.abuchen.portfolio.ui.util.FormDataFactory;
import name.abuchen.portfolio.ui.wizards.AbstractWizardPage;

import org.eclipse.jface.viewers.ArrayContentProvider;
import org.eclipse.jface.viewers.ComboViewer;
import org.eclipse.jface.viewers.IStructuredSelection;
Expand All @@ -17,6 +12,10 @@
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;

import name.abuchen.portfolio.money.CurrencyUnit;
import name.abuchen.portfolio.ui.Messages;
import name.abuchen.portfolio.ui.util.FormDataFactory;
import name.abuchen.portfolio.ui.wizards.AbstractWizardPage;
class BaseCurrencySelectionPage extends AbstractWizardPage
{
private ComboViewer combo;
Expand All @@ -41,12 +40,13 @@ public void createControl(Composite parent)
Label label = new Label(container, SWT.NONE);
label.setText(Messages.ColumnCurrency);


List<CurrencyUnit> currencies = CurrencyUnit.getAvailableCurrencyUnits();
Collections.sort(currencies);
combo = new ComboViewer(container);
combo.setContentProvider(ArrayContentProvider.getInstance());
combo.setInput(currencies);
combo.setSelection(new StructuredSelection(CurrencyUnit.getInstance(CurrencyUnit.EUR)));
combo.setSelection(new StructuredSelection(CurrencyUnit.getDefaultInstance()));

Label description = new Label(container, SWT.WRAP);
description.setText(this.explanationIndividualCurrency);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import java.util.Enumeration;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.MissingResourceException;
import java.util.NavigableMap;
Expand Down Expand Up @@ -73,6 +74,15 @@ public static CurrencyUnit getInstance(String currencyCode)
return CACHE.get(currencyCode);
}

public static CurrencyUnit getDefaultInstance()
{
String defaultCurrencyISO4217 = java.util.Currency.getInstance(Locale.getDefault()).getCurrencyCode();
CurrencyUnit defaultCurrencyUnit = CurrencyUnit.getInstance(defaultCurrencyISO4217);
if (defaultCurrencyUnit != null)
{ return defaultCurrencyUnit; }
return CurrencyUnit.getInstance(EUR);
}

public static CurrencyUnit getInstanceBySymbol(String currencySymbol)
{
if (currencySymbol == null)
Expand Down

0 comments on commit e404ebd

Please sign in to comment.