Search in sources :

Example 1 with IWorkbench

use of org.eclipse.e4.ui.workbench.IWorkbench 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 IWorkbench

use of org.eclipse.e4.ui.workbench.IWorkbench in project AGREE by loonwerks.

the class VariablesViewPart method getEventBroker.

private IEventBroker getEventBroker() {
    final IEclipseContext ctx = Objects.requireNonNull(EclipseContextFactory.getServiceContext(FrameworkUtil.getBundle(getClass()).getBundleContext()), "unable to retrieve OSGI context");
    final IWorkbench workbench = Objects.requireNonNull(ctx.get(IWorkbench.class), "unable to retrieve E4 workbench");
    final IEventBroker eventBroker = Objects.requireNonNull(workbench.getApplication().getContext().get(IEventBroker.class), "unable to retrieve event broker");
    return eventBroker;
}
Also used : IWorkbench(org.eclipse.e4.ui.workbench.IWorkbench) IEclipseContext(org.eclipse.e4.core.contexts.IEclipseContext) IEventBroker(org.eclipse.e4.core.services.events.IEventBroker)

Example 3 with IWorkbench

use of org.eclipse.e4.ui.workbench.IWorkbench in project whole by wholeplatform.

the class QuitHandler method execute.

@Execute
public void execute(EPartService partService, IWorkbench workbench, Shell shell) {
    IEclipsePreferences preferences = InstanceScope.INSTANCE.getNode("org.whole.product.e4.lw");
    boolean exitWithoutPrompt = preferences.getBoolean("exitWithoutPrompt", false);
    if (exitWithoutPrompt) {
        safeCloseWorkbench(partService, workbench);
        return;
    }
    MessageDialogWithToggle dialog = MessageDialogWithToggle.openOkCancelConfirm(shell, "Confirm exit", "Exit Whole Platform?", "Always exit without prompt", exitWithoutPrompt, null, null);
    if (dialog.getReturnCode() == Window.OK) {
        preferences.putBoolean("exitWithoutPrompt", dialog.getToggleState());
        try {
            preferences.flush();
        } catch (BackingStoreException e) {
        }
        safeCloseWorkbench(partService, workbench);
    }
}
Also used : IEclipsePreferences(org.eclipse.core.runtime.preferences.IEclipsePreferences) BackingStoreException(org.osgi.service.prefs.BackingStoreException) MessageDialogWithToggle(org.eclipse.jface.dialogs.MessageDialogWithToggle) Execute(org.eclipse.e4.core.di.annotations.Execute)

Example 4 with IWorkbench

use of org.eclipse.e4.ui.workbench.IWorkbench in project aero.minova.rcp by minova-afis.

the class ApplicationPreferenceWindowHandler method execute.

