Search in sources :

Example 6 with SecuritySelection

use of name.abuchen.portfolio.ui.selection.SecuritySelection in project portfolio by buchen.

the class OpenBookmarksHandler method execute.

@Execute
public void execute(@Named(IServiceConstants.ACTIVE_PART) MPart part, @Named(IServiceConstants.ACTIVE_SHELL) Shell shell, ESelectionService selectionService) {
    Object object = selectionService.getSelection();
    if (!(object instanceof SecuritySelection))
        return;
    SecuritySelection selection = (SecuritySelection) object;
    if (selection.getClient().getSettings().getBookmarks().isEmpty())
        return;
    List<Bookmark> bookmarks = selection.getClient().getSettings().getBookmarks().stream().filter(b -> !b.isSeparator()).collect(Collectors.toList());
    BookmarkPopup<Bookmark> popup = new // 
    BookmarkPopup<>(// 
    shell, // 
    selection.getSecurity().getName(), // 
    bookmarks, // 
    Bookmark::getLabel, bm -> DesktopAPI.browse(bm.constructURL(selection.getClient(), selection.getSecurity())));
    popup.open();
}
Also used : IServiceConstants(org.eclipse.e4.ui.services.IServiceConstants) TableViewer(org.eclipse.jface.viewers.TableViewer) Execute(org.eclipse.e4.core.di.annotations.Execute) Function(java.util.function.Function) TableColumnLayout(org.eclipse.jface.layout.TableColumnLayout) ColumnPixelData(org.eclipse.jface.viewers.ColumnPixelData) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) MPart(org.eclipse.e4.ui.model.application.ui.basic.MPart) ESelectionService(org.eclipse.e4.ui.workbench.modeling.ESelectionService) Composite(org.eclipse.swt.widgets.Composite) Named(javax.inject.Named) Shell(org.eclipse.swt.widgets.Shell) GridDataFactory(org.eclipse.jface.layout.GridDataFactory) ArrayContentProvider(org.eclipse.jface.viewers.ArrayContentProvider) ColumnLabelProvider(org.eclipse.jface.viewers.ColumnLabelProvider) DesktopAPI(name.abuchen.portfolio.ui.util.DesktopAPI) Collectors(java.util.stream.Collectors) TableViewerColumn(org.eclipse.jface.viewers.TableViewerColumn) GridLayoutFactory(org.eclipse.jface.layout.GridLayoutFactory) Consumer(java.util.function.Consumer) PopupDialog(org.eclipse.jface.dialogs.PopupDialog) List(java.util.List) Bookmark(name.abuchen.portfolio.model.Bookmark) SWT(org.eclipse.swt.SWT) SecuritySelection(name.abuchen.portfolio.ui.selection.SecuritySelection) SelectionEvent(org.eclipse.swt.events.SelectionEvent) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) Control(org.eclipse.swt.widgets.Control) SelectionListener(org.eclipse.swt.events.SelectionListener) SecuritySelection(name.abuchen.portfolio.ui.selection.SecuritySelection) Bookmark(name.abuchen.portfolio.model.Bookmark) Execute(org.eclipse.e4.core.di.annotations.Execute)

Example 7 with SecuritySelection

use of name.abuchen.portfolio.ui.selection.SecuritySelection 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 8 with SecuritySelection

use of name.abuchen.portfolio.ui.selection.SecuritySelection in project portfolio by buchen.

the class AbstractNodeTreeViewer method createControl.

