Search in sources :

Example 1 with IEclipseContext

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$
*/
}
Also used : IEclipseContext(org.eclipse.e4.core.contexts.IEclipseContext) IThemeEngine(org.eclipse.e4.ui.css.swt.theme.IThemeEngine) MApplication(org.eclipse.e4.ui.model.application.MApplication)

Example 2 with IEclipseContext

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);
    }
}
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 3 with IEclipseContext

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;
}
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 4 with IEclipseContext

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;
}
Also used : E4GraphicalViewer(org.whole.lang.e4.ui.viewers.E4GraphicalViewer) IContributionItem(org.eclipse.jface.action.IContributionItem) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) IImportAsModelDialogFactory(org.whole.lang.ui.dialogs.IImportAsModelDialogFactory) IPartFocusListener(org.whole.lang.ui.editparts.IPartFocusListener) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) FocusEvent(org.eclipse.swt.events.FocusEvent) ActionRegistry(org.whole.lang.e4.ui.actions.ActionRegistry) ContextMenuProvider(org.eclipse.gef.ContextMenuProvider) JFaceMenuBuilder(org.whole.lang.e4.ui.menu.JFaceMenuBuilder) E4KeyHandler(org.whole.lang.e4.ui.actions.E4KeyHandler) IEclipseContext(org.eclipse.e4.core.contexts.IEclipseContext) GridData(org.eclipse.swt.layout.GridData) E4NavigationKeyHandler(org.whole.lang.e4.ui.actions.E4NavigationKeyHandler) IMenuManager(org.eclipse.jface.action.IMenuManager) FocusListener(org.eclipse.swt.events.FocusListener) IPartFocusListener(org.whole.lang.ui.editparts.IPartFocusListener) IEntityPartViewer(org.whole.lang.ui.viewers.IEntityPartViewer) IEntityPart(org.whole.lang.ui.editparts.IEntityPart)

Example 5 with IEclipseContext

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");
    }
}
Also used : IEntity(org.whole.lang.model.IEntity) QueriesEntityFactory(org.whole.lang.queries.factories.QueriesEntityFactory) IEclipseContext(org.eclipse.e4.core.contexts.IEclipseContext) ActionFactory(org.whole.lang.e4.ui.actions.ActionFactory)

Aggregations

IEclipseContext (org.eclipse.e4.core.contexts.IEclipseContext)195 Test (org.junit.Test)142 RunAndTrack (org.eclipse.e4.core.contexts.RunAndTrack)18 ContextFunction (org.eclipse.e4.core.contexts.ContextFunction)17 BundleContext (org.osgi.framework.BundleContext)15 IEntity (org.whole.lang.model.IEntity)11 IEntityPartViewer (org.whole.lang.ui.viewers.IEntityPartViewer)9 Execute (org.eclipse.e4.core.di.annotations.Execute)7 MPart (org.eclipse.e4.ui.model.application.ui.basic.MPart)6 IImportAsModelDialogFactory (org.whole.lang.ui.dialogs.IImportAsModelDialogFactory)6 Hashtable (java.util.Hashtable)5 PrimaryObjectSupplier (org.eclipse.e4.core.di.suppliers.PrimaryObjectSupplier)4 Named (javax.inject.Named)3 PerformanceTestRunner (org.eclipse.core.tests.harness.PerformanceTestRunner)3 InjectionException (org.eclipse.e4.core.di.InjectionException)3 CanExecute (org.eclipse.e4.core.di.annotations.CanExecute)3 Optional (org.eclipse.e4.core.di.annotations.Optional)3 UISynchronize (org.eclipse.e4.ui.di.UISynchronize)3 ContextMenuProvider (org.eclipse.gef.ContextMenuProvider)3 IMenuManager (org.eclipse.jface.action.IMenuManager)3