org.eclipse.e4.ui.model.application.MApplication Java Examples

The following examples show how to use org.eclipse.e4.ui.model.application.MApplication. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CoreUiUtil.java    From elexis-3-core with Eclipse Public License 1.0 6 votes vote down vote up
@Inject
@Optional
public void subscribeAppStartupComplete(
	@UIEventTopic(UIEvents.UILifeCycle.APP_STARTUP_COMPLETE) Event event, UISynchronize sync){
	
	synchronized (lock) {
		Object property = event.getProperty("org.eclipse.e4.data");
		if (property instanceof MApplication) {
			MApplication application = (MApplication) property;
			// A RAP application has one application context per client
			// the resp. context service implementation considers this
			contextService.getRootContext().setNamed("applicationContext",
				application.getContext());
			
			if (!delayedInjection.isEmpty()) {
				for (Object object : delayedInjection) {
					sync.asyncExec(() -> {
						injectServices(object);
					});
				}
				delayedInjection.clear();
			}
		}
	}
}
 
Example #2
Source File: PerspectiveHelper.java    From gama with GNU General Public License v3.0 6 votes vote down vote up
public static void cleanPerspectives() {
	final EModelService e = PlatformUI.getWorkbench().getService(EModelService.class);
	final MApplication a = PlatformUI.getWorkbench().getService(MApplication.class);

	final List<PerspectiveImpl> perspectives = e.findElements(a, PerspectiveImpl.class, EModelService.ANYWHERE,
		element -> matches(element.getElementId()));
	for ( final PerspectiveImpl p : perspectives ) {
		// DEBUG.OUT("Dirty perspective implementation found and removed: " + p.getElementId());
		p.getParent().getChildren().remove(p);
	}

	final IPerspectiveRegistry reg = PlatformUI.getWorkbench().getPerspectiveRegistry();
	for ( final IPerspectiveDescriptor desc : reg.getPerspectives() ) {
		if ( matches(desc.getId()) ) {
			// DEBUG.OUT("Dirty perspective descriptor found and removed: " + desc.getId());
			reg.deletePerspective(desc);
		}
	}

	// DEBUG.OUT("Current perspectives: " + listCurrentPerspectives());
}
 
Example #3
Source File: PerspectiveImportService.java    From elexis-3-core with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public int deletePerspective(String perspectiveId){
	IPerspectiveRegistry iPerspectiveRegistry =
		PlatformUI.getWorkbench().getPerspectiveRegistry();
	MApplication mApplication = getService(MApplication.class);
	IPerspectiveDescriptor existingPerspectiveDescriptor =
		iPerspectiveRegistry.findPerspectiveWithId(perspectiveId);
	
	int idx = -1;
	
	if (existingPerspectiveDescriptor != null) {
		
		idx = closePerspective(existingPerspectiveDescriptor);
		//NOT WORKING IF PERSPECTIVE IS PREDEFINED - workaround with generics
		iPerspectiveRegistry.deletePerspective(existingPerspectiveDescriptor);
		PerspectiveImportService.genericInvokMethod(iPerspectiveRegistry, "removeSnippet",
			MSnippetContainer.class, String.class, mApplication,
			existingPerspectiveDescriptor.getId());
		
	}
	return idx;
}
 
Example #4
Source File: CoreUiUtil.java    From elexis-3-core with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public void handleEvent(Event event){
	synchronized (lock) {
		Object property = event.getProperty("org.eclipse.e4.data");
		if (property instanceof MApplication) {
			MApplication application = (MApplication) property;
			CoreUiUtil.applicationContext = application.getContext();
			
			if (!delayedInjection.isEmpty()) {
				for (Object object : delayedInjection) {
					Display.getDefault().asyncExec(() -> {
						injectServices(object);
					});
				}
				delayedInjection.clear();
			}
		}
	}
}
 
