Search in sources :

Example 36 with TableColumnLayout

use of org.eclipse.jface.layout.TableColumnLayout in project portfolio by buchen.

the class NewPortfolioAccountPage method createControl.

@Override
public void createControl(Composite parent) {
    Composite container = new Composite(parent, SWT.NULL);
    setControl(container);
    GridLayoutFactory.fillDefaults().numColumns(5).applyTo(container);
    Label lblPort = new Label(container, SWT.NULL);
    lblPort.setText(Messages.ColumnPortfolio);
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).applyTo(lblPort);
    final Text portfolioName = new Text(container, SWT.BORDER | SWT.SINGLE);
    GridDataFactory.fillDefaults().grab(true, false).align(SWT.FILL, SWT.CENTER).applyTo(portfolioName);
    Label lblAcc = new Label(container, SWT.NULL);
    lblAcc.setText(Messages.ColumnReferenceAccount);
    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);
    final List<Pair> data = new ArrayList<Pair>();
    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(5, 1).grab(true, true).applyTo(tableContainer);
    TableColumnLayout layout = new TableColumnLayout();
    tableContainer.setLayout(layout);
    final TableViewer tViewer = new TableViewer(tableContainer);
    button.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            String portName = portfolioName.getText();
            String acnName = accountName.getText();
            if (portName.length() > 0 && acnName.length() > 0) {
                Account account = new Account();
                account.setName(acnName);
                account.setCurrencyCode(client.getBaseCurrency());
                Portfolio portfolio = new Portfolio();
                portfolio.setName(portName);
                portfolio.setReferenceAccount(account);
                client.addAccount(account);
                client.addPortfolio(portfolio);
                data.add(new Pair(portName, acnName));
                tViewer.refresh();
                // delete previous input
                // $NON-NLS-1$
                accountName.setText("");
                // $NON-NLS-1$
                portfolioName.setText("");
                // focus first input field
                portfolioName.setFocus();
                setPageComplete(true);
            }
        }
    });
    Table table = tViewer.getTable();
    table.setEnabled(false);
    table.setHeaderVisible(true);
    table.setLinesVisible(false);
    tViewer.setContentProvider(ArrayContentProvider.getInstance());
    tViewer.setInput(data);
    TableViewerColumn pCol = new TableViewerColumn(tViewer, SWT.NONE);
    layout.setColumnData(pCol.getColumn(), new ColumnWeightData(50));
    pCol.getColumn().setText(Messages.ColumnPortfolio);
    pCol.setLabelProvider(new ColumnLabelProvider() {

        @Override
        public String getText(Object element) {
            return ((Pair) element).portfolio;
        }

        @Override
        public Image getImage(Object element) {
            return Images.PORTFOLIO.image();
        }
    });
    TableViewerColumn aCol = new TableViewerColumn(tViewer, SWT.NONE);
    layout.setColumnData(aCol.getColumn(), new ColumnWeightData(50));
    aCol.getColumn().setText(Messages.ColumnReferenceAccount);
    aCol.setLabelProvider(new ColumnLabelProvider() {

        @Override
        public String getText(Object element) {
            return ((Pair) element).account;
        }

        @Override
        public Image getImage(Object element) {
            return Images.ACCOUNT.image();
        }
    });
    container.pack();
    setPageComplete(false);
}
Also used : ColumnWeightData(org.eclipse.jface.viewers.ColumnWeightData) Account(name.abuchen.portfolio.model.Account) Table(org.eclipse.swt.widgets.Table) Composite(org.eclipse.swt.widgets.Composite) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) Portfolio(name.abuchen.portfolio.model.Portfolio) Label(org.eclipse.swt.widgets.Label) ArrayList(java.util.ArrayList) Text(org.eclipse.swt.widgets.Text) Image(org.eclipse.swt.graphics.Image) ColumnLabelProvider(org.eclipse.jface.viewers.ColumnLabelProvider) TableColumnLayout(org.eclipse.jface.layout.TableColumnLayout) Button(org.eclipse.swt.widgets.Button) SelectionEvent(org.eclipse.swt.events.SelectionEvent) TableViewer(org.eclipse.jface.viewers.TableViewer) TableViewerColumn(org.eclipse.jface.viewers.TableViewerColumn)

