Search in sources :

Example 1 with MPart

use of org.eclipse.e4.ui.model.application.ui.basic.MPart in project ACS by ACS-Community.

the class PeriodicRefreshHandler method execute.

/**
	 * Starts a {@link NotifyServiceUpdateJob} with 10 seconds refresh period,
	 * which will notify the interested parts via the IEventBroker.
	 * <p>
	 * An alternative implementation could get parameter <code>@Active MPart part</code> injected
	 * and notify the part directly, without IEventBroker.
	 */
@Execute
public void execute(MHandledItem handledItem) {
    // sync menu item state
    sharedIsSelected = handledItem.isSelected();
    for (MItem menuItem : menuItemsToSync.values()) {
        menuItem.setSelected(sharedIsSelected);
    }
    // start or stop the periodic refresh job
    if (sharedIsSelected) {
        if (job == null) {
            // start periodic refreshes
            job = new NotifyServiceUpdateJob(eventModel, sync, statusLineWriter, eventBroker, refreshDelaySeconds * 1000);
            job.schedule();
            System.out.println("Scheduled refresh job.");
        } else {
            System.out.println("Error: refresh job is already running!");
        }
    } else {
        if (job != null) {
            job.cancel();
            job = null;
            System.out.println("Cancelled refresh job.");
        } else {
            System.out.println("Error: refresh job is already cancelled!");
        }
    }
}
Also used : MItem(org.eclipse.e4.ui.model.application.ui.menu.MItem) CanExecute(org.eclipse.e4.core.di.annotations.CanExecute) Execute(org.eclipse.e4.core.di.annotations.Execute)

Example 2 with MPart

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

the class UIHelper method enableClose.

/**
 * @param site
 *            Site on which to enable/disable closing
 * @param enable_close
 *            Enable the close button, allow closing the part?
 */
public void enableClose(IWorkbenchPartSite site, boolean enable_close) {
    // TODO Improve implementation
    // Configure the E4 model element.
    // Issue 1:
    // When opening the display for the first time,
    // the 'x' in the tab is still displayed.
    // Only on _restart_ of the app will the tab be displayed
    // without the 'x' to close it.
    // Issue 2:
    // Part can still be closed via Ctrl-W (Command-W on OS X)
    // or via menu File/close.
    final MPart part = site.getService(MPart.class);
    part.setCloseable(false);
// Original RCP code
// PartPane currentEditorPartPane = ((PartSite) site)
// .getPane();
// PartStack stack = currentEditorPartPane.getStack();
// Control control = stack.getControl();
// if (control instanceof CTabFolder) {
// CTabFolder tabFolder = (CTabFolder) control;
// tabFolder.getSelection().setShowClose(false);
// }
}
Also used : MPart(org.eclipse.e4.ui.model.application.ui.basic.MPart)

Example 3 with MPart

use of org.eclipse.e4.ui.model.application.ui.basic.MPart in project nebula.widgets.nattable by eclipse.

the class LifecycleManager method preSave.

@PreSave
void preSave(EModelService modelService, MApplication app) {
    List<String> tags = new ArrayList<>();
    tags.add(CLOSE_ON_SHUTDOWN_TAG);
    List<MPart> elementsWithTags = modelService.findElements(app, null, MPart.class, tags);
    for (MPart part : elementsWithTags) {
        try {
            part.setToBeRendered(false);
            part.setVisible(false);
            MElementContainer<MUIElement> parent = part.getParent();
            parent.getChildren().remove(part);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
Also used : MPart(org.eclipse.e4.ui.model.application.ui.basic.MPart) ArrayList(java.util.ArrayList) MUIElement(org.eclipse.e4.ui.model.application.ui.MUIElement) PreSave(org.eclipse.e4.ui.workbench.lifecycle.PreSave)

Example 4 with MPart

use of org.eclipse.e4.ui.model.application.ui.basic.MPart in project nebula.widgets.nattable by eclipse.

the class NavigationPart method openExampleInTab.

private void openExampleInTab(final String examplePath) {
    final INatExample example = getExample(examplePath);
    if (example == null) {
        return;
    }
    MPartStack stack = (MPartStack) modelService.find("org.eclipse.nebula.widgets.nattable.examples.e4.partstack.0", app);
    MPart part = null;
    if (examplePath.startsWith("/" + E4_EXAMPLES_PREFIX)) {
        part = (MPart) modelService.find(example.getClass().getName(), app);
        if (part == null) {
            part = partService.createPart(example.getClass().getName());
            part.getTags().add(LifecycleManager.CLOSE_ON_SHUTDOWN_TAG);
            part.getTags().add(EPartService.REMOVE_ON_HIDE_TAG);
            stack.getChildren().add(part);
        }
    } else {
        part = partService.createPart("org.eclipse.nebula.widgets.nattable.examples.e4.partdescriptor.natexample");
        part.getTags().add(LifecycleManager.CLOSE_ON_SHUTDOWN_TAG);
        part.getTags().add(EPartService.REMOVE_ON_HIDE_TAG);
        part.getTransientData().put("example", example);
        part.getTransientData().put("examplePath", examplePath);
        stack.getChildren().add(part);
    }
    part.setLabel(example.getName());
    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) INatExample(org.eclipse.nebula.widgets.nattable.examples.INatExample)

Example 5 with MPart

use of org.eclipse.e4.ui.model.application.ui.basic.MPart in project org.csstudio.display.builder by kasemir.

the class RuntimeViewPart method persist.

/**
 * Persist the view's input "on demand".
 *
 *  <p>Framework only persists to memento on exit,
 *  and only for the currently visible views.
 *
 *  <p>Display info for views in other perspectives
 *  which are hidden on application shutdown will be lost.
 *  By forcing a persist for each view while the app is still running,
 *  each view can be restored when a perspective is later re-activated.
 *
 *  <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() {
    try {
        // Obtain E4 model element for E3 view,
        // based on http://www.vogella.com/tutorials/EclipsePlugIn/article.html#eclipsecontext
        final IEclipseContext context = getViewSite().getService(IEclipseContext.class);
        final MPart part = 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();
        root.save(writer);
        part.getPersistedState().put(TAG_MEMENTO, writer.toString());
    } catch (Exception ex) {
        logger.log(Level.WARNING, "Cannot persist " + display_info, 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)

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