Example usage for org.eclipse.jface.viewers TreeSelection getElementComparer

List of usage examples for org.eclipse.jface.viewers TreeSelection getElementComparer

Introduction

In this page you can find the example usage for org.eclipse.jface.viewers TreeSelection getElementComparer.

Prototype

public IElementComparer getElementComparer() 

Source Link

Document

Returns the element comparer passed in when the tree selection has been created or null if no comparer has been provided.

Usage

From source file:com.google.dart.tools.internal.corext.refactoring.reorg.RenameSelectionState.java

License:Open Source License

public void restore(Object newElement) {
    if (fDisplay == null) {
        return;//from   www.  j av a  2s  .  co m
    }
    for (int i = 0; i < fParts.size(); i++) {
        IStructuredSelection currentSelection = fSelections.get(i);
        boolean changed = false;
        final ISetSelectionTarget target = (ISetSelectionTarget) fParts.get(i);
        final IStructuredSelection[] newSelection = new IStructuredSelection[1];
        newSelection[0] = currentSelection;
        if (currentSelection instanceof TreeSelection) {
            TreeSelection treeSelection = (TreeSelection) currentSelection;
            TreePath[] paths = treeSelection.getPaths();
            for (int p = 0; p < paths.length; p++) {
                TreePath path = paths[p];
                if (path.getSegmentCount() > 0 && path.getLastSegment().equals(fElement)) {
                    paths[p] = createTreePath(path, newElement);
                    changed = true;
                }
            }
            if (changed) {
                newSelection[0] = new TreeSelection(paths, treeSelection.getElementComparer());
            }
        } else {
            Object[] elements = currentSelection.toArray();
            for (int e = 0; e < elements.length; e++) {
                if (elements[e].equals(fElement)) {
                    elements[e] = newElement;
                    changed = true;
                }
            }
            if (changed) {
                newSelection[0] = new StructuredSelection(elements);
            }
        }
        if (changed) {
            fDisplay.asyncExec(new Runnable() {
                @Override
                public void run() {
                    target.selectReveal(newSelection[0]);
                }
            });
        }
    }
}

From source file:ext.org.eclipse.jdt.internal.ui.refactoring.reorg.RenameSelectionState.java

License:Open Source License

public void restore(Object newElement) {
    if (fDisplay == null)
        return;/*  w  w  w. j  av a2 s .c om*/
    for (int i = 0; i < fParts.size(); i++) {
        IStructuredSelection currentSelection = fSelections.get(i);
        boolean changed = false;
        final ISetSelectionTarget target = (ISetSelectionTarget) fParts.get(i);
        final IStructuredSelection[] newSelection = new IStructuredSelection[1];
        newSelection[0] = currentSelection;
        if (currentSelection instanceof TreeSelection) {
            TreeSelection treeSelection = (TreeSelection) currentSelection;
            TreePath[] paths = treeSelection.getPaths();
            for (int p = 0; p < paths.length; p++) {
                TreePath path = paths[p];
                if (path.getSegmentCount() > 0 && path.getLastSegment().equals(fElement)) {
                    paths[p] = createTreePath(path, newElement);
                    changed = true;
                }
            }
            if (changed) {
                newSelection[0] = new TreeSelection(paths, treeSelection.getElementComparer());
            }
        } else {
            Object[] elements = currentSelection.toArray();
            for (int e = 0; e < elements.length; e++) {
                if (elements[e].equals(fElement)) {
                    elements[e] = newElement;
                    changed = true;
                }
            }
            if (changed) {
                newSelection[0] = new StructuredSelection(elements);
            }
        }
        if (changed) {
            fDisplay.asyncExec(new Runnable() {
                public void run() {
                    target.selectReveal(newSelection[0]);
                }
            });
        }
    }
}

From source file:org.eclipse.debug.internal.ui.viewers.model.InternalVirtualTreeModelViewer.java

License:Open Source License

