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

The following examples show how to use org.eclipse.e4.ui.model.application.ui.MElementContainer#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: ArrangeDisplayViews.java    From gama with GNU General Public License v3.0 6 votes vote down vote up
public static void hideDisplays(final MPartStack displayStack, final List<MPlaceholder> holders) {
	final MElementContainer<MUIElement> parent = displayStack.getParent();
	parent.setVisible(false);
	holders.forEach((ph) -> {
		ph.setVisible(false);
		displayStack.getChildren().add(ph);
	});
	activateDisplays(holders, false);
	for (final MUIElement element : new ArrayList<>(parent.getChildren())) {
		if (element.getTransientData().containsKey(LAYOUT)) {
			element.setVisible(false);
			element.setToBeRendered(false);
			parent.getChildren().remove(element);
		}
	}
}
 
Example 2
Source File: E4WindowCmd.java    From e4macs with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * 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 3
Source File: WindowJoinCmd.java    From e4macs with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * 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 4
Source File: E4WindowCmd.java    From e4macs with Eclipse Public License 1.0 5 votes vote down vote up
private List<MElementContainer<MUIElement>> getStacks(List<MElementContainer<MUIElement>> result, MElementContainer<MUIElement> container) {
	for (MUIElement child : container.getChildren()) {
		@SuppressWarnings("unchecked") // We type check all the way down
		MElementContainer<MUIElement> c = (MElementContainer<MUIElement>)child;
		if (child instanceof MPartStack) {
			result.add(c);
		} else {
			getStacks(result,c);
		}
	}
	return result;
}
 
Example 5
Source File: E4WindowCmd.java    From e4macs with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * If parent is a sash, keep looking until we find a PartStack
 * 
 * @param parent a sash of PartStack
 * @return the first PartStack we find
 */
@SuppressWarnings("unchecked")  // for safe cast to MElementContainer<MUIElement>
private MElementContainer<MUIElement> findTheStack(MElementContainer<MUIElement> parent) {
	MElementContainer<MUIElement> result = parent;
	if ((MPartSashContainerElement)parent instanceof MPartSashContainer) {
		List<MUIElement> children = parent.getChildren();
		result = findTheStack((MElementContainer<MUIElement>)children.get(0));
	}
	return result;
}
 
Example 6
Source File: WindowJoinCmd.java    From e4macs with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * 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 7
Source File: UIHelper.java    From tlaplus with MIT License 4 votes vote down vote up
/**
 * Parts (Editors and Views) can be stacked if the user drags them on top of
 * each other. This method returns true, if the given part (first parameter)
 * and the second part (identified by its Id) are indeed stacked.
 * 
 * @param part
 *            The one part (not null) for which to check if the second part
 *            (otherId) are on the same part stack.
 * @param otherId
 *            The second part's id (not null).
 * @return true iff both parts are stacked on top of each other, false
 *         otherwise.
 */
public static boolean isInSameStack(final IWorkbenchPart part, final String otherId) {
	Assert.isNotNull(part);
	Assert.isNotNull(otherId);
	
	// The implementation below uses Eclipse's new UI model (e4) that is the
	// default starting with the 4.x series. It does *not* exist on any 3.x
	// release of Eclipse. Thus, if the Toolbox ever has to run on 3.x
	// again, just remove the implementation below and return false. The
	// only place where this method is used at the time of writing is to
	// prevent a stack overflow when the ModelEditor and TLCErrorView are
	// stacked. This isn't possible with 3.x anyway as Views (TLCErrorView)
	// and Editors (ModelEditor) could not be stacked upon each other (this
	// was actually an artificial restriction and missed by many). That is
	// also the very reason, why the Eclipse 3.x API does not support
	// finding out if an editor and a view are stacked
	// (IWorkbenchPage#getViewRefererences() and
	// IWorkbenchPage#getEditorReferences() are mutually exclusive).

	// Obtain the e4's part context IEclipseContext (each logical UI element
	// (parts, perspectives, application windows... have a corresponding
	// context).
	final IEclipseContext ctx = (IEclipseContext) part.getSite().getService(IEclipseContext.class);
	if (ctx == null) {
		// I don't see in which case the ctx is null, but lets be on the safe side.
		return false;
	}
	// The ctx also has the e4 UI model counterpart (MPart) to the technical
	// IWorkbenchPart instance (the UI model is a logical representation of
	// the UI state of the Toolbox).
	final MPart e4ModelPart = ctx.get(MPart.class);
	// e4 Model elements have references to their respective parents. In
	// case of our MPart/IWorkbenchPart, it is a stack if it happens to be
	// rendered in one at the moment.
	final MElementContainer<MUIElement> stack = e4ModelPart.getParent();
	if (stack == null) {
		// The part has no parent, e.g when it's not stacked
		return false;
	}
	// A MPartStack's children are the MParts currently rendered in it
	// (visible or not). Since it is the MPartStack of the IWorkbenchPart,
	// we just check if another child has the Id of the other part we are
	// interested in. If this is the case, both parts are indeed shown in
	// the same part stack on top of each other.
	final List<MUIElement> children = stack.getChildren();
	for (final MUIElement muiElement : children) {
		final String elementId = muiElement.getElementId();
		if (elementId != null && elementId.equals(otherId)) {
			return true;
		}
	}
	return false;
}