Java Code Examples for org.eclipse.jface.viewers.ViewerComparator#sort()

The following examples show how to use org.eclipse.jface.viewers.ViewerComparator#sort() . 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: ProjectSettingDialog.java    From translationstudio8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Selects the saved item in the tree of preference pages. If it cannot do this it saves the first one.
 */
protected void selectSavedItem() {
	IPreferenceNode node = findNodeMatching(getSelectedNodePreference());
	if (node == null) {
		IPreferenceNode[] nodes = preferenceManager.getRootSubNodes();
		ViewerComparator comparator = getTreeViewer().getComparator();
		if (comparator != null)	{
			comparator.sort(null, nodes);
		}			
		for (int i = 0; i < nodes.length; i++) {
			IPreferenceNode selectedNode = nodes[i];
			if (selectedNode != null) {
				node = selectedNode;
				break;
			}
		}
	}
	if (node != null) {
		getTreeViewer().setSelection(new StructuredSelection(node), true);
		// Keep focus in tree. See bugs 2692, 2621, and 6775.
		getTreeViewer().getControl().setFocus();
		boolean expanded = getTreeViewer().getExpandedState(node);
		getTreeViewer().setExpandedState(node, !expanded);
	}
}
 
Example 2
Source File: ProjectSettingDialog.java    From tmxeditor8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Selects the saved item in the tree of preference pages. If it cannot do this it saves the first one.
 */
protected void selectSavedItem() {
	IPreferenceNode node = findNodeMatching(getSelectedNodePreference());
	if (node == null) {
		IPreferenceNode[] nodes = preferenceManager.getRootSubNodes();
		ViewerComparator comparator = getTreeViewer().getComparator();
		if (comparator != null)	{
			comparator.sort(null, nodes);
		}			
		for (int i = 0; i < nodes.length; i++) {
			IPreferenceNode selectedNode = nodes[i];
			if (selectedNode != null) {
				node = selectedNode;
				break;
			}
		}
	}
	if (node != null) {
		getTreeViewer().setSelection(new StructuredSelection(node), true);
		// Keep focus in tree. See bugs 2692, 2621, and 6775.
		getTreeViewer().getControl().setFocus();
		boolean expanded = getTreeViewer().getExpandedState(node);
		getTreeViewer().setExpandedState(node, !expanded);
	}
}