Example #5
Source File: UiStartupHandler.java    From elexis-3-core with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public void handleEvent(Event event){
	Object property = event.getProperty("org.eclipse.e4.data");
	if (property instanceof MApplication) {
		MApplication application = (MApplication) property;
		
		EModelService modelService = application.getContext().get(EModelService.class);
		
		UiDesk.asyncExec(new Runnable() {
			public void run(){
				addMandantSelectionItem(application, modelService);
				ElexisFastViewUtil.registerPerspectiveListener();
			}
		});
		
	}
}
 
Example #6
Source File: E4PreferencesHandler.java    From e4Preferences with Eclipse Public License 1.0 6 votes vote down vote up
@Execute
public void execute(@Named(IServiceConstants.ACTIVE_SHELL) Shell shell, @Optional PreferenceManager pm, MApplication appli)
{
	// Manage the possible null pm (case of pure E4 application. With E3 it
	// will be initialized by org.eclipse.ui.internal.WorkbenchPlugin
	// see line 1536
	if (pm == null)
	{
		pm = new E4PrefManager();
		E4PreferenceRegistry registry = new E4PreferenceRegistry();
		IEclipseContext appliContext = appli.getContext();
		registry.populatePrefManagerWithE4Extensions(pm, appliContext);
		appliContext.set(PreferenceManager.class, pm);
	}
	
	// Can display the standard dialog.
	PreferenceDialog dialog = new PreferenceDialog(shell, pm);
	dialog.create();
	dialog.getTreeViewer().setComparator(new ViewerComparator());
	dialog.getTreeViewer().expandAll();
	dialog.open();
}
 
Example #7
Source File: RemoveQuickAccessProcessor.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
@Execute
public void removeQuickAccess(final MApplication application) {
    final List<MTrimContribution> trimContributions = application.getTrimContributions();
    for (final MTrimContribution trimContribution : trimContributions) {
        if ("org.eclipse.ui.ide.application.trimcontribution.QuickAccess".equals(trimContribution.getElementId())) {
            trimContributions.remove(trimContribution);
            break;
        }
    }
}
 
Example #8
Source File: PerspectiveImportService.java    From elexis-3-core with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public MTrimmedWindow getActiveWindow(){
	EModelService modelService = getService(EModelService.class);
	MApplication mApplication = getService(MApplication.class);
	
	MTrimmedWindow mWindow = (MTrimmedWindow) modelService.find("IDEWindow", mApplication);
	if (mWindow == null) {
		List<MWindow> windows = mApplication.getChildren();
		if (!windows.isEmpty() && windows.get(0) instanceof MTrimmedWindow) {
			mWindow = (MTrimmedWindow) windows.get(0);
		}
	}
	return mWindow;
}
 
Example #9
Source File: PerspektiveImportHandler.java    From elexis-3-core with Eclipse Public License 1.0 5 votes vote down vote up
private void switchToPerspectiveLegacy(MPerspective loadedPerspective,
	List<String> preLoadedFastViewIds){
	
	EModelService modelService = getService(EModelService.class);
	EPartService partService = getService(EPartService.class);
	MApplication mApplication = getService(MApplication.class);
	MTrimmedWindow mWindow = (MTrimmedWindow) modelService.find("IDEWindow", mApplication);
	if (mWindow == null) {
		List<MWindow> windows = mApplication.getChildren();
		if (!windows.isEmpty() && windows.get(0) instanceof MTrimmedWindow) {
			mWindow = (MTrimmedWindow) windows.get(0);
		}
	}
	MPerspective activePerspective = modelService.getActivePerspective(mWindow);
	MElementContainer<MUIElement> perspectiveParent = activePerspective.getParent();
	List<String> fastViewIds = preLoadedFastViewIds;
	
	// add the loaded perspective and switch to it
	String id = loadedPerspective.getElementId();
	Iterator<MUIElement> it = perspectiveParent.getChildren().iterator();
	while (it.hasNext()) {
		MUIElement element = it.next();
		if (id.equals(element.getElementId()) || element.getElementId().startsWith(id + ".<")) {
			it.remove();
		}
	}
	perspectiveParent.getChildren().add(loadedPerspective);
	
	// add fast view
	for (String fastViewId : fastViewIds) {
		ElexisFastViewUtil.addToFastView(loadedPerspective.getElementId(), fastViewId);
	}
	// the workbench window must be on top - otherwise the exception 'Application does not have an active window' occurs
	PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell().open();
	
	partService.switchPerspective(loadedPerspective);
}
 
