Skip to content

Commit

Permalink
Display offset account in lists of transactions
Browse files Browse the repository at this point in the history
Issue: #22
  • Loading branch information
buchen committed Mar 10, 2013
1 parent c38ec9d commit 0243fd2
Show file tree
Hide file tree
Showing 10 changed files with 130 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ public class Messages extends NLS
public static String ColumnMarketValue;
public static String ColumnMonth;
public static String ColumnName;
public static String ColumnOffsetAccount;
public static String ColumnPortfolio;
public static String ColumnPortfolioFrom;
public static String ColumnPortfolioTo;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,8 @@ ColumnMonth = Month

ColumnName = Name

ColumnOffsetAccount = Offset Account

ColumnPortfolio = Portfolio

ColumnPortfolioFrom = From
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,8 @@ ColumnMonth = Monat

ColumnName = Name

ColumnOffsetAccount = Gegenkonto

ColumnPortfolio = Portfolio

ColumnPortfolioFrom = Von
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public void setVisible(boolean isVisible)
{
this.isVisible = isVisible;
}

public void setMoveable(boolean isMoveable)
{
this.isMoveable = isMoveable;
Expand Down Expand Up @@ -162,7 +162,7 @@ String getOptionsMenuLabel()
{
return optionsMenuLabel;
}

private void create(TableViewer viewer, TableColumnLayout layout, Object option)
{
create(viewer, layout, option, defaultSortDirection, getDefaultWidth());
Expand Down Expand Up @@ -216,6 +216,7 @@ public void destroy(TableViewer viewer, Object option)

private String identifier;
private boolean isUserConfigured = false;
private boolean doSaveState = true;

private List<Column> columns = new ArrayList<Column>();

Expand All @@ -241,12 +242,18 @@ public void widgetDisposed(DisposeEvent e)

private void widgetDisposed()
{
persistColumnConfig();
if (doSaveState)
persistColumnConfig();

if (contextMenu != null)
contextMenu.dispose();
}

public void setDoSaveState(boolean doSaveState)
{
this.doSaveState = doSaveState;
}

public void showHideShowColumnsMenu(Shell shell)
{
if (contextMenu == null)
Expand Down Expand Up @@ -372,7 +379,8 @@ public void addColumn(Column column)

public void createColumns()
{
createFromColumnConfig();
if (doSaveState)
createFromColumnConfig();

if (viewer.getTable().getColumnCount() > 0)
{
Expand Down Expand Up @@ -402,21 +410,21 @@ private void createFromColumnConfig()
Matcher matcher = CONFIG_PATTERN.matcher(tokens.nextToken());
if (!matcher.matches())
continue;

// index
Column col = columns.get(Integer.parseInt(matcher.group(1)));

// option
String o = matcher.group(2);
Integer option = o != null ? Integer.parseInt(o) : null;

// direction
String d = matcher.group(3);
Integer direction = d != null ? Integer.parseInt(d) : null;

// width
int width = Integer.parseInt(matcher.group(4));

col.create(viewer, layout, option, direction, width);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ protected void createBottomTable(Composite parent)

ShowHideColumnHelper support = new ShowHideColumnHelper(AccountListView.class.getSimpleName() + "@bottom", //$NON-NLS-1$
transactions, layout);
support.setDoSaveState(false);

Column column = new Column(Messages.ColumnDate, SWT.None, 80);
column.setLabelProvider(new ColumnLabelProvider()
Expand Down Expand Up @@ -293,6 +294,25 @@ public Color getForeground(Object element)
column.setMoveable(false);
support.addColumn(column);

column = new Column(Messages.ColumnOffsetAccount, SWT.None, 120);
column.setLabelProvider(new ColumnLabelProvider()
{
@Override
public String getText(Object e)
{
AccountTransaction t = (AccountTransaction) e;
return t.getCrossEntry() != null ? t.getCrossEntry().getCrossEntity(t).toString() : null;
}

@Override
public Color getForeground(Object element)
{
return colorFor((AccountTransaction) element);
}
});
column.setMoveable(false);
support.addColumn(column);

support.createColumns();

transactions.getTable().setHeaderVisible(true);
Expand Down Expand Up @@ -321,6 +341,7 @@ public void onModified(Object element, String property)
.readonly("type") //$NON-NLS-1$
.amount("amount") //$NON-NLS-1$
.combobox("security", securities, true) //$NON-NLS-1$
.readonly("crossentry") //$NON-NLS-1$
.apply();

hookContextMenu(transactions.getTable(), new IMenuListener()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,7 @@ private Control createTransactionsTable(CTabFolder folder)

ShowHideColumnHelper support = new ShowHideColumnHelper(PortfolioListView.class.getSimpleName() + "@bottom", //$NON-NLS-1$
transactions, layout);
support.setDoSaveState(false);

Column column = new Column(Messages.ColumnDate, SWT.None, 80);
column.setLabelProvider(new ColumnLabelProvider()
Expand Down Expand Up @@ -392,6 +393,25 @@ public Color getForeground(Object element)
column.setMoveable(false);
support.addColumn(column);

column = new Column(Messages.ColumnOffsetAccount, SWT.None, 120);
column.setLabelProvider(new ColumnLabelProvider()
{
@Override
public String getText(Object e)
{
PortfolioTransaction t = (PortfolioTransaction) e;
return t.getCrossEntry() != null ? t.getCrossEntry().getCrossEntity(t).toString() : null;
}

@Override
public Color getForeground(Object element)
{
return colorFor((PortfolioTransaction) element);
}
});
column.setMoveable(false);
support.addColumn(column);

support.createColumns();

transactions.getTable().setHeaderVisible(true);
Expand Down Expand Up @@ -425,6 +445,7 @@ public void onModified(Object element, String property)
.shares("shares") // //$NON-NLS-1$
.amount("amount") // //$NON-NLS-1$
.amount("fees") // //$NON-NLS-1$
.readonly("crossentry") //$NON-NLS-1$
.apply();

hookContextMenu(transactions.getTable(), new IMenuListener()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,25 @@ else if (t == transactionTo)
}
}

@Override
public Transaction getCrossTransaction(Transaction t)
{
if (t.equals(transactionFrom))
return transactionTo;
else if (t.equals(transactionTo))
return transactionFrom;
else
throw new UnsupportedOperationException();
}

@Override
public Object getCrossEntity(Transaction t)
{
if (t.equals(transactionFrom))
return accountTo;
else if (t.equals(transactionTo))
return accountFrom;
else
throw new UnsupportedOperationException();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -92,4 +92,25 @@ else if (t == portfolioTransaction)
}
}

@Override
public Transaction getCrossTransaction(Transaction t)
{
if (t.equals(portfolioTransaction))
return accountTransaction;
else if (t.equals(accountTransaction))
return portfolioTransaction;
else
throw new UnsupportedOperationException();
}

@Override
public Object getCrossEntity(Transaction t)
{
if (t.equals(portfolioTransaction))
return account;
else if (t.equals(accountTransaction))
return portfolio;
else
throw new UnsupportedOperationException();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,8 @@ public interface CrossEntry
public void updateFrom(Transaction t);

public void delete();

public Transaction getCrossTransaction(Transaction t);

public Object getCrossEntity(Transaction t);
}
Original file line number Diff line number Diff line change
Expand Up @@ -87,4 +87,25 @@ else if (t.equals(transactionTo))
}
}

@Override
public Transaction getCrossTransaction(Transaction t)
{
if (t.equals(transactionFrom))
return transactionTo;
else if (t.equals(transactionTo))
return transactionFrom;
else
throw new UnsupportedOperationException();
}

@Override
public Object getCrossEntity(Transaction t)
{
if (t.equals(transactionFrom))
return portfolioTo;
else if (t.equals(transactionTo))
return portfolioFrom;
else
throw new UnsupportedOperationException();
}
}

0 comments on commit 0243fd2

Please sign in to comment.