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.List;
 
 import  org.eclipse.core.runtime.IProgressMonitor;
 import  org.eclipse.core.runtime.IStatus;
 import  org.eclipse.core.runtime.OperationCanceledException;
 import  org.eclipse.core.runtime.Status;
 import  org.eclipse.core.runtime.jobs.Job;
 
 
 public class OutlineRefreshJob extends Job {
 	
 	private final static Logger LOG = Logger.getLogger(OutlineRefreshJob.class);
 	
 	
 	
 	public OutlineRefreshJob() {
 		super("Refreshing Outline");
 	}
 
 	public void setOutlinePage(OutlinePage outlinePage) {
 		this. = outlinePage;
 	}
 	
 	protected IStatus run(IProgressMonitor monitor) {
 		if ( == null) {
 			return Status.OK_STATUS;
 		}
 		try {
 			OutlineTreeState newState = new OutlineTreeState();
 			IOutlineNode rootNode = refreshOutlineModel(monitorformerStatenewState);
 			if (!monitor.isCanceled())
 				.refreshViewer(rootNodenewState.getExpandedNodes(), newState.getSelectedNodes());
 			else
 				return Status.CANCEL_STATUS;
 			return Status.OK_STATUS;
 		} catch (OperationCanceledException oce) {
 			return Status.CANCEL_STATUS;
 		} catch (Exception e) {
 			.error("Error refreshing outline"e);
 			return Status.OK_STATUS;
 		}
 	}
 
 	protected IOutlineNode refreshOutlineModel(final IProgressMonitor monitorfinal OutlineTreeState formerState,
 			final OutlineTreeState newState) {
 		final IOutlineTreeProvider treeProvider = .getTreeProvider();
 		if (treeProvider instanceof IOutlineTreeProvider.Background) {
 			return internalRefreshOutlineModel(formerStatenewStatetreeProvider);
 		} else {
 				protected IOutlineNode run() throws Exception {
 					return internalRefreshOutlineModel(formerStatenewStatetreeProvider);
 				}
 			}.syncExec();
 		}
 	}

Since:
2.7
 
 	protected IOutlineNode internalRefreshOutlineModel(final OutlineTreeState formerState,
 			final OutlineTreeState newStatefinal IOutlineTreeProvider treeProvider) {
 			public IOutlineNode exec(XtextResource resourceCancelIndicator cancelIndicatorthrows Exception {
 				IOutlineNode rootNode = createModel(treeProvidercancelIndicator);
 				restoreChildrenSelectionAndExpansion(rootNoderesourceformerStatenewStatecancelIndicator);
 				return rootNode;
 			}
 
 			private IOutlineNode createModel(final IOutlineTreeProvider treeProviderCancelIndicator cancelIndicator) {
 				if (treeProvider instanceof IOutlineTreeProvider.Cancelable)
 					return ((IOutlineTreeProvider.CancelabletreeProvider).createRoot(
							.getXtextDocument(), cancelIndicator);
				else
					return treeProvider.createRoot(.getXtextDocument());
			}
		});
		return rootNode;
	}

Deprecated:
use restoreChildrenSelectionAndExpansion(IOutlineNode, Resource, OutlineTreeState, OutlineTreeState, CancelIndicator) instead
	protected void restoreChildrenSelectionAndExpansion(IOutlineNode parentResource resourceOutlineTreeState formerStateOutlineTreeState newState) {
		restoreChildrenSelectionAndExpansion(parentresourceformerStatenewState.);
	}

Since:
2.7
	protected void restoreChildrenSelectionAndExpansion(IOutlineNode parentResource resourceOutlineTreeState formerStateOutlineTreeState newStateCancelIndicator cancelIndicator) {
		List<IOutlineNodechildren = parent.getChildren();
		for(IOutlineNode childchildren) {
			if(cancelIndicator.isCanceled())
				throw new OperationCanceledException();
			if(containsUsingComparer(formerState.getExpandedNodes(), child)) {
				restoreChildrenSelectionAndExpansion(childresourceformerStatenewStatecancelIndicator);
				newState.addExpandedNode(child);
			}
			if(containsUsingComparer(formerState.getSelectedNodes(), child)) {
				newState.addSelectedNode(child);
			}
		}
	}
	protected boolean containsUsingComparer(Iterable<IOutlineNodelistfinal IOutlineNode node) {
		return Iterables.any(listnew Predicate<IOutlineNode>() {
			public boolean apply(IOutlineNode nodeFromList) {
				return .equals(nodenodeFromList);
			}
		});
	}
New to GrepCode? Check out our FAQ X