private static void collectAccountTransactions( Client client, Date start, Date end, List<Transaction> transactions) { for (Account account : client.getAccounts()) { for (AccountTransaction t : account.getTransactions()) { if (t.getDate().getTime() > start.getTime() && t.getDate().getTime() <= end.getTime()) { switch (t.getType()) { case DEPOSIT: case REMOVAL: case TRANSFER_IN: case TRANSFER_OUT: transactions.add(t); break; case BUY: case SELL: case FEES: case TAXES: case DIVIDENDS: case INTEREST: case TAX_REFUND: break; default: throw new UnsupportedOperationException(); } } } } }
public static SecurityPerformanceSnapshot create( Client client, CurrencyConverter converter, ReportingPeriod period) { Map<Security, SecurityPerformanceRecord> transactions = initRecords(client); for (Account account : client.getAccounts()) extractSecurityRelatedAccountTransactions(account, period, transactions); for (Portfolio portfolio : client.getPortfolios()) { extractSecurityRelatedPortfolioTransactions(portfolio, period, transactions); addPseudoValuationTansactions(portfolio, converter, period, transactions); } return doCreateSnapshot(client, converter, transactions, period); }
@Override public boolean performFinish() { Object exportItem = exportPage.getExportItem(); Class<?> exportClass = exportPage.getExportClass(); File file = getFile(exportItem); try { // account transactions if (exportItem == AccountTransaction.class) { new CSVExporter().exportAccountTransactions(file, client.getAccounts()); } else if (exportClass == AccountTransaction.class) { new CSVExporter().exportAccountTransactions(file, (Account) exportItem); } // portfolio transactions else if (exportItem == PortfolioTransaction.class) { new CSVExporter().exportPortfolioTransactions(file, client.getPortfolios()); } else if (exportClass == PortfolioTransaction.class) { new CSVExporter().exportPortfolioTransactions(file, (Portfolio) exportItem); } // master data else if (exportItem == Security.class) { new CSVExporter() .exportSecurityMasterData( new File(file, Messages.ExportWizardSecurityMasterData + ".csv"), client.getSecurities()); // $NON-NLS-1$ } else if (exportClass == Security.class) { if (Messages.ExportWizardSecurityMasterData.equals(exportItem)) new CSVExporter().exportSecurityMasterData(file, client.getSecurities()); else if (Messages.ExportWizardMergedSecurityPrices.equals(exportItem)) new CSVExporter().exportMergedSecurityPrices(file, client.getSecurities()); } // historical quotes else if (exportItem == SecurityPrice.class) { new CSVExporter().exportSecurityPrices(file, client.getSecurities()); } else if (exportClass == SecurityPrice.class) { new CSVExporter().exportSecurityPrices(file, (Security) exportItem); } else { throw new UnsupportedOperationException( MessageFormat.format(Messages.ExportWizardUnsupportedExport, exportClass, exportItem)); } } catch (IOException e) { PortfolioPlugin.log(e); MessageDialog.openError(getShell(), Messages.ExportWizardErrorExporting, e.getMessage()); } return true; }
public static ClientSnapshot create(Client client, Date time) { ClientSnapshot snapshot = new ClientSnapshot(client, time); for (Account account : client.getAccounts()) snapshot.accounts.add(AccountSnapshot.create(account, time)); for (Portfolio portfolio : client.getPortfolios()) snapshot.portfolios.add(PortfolioSnapshot.create(portfolio, time)); if (snapshot.portfolios.isEmpty()) snapshot.jointPortfolio = PortfolioSnapshot.create(new Portfolio(), time); else if (snapshot.portfolios.size() == 1) snapshot.jointPortfolio = snapshot.portfolios.get(0); else snapshot.jointPortfolio = PortfolioSnapshot.merge(snapshot.portfolios); return snapshot; }
@Override public void createControl(Composite parent) { Composite container = new Composite(parent, SWT.NULL); setControl(container); GridLayoutFactory.fillDefaults().numColumns(3).applyTo(container); Label lblAcc = new Label(container, SWT.NULL); lblAcc.setText(Messages.ColumnAccount); GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).applyTo(lblAcc); final Text accountName = new Text(container, SWT.BORDER | SWT.SINGLE); GridDataFactory.fillDefaults() .grab(true, false) .align(SWT.FILL, SWT.CENTER) .applyTo(accountName); Button button = new Button(container, SWT.PUSH); button.setText(Messages.NewFileWizardButtonAdd); GridDataFactory.fillDefaults().applyTo(button); Composite tableContainer = new Composite(container, SWT.NONE); GridDataFactory.fillDefaults().span(3, 1).grab(true, true).applyTo(tableContainer); TableColumnLayout layout = new TableColumnLayout(); tableContainer.setLayout(layout); tViewer = new TableViewer(tableContainer); button.addSelectionListener( new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { String acnName = accountName.getText(); if (acnName.length() > 0) { Account currentAccount = new Account(); currentAccount.setName(acnName); client.addAccount(currentAccount); tViewer.refresh(); accountName.setText(""); // $NON-NLS-1$ accountName.setFocus(); } } }); Table table = tViewer.getTable(); table.setHeaderVisible(true); table.setEnabled(false); tViewer.setContentProvider(ArrayContentProvider.getInstance()); tViewer.setInput(client.getAccounts()); TableViewerColumn aCol = new TableViewerColumn(tViewer, SWT.NONE); layout.setColumnData(aCol.getColumn(), new ColumnWeightData(50)); aCol.getColumn().setText(Messages.ColumnAccount); aCol.setLabelProvider( new ColumnLabelProvider() { @Override public String getText(Object element) { return ((Account) element).getName(); } @Override public Image getImage(Object element) { return PortfolioPlugin.image(PortfolioPlugin.IMG_ACCOUNT); } }); container.pack(); setPageComplete(true); }