org.eclipse.e4.ui.model.application.ui.advanced.MPerspective Java Examples
The following examples show how to use
org.eclipse.e4.ui.model.application.ui.advanced.MPerspective.
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 |
private static MToolControl createFastViewToolControl(MTrimmedWindow window, MPerspective mPerspective, EModelService eModelService, MTrimBar mTrimBar){ if (mTrimBar != null) { MToolControl mToolControl = eModelService.createModelElement(MToolControl.class); mToolControl.setElementId(getToolControlId(window, mPerspective)); mToolControl.setContributionURI( "bundleclass://org.eclipse.e4.ui.workbench.addons.swt/org.eclipse.e4.ui.workbench.addons.minmax.TrimStack"); mToolControl.setToBeRendered(true); mToolControl.setVisible(true); mToolControl.getTags().add("TrimStack"); if (!hasFastViewPersistedState(mPerspective)) { mToolControl.getPersistedState().put("YSize", "600"); } mTrimBar.getChildren().add(0, mToolControl); mTrimBar.setVisible(true); mTrimBar.setToBeRendered(true); return mToolControl; } return null; }
Example #2
Source File: ElexisFastViewUtil.java From elexis-3-core with Eclipse Public License 1.0 | 6 votes |
private static MPartStack createFastViewStack(MTrimmedWindow window, MPerspective mPerspective, EModelService eModelService){ if (window != null && mPerspective != null) { MPartStack mPartStack = eModelService.createModelElement(MPartStack.class); mPartStack.setElementId(ELEXIS_FASTVIEW_STACK); mPartStack.setToBeRendered(true); mPartStack.getTags().add("Minimized"); mPartStack.setOnTop(false); mPartStack.setVisible(false); mPartStack.getTags().add("NoAutoCollapse"); mPartStack.getTags().add("active"); mPerspective.getChildren().add(0, mPartStack); return mPartStack; } return null; }
Example #3
Source File: PerspectiveImportService.java From elexis-3-core with Eclipse Public License 1.0 | 6 votes |
private int isPerspectiveInsideStack(IPerspectiveDescriptor pd){ int idx = -1; if (pd != null) { List<MPerspective> perspectivesInStack; MPerspectiveStack mPerspectiveStack = getPerspectiveStack(); perspectivesInStack = mPerspectiveStack.getChildren(); for (MPerspective perspectiveInStack : perspectivesInStack) { if (pd.getId().equals(perspectiveInStack.getElementId())) { idx++; break; } } } return idx; }
Example #4
Source File: ElexisFastViewUtil.java From elexis-3-core with Eclipse Public License 1.0 | 6 votes |
/** * 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 #5
Source File: PerspektiveImportHandler.java From elexis-3-core with Eclipse Public License 1.0 | 6 votes |
@SuppressWarnings("restriction") private IPerspectiveDescriptor savePerspectiveToRegistryLegacy(MPerspective perspective){ IPerspectiveRegistry perspectiveRegistry = (PerspectiveRegistry) PlatformUI.getWorkbench().getPerspectiveRegistry(); IPerspectiveDescriptor pd = perspectiveRegistry.findPerspectiveWithId(perspective.getElementId()); if (pd == null) { ((PerspectiveRegistry) perspectiveRegistry).addPerspective(perspective); pd = perspectiveRegistry.findPerspectiveWithId(perspective.getElementId()); } else { LoggerFactory.getLogger(PerspektiveImportHandler.class) .error("perspective descriptor already exists for perspective id: " + perspective.getElementId()); } return pd; }
Example #6
Source File: InitialPerspectiveStorageAddon.java From codeexamples-eclipse with Eclipse Public License 1.0 | 6 votes |
@Inject @Optional public void selectedElement(@EventTopic(UIEvents.ElementContainer.TOPIC_SELECTEDELEMENT) Event event, EModelService modelService) { if (!UIEvents.isSET(event)) { return; } Object newlySelectedPerspective = event.getProperty(EventTags.NEW_VALUE); if (newlySelectedPerspective instanceof MPerspective) { MPerspective perspectiveToBeCloned = (MPerspective) newlySelectedPerspective; MWindow topLevelWindow = modelService.getTopLevelWindowFor(perspectiveToBeCloned); // try to find already existing snippet if (null == modelService.findSnippet(topLevelWindow, perspectiveToBeCloned.getElementId())) { // clone perspective in case there is no snippet yet modelService.cloneElement(perspectiveToBeCloned, topLevelWindow); } } }
Example #7
Source File: StartupHandler.java From elexis-3-core with Eclipse Public License 1.0 | 6 votes |
@Override public void handleEvent(Event event){ if (CoreHub.globalCfg.get(UsageSettings.CONFIG_USAGE_STATISTICS, false)) { registerNotifications(); StatisticsManager.INSTANCE.getStatistics().setFrom(new Date()); // add start perspective to statistics MPerspective mPerspective = PerspectiveUtil.getActivePerspective(); if (mPerspective != null) { StatisticsManager.INSTANCE.addCallingStatistic(mPerspective.getElementId(), true); } } if (CoreHub.globalCfg.get(UsageSettings.CONFIG_USAGE_STATISTICS, false)) { registerEventPerformance(); } }
Example #8
Source File: ElexisFastViewUtil.java From elexis-3-core with Eclipse Public License 1.0 | 6 votes |
/** * Transfer persisted state (incl. size) of fastview defined in perspective, to fastview * {@link MToolControl} defined in window. * * @param fromPerspective * @param toWindow */ public static void transferFastViewPersistedState(MPerspective fromPerspective, MTrimmedWindow toWindow){ EModelService modelService = getService(EModelService.class); String perspectiveId = fromPerspective.getElementId(); Optional<MToolControl> mToolControl = getFastViewToolControl(modelService, toWindow, perspectiveId, SideValue.BOTTOM); mToolControl.ifPresent(toolControl -> { Optional<MPartStack> mStack = getFastViewPartStack(fromPerspective); mStack.ifPresent(stack -> { if (stack.getPersistedState() != null && !stack.getPersistedState().isEmpty()) { for (String key : stack.getPersistedState().keySet()) { toolControl.getPersistedState().put(key, stack.getPersistedState().get(key)); } } }); }); }
Example #9
Source File: ElexisFastViewUtil.java From elexis-3-core with Eclipse Public License 1.0 | 5 votes |
private static boolean hasFastViewPersistedState(MPerspective mPerspective){ Optional<MPartStack> mStack = getFastViewPartStack(mPerspective); if (mStack.isPresent()) { Map<String, String> persistedState = mStack.get().getPersistedState(); return persistedState != null && !persistedState.isEmpty(); } return false; }
Example #10
Source File: ShowNXTPerspectiveHandler.java From offspring with MIT License | 5 votes |
@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 #11
Source File: ElexisFastViewUtil.java From elexis-3-core with Eclipse Public License 1.0 | 5 votes |
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 #12
Source File: ElexisProcessor.java From elexis-3-core with Eclipse Public License 1.0 | 5 votes |
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: 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 #14
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 #15
Source File: PerspectiveImportService.java From elexis-3-core with Eclipse Public License 1.0 | 5 votes |
@SuppressWarnings("restriction") @Override public MPerspective loadPerspectiveFromStream(InputStream in) throws IOException{ try { Resource resource = new E4XMIResourceFactory().createResource(null); resource.load(in, null); if (!resource.getContents().isEmpty()) { MPerspective loadedPerspective = (MPerspective) resource.getContents().get(0); return loadedPerspective; } return null; } finally { IOUtils.closeQuietly(in); } }
Example #16
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 #17
Source File: PerspectiveImportService.java From elexis-3-core with Eclipse Public License 1.0 | 5 votes |
private String getActivePerspectiveId(){ MPerspective mPerspective = getActivePerspective(); if (mPerspective != null) { return mPerspective.getElementId(); } return null; }
Example #18
Source File: PerspectiveExportService.java From elexis-3-core with Eclipse Public License 1.0 | 5 votes |
/** * Workaround for https://bugs.eclipse.org/bugs/show_bug.cgi?id=481996 Set the references of the * placeholder to the corresponding parts again in the copy. */ private static MPerspective clonePerspectiveWithWorkaround(EModelService modelService, MPerspective original){ MPerspective clone = (MPerspective) modelService.cloneElement(original, null); clone.setElementId(original.getElementId()); List<MPlaceholder> placeholderClones = modelService.findElements(clone, null, MPlaceholder.class, null, EModelService.IN_ANY_PERSPECTIVE); // For each placeholder in the new perspective, set the reference value to the one from the old perspective for (MPlaceholder placeholderClone : placeholderClones) { // Search for the corresponding placeholder in the "old" perspective List<MPlaceholder> placeholderOriginal = modelService.findElements(original, placeholderClone.getElementId(), MPlaceholder.class, null, EModelService.IN_ANY_PERSPECTIVE); if (placeholderOriginal.size() == 1) { // We found only one corresponding placeholder element. Set reference of old element to the new element placeholderClone.setRef((placeholderOriginal.get(0).getRef())); } else if (placeholderOriginal.isEmpty()) { System.out.println("NO PLACEHOLDER"); } else { System.out.println("MORE THEN ONE PLACEHOLDER" + " " //$NON-NLS-1$ + placeholderOriginal.toString()); placeholderClone.setRef((placeholderOriginal.get(0).getRef())); } } return clone; }
Example #19
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 #20
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 #21
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 #22
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 #23
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 #24
Source File: ShowTraderPerspectiveHandler.java From offspring with MIT License | 5 votes |
@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 #25
Source File: ShowTraderPerspectiveHandler.java From offspring with MIT License | 4 votes |
@CanExecute public boolean canExecute(MPerspective myPerspective) { if (!myPerspective.getElementId().equals(PART_ID)) return true; return false; }
Example #26
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); } }
Example #27
Source File: ShowNXTPerspectiveHandler.java From offspring with MIT License | 4 votes |
@CanExecute public boolean canExecute(MPerspective myPerspective) { if (!myPerspective.getElementId().equals(PART_ID)) return true; return false; }
Example #28
Source File: PerspectiveImportService.java From elexis-3-core with Eclipse Public License 1.0 | 4 votes |
@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 #29
Source File: ShowHomePerspectiveHandler.java From offspring with MIT License | 4 votes |
@CanExecute public boolean canExecute(MPerspective myPerspective) { if (!myPerspective.getElementId().equals(PART_ID)) return true; return false; }
Example #30
Source File: ShowHomePerspectiveHandler.java From offspring with MIT License | 4 votes |
@Execute public void execute(MApplication app, EPartService partService, EModelService modelService) { MPerspective element = (MPerspective) modelService.find(PART_ID, app); partService.switchPerspective(element); }