private boolean detectWorkbenchCorruption(MApplication application) { if (application.getChildren().isEmpty()) { WorkbenchPlugin.log( "When auto-saving the workbench model, there were no top-level windows. " //$NON-NLS-1$ + " Skipped saving the model.", //$NON-NLS-1$ new Exception()); // log a stack trace to assist debugging return true; } return false; }
public void restoreDefaultModel() { application.getTags().clear(); application.getPersistedState().clear(); application.getSnippets().clear(); application.getDescriptors().clear(); application.getChildren().clear(); application.getChildren().addAll(defaultWindows); }
/** * @return {@code true} if the specified application model has top-level windows. */ private boolean hasTopLevelWindows(Resource applicationResource) { if (applicationResource == null || applicationResource.getContents() == null) { // If the application resource doesn't exist or has no contents, then it has no // top-level windows (and we are in an error state). return false; } MApplication application = (MApplication) applicationResource.getContents().get(0); return !application.getChildren().isEmpty(); }
private MWindow getWindow() { if (workbenchWindow != null) return workbenchWindow; if (application.getSelectedElement() != null) return application.getSelectedElement(); List<MWindow> windows = application.getChildren(); if (windows.size() != 0) return windows.get(0); return null; }
@Override public IWorkbenchWindow[] getWorkbenchWindows() { List<IWorkbenchWindow> windows = new ArrayList<>(); for (MWindow window : application.getChildren()) { IEclipseContext context = window.getContext(); if (context != null) { IWorkbenchWindow wwindow = context.get(IWorkbenchWindow.class); if (wwindow != null) { windows.add(wwindow); } } } return windows.toArray(new IWorkbenchWindow[windows.size()]); }
@Override public void changeApplicationLocale(Locale locale) { // the TranslationService.LOCALE context parameter is specified as String // so we put the String representation of the given Locale to the context this.application.getContext().set(TranslationService.LOCALE, locale); // update model updateLocalization(this.application.getChildren()); // fire event broker.post(LOCALE_CHANGE, locale); }
@Override public void stop() { if (this.app != null) { this.app.getContext().set("__efx_engine_shutdown", Boolean.TRUE); //$NON-NLS-1$ for (MWindow w : this.app.getChildren()) { ElementRenderer<MUIElement, Object> r = getRenderer(w); if (r != null) { removeGui(w); } } } }
@Override public void changeApplicationLocale(String localeString) { try { Locale locale = ResourceBundleHelper.toLocale(localeString); // set the locale to the application context // use the resolved locale instead of the given locale string to avoid invalid locales // in context this.application.getContext().set(TranslationService.LOCALE, locale); // update model updateLocalization(this.application.getChildren()); // fire event broker.post(LOCALE_CHANGE, locale); } catch (Exception e) { // performing a locale update failed // there is no locale change performed if (logService != null) logService.log(LogService.LOG_ERROR, e.getMessage() + " - No Locale change will be performed."); //$NON-NLS-1$ } }
private void cleanUp(MWindow window) { MUIElement parent = modelService.getContainer(window); if (parent instanceof MApplication) { MApplication application = (MApplication) parent; List<MWindow> children = application.getChildren(); if (children.size() > 1) { // not the last window, destroy and remove window.setToBeRendered(false); children.remove(window); } else { // last window, just destroy without changing the model engine.removeGui(window); } } else if (parent != null) { window.setToBeRendered(false); // this is a detached window, check for parts if (modelService.findElements(window, null, MPart.class) .isEmpty()) { // if no parts, remove it if (parent instanceof MWindow) { ((MWindow) parent).getWindows().remove(window); } else if (parent instanceof MPerspective) { ((MPerspective) parent).getWindows().remove(window); } } } }
private void cleanUp(MWindow window) { Object parent = ((EObject) window).eContainer(); if (parent instanceof MApplication) { MApplication application = (MApplication) parent; List<MWindow> children = application.getChildren(); if (children.size() > 1) { // not the last window, destroy and remove window.setToBeRendered(false); children.remove(window); } else { // last window, just destroy without changing the model engine.removeGui(window); } } else if (parent != null) { window.setToBeRendered(false); // this is a detached window, check for parts if (modelService.findElements(window, null, MPart.class, null) .isEmpty()) { // if no parts, remove it if (parent instanceof MWindow) { ((MWindow) parent).getWindows().remove(window); } else if (parent instanceof MPerspective) { ((MPerspective) parent).getWindows().remove(window); } } } }
public void handleEvent(Event event) { Object element = event.getProperty(IEventBroker.DATA); if (!(element instanceof MApplication)) { return; } Set<CSSEngine> engines = new HashSet<>(); // In theory we can have multiple engines since API allows it. // It doesn't hurt to be prepared for such case for (MWindow window : ((MApplication) element).getChildren()) { CSSEngine engine = getEngine(window); if (engine != null) { engines.add(engine); } } for (CSSEngine engine : engines) { for (Object resource : removeResources(engine.getResourcesRegistry())) { if (resource instanceof Resource && !((Resource) resource).isDisposed()) { unusedResources.add((Resource) resource); } } engine.reapply(); } }
/** * Initialize the services * * @param appModel * the application model */ protected void initializeServices(MApplication appModel) { IEclipseContext appContext = appModel.getContext(); // // make sure we only add trackers once // if (appContext.containsKey(CONTEXT_INITIALIZED)) // return; // appContext.set(CONTEXT_INITIALIZED, "true"); initializeApplicationServices(appContext); List<MWindow> windows = appModel.getChildren(); for (MWindow childWindow : windows) { initializeWindowServices(childWindow); } ((EObject) appModel).eAdapters().add(new AdapterImpl() { @Override public void notifyChanged(Notification notification) { if (notification.getFeatureID(MApplication.class) != UiPackageImpl.ELEMENT_CONTAINER__CHILDREN) return; if (notification.getEventType() != Notification.ADD) return; MWindow childWindow = (MWindow) notification.getNewValue(); initializeWindowServices(childWindow); } }); }
public void migrate() { if (!isLegacyWorkbenchDetected()) { return; } workbenchMemento = loadMemento(); if (workbenchMemento == null) { return; } defaultWindows = new ArrayList<>(application.getChildren()); application.getChildren().clear(); IEclipseContext builderContext = context.createChild(); IModelBuilderFactory builderFactory = ContextInjectionFactory.make(ModelBuilderFactoryImpl.class, builderContext); builderContext.set(IModelBuilderFactory.class, builderFactory); ApplicationBuilder modelBuilder = builderFactory.createApplicationBuilder(new WorkbenchMementoReader( workbenchMemento)); modelBuilder.createApplication(); context.remove(E4Workbench.NO_SAVED_MODEL_FOUND); PrefUtil.getAPIPreferenceStore().setValue(IWorkbenchPreferenceConstants.SHOW_INTRO, false); migrated = true; }
/** * Clean up the action bars. */ public void dispose() { coolBarManager.dispose(); menuManager.dispose(); statusLineManager.dispose(); windowModel.getContext().deactivate(); windowModel.getContext().dispose(); ((Shell) windowModel.getWidget()).dispose(); app.getChildren().remove(windowModel); }
void createApplication() { List<MWindow> windows = application.getChildren(); for (WindowReader windowReader : reader.getWindowReaders()) { WindowBuilder windowBuilder = builderFactory.createWindowBuilder(windowReader); MWindow window = windowBuilder.createWindow(); windows.add(window); if (windowBuilder.isSelected()) { application.setSelectedElement(window); } Object list = window.getTransientData().remove(WindowBuilder.PERSPECTIVES); if (list instanceof List<?>) { List<MPerspective> perspectiveList = (List<MPerspective>) list; for (MPerspective perspective : perspectiveList) { importToolbarsLocation(perspective); } } } addClosedPerspectives(); addMRU(); }
/** * Get the active non modal shell. If there isn't one return null. * * @return Shell */ public static Shell getNonModalShell() { MApplication application = PlatformUI.getWorkbench().getService(MApplication.class); if (application == null) { // better safe than sorry return null; } MWindow window = application.getSelectedElement(); if (window != null) { Object widget = window.getWidget(); if (widget instanceof Shell) { return (Shell) widget; } } for (MWindow child : application.getChildren()) { Object widget = child.getWidget(); if (widget instanceof Shell) { return (Shell) widget; } } return null; }
if ((activeWindow == null || activeWindow.getWidget() == null) && !application.getChildren().isEmpty()) { activeWindow = application.getChildren().get(0);
windowModel.setWidget(shell); windowModel.setToBeRendered(false); app.getChildren().add(windowModel); shell.setData(org.eclipse.e4.ui.internal.workbench.swt.AbstractPartRenderer.OWNING_ME, windowModel);
window.setWidth(size.x); window.setHeight(size.y); application.getChildren().add(window); application.setSelectedElement(window);
for (MWindow window : application.getChildren()) { moveStickyViews(stickyViews, window);