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!");
}
}
}
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);
// }
}
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();
}
}
}
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);
}
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);
}
}
Aggregations