### Eclipse Workspace Patch 1.0
#P org.eclipse.cdt.rpm.editor_installed
Index: src/org/eclipse/cdt/rpm/editor/SpecfileConfiguration.java
===================================================================
RCS file: /cvs/eclipse/rpm/org.eclipse.cdt.rpm.editor/src/org/eclipse/cdt/rpm/editor/SpecfileConfiguration.java,v
retrieving revision 1.6
diff -u -r1.6 SpecfileConfiguration.java
--- src/org/eclipse/cdt/rpm/editor/SpecfileConfiguration.java	19 Dec 2006 15:31:33 -0000	1.6
+++ src/org/eclipse/cdt/rpm/editor/SpecfileConfiguration.java	20 Feb 2007 20:25:20 -0000
@@ -1,11 +1,14 @@
 package org.eclipse.cdt.rpm.editor;
 
+import org.eclipse.core.runtime.NullProgressMonitor;
 import org.eclipse.jface.text.IDocument;
 import org.eclipse.jface.text.ITextDoubleClickStrategy;
 import org.eclipse.jface.text.ITextHover;
 import org.eclipse.jface.text.TextAttribute;
 import org.eclipse.jface.text.presentation.IPresentationReconciler;
 import org.eclipse.jface.text.presentation.PresentationReconciler;
+import org.eclipse.jface.text.reconciler.IReconciler;
+import org.eclipse.jface.text.reconciler.MonoReconciler;
 import org.eclipse.jface.text.rules.DefaultDamagerRepairer;
 import org.eclipse.jface.text.rules.Token;
 import org.eclipse.jface.text.source.ISourceViewer;
@@ -89,4 +92,14 @@
 		return reconciler;
 	}
 
+	/*
+	 * @see SourceViewerConfiguration#getReconciler(ISourceViewer)
+	 */
+	public IReconciler getReconciler(ISourceViewer sourceViewer) {
+		SpecfileReconcilingStrategy strategy= new SpecfileReconcilingStrategy(editor);
+		MonoReconciler reconciler= new MonoReconciler(strategy, false);
+		reconciler.setProgressMonitor(new NullProgressMonitor());
+		reconciler.setDelay(500);
+		return reconciler;
+	}
 }
\ No newline at end of file
Index: src/org/eclipse/cdt/rpm/editor/SpecfileEditor.java
===================================================================
RCS file: /cvs/eclipse/rpm/org.eclipse.cdt.rpm.editor/src/org/eclipse/cdt/rpm/editor/SpecfileEditor.java,v
retrieving revision 1.6
diff -u -r1.6 SpecfileEditor.java
--- src/org/eclipse/cdt/rpm/editor/SpecfileEditor.java	4 Dec 2006 15:01:40 -0000	1.6
+++ src/org/eclipse/cdt/rpm/editor/SpecfileEditor.java	20 Feb 2007 20:25:20 -0000
@@ -6,6 +6,11 @@
 import org.eclipse.core.resources.IFile;
 import org.eclipse.core.runtime.CoreException;
 import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.text.source.ISourceViewer;
+import org.eclipse.jface.text.source.IVerticalRuler;
+import org.eclipse.jface.text.source.projection.ProjectionSupport;
+import org.eclipse.jface.text.source.projection.ProjectionViewer;
+import org.eclipse.swt.widgets.Composite;
 import org.eclipse.ui.IEditorInput;
 import org.eclipse.ui.IFileEditorInput;
 import org.eclipse.ui.editors.text.TextEditor;
@@ -17,6 +22,7 @@
 	private SpecfileContentOutlinePage outlinePage;
 	private IEditorInput input;
 	private Specfile specfile;
+	private ProjectionSupport projectionSupport;
 
 	public SpecfileEditor() {
 		super();
@@ -91,10 +97,41 @@
 			}
 			return outlinePage;
 		}
+		if (projectionSupport != null) {
+			Object adapter= projectionSupport.getAdapter(getSourceViewer(), required);
+			if (adapter != null)
+				return adapter;
+		}
 		return super.getAdapter(required);
 	}
+	
 	public Specfile getSpecfile() {
 		return specfile;
 	}
 
