Search in sources :

Example 1 with MMenuItem

use of org.eclipse.e4.ui.model.application.ui.menu.MMenuItem in project portfolio by buchen.

the class NewTransactionHandler method execute.

@Execute
public void execute(MMenuItem menuItem, SelectionService selectionService) {
    PortfolioPart part = (PortfolioPart) menuItem.getTransientData().get(PortfolioPart.class.getName());
    @SuppressWarnings("unchecked") Class<? extends AbstractTransactionDialog> dialog = (Class<? extends AbstractTransactionDialog>) menuItem.getTransientData().get(AbstractTransactionDialog.class.getName());
    Object transaction = menuItem.getTransientData().get(UIConstants.Parameter.NAME);
    part.getCurrentView().ifPresent(view -> {
        // $NON-NLS-1$
        OpenDialogAction action = new OpenDialogAction(view, transaction.toString() + "...");
        action.type(dialog);
        if (Enum.class.isAssignableFrom(transaction.getClass()))
            action.parameters(transaction);
        selectionService.getSelection(part.getClient()).ifPresent(s -> action.with(s.getSecurity()));
        action.run();
    });
}
Also used : AbstractTransactionDialog(name.abuchen.portfolio.ui.dialogs.transactions.AbstractTransactionDialog) PortfolioPart(name.abuchen.portfolio.ui.editor.PortfolioPart) OpenDialogAction(name.abuchen.portfolio.ui.dialogs.transactions.OpenDialogAction) Execute(org.eclipse.e4.core.di.annotations.Execute)

Example 2 with MMenuItem

use of org.eclipse.e4.ui.model.application.ui.menu.MMenuItem in project portfolio by buchen.

the class SelectReportingCurrencyHandler method isVisible.

@CanExecute
boolean isVisible(MMenuItem menuItem) {
    CurrencyUnit currency = (CurrencyUnit) menuItem.getTransientData().get(CurrencyUnit.class.getName());
    PortfolioPart part = (PortfolioPart) menuItem.getTransientData().get(PortfolioPart.class.getName());
    if (currency == null || part == null)
        return false;
    menuItem.setSelected(currency.getCurrencyCode().equals(part.getClient().getBaseCurrency()));
    return true;
}
Also used : CurrencyUnit(name.abuchen.portfolio.money.CurrencyUnit) PortfolioPart(name.abuchen.portfolio.ui.editor.PortfolioPart) CanExecute(org.eclipse.e4.core.di.annotations.CanExecute)

Example 3 with MMenuItem

use of org.eclipse.e4.ui.model.application.ui.menu.MMenuItem in project portfolio by buchen.

the class SetCurrentViewAsInitialViewHandler method isVisible.

@CanExecute
boolean isVisible(@Named(IServiceConstants.ACTIVE_PART) MPart part, MMenuItem menuItem) {
    if (!MenuHelper.getActiveClientInput(part, false).isPresent())
        return false;
    PortfolioPart portfolioPart = (PortfolioPart) part.getObject();
    Optional<Navigation.Item> view = portfolioPart.getSelectedItem();
    if (!view.isPresent())
        return false;
    menuItem.setLabel(MessageFormat.format(Messages.MenuSetCurrentViewAsInitialView, view.get().getLabel()));
    menuItem.setSelected(portfolioPart.getClientInput().getNavigation().getIdentifier(view.get()).equals(part.getPersistedState().get(UIConstants.PersistedState.INITIAL_VIEW)));
    return true;
}
Also used : MMenuItem(org.eclipse.e4.ui.model.application.ui.menu.MMenuItem) PortfolioPart(name.abuchen.portfolio.ui.editor.PortfolioPart) CanExecute(org.eclipse.e4.core.di.annotations.CanExecute)

Example 4 with MMenuItem

use of org.eclipse.e4.ui.model.application.ui.menu.MMenuItem in project aero.minova.rcp by minova-afis.

the class IconRendering method subscribeTopicChildrenChanged.

