Java Code Examples for org.eclipse.jface.text.source.projection.ProjectionAnnotationModel#modifyAnnotations()

The following examples show how to use org.eclipse.jface.text.source.projection.ProjectionAnnotationModel#modifyAnnotations() . 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: DefaultFoldingStructureProvider.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
protected void updateFoldingRegions(boolean allowCollapse, ProjectionAnnotationModel model,
		Collection<FoldedPosition> foldedPositions, Annotation[] deletions) {
	Map<ProjectionAnnotation, Position> additionsMap = Maps.newHashMap();
	for (FoldedPosition foldedPosition: foldedPositions) {
		addProjectionAnnotation(allowCollapse, foldedPosition, additionsMap);
	}
	if (deletions.length != 0 || additionsMap.size() != 0) {
		model.modifyAnnotations(deletions, additionsMap, new Annotation[] {});
	}
}
 
Example 2
Source File: AbstractFoldingEditor.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
public void updateFoldingStructure(Map<ProjectionAnnotation, Position> annotations)
{
	synchronized (lockUpdateFoldingStructure)
	{
		List<Annotation> deletions = new ArrayList<Annotation>();
		Collection<Position> additions = annotations.values();
		ProjectionAnnotationModel currentModel = getAnnotationModel();
		if (currentModel == null)
		{
			return;
		}
		for (@SuppressWarnings("rawtypes")
		Iterator iter = currentModel.getAnnotationIterator(); iter.hasNext();)
		{
			Object annotation = iter.next();
			if (annotation instanceof ProjectionAnnotation)
			{
				Position position = currentModel.getPosition((Annotation) annotation);
				if (additions.contains(position))
				{
					additions.remove(position);
				}
				else
				{
					deletions.add((Annotation) annotation);
				}
			}
		}
		if (annotations.size() != 0 || deletions.size() != 0)
		{
			currentModel.modifyAnnotations(deletions.toArray(new Annotation[deletions.size()]), annotations, null);
		}
	}
}
 
Example 3
Source File: DefaultJavaFoldingStructureProvider.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Collapses or expands all annotations matched by the passed filter.
 *
 * @param filter the filter to use to select which annotations to collapse
 * @param expand <code>true</code> to expand the matched annotations, <code>false</code> to
 *        collapse them
 */
private void modifyFiltered(Filter filter, boolean expand) {
	if (!isInstalled())
		return;

	ProjectionAnnotationModel model= getModel();
	if (model == null)
		return;

	List<JavaProjectionAnnotation> modified= new ArrayList<JavaProjectionAnnotation>();
	Iterator<Annotation> iter= model.getAnnotationIterator();
	while (iter.hasNext()) {
		Object annotation= iter.next();
		if (annotation instanceof JavaProjectionAnnotation) {
			JavaProjectionAnnotation java= (JavaProjectionAnnotation) annotation;

			if (expand == java.isCollapsed() && filter.match(java)) {
				if (expand)
					java.markExpanded();
				else
					java.markCollapsed();
				modified.add(java);
			}

		}
	}

	model.modifyAnnotations(null, null, modified.toArray(new Annotation[modified.size()]));
}
 
Example 4
Source File: DecoratedScriptEditor.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Collapses all item with the specified style.
 * 
 * @param style
 *            the style to collapse
 */
private void collapseStyle( int style )
{
	ISourceViewer viewer = getViewer( );

	if ( !( viewer instanceof ProjectionViewer ) )
	{
		return;
	}

	ProjectionAnnotationModel model = ( (ProjectionViewer) viewer ).getProjectionAnnotationModel( );

	if ( model == null )
	{
		return;
	}

	List modified = new ArrayList( );
	Iterator iter = model.getAnnotationIterator( );

	while ( iter.hasNext( ) )
	{
		Object annotation = iter.next( );

		if ( annotation instanceof ScriptProjectionAnnotation )
		{
			ScriptProjectionAnnotation scriptAnnotation = (ScriptProjectionAnnotation) annotation;

			if ( !scriptAnnotation.isCollapsed( )
					&& scriptAnnotation.isStyle( style ) )
			{
				scriptAnnotation.markCollapsed( );
				modified.add( scriptAnnotation );
			}
		}
	}
	model.modifyAnnotations( null,
			null,
			(Annotation[]) modified.toArray( new Annotation[modified.size( )] ) );
}