Skip to content
Snippets Groups Projects
Commit 05bf1086 authored by Simon Barner's avatar Simon Barner
Browse files

GenericAnnotationView.getModelElementLevel() and getModelElementAncestor() to EcoreUtils

refs 2289
parent 695e1c43
No related branches found
No related tags found
No related merge requests found
......@@ -23,7 +23,6 @@ import java.util.Map;
import java.util.Set;
import java.util.TreeSet;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.jface.viewers.ArrayContentProvider;
import org.eclipse.jface.viewers.ColumnLabelProvider;
import org.eclipse.jface.viewers.ColumnViewerToolTipSupport;
......@@ -69,7 +68,7 @@ import org.fortiss.tooling.base.ui.annotation.view.generic.filter.AnnotationFilt
* @author eder, diewald, barner
* @author $Author$
* @version $Rev$
* @ConQAT.Rating GREEN Hash: 3692BC71F2463FE6F6A5B7FE464CA393
* @ConQAT.Rating YELLOW Hash: A017D78A4C2EC0D3776FBD13FE452645
*/
public class GenericAnnotationView extends AnnotationViewPartBase {
/** Root composite of {@link GenericAnnotationView}. */
......@@ -140,33 +139,6 @@ public class GenericAnnotationView extends AnnotationViewPartBase {
return annotationFilter;
}
// TODO (see #2289) Move to EcoreUtils
/** Computes the level of an {@link IModelElement} in the tree. */
public static int getModelElementLevel(EObject o) {
int level = 0;
while(o.eContainer() != null) {
level++;
o = o.eContainer();
}
return level;
}
// TODO (see #2289) Move to EcoreUtils
/**
* Returns the ancestor of the {@link IModelElement} {@code modelElement} that is
* {@code levelsUp} levels above model element in the hierarchy, or {@code null}, in case
* {@code levelsUp} > depth(modelElement}.
*/
public static EObject getModelElementAncestor(EObject o, int levelsUp) {
while(o.eContainer() != null && levelsUp > 0) {
o = o.eContainer();
levelsUp--;
}
return o;
}
/** Updates the table after a filter change */
public void update() {
// Full update, i.e. including reconstructions of columns is always required due to the
......
......@@ -17,8 +17,8 @@ $Id$
+--------------------------------------------------------------------------*/
package org.fortiss.tooling.base.ui.annotation.view.generic;
import static org.fortiss.tooling.base.ui.annotation.view.generic.GenericAnnotationView.getModelElementAncestor;
import static org.fortiss.tooling.base.ui.annotation.view.generic.GenericAnnotationView.getModelElementLevel;
import static org.fortiss.tooling.kernel.utils.EcoreUtils.getModelElementAncestor;
import static org.fortiss.tooling.kernel.utils.EcoreUtils.getModelElementLevel;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.jface.viewers.Viewer;
......@@ -35,7 +35,7 @@ import org.fortiss.tooling.kernel.model.INamedElement;
* @author eder, diewald, barner
* @author $Author$
* @version $Rev$
* @ConQAT.Rating GREEN Hash: CB8928BF75D68CF598C29B536B603B16
* @ConQAT.Rating YELLOW Hash: 5B767B06FBDBAA5717DD857B148FE553
*/
public class HierarchicalNameComparator extends ViewerComparator {
......
......@@ -17,8 +17,8 @@ $Id$
+--------------------------------------------------------------------------*/
package org.fortiss.tooling.base.ui.annotation.view.generic.filter;
import static org.fortiss.tooling.base.ui.annotation.view.generic.GenericAnnotationView.getModelElementAncestor;
import static org.fortiss.tooling.base.ui.annotation.view.generic.GenericAnnotationView.getModelElementLevel;
import static org.fortiss.tooling.kernel.utils.EcoreUtils.getModelElementAncestor;
import static org.fortiss.tooling.kernel.utils.EcoreUtils.getModelElementLevel;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.jface.viewers.TableViewer;
......@@ -44,7 +44,7 @@ import org.fortiss.tooling.kernel.model.IProjectRootElement;
* @author barner
* @author $Author$
* @version $Rev$
* @ConQAT.Rating GREEN Hash: 4AFB9561426C00D767D4E6E91CF24B29
* @ConQAT.Rating YELLOW Hash: 1D5F427C7FCB775316A06A27FB2ADDBE
*/
public class AnnotationFilter extends ViewerFilter {
/** Filter hint text. */
......
......@@ -48,7 +48,7 @@ import org.eclipse.emf.ecore.util.EcoreUtil.Copier;
* @author ratiu
* @author $Author: hoelzl $
* @version $Rev: 18709 $
* @ConQAT.Rating GREEN Hash: 283A66F00038F9CA2487E758FC9C057E
* @ConQAT.Rating YELLOW Hash: 270D4A0ECC6F3F4A98737C3C53C9D4E0
*/
public class EcoreUtils {
......@@ -380,4 +380,29 @@ public class EcoreUtils {
return null;
}
/** Computes the level of an {@link EObject} in the tree. */
public static int getModelElementLevel(EObject o) {
int level = 0;
while(o.eContainer() != null) {
level++;
o = o.eContainer();
}
return level;
}
/**
* Returns the ancestor of the {@link EObject} {@code o} that is {@code levelsUp} levels above
* model element in the hierarchy, or {@code null}, in case {@code levelsUp >
* depth(modelElement)}.
*/
public static EObject getModelElementAncestor(EObject o, int levelsUp) {
while(o.eContainer() != null && levelsUp > 0) {
o = o.eContainer();
levelsUp--;
}
return o;
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment