Java Code Examples for org.eclipse.swt.widgets.Tree#setSelection()

The following examples show how to use org.eclipse.swt.widgets.Tree#setSelection() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AbstractInformationControl.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Selects the first element in the tree which
 * matches the current filter pattern.
 */
protected void selectFirstMatch() {
	Object selectedElement= fTreeViewer.testFindItem(fInitiallySelectedType);
	TreeItem element;
	final Tree tree= fTreeViewer.getTree();
	if (selectedElement instanceof TreeItem)
		element= findElement(new TreeItem[] { (TreeItem)selectedElement });
	else
		element= findElement(tree.getItems());

	if (element != null) {
		tree.setSelection(element);
		tree.showItem(element);
	} else
		fTreeViewer.setSelection(StructuredSelection.EMPTY);
}
 
Example 2
Source File: ColumnChooserDialog.java    From translationstudio8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * If all the leaves in a group are selected the group is also selected
 */
private void setGroupsSelectionIfRequired(Tree tree, List<Integer> columnEntryIndexes){
	Collection<TreeItem> allLeaves = ArrayUtil.asCollection(tree.getItems());
	Collection<TreeItem> selectedLeaves = ArrayUtil.asCollection(tree.getSelection());

	for (TreeItem leaf : allLeaves) {
		if(isColumnGroupLeaf(leaf)){
			boolean markSelected = true;
			Collection<TreeItem> nestedLeaves = ArrayUtil.asCollection(leaf.getItems());

			for (TreeItem nestedLeaf : nestedLeaves) {
				ColumnEntry columnEntry = getColumnEntryInLeaf(nestedLeaf);
				if(!columnEntryIndexes.contains(columnEntry.getIndex())){
					markSelected = false;
				}
			}
			if(markSelected){
				selectedLeaves.add(leaf);
			}
		}
	}
	tree.setSelection(selectedLeaves.toArray(new TreeItem[] {}));
}
 
Example 3
Source File: GodClass.java    From JDeodorant with MIT License 6 votes vote down vote up
private void setSelectedLineWithinCandidateGroup(Tree tree, TreeItem candidateGroupTreeItem, CandidateRefactoring candidateRefactoring) {
	for(int i=0; i<candidateGroupTreeItem.getItemCount(); i++){
		TreeItem conceptTreeItem = candidateGroupTreeItem.getItem(i);
		ExtractedConcept concept = (ExtractedConcept)conceptTreeItem.getData();
		if(concept.getConceptClusters().contains(candidateRefactoring)) {
			conceptTreeItem.setExpanded(true);
			treeViewer.refresh();
			for(int j=0; j<conceptTreeItem.getItemCount(); j++) {
				TreeItem candidateTreeItem = conceptTreeItem.getItem(j);
				CandidateRefactoring candidate = (CandidateRefactoring)candidateTreeItem.getData();
				if(candidate.equals(candidateRefactoring)) {
					tree.setSelection(candidateTreeItem);
					treeViewer.refresh();
					break;
				}
			}
			break;
		}
	}
}
 
Example 4
Source File: ColumnChooserDialog.java    From tmxeditor8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * If all the leaves in a group are selected the group is also selected
 */
private void setGroupsSelectionIfRequired(Tree tree, List<Integer> columnEntryIndexes){
	Collection<TreeItem> allLeaves = ArrayUtil.asCollection(tree.getItems());
	Collection<TreeItem> selectedLeaves = ArrayUtil.asCollection(tree.getSelection());

	for (TreeItem leaf : allLeaves) {
		if(isColumnGroupLeaf(leaf)){
			boolean markSelected = true;
			Collection<TreeItem> nestedLeaves = ArrayUtil.asCollection(leaf.getItems());

			for (TreeItem nestedLeaf : nestedLeaves) {
				ColumnEntry columnEntry = getColumnEntryInLeaf(nestedLeaf);
				if(!columnEntryIndexes.contains(columnEntry.getIndex())){
					markSelected = false;
				}
			}
			if(markSelected){
				selectedLeaves.add(leaf);
			}
		}
	}
	tree.setSelection(selectedLeaves.toArray(new TreeItem[] {}));
}
 
