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

The following examples show how to use org.eclipse.e4.ui.model.application.ui.MElementContainer#getParent() . 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: E4WindowCmd.java    From e4macs with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * 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 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: FrameJoinCmd.java    From e4macs with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * @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 4
Source File: E4WindowCmd.java    From e4macs with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * @param ele start from here
 * @return the most distant parent for the editor area
 */
protected MElementContainer<MUIElement> getTopElement(MElementContainer<MUIElement> ele) {
	MElementContainer<MUIElement> parent = ele;
	// get the outer container
	if (parent != null) {
		while (!((Object)parent instanceof MArea) && parent.getParent() != null) {
				parent = parent.getParent();
		}
	}
	return parent;
}