Example #10
Source File: PerspectiveUtil.java    From elexis-3-core with Eclipse Public License 1.0 5 votes vote down vote up
public static MTrimmedWindow getActiveWindow(){
	EModelService modelService = getService(EModelService.class);
	MApplication mApplication = getService(MApplication.class);
	
	MTrimmedWindow mWindow = (MTrimmedWindow) modelService.find("IDEWindow", mApplication);
	if (mWindow == null) {
		List<MWindow> windows = mApplication.getChildren();
		if (!windows.isEmpty() && windows.get(0) instanceof MTrimmedWindow) {
			mWindow = (MTrimmedWindow) windows.get(0);
		}
	}
	return mWindow;
}
 
Example #11
Source File: ContextService.java    From elexis-3-core with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void handleEvent(Event event){
	Object property = event.getProperty("org.eclipse.e4.data");
	if (property instanceof MApplication) {
		MApplication application = (MApplication) property;
		applicationContext = application.getContext();
		if (getRootContext() != null) {
			((Context) getRootContext()).setEclipseContext(applicationContext);
		}
	}
	// set initial values for injection
	applicationContext.set(IUser.class, getRootContext().getTyped(IUser.class).orElse(null));
}
 
Example #12
Source File: ElexisProcessor.java    From elexis-3-core with Eclipse Public License 1.0 5 votes vote down vote up
private void updateModelVersions(MApplication mApplication, EModelService eModelService){
	try {
		List<MWindow> windows = mApplication.getChildren();
		if (!windows.isEmpty() && windows.get(0) instanceof MTrimmedWindow) {
			MTrimmedWindow mWindow = (MTrimmedWindow) windows.get(0);
			// remove old model elements like perspectives etc
			for (String modelElementId : removeModelElements) {
				MUIElement element = eModelService.find(modelElementId, mApplication);
				if (element != null) {
					if (element instanceof MPerspective) {
						eModelService.removePerspectiveModel((MPerspective) element, mWindow);
						logger.info(
							"model element (perspective): " + modelElementId + " removed!");
					} else {
						MElementContainer<MUIElement> parent = element.getParent();
						parent.getChildren().remove(element);
						element.setToBeRendered(false);
						logger.info("model element: " + modelElementId + " removed!");
					}
				}
			}
		} else {
			logger.warn("cannot find active window");
		}
	} catch (Exception e) {
		logger.error("unexpected exception - cannot do updates on models", e);
	}
}
 
Example #13
Source File: ElexisProcessor.java    From elexis-3-core with Eclipse Public License 1.0 5 votes vote down vote up
@Execute
public void execute(MApplication mApplication, EModelService eModelService){
	this.mApplication = mApplication;
	this.eModelService = eModelService;

	if (eModelService != null) {
		updateModelVersions(mApplication, eModelService);
	}
	
	updateToolbar();
	
	updateInjectViews();
	
	updateE4Views();
}
 
Example #14
Source File: ElexisFastViewUtil.java    From elexis-3-core with Eclipse Public License 1.0 5 votes vote down vote up
private static MTrimmedWindow getCurrentWindow(EModelService eModelService,
	MApplication mApplication){
	MTrimmedWindow window = (MTrimmedWindow) eModelService.find("IDEWindow", mApplication);
	if (window == null) {
		List<MWindow> windows = mApplication.getChildren();
		if (!windows.isEmpty() && windows.get(0) instanceof MTrimmedWindow) {
			window = (MTrimmedWindow) windows.get(0);
		}
	}
	return window;
}
 
