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;
41 //import org.eclipse.jface.text.Assert;
42 import org.eclipse.core.runtime.Assert;
43 import org.eclipse.jface.text.BadLocationException;
44 import org.eclipse.jface.text.DefaultLineTracker;
45 import org.eclipse.jface.text.Document;
46 import org.eclipse.jface.text.IDocument;
47 import org.eclipse.jface.text.ILineTracker;
48 import org.eclipse.jface.text.ISynchronizable;
49 import org.eclipse.jface.text.Position;
50 import org.eclipse.jface.text.source.Annotation;
51 import org.eclipse.jface.text.source.AnnotationModelEvent;
52 import org.eclipse.jface.text.source.IAnnotationAccessExtension;
53 import org.eclipse.jface.text.source.IAnnotationModel;
54 import org.eclipse.jface.text.source.IAnnotationModelListener;
55 import org.eclipse.jface.text.source.IAnnotationModelListenerExtension;
56 import org.eclipse.jface.text.source.IAnnotationPresentation;
57 import org.eclipse.jface.text.source.ImageUtilities;
58 import org.eclipse.jface.util.IPropertyChangeListener;
60 //import org.eclipse.jface.util.ListenerList;
61 import org.eclipse.core.runtime.ListenerList;
62 import org.eclipse.jface.util.PropertyChangeEvent;
63 import org.eclipse.swt.SWT;
64 import org.eclipse.swt.graphics.GC;
65 import org.eclipse.swt.graphics.Image;
66 import org.eclipse.swt.graphics.Rectangle;
67 import org.eclipse.swt.widgets.Canvas;
68 import org.eclipse.swt.widgets.Display;
69 import org.eclipse.ui.IFileEditorInput;
70 import org.eclipse.ui.editors.text.EditorsUI;
71 import org.eclipse.ui.editors.text.ForwardingDocumentProvider;
72 import org.eclipse.ui.editors.text.TextFileDocumentProvider;
73 import org.eclipse.ui.texteditor.AbstractMarkerAnnotationModel;
74 import org.eclipse.ui.texteditor.AnnotationPreference;
75 import org.eclipse.ui.texteditor.AnnotationPreferenceLookup;
76 import org.eclipse.ui.texteditor.IDocumentProvider;
77 import org.eclipse.ui.texteditor.MarkerAnnotation;
78 import org.eclipse.ui.texteditor.MarkerUtilities;
79 import org.eclipse.ui.texteditor.ResourceMarkerAnnotationModel;
82 * The PHPDocumentProvider provides the IDocuments used by java editors.
85 public class PHPDocumentProvider extends TextFileDocumentProvider implements
86 ICompilationUnitDocumentProvider {
88 * Here for visibility issues only.
92 * Bundle of all required informations to allow working copy management.
95 * Bundle of all required informations to allow working copy management.
97 static protected class CompilationUnitInfo extends FileInfo {
98 public ICompilationUnit fCopy;
102 * Annotation model dealing with java marker annotations and temporary
103 * problems. Also acts as problem requestor for its compilation unit.
104 * Initialiy inactive. Must explicitly be activated.
106 protected static class CompilationUnitAnnotationModel extends
107 ResourceMarkerAnnotationModel implements IProblemRequestor,
108 IProblemRequestorExtension {
110 private static class ProblemRequestorState {
111 boolean fInsideReportingSequence = false;
113 List fReportedProblems;
116 private ThreadLocal fProblemRequestorState = new ThreadLocal();
118 private int fStateCount = 0;
120 private ICompilationUnit fCompilationUnit;
122 private List fGeneratedAnnotations;
124 private IProgressMonitor fProgressMonitor;
126 private boolean fIsActive = false;
128 private ReverseMap fReverseMap = new ReverseMap();
130 private List fPreviouslyOverlaid = null;
132 private List fCurrentlyOverlaid = new ArrayList();
134 public CompilationUnitAnnotationModel(IResource resource) {
138 public void setCompilationUnit(ICompilationUnit unit) {
139 fCompilationUnit = unit;
142 protected MarkerAnnotation createMarkerAnnotation(IMarker marker) {
143 String markerType = MarkerUtilities.getMarkerType(marker);
144 if (markerType != null
146 .startsWith(JavaMarkerAnnotation.JAVA_MARKER_TYPE_PREFIX))
147 return new JavaMarkerAnnotation(marker);
148 return super.createMarkerAnnotation(marker);
152 * @see org.eclipse.jface.text.source.AnnotationModel#createAnnotationModelEvent()
154 protected AnnotationModelEvent createAnnotationModelEvent() {
155 return new CompilationUnitAnnotationModelEvent(this, getResource());
158 protected Position createPositionFromProblem(IProblem problem) {
159 int start = problem.getSourceStart();
163 int length = problem.getSourceEnd() - problem.getSourceStart() + 1;
167 return new Position(start, length);
171 * @see IProblemRequestor#beginReporting()
173 public void beginReporting() {
174 ProblemRequestorState state = (ProblemRequestorState) fProblemRequestorState
177 internalBeginReporting(false);
181 * @see net.sourceforge.phpdt.internal.ui.text.java.IProblemRequestorExtension#beginReportingSequence()
183 public void beginReportingSequence() {
184 ProblemRequestorState state = (ProblemRequestorState) fProblemRequestorState
187 internalBeginReporting(true);
191 * Sets up the infrastructure necessary for problem reporting.
193 * @param insideReportingSequence
194 * <code>true</code> if this method call is issued from
195 * inside a reporting sequence
197 private void internalBeginReporting(boolean insideReportingSequence) {
198 if (fCompilationUnit != null) {
200 // fCompilationUnit.getJavaProject().isOnClasspath(fCompilationUnit))
202 ProblemRequestorState state = new ProblemRequestorState();
203 state.fInsideReportingSequence = insideReportingSequence;
204 state.fReportedProblems = new ArrayList();
205 synchronized (getLockObject()) {
206 fProblemRequestorState.set(state);
213 * @see IProblemRequestor#acceptProblem(IProblem)
215 public void acceptProblem(IProblem problem) {
217 ProblemRequestorState state = (ProblemRequestorState) fProblemRequestorState
220 state.fReportedProblems.add(problem);
225 * @see IProblemRequestor#endReporting()
227 public void endReporting() {
228 ProblemRequestorState state = (ProblemRequestorState) fProblemRequestorState
230 if (state != null && !state.fInsideReportingSequence)
231 internalEndReporting(state);
235 * @see net.sourceforge.phpdt.internal.ui.text.java.IProblemRequestorExtension#endReportingSequence()
237 public void endReportingSequence() {
238 ProblemRequestorState state = (ProblemRequestorState) fProblemRequestorState
240 if (state != null && state.fInsideReportingSequence)
241 internalEndReporting(state);
244 private void internalEndReporting(ProblemRequestorState state) {
246 synchronized (getLockObject()) {
248 stateCount = fStateCount;
249 fProblemRequestorState.set(null);
252 if (stateCount == 0 && isActive())
253 reportProblems(state.fReportedProblems);
257 * Signals the end of problem reporting.
259 private void reportProblems(List reportedProblems) {
260 if (fProgressMonitor != null && fProgressMonitor.isCanceled())
263 boolean temporaryProblemsChanged = false;
265 synchronized (getLockObject()) {
267 boolean isCanceled = false;
269 fPreviouslyOverlaid = fCurrentlyOverlaid;
270 fCurrentlyOverlaid = new ArrayList();
272 if (fGeneratedAnnotations.size() > 0) {
273 temporaryProblemsChanged = true;
274 removeAnnotations(fGeneratedAnnotations, false, true);
275 fGeneratedAnnotations.clear();
278 if (reportedProblems != null && reportedProblems.size() > 0) {
280 Iterator e = reportedProblems.iterator();
281 while (e.hasNext()) {
283 if (fProgressMonitor != null
284 && fProgressMonitor.isCanceled()) {
289 IProblem problem = (IProblem) e.next();
290 Position position = createPositionFromProblem(problem);
291 if (position != null) {
294 ProblemAnnotation annotation = new ProblemAnnotation(
295 problem, fCompilationUnit);
296 overlayMarkers(position, annotation);
297 addAnnotation(annotation, position, false);
298 fGeneratedAnnotations.add(annotation);
300 temporaryProblemsChanged = true;
301 } catch (BadLocationException x) {
302 // ignore invalid position
308 removeMarkerOverlays(isCanceled);
309 fPreviouslyOverlaid = null;
312 if (temporaryProblemsChanged)
316 private void removeMarkerOverlays(boolean isCanceled) {
318 fCurrentlyOverlaid.addAll(fPreviouslyOverlaid);
319 } else if (fPreviouslyOverlaid != null) {
320 Iterator e = fPreviouslyOverlaid.iterator();
321 while (e.hasNext()) {
322 JavaMarkerAnnotation annotation = (JavaMarkerAnnotation) e
324 annotation.setOverlay(null);
330 * Overlays value with problem annotation.
332 * @param problemAnnotation
334 private void setOverlay(Object value,
335 ProblemAnnotation problemAnnotation) {
336 if (value instanceof JavaMarkerAnnotation) {
337 JavaMarkerAnnotation annotation = (JavaMarkerAnnotation) value;
338 if (annotation.isProblem()) {
339 annotation.setOverlay(problemAnnotation);
340 fPreviouslyOverlaid.remove(annotation);
341 fCurrentlyOverlaid.add(annotation);
347 private void overlayMarkers(Position position,
348 ProblemAnnotation problemAnnotation) {
349 Object value = getAnnotations(position);
350 if (value instanceof List) {
351 List list = (List) value;
352 for (Iterator e = list.iterator(); e.hasNext();)
353 setOverlay(e.next(), problemAnnotation);
355 setOverlay(value, problemAnnotation);
360 * Tells this annotation model to collect temporary problems from now
363 private void startCollectingProblems() {
364 fGeneratedAnnotations = new ArrayList();
368 * Tells this annotation model to no longer collect temporary problems.
370 private void stopCollectingProblems() {
371 if (fGeneratedAnnotations != null)
372 removeAnnotations(fGeneratedAnnotations, true, true);
373 fGeneratedAnnotations = null;
377 * @see IProblemRequestor#isActive()
379 public boolean isActive() {
384 * @see IProblemRequestorExtension#setProgressMonitor(IProgressMonitor)
386 public void setProgressMonitor(IProgressMonitor monitor) {
387 fProgressMonitor = monitor;
391 * @see IProblemRequestorExtension#setIsActive(boolean)
393 public void setIsActive(boolean isActive) {
394 if (fIsActive != isActive) {
395 fIsActive = isActive;
397 startCollectingProblems();
399 stopCollectingProblems();
403 private Object getAnnotations(Position position) {
404 return fReverseMap.get(position);
408 * @see AnnotationModel#addAnnotation(Annotation, Position, boolean)
410 protected void addAnnotation(Annotation annotation, Position position,
411 boolean fireModelChanged) throws BadLocationException {
412 super.addAnnotation(annotation, position, fireModelChanged);
414 Object cached = fReverseMap.get(position);
416 fReverseMap.put(position, annotation);
417 else if (cached instanceof List) {
418 List list = (List) cached;
419 list.add(annotation);
420 } else if (cached instanceof Annotation) {
421 List list = new ArrayList(2);
423 list.add(annotation);
424 fReverseMap.put(position, list);
429 * @see AnnotationModel#removeAllAnnotations(boolean)
431 protected void removeAllAnnotations(boolean fireModelChanged) {
432 super.removeAllAnnotations(fireModelChanged);
437 * @see AnnotationModel#removeAnnotation(Annotation, boolean)
439 protected void removeAnnotation(Annotation annotation,
440 boolean fireModelChanged) {
441 Position position = getPosition(annotation);
442 Object cached = fReverseMap.get(position);
443 if (cached instanceof List) {
444 List list = (List) cached;
445 list.remove(annotation);
446 if (list.size() == 1) {
447 fReverseMap.put(position, list.get(0));
450 } else if (cached instanceof Annotation) {
451 fReverseMap.remove(position);
453 super.removeAnnotation(annotation, fireModelChanged);
457 protected static class GlobalAnnotationModelListener implements
458 IAnnotationModelListener, IAnnotationModelListenerExtension {
460 private ListenerList fListenerList;
462 public GlobalAnnotationModelListener() {
463 fListenerList = new ListenerList();
466 public void addListener(IAnnotationModelListener listener) {
467 fListenerList.add(listener);
471 * @see IAnnotationModelListenerExtension#modelChanged(AnnotationModelEvent)
473 public void modelChanged(AnnotationModelEvent event) {
474 Object[] listeners = fListenerList.getListeners();
475 for (int i = 0; i < listeners.length; i++) {
476 Object curr = listeners[i];
477 if (curr instanceof IAnnotationModelListenerExtension) {
478 ((IAnnotationModelListenerExtension) curr)
479 .modelChanged(event);
485 * @see IAnnotationModelListener#modelChanged(IAnnotationModel)
487 public void modelChanged(IAnnotationModel model) {
488 Object[] listeners = fListenerList.getListeners();
489 for (int i = 0; i < listeners.length; i++) {
490 ((IAnnotationModelListener) listeners[i]).modelChanged(model);
494 public void removeListener(IAnnotationModelListener listener) {
495 fListenerList.remove(listener);
500 * Annotation representating an <code>IProblem</code>.
502 static public class ProblemAnnotation extends Annotation implements
503 IJavaAnnotation, IAnnotationPresentation {
505 private static final String SPELLING_ANNOTATION_TYPE = "org.eclipse.ui.workbench.texteditor.spelling";
507 // XXX: To be fully correct these constants should be non-static
509 * The layer in which task problem annotations are located.
511 private static final int TASK_LAYER;
514 * The layer in which info problem annotations are located.
516 private static final int INFO_LAYER;
519 * The layer in which warning problem annotations representing are
522 private static final int WARNING_LAYER;
525 * The layer in which error problem annotations representing are
528 private static final int ERROR_LAYER;
531 AnnotationPreferenceLookup lookup = EditorsUI
532 .getAnnotationPreferenceLookup();
533 TASK_LAYER = computeLayer(
534 "org.eclipse.ui.workbench.texteditor.task", lookup); //$NON-NLS-1$
535 INFO_LAYER = computeLayer("net.sourceforge.phpdt.ui.info", lookup); //$NON-NLS-1$
536 WARNING_LAYER = computeLayer(
537 "net.sourceforge.phpdt.ui.warning", lookup); //$NON-NLS-1$
538 ERROR_LAYER = computeLayer("net.sourceforge.phpdt.ui.error", lookup); //$NON-NLS-1$
541 private static int computeLayer(String annotationType,
542 AnnotationPreferenceLookup lookup) {
543 Annotation annotation = new Annotation(annotationType, false, null);
544 AnnotationPreference preference = lookup
545 .getAnnotationPreference(annotation);
546 if (preference != null)
547 return preference.getPresentationLayer() + 1;
549 return IAnnotationAccessExtension.DEFAULT_LAYER + 1;
552 // private static Image fgQuickFixImage;
553 // private static Image fgQuickFixErrorImage;
554 // private static boolean fgQuickFixImagesInitialized= false;
556 private ICompilationUnit fCompilationUnit;
558 private List fOverlaids;
560 private IProblem fProblem;
562 private Image fImage;
564 private boolean fQuickFixImagesInitialized = false;
566 private int fLayer = IAnnotationAccessExtension.DEFAULT_LAYER;
568 public ProblemAnnotation(IProblem problem, ICompilationUnit cu) {
571 fCompilationUnit = cu;
573 if (SpellProblem.Spelling == fProblem.getID()) {
574 setType(SPELLING_ANNOTATION_TYPE);
575 fLayer = WARNING_LAYER;
576 } else if (IProblem.Task == fProblem.getID()) {
577 setType(JavaMarkerAnnotation.TASK_ANNOTATION_TYPE);
579 } else if (fProblem.isWarning()) {
580 setType(JavaMarkerAnnotation.WARNING_ANNOTATION_TYPE);
581 fLayer = WARNING_LAYER;
582 } else if (fProblem.isError()) {
583 setType(JavaMarkerAnnotation.ERROR_ANNOTATION_TYPE);
584 fLayer = ERROR_LAYER;
586 setType(JavaMarkerAnnotation.INFO_ANNOTATION_TYPE);
592 * @see org.eclipse.jface.text.source.IAnnotationPresentation#getLayer()
594 public int getLayer() {
598 private void initializeImages() {
599 // http://bugs.eclipse.org/bugs/show_bug.cgi?id=18936
600 // if (!fQuickFixImagesInitialized) {
601 // if (isProblem() && indicateQuixFixableProblems() &&
602 // JavaCorrectionProcessor.hasCorrections(this)) { // no light bulb
604 // if (!fgQuickFixImagesInitialized) {
606 // JavaPluginImages.get(JavaPluginImages.IMG_OBJS_FIXABLE_PROBLEM);
607 // fgQuickFixErrorImage=
608 // JavaPluginImages.get(JavaPluginImages.IMG_OBJS_FIXABLE_ERROR);
609 // fgQuickFixImagesInitialized= true;
611 // if (JavaMarkerAnnotation.ERROR_ANNOTATION_TYPE.equals(getType()))
612 // fImage= fgQuickFixErrorImage;
614 // fImage= fgQuickFixImage;
616 // fQuickFixImagesInitialized= true;
620 // private boolean indicateQuixFixableProblems() {
621 // return PreferenceConstants.getPreferenceStore().getBoolean(
622 // PreferenceConstants.EDITOR_CORRECTION_INDICATION);
626 * @see Annotation#paint
628 public void paint(GC gc, Canvas canvas, Rectangle r) {
631 ImageUtilities.drawImage(fImage, gc, canvas, r, SWT.CENTER,
636 * @see IJavaAnnotation#getImage(Display)
638 public Image getImage(Display display) {
644 * @see IJavaAnnotation#getMessage()
646 public String getText() {
647 return fProblem.getMessage();
651 * @see IJavaAnnotation#getArguments()
653 public String[] getArguments() {
654 return isProblem() ? fProblem.getArguments() : null;
658 * @see IJavaAnnotation#getId()
661 return fProblem.getID();
665 * @see IJavaAnnotation#isProblem()
667 public boolean isProblem() {
668 String type = getType();
669 return JavaMarkerAnnotation.WARNING_ANNOTATION_TYPE.equals(type)
670 || JavaMarkerAnnotation.ERROR_ANNOTATION_TYPE.equals(type)
671 || SPELLING_ANNOTATION_TYPE.equals(type);
675 * @see IJavaAnnotation#hasOverlay()
677 public boolean hasOverlay() {
682 * @see net.sourceforge.phpdt.internal.ui.javaeditor.IJavaAnnotation#getOverlay()
684 public IJavaAnnotation getOverlay() {
689 * @see IJavaAnnotation#addOverlaid(IJavaAnnotation)
691 public void addOverlaid(IJavaAnnotation annotation) {
692 if (fOverlaids == null)
693 fOverlaids = new ArrayList(1);
694 fOverlaids.add(annotation);
698 * @see IJavaAnnotation#removeOverlaid(IJavaAnnotation)
700 public void removeOverlaid(IJavaAnnotation annotation) {
701 if (fOverlaids != null) {
702 fOverlaids.remove(annotation);
703 if (fOverlaids.size() == 0)
709 * @see IJavaAnnotation#getOverlaidIterator()
711 public Iterator getOverlaidIterator() {
712 if (fOverlaids != null)
713 return fOverlaids.iterator();
718 * @see net.sourceforge.phpdt.internal.ui.javaeditor.IJavaAnnotation#getCompilationUnit()
720 public ICompilationUnit getCompilationUnit() {
721 return fCompilationUnit;
726 * Internal structure for mapping positions to some value. The reason for
727 * this specific structure is that positions can change over time. Thus a
728 * lookup is based on value and not on hash value.
730 protected static class ReverseMap {
738 private int fAnchor = 0;
740 private List fList = new ArrayList(2);
742 public ReverseMap() {
745 public void clear() {
749 public Object get(Position position) {
754 int length = fList.size();
755 for (int i = fAnchor; i < length; i++) {
756 entry = (Entry) fList.get(i);
757 if (entry.fPosition.equals(position)) {
764 for (int i = 0; i < fAnchor; i++) {
765 entry = (Entry) fList.get(i);
766 if (entry.fPosition.equals(position)) {
775 private int getIndex(Position position) {
777 int length = fList.size();
778 for (int i = 0; i < length; i++) {
779 entry = (Entry) fList.get(i);
780 if (entry.fPosition.equals(position))
786 public void put(Position position, Object value) {
787 int index = getIndex(position);
789 Entry entry = new Entry();
790 entry.fPosition = position;
791 entry.fValue = value;
794 Entry entry = (Entry) fList.get(index);
795 entry.fValue = value;
799 public void remove(Position position) {
800 int index = getIndex(position);
807 * Document that can also be used by a background reconciler.
809 protected static class PartiallySynchronizedDocument extends Document {
812 * @see IDocumentExtension#startSequentialRewrite(boolean)
814 synchronized public void startSequentialRewrite(boolean normalized) {
815 super.startSequentialRewrite(normalized);
819 * @see IDocumentExtension#stopSequentialRewrite()
821 synchronized public void stopSequentialRewrite() {
822 super.stopSequentialRewrite();
826 * @see IDocument#get()
828 synchronized public String get() {
833 * @see IDocument#get(int, int)
835 synchronized public String get(int offset, int length)
836 throws BadLocationException {
837 return super.get(offset, length);
841 * @see IDocument#getChar(int)
843 synchronized public char getChar(int offset)
844 throws BadLocationException {
845 return super.getChar(offset);
849 * @see IDocument#replace(int, int, String)
851 synchronized public void replace(int offset, int length, String text)
852 throws BadLocationException {
853 super.replace(offset, length, text);
857 * @see IDocument#set(String)
859 synchronized public void set(String text) {
865 // private static PHPPartitionScanner HTML_PARTITION_SCANNER = null;
867 // private static PHPPartitionScanner PHP_PARTITION_SCANNER = null;
868 // private static PHPPartitionScanner SMARTY_PARTITION_SCANNER = null;
870 // // private final static String[] TYPES= new String[] {
871 // PHPPartitionScanner.PHP, PHPPartitionScanner.JAVA_DOC,
872 // PHPPartitionScanner.JAVA_MULTILINE_COMMENT };
873 // private final static String[] TYPES =
875 // IPHPPartitionScannerConstants.PHP,
876 // IPHPPartitionScannerConstants.PHP_MULTILINE_COMMENT,
877 // IPHPPartitionScannerConstants.HTML,
878 // IPHPPartitionScannerConstants.HTML_MULTILINE_COMMENT,
879 // IPHPPartitionScannerConstants.JAVASCRIPT,
880 // IPHPPartitionScannerConstants.CSS,
881 // IPHPPartitionScannerConstants.SMARTY,
882 // IPHPPartitionScannerConstants.SMARTY_MULTILINE_COMMENT };
883 // private static PHPPartitionScanner XML_PARTITION_SCANNER = null;
885 /* Preference key for temporary problems */
886 private final static String HANDLE_TEMPORARY_PROBLEMS = PreferenceConstants.EDITOR_EVALUTE_TEMPORARY_PROBLEMS;
888 /** Indicates whether the save has been initialized by this provider */
889 private boolean fIsAboutToSave = false;
891 /** The save policy used by this provider */
892 private ISavePolicy fSavePolicy;
894 /** Internal property changed listener */
895 private IPropertyChangeListener fPropertyListener;
897 /** annotation model listener added to all created CU annotation models */
898 private GlobalAnnotationModelListener fGlobalAnnotationModelListener;
900 public PHPDocumentProvider() {
901 // IDocumentProvider provider= new TextFileDocumentProvider(new
902 // JavaStorageDocumentProvider());
903 IDocumentProvider provider = new TextFileDocumentProvider();
904 provider = new ForwardingDocumentProvider(
905 IPHPPartitions.PHP_PARTITIONING,
906 new JavaDocumentSetupParticipant(), provider);
907 setParentDocumentProvider(provider);
909 fGlobalAnnotationModelListener = new GlobalAnnotationModelListener();
910 fPropertyListener = new IPropertyChangeListener() {
911 public void propertyChange(PropertyChangeEvent event) {
912 if (HANDLE_TEMPORARY_PROBLEMS.equals(event.getProperty()))
913 enableHandlingTemporaryProblems();
916 WebUI.getDefault().getPreferenceStore()
917 .addPropertyChangeListener(fPropertyListener);
922 * Sets the document provider's save policy.
924 public void setSavePolicy(ISavePolicy savePolicy) {
925 fSavePolicy = savePolicy;
929 * Creates a compilation unit from the given file.
932 * the file from which to create the compilation unit
934 protected ICompilationUnit createCompilationUnit(IFile file) {
935 Object element = JavaCore.create(file);
936 if (element instanceof ICompilationUnit)
937 return (ICompilationUnit) element;
942 * @see org.eclipse.ui.editors.text.TextFileDocumentProvider#createEmptyFileInfo()
944 protected FileInfo createEmptyFileInfo() {
945 return new CompilationUnitInfo();
949 * @see org.eclipse.ui.editors.text.TextFileDocumentProvider#createAnnotationModel(org.eclipse.core.resources.IFile)
951 protected IAnnotationModel createAnnotationModel(IFile file) {
952 return new CompilationUnitAnnotationModel(file);
956 * @see AbstractDocumentProvider#createElementInfo(Object)
958 // protected ElementInfo createElementInfo(Object element) throws
961 // if (!(element instanceof IFileEditorInput))
962 // return super.createElementInfo(element);
964 // IFileEditorInput input = (IFileEditorInput) element;
965 // ICompilationUnit original = createCompilationUnit(input.getFile());
966 // if (original != null) {
971 // refreshFile(input.getFile());
972 // } catch (CoreException x) {
973 // handleCoreException(x,
974 // PHPEditorMessages.getString("PHPDocumentProvider.error.createElementInfo"));
978 // IAnnotationModel m = createCompilationUnitAnnotationModel(input);
979 // IProblemRequestor r = m instanceof IProblemRequestor ?
980 // (IProblemRequestor) m : null;
981 // ICompilationUnit c = (ICompilationUnit)
982 // original.getSharedWorkingCopy(getProgressMonitor(), fBufferFactory, r);
984 // DocumentAdapter a = null;
986 // a = (DocumentAdapter) c.getBuffer();
987 // } catch (ClassCastException x) {
988 // IStatus status = new Status(IStatus.ERROR, PHPeclipsePlugin.PLUGIN_ID,
989 // PHPStatusConstants.TEMPLATE_IO_EXCEPTION, "Shared working copy has wrong
990 // buffer", x); //$NON-NLS-1$
991 // throw new CoreException(status);
994 // _FileSynchronizer f = new _FileSynchronizer(input);
997 // CompilationUnitInfo info = new CompilationUnitInfo(a.getDocument(), m, f,
999 // info.setModificationStamp(computeModificationStamp(input.getFile()));
1000 // info.fStatus = a.getStatus();
1001 // info.fEncoding = getPersistedEncoding(input);
1003 // if (r instanceof IProblemRequestorExtension) {
1004 // IProblemRequestorExtension extension = (IProblemRequestorExtension) r;
1005 // extension.setIsActive(isHandlingTemporaryProblems());
1007 // m.addAnnotationModelListener(fGlobalAnnotationModelListener);
1011 // } catch (JavaModelException x) {
1012 // throw new CoreException(x.getStatus());
1015 // return super.createElementInfo(element);
1019 * @see AbstractDocumentProvider#disposeElementInfo(Object, ElementInfo)
1021 // protected void disposeElementInfo(Object element, ElementInfo info) {
1023 // if (info instanceof CompilationUnitInfo) {
1024 // CompilationUnitInfo cuInfo = (CompilationUnitInfo) info;
1025 // cuInfo.fCopy.destroy();
1026 // cuInfo.fModel.removeAnnotationModelListener(fGlobalAnnotationModelListener);
1029 // super.disposeElementInfo(element, info);
1032 * @see AbstractDocumentProvider#doSaveDocument(IProgressMonitor, Object,
1033 * IDocument, boolean)
1035 // protected void doSaveDocument(IProgressMonitor monitor, Object element,
1036 // IDocument document, boolean overwrite)
1037 // throws CoreException {
1039 // ElementInfo elementInfo = getElementInfo(element);
1040 // if (elementInfo instanceof CompilationUnitInfo) {
1041 // CompilationUnitInfo info = (CompilationUnitInfo) elementInfo;
1043 // // update structure, assumes lock on info.fCopy
1044 // info.fCopy.reconcile();
1046 // ICompilationUnit original = (ICompilationUnit)
1047 // info.fCopy.getOriginalElement();
1048 // IResource resource = original.getResource();
1050 // if (resource == null) {
1051 // // underlying resource has been deleted, just recreate file, ignore the
1053 // super.doSaveDocument(monitor, element, document, overwrite);
1057 // if (resource != null && !overwrite)
1058 // checkSynchronizationState(info.fModificationStamp, resource);
1060 // if (fSavePolicy != null)
1061 // fSavePolicy.preSave(info.fCopy);
1063 // // inform about the upcoming content change
1064 // fireElementStateChanging(element);
1066 // fIsAboutToSave = true;
1067 // // commit working copy
1068 // info.fCopy.commit(overwrite, monitor);
1069 // } catch (CoreException x) {
1070 // // inform about the failure
1071 // fireElementStateChangeFailed(element);
1073 // } catch (RuntimeException x) {
1074 // // inform about the failure
1075 // fireElementStateChangeFailed(element);
1078 // fIsAboutToSave = false;
1081 // // If here, the dirty state of the editor will change to "not dirty".
1082 // // Thus, the state changing flag will be reset.
1084 // AbstractMarkerAnnotationModel model = (AbstractMarkerAnnotationModel)
1086 // model.updateMarkers(info.fDocument);
1088 // if (resource != null)
1089 // info.setModificationStamp(computeModificationStamp(resource));
1091 // if (fSavePolicy != null) {
1092 // ICompilationUnit unit = fSavePolicy.postSave(original);
1093 // if (unit != null) {
1094 // IResource r = unit.getResource();
1095 // IMarker[] markers = r.findMarkers(IMarker.MARKER, true,
1096 // IResource.DEPTH_ZERO);
1097 // if (markers != null && markers.length > 0) {
1098 // for (int i = 0; i < markers.length; i++)
1099 // model.updateMarker(markers[i], info.fDocument, null);
1105 // super.doSaveDocument(monitor, element, document, overwrite);
1109 * @see org.eclipse.ui.editors.text.TextFileDocumentProvider#createFileInfo(java.lang.Object)
1111 protected FileInfo createFileInfo(Object element) throws CoreException {
1112 if (!(element instanceof IFileEditorInput))
1115 IFileEditorInput input = (IFileEditorInput) element;
1116 ICompilationUnit original = createCompilationUnit(input.getFile());
1117 if (original == null)
1120 FileInfo info = super.createFileInfo(element);
1121 if (!(info instanceof CompilationUnitInfo))
1124 CompilationUnitInfo cuInfo = (CompilationUnitInfo) info;
1125 setUpSynchronization(cuInfo);
1127 IProblemRequestor requestor = cuInfo.fModel instanceof IProblemRequestor ? (IProblemRequestor) cuInfo.fModel
1130 original.becomeWorkingCopy(requestor, getProgressMonitor());
1131 cuInfo.fCopy = original;
1133 if (cuInfo.fModel instanceof CompilationUnitAnnotationModel) {
1134 CompilationUnitAnnotationModel model = (CompilationUnitAnnotationModel) cuInfo.fModel;
1135 model.setCompilationUnit(cuInfo.fCopy);
1138 if (cuInfo.fModel != null)
1140 .addAnnotationModelListener(fGlobalAnnotationModelListener);
1142 if (requestor instanceof IProblemRequestorExtension) {
1143 IProblemRequestorExtension extension = (IProblemRequestorExtension) requestor;
1144 extension.setIsActive(isHandlingTemporaryProblems());
1150 private void setUpSynchronization(CompilationUnitInfo cuInfo) {
1151 IDocument document = cuInfo.fTextFileBuffer.getDocument();
1152 IAnnotationModel model = cuInfo.fModel;
1154 if (document instanceof ISynchronizable
1155 && model instanceof ISynchronizable) {
1156 Object lock = ((ISynchronizable) document).getLockObject();
1157 ((ISynchronizable) model).setLockObject(lock);
1162 * @see org.eclipse.ui.editors.text.TextFileDocumentProvider#disposeFileInfo(java.lang.Object,
1163 * org.eclipse.ui.editors.text.TextFileDocumentProvider.FileInfo)
1165 protected void disposeFileInfo(Object element, FileInfo info) {
1166 if (info instanceof CompilationUnitInfo) {
1167 CompilationUnitInfo cuInfo = (CompilationUnitInfo) info;
1170 cuInfo.fCopy.discardWorkingCopy();
1171 } catch (JavaModelException x) {
1172 handleCoreException(x, x.getMessage());
1175 if (cuInfo.fModel != null)
1177 .removeAnnotationModelListener(fGlobalAnnotationModelListener);
1179 super.disposeFileInfo(element, info);
1182 protected void commitWorkingCopy(IProgressMonitor monitor, Object element,
1183 CompilationUnitInfo info, boolean overwrite) throws CoreException {
1184 synchronized (info.fCopy) {
1185 info.fCopy.reconcile();
1188 IDocument document = info.fTextFileBuffer.getDocument();
1189 IResource resource = info.fCopy.getResource();
1191 Assert.isTrue(resource instanceof IFile);
1192 if (!resource.exists()) {
1193 // underlying resource has been deleted, just recreate file, ignore
1195 createFileFromDocument(monitor, (IFile) resource, document);
1199 if (fSavePolicy != null)
1200 fSavePolicy.preSave(info.fCopy);
1204 fIsAboutToSave = true;
1205 info.fCopy.commitWorkingCopy(overwrite, monitor);
1207 } catch (CoreException x) {
1208 // inform about the failure
1209 fireElementStateChangeFailed(element);
1211 } catch (RuntimeException x) {
1212 // inform about the failure
1213 fireElementStateChangeFailed(element);
1216 fIsAboutToSave = false;
1219 // If here, the dirty state of the editor will change to "not dirty".
1220 // Thus, the state changing flag will be reset.
1221 if (info.fModel instanceof AbstractMarkerAnnotationModel) {
1222 AbstractMarkerAnnotationModel model = (AbstractMarkerAnnotationModel) info.fModel;
1223 model.updateMarkers(document);
1226 if (fSavePolicy != null) {
1227 ICompilationUnit unit = fSavePolicy.postSave(info.fCopy);
1229 && info.fModel instanceof AbstractMarkerAnnotationModel) {
1230 IResource r = unit.getResource();
1231 IMarker[] markers = r.findMarkers(IMarker.MARKER, true,
1232 IResource.DEPTH_ZERO);
1233 if (markers != null && markers.length > 0) {
1234 AbstractMarkerAnnotationModel model = (AbstractMarkerAnnotationModel) info.fModel;
1235 for (int i = 0; i < markers.length; i++)
1236 model.updateMarker(document, markers[i], null);
1244 * @see org.eclipse.ui.editors.text.TextFileDocumentProvider#createSaveOperation(java.lang.Object,
1245 * org.eclipse.jface.text.IDocument, boolean)
1247 protected DocumentProviderOperation createSaveOperation(
1248 final Object element, final IDocument document,
1249 final boolean overwrite) throws CoreException {
1250 // final FileInfo info= getFileInfo(element);
1251 // if (info instanceof CompilationUnitInfo) {
1252 // return new DocumentProviderOperation() {
1255 // org.eclipse.ui.editors.text.TextFileDocumentProvider.DocumentProviderOperation#execute(org.eclipse.core.runtime.IProgressMonitor)
1257 // protected void execute(IProgressMonitor monitor) throws CoreException
1259 // commitWorkingCopy(monitor, element, (CompilationUnitInfo) info,
1264 // org.eclipse.ui.editors.text.TextFileDocumentProvider.DocumentProviderOperation#getSchedulingRule()
1266 // public ISchedulingRule getSchedulingRule() {
1267 // if (info.fElement instanceof IFileEditorInput) {
1268 // IFile file= ((IFileEditorInput) info.fElement).getFile();
1269 // IResourceRuleFactory ruleFactory=
1270 // ResourcesPlugin.getWorkspace().getRuleFactory();
1271 // if (file == null || !file.exists())
1272 // return ruleFactory.createRule(file);
1274 // return ruleFactory.modifyRule(file);
1281 final FileInfo info = getFileInfo(element);
1282 if (info instanceof CompilationUnitInfo) {
1283 return new DocumentProviderOperation() {
1285 * @see org.eclipse.ui.editors.text.TextFileDocumentProvider.DocumentProviderOperation#execute(org.eclipse.core.runtime.IProgressMonitor)
1287 protected void execute(IProgressMonitor monitor)
1288 throws CoreException {
1289 commitWorkingCopy(monitor, element,
1290 (CompilationUnitInfo) info, overwrite);
1294 * @see org.eclipse.ui.editors.text.TextFileDocumentProvider.DocumentProviderOperation#getSchedulingRule()
1296 public ISchedulingRule getSchedulingRule() {
1297 if (info.fElement instanceof IFileEditorInput) {
1298 IFile file = ((IFileEditorInput) info.fElement)
1300 return computeSchedulingRule(file);
1310 * (non-Javadoc) Method declared on AbstractDocumentProvider
1312 // protected IDocument createDocument(Object element) throws CoreException {
1313 // if (element instanceof IEditorInput) {
1314 // Document document = new PartiallySynchronizedDocument();
1315 // if (setDocumentContent(document, (IEditorInput) element,
1316 // getEncoding(element))) {
1317 // initializeDocument(document, (IEditorInput) element);
1320 // // IDocument document = super.createDocument(element);
1321 // // if (document != null) {
1322 // // IDocumentPartitioner partitioner = null;
1323 // // if (element instanceof FileEditorInput) {
1324 // // IFile file = (IFile) ((FileEditorInput)
1325 // element).getAdapter(IFile.class);
1326 // // String filename = file.getLocation().toString();
1327 // // String extension = filename.substring(filename.lastIndexOf("."),
1328 // filename.length());
1329 // // // System.out.println(extension);
1330 // // if (extension.equalsIgnoreCase(".html") ||
1331 // extension.equalsIgnoreCase(".htm")) {
1333 // // partitioner = createHTMLPartitioner();
1334 // // } else if (extension.equalsIgnoreCase(".xml")) {
1336 // // partitioner = createXMLPartitioner();
1337 // // } else if (extension.equalsIgnoreCase(".js")) {
1339 // // partitioner = createJavaScriptPartitioner();
1340 // // } else if (extension.equalsIgnoreCase(".css")) {
1341 // // // cascading style sheets
1342 // // partitioner = createCSSPartitioner();
1343 // // } else if (extension.equalsIgnoreCase(".tpl")) {
1345 // // partitioner = createSmartyPartitioner();
1346 // // } else if (extension.equalsIgnoreCase(".inc")) {
1347 // // // php include files ?
1348 // // partitioner = createIncludePartitioner();
1352 // // if (partitioner == null) {
1353 // // partitioner = createPHPPartitioner();
1355 // // document.setDocumentPartitioner(partitioner);
1356 // // partitioner.connect(document);
1363 // * Return a partitioner for .html files.
1365 // private IDocumentPartitioner createHTMLPartitioner() {
1366 // return new DefaultPartitioner(getHTMLPartitionScanner(), TYPES);
1369 // private IDocumentPartitioner createIncludePartitioner() {
1370 // return new DefaultPartitioner(getPHPPartitionScanner(), TYPES);
1373 // private IDocumentPartitioner createJavaScriptPartitioner() {
1374 // return new DefaultPartitioner(getHTMLPartitionScanner(), TYPES);
1377 * Creates a line tracker working with the same line delimiters as the
1378 * document of the given element. Assumes the element to be managed by this
1379 * document provider.
1382 * the element serving as blue print
1383 * @return a line tracker based on the same line delimiters as the element's
1386 public ILineTracker createLineTracker(Object element) {
1387 return new DefaultLineTracker();
1391 // * Return a partitioner for .php files.
1393 // private IDocumentPartitioner createPHPPartitioner() {
1394 // return new DefaultPartitioner(getPHPPartitionScanner(), TYPES);
1397 // private IDocumentPartitioner createSmartyPartitioner() {
1398 // return new DefaultPartitioner(getSmartyPartitionScanner(), TYPES);
1401 // private IDocumentPartitioner createXMLPartitioner() {
1402 // return new DefaultPartitioner(getXMLPartitionScanner(), TYPES);
1406 // * Return a scanner for creating html partitions.
1408 // private PHPPartitionScanner getHTMLPartitionScanner() {
1409 // if (HTML_PARTITION_SCANNER == null)
1410 // HTML_PARTITION_SCANNER = new
1411 // PHPPartitionScanner(IPHPPartitionScannerConstants.HTML_FILE);
1412 // return HTML_PARTITION_SCANNER;
1415 // * Return a scanner for creating php partitions.
1417 // private PHPPartitionScanner getPHPPartitionScanner() {
1418 // if (PHP_PARTITION_SCANNER == null)
1419 // PHP_PARTITION_SCANNER = new
1420 // PHPPartitionScanner(IPHPPartitionScannerConstants.PHP_FILE);
1421 // return PHP_PARTITION_SCANNER;
1425 // * Return a scanner for creating smarty partitions.
1427 // private PHPPartitionScanner getSmartyPartitionScanner() {
1428 // if (SMARTY_PARTITION_SCANNER == null)
1429 // SMARTY_PARTITION_SCANNER = new
1430 // PHPPartitionScanner(IPHPPartitionScannerConstants.SMARTY_FILE);
1431 // return SMARTY_PARTITION_SCANNER;
1435 // * Return a scanner for creating xml partitions.
1437 // private PHPPartitionScanner getXMLPartitionScanner() {
1438 // if (XML_PARTITION_SCANNER == null)
1439 // XML_PARTITION_SCANNER = new
1440 // PHPPartitionScanner(IPHPPartitionScannerConstants.XML_FILE);
1441 // return XML_PARTITION_SCANNER;
1444 // protected void initializeDocument(IDocument document, IEditorInput
1446 // if (document != null) {
1447 // JavaTextTools tools = PHPeclipsePlugin.getDefault().getJavaTextTools();
1448 // IDocumentPartitioner partitioner = null;
1449 // if (editorInput != null && editorInput instanceof FileEditorInput) {
1450 // IFile file = (IFile) ((FileEditorInput)
1451 // editorInput).getAdapter(IFile.class);
1452 // String filename = file.getLocation().toString();
1453 // String extension = filename.substring(filename.lastIndexOf("."),
1454 // filename.length());
1455 // partitioner = tools.createDocumentPartitioner(extension);
1457 // partitioner = tools.createDocumentPartitioner(".php");
1459 // document.setDocumentPartitioner(partitioner);
1460 // partitioner.connect(document);
1465 * @see org.eclipse.ui.texteditor.AbstractDocumentProvider#doResetDocument(java.lang.Object,
1466 * org.eclipse.core.runtime.IProgressMonitor)
1468 // protected void doResetDocument(Object element, IProgressMonitor monitor)
1469 // throws CoreException {
1470 // if (element == null)
1473 // ElementInfo elementInfo= getElementInfo(element);
1474 // if (elementInfo instanceof CompilationUnitInfo) {
1475 // CompilationUnitInfo info= (CompilationUnitInfo) elementInfo;
1477 // IDocument document;
1478 // IStatus status= null;
1482 // ICompilationUnit original= (ICompilationUnit)
1483 // info.fCopy.getOriginalElement();
1484 // IResource resource= original.getResource();
1485 // if (resource instanceof IFile) {
1487 // IFile file= (IFile) resource;
1490 // refreshFile(file, monitor);
1491 // } catch (CoreException x) {
1492 // handleCoreException(x,
1493 // PHPEditorMessages.getString("CompilationUnitDocumentProvider.error.resetDocument"));
1497 // IFileEditorInput input= new FileEditorInput(file);
1498 // document= super.createDocument(input);
1501 // document= createEmptyDocument();
1504 // } catch (CoreException x) {
1505 // document= createEmptyDocument();
1506 // status= x.getStatus();
1509 // fireElementContentAboutToBeReplaced(element);
1511 // removeUnchangedElementListeners(element, info);
1512 // info.fDocument.set(document.get());
1513 // info.fCanBeSaved= false;
1514 // info.fStatus= status;
1515 // addUnchangedElementListeners(element, info);
1517 // fireElementContentReplaced(element);
1518 // fireElementDirtyStateChanged(element, false);
1521 // super.doResetDocument(element, monitor);
1525 * @see AbstractDocumentProvider#resetDocument(Object)
1527 // public void resetDocument(Object element) throws CoreException {
1528 // if (element == null)
1531 // ElementInfo elementInfo = getElementInfo(element);
1532 // if (elementInfo instanceof CompilationUnitInfo) {
1533 // CompilationUnitInfo info = (CompilationUnitInfo) elementInfo;
1535 // IDocument document;
1536 // IStatus status = null;
1540 // ICompilationUnit original = (ICompilationUnit)
1541 // info.fCopy.getOriginalElement();
1542 // IResource resource = original.getResource();
1543 // if (resource instanceof IFile) {
1545 // IFile file = (IFile) resource;
1548 // refreshFile(file);
1549 // } catch (CoreException x) {
1550 // handleCoreException(x,
1551 // PHPEditorMessages.getString("PHPDocumentProvider.error.resetDocument"));
1555 // IFileEditorInput input = new FileEditorInput(file);
1556 // document = super.createDocument(input);
1559 // document = new Document();
1562 // } catch (CoreException x) {
1563 // document = new Document();
1564 // status = x.getStatus();
1567 // fireElementContentAboutToBeReplaced(element);
1569 // removeUnchangedElementListeners(element, info);
1570 // info.fDocument.set(document.get());
1571 // info.fCanBeSaved = false;
1572 // info.fStatus = status;
1573 // addUnchangedElementListeners(element, info);
1575 // fireElementContentReplaced(element);
1576 // fireElementDirtyStateChanged(element, false);
1579 // super.resetDocument(element);
1583 * Saves the content of the given document to the given element. This is
1584 * only performed when this provider initiated the save.
1587 * the progress monitor
1589 * the element to which to save
1591 * the document to save
1593 * <code>true</code> if the save should be enforced
1595 public void saveDocumentContent(IProgressMonitor monitor, Object element,
1596 IDocument document, boolean overwrite) throws CoreException {
1597 if (!fIsAboutToSave)
1599 super.saveDocument(monitor, element, document, overwrite);
1600 // if (!fIsAboutToSave)
1603 // if (element instanceof IFileEditorInput) {
1604 // IFileEditorInput input = (IFileEditorInput) element;
1606 // String encoding = getEncoding(element);
1607 // if (encoding == null)
1608 // encoding = ResourcesPlugin.getEncoding();
1609 // InputStream stream = new
1610 // ByteArrayInputStream(document.get().getBytes(encoding));
1611 // IFile file = input.getFile();
1612 // file.setContents(stream, overwrite, true, monitor);
1613 // } catch (IOException x) {
1614 // IStatus s = new Status(IStatus.ERROR, PHPeclipsePlugin.PLUGIN_ID,
1615 // IStatus.OK, x.getMessage(), x);
1616 // throw new CoreException(s);
1622 * Returns the underlying resource for the given element.
1626 * @return the underlying resource of the given element
1628 // public IResource getUnderlyingResource(Object element) {
1629 // if (element instanceof IFileEditorInput) {
1630 // IFileEditorInput input = (IFileEditorInput) element;
1631 // return input.getFile();
1636 * @see net.sourceforge.phpdt.internal.ui.javaeditor.ICompilationUnitDocumentProvider#getWorkingCopy(java.lang.Object)
1638 public ICompilationUnit getWorkingCopy(Object element) {
1639 FileInfo fileInfo = getFileInfo(element);
1640 if (fileInfo instanceof CompilationUnitInfo) {
1641 CompilationUnitInfo info = (CompilationUnitInfo) fileInfo;
1648 * @see net.sourceforge.phpdt.internal.ui.javaeditor.ICompilationUnitDocumentProvider#shutdown()
1650 public void shutdown() {
1651 WebUI.getDefault().getPreferenceStore()
1652 .removePropertyChangeListener(fPropertyListener);
1653 Iterator e = getConnectedElementsIterator();
1655 disconnect(e.next());
1659 * Returns the preference whether handling temporary problems is enabled.
1661 protected boolean isHandlingTemporaryProblems() {
1662 IPreferenceStore store = WebUI.getDefault()
1663 .getPreferenceStore();
1664 return store.getBoolean(HANDLE_TEMPORARY_PROBLEMS);
1668 * Switches the state of problem acceptance according to the value in the
1671 protected void enableHandlingTemporaryProblems() {
1672 boolean enable = isHandlingTemporaryProblems();
1673 for (Iterator iter = getFileInfosIterator(); iter.hasNext();) {
1674 FileInfo info = (FileInfo) iter.next();
1675 if (info.fModel instanceof IProblemRequestorExtension) {
1676 IProblemRequestorExtension extension = (IProblemRequestorExtension) info.fModel;
1677 extension.setIsActive(enable);
1683 * Adds a listener that reports changes from all compilation unit annotation
1686 public void addGlobalAnnotationModelListener(
1687 IAnnotationModelListener listener) {
1688 fGlobalAnnotationModelListener.addListener(listener);
1692 * Removes the listener.
1694 public void removeGlobalAnnotationModelListener(
1695 IAnnotationModelListener listener) {
1696 fGlobalAnnotationModelListener.removeListener(listener);
1700 * Computes the scheduling rule needed to create or modify a resource. If
1701 * the resource exists, its modify rule is returned. If it does not, the
1702 * resource hierarchy is iterated towards the workspace root to find the
1703 * first parent of <code>toCreateOrModify</code> that exists. Then the
1704 * 'create' rule for the last non-existing resource is returned.
1706 * XXX This is a workaround for
1707 * https://bugs.eclipse.org/bugs/show_bug.cgi?id=67601
1708 * IResourceRuleFactory.createRule should iterate the hierarchy itself.
1711 * XXX to be replaced by call to
1712 * TextFileDocumentProvider.computeSchedulingRule after 3.0
1715 * @param toCreateOrModify
1716 * the resource to create or modify
1717 * @return the minimal scheduling rule needed to modify or create a resource
1719 protected ISchedulingRule computeSchedulingRule(IResource toCreateOrModify) {
1720 IResourceRuleFactory factory = ResourcesPlugin.getWorkspace()
1722 if (toCreateOrModify.exists()) {
1723 return factory.modifyRule(toCreateOrModify);
1725 IResource parent = toCreateOrModify;
1727 toCreateOrModify = parent;
1728 parent = toCreateOrModify.getParent();
1729 } while (parent != null && !parent.exists());
1731 return factory.createRule(toCreateOrModify);