@Execute
public void execute(IThemeEngine themeEngine, IWorkbench workbench, IEclipseContext context) {
    pwm = new PreferenceWindowModel(s);
    // In Context injected, damit TranslationService genutzt werden kann
    ContextInjectionFactory.inject(pwm, application.getContext());
    this.workbench = workbench;
    // Shell des Windows der Application finden
    MWindow appWindow = application.getChildren().get(0);
    Shell shell = (Shell) appWindow.getWidget();
    // Die Shell des Windows deaktivieren
    shell.setEnabled(false);
    String currentTheme = (String) InstancePreferenceAccessor.getValue(preferences, ApplicationPreferences.FONT_ICON_SIZE, DisplayType.COMBO, "M", s);
    boolean curentSelectAllControls = (boolean) InstancePreferenceAccessor.getValue(preferences, ApplicationPreferences.SELECT_ALL_CONTROLS, DisplayType.CHECK, true, s);
    List<PreferenceTabDescriptor> preferenceTabs = pwm.createModel(context);
    Map<String, Object> data = fillData(preferenceTabs);
    PreferenceWindow window = PreferenceWindow.create(shell, data);
    for (PreferenceTabDescriptor tabDescriptor : preferenceTabs) {
        // Tab erstellen und hinzufügen
        PWTab newTab = window.addTab(tabDescriptor.getImage(), tabDescriptor.getLabel());
        for (PreferenceSectionDescriptor section : tabDescriptor.getSections()) {
            // Section hinzufügen
            newTab.add(new PWSeparator(section.getLabel()));
            for (PreferenceDescriptor pref : section.getPreferences()) {
                // Preference hinzufügen
                Object[] values = pref.getPossibleValues();
                String key = pref.getKey();
                createWidgets(newTab, pref, key, translationService, values);
            }
        }
    }
    // Preference Handler finden
    List<MHandler> preferenceHandlers = modelService.findElements(application, "aero.minova.rcp.rcp.handler.preferencehandler", MHandler.class);
    MHandler preferenceHandler = preferenceHandlers.get(0);
    // Preference Handler deaktivieren
    handlerService.deactivateHandler("org.eclipse.ui.window.preferences", preferenceHandler.getObject());
    window.setSelectedTab(0);
    if (window.open()) {
        InstancePreferenceAccessor.putValue(preferences, ApplicationPreferences.TIMEZONE, DisplayType.ZONEID, window.getValueFor(ApplicationPreferences.TIMEZONE), s);
        InstancePreferenceAccessor.putValue(preferences, ApplicationPreferences.LOCALE_LANGUAGE, DisplayType.LOCALE, window.getValueFor(ApplicationPreferences.LOCALE_LANGUAGE), s);
        InstancePreferenceAccessor.putValue(preferences, ApplicationPreferences.COUNTRY, DisplayType.LOCALE, window.getValueFor(ApplicationPreferences.COUNTRY), s);
        for (PreferenceTabDescriptor tab : preferenceTabs) {
            for (PreferenceSectionDescriptor section : tab.getSections()) {
                for (PreferenceDescriptor pref : section.getPreferences()) {
                    if (pref.getDisplayType() != DisplayType.ZONEID && pref.getDisplayType() != DisplayType.CUSTOMCHECK) {
                        InstancePreferenceAccessor.putValue(preferences, pref.getKey(), pref.getDisplayType(), window.getValueFor(pref.getKey()), s);
                    }
                }
            }
        }
        try {
            preferences.flush();
            lcs.changeApplicationLocale(CustomLocale.getLocale());
        } catch (BackingStoreException | NullPointerException e) {
            e.printStackTrace();
        }
    }
    if (Util.isValid(shell)) {
        // Die Shell des Windows aktivieren
        shell.setEnabled(true);
        // Preference Handler wieder aktivieren
        handlerService.activateHandler("org.eclipse.ui.window.preferences", preferenceHandler.getObject());
    }
    boolean newSelectAllControls = (boolean) InstancePreferenceAccessor.getValue(preferences, ApplicationPreferences.SELECT_ALL_CONTROLS, DisplayType.CHECK, true, s);
    String newTheme = (String) InstancePreferenceAccessor.getValue(preferences, ApplicationPreferences.FONT_ICON_SIZE, DisplayType.COMBO, "M", s);
    if (!currentTheme.equals(newTheme) || !curentSelectAllControls == newSelectAllControls) {
        Shell activeShell = Display.getCurrent().getActiveShell();
        PlainMessageDialog confirmRestart = getBuilder(activeShell, translationService.translate("@Action.Restart", null)).buttonLabels(List.of(translationService.translate("@Action.Restart", null), translationService.translate("@Abort", null))).message(translationService.translate("@Preferences.RestartMessage", null)).build();
        int openConfirm = confirmRestart.open();
        if (openConfirm == 0) {
            if (!currentTheme.equals(newTheme)) {
                updateTheme(newTheme, themeEngine, workbench);
            } else {
                workbench.restart();
            }
        }
    }
}
Also used : PlainMessageDialog(org.eclipse.jface.dialogs.PlainMessageDialog) PreferenceWindow(org.eclipse.nebula.widgets.opal.preferencewindow.PreferenceWindow) MHandler(org.eclipse.e4.ui.model.application.commands.MHandler) PreferenceWindowModel(aero.minova.rcp.preferencewindow.builder.PreferenceWindowModel) PreferenceTabDescriptor(aero.minova.rcp.preferencewindow.builder.PreferenceTabDescriptor) PreferenceDescriptor(aero.minova.rcp.preferencewindow.builder.PreferenceDescriptor) BackingStoreException(org.osgi.service.prefs.BackingStoreException) PreferenceSectionDescriptor(aero.minova.rcp.preferencewindow.builder.PreferenceSectionDescriptor) MWindow(org.eclipse.e4.ui.model.application.ui.basic.MWindow) Shell(org.eclipse.swt.widgets.Shell) PWSeparator(org.eclipse.nebula.widgets.opal.preferencewindow.widgets.PWSeparator) PWTab(org.eclipse.nebula.widgets.opal.preferencewindow.PWTab) Execute(org.eclipse.e4.core.di.annotations.Execute)

