org.eclipse.e4.ui.model.application.ui.basic.MPart Java Examples
The following examples show how to use
org.eclipse.e4.ui.model.application.ui.basic.MPart.
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: SwitchToBufferFrameCmd.java From e4macs with Eclipse Public License 1.0 | 6 votes |
@Execute public Object execute(@Active MWindow window, @Active MPart apart, @Active IEditorPart editor, @Active EmacsPlusCmdHandler handler, @Named(E4CmdHandler.CMD_CTX_KEY)boolean display, @Named(E4CmdHandler.PRE_CTX_KEY) String prefix) { this.window = window; this.handler = handler; this.apart = apart; this.displayOnly = display; this.prefix = prefix; try { ITextEditor ted = EmacsPlusUtils.getTextEditor(editor, true); if (ted != null) { MinibufferHandler.bufferTransform(new SwitchMinibuffer(this, true), ted, null); } } catch (BadLocationException e) { // Shouldn't happen Beeper.beep(); } return null; }
Example #2
Source File: E4WindowCmd.java From e4macs with Eclipse Public License 1.0 | 6 votes |
/** * Get the list of detached windows, if any * * NB: The docs don't guarantee a non-null return, but the implementation seems to * Nor do they guarantee an order, but the implementation currently returns the same order * @return the list of detached windows */ List<MTrimmedWindow> getDetachedFrames() { final MWindow topWindow = application.getChildren().get(0); // NB Selectors aren't supported until Luna // final Selector match = new Selector() { // public boolean select(MApplicationElement element) { // boolean result = element != topWindow && ((MTrimmedWindow)element).isToBeRendered(); // return result && !modelService.findElements((MUIElement)element, null, MPart.class, EDITOR_TAG, EModelService.IN_ANY_PERSPECTIVE).isEmpty(); // } // }; // List<MTrimmedWindow> mts = modelService.findElements(topWindow, MTrimmedWindow.class, EModelService.IN_ANY_PERSPECTIVE, match); // get the all detached editor trimmed windows // the implementation searches all detached windows in this case List<MTrimmedWindow> mts = modelService.findElements(topWindow, null, MTrimmedWindow.class, null, EModelService.IN_ANY_PERSPECTIVE); List<MTrimmedWindow> refined = new ArrayList<MTrimmedWindow>(); for (MTrimmedWindow mt : mts) { if (mt != topWindow && mt.isToBeRendered() && !modelService.findElements(mt, null, MPart.class, EDITOR_TAG, EModelService.IN_ANY_PERSPECTIVE).isEmpty()) { refined.add(mt); } } return refined; }
Example #3
Source File: E4WindowCmd.java From e4macs with Eclipse Public License 1.0 | 6 votes |
/** * Find the edit area. * * @param w * * @return the MArea element containing the editors */ protected MUIElement getEditArea(MWindow w) { // Seems like we should be able to use modelService.find(ID_EDITOR_AREA, w), but that returns a useless PlaceHolder // NB Selectors aren't supported until Luna // final Selector match = new Selector() { // public boolean select(MApplicationElement element) { // return !modelService.findElements((MUIElement)element, null, MPart.class, EDITOR_TAG, EModelService.IN_ANY_PERSPECTIVE).isEmpty(); // } // }; // List<MArea> area = modelService.findElements(w, MArea.class, EModelService.IN_SHARED_AREA, match); List<MArea> area = modelService.findElements(w, null, MArea.class, null, EModelService.IN_SHARED_AREA); List<MArea> refined = new ArrayList<MArea>(); if (area != null) { for (MArea m : area) { if (!modelService.findElements(m, null, MPart.class, EDITOR_TAG, EModelService.IN_ANY_PERSPECTIVE).isEmpty()) { refined.add(m); } } } return refined.isEmpty() ? null : refined.get(0); }
Example #4
Source File: WindowJoinCmd.java From e4macs with Eclipse Public License 1.0 | 6 votes |
/** * Merge the stack containing the selected part into its neighbor and return the * element to activate. This will be the originating buffer on split-self or the * active element in the other stack if not. * * @param apart * @return the element to select */ MPart joinOne(MPart apart) { // We're going to end up with 1, so avoid the overhead of futzing with the stacks if (isSplitSelf() && getOrderedStacks(apart).size() < 3) { this.joinAll(apart); return apart; } else { PartAndStack ps = getParentStack(apart); MElementContainer<MUIElement> pstack = ps.getStack(); MPart part = ps.getPart(); MElementContainer<MUIElement> adjacent = getAdjacentElement(pstack, part, true); MUIElement otherPart = getSelected(adjacent); // deduplicate editors across these two stacks closeOthers(pstack, adjacent); if (pstack == null || join2Stacks(pstack, adjacent, part) == null) { // Invalid state Beeper.beep(); } return (otherPart instanceof MPart) ? (MPart)otherPart : apart; } }
Example #5
Source File: WindowJoinCmd.java From e4macs with Eclipse Public License 1.0 | 6 votes |
/** * Get all the IEditorReferences in a given part stack * * @param stack * @return the collection of IEditorReferences */ private Collection<IEditorReference> getStackEditors(MElementContainer<MUIElement> stack) { Collection<IEditorReference> editors = new ArrayList<IEditorReference>(); for (MUIElement child : stack.getChildren()) { if (child instanceof MPart) { // TODO: There must be a better way of getting the editor out of e4, but I can't find it Object cEditor = ((MPart) child).getObject(); if (cEditor != null) { try { // avoid discouraged access of org.eclipse.ui.internal.e4.compatibility.CompatibilityEditor // which is expected cEditor's type in e4 Method method = cEditor.getClass().getMethod(GET_REF); if (method != null) { IEditorReference ie = (IEditorReference)method.invoke(cEditor); editors.add(ie); } } catch (NoSuchMethodException | SecurityException | IllegalAccessException | IllegalArgumentException | InvocationTargetException | ClassCastException e) { } } } } return editors; }
Example #6
Source File: E4WindowCmd.java From e4macs with Eclipse Public License 1.0 | 6 votes |
/** * Find the first element with which we should join * * @param dragStack the stack to join * @return the target stack */ @SuppressWarnings("unchecked") // for safe cast to MElementContainer<MUIElement> protected MElementContainer<MUIElement> getAdjacentElement(MElementContainer<MUIElement> dragStack, MPart part, boolean stackp) { MElementContainer<MUIElement> result = null; if (dragStack != null) { MElementContainer<MUIElement> psash = dragStack.getParent(); if ((Object)psash instanceof MPartSashContainer) { List<MUIElement> children = psash.getChildren(); int size = children.size(); if (size > 1) { int index = children.indexOf(dragStack)+1; // use the next element, or previous if we're the last one result = (MElementContainer<MUIElement>)children.get((index == size) ? index - 2 : index); if (stackp) { result = findTheStack(result); } } } } return result; }
Example #7
Source File: E4WindowCmd.java From e4macs with Eclipse Public License 1.0 | 6 votes |
/** * The parent of the apart is typically a PartStack, but it could be something under an MCompositePart, so look up * @param apart the original selection * @return the MPart and PartStack */ protected PartAndStack getParentStack(MPart apart) { MPartSashContainerElement part = apart; MElementContainer<MUIElement> stack = apart.getParent(); try { while (!((MPartSashContainerElement)stack instanceof MPartStack)) { if ((MPartSashContainerElement)stack instanceof MArea) { // some unexpected structure stack = null; part = apart; break; } else { part = (MPartSashContainerElement)stack; stack = stack.getParent(); } } } catch (Exception e) { // Bail on anything unexpected - will just make the command a noop stack = null; part = apart; } return new PartAndStack((MPart)part, stack); }
Example #8
Source File: OtherWindowCmd.java From e4macs with Eclipse Public License 1.0 | 6 votes |
@Execute protected void doOtherWindow(@Active MPart apart, @Named(E4CmdHandler.CMD_CTX_KEY)String cmd, @Active EmacsPlusCmdHandler handler) { PartAndStack ps = getParentStack(apart); MElementContainer<MUIElement> otherStack = getAdjacentElement(ps.getStack(), ps.getPart(), true); MPart other = (MPart)otherStack.getSelectedElement(); // TODO An egregious hack that may break at any time // Is there a defined way of getting the IEditorPart from an MPart? if (other.getObject() instanceof CompatibilityEditor) { IEditorPart editor = ((CompatibilityEditor) other.getObject()).getEditor(); try { reactivate(other); if (handler.isUniversalPresent()) { EmacsPlusUtils.executeCommand(cmd, handler.getUniversalCount(), null, editor); } else { EmacsPlusUtils.executeCommand(cmd, null, editor); } } catch (Exception e) { e.printStackTrace(); } finally { reactivate(apart); } } }
Example #9
Source File: AutomaticSwitchPerspectivePartListener.java From bonita-studio with GNU General Public License v2.0 | 6 votes |
protected void switchPerspective(final MPart part) { if (!isSwitching) { isSwitching = true; try { final String activePerspective = getActivePerspectiveId(part); if (part != null && "org.eclipse.e4.ui.compatibility.editor".equals(part.getElementId())) { final CompatibilityEditor compatibilityEditor = (CompatibilityEditor) part.getObject(); if (compatibilityEditor != null && activePerspective != null) { final String id = BonitaPerspectivesUtils.getPerspectiveId(compatibilityEditor.getEditor()); if (id != null && !id.equals(activePerspective)) { BonitaPerspectivesUtils.switchToPerspective(id); } } } } finally { isSwitching = false; } } }
Example #10
Source File: CustomPopupMenuExtender.java From bonita-studio with GNU General Public License v2.0 | 6 votes |
public CustomPopupMenuExtender(final String id, final MenuManager menu, final ISelectionProvider prov, final IWorkbenchPart part, IEclipseContext context, final boolean includeEditorInput) { super(); this.menu = menu; this.selProvider = prov; this.part = part; this.context = context; this.modelPart = part.getSite().getService(MPart.class); if (includeEditorInput) { bitSet |= INCLUDE_EDITOR_INPUT; } menu.addMenuListener(this); if (!menu.getRemoveAllWhenShown()) { menuWrapper = new SubMenuManager(menu); menuWrapper.setVisible(true); } createModelFor(id); addMenuId(id); Platform.getExtensionRegistry().addRegistryChangeListener(this); }
Example #11
Source File: FrameJoinCmd.java From e4macs with Eclipse Public License 1.0 | 6 votes |
/** * @see com.mulgasoft.emacsplus.e4.commands.E4WindowCmd#getAdjacentElement(org.eclipse.e4.ui.model.application.ui.MElementContainer, boolean, org.eclipse.e4.ui.model.application.ui.basic.MPart) */ protected MElementContainer<MUIElement> getAdjacentElement(MElementContainer<MUIElement> dragStack, MPart part, boolean stackp) { MElementContainer<MUIElement> result = null; if (dragStack != null) { MElementContainer<MUIElement> psash = dragStack.getParent(); MElementContainer<MUIElement> top = getTopElement(psash); if ((Object)top instanceof MTrimmedWindow) { // if we contain splits, remove them first if (top != psash) { super.joinAll(part); } Collection<MPart> parts = getParts(application.getChildren().get(0), EModelService.IN_SHARED_AREA); for (MPart p : parts) { List<MElementContainer<MUIElement>> all = getOrderedStacks(p); // if it has a PartStack, it sh/c/ould be an editor stack if (!all.isEmpty()) { result = all.get(0); break; }; }; } } return result; }
Example #12
Source File: SwitchToBufferOtherCmd.java From e4macs with Eclipse Public License 1.0 | 6 votes |
void switchTo(MPart newPart) { if (getOrderedStacks(apart).size() == 1) { // case 1: 1 frame, split with miniPart // convenience hack: change direction on uArg splitIt(newPart, getDirection((isUniversalPresent()) ? !DISPLAY_HORIZONTAL : DISPLAY_HORIZONTAL)); } else { // case 2: multiple stacks, move to adjacent stack // get the starting stack MElementContainer<MUIElement> stack = getParentStack(apart).getStack(); // get the topart's stack MElementContainer<MUIElement> tstack = getParentStack(newPart).getStack(); stack = findNextStack(apart, stack, 1); if (stack != null && stack != tstack) { modelService.move(newPart, stack, 0); } } if (displayOnly) { // brings to top partService.showPart(newPart, PartState.VISIBLE); reactivate(apart); } else { // bug in Kepler forces us to activate the old before the new reactivate(apart); reactivate(newPart); } }
Example #13
Source File: SwitchToBufferOtherCmd.java From e4macs with Eclipse Public License 1.0 | 6 votes |
@Execute public Object execute(@Active MPart apart, @Active IEditorPart editor, @Active EmacsPlusCmdHandler handler, @Named(E4CmdHandler.CMD_CTX_KEY)boolean display, @Named(E4CmdHandler.PRE_CTX_KEY) String prefix) { this.handler = handler; this.apart = apart; this.displayOnly = display; this.prefix = prefix; try { ITextEditor ted = EmacsPlusUtils.getTextEditor(editor, true); if (ted != null) { MinibufferHandler.bufferTransform(new SwitchMinibuffer(this), ted, null); } } catch (BadLocationException e) { // Shouldn't happen Beeper.beep(); } return null; }
Example #14
Source File: TaskDetailPart.java From elexis-3-core with Eclipse Public License 1.0 | 6 votes |
@PostConstruct public void postConstruct(Composite parent, MPart part){ parent.setLayout(new GridLayout(1, false)); ITask task = (ITask) part.getTransientData().get("task"); part.setIconURI(TaskResultLabelProvider.getInstance().getIconURI(task)); String runAt; LocalDateTime _runAt = task.getRunAt(); if(_runAt != null) { runAt = _runAt.format(DateTimeFormatter.ofLocalizedDate(FormatStyle.FULL)); } else { runAt = "queued"; } String partLabel = task.getTaskDescriptor().getReferenceId() + " - " + runAt; part.setLabel(partLabel); Map<String, Object> e4Services = new HashMap<String, Object>(); e4Services.put(ECommandService.class.getName(), commandService); e4Services.put(EHandlerService.class.getName(), handlerService); taskResultDetailDialogContributions.createDetailCompositeForTask(parent, task, e4Services); }
Example #15
Source File: WindowJoinCmd.java From e4macs with Eclipse Public License 1.0 | 5 votes |
void closePart(MPart part) { // based on org.eclipse.e4.ui.workbench.renderers.swt.StackRenderer.closePart() IEclipseContext context = part.getContext(); if (context != null && part.isCloseable()) { EPartService partService = context.get(EPartService.class); partService.hidePart(part,true); } }
Example #16
Source File: FrameOtherCmd.java From e4macs with Eclipse Public License 1.0 | 5 votes |
/** * If we can find a selected MPart, activate it * * @param ele */ private void focusIt(MUIElement ele) { MUIElement sel = getSelected(ele); // There's a bug somewhere in eclipse where this could return null, so check if (sel != null) { sel.setVisible(true); if (sel instanceof MPart) { reactivate((MPart)sel); } } }
Example #17
Source File: FrameJoinCmd.java From e4macs with Eclipse Public License 1.0 | 5 votes |
@Override MPart joinOne(MPart apart) { joined = true; if ((Object)getTopElement(apart.getParent()) instanceof MTrimmedWindow) { return super.joinOne(apart); } else { joined = false; Beeper.beep(); } return apart; }
Example #18
Source File: WindowJoinCmd.java From e4macs with Eclipse Public License 1.0 | 5 votes |
@Execute public Object execute(@Active MPart apart, @Active IEditorPart editor, @Named(E4CmdHandler.CMD_CTX_KEY)Join jtype, @Active EmacsPlusCmdHandler handler) { MPart active = apart; boolean joined = preJoin(editor); switch (jtype) { case ONE: active = joinOne(apart); if (joined) { // don't switch buffers on a split self merge active = apart; } break; case ALL: joinAll(apart); break; } postJoin(editor); if (handler.isUniversalPresent()) { // convenience hack // change setting without changing preference store setSplitSelf(!isSplitSelf()); } final MPart ed = active; Display.getDefault().asyncExec(() -> {reactivate(ed);}); return null; }
Example #19
Source File: E4WindowCmd.java From e4macs with Eclipse Public License 1.0 | 5 votes |
/** * Get the ordered list of stacks * @param apart * @return a list of MElementContainer<MUIElement> representing all the PartStacks */ protected List<MElementContainer<MUIElement>> getOrderedStacks(MPart apart) { List<MElementContainer<MUIElement>> result = new ArrayList<MElementContainer<MUIElement>>(); MElementContainer<MUIElement> parent = getTopElement(apart.getParent()); if (parent != null) { result = getStacks(result, parent); } return result; }
Example #20
Source File: WindowDeclOtherCmd.java From e4macs with Eclipse Public License 1.0 | 5 votes |
@Execute public Object execute(@Active MPart apart, @Active IEditorPart editor, @Active MWindow mwin, @Active EmacsPlusCmdHandler handler) { try { this.apart = apart; this.handler = handler; Command ex = getOpenCmd(editor); if (ex != null) { MUIElement area = getEditArea(application.getChildren().get(0)); MUIElement osel = getSelected(area); EmacsPlusUtils.executeCommand(ex.getId(), null); MUIElement sel = getSelected(area); // see if it was able to open a declaration if (sel instanceof MPart && sel != apart && sel != osel) { // another way of determining if we're main or frame if (!mwin.getTags().contains(TOP_TAG) && !handler.isUniversalPresent()) { // If they're in different frames, move copy to source frame first modelService.move(sel, getParentStack(apart).getStack(), 0); }; switchTo((MPart)sel); } } } catch (Exception e) { // Shouldn't happen Beeper.beep(); } return null; }
Example #21
Source File: WindowShrinkCmd.java From e4macs with Eclipse Public License 1.0 | 5 votes |
@Execute public Object execute(@Active MPart apart, @Named(E4CmdHandler.CMD_CTX_KEY)Col stype, @Active EmacsPlusCmdHandler handler) { PartAndStack ps = getParentStack(apart); MElementContainer<MUIElement> stack = ps.getStack(); MElementContainer<MUIElement> next = getAdjacentElement(stack, ps.getPart(), false); int count = handler.getUniversalCount(); // if we have an adjacent part, we're in a sash if (next != null) { switch (stype) { case SHRINK: adjustContainerData((MUIElement)stack, (MUIElement)next, count, getTotalSize(apart)); break; case ENLARGE: adjustContainerData((MUIElement)next, (MUIElement)stack, count, getTotalSize(apart)); break; case BALANCE: balancePartSash(stack); break; } // For some reason, in recent eclipses, we have to request the layout manually Object widget = stack.getWidget(); // Double check before grabbing the parent composite for looping if (widget instanceof CTabFolder) { // this is apparently the recommended way of getting these to redraw properly for (Control c : ((Composite)widget).getParent().getChildren()) { c.requestLayout(); } } } return null; }
Example #22
Source File: WindowJoinCmd.java From e4macs with Eclipse Public License 1.0 | 5 votes |
/** * Merge all stacks into one * * @param apart - the selected MPart */ void joinAll(MPart apart) { try { // deduplicate editors across all stacks IDeduplication.closeAllDuplicates(EmacsPlusUtils.getWorkbenchPage()); } catch (PartInitException e) { // Ignore } List<MElementContainer<MUIElement>> stacks = getOrderedStacks(apart); if (stacks.size() > 1) { PartAndStack ps = getParentStack(apart); MElementContainer<MUIElement> pstack = ps.getStack(); MPart part = ps.getPart(); // check for unexpected result - who knows what Eclipse might do if (pstack != null) { MElementContainer<MUIElement> dropStack = stacks.get(0); for (int i = 1; i < stacks.size(); i++) { MElementContainer<MUIElement> stack = stacks.get(i); if (stack == pstack) { continue; } join2Stacks(stacks.get(i), dropStack, null); } // lastly, join in the selected stack if (pstack != dropStack) { join2Stacks(pstack, dropStack, part); } } else { Beeper.beep(); } } }
Example #23
Source File: TaskResultPartTableFilterHandler.java From elexis-3-core with Eclipse Public License 1.0 | 5 votes |
@Execute public void execute(MPart part, MDirectToolItem item){ TaskResultPart taskResultPart = (TaskResultPart) part.getObject(); if (item.isSelected()) { if (showFailuresOnlyFilter == null) { showFailuresOnlyFilter = (object) -> !((ITask) object).isSucceeded(); } taskResultPart.getContentProvider().setFilter(showFailuresOnlyFilter); } else { taskResultPart.getContentProvider().setFilter(AcceptAllFilter.getInstance()); } }
Example #24
Source File: WindowJoinCmd.java From e4macs with Eclipse Public License 1.0 | 5 votes |
/** * Given 2 partStacks, move children of pstack into dropStack * @param pstack - source stack * @param dropStack - destination stack * @param apart - the initiating part * @return the enhanced dropStack */ protected MElementContainer<MUIElement> join2Stacks(MElementContainer<MUIElement> pstack, MElementContainer<MUIElement> dropStack, MPart apart) { if (dropStack != null && ((MPartSashContainerElement)dropStack) instanceof MPartStack) { List<MUIElement> eles = pstack.getChildren(); boolean hasPart = apart != null; int offset = 1; List<MUIElement> drops = dropStack.getChildren(); while (eles.size() > (hasPart ? 1 : 0)) { MUIElement ele = eles.get(eles.size() - offset); if (hasPart && ele == apart) { offset++; continue; } eles.remove(ele); if (hasPart) { drops.add(0,ele); } else { drops.add(ele); } } if (hasPart) { // Move the selected element to the leftmost position eles.remove(apart); drops.add(0,apart); dropStack.setSelectedElement(apart); } checkSizeData(pstack,dropStack); } return dropStack; }
Example #25
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 #26
Source File: OpenIntroAddon.java From bonita-studio with GNU General Public License v2.0 | 5 votes |
private void handleEvent(Event event) { Object part = event.getProperty(UIEvents.EventTags.ELEMENT); if (part instanceof MPart) { if (((MPart) part).getElementId().equals("org.eclipse.e4.ui.compatibility.editor")) { if(repositoryAccessor.getCurrentRepository().isOpenIntroListenerEnabled()) { PlatformUtil.openIntroIfNoOtherEditorOpen(); } } } }
Example #27
Source File: ElexisProcessor.java From elexis-3-core with Eclipse Public License 1.0 | 5 votes |
private void updateInjectViews(){ for (String viewId : injectViewIds) { List<MPart> foundParts = eModelService.findElements(mApplication, viewId, MPart.class, null); for (MPart mPart : foundParts) { List<String> tags = mPart.getTags(); if (!tags.contains("inject")) { tags.add("inject"); } } } }
Example #28
Source File: ElexisProcessor.java From elexis-3-core with Eclipse Public License 1.0 | 5 votes |
private void updateE4Views(){ for (String viewId : e4ViewIds) { List<MPart> foundParts = eModelService.findElements(mApplication, viewId, MPart.class, null); for (MPart mPart : foundParts) { // remove references to old CompatibilityView part if (mPart.getContributionURI() == null || mPart.getContributionURI().endsWith("CompatibilityView")) { EcoreUtil.delete((EObject) mPart); } } } }
Example #29
Source File: TaskResultPart.java From elexis-3-core with Eclipse Public License 1.0 | 5 votes |
@Override public void doubleClick(DoubleClickEvent event){ ITask selectedTask = (ITask) ((StructuredSelection) event.getSelection()).getFirstElement(); MPart taskDetailPart = partService.createPart("ch.elexis.core.ui.tasks.partdescriptor.taskdetail"); taskDetailPart.getTransientData().put("task", selectedTask); partService.showPart(taskDetailPart, PartState.CREATE); }
Example #30
Source File: HandlerDisplayIgnored.java From MergeProcessor with Apache License 2.0 | 5 votes |
@Execute public void execute(MItem item, MPart part, IConfiguration configuration, UISynchronize uiSynch) { LogUtil.entering(item, part, configuration, uiSynch); configuration.setDisplayIgnored(item.isSelected()); final Object object = part.getObject(); if (object instanceof Dashboard) { final Dashboard view = (Dashboard) object; uiSynch.syncExec(view::refresh); } LogUtil.exiting(); }