Java Code Examples for org.eclipse.e4.ui.workbench.modeling.EModelService#find()

The following examples show how to use org.eclipse.e4.ui.workbench.modeling.EModelService#find() . 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 6 votes vote down vote up
private static Optional<MToolControl> getFastViewToolControl(EModelService eModelService,
	MTrimmedWindow workbenchWindow, String perspectiveId, SideValue sideValue){
	if (workbenchWindow != null) {
		MTrimBar trimbar = findTrimBar(eModelService, workbenchWindow, sideValue);
		if (trimbar != null) {
			MToolControl toolControl = (MToolControl) eModelService
				.find(getToolControlId(workbenchWindow, perspectiveId), trimbar);
			if (toolControl == null && workbenchWindow.getElementId() != null) {
				// it also can be that the main view id is also a part of the stack
				toolControl = (MToolControl) eModelService.find(ELEXIS_FASTVIEW_STACK + "("
					+ workbenchWindow.getElementId() + ").(" + perspectiveId + ")", trimbar);
				if (toolControl != null) {
					toolControl.setElementId(getToolControlId(workbenchWindow, perspectiveId));
				}
			}
			if (toolControl != null) {
				return Optional.of(toolControl);
			}
		}
	}
	return Optional.empty();
}
 
Example 2
Source File: ElexisFastViewUtil.java    From elexis-3-core with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Transfer persisted state (incl. size) of fastview {@link MToolControl} defined in window, to
 * fastview defined in perspective.
 * 
 * @param fromWindow
 * @param toPerspective
 */
public static void transferFastViewPersistedState(MTrimmedWindow fromWindow,
	MPerspective toPerspective){
	EModelService modelService = getService(EModelService.class);
	// check if toolcontrol exists
	MToolControl toolControl = (MToolControl) modelService
		.find(ElexisFastViewUtil.getToolControlId(fromWindow, toPerspective), fromWindow);
	if (toolControl != null && toolControl.getPersistedState() != null) {
		Optional<MPartStack> mStack = getFastViewPartStack(toPerspective);
		mStack.ifPresent(stack -> {
			Map<String, String> perspectiveState = stack.getPersistedState();
			for (String key : toolControl.getPersistedState().keySet()) {
				perspectiveState.put(key, toolControl.getPersistedState().get(key));
			}
		});
	}
}
 
Example 3
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 4
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 5
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 6
Source File: SwitchPerspectiveHandler.java    From codeexamples-eclipse with Eclipse Public License 1.0 5 votes vote down vote up
@Execute
public void execute(EModelService modelService, EPartService partService,
		MWindow window,
		@Named("com.vogella.rcp.jface.translation.commandparameter.perspectiveid") String id) {
	MPerspective activePerspective = modelService
			.getActivePerspective(window);


	MUIElement find = modelService.find(id, window);
	if (find == null || activePerspective.equals(find)) {
		return;
	}

	partService.switchPerspective((MPerspective) find);
}
 
Example 7
Source File: NormalCoolBarHandler.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
public Object execute(ExecutionEvent event) throws ExecutionException {
	MWindow model = ((WorkbenchWindow) PlatformUI.getWorkbench().getActiveWorkbenchWindow()).getModel();
	EModelService modelService = model.getContext().get(EModelService.class);
	MToolControl bonitaCoolBar = (MToolControl) modelService.find(
			"BonitaCoolbar", model);
	if(bonitaCoolBar != null){
		CoolbarToolControl coolbarControl = (CoolbarToolControl) bonitaCoolBar.getObject();
		coolbarControl.maximizeCoolbar();
	}
	return null;
}
 