Example 37 with TableColumnLayout

use of org.eclipse.jface.layout.TableColumnLayout in project portfolio by buchen.

the class CSVImportDefinitionPage method createControl.

@Override
public void createControl(Composite parent) {
    Composite container = new Composite(parent, SWT.NULL);
    setControl(container);
    container.setLayout(new FormLayout());
    Label lblTarget = new Label(container, SWT.RIGHT);
    lblTarget.setText(Messages.CSVImportLabelTarget);
    Combo cmbTarget = new Combo(container, SWT.READ_ONLY);
    ComboViewer target = new ComboViewer(cmbTarget);
    target.setContentProvider(ArrayContentProvider.getInstance());
    target.setLabelProvider(new LabelProvider() {

        @Override
        public String getText(Object element) {
            return ((Extractor) element).getLabel();
        }
    });
    target.getCombo().setEnabled(!onlySecurityPrices);
    target.addSelectionChangedListener(this);
    Label lblDelimiter = new Label(container, SWT.NONE);
    lblDelimiter.setText(Messages.CSVImportLabelDelimiter);
    Combo cmbDelimiter = new Combo(container, SWT.READ_ONLY);
    ComboViewer delimiter = new ComboViewer(cmbDelimiter);
    delimiter.setContentProvider(ArrayContentProvider.getInstance());
    delimiter.setInput(new Delimiter[] { // 
    new Delimiter(',', Messages.CSVImportSeparatorComma), // 
    new Delimiter(';', Messages.CSVImportSeparatorSemicolon), new Delimiter('\t', Messages.CSVImportSeparatorTab) });
    cmbDelimiter.select(1);
    delimiter.addSelectionChangedListener(this);
    Label lblSkipLines = new Label(container, SWT.NONE);
    lblSkipLines.setText(Messages.CSVImportLabelSkipLines);
    final Spinner skipLines = new Spinner(container, SWT.BORDER);
    skipLines.setMinimum(0);
    skipLines.addModifyListener(event -> onSkipLinesChanged(skipLines.getSelection()));
    Label lblEncoding = new Label(container, SWT.NONE);
    lblEncoding.setText(Messages.CSVImportLabelEncoding);
    Combo cmbEncoding = new Combo(container, SWT.READ_ONLY);
    ComboViewer encoding = new ComboViewer(cmbEncoding);
    encoding.setContentProvider(ArrayContentProvider.getInstance());
    encoding.setInput(Charset.availableCharsets().values().toArray());
    encoding.setSelection(new StructuredSelection(Charset.defaultCharset()));
    encoding.addSelectionChangedListener(this);
    final Button firstLineIsHeader = new Button(container, SWT.CHECK);
    firstLineIsHeader.setText(Messages.CSVImportLabelFirstLineIsHeader);
    firstLineIsHeader.setSelection(true);
    firstLineIsHeader.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent event) {
            onFirstLineIsHeaderChanged(firstLineIsHeader.getSelection());
        }
    });
    Composite compositeTable = new Composite(container, SWT.NONE);
    // 
    // form layout
    // 
    int width = widest(lblTarget, lblDelimiter, lblEncoding);
    FormDataFactory.startingWith(lblTarget).width(width).top(new FormAttachment(0, 5)).thenRight(cmbTarget).right(new FormAttachment(50, -5)).thenBelow(cmbDelimiter).label(lblDelimiter).right(new FormAttachment(50, -5)).thenBelow(cmbEncoding).label(lblEncoding).right(new FormAttachment(50, -5));
    FormDataFactory.startingWith(cmbDelimiter).thenRight(lblSkipLines).suffix(skipLines);
    FormDataFactory.startingWith(cmbEncoding).thenRight(firstLineIsHeader);
    FormData data = new FormData();
    data.top = new FormAttachment(cmbEncoding, 10);
    data.left = new FormAttachment(0, 0);
    data.right = new FormAttachment(100, 0);
    data.bottom = new FormAttachment(100, 0);
    data.width = 100;
    data.height = 100;
    compositeTable.setLayoutData(data);
    // 
    // table & columns
    // 
    TableColumnLayout layout = new TableColumnLayout();
    compositeTable.setLayout(layout);
    tableViewer = new TableViewer(compositeTable, SWT.BORDER | SWT.FULL_SELECTION);
    final Table table = tableViewer.getTable();
    table.setHeaderVisible(true);
    table.setLinesVisible(true);
    tableViewer.setLabelProvider(new ImportLabelProvider(importer));
    tableViewer.setContentProvider(ArrayContentProvider.getInstance());
    table.addMouseListener(new MouseListener() {

        @Override
        public // NOSONAR
        void mouseUp(// NOSONAR
        MouseEvent e) {
        }

        @Override
        public // NOSONAR
        void mouseDown(// NOSONAR
        MouseEvent e) {
        }

        @Override
        public void mouseDoubleClick(MouseEvent e) {
            TableItem item = table.getItem(0);
            if (item == null)
                return;
            int columnIndex = -1;
            for (int ii = 0; ii < table.getColumnCount(); ii++) {
                Rectangle bounds = item.getBounds(ii);
                int width = table.getColumn(ii).getWidth();
                if (e.x >= bounds.x && e.x <= bounds.x + width)
                    columnIndex = ii;
            }
            if (columnIndex >= 0)
                onColumnSelected(columnIndex);
        }
    });
    // 
    // setup form elements
    // 
    target.setInput(importer.getExtractors());
    target.getCombo().select(importer.getExtractors().indexOf(importer.getExtractor()));
    doProcessFile();
}
Also used : Spinner(org.eclipse.swt.widgets.Spinner) TableItem(org.eclipse.swt.widgets.TableItem) Label(org.eclipse.swt.widgets.Label) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) Rectangle(org.eclipse.swt.graphics.Rectangle) Combo(org.eclipse.swt.widgets.Combo) MouseListener(org.eclipse.swt.events.MouseListener) TableColumnLayout(org.eclipse.jface.layout.TableColumnLayout) Button(org.eclipse.swt.widgets.Button) SelectionEvent(org.eclipse.swt.events.SelectionEvent) FormAttachment(org.eclipse.swt.layout.FormAttachment) FormLayout(org.eclipse.swt.layout.FormLayout) FormData(org.eclipse.swt.layout.FormData) Table(org.eclipse.swt.widgets.Table) MouseEvent(org.eclipse.swt.events.MouseEvent) Composite(org.eclipse.swt.widgets.Composite) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) ComboViewer(org.eclipse.jface.viewers.ComboViewer) ITableLabelProvider(org.eclipse.jface.viewers.ITableLabelProvider) ColumnLabelProvider(org.eclipse.jface.viewers.ColumnLabelProvider) LabelProvider(org.eclipse.jface.viewers.LabelProvider) TableViewer(org.eclipse.jface.viewers.TableViewer)

