Search in sources :

Example 1 with ContextMenu

use of name.abuchen.portfolio.ui.util.ContextMenu in project portfolio by buchen.

the class DashboardView method buildDelegate.

private WidgetDelegate buildDelegate(Composite columnControl, WidgetFactory widgetType, Dashboard.Widget widget) {
    WidgetDelegate delegate = widgetType.create(widget, dashboardData);
    Composite element = delegate.createControl(columnControl, resources);
    element.setData(widget);
    element.setData(DELEGATE_KEY, delegate);
    Composite filler = (Composite) columnControl.getData(FILLER_KEY);
    element.moveAbove(filler);
    new ContextMenu(delegate.getTitleControl(), manager -> widgetMenuAboutToShow(manager, delegate)).hook();
    InfoToolTip.attach(delegate.getTitleControl(), () -> buildToolTip(delegate));
    addDragListener(element);
    addDropListener(element);
    for (Control child : element.getChildren()) addDragListener(child);
    GridDataFactory.fillDefaults().grab(true, false).applyTo(element);
    return delegate;
}
Also used : InputDialog(org.eclipse.jface.dialogs.InputDialog) ContextMenu(name.abuchen.portfolio.ui.util.ContextMenu) IPreferenceStore(org.eclipse.jface.preference.IPreferenceStore) DND(org.eclipse.swt.dnd.DND) ToolBar(org.eclipse.swt.widgets.ToolBar) Images(name.abuchen.portfolio.ui.Images) Image(org.eclipse.swt.graphics.Image) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) GC(org.eclipse.swt.graphics.GC) Point(org.eclipse.swt.graphics.Point) LocalSelectionTransfer(org.eclipse.jface.util.LocalSelectionTransfer) Inject(javax.inject.Inject) DropTargetEvent(org.eclipse.swt.dnd.DropTargetEvent) DropTargetAdapter(org.eclipse.swt.dnd.DropTargetAdapter) Composite(org.eclipse.swt.widgets.Composite) Messages(name.abuchen.portfolio.ui.Messages) AbstractHistoricView(name.abuchen.portfolio.ui.views.AbstractHistoricView) DragSource(org.eclipse.swt.dnd.DragSource) InfoToolTip(name.abuchen.portfolio.ui.util.InfoToolTip) DropTarget(org.eclipse.swt.dnd.DropTarget) Separator(org.eclipse.jface.action.Separator) Dashboard(name.abuchen.portfolio.model.Dashboard) MenuManager(org.eclipse.jface.action.MenuManager) GridDataFactory(org.eclipse.jface.layout.GridDataFactory) SimpleAction(name.abuchen.portfolio.ui.util.SimpleAction) Action(org.eclipse.jface.action.Action) Display(org.eclipse.swt.widgets.Display) Collectors(java.util.stream.Collectors) GridLayoutFactory(org.eclipse.jface.layout.GridLayoutFactory) AbstractDropDown(name.abuchen.portfolio.ui.util.AbstractDropDown) Transfer(org.eclipse.swt.dnd.Transfer) Consumer(java.util.function.Consumer) IMenuManager(org.eclipse.jface.action.IMenuManager) StringJoiner(java.util.StringJoiner) SWT(org.eclipse.swt.SWT) DragSourceEvent(org.eclipse.swt.dnd.DragSourceEvent) DragSourceAdapter(org.eclipse.swt.dnd.DragSourceAdapter) Control(org.eclipse.swt.widgets.Control) Control(org.eclipse.swt.widgets.Control) Composite(org.eclipse.swt.widgets.Composite) ContextMenu(name.abuchen.portfolio.ui.util.ContextMenu)

Example 2 with ContextMenu

use of name.abuchen.portfolio.ui.util.ContextMenu in project portfolio by buchen.

the class DashboardView method buildColumn.

