use of org.eclipse.e4.core.contexts.IEclipseContext in project archi by archimatetool.
the class GeneralPreferencePage method init.
public void init(IWorkbench workbench) {
// e4 method (taken from org.eclipse.ui.internal.dialogs.ViewsPreferencePage init(IWorkbench))
MApplication application = workbench.getService(MApplication.class);
IEclipseContext context = application.getContext();
// This is "org.eclipse.e4.ui.css.theme.e4_default" //$NON-NLS-1$
fDefaultTheme = (String) context.get("cssTheme");
fThemeEngine = context.get(IThemeEngine.class);
fCurrentTheme = fThemeEngine.getActiveTheme();
/*
// e3 method
Bundle bundle = FrameworkUtil.getBundle(ArchiPlugin.class);
BundleContext context = bundle.getBundleContext();
ServiceReference<IThemeManager> ref = context.getServiceReference(IThemeManager.class);
IThemeManager themeManager = context.getService(ref);
fThemeEngine = themeManager.getEngineForDisplay(Display.getCurrent());
fDefaultTheme = "org.eclipse.e4.ui.css.theme.e4_default"; //$NON-NLS-1$
*/
}
use of org.eclipse.e4.core.contexts.IEclipseContext 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);
}
}
use of org.eclipse.e4.core.contexts.IEclipseContext in project org.csstudio.display.builder by kasemir.
the class RuntimeViewPart method findPlaceholder.
/**
* Find the MPlaceholder corresponding to this MPart in the MPerspective. This
* may have persisted information relevant to loading this view.
* @return corresponding placeholder or <code>null</code>
*/
private MPlaceholder findPlaceholder() {
final IEclipseContext localContext = getViewSite().getService(IEclipseContext.class);
final MPart part = localContext.get(MPart.class);
final EModelService service = PlatformUI.getWorkbench().getService(EModelService.class);
final IEclipseContext globalContext = 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.core.contexts.IEclipseContext in project whole by wholeplatform.
the class ModelMergeViewer method createMergeArea.
protected Control createMergeArea(Composite parent) {
IImportAsModelDialogFactory factory = ContextInjectionFactory.make(ImportAsModelDialogFactory.class, getContext());
IEclipseContext params = EclipseContextFactory.create();
params.set("parent", parent);
params.set(IImportAsModelDialogFactory.class, factory);
viewer = ContextInjectionFactory.make(E4GraphicalViewer.class, getContext(), params);
viewer.getControl().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
viewer.addSelectionChangedListener(new ISelectionChangedListener() {
@Override
public void selectionChanged(SelectionChangedEvent event) {
updateSelection(E4Utils.createSelectionBindings(event, getContext()));
}
});
viewer.getControl().addFocusListener(new FocusListener() {
@Override
public void focusLost(FocusEvent event) {
}
@SuppressWarnings("unchecked")
@Override
public void focusGained(FocusEvent event) {
getContext().set(IEntityPartViewer.class, viewer);
getContext().set(ActionRegistry.class, actionRegistry);
updateSelection(E4Utils.createSelectionBindings(viewer.getSelectedEditParts(), viewer, getContext()));
}
});
viewer.addPartFocusListener(new IPartFocusListener() {
@SuppressWarnings("unchecked")
public void focusChanged(IEntityPart oldPart, IEntityPart newPart) {
updateSelection(E4Utils.createSelectionBindings(viewer.getSelectedEditParts(), viewer, getContext()));
}
});
E4KeyHandler keyHandler = new E4KeyHandler(getContext());
keyHandler.setParent(new E4NavigationKeyHandler(getContext()));
viewer.setKeyHandler(keyHandler);
viewer.setEntityContents(createDefaultContents());
getContext().set(IEntityPartViewer.class, viewer);
actionRegistry = ContextInjectionFactory.make(ActionRegistry.class, getContext());
actionRegistry.registerWorkbenchActions();
getContext().set(ActionRegistry.class, actionRegistry);
JFaceMenuBuilder uiBuilder = ContextInjectionFactory.make(JFaceMenuBuilder.class, getContext());
contextMenuProvider = new PopupMenuProvider<IContributionItem, IMenuManager>(uiBuilder);
viewer.setContextMenu(new ContextMenuProvider(viewer) {
@Override
public void buildContextMenu(IMenuManager menuManager) {
contextMenuProvider.populate(menuManager);
}
});
return parent;
}
use of org.eclipse.e4.core.contexts.IEclipseContext in project whole by wholeplatform.
the class ActionsE4InterpreterVisitor method createAction.
protected IAction createAction(Value kind, IEnablerPredicate enablerPredicate, IEntityTransformer transformer, IEntity prototype, String text) {
// FIXME transformer always passed as null
IEclipseContext context = (IEclipseContext) getBindings().wGetValue("context");
ActionFactory actionRegistry = new ActionFactory(context);
QueriesEntityFactory qf = QueriesEntityFactory.instance;
IEntity predicate = enablerPredicate instanceof OpaqueEnablerPredicate ? ((OpaqueEnablerPredicate) enablerPredicate).value : qf.createBooleanLiteral(true);
switch(kind.getOrdinal()) {
case ActionKindEnum.REPLACE_ord:
return actionRegistry.createReplaceFragmentAction(text, predicate, prototype);
case ActionKindEnum.INSERT_ord:
return actionRegistry.createAddFragmentAction(text, predicate, prototype);
case ActionKindEnum.WRAP_ord:
IEntity behavior = qf.createPointwiseUpdate(qf.createVariableRefStep("focusEntity"), CommonsEntityAdapterFactory.createStageUpFragment(QueriesEntityDescriptorEnum.Expression, prototype));
return actionRegistry.createPerformAction(text, WRAP_ICON_URI, predicate, behavior);
case ActionKindEnum.PERFORM_ord:
return actionRegistry.createPerformAction(text, WRAP_ICON_URI, predicate, prototype);
default:
throw new IllegalArgumentException("not implemented yet");
}
}
Aggregations