Example 5
Source File: ERDiagramOutlinePage.java    From erflute with Apache License 2.0 5 votes vote down vote up
public void setFilterText(String filterText) {
    editPartFactory.setFilterText(filterText);
    viewer.setContents(diagram);
    final Tree tree = (Tree) viewer.getControl();
    final TreeItem[] items = tree.getItems();
    expand(items);
    final TreeItem[] tableItems = items[0].getItems();
    if (tableItems.length >= 1) {
        tree.setSelection(tableItems[0]);
    }
}
 
Example 6
Source File: SelectAllAction.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Selects all resources in the view.
 */
@Override
public void run() {
	if (fViewer instanceof TreeViewer) {
		ArrayList<TreeItem> allVisible= new ArrayList<TreeItem>();
		Tree tree= ((TreeViewer) fViewer).getTree();
		collectExpandedAndVisible(tree.getItems(), allVisible);
		tree.setSelection(allVisible.toArray(new TreeItem[allVisible.size()]));
		fViewer.setSelection(fViewer.getSelection());
	} else if (fViewer instanceof TableViewer) {
		((TableViewer) fViewer).getTable().selectAll();
		// force viewer selection change
		fViewer.setSelection(fViewer.getSelection());
	}
}
 
Example 7
Source File: ColumnChooserDialog.java    From translationstudio8 with GNU General Public License v2.0 5 votes vote down vote up
private void selectAllChildren(Tree tree, TreeItem treeItem) {
	Collection<TreeItem> selectedLeaves = ArrayUtil.asCollection(tree.getSelection());
	if(isColumnGroupLeaf(treeItem)){
		selectedLeaves.addAll(ArrayUtil.asCollection(treeItem.getItems()));
	}
	tree.setSelection(selectedLeaves.toArray(new TreeItem[]{}));
	tree.showSelection();
}
 
Example 8
Source File: ColumnChooserDialog.java    From translationstudio8 with GNU General Public License v2.0 5 votes vote down vote up
private void unSelectAllChildren(Tree tree, TreeItem treeItem) {
	Collection<TreeItem> selectedLeaves = ArrayUtil.asCollection(tree.getSelection());
	if(isColumnGroupLeaf(treeItem)){
		selectedLeaves.removeAll(ArrayUtil.asCollection(treeItem.getItems()));
	}
	tree.setSelection(selectedLeaves.toArray(new TreeItem[]{}));
	tree.showSelection();
}
 
Example 9
Source File: ColumnChooserDialog.java    From translationstudio8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Marks the leaves in the tree as selected
 * @param tree containing the leaves
 * @param indexes index of the leaf in the tree
 */
protected void setSelection(Tree tree, List<Integer> indexes) {
	List<TreeItem> selectedLeaves = new ArrayList<TreeItem>();

	for (Integer leafIndex : indexes) {
		selectedLeaves.add(tree.getItem(leafIndex.intValue()));
	}
	tree.setSelection(selectedLeaves.toArray(new TreeItem[] {}));
	tree.showSelection();
}
 
Example 10
Source File: ColumnChooserDialog.java    From tmxeditor8 with GNU General Public License v2.0 5 votes vote down vote up
private void selectAllChildren(Tree tree, TreeItem treeItem) {
	Collection<TreeItem> selectedLeaves = ArrayUtil.asCollection(tree.getSelection());
	if(isColumnGroupLeaf(treeItem)){
		selectedLeaves.addAll(ArrayUtil.asCollection(treeItem.getItems()));
	}
	tree.setSelection(selectedLeaves.toArray(new TreeItem[]{}));
	tree.showSelection();
}
 
Example 11
Source File: ColumnChooserDialog.java    From tmxeditor8 with GNU General Public License v2.0 5 votes vote down vote up
private void unSelectAllChildren(Tree tree, TreeItem treeItem) {
	Collection<TreeItem> selectedLeaves = ArrayUtil.asCollection(tree.getSelection());
	if(isColumnGroupLeaf(treeItem)){
		selectedLeaves.removeAll(ArrayUtil.asCollection(treeItem.getItems()));
	}
	tree.setSelection(selectedLeaves.toArray(new TreeItem[]{}));
	tree.showSelection();
}
 
Example 12
Source File: ColumnChooserDialog.java    From tmxeditor8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Marks the leaves in the tree as selected
 * @param tree containing the leaves
 * @param indexes index of the leaf in the tree
 */
