Search in sources :

Example 41 with TableColumnLayout

use of org.eclipse.jface.layout.TableColumnLayout 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 42 with TableColumnLayout

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

the class DividendsMatrixTab method createControl.

@Override
public Control createControl(Composite parent) {
    LocalResourceManager resources = new LocalResourceManager(JFaceResources.getResources(), parent);
    boldFont = resources.createFont(FontDescriptor.createFrom(parent.getFont()).setStyle(SWT.BOLD));
    Composite container = new Composite(parent, SWT.NONE);
    tableLayout = new TableColumnLayout();
    container.setLayout(tableLayout);
    tableViewer = new TableViewer(container, SWT.FULL_SELECTION);
    ColumnViewerToolTipSupport.enableFor(tableViewer, ToolTip.NO_RECREATE);
    createColumns(tableViewer, tableLayout);
    tableViewer.getTable().setHeaderVisible(true);
    tableViewer.getTable().setLinesVisible(true);
    tableViewer.setContentProvider(ArrayContentProvider.getInstance());
    tableViewer.addSelectionChangedListener(event -> {
        InvestmentVehicle vehicle = ((DividendsViewModel.Line) ((IStructuredSelection) event.getSelection()).getFirstElement()).getVehicle();
        if (vehicle != null && vehicle instanceof Security)
            selectionService.setSelection(new SecuritySelection(model.getClient(), (Security) vehicle));
    });
    tableViewer.setInput(model.getAllLines());
    for (TableColumn c : tableViewer.getTable().getColumns()) c.pack();
    model.addUpdateListener(() -> updateColumns(tableViewer, tableLayout));
    return container;
}
Also used : Line(name.abuchen.portfolio.ui.views.dividends.DividendsViewModel.Line) SecuritySelection(name.abuchen.portfolio.ui.selection.SecuritySelection) Composite(org.eclipse.swt.widgets.Composite) TableColumnLayout(org.eclipse.jface.layout.TableColumnLayout) LocalResourceManager(org.eclipse.jface.resource.LocalResourceManager) InvestmentVehicle(name.abuchen.portfolio.model.InvestmentVehicle) Security(name.abuchen.portfolio.model.Security) TableViewer(org.eclipse.jface.viewers.TableViewer) TableColumn(org.eclipse.swt.widgets.TableColumn)

Example 43 with TableColumnLayout

use of org.eclipse.jface.layout.TableColumnLayout 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 44 with TableColumnLayout

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

the class AddTaxonomyPage method createControl.

@Override
public void createControl(Composite parent) {
    Composite container = new Composite(parent, SWT.NONE);
    setControl(container);
    TableColumnLayout layout = new TableColumnLayout();
    container.setLayout(layout);
    final TableViewer viewer = new TableViewer(container);
    TableViewerColumn column = new TableViewerColumn(viewer, SWT.NONE);
    layout.setColumnData(column.getColumn(), new ColumnWeightData(90));
    column.getColumn().setText(Messages.ColumnTaxonomy);
    column.setLabelProvider(new ColumnLabelProvider() {

        @Override
        public String getText(Object element) {
            return ((TaxonomyTemplate) element).getName();
        }
    });
    column = new TableViewerColumn(viewer, SWT.NONE);
    layout.setColumnData(column.getColumn(), new ColumnWeightData(10));
    column.setLabelProvider(new ColumnLabelProvider() {

        @Override
        public String getText(Object element) {
            return null;
        }

        @Override
        public Image getImage(Object element) {
            TaxonomyTemplate t = (TaxonomyTemplate) element;
            if (taxonomiesAdded.contains(t.getId()))
                return Images.CHECK.image();
            else
                return null;
        }
    });
    viewer.addDoubleClickListener(new IDoubleClickListener() {

        @Override
        public void doubleClick(DoubleClickEvent event) {
            TaxonomyTemplate template = (TaxonomyTemplate) ((IStructuredSelection) event.getSelection()).getFirstElement();
            if (template != null && !taxonomiesAdded.contains(template.getId())) {
                taxonomiesAdded.add(template.getId());
                client.addTaxonomy(template.build());
                viewer.refresh(template);
            }
        }
    });
    viewer.getTable().setHeaderVisible(true);
    viewer.setContentProvider(ArrayContentProvider.getInstance());
    viewer.setInput(TaxonomyTemplate.list());
    setPageComplete(true);
}
Also used : ColumnWeightData(org.eclipse.jface.viewers.ColumnWeightData) Composite(org.eclipse.swt.widgets.Composite) DoubleClickEvent(org.eclipse.jface.viewers.DoubleClickEvent) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) Image(org.eclipse.swt.graphics.Image) ColumnLabelProvider(org.eclipse.jface.viewers.ColumnLabelProvider) TableColumnLayout(org.eclipse.jface.layout.TableColumnLayout) IDoubleClickListener(org.eclipse.jface.viewers.IDoubleClickListener) TaxonomyTemplate(name.abuchen.portfolio.model.TaxonomyTemplate) TableViewer(org.eclipse.jface.viewers.TableViewer) TableViewerColumn(org.eclipse.jface.viewers.TableViewerColumn)

