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 / +41 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
		}
128
	}
129
130
	public void forceReconciling() {
131
		super.forceReconciling();
103
	}
132
	}
104
133
105
	protected String getContentType(IDocument doc) {
134
	protected String getContentType(IDocument doc) {
Lines 282-287 Link Here
282
			getFoldingStrategy().reconcile(dirtyRegion, null);
311
			getFoldingStrategy().reconcile(dirtyRegion, null);
283
		}
312
		}
284
	}
313
	}
314
	
315
	public void removeReconcilingListener(ISourceReconcilingListener listener) {
316
		Set listeners = new HashSet(Arrays.asList(fReconcileListeners));
317
		listeners.remove(listener);
318
		fReconcileListeners = (ISourceReconcilingListener[]) listeners.toArray(new ISourceReconcilingListener[listeners.size()]);
319
	}
320
285
321
286
	public void setDocument(IDocument doc) {
322
	public void setDocument(IDocument doc) {
287
		super.setDocument(doc);
323
		super.setDocument(doc);
Lines 332-338 Link Here
332
	 */
368
	 */
333
	public void install(ITextViewer textViewer) {
369
	public void install(ITextViewer textViewer) {
334
		super.install(textViewer);
370
		super.install(textViewer);
335
		
371
336
		//determine if validation is enabled
372
		//determine if validation is enabled
337
		this.fValidationEnabled = SSEUIPlugin.getInstance().getPreferenceStore().getBoolean(
373
		this.fValidationEnabled = SSEUIPlugin.getInstance().getPreferenceStore().getBoolean(
338
				CommonEditorPreferenceNames.EVALUATE_TEMPORARY_PROBLEMS);
374
				CommonEditorPreferenceNames.EVALUATE_TEMPORARY_PROBLEMS);
Lines 357-362 Link Here
357
				fSpellcheckStrategy.setDocument(null);
393
				fSpellcheckStrategy.setDocument(null);
358
				fSpellcheckStrategy = null;
394
				fSpellcheckStrategy = null;
359
			}
395
			}
396
397
			fReconcileListeners = new ISourceReconcilingListener[0];
360
		}
398
		}
361
		super.uninstall();
399
		super.uninstall();
362
	}
400
	}
(-)src/org/eclipse/wst/sse/ui/internal/reconcile/DirtyRegionProcessor.java (+22 lines)
Lines 267-272 Link Here
267
	/** The job should be reset because of document changes */
267
	/** The job should be reset because of document changes */
268
	private boolean fReset = false;
268
	private boolean fReset = false;
269
	private boolean fIsCanceled = false;
269
	private boolean fIsCanceled = false;
270
	private boolean fHasReconciled = false;
270
	private Object LOCK = new Object();
271
	private Object LOCK = new Object();
271
272
272
	/**
273
	/**
Lines 636-641 Link Here
636
		if (!PlatformUI.isWorkbenchRunning())
637
		if (!PlatformUI.isWorkbenchRunning())
637
			return status;
638
			return status;
638
639
640
		if (!fHasReconciled) {
641
			initialReconcile();
642
			fHasReconciled = true;
643
		}
644
639
		Thread.currentThread().setPriority(Thread.MIN_PRIORITY);
645
		Thread.currentThread().setPriority(Thread.MIN_PRIORITY);
640
		boolean processed = false;
646
		boolean processed = false;
641
		try {
647
		try {
Lines 708-713 Link Here
708
	}
714
	}
709
715
710
	/**
716
	/**
717
	 * This method is called before the initial reconciling of the document. 
718
	 */
719
	protected void initialReconcile() {
720
	}
721
722
	/**
711
	 * Sets the document partitioning for this reconciler.
723
	 * Sets the document partitioning for this reconciler.
712
	 * 
724
	 * 
713
	 * @param partitioning
725
	 * @param partitioning
Lines 718-723 Link Here
718
	}
730
	}
719
731
720
	/**
732
	/**
733
	 * Forces reconciling of the entire document.
734
	 */
735
	protected void forceReconciling() {
736
		if (!fHasReconciled)
737
			return;
738
739
		setEntireDocumentDirty(getDocument());
740
	}
