ColumnEditingSupport.prepare(assets);
support = new ShowHideColumnHelper(StatementOfAssetsViewer.class.getName(), client, owner.getPreferenceStore(),
assets, layout);
Column column = new Column("0", Messages.ColumnSharesOwned, SWT.RIGHT, 80); //$NON-NLS-1$
column.setLabelProvider(new SharesLabelProvider()
{
@Override
public Long getValue(Object e)
{
Element element = (Element) e;
return element.isSecurity() ? element.getSecurityPosition().getShares() : null;
}
@Override
public String getToolTipText(Object e)
{
Element element = (Element) e;
return element.isSecurity() ? Values.Share.format(element.getSecurityPosition().getShares()) : null;
}
});
support.addColumn(column);
column = new NameColumn("1"); //$NON-NLS-1$
column.setLabelProvider(new NameColumnLabelProvider()
{
@Override
public String getText(Object e)
{
if (((Element) e).isGroupByTaxonomy())
return Messages.LabelTotalSum;
return super.getText(e);
}
@Override
public Font getFont(Object e)
{
return ((Element) e).isGroupByTaxonomy() || ((Element) e).isCategory() ? boldFont : null;
}
@Override
public Image getImage(Object e)
{
if (((Element) e).isCategory())
return null;
return super.getImage(e);
}
});
column.setEditingSupport(new StringEditingSupport(Named.class, "name") //$NON-NLS-1$
{
@Override
public boolean canEdit(Object element)
{
boolean isCategory = ((Element) element).isCategory();
boolean isUnassignedCategory = isCategory
&& Classification.UNASSIGNED_ID.equals(((Element) element).getCategory()
.getClassification().getId());
return !isUnassignedCategory ? super.canEdit(element) : false;
}
}.setMandatory(true).addListener(new MarkDirtyListener(this.owner)));
column.setSorter(null);
support.addColumn(column);
column = new Column("2", Messages.ColumnTicker, SWT.None, 60); //$NON-NLS-1$
column.setLabelProvider(new ColumnLabelProvider()
{
@Override
public String getText(Object e)
{
Element element = (Element) e;
return element.isSecurity() ? element.getSecurity().getTickerSymbol() : null;
}
});
support.addColumn(column);
column = new Column("12", Messages.ColumnWKN, SWT.None, 60); //$NON-NLS-1$
column.setLabelProvider(new ColumnLabelProvider()
{
@Override
public String getText(Object e)
{
Element element = (Element) e;
return element.isSecurity() ? element.getSecurity().getWkn() : null;
}
});
column.setVisible(false);
support.addColumn(column);
column = new IsinColumn("3"); //$NON-NLS-1$
column.getEditingSupport().addListener(new MarkDirtyListener(this.owner));
column.setSorter(null);
column.setVisible(false);
support.addColumn(column);
column = new Column("4", Messages.ColumnQuote, SWT.RIGHT, 60); //$NON-NLS-1$
column.setLabelProvider(new ColumnLabelProvider()
{
@Override
public String getText(Object e)
{
Element element = (Element) e;
return element.isSecurity() ? Values.Quote.format(element.getSecurityPosition().getPrice().getValue())
: null;
}
});
support.addColumn(column);
column = new Column("5", Messages.ColumnMarketValue, SWT.RIGHT, 80); //$NON-NLS-1$
column.setLabelProvider(new ColumnLabelProvider()
{
@Override
public String getText(Object e)
{
Element element = (Element) e;
return Values.Amount.format(element.getValuation());
}
@Override
public Font getFont(Object e)
{
return ((Element) e).isGroupByTaxonomy() || ((Element) e).isCategory() ? boldFont : null;
}
});
support.addColumn(column);
column = new Column("6", Messages.ColumnShareInPercent, SWT.RIGHT, 80); //$NON-NLS-1$
column.setLabelProvider(new ColumnLabelProvider()
{
@Override
public String getText(Object e)
{
Element element = (Element) e;
if (element.isGroupByTaxonomy())
return Values.Percent.format(1d);
if (element.isCategory())
return Values.Percent.format(element.getCategory().getShare());
else
return Values.Percent.format(element.getPosition().getShare());
}
@Override
public Font getFont(Object e)
{
return ((Element) e).isGroupByTaxonomy() || ((Element) e).isCategory() ? boldFont : null;
}
});
support.addColumn(column);
column = new Column("7", Messages.ColumnPurchasePrice, SWT.RIGHT, 60); //$NON-NLS-1$
column.setLabelProvider(new ColumnLabelProvider()
{
@Override
public String getText(Object e)
{
Element element = (Element) e;
if (element.isSecurity())
{
long purchasePrice = element.getSecurityPosition().getFIFOPurchasePrice();
return purchasePrice == 0 ? null : Values.Amount.format(purchasePrice);
}
return null;
}
});
column.setVisible(false);
support.addColumn(column);
column = new Column("8", Messages.ColumnPurchaseValue, SWT.RIGHT, 80); //$NON-NLS-1$
column.setLabelProvider(new ColumnLabelProvider()
{
@Override
public String getText(Object e)
{
Element element = (Element) e;
long purchaseValue = element.getFIFOPurchaseValue();
return purchaseValue == 0 ? null : Values.Amount.format(purchaseValue);
}
@Override
public Font getFont(Object e)
{
return ((Element) e).isGroupByTaxonomy() || ((Element) e).isCategory() ? boldFont : null;
}
});
column.setVisible(false);
support.addColumn(column);
column = new Column("9", Messages.ColumnProfitLoss, SWT.RIGHT, 80); //$NON-NLS-1$
column.setLabelProvider(new ColumnLabelProvider()
{
@Override
public String getText(Object e)
{
Element element = (Element) e;
long profitLoss = element.getProfitLoss();
return profitLoss == 0 ? null : Values.Amount.format(profitLoss);
}
@Override
public Color getForeground(Object e)
{
Element element = (Element) e;
long profitLoss = element.getProfitLoss();
if (profitLoss < 0)
return Display.getCurrent().getSystemColor(SWT.COLOR_DARK_RED);
else if (profitLoss > 0)
return Display.getCurrent().getSystemColor(SWT.COLOR_DARK_GREEN);
else
return null;
}
@Override
public Font getFont(Object e)
{
return ((Element) e).isGroupByTaxonomy() || ((Element) e).isCategory() ? boldFont : null;
}
});
column.setVisible(false);
support.addColumn(column);
column = new NoteColumn();
column.getEditingSupport().addListener(new MarkDirtyListener(this.owner));
column.setSorter(null);
support.addColumn(column);
column = new Column("10", Messages.ColumnIRRPerformance, SWT.RIGHT, 80); //$NON-NLS-1$
column.setOptions(Messages.LabelReportingYears, Messages.ColumnIRRPerformanceOption, 1, 2, 3, 4, 5, 10);
column.setLabelProvider(new OptionLabelProvider()
{
@Override
public String getText(Object e, Integer option)
{
Element element = (Element) e;
if (element.isSecurity())
{
calculatePerformance(element, option);
SecurityPerformanceRecord record = element.getPerformance(option);
return Values.Percent.format(record.getIrr());
}
return null;
}
@Override
public Color getForeground(Object e, Integer option)
{
Element element = (Element) e;
if (element.isSecurity())
{
calculatePerformance(element, option);
SecurityPerformanceRecord record = element.getPerformance(option);
double irr = record.getIrr();
if (irr < 0)
return Display.getCurrent().getSystemColor(SWT.COLOR_DARK_RED);
else if (irr > 0)
return Display.getCurrent().getSystemColor(SWT.COLOR_DARK_GREEN);
}
return null;
}
});
column.setVisible(false);
support.addColumn(column);
column = new Column("11", Messages.ColumnTotalProfitLoss, SWT.RIGHT, 80); //$NON-NLS-1$
column.setOptions(Messages.LabelReportingYears, Messages.ColumnTotalProfitLossOption, 1, 2, 3, 4, 5, 10);
column.setLabelProvider(new OptionLabelProvider()
{
@Override
public String getText(Object e, Integer option)
{
Element element = (Element) e;
if (element.isSecurity())
{
calculatePerformance(element, option);
SecurityPerformanceRecord record = element.getPerformance(option);
return Values.Amount.format(record.getDelta());
}
return null;
}
@Override
public Color getForeground(Object e, Integer option)
{
Element element = (Element) e;
if (element.isSecurity())
{
calculatePerformance(element, option);
SecurityPerformanceRecord record = element.getPerformance(option);
long delta = record.getDelta();
if (delta < 0)
return Display.getCurrent().getSystemColor(SWT.COLOR_DARK_RED);
else if (delta > 0)
return Display.getCurrent().getSystemColor(SWT.COLOR_DARK_GREEN);
}
return null;
}
});
column.setVisible(false);
support.addColumn(column);
addTaxonomyColumns();
addAttributeColumns();