Search in sources :

Example 16 with ColumnPixelData

use of org.eclipse.jface.viewers.ColumnPixelData in project portfolio by buchen.

the class DividendsMatrixTab method createMonthColumn.

private void createMonthColumn(TableViewer records, TableColumnLayout layout, LocalDate start, int index) {
    TableViewerColumn column = new TableViewerColumn(records, SWT.RIGHT);
    column.getColumn().setText(formatter.format(start));
    column.setLabelProvider(new ColumnLabelProvider() {

        @Override
        public String getText(Object element) {
            Line line = (DividendsViewModel.Line) element;
            return line.getVehicle() != null ? Values.Amount.formatNonZero(line.getValue(index)) : Values.Amount.format(line.getValue(index));
        }

        @Override
        public String getToolTipText(Object element) {
            InvestmentVehicle vehicle = ((DividendsViewModel.Line) element).getVehicle();
            return TextUtil.tooltip(vehicle != null ? vehicle.getName() : null);
        }

        @Override
        public Font getFont(Object element) {
            InvestmentVehicle vehicle = ((DividendsViewModel.Line) element).getVehicle();
            return vehicle != null ? null : boldFont;
        }
    });
    layout.setColumnData(column.getColumn(), new ColumnPixelData(50));
}
Also used : Line(name.abuchen.portfolio.ui.views.dividends.DividendsViewModel.Line) ColumnLabelProvider(org.eclipse.jface.viewers.ColumnLabelProvider) InvestmentVehicle(name.abuchen.portfolio.model.InvestmentVehicle) ColumnPixelData(org.eclipse.jface.viewers.ColumnPixelData) TableViewerColumn(org.eclipse.jface.viewers.TableViewerColumn) Font(org.eclipse.swt.graphics.Font)

Example 17 with ColumnPixelData

use of org.eclipse.jface.viewers.ColumnPixelData in project portfolio by buchen.

the class DividendsMatrixTab method createSecurityColumn.

protected void createSecurityColumn(TableViewer records, TableColumnLayout layout, boolean isSorted) {
    TableViewerColumn column = new TableViewerColumn(records, SWT.NONE);
    column.getColumn().setText(Messages.ColumnSecurity);
    column.setLabelProvider(new ColumnLabelProvider() {

        @Override
        public Image getImage(Object element) {
            InvestmentVehicle vehicle = ((DividendsViewModel.Line) element).getVehicle();
            return vehicle != null ? Images.SECURITY.image() : null;
        }

        @Override
        public String getText(Object element) {
            InvestmentVehicle vehicle = ((DividendsViewModel.Line) element).getVehicle();
            return vehicle != null ? vehicle.getName() : Messages.ColumnSum;
        }

        @Override
        public Font getFont(Object element) {
            InvestmentVehicle vehicle = ((DividendsViewModel.Line) element).getVehicle();
            return vehicle != null ? null : boldFont;
        }
    });
    ColumnViewerSorter.create((o1, o2) -> {
        int direction = ColumnViewerSorter.SortingContext.getSortDirection();
        DividendsViewModel.Line line1 = (DividendsViewModel.Line) o1;
        DividendsViewModel.Line line2 = (DividendsViewModel.Line) o2;
        if (line1.getVehicle() == null)
            return direction == SWT.DOWN ? 1 : -1;
        if (line2.getVehicle() == null)
            return direction == SWT.DOWN ? -1 : 1;
        String n1 = line1.getVehicle().getName();
        String n2 = line2.getVehicle().getName();
        return n1.compareToIgnoreCase(n2);
    }).attachTo(records, column, isSorted);
    layout.setColumnData(column.getColumn(), new ColumnPixelData(200));
}
Also used : Values(name.abuchen.portfolio.money.Values) TableViewer(org.eclipse.jface.viewers.TableViewer) InvestmentVehicle(name.abuchen.portfolio.model.InvestmentVehicle) TableColumn(org.eclipse.swt.widgets.TableColumn) Images(name.abuchen.portfolio.ui.Images) Image(org.eclipse.swt.graphics.Image) JFaceResources(org.eclipse.jface.resource.JFaceResources) TableColumnLayout(org.eclipse.jface.layout.TableColumnLayout) ColumnPixelData(org.eclipse.jface.viewers.ColumnPixelData) MessageFormat(java.text.MessageFormat) Inject(javax.inject.Inject) TextUtil(name.abuchen.portfolio.util.TextUtil) ESelectionService(org.eclipse.e4.ui.workbench.modeling.ESelectionService) Composite(org.eclipse.swt.widgets.Composite) Messages(name.abuchen.portfolio.ui.Messages) ColumnViewerToolTipSupport(org.eclipse.jface.viewers.ColumnViewerToolTipSupport) Font(org.eclipse.swt.graphics.Font) FontDescriptor(org.eclipse.jface.resource.FontDescriptor) Month(java.time.Month) SimpleAction(name.abuchen.portfolio.ui.util.SimpleAction) ColumnViewerSorter(name.abuchen.portfolio.ui.util.viewers.ColumnViewerSorter) Action(org.eclipse.jface.action.Action) Security(name.abuchen.portfolio.model.Security) ArrayContentProvider(org.eclipse.jface.viewers.ArrayContentProvider) ColumnLabelProvider(org.eclipse.jface.viewers.ColumnLabelProvider) TableViewerColumn(org.eclipse.jface.viewers.TableViewerColumn) TableViewerCSVExporter(name.abuchen.portfolio.ui.util.TableViewerCSVExporter) IMenuManager(org.eclipse.jface.action.IMenuManager) LocalDate(java.time.LocalDate) DateTimeFormatter(java.time.format.DateTimeFormatter) SWT(org.eclipse.swt.SWT) ToolTip(org.eclipse.jface.window.ToolTip) SecuritySelection(name.abuchen.portfolio.ui.selection.SecuritySelection) LocalResourceManager(org.eclipse.jface.resource.LocalResourceManager) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) Control(org.eclipse.swt.widgets.Control) Line(name.abuchen.portfolio.ui.views.dividends.DividendsViewModel.Line) Line(name.abuchen.portfolio.ui.views.dividends.DividendsViewModel.Line) ColumnLabelProvider(org.eclipse.jface.viewers.ColumnLabelProvider) InvestmentVehicle(name.abuchen.portfolio.model.InvestmentVehicle) ColumnPixelData(org.eclipse.jface.viewers.ColumnPixelData) Image(org.eclipse.swt.graphics.Image) TableViewerColumn(org.eclipse.jface.viewers.TableViewerColumn) Font(org.eclipse.swt.graphics.Font)