Example 38 with TableColumnLayout

use of org.eclipse.jface.layout.TableColumnLayout in project portfolio by buchen.

the class TransactionsTab method createControl.

@Override
public Control createControl(Composite parent) {
    Composite container = new Composite(parent, SWT.NONE);
    TableColumnLayout layout = new TableColumnLayout();
    container.setLayout(layout);
    tableViewer = new TableViewer(container, SWT.FULL_SELECTION | SWT.MULTI);
    ColumnViewerToolTipSupport.enableFor(tableViewer, ToolTip.NO_RECREATE);
    ShowHideColumnHelper support = new // $NON-NLS-1$
    ShowHideColumnHelper(// $NON-NLS-1$
    TransactionsTab.class.getSimpleName() + "@v2", preferences, tableViewer, layout);
    addColumns(support);
    support.createColumns();
    tableViewer.getTable().setHeaderVisible(true);
    tableViewer.getTable().setLinesVisible(true);
    tableViewer.setContentProvider(ArrayContentProvider.getInstance());
    tableViewer.addSelectionChangedListener(event -> {
        TransactionPair<?> tx = ((TransactionPair<?>) ((IStructuredSelection) event.getSelection()).getFirstElement());
        if (tx != null && tx.getTransaction().getSecurity() != null)
            selectionService.setSelection(new SecuritySelection(model.getClient(), tx.getTransaction().getSecurity()));
    });
    tableViewer.setInput(model.getTransactions());
    model.addUpdateListener(() -> tableViewer.setInput(model.getTransactions()));
    return container;
}
Also used : SecuritySelection(name.abuchen.portfolio.ui.selection.SecuritySelection) Composite(org.eclipse.swt.widgets.Composite) TableColumnLayout(org.eclipse.jface.layout.TableColumnLayout) ShowHideColumnHelper(name.abuchen.portfolio.ui.util.viewers.ShowHideColumnHelper) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) TableViewer(org.eclipse.jface.viewers.TableViewer)