Example #15
Source File: UiStartupHandler.java    From elexis-3-core with Eclipse Public License 1.0 5 votes vote down vote up
private void addMandantSelectionItem(MApplication mApplication, EModelService eModelService){
	
	MTrimBar trimbar =
		(MTrimBar) eModelService.find("org.eclipse.ui.main.toolbar", mApplication);
	
	if (trimbar != null) {
		MTrimElement mTrimElement = null;
		int position = 0;
		int i = 0;
		List<MTrimElement> childrens = trimbar.getChildren();
		for (MTrimElement element : childrens) {
			
			if ("ch.elexis.core.ui.toolcontrol.mandantselection"
				.equals(element.getElementId())) {
				mTrimElement = element;
			}
			
			if (position == 0 && ("ch.elexis.toolbar1".equals(element.getElementId())
				|| "PerspectiveSpacer".equals(element.getElementId()))) {
				position = i;
			}
			i++;
		}
		
		if (mTrimElement == null) {
			MToolControl mToolControl = eModelService.createModelElement(MToolControl.class);
			mToolControl.setElementId("ch.elexis.core.ui.toolcontrol.mandantselection");
			mToolControl.setContributionURI(
				"bundleclass://ch.elexis.core.ui/ch.elexis.core.ui.coolbar.MandantSelectionContributionItem");
			mToolControl.setToBeRendered(true);
			mToolControl.setVisible(true);
			
			childrens.add(position, mToolControl);
		}
	}
	
}
 
Example #16
Source File: N4JSApplicationWorkbenchWindowAdvisor.java    From n4js with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * The 'Show View' dialog behavior slightly changed with E4. Even if the views are properly removed via activities
 * (by the unique view IDs) the content provider creates the root category for the unavailable views as well since
 * it is using the {@link MApplication}.
 */
private void reviewDisabledCategoriesFromAppModel() {
	final IWorkbenchWindow workbenchWindow = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
	final MApplication service = workbenchWindow.getService(MApplication.class);
	for (Iterator<MPartDescriptor> itr = service.getDescriptors().iterator(); itr.hasNext(); /**/) {
		final MPartDescriptor descriptor = itr.next();
		if (isView(descriptor) && isDisabledView(descriptor)) {
			itr.remove();
		}
	}
}
 
Example #17
Source File: DemoEntryCompositeContextFunction.java    From ice with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public Object compute(IEclipseContext context, String contextKey) {
	IEntryCompositeProvider provider = ContextInjectionFactory
			.make(DemoEntryCompositeProvider.class, context);
	// add the new object to the application context
	MApplication application = context.get(MApplication.class);
	IEclipseContext ctx = application.getContext();
	ctx.set(IEntryCompositeProvider.class, provider);
	return provider;
}
 
Example #18
Source File: DemoGeometryPageContextFunction.java    From ice with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public Object compute(IEclipseContext context, String contextKey) {
	IPageProvider provider = ContextInjectionFactory
			.make(DemoGeometryPageProvider.class, context);
	// add the new object to the application context
	MApplication application = context.get(MApplication.class);
	IEclipseContext ctx = application.getContext();
	ctx.set(IPageProvider.class, provider);
	return provider;
}
 
Example #19
Source File: DemoGeometryPageFactoryContextFunction.java    From ice with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public Object compute(IEclipseContext context, String contextKey) {
	IPageFactory factory = ContextInjectionFactory
			.make(DemoGeometryPageFactory.class, context);
	// add the new object to the application context
	MApplication application = context.get(MApplication.class);
	IEclipseContext ctx = application.getContext();
	ctx.set(IPageFactory.class, factory);
	return factory;
}
 
Example #20
Source File: DefaultPageFactoryContextFunction.java    From ice with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public Object compute(IEclipseContext context, String contextKey) {
	IPageFactory factory = ContextInjectionFactory
			.make(DefaultPageFactory.class, context);
	// add the new object to the application context
	MApplication application = context.get(MApplication.class);
	IEclipseContext ctx = application.getContext();
	ctx.set(IPageFactory.class, factory);
	return factory;
}
 
