View | Details | Raw Unified | Return to bug 247221 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/wst/sse/ui/internal/reconcile/DocumentRegionProcessor.java (-3 / +37 lines)
Lines 14-21 Link Here
14
import java.io.IOException;
14
import java.io.IOException;
15
import java.io.StringReader;
15
import java.io.StringReader;
16
import java.util.ArrayList;
16
import java.util.ArrayList;
17
import java.util.Arrays;
18
import java.util.HashSet;
17
import java.util.List;
19
import java.util.List;
20
import java.util.Set;
18
21
22
import org.eclipse.core.runtime.NullProgressMonitor;
19
import org.eclipse.core.runtime.Platform;
23
import org.eclipse.core.runtime.Platform;
20
import org.eclipse.core.runtime.content.IContentDescription;
24
import org.eclipse.core.runtime.content.IContentDescription;
21
import org.eclipse.core.runtime.content.IContentType;
25
import org.eclipse.core.runtime.content.IContentType;
Lines 26-31 Link Here
26
import org.eclipse.jface.text.Region;
30
import org.eclipse.jface.text.Region;
27
import org.eclipse.jface.text.reconciler.DirtyRegion;
31
import org.eclipse.jface.text.reconciler.DirtyRegion;
28
import org.eclipse.jface.text.reconciler.IReconcilingStrategy;
32
import org.eclipse.jface.text.reconciler.IReconcilingStrategy;
33
import org.eclipse.jface.text.source.IAnnotationModel;
29
import org.eclipse.jface.text.source.ISourceViewer;
34
import org.eclipse.jface.text.source.ISourceViewer;
30
import org.eclipse.wst.sse.ui.internal.ExtendedConfigurationBuilder;
35
import org.eclipse.wst.sse.ui.internal.ExtendedConfigurationBuilder;
31
import org.eclipse.wst.sse.ui.internal.IReleasable;
36
import org.eclipse.wst.sse.ui.internal.IReleasable;
Lines 45-51 Link Here
45
 * validator strategies - DirtyRegion processing logic.
50
 * validator strategies - DirtyRegion processing logic.
46
 */
51
 */
47
public class DocumentRegionProcessor extends DirtyRegionProcessor {
52
public class DocumentRegionProcessor extends DirtyRegionProcessor {
48
49
	private static final boolean DEBUG_VALIDATORS = Boolean.TRUE.toString().equalsIgnoreCase(Platform.getDebugOption("org.eclipse.wst.sse.ui/debug/reconcilerValidators")); //$NON-NLS-1$
53
	private static final boolean DEBUG_VALIDATORS = Boolean.TRUE.toString().equalsIgnoreCase(Platform.getDebugOption("org.eclipse.wst.sse.ui/debug/reconcilerValidators")); //$NON-NLS-1$
50
54
51
	/**
55
	/**
Lines 60-65 Link Here
60
	 */
64
	 */
61
	private ValidatorStrategy fValidatorStrategy;
65
	private ValidatorStrategy fValidatorStrategy;
62
66
67
	private ISourceReconcilingListener[] fReconcileListeners = new ISourceReconcilingListener[0];
68
63
	private IReconcilingStrategy fSemanticHighlightingStrategy;
69
	private IReconcilingStrategy fSemanticHighlightingStrategy;
64
	
70
	
65
	/**
71
	/**
Lines 74-86 Link Here
74
	 * false otherwise
80
	 * false otherwise
75
	 */
81
	 */
76
	private boolean fValidationEnabled;
82
	private boolean fValidationEnabled;
77
	
83
84
	public void addReconcilingListener(ISourceReconcilingListener listener) {
85
		Set listeners = new HashSet(Arrays.asList(fReconcileListeners));
86
		listeners.add(listener);
87
		fReconcileListeners = (ISourceReconcilingListener[]) listeners.toArray(new ISourceReconcilingListener[listeners.size()]);
88
	}
89
78
	protected void beginProcessing() {
90
	protected void beginProcessing() {
79
		super.beginProcessing();
91
		super.beginProcessing();
80
		ValidatorStrategy validatorStrategy = getValidatorStrategy();
92
		ValidatorStrategy validatorStrategy = getValidatorStrategy();
81
		if (validatorStrategy != null) {
93
		if (validatorStrategy != null) {
82
			validatorStrategy.beginProcessing();
94
			validatorStrategy.beginProcessing();
83
		}
95
		}
96
		if ((getTextViewer() instanceof ISourceViewer)) {
97
			for (int i = 0; i < fReconcileListeners.length; i++) {
98
				fReconcileListeners[i].aboutToBeReconciled();
99
			}
100
		}
84
	}
101
	}
85
102
86
	protected void endProcessing() {
103
	protected void endProcessing() {
Lines 100-105 Link Here
100
		if (semanticHighlightingStrategy != null && document != null) {
117
		if (semanticHighlightingStrategy != null && document != null) {
101
			semanticHighlightingStrategy.reconcile(new Region(0, document.getLength()));
118
			semanticHighlightingStrategy.reconcile(new Region(0, document.getLength()));
102
		}
119
		}
120
121
		if ((getTextViewer() instanceof ISourceViewer)) {
122
			ISourceViewer sourceViewer = (ISourceViewer) getTextViewer();
123
			IAnnotationModel annotationModel = sourceViewer.getAnnotationModel();
124
			for (int i = 0; i < fReconcileListeners.length; i++) {
125
				fReconcileListeners[i].reconciled(document, annotationModel, false, new NullProgressMonitor());
126
			}
127
		}
103
	}
128
	}
104
129
105
	protected String getContentType(IDocument doc) {
130
	protected String getContentType(IDocument doc) {
Lines 282-287 Link Here
282
			getFoldingStrategy().reconcile(dirtyRegion, null);
307
			getFoldingStrategy().reconcile(dirtyRegion, null);
283
		}
308
		}
284
	}
309
	}
