Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Copyright (c) 2010 itemis AG (http://www.itemis.eu) and others. All rights reserved. This program and the accompanying materials are made available under the terms of the Eclipse Public License v1.0 which accompanies this distribution, and is available at http://www.eclipse.org/legal/epl-v10.html /
  
  package org.eclipse.xtext.ui.editor.outline.impl;
  
 import java.util.Set;
 
 import  org.eclipse.jface.viewers.ISelection;
 import  org.eclipse.jface.viewers.IStructuredSelection;
 import  org.eclipse.jface.viewers.TreeViewer;
 
Either stores the expansion/selection of a tree viewer or aggregates the new expansion/selection state.

Author(s):
Jan Koehnlein - Initial contribution and API
 
 public class OutlineTreeState {
 
 	private static final Logger LOG = Logger.getLogger(OutlineTreeState.class);
 
 
 	public OutlineTreeState(TreeViewer treeViewer) {
 		 = Collections.unmodifiableSet(getExpandedNodes(treeViewer));
 		 = Collections.unmodifiableSet(getSelectedNodes(treeViewer));
 	}
 
 	public OutlineTreeState() {
 	}
 
 	protected Set<IOutlineNodegetExpandedNodes(final TreeViewer treeViewer) {
 		final Set<IOutlineNodeexpandedNodes = Sets.newHashSet();
 		DisplayRunHelper.runSyncInDisplayThread(new Runnable() {
 			public void run() {
 				if (!treeViewer.getTree().isDisposed()) {
 					Object[] expandedElements = treeViewer.getExpandedElements();
 					for (Object expandedElement : expandedElements) {
 						if (!(expandedElement instanceof IOutlineNode))
 							.error("Content outline contains illegal node " + expandedElement);
 						else
 							expandedNodes.add((IOutlineNodeexpandedElement);
 					}
 				}
 			}
 		});
 		return expandedNodes;
 	}
 
 	protected Set<IOutlineNodegetSelectedNodes(final TreeViewer treeViewer) {
 		DisplayRunHelper.runSyncInDisplayThread(new Runnable() {
 			public void run() {
 				ISelection selection = treeViewer.getSelection();
 				if (selection instanceof IStructuredSelection) {
 					for (Iterator<?> selectionIter = ((IStructuredSelection) selection).iterator(); selectionIter
 							.hasNext();) {
 						Object selectedElement = selectionIter.next();
 						if (!(selectedElement instanceof IOutlineNode))
 							.error("Content outline contains illegal node " + selectedElement);
 						else
 							.add((IOutlineNodeselectedElement);
 					}
 				}
 			}
 		});
 		return ;
 	}
 
 		return ;
 	}
 
 		return ;
 	}
 
 	public boolean addExpandedNode(IOutlineNode node) {
 		if (.contains(node))
 			return false;
 		return .add(node);
 	}
 
 	public boolean addSelectedNode(IOutlineNode node) {
			return false;
		return .add(node);
	}
New to GrepCode? Check out our FAQ X