Example 39 with TableColumnLayout

use of org.eclipse.jface.layout.TableColumnLayout in project portfolio by buchen.

the class BookmarksListTab method createTab.

@Override
public CTabItem createTab(CTabFolder folder) {
    Composite container = new Composite(folder, SWT.NONE);
    TableColumnLayout layout = new TableColumnLayout();
    container.setLayout(layout);
    bookmarks = new TableViewer(container, SWT.FULL_SELECTION | SWT.MULTI);
    ColumnEditingSupport.prepare(bookmarks);
    ShowHideColumnHelper support = new // $NON-NLS-1$
    ShowHideColumnHelper(// $NON-NLS-1$
    BookmarksListTab.class.getSimpleName() + "@bottom", preferences, bookmarks, layout);
    // Create Column for Bookmark
    Column column = new Column(Messages.BookmarksListView_bookmark, SWT.None, 150);
    column.setLabelProvider(new ColumnLabelProvider() {

        @Override
        public String getText(Object element) {
            return ((Bookmark) element).getLabel();
        }

        @Override
        public Image getImage(Object element) {
            return Images.TEXT.image();
        }
    });
    // $NON-NLS-1$
    new StringEditingSupport(Bookmark.class, "label").addListener(this).attachTo(column);
    support.addColumn(column);
    // Create Column for URL
    column = new Column(Messages.BookmarksListView_url, SWT.None, 500);
    column.setLabelProvider(new ColumnLabelProvider() {

        @Override
        public String getText(Object element) {
            return ((Bookmark) element).getPattern();
        }
    });
    // $NON-NLS-1$
    new StringEditingSupport(Bookmark.class, "pattern").addListener(this).attachTo(column);
    support.addColumn(column);
    support.createColumns();
    bookmarks.getTable().setHeaderVisible(true);
    bookmarks.getTable().setLinesVisible(true);
    bookmarks.setContentProvider(ArrayContentProvider.getInstance());
    bookmarks.setInput(client.getSettings().getBookmarks());
    bookmarks.refresh();
    new ContextMenu(bookmarks.getTable(), this::fillContextMenu).hook();
    CTabItem item = new CTabItem(folder, SWT.NONE);
    item.setText(Messages.BookmarksListView_title);
    item.setControl(container);
    return item;
}
Also used : Composite(org.eclipse.swt.widgets.Composite) ContextMenu(name.abuchen.portfolio.ui.util.ContextMenu) StringEditingSupport(name.abuchen.portfolio.ui.util.viewers.StringEditingSupport) Image(org.eclipse.swt.graphics.Image) CTabItem(org.eclipse.swt.custom.CTabItem) ColumnLabelProvider(org.eclipse.jface.viewers.ColumnLabelProvider) TableColumnLayout(org.eclipse.jface.layout.TableColumnLayout) ShowHideColumnHelper(name.abuchen.portfolio.ui.util.viewers.ShowHideColumnHelper) Column(name.abuchen.portfolio.ui.util.viewers.Column) TableViewer(org.eclipse.jface.viewers.TableViewer)