310
	
311
	public void removeReconcilingListener(ISourceReconcilingListener listener) {
312
		Set listeners = new HashSet(Arrays.asList(fReconcileListeners));
313
		listeners.remove(listener);
314
		fReconcileListeners = (ISourceReconcilingListener[]) listeners.toArray(new ISourceReconcilingListener[listeners.size()]);
315
	}
316
285
317
286
	public void setDocument(IDocument doc) {
318
	public void setDocument(IDocument doc) {
287
		super.setDocument(doc);
319
		super.setDocument(doc);
Lines 332-338 Link Here
332
	 */
364
	 */
333
	public void install(ITextViewer textViewer) {
365
	public void install(ITextViewer textViewer) {
334
		super.install(textViewer);
366
		super.install(textViewer);
335
		
367
336
		//determine if validation is enabled
368
		//determine if validation is enabled
337
		this.fValidationEnabled = SSEUIPlugin.getInstance().getPreferenceStore().getBoolean(
369
		this.fValidationEnabled = SSEUIPlugin.getInstance().getPreferenceStore().getBoolean(
338
				CommonEditorPreferenceNames.EVALUATE_TEMPORARY_PROBLEMS);
370
				CommonEditorPreferenceNames.EVALUATE_TEMPORARY_PROBLEMS);
Lines 357-362 Link Here
357
				fSpellcheckStrategy.setDocument(null);
389
				fSpellcheckStrategy.setDocument(null);
358
				fSpellcheckStrategy = null;
390
				fSpellcheckStrategy = null;
359
			}
391
			}
392
393
			fReconcileListeners = new ISourceReconcilingListener[0];
360
		}
394
		}
361
		super.uninstall();
395
		super.uninstall();
362
	}
396
	}
(-)src/org/eclipse/wst/sse/ui/internal/reconcile/DirtyRegionProcessor.java (+47 lines)
Lines 41-46 Link Here
41
import org.eclipse.jface.text.reconciler.IReconciler;
41
import org.eclipse.jface.text.reconciler.IReconciler;
42
import org.eclipse.jface.text.reconciler.IReconcilerExtension;
42
import org.eclipse.jface.text.reconciler.IReconcilerExtension;
43
import org.eclipse.jface.text.reconciler.IReconcilingStrategy;
43
import org.eclipse.jface.text.reconciler.IReconcilingStrategy;
44
import org.eclipse.ui.IPartListener;
45
import org.eclipse.ui.IWorkbenchPart;
44
import org.eclipse.ui.PlatformUI;
46
import org.eclipse.ui.PlatformUI;
45
import org.eclipse.wst.sse.ui.internal.Logger;
47
import org.eclipse.wst.sse.ui.internal.Logger;
46
import org.eclipse.wst.sse.ui.internal.SSEUIMessages;
48
import org.eclipse.wst.sse.ui.internal.SSEUIMessages;
Lines 213-218 Link Here
213
		}
