1 package net.sourceforge.phpeclipse.phpeditor;
3 /**********************************************************************
4 Copyright (c) 2000, 2002 IBM Corp. and others.
5 All rights reserved. This program and the accompanying materials
6 are made available under the terms of the Common Public License v1.0
7 which accompanies this distribution, and is available at
8 http://www.eclipse.org/legal/cpl-v10.html
11 IBM Corporation - Initial implementation
13 **********************************************************************/
15 import java.util.ArrayList;
16 import java.util.Iterator;
17 import java.util.List;
19 import net.sourceforge.phpdt.core.ICompilationUnit;
20 import net.sourceforge.phpdt.core.IProblemRequestor;
21 import net.sourceforge.phpdt.core.JavaCore;
22 import net.sourceforge.phpdt.core.JavaModelException;
23 import net.sourceforge.phpdt.core.compiler.IProblem;
24 import net.sourceforge.phpdt.internal.ui.text.IPHPPartitions;
25 import net.sourceforge.phpdt.internal.ui.text.java.IProblemRequestorExtension;
26 import net.sourceforge.phpdt.internal.ui.text.spelling.SpellReconcileStrategy.SpellProblem;
27 import net.sourceforge.phpdt.ui.PreferenceConstants;
28 import net.sourceforge.phpeclipse.PHPeclipsePlugin;
29 import net.sourceforge.phpeclipse.ui.WebUI;
31 import org.eclipse.core.resources.IFile;
32 import org.eclipse.core.resources.IMarker;
33 import org.eclipse.core.resources.IResource;
34 import org.eclipse.core.resources.IResourceRuleFactory;
35 import org.eclipse.core.resources.ResourcesPlugin;
36 import org.eclipse.core.runtime.CoreException;
37 import org.eclipse.core.runtime.IProgressMonitor;
38 import org.eclipse.core.runtime.jobs.ISchedulingRule;
39 import org.eclipse.jface.preference.IPreferenceStore;
40 import org.eclipse.jface.text.Assert;
41 import org.eclipse.jface.text.BadLocationException;
42 import org.eclipse.jface.text.DefaultLineTracker;
43 import org.eclipse.jface.text.Document;
44 import org.eclipse.jface.text.IDocument;
45 import org.eclipse.jface.text.ILineTracker;
46 import org.eclipse.jface.text.ISynchronizable;
47 import org.eclipse.jface.text.Position;
48 import org.eclipse.jface.text.source.Annotation;
49 import org.eclipse.jface.text.source.AnnotationModelEvent;
50 import org.eclipse.jface.text.source.IAnnotationAccessExtension;
51 import org.eclipse.jface.text.source.IAnnotationModel;
52 import org.eclipse.jface.text.source.IAnnotationModelListener;
53 import org.eclipse.jface.text.source.IAnnotationModelListenerExtension;
54 import org.eclipse.jface.text.source.IAnnotationPresentation;
55 import org.eclipse.jface.text.source.ImageUtilities;
56 import org.eclipse.jface.util.IPropertyChangeListener;
58 //import org.eclipse.jface.util.ListenerList;
59 import org.eclipse.core.runtime.ListenerList;
60 import org.eclipse.jface.util.PropertyChangeEvent;
61 import org.eclipse.swt.SWT;
62 import org.eclipse.swt.graphics.GC;
63 import org.eclipse.swt.graphics.Image;
64 import org.eclipse.swt.graphics.Rectangle;
65 import org.eclipse.swt.widgets.Canvas;
66 import org.eclipse.swt.widgets.Display;
67 import org.eclipse.ui.IFileEditorInput;
68 import org.eclipse.ui.editors.text.EditorsUI;
69 import org.eclipse.ui.editors.text.ForwardingDocumentProvider;
70 import org.eclipse.ui.editors.text.TextFileDocumentProvider;
71 import org.eclipse.ui.texteditor.AbstractMarkerAnnotationModel;
72 import org.eclipse.ui.texteditor.AnnotationPreference;
73 import org.eclipse.ui.texteditor.AnnotationPreferenceLookup;
74 import org.eclipse.ui.texteditor.IDocumentProvider;
75 import org.eclipse.ui.texteditor.MarkerAnnotation;
76 import org.eclipse.ui.texteditor.MarkerUtilities;
77 import org.eclipse.ui.texteditor.ResourceMarkerAnnotationModel;
80 * The PHPDocumentProvider provides the IDocuments used by java editors.
83 public class PHPDocumentProvider extends TextFileDocumentProvider implements
84 ICompilationUnitDocumentProvider {
86 * Here for visibility issues only.
90 * Bundle of all required informations to allow working copy management.
93 * Bundle of all required informations to allow working copy management.
95 static protected class CompilationUnitInfo extends FileInfo {
96 public ICompilationUnit fCopy;
100 * Annotation model dealing with java marker annotations and temporary
101 * problems. Also acts as problem requestor for its compilation unit.
102 * Initialiy inactive. Must explicitly be activated.
104 protected static class CompilationUnitAnnotationModel extends
105 ResourceMarkerAnnotationModel implements IProblemRequestor,
106 IProblemRequestorExtension {
108 private static class ProblemRequestorState {
109 boolean fInsideReportingSequence = false;
111 List fReportedProblems;
114 private ThreadLocal fProblemRequestorState = new ThreadLocal();
116 private int fStateCount = 0;
118 private ICompilationUnit fCompilationUnit;
120 private List fGeneratedAnnotations;
122 private IProgressMonitor fProgressMonitor;
124 private boolean fIsActive = false;
126 private ReverseMap fReverseMap = new ReverseMap();
128 private List fPreviouslyOverlaid = null;
130 private List fCurrentlyOverlaid = new ArrayList();
132 public CompilationUnitAnnotationModel(IResource resource) {
136 public void setCompilationUnit(ICompilationUnit unit) {
137 fCompilationUnit = unit;
140 protected MarkerAnnotation createMarkerAnnotation(IMarker marker) {
141 String markerType = MarkerUtilities.getMarkerType(marker);
142 if (markerType != null
144 .startsWith(JavaMarkerAnnotation.JAVA_MARKER_TYPE_PREFIX))
145 return new JavaMarkerAnnotation(marker);
146 return super.createMarkerAnnotation(marker);
150 * @see org.eclipse.jface.text.source.AnnotationModel#createAnnotationModelEvent()
152 protected AnnotationModelEvent createAnnotationModelEvent() {
153 return new CompilationUnitAnnotationModelEvent(this, getResource());
156 protected Position createPositionFromProblem(IProblem problem) {
157 int start = problem.getSourceStart();
161 int length = problem.getSourceEnd() - problem.getSourceStart() + 1;
165 return new Position(start, length);
169 * @see IProblemRequestor#beginReporting()
171 public void beginReporting() {
172 ProblemRequestorState state = (ProblemRequestorState) fProblemRequestorState
175 internalBeginReporting(false);
179 * @see net.sourceforge.phpdt.internal.ui.text.java.IProblemRequestorExtension#beginReportingSequence()
181 public void beginReportingSequence() {
182 ProblemRequestorState state = (ProblemRequestorState) fProblemRequestorState
185 internalBeginReporting(true);
189 * Sets up the infrastructure necessary for problem reporting.
191 * @param insideReportingSequence
192 * <code>true</code> if this method call is issued from
193 * inside a reporting sequence
195 private void internalBeginReporting(boolean insideReportingSequence) {
196 if (fCompilationUnit != null) {
198 // fCompilationUnit.getJavaProject().isOnClasspath(fCompilationUnit))
200 ProblemRequestorState state = new ProblemRequestorState();
201 state.fInsideReportingSequence = insideReportingSequence;
202 state.fReportedProblems = new ArrayList();
203 synchronized (getLockObject()) {
204 fProblemRequestorState.set(state);
211 * @see IProblemRequestor#acceptProblem(IProblem)
213 public void acceptProblem(IProblem problem) {
215 ProblemRequestorState state = (ProblemRequestorState) fProblemRequestorState
218 state.fReportedProblems.add(problem);
223 * @see IProblemRequestor#endReporting()
225 public void endReporting() {
226 ProblemRequestorState state = (ProblemRequestorState) fProblemRequestorState
228 if (state != null && !state.fInsideReportingSequence)
229 internalEndReporting(state);
233 * @see net.sourceforge.phpdt.internal.ui.text.java.IProblemRequestorExtension#endReportingSequence()
235 public void endReportingSequence() {
236 ProblemRequestorState state = (ProblemRequestorState) fProblemRequestorState
238 if (state != null && state.fInsideReportingSequence)
239 internalEndReporting(state);
242 private void internalEndReporting(ProblemRequestorState state) {
244 synchronized (getLockObject()) {
246 stateCount = fStateCount;
247 fProblemRequestorState.set(null);
250 if (stateCount == 0 && isActive())
251 reportProblems(state.fReportedProblems);
255 * Signals the end of problem reporting.
257 private void reportProblems(List reportedProblems) {
258 if (fProgressMonitor != null && fProgressMonitor.isCanceled())
261 boolean temporaryProblemsChanged = false;
263 synchronized (getLockObject()) {
265 boolean isCanceled = false;
267 fPreviouslyOverlaid = fCurrentlyOverlaid;
268 fCurrentlyOverlaid = new ArrayList();
270 if (fGeneratedAnnotations.size() > 0) {
271 temporaryProblemsChanged = true;
272 removeAnnotations(fGeneratedAnnotations, false, true);
273 fGeneratedAnnotations.clear();
276 if (reportedProblems != null && reportedProblems.size() > 0) {
278 Iterator e = reportedProblems.iterator();
279 while (e.hasNext()) {
281 if (fProgressMonitor != null
282 && fProgressMonitor.isCanceled()) {
287 IProblem problem = (IProblem) e.next();
288 Position position = createPositionFromProblem(problem);
289 if (position != null) {
292 ProblemAnnotation annotation = new ProblemAnnotation(
293 problem, fCompilationUnit);
294 overlayMarkers(position, annotation);
295 addAnnotation(annotation, position, false);
296 fGeneratedAnnotations.add(annotation);
298 temporaryProblemsChanged = true;
299 } catch (BadLocationException x) {
300 // ignore invalid position
306 removeMarkerOverlays(isCanceled);
307 fPreviouslyOverlaid = null;
310 if (temporaryProblemsChanged)
314 private void removeMarkerOverlays(boolean isCanceled) {
316 fCurrentlyOverlaid.addAll(fPreviouslyOverlaid);
317 } else if (fPreviouslyOverlaid != null) {
318 Iterator e = fPreviouslyOverlaid.iterator();
319 while (e.hasNext()) {
320 JavaMarkerAnnotation annotation = (JavaMarkerAnnotation) e
322 annotation.setOverlay(null);
328 * Overlays value with problem annotation.
330 * @param problemAnnotation
332 private void setOverlay(Object value,
333 ProblemAnnotation problemAnnotation) {
334 if (value instanceof JavaMarkerAnnotation) {
335 JavaMarkerAnnotation annotation = (JavaMarkerAnnotation) value;
336 if (annotation.isProblem()) {
337 annotation.setOverlay(problemAnnotation);
338 fPreviouslyOverlaid.remove(annotation);
339 fCurrentlyOverlaid.add(annotation);
345 private void overlayMarkers(Position position,
346 ProblemAnnotation problemAnnotation) {
347 Object value = getAnnotations(position);
348 if (value instanceof List) {
349 List list = (List) value;
350 for (Iterator e = list.iterator(); e.hasNext();)
351 setOverlay(e.next(), problemAnnotation);
353 setOverlay(value, problemAnnotation);
358 * Tells this annotation model to collect temporary problems from now
361 private void startCollectingProblems() {
362 fGeneratedAnnotations = new ArrayList();
366 * Tells this annotation model to no longer collect temporary problems.
368 private void stopCollectingProblems() {
369 if (fGeneratedAnnotations != null)
370 removeAnnotations(fGeneratedAnnotations, true, true);
371 fGeneratedAnnotations = null;
375 * @see IProblemRequestor#isActive()
377 public boolean isActive() {
382 * @see IProblemRequestorExtension#setProgressMonitor(IProgressMonitor)
384 public void setProgressMonitor(IProgressMonitor monitor) {
385 fProgressMonitor = monitor;
389 * @see IProblemRequestorExtension#setIsActive(boolean)
391 public void setIsActive(boolean isActive) {
392 if (fIsActive != isActive) {
393 fIsActive = isActive;
395 startCollectingProblems();
397 stopCollectingProblems();
401 private Object getAnnotations(Position position) {
402 return fReverseMap.get(position);
406 * @see AnnotationModel#addAnnotation(Annotation, Position, boolean)
408 protected void addAnnotation(Annotation annotation, Position position,
409 boolean fireModelChanged) throws BadLocationException {
410 super.addAnnotation(annotation, position, fireModelChanged);
412 Object cached = fReverseMap.get(position);
414 fReverseMap.put(position, annotation);
415 else if (cached instanceof List) {
416 List list = (List) cached;
417 list.add(annotation);
418 } else if (cached instanceof Annotation) {
419 List list = new ArrayList(2);
421 list.add(annotation);
422 fReverseMap.put(position, list);
427 * @see AnnotationModel#removeAllAnnotations(boolean)
429 protected void removeAllAnnotations(boolean fireModelChanged) {
430 super.removeAllAnnotations(fireModelChanged);
435 * @see AnnotationModel#removeAnnotation(Annotation, boolean)
437 protected void removeAnnotation(Annotation annotation,
438 boolean fireModelChanged) {
439 Position position = getPosition(annotation);
440 Object cached = fReverseMap.get(position);
441 if (cached instanceof List) {
442 List list = (List) cached;
443 list.remove(annotation);
444 if (list.size() == 1) {
445 fReverseMap.put(position, list.get(0));
448 } else if (cached instanceof Annotation) {
449 fReverseMap.remove(position);
451 super.removeAnnotation(annotation, fireModelChanged);
455 protected static class GlobalAnnotationModelListener implements
456 IAnnotationModelListener, IAnnotationModelListenerExtension {
458 private ListenerList fListenerList;
460 public GlobalAnnotationModelListener() {
461 fListenerList = new ListenerList();
464 public void addListener(IAnnotationModelListener listener) {
465 fListenerList.add(listener);
469 * @see IAnnotationModelListenerExtension#modelChanged(AnnotationModelEvent)
471 public void modelChanged(AnnotationModelEvent event) {
472 Object[] listeners = fListenerList.getListeners();
473 for (int i = 0; i < listeners.length; i++) {
474 Object curr = listeners[i];
475 if (curr instanceof IAnnotationModelListenerExtension) {
476 ((IAnnotationModelListenerExtension) curr)
477 .modelChanged(event);
483 * @see IAnnotationModelListener#modelChanged(IAnnotationModel)
485 public void modelChanged(IAnnotationModel model) {
486 Object[] listeners = fListenerList.getListeners();
487 for (int i = 0; i < listeners.length; i++) {
488 ((IAnnotationModelListener) listeners[i]).modelChanged(model);
492 public void removeListener(IAnnotationModelListener listener) {
493 fListenerList.remove(listener);
498 * Annotation representating an <code>IProblem</code>.
500 static public class ProblemAnnotation extends Annotation implements
501 IJavaAnnotation, IAnnotationPresentation {
503 private static final String SPELLING_ANNOTATION_TYPE = "org.eclipse.ui.workbench.texteditor.spelling";
505 // XXX: To be fully correct these constants should be non-static
507 * The layer in which task problem annotations are located.
509 private static final int TASK_LAYER;
512 * The layer in which info problem annotations are located.
514 private static final int INFO_LAYER;
517 * The layer in which warning problem annotations representing are
520 private static final int WARNING_LAYER;
523 * The layer in which error problem annotations representing are
526 private static final int ERROR_LAYER;
529 AnnotationPreferenceLookup lookup = EditorsUI
530 .getAnnotationPreferenceLookup();
531 TASK_LAYER = computeLayer(
532 "org.eclipse.ui.workbench.texteditor.task", lookup); //$NON-NLS-1$
533 INFO_LAYER = computeLayer("net.sourceforge.phpdt.ui.info", lookup); //$NON-NLS-1$
534 WARNING_LAYER = computeLayer(
535 "net.sourceforge.phpdt.ui.warning", lookup); //$NON-NLS-1$
536 ERROR_LAYER = computeLayer("net.sourceforge.phpdt.ui.error", lookup); //$NON-NLS-1$
539 private static int computeLayer(String annotationType,
540 AnnotationPreferenceLookup lookup) {
541 Annotation annotation = new Annotation(annotationType, false, null);
542 AnnotationPreference preference = lookup
543 .getAnnotationPreference(annotation);
544 if (preference != null)
545 return preference.getPresentationLayer() + 1;
547 return IAnnotationAccessExtension.DEFAULT_LAYER + 1;
550 // private static Image fgQuickFixImage;
551 // private static Image fgQuickFixErrorImage;
552 // private static boolean fgQuickFixImagesInitialized= false;
554 private ICompilationUnit fCompilationUnit;
556 private List fOverlaids;
558 private IProblem fProblem;
560 private Image fImage;
562 private boolean fQuickFixImagesInitialized = false;
564 private int fLayer = IAnnotationAccessExtension.DEFAULT_LAYER;
566 public ProblemAnnotation(IProblem problem, ICompilationUnit cu) {
569 fCompilationUnit = cu;
571 if (SpellProblem.Spelling == fProblem.getID()) {
572 setType(SPELLING_ANNOTATION_TYPE);
573 fLayer = WARNING_LAYER;
574 } else if (IProblem.Task == fProblem.getID()) {
575 setType(JavaMarkerAnnotation.TASK_ANNOTATION_TYPE);
577 } else if (fProblem.isWarning()) {
578 setType(JavaMarkerAnnotation.WARNING_ANNOTATION_TYPE);
579 fLayer = WARNING_LAYER;
580 } else if (fProblem.isError()) {
581 setType(JavaMarkerAnnotation.ERROR_ANNOTATION_TYPE);
582 fLayer = ERROR_LAYER;
584 setType(JavaMarkerAnnotation.INFO_ANNOTATION_TYPE);
590 * @see org.eclipse.jface.text.source.IAnnotationPresentation#getLayer()
592 public int getLayer() {
596 private void initializeImages() {
597 // http://bugs.eclipse.org/bugs/show_bug.cgi?id=18936
598 // if (!fQuickFixImagesInitialized) {
599 // if (isProblem() && indicateQuixFixableProblems() &&
600 // JavaCorrectionProcessor.hasCorrections(this)) { // no light bulb
602 // if (!fgQuickFixImagesInitialized) {
604 // JavaPluginImages.get(JavaPluginImages.IMG_OBJS_FIXABLE_PROBLEM);
605 // fgQuickFixErrorImage=
606 // JavaPluginImages.get(JavaPluginImages.IMG_OBJS_FIXABLE_ERROR);
607 // fgQuickFixImagesInitialized= true;
609 // if (JavaMarkerAnnotation.ERROR_ANNOTATION_TYPE.equals(getType()))
610 // fImage= fgQuickFixErrorImage;
612 // fImage= fgQuickFixImage;
614 // fQuickFixImagesInitialized= true;
618 private boolean indicateQuixFixableProblems() {
619 return PreferenceConstants.getPreferenceStore().getBoolean(
620 PreferenceConstants.EDITOR_CORRECTION_INDICATION);
624 * @see Annotation#paint
626 public void paint(GC gc, Canvas canvas, Rectangle r) {
629 ImageUtilities.drawImage(fImage, gc, canvas, r, SWT.CENTER,
634 * @see IJavaAnnotation#getImage(Display)
636 public Image getImage(Display display) {
642 * @see IJavaAnnotation#getMessage()
644 public String getText() {
645 return fProblem.getMessage();
649 * @see IJavaAnnotation#getArguments()
651 public String[] getArguments() {
652 return isProblem() ? fProblem.getArguments() : null;
656 * @see IJavaAnnotation#getId()
659 return fProblem.getID();
663 * @see IJavaAnnotation#isProblem()
665 public boolean isProblem() {
666 String type = getType();
667 return JavaMarkerAnnotation.WARNING_ANNOTATION_TYPE.equals(type)
668 || JavaMarkerAnnotation.ERROR_ANNOTATION_TYPE.equals(type)
669 || SPELLING_ANNOTATION_TYPE.equals(type);
673 * @see IJavaAnnotation#hasOverlay()
675 public boolean hasOverlay() {
680 * @see net.sourceforge.phpdt.internal.ui.javaeditor.IJavaAnnotation#getOverlay()
682 public IJavaAnnotation getOverlay() {
687 * @see IJavaAnnotation#addOverlaid(IJavaAnnotation)
689 public void addOverlaid(IJavaAnnotation annotation) {
690 if (fOverlaids == null)
691 fOverlaids = new ArrayList(1);
692 fOverlaids.add(annotation);
696 * @see IJavaAnnotation#removeOverlaid(IJavaAnnotation)
698 public void removeOverlaid(IJavaAnnotation annotation) {
699 if (fOverlaids != null) {
700 fOverlaids.remove(annotation);
701 if (fOverlaids.size() == 0)
707 * @see IJavaAnnotation#getOverlaidIterator()
709 public Iterator getOverlaidIterator() {
710 if (fOverlaids != null)
711 return fOverlaids.iterator();
716 * @see net.sourceforge.phpdt.internal.ui.javaeditor.IJavaAnnotation#getCompilationUnit()
718 public ICompilationUnit getCompilationUnit() {
719 return fCompilationUnit;
724 * Internal structure for mapping positions to some value. The reason for
725 * this specific structure is that positions can change over time. Thus a
726 * lookup is based on value and not on hash value.
728 protected static class ReverseMap {
736 private int fAnchor = 0;
738 private List fList = new ArrayList(2);
740 public ReverseMap() {
743 public void clear() {
747 public Object get(Position position) {
752 int length = fList.size();
753 for (int i = fAnchor; i < length; i++) {
754 entry = (Entry) fList.get(i);
755 if (entry.fPosition.equals(position)) {
762 for (int i = 0; i < fAnchor; i++) {
763 entry = (Entry) fList.get(i);
764 if (entry.fPosition.equals(position)) {
773 private int getIndex(Position position) {
775 int length = fList.size();
776 for (int i = 0; i < length; i++) {
777 entry = (Entry) fList.get(i);
778 if (entry.fPosition.equals(position))
784 public void put(Position position, Object value) {
785 int index = getIndex(position);
787 Entry entry = new Entry();
788 entry.fPosition = position;
789 entry.fValue = value;
792 Entry entry = (Entry) fList.get(index);
793 entry.fValue = value;
797 public void remove(Position position) {
798 int index = getIndex(position);
805 * Document that can also be used by a background reconciler.
807 protected static class PartiallySynchronizedDocument extends Document {
810 * @see IDocumentExtension#startSequentialRewrite(boolean)
812 synchronized public void startSequentialRewrite(boolean normalized) {
813 super.startSequentialRewrite(normalized);
817 * @see IDocumentExtension#stopSequentialRewrite()
819 synchronized public void stopSequentialRewrite() {
820 super.stopSequentialRewrite();
824 * @see IDocument#get()
826 synchronized public String get() {
831 * @see IDocument#get(int, int)
833 synchronized public String get(int offset, int length)
834 throws BadLocationException {
835 return super.get(offset, length);
839 * @see IDocument#getChar(int)
841 synchronized public char getChar(int offset)
842 throws BadLocationException {
843 return super.getChar(offset);
847 * @see IDocument#replace(int, int, String)
849 synchronized public void replace(int offset, int length, String text)
850 throws BadLocationException {
851 super.replace(offset, length, text);
855 * @see IDocument#set(String)
857 synchronized public void set(String text) {
863 // private static PHPPartitionScanner HTML_PARTITION_SCANNER = null;
865 // private static PHPPartitionScanner PHP_PARTITION_SCANNER = null;
866 // private static PHPPartitionScanner SMARTY_PARTITION_SCANNER = null;
868 // // private final static String[] TYPES= new String[] {
869 // PHPPartitionScanner.PHP, PHPPartitionScanner.JAVA_DOC,
870 // PHPPartitionScanner.JAVA_MULTILINE_COMMENT };
871 // private final static String[] TYPES =
873 // IPHPPartitionScannerConstants.PHP,
874 // IPHPPartitionScannerConstants.PHP_MULTILINE_COMMENT,
875 // IPHPPartitionScannerConstants.HTML,
876 // IPHPPartitionScannerConstants.HTML_MULTILINE_COMMENT,
877 // IPHPPartitionScannerConstants.JAVASCRIPT,
878 // IPHPPartitionScannerConstants.CSS,
879 // IPHPPartitionScannerConstants.SMARTY,
880 // IPHPPartitionScannerConstants.SMARTY_MULTILINE_COMMENT };
881 // private static PHPPartitionScanner XML_PARTITION_SCANNER = null;
883 /* Preference key for temporary problems */
884 private final static String HANDLE_TEMPORARY_PROBLEMS = PreferenceConstants.EDITOR_EVALUTE_TEMPORARY_PROBLEMS;
886 /** Indicates whether the save has been initialized by this provider */
887 private boolean fIsAboutToSave = false;
889 /** The save policy used by this provider */
890 private ISavePolicy fSavePolicy;
892 /** Internal property changed listener */
893 private IPropertyChangeListener fPropertyListener;
895 /** annotation model listener added to all created CU annotation models */
896 private GlobalAnnotationModelListener fGlobalAnnotationModelListener;
898 public PHPDocumentProvider() {
899 // IDocumentProvider provider= new TextFileDocumentProvider(new
900 // JavaStorageDocumentProvider());
901 IDocumentProvider provider = new TextFileDocumentProvider();
902 provider = new ForwardingDocumentProvider(
903 IPHPPartitions.PHP_PARTITIONING,
904 new JavaDocumentSetupParticipant(), provider);
905 setParentDocumentProvider(provider);
907 fGlobalAnnotationModelListener = new GlobalAnnotationModelListener();
908 fPropertyListener = new IPropertyChangeListener() {
909 public void propertyChange(PropertyChangeEvent event) {
910 if (HANDLE_TEMPORARY_PROBLEMS.equals(event.getProperty()))
911 enableHandlingTemporaryProblems();
914 WebUI.getDefault().getPreferenceStore()
915 .addPropertyChangeListener(fPropertyListener);
920 * Sets the document provider's save policy.
922 public void setSavePolicy(ISavePolicy savePolicy) {
923 fSavePolicy = savePolicy;
927 * Creates a compilation unit from the given file.
930 * the file from which to create the compilation unit
932 protected ICompilationUnit createCompilationUnit(IFile file) {
933 Object element = JavaCore.create(file);
934 if (element instanceof ICompilationUnit)
935 return (ICompilationUnit) element;
940 * @see org.eclipse.ui.editors.text.TextFileDocumentProvider#createEmptyFileInfo()
942 protected FileInfo createEmptyFileInfo() {
943 return new CompilationUnitInfo();
947 * @see org.eclipse.ui.editors.text.TextFileDocumentProvider#createAnnotationModel(org.eclipse.core.resources.IFile)
949 protected IAnnotationModel createAnnotationModel(IFile file) {
950 return new CompilationUnitAnnotationModel(file);
954 * @see AbstractDocumentProvider#createElementInfo(Object)
956 // protected ElementInfo createElementInfo(Object element) throws
959 // if (!(element instanceof IFileEditorInput))
960 // return super.createElementInfo(element);
962 // IFileEditorInput input = (IFileEditorInput) element;
963 // ICompilationUnit original = createCompilationUnit(input.getFile());
964 // if (original != null) {
969 // refreshFile(input.getFile());
970 // } catch (CoreException x) {
971 // handleCoreException(x,
972 // PHPEditorMessages.getString("PHPDocumentProvider.error.createElementInfo"));
976 // IAnnotationModel m = createCompilationUnitAnnotationModel(input);
977 // IProblemRequestor r = m instanceof IProblemRequestor ?
978 // (IProblemRequestor) m : null;
979 // ICompilationUnit c = (ICompilationUnit)
980 // original.getSharedWorkingCopy(getProgressMonitor(), fBufferFactory, r);
982 // DocumentAdapter a = null;
984 // a = (DocumentAdapter) c.getBuffer();
985 // } catch (ClassCastException x) {
986 // IStatus status = new Status(IStatus.ERROR, PHPeclipsePlugin.PLUGIN_ID,
987 // PHPStatusConstants.TEMPLATE_IO_EXCEPTION, "Shared working copy has wrong
988 // buffer", x); //$NON-NLS-1$
989 // throw new CoreException(status);
992 // _FileSynchronizer f = new _FileSynchronizer(input);
995 // CompilationUnitInfo info = new CompilationUnitInfo(a.getDocument(), m, f,
997 // info.setModificationStamp(computeModificationStamp(input.getFile()));
998 // info.fStatus = a.getStatus();
999 // info.fEncoding = getPersistedEncoding(input);
1001 // if (r instanceof IProblemRequestorExtension) {
1002 // IProblemRequestorExtension extension = (IProblemRequestorExtension) r;
1003 // extension.setIsActive(isHandlingTemporaryProblems());
1005 // m.addAnnotationModelListener(fGlobalAnnotationModelListener);
1009 // } catch (JavaModelException x) {
1010 // throw new CoreException(x.getStatus());
1013 // return super.createElementInfo(element);
1017 * @see AbstractDocumentProvider#disposeElementInfo(Object, ElementInfo)
1019 // protected void disposeElementInfo(Object element, ElementInfo info) {
1021 // if (info instanceof CompilationUnitInfo) {
1022 // CompilationUnitInfo cuInfo = (CompilationUnitInfo) info;
1023 // cuInfo.fCopy.destroy();
1024 // cuInfo.fModel.removeAnnotationModelListener(fGlobalAnnotationModelListener);
1027 // super.disposeElementInfo(element, info);
1030 * @see AbstractDocumentProvider#doSaveDocument(IProgressMonitor, Object,
1031 * IDocument, boolean)
1033 // protected void doSaveDocument(IProgressMonitor monitor, Object element,
1034 // IDocument document, boolean overwrite)
1035 // throws CoreException {
1037 // ElementInfo elementInfo = getElementInfo(element);
1038 // if (elementInfo instanceof CompilationUnitInfo) {
1039 // CompilationUnitInfo info = (CompilationUnitInfo) elementInfo;
1041 // // update structure, assumes lock on info.fCopy
1042 // info.fCopy.reconcile();
1044 // ICompilationUnit original = (ICompilationUnit)
1045 // info.fCopy.getOriginalElement();
1046 // IResource resource = original.getResource();
1048 // if (resource == null) {
1049 // // underlying resource has been deleted, just recreate file, ignore the
1051 // super.doSaveDocument(monitor, element, document, overwrite);
1055 // if (resource != null && !overwrite)
1056 // checkSynchronizationState(info.fModificationStamp, resource);
1058 // if (fSavePolicy != null)
1059 // fSavePolicy.preSave(info.fCopy);
1061 // // inform about the upcoming content change
1062 // fireElementStateChanging(element);
1064 // fIsAboutToSave = true;
1065 // // commit working copy
1066 // info.fCopy.commit(overwrite, monitor);
1067 // } catch (CoreException x) {
1068 // // inform about the failure
1069 // fireElementStateChangeFailed(element);
1071 // } catch (RuntimeException x) {
1072 // // inform about the failure
1073 // fireElementStateChangeFailed(element);
1076 // fIsAboutToSave = false;
1079 // // If here, the dirty state of the editor will change to "not dirty".
1080 // // Thus, the state changing flag will be reset.
1082 // AbstractMarkerAnnotationModel model = (AbstractMarkerAnnotationModel)
1084 // model.updateMarkers(info.fDocument);
1086 // if (resource != null)
1087 // info.setModificationStamp(computeModificationStamp(resource));
1089 // if (fSavePolicy != null) {
1090 // ICompilationUnit unit = fSavePolicy.postSave(original);
1091 // if (unit != null) {
1092 // IResource r = unit.getResource();
1093 // IMarker[] markers = r.findMarkers(IMarker.MARKER, true,
1094 // IResource.DEPTH_ZERO);
1095 // if (markers != null && markers.length > 0) {
1096 // for (int i = 0; i < markers.length; i++)
1097 // model.updateMarker(markers[i], info.fDocument, null);
1103 // super.doSaveDocument(monitor, element, document, overwrite);
1107 * @see org.eclipse.ui.editors.text.TextFileDocumentProvider#createFileInfo(java.lang.Object)
1109 protected FileInfo createFileInfo(Object element) throws CoreException {
1110 if (!(element instanceof IFileEditorInput))
1113 IFileEditorInput input = (IFileEditorInput) element;
1114 ICompilationUnit original = createCompilationUnit(input.getFile());
1115 if (original == null)
1118 FileInfo info = super.createFileInfo(element);
1119 if (!(info instanceof CompilationUnitInfo))
1122 CompilationUnitInfo cuInfo = (CompilationUnitInfo) info;
1123 setUpSynchronization(cuInfo);
1125 IProblemRequestor requestor = cuInfo.fModel instanceof IProblemRequestor ? (IProblemRequestor) cuInfo.fModel
1128 original.becomeWorkingCopy(requestor, getProgressMonitor());
1129 cuInfo.fCopy = original;
1131 if (cuInfo.fModel instanceof CompilationUnitAnnotationModel) {
1132 CompilationUnitAnnotationModel model = (CompilationUnitAnnotationModel) cuInfo.fModel;
1133 model.setCompilationUnit(cuInfo.fCopy);
1136 if (cuInfo.fModel != null)
1138 .addAnnotationModelListener(fGlobalAnnotationModelListener);
1140 if (requestor instanceof IProblemRequestorExtension) {
1141 IProblemRequestorExtension extension = (IProblemRequestorExtension) requestor;
1142 extension.setIsActive(isHandlingTemporaryProblems());
1148 private void setUpSynchronization(CompilationUnitInfo cuInfo) {
1149 IDocument document = cuInfo.fTextFileBuffer.getDocument();
1150 IAnnotationModel model = cuInfo.fModel;
1152 if (document instanceof ISynchronizable
1153 && model instanceof ISynchronizable) {
1154 Object lock = ((ISynchronizable) document).getLockObject();
1155 ((ISynchronizable) model).setLockObject(lock);
1160 * @see org.eclipse.ui.editors.text.TextFileDocumentProvider#disposeFileInfo(java.lang.Object,
1161 * org.eclipse.ui.editors.text.TextFileDocumentProvider.FileInfo)
1163 protected void disposeFileInfo(Object element, FileInfo info) {
1164 if (info instanceof CompilationUnitInfo) {
1165 CompilationUnitInfo cuInfo = (CompilationUnitInfo) info;
1168 cuInfo.fCopy.discardWorkingCopy();
1169 } catch (JavaModelException x) {
1170 handleCoreException(x, x.getMessage());
1173 if (cuInfo.fModel != null)
1175 .removeAnnotationModelListener(fGlobalAnnotationModelListener);
1177 super.disposeFileInfo(element, info);
1180 protected void commitWorkingCopy(IProgressMonitor monitor, Object element,
1181 CompilationUnitInfo info, boolean overwrite) throws CoreException {
1182 synchronized (info.fCopy) {
1183 info.fCopy.reconcile();
1186 IDocument document = info.fTextFileBuffer.getDocument();
1187 IResource resource = info.fCopy.getResource();
1189 Assert.isTrue(resource instanceof IFile);
1190 if (!resource.exists()) {
1191 // underlying resource has been deleted, just recreate file, ignore
1193 createFileFromDocument(monitor, (IFile) resource, document);
1197 if (fSavePolicy != null)
1198 fSavePolicy.preSave(info.fCopy);
1202 fIsAboutToSave = true;
1203 info.fCopy.commitWorkingCopy(overwrite, monitor);
1205 } catch (CoreException x) {
1206 // inform about the failure
1207 fireElementStateChangeFailed(element);
1209 } catch (RuntimeException x) {
1210 // inform about the failure
1211 fireElementStateChangeFailed(element);
1214 fIsAboutToSave = false;
1217 // If here, the dirty state of the editor will change to "not dirty".
1218 // Thus, the state changing flag will be reset.
1219 if (info.fModel instanceof AbstractMarkerAnnotationModel) {
1220 AbstractMarkerAnnotationModel model = (AbstractMarkerAnnotationModel) info.fModel;
1221 model.updateMarkers(document);
1224 if (fSavePolicy != null) {
1225 ICompilationUnit unit = fSavePolicy.postSave(info.fCopy);
1227 && info.fModel instanceof AbstractMarkerAnnotationModel) {
1228 IResource r = unit.getResource();
1229 IMarker[] markers = r.findMarkers(IMarker.MARKER, true,
1230 IResource.DEPTH_ZERO);
1231 if (markers != null && markers.length > 0) {
1232 AbstractMarkerAnnotationModel model = (AbstractMarkerAnnotationModel) info.fModel;
1233 for (int i = 0; i < markers.length; i++)
1234 model.updateMarker(document, markers[i], null);
1242 * @see org.eclipse.ui.editors.text.TextFileDocumentProvider#createSaveOperation(java.lang.Object,
1243 * org.eclipse.jface.text.IDocument, boolean)
1245 protected DocumentProviderOperation createSaveOperation(
1246 final Object element, final IDocument document,
1247 final boolean overwrite) throws CoreException {
1248 // final FileInfo info= getFileInfo(element);
1249 // if (info instanceof CompilationUnitInfo) {
1250 // return new DocumentProviderOperation() {
1253 // org.eclipse.ui.editors.text.TextFileDocumentProvider.DocumentProviderOperation#execute(org.eclipse.core.runtime.IProgressMonitor)
1255 // protected void execute(IProgressMonitor monitor) throws CoreException
1257 // commitWorkingCopy(monitor, element, (CompilationUnitInfo) info,
1262 // org.eclipse.ui.editors.text.TextFileDocumentProvider.DocumentProviderOperation#getSchedulingRule()
1264 // public ISchedulingRule getSchedulingRule() {
1265 // if (info.fElement instanceof IFileEditorInput) {
1266 // IFile file= ((IFileEditorInput) info.fElement).getFile();
1267 // IResourceRuleFactory ruleFactory=
1268 // ResourcesPlugin.getWorkspace().getRuleFactory();
1269 // if (file == null || !file.exists())
1270 // return ruleFactory.createRule(file);
1272 // return ruleFactory.modifyRule(file);
1279 final FileInfo info = getFileInfo(element);
1280 if (info instanceof CompilationUnitInfo) {
1281 return new DocumentProviderOperation() {
1283 * @see org.eclipse.ui.editors.text.TextFileDocumentProvider.DocumentProviderOperation#execute(org.eclipse.core.runtime.IProgressMonitor)
1285 protected void execute(IProgressMonitor monitor)
1286 throws CoreException {
1287 commitWorkingCopy(monitor, element,
1288 (CompilationUnitInfo) info, overwrite);
1292 * @see org.eclipse.ui.editors.text.TextFileDocumentProvider.DocumentProviderOperation#getSchedulingRule()
1294 public ISchedulingRule getSchedulingRule() {
1295 if (info.fElement instanceof IFileEditorInput) {
1296 IFile file = ((IFileEditorInput) info.fElement)
1298 return computeSchedulingRule(file);
1308 * (non-Javadoc) Method declared on AbstractDocumentProvider
1310 // protected IDocument createDocument(Object element) throws CoreException {
1311 // if (element instanceof IEditorInput) {
1312 // Document document = new PartiallySynchronizedDocument();
1313 // if (setDocumentContent(document, (IEditorInput) element,
1314 // getEncoding(element))) {
1315 // initializeDocument(document, (IEditorInput) element);
1318 // // IDocument document = super.createDocument(element);
1319 // // if (document != null) {
1320 // // IDocumentPartitioner partitioner = null;
1321 // // if (element instanceof FileEditorInput) {
1322 // // IFile file = (IFile) ((FileEditorInput)
1323 // element).getAdapter(IFile.class);
1324 // // String filename = file.getLocation().toString();
1325 // // String extension = filename.substring(filename.lastIndexOf("."),
1326 // filename.length());
1327 // // // System.out.println(extension);
1328 // // if (extension.equalsIgnoreCase(".html") ||
1329 // extension.equalsIgnoreCase(".htm")) {
1331 // // partitioner = createHTMLPartitioner();
1332 // // } else if (extension.equalsIgnoreCase(".xml")) {
1334 // // partitioner = createXMLPartitioner();
1335 // // } else if (extension.equalsIgnoreCase(".js")) {
1337 // // partitioner = createJavaScriptPartitioner();
1338 // // } else if (extension.equalsIgnoreCase(".css")) {
1339 // // // cascading style sheets
1340 // // partitioner = createCSSPartitioner();
1341 // // } else if (extension.equalsIgnoreCase(".tpl")) {
1343 // // partitioner = createSmartyPartitioner();
1344 // // } else if (extension.equalsIgnoreCase(".inc")) {
1345 // // // php include files ?
1346 // // partitioner = createIncludePartitioner();
1350 // // if (partitioner == null) {
1351 // // partitioner = createPHPPartitioner();
1353 // // document.setDocumentPartitioner(partitioner);
1354 // // partitioner.connect(document);
1361 // * Return a partitioner for .html files.
1363 // private IDocumentPartitioner createHTMLPartitioner() {
1364 // return new DefaultPartitioner(getHTMLPartitionScanner(), TYPES);
1367 // private IDocumentPartitioner createIncludePartitioner() {
1368 // return new DefaultPartitioner(getPHPPartitionScanner(), TYPES);
1371 // private IDocumentPartitioner createJavaScriptPartitioner() {
1372 // return new DefaultPartitioner(getHTMLPartitionScanner(), TYPES);
1375 * Creates a line tracker working with the same line delimiters as the
1376 * document of the given element. Assumes the element to be managed by this
1377 * document provider.
1380 * the element serving as blue print
1381 * @return a line tracker based on the same line delimiters as the element's
1384 public ILineTracker createLineTracker(Object element) {
1385 return new DefaultLineTracker();
1389 // * Return a partitioner for .php files.
1391 // private IDocumentPartitioner createPHPPartitioner() {
1392 // return new DefaultPartitioner(getPHPPartitionScanner(), TYPES);
1395 // private IDocumentPartitioner createSmartyPartitioner() {
1396 // return new DefaultPartitioner(getSmartyPartitionScanner(), TYPES);
1399 // private IDocumentPartitioner createXMLPartitioner() {
1400 // return new DefaultPartitioner(getXMLPartitionScanner(), TYPES);
1404 // * Return a scanner for creating html partitions.
1406 // private PHPPartitionScanner getHTMLPartitionScanner() {
1407 // if (HTML_PARTITION_SCANNER == null)
1408 // HTML_PARTITION_SCANNER = new
1409 // PHPPartitionScanner(IPHPPartitionScannerConstants.HTML_FILE);
1410 // return HTML_PARTITION_SCANNER;
1413 // * Return a scanner for creating php partitions.
1415 // private PHPPartitionScanner getPHPPartitionScanner() {
1416 // if (PHP_PARTITION_SCANNER == null)
1417 // PHP_PARTITION_SCANNER = new
1418 // PHPPartitionScanner(IPHPPartitionScannerConstants.PHP_FILE);
1419 // return PHP_PARTITION_SCANNER;
1423 // * Return a scanner for creating smarty partitions.
1425 // private PHPPartitionScanner getSmartyPartitionScanner() {
1426 // if (SMARTY_PARTITION_SCANNER == null)
1427 // SMARTY_PARTITION_SCANNER = new
1428 // PHPPartitionScanner(IPHPPartitionScannerConstants.SMARTY_FILE);
1429 // return SMARTY_PARTITION_SCANNER;
1433 // * Return a scanner for creating xml partitions.
1435 // private PHPPartitionScanner getXMLPartitionScanner() {
1436 // if (XML_PARTITION_SCANNER == null)
1437 // XML_PARTITION_SCANNER = new
1438 // PHPPartitionScanner(IPHPPartitionScannerConstants.XML_FILE);
1439 // return XML_PARTITION_SCANNER;
1442 // protected void initializeDocument(IDocument document, IEditorInput
1444 // if (document != null) {
1445 // JavaTextTools tools = PHPeclipsePlugin.getDefault().getJavaTextTools();
1446 // IDocumentPartitioner partitioner = null;
1447 // if (editorInput != null && editorInput instanceof FileEditorInput) {
1448 // IFile file = (IFile) ((FileEditorInput)
1449 // editorInput).getAdapter(IFile.class);
1450 // String filename = file.getLocation().toString();
1451 // String extension = filename.substring(filename.lastIndexOf("."),
1452 // filename.length());
1453 // partitioner = tools.createDocumentPartitioner(extension);
1455 // partitioner = tools.createDocumentPartitioner(".php");
1457 // document.setDocumentPartitioner(partitioner);
1458 // partitioner.connect(document);
1463 * @see org.eclipse.ui.texteditor.AbstractDocumentProvider#doResetDocument(java.lang.Object,
1464 * org.eclipse.core.runtime.IProgressMonitor)
1466 // protected void doResetDocument(Object element, IProgressMonitor monitor)
1467 // throws CoreException {
1468 // if (element == null)
1471 // ElementInfo elementInfo= getElementInfo(element);
1472 // if (elementInfo instanceof CompilationUnitInfo) {
1473 // CompilationUnitInfo info= (CompilationUnitInfo) elementInfo;
1475 // IDocument document;
1476 // IStatus status= null;
1480 // ICompilationUnit original= (ICompilationUnit)
1481 // info.fCopy.getOriginalElement();
1482 // IResource resource= original.getResource();
1483 // if (resource instanceof IFile) {
1485 // IFile file= (IFile) resource;
1488 // refreshFile(file, monitor);
1489 // } catch (CoreException x) {
1490 // handleCoreException(x,
1491 // PHPEditorMessages.getString("CompilationUnitDocumentProvider.error.resetDocument"));
1495 // IFileEditorInput input= new FileEditorInput(file);
1496 // document= super.createDocument(input);
1499 // document= createEmptyDocument();
1502 // } catch (CoreException x) {
1503 // document= createEmptyDocument();
1504 // status= x.getStatus();
1507 // fireElementContentAboutToBeReplaced(element);
1509 // removeUnchangedElementListeners(element, info);
1510 // info.fDocument.set(document.get());
1511 // info.fCanBeSaved= false;
1512 // info.fStatus= status;
1513 // addUnchangedElementListeners(element, info);
1515 // fireElementContentReplaced(element);
1516 // fireElementDirtyStateChanged(element, false);
1519 // super.doResetDocument(element, monitor);
1523 * @see AbstractDocumentProvider#resetDocument(Object)
1525 // public void resetDocument(Object element) throws CoreException {
1526 // if (element == null)
1529 // ElementInfo elementInfo = getElementInfo(element);
1530 // if (elementInfo instanceof CompilationUnitInfo) {
1531 // CompilationUnitInfo info = (CompilationUnitInfo) elementInfo;
1533 // IDocument document;
1534 // IStatus status = null;
1538 // ICompilationUnit original = (ICompilationUnit)
1539 // info.fCopy.getOriginalElement();
1540 // IResource resource = original.getResource();
1541 // if (resource instanceof IFile) {
1543 // IFile file = (IFile) resource;
1546 // refreshFile(file);
1547 // } catch (CoreException x) {
1548 // handleCoreException(x,
1549 // PHPEditorMessages.getString("PHPDocumentProvider.error.resetDocument"));
1553 // IFileEditorInput input = new FileEditorInput(file);
1554 // document = super.createDocument(input);
1557 // document = new Document();
1560 // } catch (CoreException x) {
1561 // document = new Document();
1562 // status = x.getStatus();
1565 // fireElementContentAboutToBeReplaced(element);
1567 // removeUnchangedElementListeners(element, info);
1568 // info.fDocument.set(document.get());
1569 // info.fCanBeSaved = false;
1570 // info.fStatus = status;
1571 // addUnchangedElementListeners(element, info);
1573 // fireElementContentReplaced(element);
1574 // fireElementDirtyStateChanged(element, false);
1577 // super.resetDocument(element);
1581 * Saves the content of the given document to the given element. This is
1582 * only performed when this provider initiated the save.
1585 * the progress monitor
1587 * the element to which to save
1589 * the document to save
1591 * <code>true</code> if the save should be enforced
1593 public void saveDocumentContent(IProgressMonitor monitor, Object element,
1594 IDocument document, boolean overwrite) throws CoreException {
1595 if (!fIsAboutToSave)
1597 super.saveDocument(monitor, element, document, overwrite);
1598 // if (!fIsAboutToSave)
1601 // if (element instanceof IFileEditorInput) {
1602 // IFileEditorInput input = (IFileEditorInput) element;
1604 // String encoding = getEncoding(element);
1605 // if (encoding == null)
1606 // encoding = ResourcesPlugin.getEncoding();
1607 // InputStream stream = new
1608 // ByteArrayInputStream(document.get().getBytes(encoding));
1609 // IFile file = input.getFile();
1610 // file.setContents(stream, overwrite, true, monitor);
1611 // } catch (IOException x) {
1612 // IStatus s = new Status(IStatus.ERROR, PHPeclipsePlugin.PLUGIN_ID,
1613 // IStatus.OK, x.getMessage(), x);
1614 // throw new CoreException(s);
1620 * Returns the underlying resource for the given element.
1624 * @return the underlying resource of the given element
1626 // public IResource getUnderlyingResource(Object element) {
1627 // if (element instanceof IFileEditorInput) {
1628 // IFileEditorInput input = (IFileEditorInput) element;
1629 // return input.getFile();
1634 * @see net.sourceforge.phpdt.internal.ui.javaeditor.ICompilationUnitDocumentProvider#getWorkingCopy(java.lang.Object)
1636 public ICompilationUnit getWorkingCopy(Object element) {
1637 FileInfo fileInfo = getFileInfo(element);
1638 if (fileInfo instanceof CompilationUnitInfo) {
1639 CompilationUnitInfo info = (CompilationUnitInfo) fileInfo;
1646 * @see net.sourceforge.phpdt.internal.ui.javaeditor.ICompilationUnitDocumentProvider#shutdown()
1648 public void shutdown() {
1649 WebUI.getDefault().getPreferenceStore()
1650 .removePropertyChangeListener(fPropertyListener);
1651 Iterator e = getConnectedElementsIterator();
1653 disconnect(e.next());
1657 * Returns the preference whether handling temporary problems is enabled.
1659 protected boolean isHandlingTemporaryProblems() {
1660 IPreferenceStore store = WebUI.getDefault()
1661 .getPreferenceStore();
1662 return store.getBoolean(HANDLE_TEMPORARY_PROBLEMS);
1666 * Switches the state of problem acceptance according to the value in the
1669 protected void enableHandlingTemporaryProblems() {
1670 boolean enable = isHandlingTemporaryProblems();
1671 for (Iterator iter = getFileInfosIterator(); iter.hasNext();) {
1672 FileInfo info = (FileInfo) iter.next();
1673 if (info.fModel instanceof IProblemRequestorExtension) {
1674 IProblemRequestorExtension extension = (IProblemRequestorExtension) info.fModel;
1675 extension.setIsActive(enable);
1681 * Adds a listener that reports changes from all compilation unit annotation
1684 public void addGlobalAnnotationModelListener(
1685 IAnnotationModelListener listener) {
1686 fGlobalAnnotationModelListener.addListener(listener);
1690 * Removes the listener.
1692 public void removeGlobalAnnotationModelListener(
1693 IAnnotationModelListener listener) {
1694 fGlobalAnnotationModelListener.removeListener(listener);
1698 * Computes the scheduling rule needed to create or modify a resource. If
1699 * the resource exists, its modify rule is returned. If it does not, the
1700 * resource hierarchy is iterated towards the workspace root to find the
1701 * first parent of <code>toCreateOrModify</code> that exists. Then the
1702 * 'create' rule for the last non-existing resource is returned.
1704 * XXX This is a workaround for
1705 * https://bugs.eclipse.org/bugs/show_bug.cgi?id=67601
1706 * IResourceRuleFactory.createRule should iterate the hierarchy itself.
1709 * XXX to be replaced by call to
1710 * TextFileDocumentProvider.computeSchedulingRule after 3.0
1713 * @param toCreateOrModify
1714 * the resource to create or modify
1715 * @return the minimal scheduling rule needed to modify or create a resource
1717 protected ISchedulingRule computeSchedulingRule(IResource toCreateOrModify) {
1718 IResourceRuleFactory factory = ResourcesPlugin.getWorkspace()
1720 if (toCreateOrModify.exists()) {
1721 return factory.modifyRule(toCreateOrModify);
1723 IResource parent = toCreateOrModify;
1725 toCreateOrModify = parent;
1726 parent = toCreateOrModify.getParent();
1727 } while (parent != null && !parent.exists());
1729 return factory.createRule(toCreateOrModify);