Example 5 with IWorkbench

use of org.eclipse.e4.ui.workbench.IWorkbench in project eclipse.platform.ui by eclipse-platform.

the class CommandServiceFactory method create.

@Override
public Object create(Class serviceInterface, IServiceLocator parentLocator, IServiceLocator locator) {
    if (!ICommandService.class.equals(serviceInterface)) {
        return null;
    }
    IWorkbenchLocationService wls = locator.getService(IWorkbenchLocationService.class);
    final IWorkbench wb = wls.getWorkbench();
    if (wb == null) {
        return null;
    }
    Object parent = parentLocator.getService(serviceInterface);
    if (parent == null) {
        // we are registering the global services in the Workbench
        return null;
    }
    final IWorkbenchWindow window = wls.getWorkbenchWindow();
    final IWorkbenchPartSite site = wls.getPartSite();
    if (site == null) {
        return new SlaveCommandService((ICommandService) parent, IServiceScopes.WINDOW_SCOPE, window);
    }
    if (parent instanceof SlaveCommandService) {
        IServiceLocator pageSite = wls.getPageSite();
        if (pageSite != null) {
            MContext context = pageSite.getService(MContext.class);
            if (context == null) {
                return new SlaveCommandService((ICommandService) parent, IServiceScopes.PAGESITE_SCOPE, pageSite);
            }
            return new SlaveCommandService((ICommandService) parent, IServiceScopes.PAGESITE_SCOPE, pageSite, context.getContext());
        }
        IServiceLocator mpepSite = wls.getMultiPageEditorSite();
        if (mpepSite != null) {
            MContext context = mpepSite.getService(MContext.class);
            if (context == null) {
                return new SlaveCommandService((ICommandService) parent, IServiceScopes.MPESITE_SCOPE, mpepSite);
            }
            return new SlaveCommandService((ICommandService) parent, IServiceScopes.MPESITE_SCOPE, mpepSite, context.getContext());
        }
    }
    return new SlaveCommandService((ICommandService) parent, IServiceScopes.PARTSITE_SCOPE, site);
}
Also used : IWorkbench(org.eclipse.ui.IWorkbench) IWorkbenchPartSite(org.eclipse.ui.IWorkbenchPartSite) IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) IWorkbenchLocationService(org.eclipse.ui.internal.services.IWorkbenchLocationService) IServiceLocator(org.eclipse.ui.services.IServiceLocator) MContext(org.eclipse.e4.ui.model.application.ui.MContext) ICommandService(org.eclipse.ui.commands.ICommandService)

Aggregations

IWorkbench (org.eclipse.ui.IWorkbench)9 IEclipseContext (org.eclipse.e4.core.contexts.IEclipseContext)8 MApplication (org.eclipse.e4.ui.model.application.MApplication)7 IThemeEngine (org.eclipse.e4.ui.css.swt.theme.IThemeEngine)4 MWindow (org.eclipse.e4.ui.model.application.ui.basic.MWindow)4 Shell (org.eclipse.swt.widgets.Shell)4 CoreException (org.eclipse.core.runtime.CoreException)3 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)3 IEventBroker (org.eclipse.e4.core.services.events.IEventBroker)3 ULocale (com.ibm.icu.util.ULocale)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 Hashtable (java.util.Hashtable)2 UpdateHelper (name.abuchen.portfolio.ui.update.UpdateHelper)2 Command (org.eclipse.core.commands.Command)2 Job (org.eclipse.core.runtime.jobs.Job)2 Execute (org.eclipse.e4.core.di.annotations.Execute)2 EModelService (org.eclipse.e4.ui.workbench.modeling.EModelService)2 EPartService (org.eclipse.e4.ui.workbench.modeling.EPartService)2 Dialog (org.eclipse.jface.dialogs.Dialog)2 ProgressMonitorDialog (org.eclipse.jface.dialogs.ProgressMonitorDialog)2