protected void setSelection(Tree tree, List<Integer> indexes) {
	List<TreeItem> selectedLeaves = new ArrayList<TreeItem>();

	for (Integer leafIndex : indexes) {
		selectedLeaves.add(tree.getItem(leafIndex.intValue()));
	}
	tree.setSelection(selectedLeaves.toArray(new TreeItem[] {}));
	tree.showSelection();
}
 
Example 13
Source File: TreeSelectionDialog.java    From Pydev with Eclipse Public License 1.0 5 votes vote down vote up
protected void updateSelectionIfNothingSelected(Tree tree) {
    TreeItem[] sel = tree.getSelection();
    if (sel == null || sel.length == 0) {
        TreeItem[] items = tree.getItems();
        if (items != null && items.length > 0) {
            tree.setSelection(items[0]);
        }
    }
}
 
Example 14
Source File: ERDiagramOutlinePage.java    From ermaster-b with Apache License 2.0 5 votes vote down vote up
public void setFilterText(String filterText) {
		editPartFactory.setFilterText(filterText);
		viewer.setContents(diagram);
		Tree tree = (Tree)viewer.getControl();
		TreeItem[] items = tree.getItems();
		expand(items);
		TreeItem[] tableItems = items[0].getItems();
		if (tableItems.length >= 1) {
			tree.setSelection(tableItems[0]);
		}
//		viewer.getContents().getChildren();



//		viewer.flush();
//		viewer.getEditPartFactory()
//		if (filterText == null) {
//			filterText = "";
//		}
//		this.filterText = filterText;
//		getTreeViewer().refresh();
//		getTreeViewer().expandAll();
//		JavaScriptElement element = getFirstElement(model, filterText);
//		if(element != null){
//			getViewer().setSelection(new StructuredSelection(element), true);
//		}
	}
 
Example 15
Source File: CTreeCombo.java    From nebula with Eclipse Public License 2.0 4 votes vote down vote up
void createPopup(Collection<CTreeComboItem> items, CTreeComboItem selectedItem) {
	// create shell and list
	popup = new Shell(getShell(), SWT.NO_TRIM | SWT.ON_TOP);
	final int style = getStyle();
	int listStyle = SWT.H_SCROLL | SWT.V_SCROLL | SWT.SINGLE;
	if ((style & SWT.FLAT) != 0) {
		listStyle |= SWT.FLAT;
	}
	if ((style & SWT.RIGHT_TO_LEFT) != 0) {
		listStyle |= SWT.RIGHT_TO_LEFT;
	}
	if ((style & SWT.LEFT_TO_RIGHT) != 0) {
		listStyle |= SWT.LEFT_TO_RIGHT;
	}
	tree = new Tree(popup, listStyle);
	tree.addTreeListener(hookListener);
	if (font != null) {
		tree.setFont(font);
	}
	if (foreground != null) {
		tree.setForeground(foreground);
	}
	if (background != null) {
		tree.setBackground(background);
	}

	final int[] popupEvents = { SWT.Close, SWT.Paint, SWT.Deactivate };
	for (int i = 0; i < popupEvents.length; i++) {
		popup.addListener(popupEvents[i], listener);
	}
	final int[] listEvents = { SWT.MouseUp, SWT.Selection, SWT.Traverse, SWT.KeyDown, SWT.KeyUp, SWT.FocusIn, SWT.Dispose, SWT.Collapse, SWT.Expand };
	for (int i = 0; i < listEvents.length; i++) {
		tree.addListener(listEvents[i], listener);
	}

	for (final CTreeComboColumn c : columns) {
		final TreeColumn col = new TreeColumn(tree, SWT.NONE);
		c.setRealTreeColumn(col);
	}

	if (items != null) {
		createTreeItems(items.toArray(new CTreeComboItem[0]));
	}

	if (selectedItem != null) {
		tree.setSelection(selectedItem.getRealTreeItem());
	}
}
 
Example 16
Source File: AbstractSection.java    From uima-uimaj with Apache License 2.0 4 votes vote down vote up
public static void maybeSetSelection(Tree tt, int itemIndex) {
  TreeItem[] items = tt.getItems();
  if (itemIndex >= 0 && itemIndex < items.length) {
    tt.setSelection(items[itemIndex]);
  }
}