Example 18 with ColumnPixelData

use of org.eclipse.jface.viewers.ColumnPixelData in project portfolio by buchen.

the class DividendsMatrixTab method createSumColumn.

protected void createSumColumn(TableViewer records, TableColumnLayout layout) {
    TableViewerColumn column;
    column = new TableViewerColumn(records, SWT.RIGHT);
    column.getColumn().setText(Messages.ColumnSum);
    column.setLabelProvider(new ColumnLabelProvider() {

        @Override
        public String getText(Object element) {
            DividendsViewModel.Line line = (DividendsViewModel.Line) element;
            if (showOnlyOneYear) {
                int noOfMonths = Math.min(12, line.getNoOfMonths());
                long sum = 0;
                for (int ii = 0; ii < noOfMonths; ii++) sum += line.getValue(ii);
                return Values.Amount.formatNonZero(sum);
            } else {
                return Values.Amount.formatNonZero(line.getSum());
            }
        }

        @Override
        public Font getFont(Object element) {
            return boldFont;
        }
    });
    layout.setColumnData(column.getColumn(), new ColumnPixelData(200));
}
Also used : Line(name.abuchen.portfolio.ui.views.dividends.DividendsViewModel.Line) ColumnLabelProvider(org.eclipse.jface.viewers.ColumnLabelProvider) ColumnPixelData(org.eclipse.jface.viewers.ColumnPixelData) TableViewerColumn(org.eclipse.jface.viewers.TableViewerColumn) Font(org.eclipse.swt.graphics.Font)

Example 19 with ColumnPixelData

use of org.eclipse.jface.viewers.ColumnPixelData in project portfolio by buchen.

the class PreviewQuotesPage method createControl.

@Override
public void createControl(Composite parent) {
    Composite container = new Composite(parent, SWT.NONE);
    setControl(container);
    GridLayoutFactory.fillDefaults().numColumns(1).applyTo(container);
    Button checkbox = new Button(container, SWT.CHECK);
    checkbox.setText(Messages.SplitWizardLabelUpdateQuotes);
    Composite tableContainer = new Composite(container, SWT.NONE);
    GridDataFactory.fillDefaults().grab(true, true).applyTo(tableContainer);
    TableColumnLayout layout = new TableColumnLayout();
    tableContainer.setLayout(layout);
    tableViewer = new TableViewer(tableContainer, SWT.BORDER);
    Table table = tableViewer.getTable();
    table.setHeaderVisible(true);
    table.setLinesVisible(true);
    TableColumn column = new TableColumn(tableViewer.getTable(), SWT.None);
    column.setText(Messages.ColumnDate);
    layout.setColumnData(column, new ColumnPixelData(80, true));
    column = new TableColumn(tableViewer.getTable(), SWT.RIGHT);
    column.setText(Messages.ColumnCurrentQuote);
    layout.setColumnData(column, new ColumnPixelData(80, true));
    column = new TableColumn(tableViewer.getTable(), SWT.RIGHT);
    column.setText(Messages.ColumnUpdatedQuote);
    layout.setColumnData(column, new ColumnPixelData(80, true));
    tableViewer.setLabelProvider(new TransactionLabelProvider());
    tableViewer.setContentProvider(ArrayContentProvider.getInstance());
    // bindings
    DataBindingContext context = new DataBindingContext();
    // 
    context.bindValue(// 
    WidgetProperties.selection().observe(checkbox), // $NON-NLS-1$
    BeanProperties.value("changeHistoricalQuotes").observe(model));
    checkbox.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            tableViewer.refresh();
        }
    });
}
Also used : Table(org.eclipse.swt.widgets.Table) Composite(org.eclipse.swt.widgets.Composite) TableColumnLayout(org.eclipse.jface.layout.TableColumnLayout) Button(org.eclipse.swt.widgets.Button) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) ColumnPixelData(org.eclipse.jface.viewers.ColumnPixelData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) DataBindingContext(org.eclipse.core.databinding.DataBindingContext) TableViewer(org.eclipse.jface.viewers.TableViewer) TableColumn(org.eclipse.swt.widgets.TableColumn)