private TreeSelection adjustSelectionForReplace(VirtualItem[] selectedItems, TreeSelection selection,
        VirtualItem item, Object element, Object parentElement) {
    if (item.getData() != null || selectedItems.length == selection.size() || parentElement == null) {
        // Don't do anything - we are not seeing an instance of bug 185673
        return selection;
    }/*  w  w  w.  j ava 2  s  . co m*/
    for (int i = 0; i < selectedItems.length; i++) {
        if (item == selectedItems[i]) {
            // The current item was selected, but its data is null.
            // The data will be replaced by the given element, so to keep
            // it selected, we have to add it to the selection.
            TreePath[] originalPaths = selection.getPaths();
            int length = originalPaths.length;
            TreePath[] paths = new TreePath[length + 1];
            System.arraycopy(originalPaths, 0, paths, 0, length);
            // set the element temporarily so that we can call getTreePathFromItem
            item.setData(element);
            paths[length] = getTreePathFromItem(item);
            item.setData(null);
            return new TreeSelection(paths, selection.getElementComparer());
        }
    }
    // The item was not selected, return the given selection
    return selection;
}

From source file:org.eclipse.wst.jsdt.internal.ui.refactoring.reorg.RenameSelectionState.java

License:Open Source License

public void restore(Object newElement) {
    if (fDisplay == null)
        return;//from w w w.ja va2s . c  o m
    for (int i = 0; i < fParts.size(); i++) {
        IStructuredSelection currentSelection = (IStructuredSelection) fSelections.get(i);
        boolean changed = false;
        final ISetSelectionTarget target = (ISetSelectionTarget) fParts.get(i);
        final IStructuredSelection[] newSelection = new IStructuredSelection[1];
        newSelection[0] = currentSelection;
        if (currentSelection instanceof TreeSelection) {
            TreeSelection treeSelection = (TreeSelection) currentSelection;
            TreePath[] paths = treeSelection.getPaths();
            for (int p = 0; p < paths.length; p++) {
                TreePath path = paths[p];
                if (path.getSegmentCount() > 0 && path.getLastSegment().equals(fElement)) {
                    paths[p] = createTreePath(path, newElement);
                    changed = true;
                }
            }
            if (changed) {
                newSelection[0] = new TreeSelection(paths, treeSelection.getElementComparer());
            }
        } else {
            Object[] elements = currentSelection.toArray();
            for (int e = 0; e < elements.length; e++) {
                if (elements[e].equals(fElement)) {
                    elements[e] = newElement;
                    changed = true;
                }
            }
            if (changed) {
                newSelection[0] = new StructuredSelection(elements);
            }
        }
        if (changed) {
            fDisplay.asyncExec(new Runnable() {
                public void run() {
                    target.selectReveal(newSelection[0]);
                }
            });
        }
    }
}

From source file:org.mingy.jsfs.ui.viewer.CTreeComboViewer.java

License:Open Source License

/**
 * Fix for bug 185673: If the currently replaced item was selected, add it
 * to the selection that is being restored. Only do this if its getData() is
 * currently null/*from  w  w w  . j a  va2  s . c  o m*/
 * 
 * @param selectedItems
 * @param selection
 * @param item
 * @param element
 * @return
 */
private TreeSelection adjustSelectionForReplace(Item[] selectedItems, TreeSelection selection,
        CTreeComboItem item, Object element, Object parentElement) {
    if (item.getData() != null || selectedItems.length == selection.size() || parentElement == null) {
        // Don't do anything - we are not seeing an instance of bug 185673
        return selection;
    }
    for (int i = 0; i < selectedItems.length; i++) {
        if (item == selectedItems[i]) {
            // The current item was selected, but its data is null.
            // The data will be replaced by the given element, so to keep
            // it selected, we have to add it to the selection.
            TreePath[] originalPaths = selection.getPaths();
            int length = originalPaths.length;
            TreePath[] paths = new TreePath[length + 1];
            System.arraycopy(originalPaths, 0, paths, 0, length);
            // set the element temporarily so that we can call
            // getTreePathFromItem
            item.setData(element);
            paths[length] = getTreePathFromItem(item);
            item.setData(null);
            return new TreeSelection(paths, selection.getElementComparer());
        }
    }
    // The item was not selected, return the given selection
    return selection;
}