Search in sources :

Example 21 with MPart

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

the class OPIView method persist.

/**
 * Persist the view's input "on demand".
 *
 * <p>
 * To allow saving the memento at any time.
 *
 * <p>
 * Memento is saved in the .metadata/.plugins/org.eclipse.e4.workbench/workbench.xmi inside a "persistedState"
 * element of the E4 model element.
 *
 * <p>
 * This method places it in the model just as the framework does by calling saveState() on shutdown, but allows
 * saving the state at any time.
 */
private void persist() {
    // Obtain E4 model element for E3 view,
    // based on http://www.vogella.com/tutorials/EclipsePlugIn/article.html#eclipsecontext
    final IEclipseContext context = (IEclipseContext) getViewSite().getService(IEclipseContext.class);
    final MPart model = context.get(MPart.class);
    // Based on org.eclipse.ui.internal.ViewReference#persist():
    // 
    // XML version of memento is written to E4 model.
    // If compatibility layer changes its memento persistence,
    // this will break...
    // $NON-NLS-1$
    final XMLMemento root = XMLMemento.createWriteRoot("view");
    saveState(root);
    final StringWriter writer = new StringWriter();
    try {
        root.save(writer);
        model.getPersistedState().put(TAG_MEMENTO, writer.toString());
    } catch (Exception ex) {
        OPIBuilderPlugin.getLogger().log(Level.WARNING, toString() + " failed to persist input", ex);
    }
}
Also used : MPart(org.eclipse.e4.ui.model.application.ui.basic.MPart) XMLMemento(org.eclipse.ui.XMLMemento) StringWriter(java.io.StringWriter) IEclipseContext(org.eclipse.e4.core.contexts.IEclipseContext) WorkbenchException(org.eclipse.ui.WorkbenchException) PartInitException(org.eclipse.ui.PartInitException)

Example 22 with MPart

use of org.eclipse.e4.ui.model.application.ui.basic.MPart 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 23 with MPart

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

the class E4ResourceBindingsContributor method addResourceBindings.

public void addResourceBindings(final IBindingManager bm) {
    if (bm.wIsSet("debug#breakpointsEnabled") && bm.wIsSet("eclipse#eclipseContext")) {
        try {
            EPartService partService = ((IEclipseContext) bm.wGetValue("eclipse#eclipseContext")).get(EPartService.class);
            final MPart debugPart = partService.findPart(IE4UIConstants.DEBUG_PART_ID);
            if (debugPart == null)
                return;
            IEntity breakpointsEnabled = BindingManagerFactory.instance.createValue(true);
            breakpointsEnabled.wAddRequestEventHandler(new IdentityRequestEventHandler() {

                public boolean notifyRequested(IEntity source, FeatureDescriptor feature, boolean value) {
                    Map<String, String> persistedState = debugPart.getPersistedState();
                    return Boolean.valueOf(persistedState.get("debug#breakpointsEnabled"));
                }
            });
            bm.wSet("debug#breakpointsEnabled", breakpointsEnabled);
        } catch (Exception e) {
        }
    }
}
Also used : MPart(org.eclipse.e4.ui.model.application.ui.basic.MPart) IEntity(org.whole.lang.model.IEntity) FeatureDescriptor(org.whole.lang.reflect.FeatureDescriptor) EPartService(org.eclipse.e4.ui.workbench.modeling.EPartService) IEclipseContext(org.eclipse.e4.core.contexts.IEclipseContext) Map(java.util.Map) IdentityRequestEventHandler(org.whole.lang.events.IdentityRequestEventHandler)

Example 24 with MPart

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

the class UpdateQuotesHandler method execute.

@Execute
public void execute(@Named(IServiceConstants.ACTIVE_PART) MPart part, @Named(IServiceConstants.ACTIVE_SHELL) Shell shell) {
    Client client = MenuHelper.getActiveClient(part);
    if (client == null)
        return;
    new UpdateQuotesJob(client, EnumSet.of(UpdateQuotesJob.Target.LATEST)).schedule();
}
Also used : UpdateQuotesJob(name.abuchen.portfolio.ui.UpdateQuotesJob) Client(name.abuchen.portfolio.model.Client) CanExecute(org.eclipse.e4.core.di.annotations.CanExecute) Execute(org.eclipse.e4.core.di.annotations.Execute)

Example 25 with MPart

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

the class OpenErrorLogFileHandler method execute.

@Execute
public void execute(@Named(IServiceConstants.ACTIVE_SHELL) Shell shell, // 
@Named(E4Workbench.INSTANCE_LOCATION) Location instanceLocation, MApplication app, EPartService partService, EModelService modelService) {
    // $NON-NLS-1$
    File logfile = new File(instanceLocation.getURL().getFile(), ".metadata/.log");
    if (!logfile.exists()) {
        MessageDialog.openError(shell, Messages.LabelError, MessageFormat.format(Messages.MsgErrorOpeningFile, logfile.getAbsoluteFile()));
    } else {
        MPart part = partService.createPart(UIConstants.Part.TEXT_VIEWER);
        part.getPersistedState().put(UIConstants.File.PERSISTED_STATE_KEY, logfile.getAbsolutePath());
        MPartStack stack = (MPartStack) modelService.find(UIConstants.PartStack.MAIN, app);
        stack.getChildren().add(part);
        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)

Aggregations

Execute (org.eclipse.e4.core.di.annotations.Execute)20 MPart (org.eclipse.e4.ui.model.application.ui.basic.MPart)19 Client (name.abuchen.portfolio.model.Client)12 CanExecute (org.eclipse.e4.core.di.annotations.CanExecute)11 File (java.io.File)7 MPartStack (org.eclipse.e4.ui.model.application.ui.basic.MPartStack)7 IEclipseContext (org.eclipse.e4.core.contexts.IEclipseContext)6 PortfolioPart (name.abuchen.portfolio.ui.PortfolioPart)5 WizardDialog (org.eclipse.jface.wizard.WizardDialog)5 FileDialog (org.eclipse.swt.widgets.FileDialog)5 Dialog (org.eclipse.jface.dialogs.Dialog)4 IOException (java.io.IOException)3 ArrayList (java.util.ArrayList)3 MUIElement (org.eclipse.e4.ui.model.application.ui.MUIElement)3 IPreferenceStore (org.eclipse.jface.preference.IPreferenceStore)3 StringWriter (java.io.StringWriter)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 List (java.util.List)2 Named (javax.inject.Named)2 Extractor (name.abuchen.portfolio.datatransfer.Extractor)2