Example 45 with TableColumnLayout

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

the class ImportIndizesPage method createControl.

@Override
public void createControl(Composite parent) {
    Composite container = new Composite(parent, SWT.NULL);
    setControl(container);
    GridLayoutFactory.fillDefaults().applyTo(container);
    comboDropDown = new Combo(container, SWT.DROP_DOWN | SWT.BORDER | SWT.READ_ONLY);
    GridDataFactory.fillDefaults().align(SWT.BEGINNING, SWT.FILL).applyTo(comboDropDown);
    final ComboViewer comboViewer = new ComboViewer(comboDropDown);
    comboViewer.setContentProvider(ArrayContentProvider.getInstance());
    comboViewer.setInput(proposals);
    Composite tableContainer = new Composite(container, SWT.NONE);
    GridDataFactory.fillDefaults().span(2, 1).grab(true, true).applyTo(tableContainer);
    TableColumnLayout layout = new TableColumnLayout();
    tableContainer.setLayout(layout);
    final TableViewer tViewer = new TableViewer(tableContainer);
    comboViewer.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            ProposedSecurities element = (ProposedSecurities) ((IStructuredSelection) event.getSelectionProvider().getSelection()).getFirstElement();
            if (element != null)
                tViewer.setInput(element.securities);
        }
    });
    Table table = tViewer.getTable();
    table.setHeaderVisible(true);
    tViewer.setContentProvider(ArrayContentProvider.getInstance());
    TableViewerColumn aCol = new TableViewerColumn(tViewer, SWT.NONE);
    layout.setColumnData(aCol.getColumn(), new ColumnWeightData(90));
    aCol.getColumn().setText(Messages.ColumnSecurity);
    aCol.setLabelProvider(new ColumnLabelProvider() {

        @Override
        public String getText(Object element) {
            return ((Security) element).getName();
        }

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

        @Override
        public String getText(Object element) {
            return null;
        }

        @Override
        public Image getImage(Object element) {
            return client.getSecurities().contains(element) ? Images.CHECK.image() : null;
        }
    });
    tViewer.addDoubleClickListener(new IDoubleClickListener() {

        @Override
        public void doubleClick(DoubleClickEvent event) {
            Security security = (Security) ((IStructuredSelection) event.getSelection()).getFirstElement();
            if (security != null && !client.getSecurities().contains(security)) {
                client.addSecurity(security);
                tViewer.refresh(security);
            }
        }
    });
    Button button = new Button(container, SWT.PUSH);
    button.setText(Messages.NewFileWizardAddAll);
    GridDataFactory.fillDefaults().align(SWT.BEGINNING, SWT.FILL).applyTo(button);
    button.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            ProposedSecurities proposal = (ProposedSecurities) ((IStructuredSelection) comboViewer.getSelection()).getFirstElement();
            for (Security security : proposal.securities) {
                if (!client.getSecurities().contains(security))
                    client.addSecurity(security);
            }
            tViewer.refresh();
        }
    });
    comboDropDown.select(0);
    container.pack();
    setPageComplete(true);
}
Also used : ColumnWeightData(org.eclipse.jface.viewers.ColumnWeightData) Table(org.eclipse.swt.widgets.Table) Composite(org.eclipse.swt.widgets.Composite) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) Combo(org.eclipse.swt.widgets.Combo) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) DoubleClickEvent(org.eclipse.jface.viewers.DoubleClickEvent) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) Image(org.eclipse.swt.graphics.Image) Security(name.abuchen.portfolio.model.Security) ColumnLabelProvider(org.eclipse.jface.viewers.ColumnLabelProvider) TableColumnLayout(org.eclipse.jface.layout.TableColumnLayout) ComboViewer(org.eclipse.jface.viewers.ComboViewer) Button(org.eclipse.swt.widgets.Button) IDoubleClickListener(org.eclipse.jface.viewers.IDoubleClickListener) SelectionEvent(org.eclipse.swt.events.SelectionEvent) TableViewer(org.eclipse.jface.viewers.TableViewer) TableViewerColumn(org.eclipse.jface.viewers.TableViewerColumn)

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