Example 40 with TableColumnLayout

use of org.eclipse.jface.layout.TableColumnLayout in project portfolio by buchen.

the class ReviewExtractedItemsPage method createControl.

@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);
    lblImportAssistantExtractor = new Label(targetContainer, SWT.NONE);
    lblImportAssistantExtractor.setText(Messages.PDFImportWizardExtractor);
    Combo cmbImportAssistantExtractor = new Combo(targetContainer, SWT.READ_ONLY);
    comboExtractors = new ComboViewer(cmbImportAssistantExtractor);
    comboExtractors.setLabelProvider(new LabelProvider() {

        @Override
        public String getText(Object element) {
            return ((Extractor) element).getLabel();
        }
    });
    comboExtractors.addSelectionChangedListener(e -> runExtractionJob());
    if (extractor instanceof AssistantPDFExtractor) {
        List<Extractor> extractors = ((AssistantPDFExtractor) extractor).getAvailableExtractors();
        comboExtractors.add(extractors.toArray());
    } else {
        lblImportAssistantExtractor.setVisible(false);
        comboExtractors.getCombo().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(80, 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(ArrayContentProvider.getInstance());
    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(ArrayContentProvider.getInstance());
    table = errorTableViewer.getTable();
    table.setHeaderVisible(true);
    table.setLinesVisible(true);
    addColumnsExceptionTable(errorTableViewer, layout);
}
Also used : FormLayout(org.eclipse.swt.layout.FormLayout) Table(org.eclipse.swt.widgets.Table) Composite(org.eclipse.swt.widgets.Composite) AssistantPDFExtractor(name.abuchen.portfolio.datatransfer.pdf.AssistantPDFExtractor) Label(org.eclipse.swt.widgets.Label) Combo(org.eclipse.swt.widgets.Combo) StyledString(org.eclipse.jface.viewers.StyledString) TableColumnLayout(org.eclipse.jface.layout.TableColumnLayout) ComboViewer(org.eclipse.jface.viewers.ComboViewer) Button(org.eclipse.swt.widgets.Button) Extractor(name.abuchen.portfolio.datatransfer.Extractor) AssistantPDFExtractor(name.abuchen.portfolio.datatransfer.pdf.AssistantPDFExtractor) ColumnLabelProvider(org.eclipse.jface.viewers.ColumnLabelProvider) StyledCellLabelProvider(org.eclipse.jface.viewers.StyledCellLabelProvider) LabelProvider(org.eclipse.jface.viewers.LabelProvider) TableViewer(org.eclipse.jface.viewers.TableViewer) FormAttachment(org.eclipse.swt.layout.FormAttachment)

Aggregations

TableColumnLayout (org.eclipse.jface.layout.TableColumnLayout)105 Composite (org.eclipse.swt.widgets.Composite)94 TableViewer (org.eclipse.jface.viewers.TableViewer)78 TableViewerColumn (org.eclipse.jface.viewers.TableViewerColumn)62 ColumnWeightData (org.eclipse.jface.viewers.ColumnWeightData)51 GridData (org.eclipse.swt.layout.GridData)46 ColumnLabelProvider (org.eclipse.jface.viewers.ColumnLabelProvider)44 Table (org.eclipse.swt.widgets.Table)38 GridLayout (org.eclipse.swt.layout.GridLayout)34 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)31 Image (org.eclipse.swt.graphics.Image)28 Label (org.eclipse.swt.widgets.Label)27 Viewer (org.eclipse.jface.viewers.Viewer)25 SelectionChangedEvent (org.eclipse.jface.viewers.SelectionChangedEvent)23 ISelectionChangedListener (org.eclipse.jface.viewers.ISelectionChangedListener)22 SelectionEvent (org.eclipse.swt.events.SelectionEvent)22 Button (org.eclipse.swt.widgets.Button)21 ViewerComparator (org.eclipse.jface.viewers.ViewerComparator)18 TableColumn (org.eclipse.swt.widgets.TableColumn)18 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)17