Search in sources :

Example 1 with TreePath

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;
                }
            }
        }
    }
}
Also used : FOXTreeNode(org.talend.metadata.managment.ui.wizard.metadata.xml.node.FOXTreeNode) TreePath(org.eclipse.jface.viewers.TreePath) NameSpaceNode(org.talend.metadata.managment.ui.wizard.metadata.xml.node.NameSpaceNode) Attribute(org.talend.metadata.managment.ui.wizard.metadata.xml.node.Attribute) Element(org.talend.metadata.managment.ui.wizard.metadata.xml.node.Element) Iterator(java.util.Iterator)

Example 2 with TreePath

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;
            }
        }
    }
}
Also used : FOXTreeNode(org.talend.metadata.managment.ui.wizard.metadata.xml.node.FOXTreeNode) TreePath(org.eclipse.jface.viewers.TreePath) NameSpaceNode(org.talend.metadata.managment.ui.wizard.metadata.xml.node.NameSpaceNode) Attribute(org.talend.metadata.managment.ui.wizard.metadata.xml.node.Attribute) Element(org.talend.metadata.managment.ui.wizard.metadata.xml.node.Element) Iterator(java.util.Iterator)

Example 3 with TreePath

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;
    }
}
Also used : FOXTreeNode(org.talend.metadata.managment.ui.wizard.metadata.xml.node.FOXTreeNode) TreePath(org.eclipse.jface.viewers.TreePath) NameSpaceNode(org.talend.metadata.managment.ui.wizard.metadata.xml.node.NameSpaceNode) Attribute(org.talend.metadata.managment.ui.wizard.metadata.xml.node.Attribute) Element(org.talend.metadata.managment.ui.wizard.metadata.xml.node.Element) Iterator(java.util.Iterator)

Example 4 with TreePath

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);
                }
            }
        }
    });
}
Also used : TreePath(org.eclipse.jface.viewers.TreePath) TreeItem(org.eclipse.swt.widgets.TreeItem) TreeSelection(org.eclipse.jface.viewers.TreeSelection) Iterator(java.util.Iterator) Tree(org.eclipse.swt.widgets.Tree) List(java.util.List) LinkedList(java.util.LinkedList) LinkedList(java.util.LinkedList)

Example 5 with TreePath

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);
}
Also used : ILaunchConfiguration(org.eclipse.debug.core.ILaunchConfiguration) MassifHeapTreeNode(org.eclipse.linuxtools.internal.valgrind.massif.MassifHeapTreeNode) TreePath(org.eclipse.jface.viewers.TreePath) TreeSelection(org.eclipse.jface.viewers.TreeSelection) MassifViewPart(org.eclipse.linuxtools.internal.valgrind.massif.MassifViewPart) Test(org.junit.Test)

Aggregations

TreePath (org.eclipse.jface.viewers.TreePath)104 TreeSelection (org.eclipse.jface.viewers.TreeSelection)55 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)22 ArrayList (java.util.ArrayList)20 ITreeSelection (org.eclipse.jface.viewers.ITreeSelection)18 XSDComponent (org.eclipse.xsd.XSDComponent)14 Test (org.junit.Test)14 Iterator (java.util.Iterator)13 XSDAnnotation (org.eclipse.xsd.XSDAnnotation)13 Element (org.w3c.dom.Element)13 XSDAnnotationsStructure (com.amalto.workbench.utils.XSDAnnotationsStructure)12 HashSet (java.util.HashSet)10 Set (java.util.Set)10 ConsoleConfiguration (org.hibernate.console.ConsoleConfiguration)10 List (java.util.List)7 TreeViewer (org.eclipse.jface.viewers.TreeViewer)7 EntityDefinition (eu.esdihumboldt.hale.common.align.model.EntityDefinition)6 ILaunchConfiguration (org.eclipse.debug.core.ILaunchConfiguration)6 IProject (org.eclipse.core.resources.IProject)5 DoubleClickEvent (org.eclipse.jface.viewers.DoubleClickEvent)5