/******************************************************************************* * Copyright (c) 2000, 2004 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Common Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/cpl-v10.html * * Contributors: * IBM Corporation - initial API and implementation *******************************************************************************/ package net.sourceforge.phpeclipse.wiki.editor; import net.sourceforge.phpeclipse.wiki.editor.model.WikipediaOutlineParser; import net.sourceforge.phpeclipse.wiki.editor.model.WikipediaSection; 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; import org.eclipse.swt.widgets.Shell; public class WikiReconcilingStrategy implements IReconcilingStrategy, IReconcilingStrategyExtension { private WikiEditor fEditor; private IDocument fDocument; private IProgressMonitor fProgressMonitor; private WikipediaOutlineParser fParser; private WikiFoldingStructureProvider fFoldingStructureProvider; public WikiReconcilingStrategy(WikiEditor editor) { fEditor= editor; fParser= new WikipediaOutlineParser(); fFoldingStructureProvider= new WikiFoldingStructureProvider(editor); } public void setDocument(IDocument document) { fDocument= document; fFoldingStructureProvider.setDocument(fDocument); } public void setProgressMonitor(IProgressMonitor monitor) { fProgressMonitor= monitor; fFoldingStructureProvider.setProgressMonitor(fProgressMonitor); } public void reconcile(DirtyRegion dirtyRegion, IRegion subRegion) { reconcile(); } public void reconcile(IRegion partition) { reconcile(); } public void initialReconcile() { reconcile(); } private void reconcile() { final WikipediaSection section= fParser.parse(fDocument); if (section == null) return; Shell shell= fEditor.getSite().getShell(); if (shell == null || shell.isDisposed()) return; shell.getDisplay().asyncExec(new Runnable() { public void run() { fEditor.setSection(section); } }); fFoldingStructureProvider.updateFoldingRegions(section); } }