List of usage examples for org.eclipse.jface.viewers TreeSelection TreeSelection
public TreeSelection(TreePath treePath, IElementComparer comparer)
From source file:com.atlassian.connector.eclipse.internal.crucible.ui.wizards.SelectChangesetsFromCruciblePage.java
License:Open Source License
@SuppressWarnings("unchecked") private TreeSelection validateTreeSelection(TreeViewer treeViewer) { TreeSelection selection = getTreeSelection(treeViewer); if (selection != null) { ArrayList<TreePath> validSelections = new ArrayList<TreePath>(); Iterator<Object> iterator = (selection).iterator(); while (iterator.hasNext()) { Object element = iterator.next(); if (element instanceof Change) { validSelections.add((selection).getPathsFor(element)[0]); } else if (element instanceof Repository) { validSelections.add((selection).getPathsFor(element)[0]); }/*from w w w .j a va 2 s . c o m*/ } //set new selection TreeSelection newSelection = new TreeSelection( validSelections.toArray(new TreePath[validSelections.size()]), (selection).getElementComparer()); treeViewer.setSelection(newSelection); } else { treeViewer.setSelection(new TreeSelection()); } return getTreeSelection(treeViewer); }
From source file:com.atlassian.connector.eclipse.internal.crucible.ui.wizards.SelectScmChangesetsPage.java
License:Open Source License
@SuppressWarnings("unchecked") private TreeSelection validateTreeSelection(TreeViewer treeViewer, boolean allowChangesetsSelection) { TreeSelection selection = getTreeSelection(treeViewer); if (selection != null) { ArrayList<TreePath> validSelections = new ArrayList<TreePath>(); Iterator<Object> iterator = (selection).iterator(); while (iterator.hasNext()) { Object element = iterator.next(); if (element instanceof ICustomChangesetLogEntry) { validSelections.add((selection).getPathsFor(element)[0]); } else if (allowChangesetsSelection && element instanceof ScmRepository) { validSelections.add((selection).getPathsFor(element)[0]); }/* w ww .j a va 2s .c o m*/ } //set new selection TreeSelection newSelection = new TreeSelection( validSelections.toArray(new TreePath[validSelections.size()]), (selection).getElementComparer()); treeViewer.setSelection(newSelection); } else { treeViewer.setSelection(new TreeSelection()); } return getTreeSelection(treeViewer); }
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 ww w. j a v a2 s .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;/*from w w w. j ava 2 s . 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() { 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; }/*from w ww. j av a 2 s . c o 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.jdt.ui.tests.packageview.WorkingSetDropAdapterTest.java
License:Open Source License
private ITreeSelection createSelection(Object selectedElement, List treePathes) { if (treePathes == null) { treePathes = new ArrayList(); treePathes.add(new TreePath(new Object[] { selectedElement })); }/*from ww w . ja va2 s .co m*/ return new TreeSelection((TreePath[]) treePathes.toArray(new TreePath[treePathes.size()]), fPackageExplorer.getTreeViewer().getComparer()); }
From source file:org.eclipse.nebula.jface.galleryviewer.GalleryTreeViewer.java
License:Open Source License
/** * Removes the element at the specified index of the parent. The selection * is updated if required.//from ww w.j a v a 2 s . co m * * @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 (isBusy()) // return; final List oldSelection = new LinkedList(Arrays.asList(((TreeSelection) getSelection()).getPaths())); preservingSelection(new Runnable() { public void run() { TreePath removedPath = null; if (internalIsInputOrEmptyPath(parentOrTreePath)) { Gallery gallery = (Gallery) getControl(); if (index < gallery.getItemCount()) { GalleryItem item = gallery.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++) { GalleryItem parentItem = (GalleryItem) parentItems[i]; if (index < parentItem.getItemCount()) { GalleryItem 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); } } } }); }
From source file:org.eclipse.nebula.jface.gridviewer.GridTreeViewer.java
License:Open Source License
/** * 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// w w w . ja va 2 s .co m * @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); } } } }); }
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 . j a v a 2 s . co 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// ww w . j a v a 2 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; }