@Inject
@Optional
void subscribeTopicChildrenChanged(@UIEventTopic(UIEvents.ElementContainer.TOPIC_CHILDREN) Event event) {
    Object objElement = event.getProperty(UIEvents.EventTags.ELEMENT);
    // only care of added elements
    if (!UIEvents.isADD(event)) {
        return;
    }
    // Ensure that this event is for a MMenuItem or MToolBar
    if (!(objElement instanceof MMenuElement && !(objElement instanceof MPopupMenu)) && !(objElement instanceof MToolBar)) {
        return;
    }
    // Ensure that it's a View part's menu or toolbar
    MUIElement uiElement = (MUIElement) objElement;
    MUIElement parent = modelService.getContainer(uiElement);
    if (!(parent instanceof MPart)) {
        return;
    }
    MPart part = (MPart) parent;
    ImageUtil.updateIconsForPart(part);
    if (uiElement instanceof MToolBar) {
        MToolBar toolbar = (MToolBar) uiElement;
        ImageUtil.updateIconsForToolbarItems(toolbar);
    }
}
Also used : MToolBar(org.eclipse.e4.ui.model.application.ui.menu.MToolBar) MPart(org.eclipse.e4.ui.model.application.ui.basic.MPart) MPopupMenu(org.eclipse.e4.ui.model.application.ui.menu.MPopupMenu) MUIElement(org.eclipse.e4.ui.model.application.ui.MUIElement) MMenuElement(org.eclipse.e4.ui.model.application.ui.menu.MMenuElement) Inject(javax.inject.Inject) Optional(org.eclipse.e4.core.di.annotations.Optional)

Example 5 with MMenuItem

use of org.eclipse.e4.ui.model.application.ui.menu.MMenuItem in project eclipse.platform.ui by eclipse-platform.

the class RenderedElementUtil method createRenderedMenuItem.

/**
 * Create a 'rendered' menu item instance
 *
 * @return the new instance
 */
public static MMenuItem createRenderedMenuItem() {
    final MDirectMenuItem object = MMenuFactory.INSTANCE.createDirectMenuItem();
    object.getTags().add(RENDERED_TAG);
    return object;
}
Also used : MDirectMenuItem(org.eclipse.e4.ui.model.application.ui.menu.MDirectMenuItem)

Aggregations

MMenuItem (org.eclipse.e4.ui.model.application.ui.menu.MMenuItem)35 MMenu (org.eclipse.e4.ui.model.application.ui.menu.MMenu)26 MWindow (org.eclipse.e4.ui.model.application.ui.basic.MWindow)20 MenuManager (org.eclipse.jface.action.MenuManager)17 Test (org.junit.Test)17 MDirectMenuItem (org.eclipse.e4.ui.model.application.ui.menu.MDirectMenuItem)13 MHandledMenuItem (org.eclipse.e4.ui.model.application.ui.menu.MHandledMenuItem)10 MenuItem (org.eclipse.swt.widgets.MenuItem)10 Inject (javax.inject.Inject)9 Optional (org.eclipse.e4.core.di.annotations.Optional)9 MMenuSeparator (org.eclipse.e4.ui.model.application.ui.menu.MMenuSeparator)9 MPart (org.eclipse.e4.ui.model.application.ui.basic.MPart)7 MenuManagerRenderer (org.eclipse.e4.ui.workbench.renderers.swt.MenuManagerRenderer)7 Menu (org.eclipse.swt.widgets.Menu)7 IContributionItem (org.eclipse.jface.action.IContributionItem)6 PortfolioPart (name.abuchen.portfolio.ui.editor.PortfolioPart)5 Execute (org.eclipse.e4.core.di.annotations.Execute)5 MUIElement (org.eclipse.e4.ui.model.application.ui.MUIElement)5 IEclipseContext (org.eclipse.e4.core.contexts.IEclipseContext)4 CanExecute (org.eclipse.e4.core.di.annotations.CanExecute)4