Example 20 with ColumnPixelData

use of org.eclipse.jface.viewers.ColumnPixelData in project portfolio by buchen.

the class PreviewTransactionsPage method createControl.

@Override
public void createControl(Composite parent) {
    Composite container = new Composite(parent, SWT.NONE);
    setControl(container);
    GridLayoutFactory.fillDefaults().numColumns(1).applyTo(container);
    Button checkbox = new Button(container, SWT.CHECK);
    checkbox.setText(Messages.SplitWizardLabelUpdateTransactions);
    Composite tableContainer = new Composite(container, SWT.NONE);
    GridDataFactory.fillDefaults().grab(true, true).applyTo(tableContainer);
    TableColumnLayout layout = new TableColumnLayout();
    tableContainer.setLayout(layout);
    tableViewer = new TableViewer(tableContainer, SWT.BORDER);
    Table table = tableViewer.getTable();
    table.setHeaderVisible(true);
    table.setLinesVisible(true);
    TableColumn column = new TableColumn(tableViewer.getTable(), SWT.None);
    column.setText(Messages.ColumnDate);
    layout.setColumnData(column, new ColumnPixelData(100, true));
    column = new TableColumn(tableViewer.getTable(), SWT.None);
    column.setText(Messages.ColumnTransactionType);
    layout.setColumnData(column, new ColumnPixelData(80, true));
    column = new TableColumn(tableViewer.getTable(), SWT.RIGHT);
    column.setText(Messages.ColumnCurrentShares);
    layout.setColumnData(column, new ColumnPixelData(80, true));
    column = new TableColumn(tableViewer.getTable(), SWT.RIGHT);
    column.setText(Messages.ColumnUpdatedShares);
    layout.setColumnData(column, new ColumnPixelData(80, true));
    column = new TableColumn(tableViewer.getTable(), SWT.None);
    column.setText(Messages.ColumnSource);
    layout.setColumnData(column, new ColumnPixelData(200, true));
    tableViewer.setLabelProvider(new TransactionLabelProvider());
    tableViewer.setContentProvider(ArrayContentProvider.getInstance());
    // bindings
    DataBindingContext context = new DataBindingContext();
    // 
    context.bindValue(// 
    WidgetProperties.selection().observe(checkbox), // $NON-NLS-1$
    BeanProperties.value("changeTransactions").observe(model));
    checkbox.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            tableViewer.refresh();
        }
    });
}
Also used : Table(org.eclipse.swt.widgets.Table) Composite(org.eclipse.swt.widgets.Composite) TableColumnLayout(org.eclipse.jface.layout.TableColumnLayout) Button(org.eclipse.swt.widgets.Button) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) ColumnPixelData(org.eclipse.jface.viewers.ColumnPixelData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) DataBindingContext(org.eclipse.core.databinding.DataBindingContext) TableViewer(org.eclipse.jface.viewers.TableViewer) TableColumn(org.eclipse.swt.widgets.TableColumn)

Aggregations

ColumnPixelData (org.eclipse.jface.viewers.ColumnPixelData)45 TableViewerColumn (org.eclipse.jface.viewers.TableViewerColumn)20 ColumnLabelProvider (org.eclipse.jface.viewers.ColumnLabelProvider)17 TableLayout (org.eclipse.jface.viewers.TableLayout)16 Composite (org.eclipse.swt.widgets.Composite)15 TableViewer (org.eclipse.jface.viewers.TableViewer)14 ColumnWeightData (org.eclipse.jface.viewers.ColumnWeightData)13 Image (org.eclipse.swt.graphics.Image)13 GridData (org.eclipse.swt.layout.GridData)13 TableColumn (org.eclipse.swt.widgets.TableColumn)13 SelectionEvent (org.eclipse.swt.events.SelectionEvent)10 TableColumnLayout (org.eclipse.jface.layout.TableColumnLayout)9 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)8 TreeViewerColumn (org.eclipse.jface.viewers.TreeViewerColumn)8 Point (org.eclipse.swt.graphics.Point)8 Table (org.eclipse.swt.widgets.Table)8 ArrayList (java.util.ArrayList)6 TreeColumnLayout (org.eclipse.jface.layout.TreeColumnLayout)6 Viewer (org.eclipse.jface.viewers.Viewer)6 GridLayout (org.eclipse.swt.layout.GridLayout)6