215
		}
214
	}
216
	}
215
217
218
	private class PartListener implements IPartListener {
219
220
		public void partActivated(IWorkbenchPart part) {
221
			if (part.getAdapter(ITextViewer.class) == fViewer)
222
				forceReconciling();
223
		}
224
225
		public void partBroughtToTop(IWorkbenchPart part) {
226
		}
227
228
		public void partClosed(IWorkbenchPart part) {
229
		}
230
231
		public void partDeactivated(IWorkbenchPart part) {
232
		}
233
234
		public void partOpened(IWorkbenchPart part) {
235
		}
236
		
237
	}
238
216
	/** debug flag */
239
	/** debug flag */
217
	protected static final boolean DEBUG;
240
	protected static final boolean DEBUG;
218
	private static final long UPDATE_DELAY = 500;
241
	private static final long UPDATE_DELAY = 500;
Lines 263-272 Link Here
263
	 * true if entire document needs to be reprocessed after rewrite session
286
	 * true if entire document needs to be reprocessed after rewrite session
264
	 */
287
	 */
265
	boolean fReprocessAfterRewrite = false;
288
	boolean fReprocessAfterRewrite = false;
289
	/** Part listener for focus of the text viewer */
290
	private IPartListener fPartListener;
266
291
267
	/** The job should be reset because of document changes */
292
	/** The job should be reset because of document changes */
268
	private boolean fReset = false;
293
	private boolean fReset = false;
269
	private boolean fIsCanceled = false;
294
	private boolean fIsCanceled = false;
295
	private boolean fHasReconciled = false;
270
	private Object LOCK = new Object();
296
	private Object LOCK = new Object();
271
297
272
	/**
298
	/**
Lines 568-573 Link Here
568
			fViewer = textViewer;
594
			fViewer = textViewer;
569
			fTextInputListener = new TextInputListener();
595
			fTextInputListener = new TextInputListener();
570
			textViewer.addTextInputListener(fTextInputListener);
596
			textViewer.addTextInputListener(fTextInputListener);
597
			fPartListener = new PartListener();
598
			PlatformUI.getWorkbench().getActiveWorkbenchWindow().getPartService().addPartListener(fPartListener);
571
			setInstalled(true);
599
			setInstalled(true);
572
		}
600
		}
573
	}
601
	}
Lines 636-641 Link Here
636
		if (!PlatformUI.isWorkbenchRunning())
664
		if (!PlatformUI.isWorkbenchRunning())
637
			return status;
665
			return status;
638
666
667
		if (!fHasReconciled) {
668
			initialReconcile();
669
			fHasReconciled = true;
670
		}
671
639
		Thread.currentThread().setPriority(Thread.MIN_PRIORITY);
672
		Thread.currentThread().setPriority(Thread.MIN_PRIORITY);
640
		boolean processed = false;
673
		boolean processed = false;
641
		try {
674
		try {
Lines 708-713 Link Here
708
	}
741
	}
709
742
710
	/**
743
	/**
744
	 * This method is called before the initial reconciling of the document. 
745
	 */
746
	protected void initialReconcile() {
747
	}