Example 8
Source File: SmallCoolBarHandler.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
public Object execute(ExecutionEvent event) throws ExecutionException {
	MWindow model = ((WorkbenchWindow) PlatformUI.getWorkbench().getActiveWorkbenchWindow()).getModel();
	EModelService modelService = model.getContext().get(EModelService.class);
	MToolControl bonitaCoolBar = (MToolControl) modelService.find(
			"BonitaCoolbar", model);
	if(bonitaCoolBar != null){
		CoolbarToolControl coolbarControl = (CoolbarToolControl) bonitaCoolBar.getObject();
		coolbarControl.minimizeCoolbar();
	}
	return null;
}
 
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: 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 11
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 12
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 13
Source File: ElexisFastViewUtil.java    From elexis-3-core with Eclipse Public License 1.0 5 votes vote down vote up
private static Optional<MPartStack> getFastViewPartStack(MPerspective mPerspective){
	EModelService modelService = getService(EModelService.class);
	MPartStack stack =
		(MPartStack) modelService.find(ElexisFastViewUtil.ELEXIS_FASTVIEW_STACK, mPerspective);
	if (stack != null) {
		return Optional.of(stack);
	}
	return Optional.empty();
}
 
Example 14
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 15
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 16
Source File: PerspectiveHelper.java    From gama with GNU General Public License v3.0 4 votes vote down vote up
private static MUIElement getTrimStatus(final WorkbenchWindow window) {
	final EModelService modelService = window.getService(EModelService.class);
	final MUIElement searchRoot = window.getModel();
	return modelService.find(BOTTOM_TRIM_ID, searchRoot);
}
 
Example 17
Source File: ElexisFastViewUtil.java    From elexis-3-core with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * Adds a view to the fastview, if {@link MPartStack} not exists it will be created and the view
 * will be added within a {@link MPlaceholder} element.
 * 
 * @param perspectiveId
 * @param viewId
 */
public static void addToFastView(String perspectiveId, String viewId){
	EModelService eModelService = getService(EModelService.class);
	MApplication mApplication = getService(MApplication.class);
	
	MTrimmedWindow window = getCurrentWindow(eModelService, mApplication);
	
	if (window != null) {
		Object obj = eModelService.find(perspectiveId, mApplication);
		if (obj instanceof MPerspective) {
			MPerspective mPerspective = (MPerspective) obj;
			// check if fastview stack exists
			MPartStack stack =
				(MPartStack) eModelService.find(ELEXIS_FASTVIEW_STACK, mPerspective);
			
			if (stack == null) {
				stack = createFastViewStack(window, mPerspective, eModelService);
			}
			if (stack != null) {
				// check if toolcontrol exists
				MToolControl toolControl = (MToolControl) eModelService
					.find(getToolControlId(window, mPerspective), mApplication);
				
				if (toolControl == null) {
					MTrimBar mTrimBar = eModelService.getTrim(window, SideValue.BOTTOM);
					if (toolControl == null) {
						toolControl = createFastViewToolControl(window, mPerspective,
							eModelService, mTrimBar);
					}
				}
				if (toolControl != null
					&& !ElexisFastViewUtil.isViewInsideFastview(stack, viewId)
					&& mApplication.getContext().getActiveChild() != null) {
					EPartService partService = getService(EPartService.class);
					MPlaceholder placeholder = partService.createSharedPart(viewId);
					placeholder.setToBeRendered(true);
					placeholder.setElementId(viewId);
					placeholder.setCloseable(true);
					placeholder.getTags().add(EPartService.REMOVE_ON_HIDE_TAG);
					((MPart) placeholder.getRef()).setToBeRendered(true);
					stack.getChildren().add(placeholder); // Add part to stack
				}
				
			}
		}
	}
}
 
Example 18
Source File: CoolbarToolControl.java    From bonita-studio with GNU General Public License v2.0 4 votes vote down vote up
protected MTrimBar getTrimBar(final IEclipseContext context, final String trimBarId) {
    final EModelService modelService = context.get(EModelService.class);
    final MWindow window = context.get(MWindow.class);
    final MTrimBar topTrim = (MTrimBar) modelService.find(trimBarId, window);
    return topTrim;
}
 
Example 19
Source File: ShowAccountPerspectiveHandler.java    From offspring with MIT License 4 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 20
Source File: ShowHomePerspectiveHandler.java    From offspring with MIT License 4 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);
}