private void preselectDropDowns() { // idea: generally one type of document (i.e. from the same bank) will // be imported into the same account List<Account> activeAccounts = client.getActiveAccounts(); if (!activeAccounts.isEmpty()) { String uuid = preferences.getString(IMPORT_TARGET_ACCOUNT + extractor.getClass().getSimpleName()); // do not trigger selection listener (-> do not user #setSelection) primaryAccount .getCombo() .select( IntStream.range(0, activeAccounts.size()) .filter(i -> activeAccounts.get(i).getUUID().equals(uuid)) .findAny() .orElse(0)); secondaryAccount.getCombo().select(0); } List<Portfolio> activePortfolios = client.getActivePortfolios(); if (!activePortfolios.isEmpty()) { String uuid = preferences.getString(IMPORT_TARGET_PORTFOLIO + extractor.getClass().getSimpleName()); // do not trigger selection listener (-> do not user #setSelection) primaryPortfolio .getCombo() .select( IntStream.range(0, activePortfolios.size()) .filter(i -> activePortfolios.get(i).getUUID().equals(uuid)) .findAny() .orElse(0)); secondaryPortfolio.getCombo().select(0); } }
@Override public void createControl(Composite parent) { Composite container = new Composite(parent, SWT.NULL); setControl(container); container.setLayout(new FormLayout()); Composite targetContainer = new Composite(container, SWT.NONE); GridLayoutFactory.fillDefaults().numColumns(4).applyTo(targetContainer); lblPrimaryAccount = new Label(targetContainer, SWT.NONE); lblPrimaryAccount.setText(Messages.ColumnAccount); Combo cmbAccount = new Combo(targetContainer, SWT.READ_ONLY); primaryAccount = new ComboViewer(cmbAccount); primaryAccount.setContentProvider(ArrayContentProvider.getInstance()); primaryAccount.setInput(client.getActiveAccounts()); primaryAccount.addSelectionChangedListener(e -> checkEntriesAndRefresh(allEntries)); lblSecondaryAccount = new Label(targetContainer, SWT.NONE); lblSecondaryAccount.setText(Messages.LabelTransferTo); lblSecondaryAccount.setVisible(false); Combo cmbAccountTarget = new Combo(targetContainer, SWT.READ_ONLY); secondaryAccount = new ComboViewer(cmbAccountTarget); secondaryAccount.setContentProvider(ArrayContentProvider.getInstance()); secondaryAccount.setInput(client.getActiveAccounts()); secondaryAccount.getControl().setVisible(false); lblPrimaryPortfolio = new Label(targetContainer, SWT.NONE); lblPrimaryPortfolio.setText(Messages.ColumnPortfolio); Combo cmbPortfolio = new Combo(targetContainer, SWT.READ_ONLY); primaryPortfolio = new ComboViewer(cmbPortfolio); primaryPortfolio.setContentProvider(ArrayContentProvider.getInstance()); primaryPortfolio.setInput(client.getActivePortfolios()); primaryPortfolio.addSelectionChangedListener(e -> checkEntriesAndRefresh(allEntries)); lblSecondaryPortfolio = new Label(targetContainer, SWT.NONE); lblSecondaryPortfolio.setText(Messages.LabelTransferTo); lblSecondaryPortfolio.setVisible(false); Combo cmbPortfolioTarget = new Combo(targetContainer, SWT.READ_ONLY); secondaryPortfolio = new ComboViewer(cmbPortfolioTarget); secondaryPortfolio.setContentProvider(ArrayContentProvider.getInstance()); secondaryPortfolio.setInput(client.getActivePortfolios()); secondaryPortfolio.getControl().setVisible(false); preselectDropDowns(); cbConvertToDelivery = new Button(container, SWT.CHECK); cbConvertToDelivery.setText(Messages.LabelConvertBuySellIntoDeliveryTransactions); Composite compositeTable = new Composite(container, SWT.NONE); Composite errorTable = new Composite(container, SWT.NONE); // // form layout // FormDataFactory.startingWith(targetContainer) // .top(new FormAttachment(0, 0)) .left(new FormAttachment(0, 0)) .right(new FormAttachment(100, 0)) .thenBelow(cbConvertToDelivery) // .thenBelow(compositeTable) .right(targetContainer) .bottom(new FormAttachment(70, 0)) // .thenBelow(errorTable) .right(targetContainer) .bottom(new FormAttachment(100, 0)); // // table & columns // TableColumnLayout layout = new TableColumnLayout(); compositeTable.setLayout(layout); tableViewer = new TableViewer(compositeTable, SWT.BORDER | SWT.FULL_SELECTION | SWT.MULTI); tableViewer.setContentProvider(new SimpleListContentProvider()); Table table = tableViewer.getTable(); table.setHeaderVisible(true); table.setLinesVisible(true); addColumns(tableViewer, layout); attachContextMenu(table); layout = new TableColumnLayout(); errorTable.setLayout(layout); errorTableViewer = new TableViewer(errorTable, SWT.BORDER | SWT.FULL_SELECTION | SWT.MULTI); errorTableViewer.setContentProvider(new SimpleListContentProvider()); table = errorTableViewer.getTable(); table.setHeaderVisible(true); table.setLinesVisible(true); addColumnsExceptionTable(errorTableViewer, layout); }