use of org.eclipse.jface.viewers.TreePath in project tdi-studio-se by Talend.
the class MoveDownTreeNodeButton method updateStatus.
/*
* (non-Javadoc)
*
* @see org.talend.designer.fileoutputxml.ui.footer.AbstractTreeNodeButton#updateButtonStatus()
*/
@Override
protected void updateStatus(TreeSelection selection) {
if (selection.isEmpty()) {
getButton().setEnabled(false);
return;
}
final TreePath[] paths = selection.getPaths();
boolean sameSegment = true;
for (int i = 0; i < paths.length - 1; i++) {
if (paths[i].getSegmentCount() != paths[i + 1].getSegmentCount()) {
sameSegment = false;
}
}
if (sameSegment) {
getButton().setEnabled(true);
} else {
getButton().setEnabled(false);
return;
}
// if same segment ,they have the same parent and parent must be an element
FOXTreeNode foxNode = (FOXTreeNode) selection.getFirstElement();
if (foxNode.getParent() instanceof Element) {
final Element parent = (Element) foxNode.getParent();
if (parent == null) {
getButton().setEnabled(false);
return;
}
final List<? extends FOXTreeNode> attrChildren = parent.getAttributeChildren();
final List<? extends FOXTreeNode> nameSpaceChildren = parent.getNameSpaceChildren();
final List<FOXTreeNode> elementChildren = parent.getElementChildren();
final Iterator iterator = selection.iterator();
while (iterator.hasNext()) {
final Object next = iterator.next();
if (next instanceof Attribute) {
if (attrChildren.contains(next) && attrChildren.indexOf(next) == attrChildren.size() - 1) {
getButton().setEnabled(false);
return;
}
} else if (next instanceof NameSpaceNode) {
if (nameSpaceChildren.contains(next) && nameSpaceChildren.indexOf(next) == nameSpaceChildren.size() - 1) {
getButton().setEnabled(false);
return;
}
} else if (next instanceof Element) {
if (elementChildren.contains(next) && elementChildren.indexOf(next) == elementChildren.size() - 1) {
getButton().setEnabled(false);
return;
}
}
}
}
}
use of org.eclipse.jface.viewers.TreePath in project tdi-studio-se by Talend.
the class MoveUpTreeNodeButton method updateStatus.
/*
* (non-Javadoc)
*
* @see org.talend.designer.fileoutputxml.ui.footer.AbstractTreeNodeButton#updateButtonStatus()
*/
@Override
protected void updateStatus(TreeSelection selection) {
if (selection.isEmpty()) {
getButton().setEnabled(false);
return;
}
final TreePath[] paths = selection.getPaths();
boolean sameSegment = true;
for (int i = 0; i < paths.length - 1; i++) {
if (paths[i].getSegmentCount() != paths[i + 1].getSegmentCount()) {
sameSegment = false;
}
}
if (sameSegment) {
getButton().setEnabled(true);
} else {
getButton().setEnabled(false);
return;
}
// if same segment ,they have the same parent and parent must be an element
final Element parent = (Element) ((FOXTreeNode) selection.getFirstElement()).getParent();
if (parent == null) {
getButton().setEnabled(false);
return;
}
final List<? extends FOXTreeNode> attrChildren = parent.getAttributeChildren();
final List<? extends FOXTreeNode> nameSpaceChildren = parent.getNameSpaceChildren();
final List<FOXTreeNode> elementChildren = parent.getElementChildren();
final Iterator iterator = selection.iterator();
while (iterator.hasNext()) {
final Object next = iterator.next();
if (next instanceof Attribute) {
if (attrChildren.contains(next) && attrChildren.indexOf(next) == 0) {
getButton().setEnabled(false);
return;
}
} else if (next instanceof NameSpaceNode) {
if (nameSpaceChildren.contains(next) && nameSpaceChildren.indexOf(next) == 0) {
getButton().setEnabled(false);
return;
}
} else if (next instanceof Element) {
if (elementChildren.contains(next) && elementChildren.indexOf(next) == 0) {
getButton().setEnabled(false);
return;
}
}
}
}
use of org.eclipse.jface.viewers.TreePath in project tdi-studio-se by Talend.
the class MoveDownTreeNodeButton method updateStatus.
/*
* (non-Javadoc)
*
* @see org.talend.designer.fileoutputJSON.ui.footer.AbstractTreeNodeButton#updateButtonStatus()
*/
@Override
protected void updateStatus(TreeSelection selection) {
if (selection.isEmpty()) {
getButton().setEnabled(false);
return;
}
final TreePath[] paths = selection.getPaths();
boolean sameSegment = true;
for (int i = 0; i < paths.length - 1; i++) {
if (paths[i].getSegmentCount() != paths[i + 1].getSegmentCount()) {
sameSegment = false;
}
}
if (sameSegment) {
getButton().setEnabled(true);
} else {
getButton().setEnabled(false);
return;
}
// if same segment ,they have the same parent and parent must be an element
FOXTreeNode foxNode = (FOXTreeNode) selection.getFirstElement();
if (foxNode.getParent() instanceof Element) {
final Element parent = (Element) foxNode.getParent();
final List<? extends FOXTreeNode> attrChildren = parent.getAttributeChildren();
final List<? extends FOXTreeNode> nameSpaceChildren = parent.getNameSpaceChildren();
final List<FOXTreeNode> elementChildren = parent.getElementChildren();
final Iterator iterator = selection.iterator();
while (iterator.hasNext()) {
final Object next = iterator.next();
if (next instanceof Attribute) {
if (attrChildren.contains(next) && attrChildren.indexOf(next) == attrChildren.size() - 1) {
getButton().setEnabled(false);
return;
}
} else if (next instanceof NameSpaceNode) {
if (nameSpaceChildren.contains(next) && nameSpaceChildren.indexOf(next) == nameSpaceChildren.size() - 1) {
getButton().setEnabled(false);
return;
}
} else if (next instanceof Element) {
if (elementChildren.contains(next) && elementChildren.indexOf(next) == elementChildren.size() - 1) {
getButton().setEnabled(false);
return;
}
}
}
}
if (parent == null) {
getButton().setEnabled(false);
return;
}
}
use of org.eclipse.jface.viewers.TreePath in project translationstudio8 by heartsome.
the class GridTreeViewer method remove.
/**
* Removes the element at the specified index of the parent. The selection is updated if required.
*
* @param parentOrTreePath the parent element, the input element, or a tree path to the parent element
* @param index child index
* @since 3.3
*/
public void remove(final Object parentOrTreePath, final int index) {
if (checkBusy())
return;
final List oldSelection = new LinkedList(Arrays.asList(((TreeSelection) getSelection()).getPaths()));
preservingSelection(new Runnable() {
public void run() {
TreePath removedPath = null;
if (internalIsInputOrEmptyPath(parentOrTreePath)) {
Tree tree = (Tree) getControl();
if (index < tree.getItemCount()) {
TreeItem item = tree.getItem(index);
if (item.getData() != null) {
removedPath = getTreePathFromItem(item);
disassociate(item);
}
item.dispose();
}
} else {
Widget[] parentItems = internalFindItems(parentOrTreePath);
for (int i = 0; i < parentItems.length; i++) {
TreeItem parentItem = (TreeItem) parentItems[i];
if (parentItem.isDisposed())
continue;
if (index < parentItem.getItemCount()) {
TreeItem item = parentItem.getItem(index);
if (item.getData() != null) {
removedPath = getTreePathFromItem(item);
disassociate(item);
}
item.dispose();
}
}
}
if (removedPath != null) {
boolean removed = false;
for (Iterator it = oldSelection.iterator(); it.hasNext(); ) {
TreePath path = (TreePath) it.next();
if (path.startsWith(removedPath, getComparer())) {
it.remove();
removed = true;
}
}
if (removed) {
setSelection(new TreeSelection((TreePath[]) oldSelection.toArray(new TreePath[oldSelection.size()]), getComparer()), false);
}
}
}
});
}
use of org.eclipse.jface.viewers.TreePath in project linuxtools by eclipse.
the class ExpandCollapseTest method testExpand.
@Test
public void testExpand() throws Exception {
ILaunchConfiguration config = createConfiguration(proj.getProject());
// $NON-NLS-1$
doLaunch(config, "testDefaults");
MassifViewPart view = (MassifViewPart) ValgrindUIPlugin.getDefault().getView().getDynamicView();
viewer = view.getTreeViewer().getViewer();
contextMenu = viewer.getTree().getMenu();
// Select first snapshot and expand it
MassifHeapTreeNode[] snapshots = (MassifHeapTreeNode[]) viewer.getInput();
MassifHeapTreeNode snapshot = snapshots[0];
TreeSelection selection = new TreeSelection(new TreePath(new Object[] { snapshot }));
viewer.setSelection(selection);
contextMenu.notifyListeners(SWT.Show, null);
contextMenu.getItem(0).notifyListeners(SWT.Selection, null);
checkExpanded(snapshot, true);
}
Aggregations