Java Code Examples for org.eclipse.e4.ui.workbench.modeling.EModelService#getActivePerspective()
The following examples show how to use
org.eclipse.e4.ui.workbench.modeling.EModelService#getActivePerspective() .
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: SavePerspectiveHandler.java From codeexamples-eclipse with Eclipse Public License 1.0 | 5 votes |
@Execute public void execute(EModelService modelService, MWindow window) { // clone the currently active perspective MPerspective activePerspective = modelService .getActivePerspective(window); modelService.cloneElement(activePerspective, window); }
Example 2
Source File: SwitchPerspectiveHandler.java From codeexamples-eclipse with Eclipse Public License 1.0 | 5 votes |
@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 3
Source File: RestorePerspectiveHandler.java From codeexamples-eclipse with Eclipse Public License 1.0 | 5 votes |
@Execute public void execute(EModelService modelService, MWindow window, EPartService partService) { // get active perpective and find stored snippet of this perspective MPerspective activePerspective = modelService.getActivePerspective(window); MUIElement perspectiveSnippet = modelService.cloneSnippet(window, activePerspective.getElementId(), window); // remove existing active perspective MElementContainer<MUIElement> parent = activePerspective.getParent(); modelService.removePerspectiveModel(activePerspective, window); // add stored perspective snippet and switch to it parent.getChildren().add(perspectiveSnippet); partService.switchPerspective((MPerspective) perspectiveSnippet); }
Example 4
Source File: RestorePerspectiveHandler.java From codeexamples-eclipse with Eclipse Public License 1.0 | 5 votes |
@CanExecute public boolean canExecute(EModelService modelService, MWindow window) { // check whether a snippet for the active perspective exists MPerspective activePerspective = modelService.getActivePerspective(window); return modelService.findSnippet(window, activePerspective.getElementId()) != null; }
Example 5
Source File: AutomaticSwitchPerspectivePartListener.java From bonita-studio with GNU General Public License v2.0 | 5 votes |
protected String getActivePerspectiveId(final MPart part) { if (part != null && part.getContext() != null) { final EModelService service = part.getContext().get(EModelService.class); final MWindow window = service.getTopLevelWindowFor(part); String activePerspective = null; final MPerspective selectedElement = service.getActivePerspective(window); if (selectedElement != null) { activePerspective = selectedElement.getElementId(); } return activePerspective; } return null; }
Example 6
Source File: PerspectiveUtil.java From elexis-3-core with Eclipse Public License 1.0 | 5 votes |
public static MPerspective getActivePerspective(){ EModelService modelService = getService(EModelService.class); MTrimmedWindow mWindow = getActiveWindow(); if (mWindow != null) { return modelService.getActivePerspective(mWindow); } return null; }
Example 7
Source File: PerspektiveImportHandler.java From elexis-3-core with Eclipse Public License 1.0 | 5 votes |
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 8
Source File: PerspectiveImportService.java From elexis-3-core with Eclipse Public License 1.0 | 5 votes |
private MPerspective getActivePerspective(){ EModelService modelService = getService(EModelService.class); MTrimmedWindow mWindow = getActiveWindow(); if (mWindow != null) { return modelService.getActivePerspective(mWindow); } return null; }
Example 9
Source File: ElexisFastViewUtil.java From elexis-3-core with Eclipse Public License 1.0 | 4 votes |
/** * Changes the fastviews position from left trimbar to bottom trimbar */ private static void changeFastViewBarFromLeftToBottom(){ EModelService eModelService = getService(EModelService.class); MApplication mApplication = getService(MApplication.class); MTrimmedWindow mWindow = getCurrentWindow(eModelService, mApplication); if (mWindow != null) { MPerspective mPerspective = eModelService.getActivePerspective(mWindow); if (mPerspective != null) { String perspectiveId = mPerspective.getElementId(); Optional<MToolControl> mToolControl = getFastViewToolControl(eModelService, mWindow, perspectiveId, SideValue.BOTTOM); if (!mToolControl.isPresent()) { mToolControl = getFastViewToolControl(eModelService, mWindow, perspectiveId, SideValue.LEFT); mToolControl.ifPresent(toolControl -> { MTrimBar trimBarBottom = findTrimBar(eModelService, mWindow, SideValue.BOTTOM); if (trimBarBottom != null) { MToolControl copyToolcontrol = eModelService.createModelElement(MToolControl.class); copyToolcontrol.setElementId(toolControl.getElementId()); copyToolcontrol.setContributionURI( "bundleclass://org.eclipse.e4.ui.workbench.addons.swt/org.eclipse.e4.ui.workbench.addons.minmax.TrimStack"); copyToolcontrol.setToBeRendered(true); copyToolcontrol.setVisible(true); copyToolcontrol.getTags().add("TrimStack"); if (!hasFastViewPersistedState(mPerspective)) { copyToolcontrol.getPersistedState().put("YSize", "600"); } trimBarBottom.getChildren().add(0, copyToolcontrol); toolControl.setToBeRendered(false); toolControl.setVisible(false); toolControl.getParent().getChildren().remove(toolControl); toolControl.setParent(null); trimBarBottom.setVisible(true); trimBarBottom.setToBeRendered(true); } }); } else { mToolControl.get().setToBeRendered(true); } } } }
Example 10
Source File: PerspectiveExportService.java From elexis-3-core with Eclipse Public License 1.0 | 4 votes |
@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); } }