+	
+	/*
+	 * @see org.eclipse.ui.texteditor.AbstractDecoratedTextEditor#createSourceViewer(org.eclipse.swt.widgets.Composite, org.eclipse.jface.text.source.IVerticalRuler, int)
+	 */
+	protected ISourceViewer createSourceViewer(Composite parent, IVerticalRuler ruler, int styles) {
+		fAnnotationAccess = createAnnotationAccess();
+		fOverviewRuler = createOverviewRuler(getSharedColors());
+		ISourceViewer viewer= new ProjectionViewer(parent, ruler, fOverviewRuler, true, styles);
+		getSourceViewerDecorationSupport(viewer);
+		return viewer;
+	}
+
+	/*
+	 * @see org.eclipse.ui.texteditor.AbstractDecoratedTextEditor#createPartControl(org.eclipse.swt.widgets.Composite)
+	 */
+	public void createPartControl(Composite parent) {
+		super.createPartControl(parent);
+		ProjectionViewer projectionViewer = (ProjectionViewer) getSourceViewer();
+		projectionSupport = new ProjectionSupport(projectionViewer, getAnnotationAccess(), getSharedColors());
+		projectionSupport.install();
+		projectionViewer.doOperation(ProjectionViewer.TOGGLE);
+	}
+	
+	
+
 }
