blob: 3f1280239e25d9a68082ad31cadf4e3bd6f65b06 [file] [log] [blame]
/**
*
* Copyright (c) 2011, 2016 - Loetz GmbH&Co.KG (69115 Heidelberg, Germany)
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Christophe Loetz (Loetz GmbH&Co.KG) - initial implementation
*
*/
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;
}
}