748
749
	/**
711
	 * Sets the document partitioning for this reconciler.
750
	 * Sets the document partitioning for this reconciler.
712
	 * 
751
	 * 
713
	 * @param partitioning
752
	 * @param partitioning
Lines 717-722 Link Here
717
		fPartitioning = partitioning;
756
		fPartitioning = partitioning;
718
	}
757
	}
719
758
759
	protected void forceReconciling() {
760
		if (!fHasReconciled)
761
			return;
762
763
		setEntireDocumentDirty(getDocument());
764
	}
765
720
	/**
766
	/**
721
	 * Basically means process the entire document.
767
	 * Basically means process the entire document.
722
	 * 
768
	 * 
Lines 781-786 Link Here
781
		if (isInstalled()) {
827
		if (isInstalled()) {
782
			// removes widget listener
828
			// removes widget listener
783
			getTextViewer().removeTextInputListener(fTextInputListener);
829
			getTextViewer().removeTextInputListener(fTextInputListener);
830
			PlatformUI.getWorkbench().getActiveWorkbenchWindow().getPartService().removePartListener(fPartListener);
784
			setInstalled(false);
831
			setInstalled(false);
785
			cancel();
832
			cancel();
786
			fIsCanceled = true;
833
			fIsCanceled = true;
(-)src/org/eclipse/wst/sse/ui/StructuredTextEditor.java (-5 / +44 lines)
Lines 185-190 Link Here
185
import org.eclipse.wst.sse.ui.internal.provisional.extensions.breakpoint.NullSourceEditingTextTools;
185
import org.eclipse.wst.sse.ui.internal.provisional.extensions.breakpoint.NullSourceEditingTextTools;
186
import org.eclipse.wst.sse.ui.internal.provisional.preferences.CommonEditorPreferenceNames;
186
import org.eclipse.wst.sse.ui.internal.provisional.preferences.CommonEditorPreferenceNames;
187
import org.eclipse.wst.sse.ui.internal.reconcile.DocumentRegionProcessor;
187
import org.eclipse.wst.sse.ui.internal.reconcile.DocumentRegionProcessor;
188
import org.eclipse.wst.sse.ui.internal.reconcile.ISourceReconcilingListener;
188
import org.eclipse.wst.sse.ui.internal.selection.SelectionHistory;
189
import org.eclipse.wst.sse.ui.internal.selection.SelectionHistory;
189
import org.eclipse.wst.sse.ui.internal.style.SemanticHighlightingManager;
190
import org.eclipse.wst.sse.ui.internal.style.SemanticHighlightingManager;
190
import org.eclipse.wst.sse.ui.internal.text.DocumentRegionEdgeMatcher;
191
import org.eclipse.wst.sse.ui.internal.text.DocumentRegionEdgeMatcher;
Lines 859-865 Link Here
859
	private OutlinePageListener fOutlinePageListener = null;
860
	private OutlinePageListener fOutlinePageListener = null;
860
	/** This editor's projection support */
861
	/** This editor's projection support */
861
	private ProjectionSupport fProjectionSupport;
862
	private ProjectionSupport fProjectionSupport;
863
	
862
	private IPropertySheetPage fPropertySheetPage;
864
	private IPropertySheetPage fPropertySheetPage;
865
866
	private ISourceReconcilingListener[] fReconcilingListeners = new ISourceReconcilingListener[0]; 
867
863
	private String fRememberTitle;
868
	private String fRememberTitle;
864
	/** The ruler context menu to be disposed. */
869
	/** The ruler context menu to be disposed. */
865
	private Menu fRulerContextMenu;
870
	private Menu fRulerContextMenu;
Lines 1289-1295 Link Here
1289
		fInformationPresenter = new InformationPresenter(informationControlCreator);
1294
		fInformationPresenter = new InformationPresenter(informationControlCreator);
1290
		fInformationPresenter.setSizeConstraints(60, 10, true, true);
1295
		fInformationPresenter.setSizeConstraints(60, 10, true, true);
1291
		fInformationPresenter.install(getSourceViewer());
1296
		fInformationPresenter.install(getSourceViewer());
1292
1297
		addReconcilingListeners(getSourceViewerConfiguration(), getTextViewer());
1293
		installSemanticHighlighting();
1298
		installSemanticHighlighting();
1294
		
1299
		
1295
		
1300
		
Lines 1828-1833 Link Here
1828
				result = input.getAdapter(required);
1833
				result = input.getAdapter(required);
1829
			}
1834
			}
1830
		}
1835
		}
1836
		else if (ITextViewer.class.equals(required)) {
1837
			return getSourceViewer();
1838
		}