Index: src/org/eclipse/cdt/rpm/editor/SpecfileFoldingStructureProvider.java
===================================================================
RCS file: src/org/eclipse/cdt/rpm/editor/SpecfileFoldingStructureProvider.java
diff -N src/org/eclipse/cdt/rpm/editor/SpecfileFoldingStructureProvider.java
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ src/org/eclipse/cdt/rpm/editor/SpecfileFoldingStructureProvider.java	1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,115 @@
+package org.eclipse.cdt.rpm.editor;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import org.eclipse.cdt.rpm.editor.parser.Specfile;
+import org.eclipse.cdt.rpm.editor.parser.SpecfileElement;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.jface.text.BadLocationException;
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.text.Position;
+import org.eclipse.jface.text.source.Annotation;
+import org.eclipse.jface.text.source.projection.ProjectionAnnotation;
+import org.eclipse.jface.text.source.projection.ProjectionAnnotationModel;
+
+public class SpecfileFoldingStructureProvider {
+
+	private static final Annotation[] EMPTY = new Annotation[] {};
+	private SpecfileEditor sEditor;
+	private IDocument sDocument;
+	private IProgressMonitor sProgressMonitor;
+
+	public SpecfileFoldingStructureProvider(SpecfileEditor editor) {
+		sEditor = editor;
+	}
+
+	public void setProgressMonitor(IProgressMonitor progressMonitor) {
+		sProgressMonitor = progressMonitor;
+	}
+
+	public void setDocument(IDocument document) {
+		sDocument = document;
+	}
+
+	public void updateFoldingRegions(Specfile specfile) {
+		try {
+
+			ProjectionAnnotationModel model = (ProjectionAnnotationModel) sEditor
+					.getAdapter(ProjectionAnnotationModel.class);
+			if (model != null)
+				updateFoldingRegions(specfile, model);
+		} catch (BadLocationException e) {
+			e.printStackTrace();
+		}
+	}
+
+	void updateFoldingRegions(Specfile specfile, ProjectionAnnotationModel model)
+			throws BadLocationException {
+		Set/* <Position> */structure = createFoldingStructure(specfile);
+		Annotation[] deletions = computeDifferences(model, structure);
+		Map/* <Annotation,Position> */additions = computeAdditions(structure);
+		if ((deletions.length != 0 || additions.size() != 0)
+				&& (sProgressMonitor == null || !sProgressMonitor.isCanceled()))
+			model.modifyAnnotations(deletions, additions, EMPTY);
+	}
+
+	private Map computeAdditions(Set currentRegions) {
+		Map additionsMap = new HashMap();
+		for (Iterator iter = currentRegions.iterator(); iter.hasNext();)
+			additionsMap.put(new ProjectionAnnotation(), iter.next());
+		return additionsMap;
+	}
+
+	private Annotation[] computeDifferences(ProjectionAnnotationModel model,
+			Set current) {
+		List deletions = new ArrayList();
+		for (Iterator iter = model.getAnnotationIterator(); iter.hasNext();) {
+			Object annotation = iter.next();
+			if (annotation instanceof ProjectionAnnotation) {
+				Position position = model.getPosition((Annotation) annotation);
+				if (current.contains(position))
+					current.remove(position);
+				else
+					deletions.add(annotation);
+			}
+		}
+		return (Annotation[]) deletions
+				.toArray(new Annotation[deletions.size()]);
+	}
+
+	private Set createFoldingStructure(Specfile specfile)
+			throws BadLocationException {
+		Set set = new HashSet();
+		System.out.println("name: " + specfile.getName() + " lenght: " + specfile.getSections().length);
+		addFoldingRegions(set, ((Object[]) specfile.getSections()));
+		return set;
+	}
+
+	private void addFoldingRegions(Set regions, Object[] elements)
+			throws BadLocationException {
+		// add preambule folding section.
+		SpecfileElement element = (SpecfileElement) elements[0];
+		Position position = new Position(0, element.getLineStartPosition() - 1);
+		regions.add(position);
+		// add sections folding.
+		for (int i = 0; i < elements.length; i++) {
+			SpecfileElement startElement = (SpecfileElement) elements[i];
+			int offsetPos = startElement.getLineStartPosition();
+			int lenghtPos;
+			if (i < elements.length -1) {
+				SpecfileElement endElement = (SpecfileElement) elements[i+1];
+				lenghtPos = endElement.getLineStartPosition() - startElement.getLineStartPosition() - 1;
+			} else {
+				lenghtPos = sDocument.getLength() - startElement.getLineStartPosition();
+			}
+			position = new Position(offsetPos, lenghtPos);
+			regions.add(position);
+		}
+	}
+}
Index: src/org/eclipse/cdt/rpm/editor/SpecfileReconcilingStrategy.java
===================================================================
RCS file: src/org/eclipse/cdt/rpm/editor/SpecfileReconcilingStrategy.java
diff -N src/org/eclipse/cdt/rpm/editor/SpecfileReconcilingStrategy.java
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ src/org/eclipse/cdt/rpm/editor/SpecfileReconcilingStrategy.java	1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,65 @@
+package org.eclipse.cdt.rpm.editor;
+
+import org.eclipse.cdt.rpm.editor.parser.Specfile;
+import org.eclipse.cdt.rpm.editor.parser.SpecfileParser;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.text.IRegion;
+import org.eclipse.jface.text.reconciler.DirtyRegion;
+import org.eclipse.jface.text.reconciler.IReconcilingStrategy;
+import org.eclipse.jface.text.reconciler.IReconcilingStrategyExtension;
+
+public class SpecfileReconcilingStrategy implements IReconcilingStrategy, IReconcilingStrategyExtension {
+
+	private IDocument sDocument;
+	private IProgressMonitor sProgressMonitor;
+	private SpecfileParser sParser;
+	private SpecfileFoldingStructureProvider sFoldingStructureProvider;
+
+	public SpecfileReconcilingStrategy(SpecfileEditor editor) {
+		sParser= new SpecfileParser();
+		sFoldingStructureProvider= new SpecfileFoldingStructureProvider(editor);
+	}
+
+	public void setDocument(IDocument document) {
+		sDocument= document;
+		sFoldingStructureProvider.setDocument(sDocument);
+	}
+
+	public void setProgressMonitor(IProgressMonitor monitor) {
+		sProgressMonitor= monitor;
+		sFoldingStructureProvider.setProgressMonitor(sProgressMonitor);
+	}
+
+	public void reconcile(DirtyRegion dirtyRegion, IRegion subRegion) {
+		reconcile();
+	}
+
+	public void reconcile(IRegion partition) {
+		reconcile();
+	}
+
+	public void initialReconcile() {
+		reconcile();
+	}
+
+	private void reconcile() {
+		Specfile recipe= parseRecipe();
+		if (recipe != null) {
+			updateEditor(recipe);
+			updateFolding(recipe);
+		}
+	}
+
+	private Specfile parseRecipe() {
+		return sParser.parse(sDocument);
+	}
+
+	private void updateEditor(final Specfile specfile) {
+		return;
+	}
+
+	private void updateFolding(Specfile specfile) {
+		sFoldingStructureProvider.updateFoldingRegions(specfile);
+	}
+}
