| package org.eclipse.osbp.xtext.action.common; |
| |
| import org.eclipse.e4.ui.model.application.ui.MElementContainer; |
| import org.eclipse.e4.ui.model.application.ui.MUIElement; |
| import org.eclipse.e4.ui.model.application.ui.basic.MPart; |
| |
| public class E4Helper { |
| private E4Helper() { |
| } |
| |
| public static final MUIElement getPart(boolean next, MUIElement element, boolean wasActive) { |
| int direction = +1; |
| if(!next) { |
| direction = -1; |
| } |
| MElementContainer<MUIElement> parent = element.getParent(); |
| MUIElement child = null; |
| if (wasActive) { |
| int index = parent.getChildren().size() - 1; |
| if(!next) { |
| index = 0; |
| } |
| if (parent.getChildren().indexOf(element) == index) { |
| return getPart(next, parent, wasActive); |
| } else { |
| child = parent.getChildren().get(parent.getChildren().indexOf(element) + direction); |
| } |
| } else { |
| child = parent.getChildren().get(parent.getChildren().indexOf(element)); |
| } |
| if (child instanceof MPart) { |
| return child; |
| } |
| if (child instanceof MElementContainer<?> && !((MElementContainer<?>) child).getChildren().isEmpty()) { |
| int index = 0; |
| if(!next) { |
| index = ((MElementContainer<?>) child).getChildren().size() - 1; |
| } |
| return getPart(next, (MUIElement) ((MElementContainer<?>) child).getChildren().get(index), false); |
| } |
| if (parent instanceof MElementContainer<?> && !parent.getChildren().isEmpty()) { |
| int index = 0; |
| if(!next) { |
| index = parent.getChildren().size() - 1; |
| } |
| return getPart(next, (MUIElement) parent.getChildren().get(index), false); |
| } |
| return null; |
| } |
| } |