Java Code Examples for org.eclipse.e4.ui.model.application.MApplication#getChildren()

The following examples show how to use org.eclipse.e4.ui.model.application.MApplication#getChildren() . 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: 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 2
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 3
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 4
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 5
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 6
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);
	}
}