Search in sources :

Example 6 with MApplication

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

the class NewFileHandler method execute.

@Execute
public void execute(@Named(IServiceConstants.ACTIVE_SHELL) Shell shell, // 
@Optional @Named(IServiceConstants.ACTIVE_PART) MPart activePart, MApplication app, EPartService partService, EModelService modelService) {
    NewClientWizard wizard = new NewClientWizard();
    WizardDialog dialog = new WizardDialog(shell, wizard);
    if (dialog.open() == Window.OK) {
        MPart part = partService.createPart(UIConstants.Part.PORTFOLIO);
        part.setLabel(Messages.LabelUnnamedXml);
        part.getTransientData().put(Client.class.getName(), wizard.getClient());
        if (activePart != null)
            activePart.getParent().getChildren().add(part);
        else
            ((MPartStack) modelService.find(UIConstants.PartStack.MAIN, app)).getChildren().add(part);
        part.setVisible(true);
        part.getParent().setVisible(true);
        partService.showPart(part, PartState.ACTIVATE);
    }
}
Also used : NewClientWizard(name.abuchen.portfolio.ui.wizards.client.NewClientWizard) MPart(org.eclipse.e4.ui.model.application.ui.basic.MPart) MPartStack(org.eclipse.e4.ui.model.application.ui.basic.MPartStack) Client(name.abuchen.portfolio.model.Client) WizardDialog(org.eclipse.jface.wizard.WizardDialog) Execute(org.eclipse.e4.core.di.annotations.Execute)

Example 7 with MApplication

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

the class OpenRecentFileHandler method execute.

@Execute
public void execute(@Named(IServiceConstants.ACTIVE_SHELL) Shell shell, // 
@Optional @Named(IServiceConstants.ACTIVE_PART) MPart activePart, MApplication app, EPartService partService, EModelService modelService, @Named("name.abuchen.portfolio.ui.param.file") String file) {
    MPart part = partService.createPart(UIConstants.Part.PORTFOLIO);
    part.setLabel(new File(file).getName());
    part.setTooltip(file);
    part.getPersistedState().put(UIConstants.File.PERSISTED_STATE_KEY, file);
    if (activePart != null)
        activePart.getParent().getChildren().add(part);
    else
        ((MPartStack) modelService.find(UIConstants.PartStack.MAIN, app)).getChildren().add(part);
    part.setVisible(true);
    part.getParent().setVisible(true);
    partService.showPart(part, PartState.ACTIVATE);
}
Also used : MPart(org.eclipse.e4.ui.model.application.ui.basic.MPart) MPartStack(org.eclipse.e4.ui.model.application.ui.basic.MPartStack) File(java.io.File) Execute(org.eclipse.e4.core.di.annotations.Execute)

Example 8 with MApplication

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

the class OpenSampleHandler method execute.

@Execute
public void execute(// 
@Named(IServiceConstants.ACTIVE_SHELL) Shell shell, // 
final MApplication app, final EPartService partService, final EModelService modelService, @Named(UIConstants.Parameter.SAMPLE_FILE) final String sampleFile) {
    try {
        IRunnableWithProgress loadResourceOperation = new IRunnableWithProgress() {

            @Override
            public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                try (InputStream in = this.getClass().getResourceAsStream(sampleFile)) {
                    InputStream inputStream = new ProgressMonitorInputStream(in, monitor);
                    Reader replacingReader = new TokenReplacingReader(new InputStreamReader(inputStream, StandardCharsets.UTF_8), buildResourcesTokenResolver());
                    final Client client = ClientFactory.load(replacingReader);
                    fixTaxonomyLabels(client);
                    sync.asyncExec(() -> {
                        MPart part = partService.createPart(UIConstants.Part.PORTFOLIO);
                        part.setLabel(sampleFile.substring(sampleFile.lastIndexOf('/') + 1));
                        part.getTransientData().put(Client.class.getName(), client);
                        MPartStack stack = (MPartStack) modelService.find(UIConstants.PartStack.MAIN, app);
                        stack.getChildren().add(part);
                        partService.showPart(part, PartState.ACTIVATE);
                    });
                } catch (IOException ignore) {
                    PortfolioPlugin.log(ignore);
                }
            }
        };
        new ProgressMonitorDialog(shell).run(true, true, loadResourceOperation);
    } catch (InvocationTargetException | InterruptedException e) {
        PortfolioPlugin.log(e);
    }
}
Also used : ProgressMonitorInputStream(name.abuchen.portfolio.util.ProgressMonitorInputStream) MPart(org.eclipse.e4.ui.model.application.ui.basic.MPart) InputStreamReader(java.io.InputStreamReader) MPartStack(org.eclipse.e4.ui.model.application.ui.basic.MPartStack) ProgressMonitorInputStream(name.abuchen.portfolio.util.ProgressMonitorInputStream) InputStream(java.io.InputStream) ProgressMonitorDialog(org.eclipse.jface.dialogs.ProgressMonitorDialog) TokenReplacingReader(name.abuchen.portfolio.util.TokenReplacingReader) Reader(java.io.Reader) InputStreamReader(java.io.InputStreamReader) IOException(java.io.IOException) InvocationTargetException(java.lang.reflect.InvocationTargetException) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) TokenReplacingReader(name.abuchen.portfolio.util.TokenReplacingReader) Client(name.abuchen.portfolio.model.Client) Execute(org.eclipse.e4.core.di.annotations.Execute)

