use of org.eclipse.jface.viewers.TreePath in project tmdm-studio-se by Talend.
the class DataModelMainPage method getStructureByActiveItem.
public XSDAnnotationsStructure getStructureByActiveItem() {
XSDComponent xSDCom = null;
XSDAnnotationsStructure struc = null;
IStructuredSelection selection = (TreeSelection) getTreeViewer().getSelection();
if (selection.getFirstElement() instanceof Element) {
TreePath tPath = ((TreeSelection) selection).getPaths()[0];
for (int i = 0; i < tPath.getSegmentCount(); i++) {
if (tPath.getSegment(i) instanceof XSDAnnotation) {
xSDCom = (XSDAnnotation) (tPath.getSegment(i));
}
}
} else {
xSDCom = (XSDComponent) selection.getFirstElement();
}
if (xSDCom != null) {
struc = new XSDAnnotationsStructure(xSDCom);
}
return struc;
}
use of org.eclipse.jface.viewers.TreePath in project tmdm-studio-se by Talend.
the class DataModelMainPage method activeMarkerItem.
private void activeMarkerItem(TreeViewer v, Element dom) {
ITreeContentProvider provider = (ITreeContentProvider) v.getContentProvider();
for (Object data : provider.getElements(xsdSchema)) {
Object[] foundData = findMarkerData(provider, data, dom, new Object[0]);
if (foundData != null) {
TreePath treePath = new TreePath(foundData);
v.setSelection(new TreeSelection(treePath));
return;
}
}
}
use of org.eclipse.jface.viewers.TreePath in project tmdm-studio-se by Talend.
the class TreeExpandHelper method removeInvalidTreePaths.
private TreePath[] removeInvalidTreePaths(TreePath[] expandedElementPaths) {
Map<Integer, Set<TreePath>> pathMaps = new HashMap<Integer, Set<TreePath>>();
int maxSegmentCount = -1;
for (TreePath path : expandedElementPaths) {
int segmentCount = path.getSegmentCount();
Set<TreePath> pathSet = pathMaps.get(segmentCount);
if (pathSet == null) {
pathSet = new HashSet<TreePath>();
pathMaps.put(segmentCount, pathSet);
}
pathSet.add(path);
//
if (maxSegmentCount < segmentCount) {
maxSegmentCount = segmentCount;
}
}
Set<TreePath> roots = pathMaps.get(1);
if (roots == null || roots.size() == 0) {
return new TreePath[0];
}
// record TreePath by tree level
List<TreePath> paths = new ArrayList<TreePath>();
paths.addAll(roots);
for (int i = 2; i < maxSegmentCount + 1; i++) {
Set<TreePath> set = pathMaps.get(i);
if (set == null || set.size() == 0) {
break;
}
Set<TreePath> parents = pathMaps.get(i - 1);
Iterator<TreePath> iterator = set.iterator();
while (iterator.hasNext()) {
TreePath path = iterator.next();
if (parents.contains(path.getParentPath())) {
paths.add(path);
} else {
iterator.remove();
}
}
}
return paths.toArray(new TreePath[0]);
}
use of org.eclipse.jface.viewers.TreePath in project tmdm-studio-se by Talend.
the class TreeExpandHelper method getExpandedNodes.
private List<ExpandInfoNode> getExpandedNodes(TreePath[] expandedElementPaths) {
TreePath[] expandedPaths = removeInvalidTreePaths(expandedElementPaths);
List<ExpandInfoNode> expanded = new ArrayList<ExpandInfoNode>();
ExpandInfoNode rootNode = null;
for (TreePath path : expandedPaths) {
int segmentCount = path.getSegmentCount();
Object firstSegment = path.getFirstSegment();
rootNode = ExpandInfoNode.create(getName(firstSegment), firstSegment.getClass().getName());
if (expanded.contains(rootNode)) {
rootNode = expanded.get(expanded.indexOf(rootNode));
} else {
expanded.add(rootNode);
}
for (int i = 1; i < segmentCount; i++) {
Object segment = path.getSegment(i);
ExpandInfoNode newNode = ExpandInfoNode.create(getName(segment), segment.getClass().getName());
if (rootNode.childs == null) {
rootNode.addChild(newNode);
} else {
if (rootNode.childs.contains(newNode)) {
newNode = rootNode.childs.get(rootNode.childs.indexOf(newNode));
} else {
rootNode.addChild(newNode);
}
}
rootNode = newNode;
}
}
return expanded;
}
use of org.eclipse.jface.viewers.TreePath in project abstools by abstools.
the class LinkHelper method buildTreeSelection.
/**
* Build up a {@link TreeSelection} suitable for the ABSNavigator from the
* given component
*
* @param project
* IProject The according project of the ModuleDecl.
* @param md
* ModuleDecl The target ModuleDecl to highlight.
* @return A TreeSelection including a {@link TreePath} from project to md
* or null if md or project is null, or if no ABSnature can be
* retrieved from project
*/
private static TreeSelection buildTreeSelection(AbsNature nature, IProject project, InternalASTNode<ModuleDecl> md) {
assert nature != null;
// TODO: if this holds (as it should), remove argument
assert nature == md.getNature();
if (project != null && md != null) {
// Split the module's name and return the module hierarchy
ArrayList<ModulePath> paths = md.getParentHierarchyForModuleDecl();
ArrayList<Object> arli = new ArrayList<Object>();
arli.add(project);
if (paths.size() > 0) {
ModulePath lastElement = paths.get(paths.size() - 1);
arli.addAll(paths);
if (!(lastElement.hasModule() && lastElement.getModulePath().equals(md.getASTNode().getName()))) {
arli.add(md);
}
} else {
if (NavigatorUtils.hasSubModules(md)) {
arli.add(new ModulePath(nature, md.getASTNode().getName()));
} else {
arli.add(md);
}
}
TreePath path = new TreePath(arli.toArray());
TreeSelection ts = new TreeSelection(new TreePath[] { path });
return ts;
}
return null;
}
Aggregations