private Composite buildColumn(Composite composite, Dashboard.Column column) {
    Composite columnControl = new Composite(composite, SWT.NONE);
    columnControl.setBackground(composite.getBackground());
    columnControl.setData(column);
    GridLayoutFactory.fillDefaults().numColumns(1).spacing(0, 0).applyTo(columnControl);
    GridDataFactory.fillDefaults().grab(true, true).applyTo(columnControl);
    addDropListener(columnControl);
    // Each column has an empty composite at the bottom to serve as target
    // for the column context menu. A separate composite is needed because
    // *all* context menus attached to nested composites are always shown.
    Composite filler = new Composite(columnControl, SWT.NONE);
    filler.setBackground(columnControl.getBackground());
    GridDataFactory.fillDefaults().grab(true, true).applyTo(filler);
    columnControl.setData(FILLER_KEY, filler);
    new ContextMenu(filler, manager -> {
        MenuManager subMenu = new MenuManager(Messages.MenuNewWidget);
        for (WidgetFactory type : WidgetFactory.values()) subMenu.add(new SimpleAction(type.getLabel(), a -> addNewWidget(columnControl, type)));
        manager.add(subMenu);
        manager.add(new Separator());
        manager.add(new SimpleAction(Messages.MenuAddNewDashboardColumnLeft, a -> createNewColumn(column, columnControl)));
        manager.add(new SimpleAction(Messages.MenuDeleteDashboardColumn, a -> deleteColumn(columnControl)));
    }).hook();
    return columnControl;
}
Also used : InputDialog(org.eclipse.jface.dialogs.InputDialog) ContextMenu(name.abuchen.portfolio.ui.util.ContextMenu) IPreferenceStore(org.eclipse.jface.preference.IPreferenceStore) DND(org.eclipse.swt.dnd.DND) ToolBar(org.eclipse.swt.widgets.ToolBar) Images(name.abuchen.portfolio.ui.Images) Image(org.eclipse.swt.graphics.Image) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) GC(org.eclipse.swt.graphics.GC) Point(org.eclipse.swt.graphics.Point) LocalSelectionTransfer(org.eclipse.jface.util.LocalSelectionTransfer) Inject(javax.inject.Inject) DropTargetEvent(org.eclipse.swt.dnd.DropTargetEvent) DropTargetAdapter(org.eclipse.swt.dnd.DropTargetAdapter) Composite(org.eclipse.swt.widgets.Composite) Messages(name.abuchen.portfolio.ui.Messages) AbstractHistoricView(name.abuchen.portfolio.ui.views.AbstractHistoricView) DragSource(org.eclipse.swt.dnd.DragSource) InfoToolTip(name.abuchen.portfolio.ui.util.InfoToolTip) DropTarget(org.eclipse.swt.dnd.DropTarget) Separator(org.eclipse.jface.action.Separator) Dashboard(name.abuchen.portfolio.model.Dashboard) MenuManager(org.eclipse.jface.action.MenuManager) GridDataFactory(org.eclipse.jface.layout.GridDataFactory) SimpleAction(name.abuchen.portfolio.ui.util.SimpleAction) Action(org.eclipse.jface.action.Action) Display(org.eclipse.swt.widgets.Display) Collectors(java.util.stream.Collectors) GridLayoutFactory(org.eclipse.jface.layout.GridLayoutFactory) AbstractDropDown(name.abuchen.portfolio.ui.util.AbstractDropDown) Transfer(org.eclipse.swt.dnd.Transfer) Consumer(java.util.function.Consumer) IMenuManager(org.eclipse.jface.action.IMenuManager) StringJoiner(java.util.StringJoiner) SWT(org.eclipse.swt.SWT) DragSourceEvent(org.eclipse.swt.dnd.DragSourceEvent) DragSourceAdapter(org.eclipse.swt.dnd.DragSourceAdapter) Control(org.eclipse.swt.widgets.Control) Composite(org.eclipse.swt.widgets.Composite) MenuManager(org.eclipse.jface.action.MenuManager) IMenuManager(org.eclipse.jface.action.IMenuManager) ContextMenu(name.abuchen.portfolio.ui.util.ContextMenu) SimpleAction(name.abuchen.portfolio.ui.util.SimpleAction) Separator(org.eclipse.jface.action.Separator)

Example 3 with ContextMenu

use of name.abuchen.portfolio.ui.util.ContextMenu 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 4 with ContextMenu

use of name.abuchen.portfolio.ui.util.ContextMenu 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 5 with ContextMenu

use of name.abuchen.portfolio.ui.util.ContextMenu in project portfolio by buchen.

the class EditReportingPeriodsDialog method createDialogArea.

@Override
protected Control createDialogArea(Composite parent) {
    Composite container = (Composite) super.createDialogArea(parent);
    Composite tableArea = new Composite(container, SWT.NONE);
    GridDataFactory.fillDefaults().grab(true, true).minSize(SWT.DEFAULT, 200).applyTo(tableArea);
    TableColumnLayout layout = new TableColumnLayout();
    tableArea.setLayout(layout);
    tableViewer = new TableViewer(tableArea, SWT.BORDER | SWT.MULTI | SWT.MULTI);
    final Table table = tableViewer.getTable();
    table.setHeaderVisible(false);
    table.setLinesVisible(false);
    TableViewerColumn column = new TableViewerColumn(tableViewer, SWT.None);
    layout.setColumnData(column.getColumn(), new ColumnWeightData(100));
    tableViewer.setLabelProvider(new LabelProvider() {

        @Override
        public Image getImage(Object element) {
            return Images.TEXT.image();
        }
    });
    tableViewer.setContentProvider(ArrayContentProvider.getInstance());
    tableViewer.setInput(periods);
    new ContextMenu(tableViewer.getTable(), m -> fillContextMenu(m)).hook();
    return container;
}
Also used : ColumnWeightData(org.eclipse.jface.viewers.ColumnWeightData) ContextMenu(name.abuchen.portfolio.ui.util.ContextMenu) Shell(org.eclipse.swt.widgets.Shell) TableViewer(org.eclipse.jface.viewers.TableViewer) GridDataFactory(org.eclipse.jface.layout.GridDataFactory) Images(name.abuchen.portfolio.ui.Images) Image(org.eclipse.swt.graphics.Image) Action(org.eclipse.jface.action.Action) ArrayContentProvider(org.eclipse.jface.viewers.ArrayContentProvider) Table(org.eclipse.swt.widgets.Table) TableColumnLayout(org.eclipse.jface.layout.TableColumnLayout) TableViewerColumn(org.eclipse.jface.viewers.TableViewerColumn) ArrayList(java.util.ArrayList) List(java.util.List) IMenuManager(org.eclipse.jface.action.IMenuManager) Dialog(org.eclipse.jface.dialogs.Dialog) Composite(org.eclipse.swt.widgets.Composite) Messages(name.abuchen.portfolio.ui.Messages) SWT(org.eclipse.swt.SWT) ColumnWeightData(org.eclipse.jface.viewers.ColumnWeightData) ReportingPeriod(name.abuchen.portfolio.snapshot.ReportingPeriod) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) LabelProvider(org.eclipse.jface.viewers.LabelProvider) Control(org.eclipse.swt.widgets.Control) Table(org.eclipse.swt.widgets.Table) Composite(org.eclipse.swt.widgets.Composite) TableColumnLayout(org.eclipse.jface.layout.TableColumnLayout) ContextMenu(name.abuchen.portfolio.ui.util.ContextMenu) Image(org.eclipse.swt.graphics.Image) TableViewer(org.eclipse.jface.viewers.TableViewer) LabelProvider(org.eclipse.jface.viewers.LabelProvider) TableViewerColumn(org.eclipse.jface.viewers.TableViewerColumn)

Aggregations

ContextMenu (name.abuchen.portfolio.ui.util.ContextMenu)6 Composite (org.eclipse.swt.widgets.Composite)6 Image (org.eclipse.swt.graphics.Image)5 Images (name.abuchen.portfolio.ui.Images)4 Messages (name.abuchen.portfolio.ui.Messages)4 Action (org.eclipse.jface.action.Action)4 IMenuManager (org.eclipse.jface.action.IMenuManager)4 SWT (org.eclipse.swt.SWT)4 Inject (javax.inject.Inject)3 ShowHideColumnHelper (name.abuchen.portfolio.ui.util.viewers.ShowHideColumnHelper)3 Separator (org.eclipse.jface.action.Separator)3 GridDataFactory (org.eclipse.jface.layout.GridDataFactory)3 IPreferenceStore (org.eclipse.jface.preference.IPreferenceStore)3 Control (org.eclipse.swt.widgets.Control)3 StringJoiner (java.util.StringJoiner)2 Consumer (java.util.function.Consumer)2 Collectors (java.util.stream.Collectors)2 Dashboard (name.abuchen.portfolio.model.Dashboard)2 AbstractDropDown (name.abuchen.portfolio.ui.util.AbstractDropDown)2 InfoToolTip (name.abuchen.portfolio.ui.util.InfoToolTip)2