741
742
	/**
721
	 * Basically means process the entire document.
743
	 * Basically means process the entire document.
722
	 * 
744
	 * 
723
	 * @param document
745
	 * @param document
(-)src/org/eclipse/wst/sse/ui/StructuredTextEditor.java (-6 / +83 lines)
Lines 102-110 Link Here
102
import org.eclipse.ui.IEditorSite;
102
import org.eclipse.ui.IEditorSite;
103
import org.eclipse.ui.IFileEditorInput;
103
import org.eclipse.ui.IFileEditorInput;
104
import org.eclipse.ui.IPageLayout;
104
import org.eclipse.ui.IPageLayout;
105
import org.eclipse.ui.IPartListener;
105
import org.eclipse.ui.ISharedImages;
106
import org.eclipse.ui.ISharedImages;
106
import org.eclipse.ui.IStorageEditorInput;
107
import org.eclipse.ui.IStorageEditorInput;
107
import org.eclipse.ui.IWorkbenchActionConstants;
108
import org.eclipse.ui.IWorkbenchActionConstants;
109
import org.eclipse.ui.IWorkbenchPart;
108
import org.eclipse.ui.PartInitException;
110
import org.eclipse.ui.PartInitException;
109
import org.eclipse.ui.PlatformUI;
111
import org.eclipse.ui.PlatformUI;
110
import org.eclipse.ui.contexts.IContextService;
112
import org.eclipse.ui.contexts.IContextService;
Lines 181-186 Link Here
181
import org.eclipse.wst.sse.ui.internal.provisional.extensions.breakpoint.NullSourceEditingTextTools;
183
import org.eclipse.wst.sse.ui.internal.provisional.extensions.breakpoint.NullSourceEditingTextTools;
182
import org.eclipse.wst.sse.ui.internal.provisional.preferences.CommonEditorPreferenceNames;
184
import org.eclipse.wst.sse.ui.internal.provisional.preferences.CommonEditorPreferenceNames;
183
import org.eclipse.wst.sse.ui.internal.reconcile.DocumentRegionProcessor;
185
import org.eclipse.wst.sse.ui.internal.reconcile.DocumentRegionProcessor;
186
import org.eclipse.wst.sse.ui.internal.reconcile.ISourceReconcilingListener;
184
import org.eclipse.wst.sse.ui.internal.selection.SelectionHistory;
187
import org.eclipse.wst.sse.ui.internal.selection.SelectionHistory;
185
import org.eclipse.wst.sse.ui.internal.style.SemanticHighlightingManager;
188
import org.eclipse.wst.sse.ui.internal.style.SemanticHighlightingManager;
186
import org.eclipse.wst.sse.ui.internal.text.DocumentRegionEdgeMatcher;
189
import org.eclipse.wst.sse.ui.internal.text.DocumentRegionEdgeMatcher;
Lines 803-808 Link Here
803
		}
806
		}
804
	}
807
	}
805
808
809
	private class PartListener implements IPartListener {
810
811
		ITextEditor fEditor;
812
813
		public PartListener(ITextEditor editor) {
814
			fEditor = editor;
815
		}
816
817
		public void partActivated(IWorkbenchPart part) {
818
			if (part.getAdapter(ITextEditor.class) == fEditor) {
819
				IReconciler reconciler = getSourceViewerConfiguration().getReconciler(getSourceViewer());
820
				if (reconciler instanceof DocumentRegionProcessor) {
821
					((DocumentRegionProcessor) reconciler).forceReconciling();
822
				}
823
			}
824
		}
825
826
		public void partBroughtToTop(IWorkbenchPart part) {
827
		}
828
829
		public void partClosed(IWorkbenchPart part) {
830
		}
831
832
		public void partDeactivated(IWorkbenchPart part) {
833
		}
834
835
		public void partOpened(IWorkbenchPart part) {
836
		}
837
		
838
	}
839
806
	/**
840
	/**
807
	 * Not API. May be removed in the future.
841
	 * Not API. May be removed in the future.
808
	 */
842
	 */
Lines 855-861 Link Here
855
	private OutlinePageListener fOutlinePageListener = null;
889
	private OutlinePageListener fOutlinePageListener = null;
856
	/** This editor's projection support */
890
	/** This editor's projection support */
857
	private ProjectionSupport fProjectionSupport;
891
	private ProjectionSupport fProjectionSupport;
892
	
858
	private IPropertySheetPage fPropertySheetPage;
893
	private IPropertySheetPage fPropertySheetPage;
894
895
	private ISourceReconcilingListener[] fReconcilingListeners = new ISourceReconcilingListener[0]; 
896
	private IPartListener fPartListener;
897
859
	private String fRememberTitle;
898
	private String fRememberTitle;
860
	/** The ruler context menu to be disposed. */
899
	/** The ruler context menu to be disposed. */
861
	private Menu fRulerContextMenu;
900
	private Menu fRulerContextMenu;
Lines 1285-1291 Link Here
1285
		fInformationPresenter = new InformationPresenter(informationControlCreator);
1324
		fInformationPresenter = new InformationPresenter(informationControlCreator);