Example #21
Source File: DemoWidgetsProcessor.java    From ice with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * This operation executes the instructions required to register the demo
 * widgets with the e4 workbench.
 * 
 * @param context
 *            The e4 context
 * @param app
 *            the model application
 */
@Execute
public void execute(IEclipseContext context, MApplication app) {

	// Add the geometry provider
	IPageProvider provider = ContextInjectionFactory
			.make(DemoGeometryPageProvider.class, context);
	context.set("demo-geometry", provider);

	// Add the EntryComposite provider
	IEntryCompositeProvider compProvider = ContextInjectionFactory
			.make(DemoEntryCompositeProvider.class, context);
	context.set("demo-entry", compProvider);

}
 
Example #22
Source File: SamplePart.java    From codeexamples-eclipse with Eclipse Public License 1.0 5 votes vote down vote up
@PostConstruct
public void createComposite(Composite parent, IPresentationEngine presentationEngine, EModelService modelService, MApplication app, IEclipseContext context) {
	List<MTrimContribution> trimContributions = app.getTrimContributions();
	
	Optional<MTrimElement> findAny = trimContributions.stream().flatMap(tbc -> tbc.getChildren().stream()).filter(tbe -> "com.vogella.e4.renderer.toolbar".equals(tbe.getElementId())).findAny();

	findAny.ifPresent(uiElement -> {
		ToolBar toolBar = new ToolBar(parent, SWT.NONE);
		presentationEngine.createGui(uiElement, toolBar, context);
	});
}
 
Example #23
Source File: ShowTraderPerspectiveHandler.java    From offspring with MIT License 5 votes vote down vote up
@Execute
public void execute(MApplication app, EPartService partService,
    EModelService modelService) {
  MPerspective element = (MPerspective) modelService.find(PART_ID, app);
  partService.switchPerspective(element);
  logger.trace("Switch to " + PART_ID);
}
 
Example #24
Source File: ShowNXTPerspectiveHandler.java    From offspring with MIT License 5 votes vote down vote up
@Execute
public void execute(MApplication app, EPartService partService,
    EModelService modelService) {
  MPerspective element = (MPerspective) modelService.find(PART_ID, app);
  if (element != null) {
    partService.switchPerspective(element);
    logger.trace("Switch to " + PART_ID);
  }
}
 
Example #25
Source File: StartHandlerAddon.java    From offspring with MIT License 5 votes vote down vote up
@PostConstruct
void hookListeners(MApplication application, IUserService userService,
    IWallet wallet, IDataProviderPool pool, INxtService nxt,
    IAssetExchange exchange) {
  this.application = application;
  this.userService = userService;
  this.wallet = wallet;
  this.pool = pool;
  this.nxt = nxt;
  this.exchange = exchange;
  broker.subscribe(UIEvents.UILifeCycle.APP_STARTUP_COMPLETE, eventHandler);

}
 
Example #26
Source File: PerspectiveHelper.java    From gama with GNU General Public License v3.0 5 votes vote down vote up
public static void deletePerspectiveFromApplication(final IPerspectiveDescriptor d) {
	final MApplication a = PlatformUI.getWorkbench().getService(MApplication.class);
	final EModelService e = PlatformUI.getWorkbench().getService(EModelService.class);
	final List<PerspectiveImpl> perspectives = e.findElements(a, PerspectiveImpl.class, EModelService.ANYWHERE,
		element -> element.getElementId().contains(d.getId()));
	for ( final PerspectiveImpl p : perspectives ) {
		// DEBUG.OUT("Dirty perspective implementation found and removed: " + p.getElementId());
		p.getParent().getChildren().remove(p);
	}
}
 
Example #27
Source File: StartLaunchConfigMenuPDETest.java    From eclipse-extras with Eclipse Public License 1.0 4 votes vote down vote up
@Before
public void setUp() {
  application = getEclipseContext().get( MApplication.class );
}
 