@Override
public final Control createControl(Composite parent) {
    Composite container = new Composite(parent, SWT.NONE);
    TreeColumnLayout layout = new TreeColumnLayout();
    container.setLayout(layout);
    nodeViewer = new TreeViewer(container, SWT.FULL_SELECTION | SWT.MULTI);
    ColumnEditingSupport.prepare(nodeViewer);
    ColumnViewerToolTipSupport.enableFor(nodeViewer, ToolTip.NO_RECREATE);
    support = new ShowHideColumnHelper(getClass().getSimpleName() + '-' + getModel().getTaxonomy().getId(), getPreferenceStore(), nodeViewer, layout);
    addColumns(support);
    support.createColumns();
    nodeViewer.getTree().setHeaderVisible(true);
    nodeViewer.getTree().setLinesVisible(true);
    nodeViewer.setContentProvider(new ItemContentProvider());
    nodeViewer.addDragSupport(DND.DROP_MOVE | DND.DROP_COPY, new Transfer[] { TaxonomyNodeTransfer.getTransfer(), SecurityTransfer.getTransfer() }, new NodeDragListener(nodeViewer));
    nodeViewer.addDropSupport(DND.DROP_MOVE | DND.DROP_COPY, new Transfer[] { TaxonomyNodeTransfer.getTransfer() }, new NodeDropListener(this));
    nodeViewer.addFilter(new ViewerFilter() {

        @Override
        public boolean select(Viewer viewer, Object parentElement, Object element) {
            TaxonomyNode node = (TaxonomyNode) element;
            for (Predicate<TaxonomyNode> predicate : getModel().getNodeFilters()) if (!predicate.test(node))
                return false;
            return true;
        }
    });
    nodeViewer.addSelectionChangedListener(event -> {
        TaxonomyNode node = ((TaxonomyNode) ((IStructuredSelection) event.getSelection()).getFirstElement());
        if (node != null && node.getBackingSecurity() != null)
            selectionService.setSelection(new SecuritySelection(getModel().getClient(), node.getBackingSecurity()));
    });
    nodeViewer.setInput(getModel());
    new ContextMenu(nodeViewer.getControl(), this::fillContextMenu).hook();
    return container;
}
Also used : SecuritySelection(name.abuchen.portfolio.ui.selection.SecuritySelection) Composite(org.eclipse.swt.widgets.Composite) ViewerFilter(org.eclipse.jface.viewers.ViewerFilter) TreeColumnLayout(org.eclipse.jface.layout.TreeColumnLayout) TreeViewer(org.eclipse.jface.viewers.TreeViewer) TreeViewer(org.eclipse.jface.viewers.TreeViewer) Viewer(org.eclipse.jface.viewers.Viewer) ContextMenu(name.abuchen.portfolio.ui.util.ContextMenu) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) Predicate(java.util.function.Predicate) ShowHideColumnHelper(name.abuchen.portfolio.ui.util.viewers.ShowHideColumnHelper)

Example 9 with SecuritySelection

use of name.abuchen.portfolio.ui.selection.SecuritySelection 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)

Aggregations

SecuritySelection (name.abuchen.portfolio.ui.selection.SecuritySelection)9 Composite (org.eclipse.swt.widgets.Composite)8 TableViewer (org.eclipse.jface.viewers.TableViewer)7 TableColumnLayout (org.eclipse.jface.layout.TableColumnLayout)6 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)6 Security (name.abuchen.portfolio.model.Security)5 ShowHideColumnHelper (name.abuchen.portfolio.ui.util.viewers.ShowHideColumnHelper)5 ColumnLabelProvider (org.eclipse.jface.viewers.ColumnLabelProvider)4 Viewer (org.eclipse.jface.viewers.Viewer)4 Predicate (java.util.function.Predicate)3 TreeColumnLayout (org.eclipse.jface.layout.TreeColumnLayout)3 ColumnPixelData (org.eclipse.jface.viewers.ColumnPixelData)3 TreeViewer (org.eclipse.jface.viewers.TreeViewer)3 ViewerFilter (org.eclipse.jface.viewers.ViewerFilter)3 Font (org.eclipse.swt.graphics.Font)3 Image (org.eclipse.swt.graphics.Image)3 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Function (java.util.function.Function)2 ClientPerformanceSnapshot (name.abuchen.portfolio.snapshot.ClientPerformanceSnapshot)2