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);
}
}
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;
}
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) {
}
}
}
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();
}
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);
}
}
Aggregations