Example 9 with MApplication

use of org.eclipse.e4.ui.model.application.MApplication in project yamcs-studio by yamcs.

the class OPIView method findPlaceholder.

/**
 * Find the MPlaceholder corresponding to this MPart in the MPerspective. This may have persisted information
 * relevant to loading this OPIView.
 *
 * @return corresponding placeholder
 */
private MPlaceholder findPlaceholder() {
    // do not remove casting - RAP 3.0 still needs it
    final IEclipseContext localContext = (IEclipseContext) getViewSite().getService(IEclipseContext.class);
    final MPart part = localContext.get(MPart.class);
    final EModelService service = (EModelService) PlatformUI.getWorkbench().getService(EModelService.class);
    final IEclipseContext globalContext = (IEclipseContext) PlatformUI.getWorkbench().getService(IEclipseContext.class);
    final MApplication app = globalContext.get(MApplication.class);
    final List<MPlaceholder> phs = service.findElements(app, null, MPlaceholder.class, null);
    for (MPlaceholder ph : phs) {
        if (ph.getRef() == part) {
            return ph;
        }
    }
    return null;
}
Also used : MPart(org.eclipse.e4.ui.model.application.ui.basic.MPart) EModelService(org.eclipse.e4.ui.workbench.modeling.EModelService) MPlaceholder(org.eclipse.e4.ui.model.application.ui.advanced.MPlaceholder) IEclipseContext(org.eclipse.e4.core.contexts.IEclipseContext) MApplication(org.eclipse.e4.ui.model.application.MApplication)

Example 10 with MApplication

use of org.eclipse.e4.ui.model.application.MApplication in project whole by wholeplatform.

the class E4Utils method findMenu.

@SuppressWarnings("unchecked")
public static <T> T findMenu(String elementId, EModelService modelService, MApplication application, Class<T> type) {
    for (MWindow window : modelService.findElements(application, null, MWindow.class, null)) {
        MMenu mainMenu = window.getMainMenu();
        if (mainMenu == null)
            continue;
        MMenuElement menuElement = findMenu(elementId, mainMenu);
        if (menuElement != null)
            return (T) menuElement;
    }
    return null;
}
Also used : MWindow(org.eclipse.e4.ui.model.application.ui.basic.MWindow) MMenu(org.eclipse.e4.ui.model.application.ui.menu.MMenu) MMenuElement(org.eclipse.e4.ui.model.application.ui.menu.MMenuElement)

Aggregations

MPart (org.eclipse.e4.ui.model.application.ui.basic.MPart)9 MApplication (org.eclipse.e4.ui.model.application.MApplication)6 IEclipseContext (org.eclipse.e4.core.contexts.IEclipseContext)5 Execute (org.eclipse.e4.core.di.annotations.Execute)5 MPartStack (org.eclipse.e4.ui.model.application.ui.basic.MPartStack)5 File (java.io.File)3 Client (name.abuchen.portfolio.model.Client)2 IThemeEngine (org.eclipse.e4.ui.css.swt.theme.IThemeEngine)2 MUIElement (org.eclipse.e4.ui.model.application.ui.MUIElement)2 MPlaceholder (org.eclipse.e4.ui.model.application.ui.advanced.MPlaceholder)2 EModelService (org.eclipse.e4.ui.workbench.modeling.EModelService)2 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 InputStreamReader (java.io.InputStreamReader)1 Reader (java.io.Reader)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 ArrayList (java.util.ArrayList)1 NewClientWizard (name.abuchen.portfolio.ui.wizards.client.NewClientWizard)1 ProgressMonitorInputStream (name.abuchen.portfolio.util.ProgressMonitorInputStream)1 TokenReplacingReader (name.abuchen.portfolio.util.TokenReplacingReader)1