1831
		else {
1839
		else {
1832
			if (result == null && internalModel != null) {
1840
			if (result == null && internalModel != null) {
1833
				result = internalModel.getAdapter(required);
1841
				result = internalModel.getAdapter(required);
Lines 2633-2650 Link Here
2633
	 * that viewer configuration could be set after editor part was created.
2641
	 * that viewer configuration could be set after editor part was created.
2634
	 */
2642
	 */
2635
	protected void setSourceViewerConfiguration(SourceViewerConfiguration config) {
2643
	protected void setSourceViewerConfiguration(SourceViewerConfiguration config) {
2644
		SourceViewerConfiguration oldSourceViewerConfiguration = getSourceViewerConfiguration();
2636
		super.setSourceViewerConfiguration(config);
2645
		super.setSourceViewerConfiguration(config);
2637
		StructuredTextViewer stv = getTextViewer();
2646
		StructuredTextViewer stv = getTextViewer();
2638
		if (stv != null) {
2647
		if (stv != null) {
2639
			// there should be no need to unconfigure
2648
			/*
2640
			// before configure because
2649
			 * There should be no need to unconfigure before configure because
2641
			// configure will
2650
			 * configure will also unconfigure before configuring
2642
			// also unconfigure before configuring
2651
			 */
2652
			removeReconcilingListeners(oldSourceViewerConfiguration, stv);
2643
			stv.unconfigure();
2653
			stv.unconfigure();
2644
			stv.configure(config);
2654
			stv.configure(config);
2655
			addReconcilingListeners(config, stv);
2656
		}
2657
	}
2658
2659
	private void removeReconcilingListeners(SourceViewerConfiguration config, StructuredTextViewer stv) {
2660
		IReconciler reconciler = config.getReconciler(stv);
2661
		if (reconciler instanceof DocumentRegionProcessor) {
2662
			for (int i = 0; i < fReconcilingListeners.length; i++) {
2663
				((DocumentRegionProcessor) reconciler).removeReconcilingListener(fReconcilingListeners[i]);
2664
			}
2645
		}
2665
		}
2646
	}
2666
	}
2647
2667
2668
	private void addReconcilingListeners(SourceViewerConfiguration config, StructuredTextViewer stv) {
2669
		try {
2670
			List reconcilingListeners = new ArrayList(fReconcilingListeners.length);
2671
			String[] ids = getConfigurationPoints();
2672
			for (int i = 0; i < ids.length; i++) {
2673
				reconcilingListeners.addAll(ExtendedConfigurationBuilder.getInstance().getConfigurations("sourceReconcilingListener", ids[i])); //$NON-NLS-1$
2674
			}
2675
			fReconcilingListeners = (ISourceReconcilingListener[]) reconcilingListeners.toArray(new ISourceReconcilingListener[reconcilingListeners.size()]);
2676
		}
2677
		catch (ClassCastException e) {
2678
			Logger.log(Logger.ERROR, "Configuration has a reconciling listener that does not implement ISourceReconcilingListener."); //$NON-NLS-1$
2679
		}
2680
2681
		IReconciler reconciler = config.getReconciler(stv);
2682
		if (reconciler instanceof DocumentRegionProcessor) {
2683
			for (int i = 0; i < fReconcilingListeners.length; i++)
2684
				((DocumentRegionProcessor) reconciler).addReconcilingListener(fReconcilingListeners[i]);
2685
		}
2686
	}
2648
	/*
2687
	/*
2649
	 * (non-Javadoc)
2688
	 * (non-Javadoc)
2650
	 * 
2689
	 * 
(-)src/org/eclipse/wst/sse/ui/internal/reconcile/ISourceReconcilingListener.java (+44 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2009 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * 
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
12
package org.eclipse.wst.sse.ui.internal.reconcile;
13
14
import org.eclipse.core.runtime.IProgressMonitor;
15
import org.eclipse.jface.text.IDocument;
16
import org.eclipse.jface.text.source.IAnnotationModel;
17
18
/**
19
 * A course listener for source viewer "reconciling" of a document
20
 * 
21
 */
22
public interface ISourceReconcilingListener {
23
24
	/**
25
	 * Called before reconciling is started.
26
	 */
27
	void aboutToBeReconciled();
28
29
	/**
30
	 * Called after reconciling has been finished.
31
	 * 
32
	 * @param document
33
	 *            the text document or <code>null</code> if reconciliation has
34
	 *            been cancelled
35
	 * @param model
36
	 *            the annotation model that was changed or <code>null</code>
37
	 *            if reconciliation has been cancelled
38
	 * @param forced
39
	 *            <code>true</code> iff this reconciliation was forced
40
	 * @param progressMonitor
41
	 *            the progress monitor
42
	 */
43
	void reconciled(IDocument document, IAnnotationModel model, boolean forced, IProgressMonitor progressMonitor);
44
}

Return to bug 247221