1286
		fInformationPresenter.setSizeConstraints(60, 10, true, true);
1325
		fInformationPresenter.setSizeConstraints(60, 10, true, true);
1287
		fInformationPresenter.install(getSourceViewer());
1326
		fInformationPresenter.install(getSourceViewer());
1288
1327
		addReconcilingListeners(getSourceViewerConfiguration(), getTextViewer());
1328
		fPartListener = new PartListener(this);
1329
		getSite().getWorkbenchWindow().getPartService().addPartListener(fPartListener);
1289
		installSemanticHighlighting();
1330
		installSemanticHighlighting();
1290
		
1331
		
1291
		
1332
		
Lines 1529-1535 Link Here
1529
1570
1530
		if (fDropTarget != null)
1571
		if (fDropTarget != null)
1531
			fDropTarget.dispose();
1572
			fDropTarget.dispose();
1532
		
1573
1574
		if (fPartListener != null) {
1575
			getSite().getWorkbenchWindow().getPartService().removePartListener(fPartListener);
1576
			fPartListener = null;
1577
		}
1578
1533
		uninstallSemanticHighlighting();
1579
		uninstallSemanticHighlighting();
1534
1580
1535
		setPreferenceStore(null);
1581
		setPreferenceStore(null);
Lines 2650-2667 Link Here
2650
	 * that viewer configuration could be set after editor part was created.
2696
	 * that viewer configuration could be set after editor part was created.
2651
	 */
2697
	 */
2652
	protected void setSourceViewerConfiguration(SourceViewerConfiguration config) {
2698
	protected void setSourceViewerConfiguration(SourceViewerConfiguration config) {
2699
		SourceViewerConfiguration oldSourceViewerConfiguration = getSourceViewerConfiguration();
2653
		super.setSourceViewerConfiguration(config);
2700
		super.setSourceViewerConfiguration(config);
2654
		StructuredTextViewer stv = getTextViewer();
2701
		StructuredTextViewer stv = getTextViewer();
2655
		if (stv != null) {
2702
		if (stv != null) {
2656
			// there should be no need to unconfigure
2703
			/*
2657
			// before configure because
2704
			 * There should be no need to unconfigure before configure because
2658
			// configure will
2705
			 * configure will also unconfigure before configuring
2659
			// also unconfigure before configuring
2706
			 */
2707
			removeReconcilingListeners(oldSourceViewerConfiguration, stv);
2660
			stv.unconfigure();
2708
			stv.unconfigure();
2661
			stv.configure(config);
2709
			stv.configure(config);
2710
			addReconcilingListeners(config, stv);
2662
		}
2711
		}
2663
	}
2712
	}
2664
2713
2714
	private void removeReconcilingListeners(SourceViewerConfiguration config, StructuredTextViewer stv) {
2715
		IReconciler reconciler = config.getReconciler(stv);
2716
		if (reconciler instanceof DocumentRegionProcessor) {
2717
			for (int i = 0; i < fReconcilingListeners.length; i++) {
2718
				((DocumentRegionProcessor) reconciler).removeReconcilingListener(fReconcilingListeners[i]);
2719
			}
2720
		}
2721
	}
2722
2723
	private void addReconcilingListeners(SourceViewerConfiguration config, StructuredTextViewer stv) {
2724
		try {
2725
			List reconcilingListeners = new ArrayList(fReconcilingListeners.length);
2726
			String[] ids = getConfigurationPoints();
2727
			for (int i = 0; i < ids.length; i++) {
2728
				reconcilingListeners.addAll(ExtendedConfigurationBuilder.getInstance().getConfigurations("sourceReconcilingListener", ids[i])); //$NON-NLS-1$
2729
			}
2730
			fReconcilingListeners = (ISourceReconcilingListener[]) reconcilingListeners.toArray(new ISourceReconcilingListener[reconcilingListeners.size()]);
2731
		}
2732
		catch (ClassCastException e) {
2733
			Logger.log(Logger.ERROR, "Configuration has a reconciling listener that does not implement ISourceReconcilingListener."); //$NON-NLS-1$
2734
		}
2735
2736
		IReconciler reconciler = config.getReconciler(stv);
2737
		if (reconciler instanceof DocumentRegionProcessor) {
2738
			for (int i = 0; i < fReconcilingListeners.length; i++)
2739
				((DocumentRegionProcessor) reconciler).addReconcilingListener(fReconcilingListeners[i]);
2740
		}
2741
	}
2665
	/*
2742
	/*
2666
	 * (non-Javadoc)
2743
	 * (non-Javadoc)
2667
	 * 
2744
	 * 
(-)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