Example #28
Source File: PerspectiveExportService.java    From elexis-3-core with Eclipse Public License 1.0 4 votes vote down vote up
@SuppressWarnings("restriction")
@Override
public void exportPerspective(String pathToExport, String newCode, String newLabel)
	throws IOException{
	
	try (OutputStream outputStream = new FileOutputStream(pathToExport)) {
		EModelService modelService = getService(EModelService.class);
		
		MApplication mApplication = getService(MApplication.class);
		MTrimmedWindow window = (MTrimmedWindow) modelService.find("IDEWindow", mApplication);
		if (window == null) {
			List<MWindow> windows = mApplication.getChildren();
			if (!windows.isEmpty() && windows.get(0) instanceof MTrimmedWindow) {
				window = (MTrimmedWindow) windows.get(0);
			}
		}
		
		// store model of the active perspective
		MPerspective activePerspective = modelService.getActivePerspective(window);
		
		// create a resource, which is able to store e4 model elements
		E4XMIResourceFactory e4xmiResourceFactory = new E4XMIResourceFactory();
		Resource resource = e4xmiResourceFactory.createResource(null);
		
		//clone the perspective and replace the placeholder ref with element ids of their content
		MPerspective clone = clonePerspectiveWithWorkaround(modelService, activePerspective);
		
		if (newLabel != null) {
			clone.setLabel(newLabel);
		}
		
		if (newCode != null) {
			clone.setElementId(newCode);
		}
		
		List<MPlaceholder> placeholderClones = modelService.findElements(clone, null,
			MPlaceholder.class, null, EModelService.IN_ANY_PERSPECTIVE);
		for (MPlaceholder placeholder : placeholderClones) {
			/* MUIElement ref = placeholder.getRef();
			if placeholder elementid is not the view id then use tags
			if (ref != null && !placeholder.getTags().contains(ref.getElementId())) {
				placeholder.getTags().add(0, ref.getElementId());
			}*/
			placeholder.setRef(null);
		}
		
		ElexisFastViewUtil.transferFastViewPersistedState(window, clone);
		
		// add the cloned model element to the resource so that it may be stored
		resource.getContents().add((EObject) clone);
		
		resource.save(outputStream, null);
	}
}
 
Example #29
Source File: PerspectiveImportService.java    From elexis-3-core with Eclipse Public License 1.0 4 votes vote down vote up
@SuppressWarnings("restriction")
@Override
public void savePerspectiveAs(String perspectiveId, String newName){
	EModelService modelService = getService(EModelService.class);
	MApplication mApplication = getService(MApplication.class);
	PerspectiveRegistry perspectiveRegistry =
		(PerspectiveRegistry) PlatformUI.getWorkbench().getPerspectiveRegistry();
	PerspectiveDescriptor existingPerspectiveDescriptor =
		(PerspectiveDescriptor) perspectiveRegistry.findPerspectiveWithId(perspectiveId);
	if (existingPerspectiveDescriptor != null) {
		
		int idx = isPerspectiveInsideStack(existingPerspectiveDescriptor);
		
		// loads the mapplication from the orginal descriptor
		openPerspective(existingPerspectiveDescriptor);
		
		// the model must be loaded
		List<MPerspective> modelPerspective = modelService.findElements(mApplication,
			existingPerspectiveDescriptor.getId(), MPerspective.class, null);
		
		// check if the model is loaded
		if (!modelPerspective.isEmpty()) {
			// create a new pd
			PerspectiveDescriptor newPd =
				perspectiveRegistry.createPerspective(newName, existingPerspectiveDescriptor);
			
			// saves an opens the new perspective
			PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage()
				.savePerspectiveAs(newPd);
			
			// close the new created one
			closePerspective(newPd);
			
			if (idx > -1) {
				// opens the original descriptor if it was already opened
				openPerspective(existingPerspectiveDescriptor);
			}
		}
		
	}
}
 
Example #30
Source File: ArrangeDisplayViews.java    From gama with GNU General Public License v3.0 4 votes vote down vote up
private static MApplication getApplication() {
	return WorkbenchHelper.getService(MApplication.class);
}