X-Git-Url: http://secure.phpeclipse.com
diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/PHPDocumentProvider.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/PHPDocumentProvider.java
index 599cd4f..22c26b6 100644
--- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/PHPDocumentProvider.java
+++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/PHPDocumentProvider.java
@@ -9,12 +9,9 @@ http://www.eclipse.org/legal/cpl-v10.html
Contributors:
IBM Corporation - Initial implementation
- Klaus Hartlage - www.eclipseproject.de
+ www.phpeclipse.de
**********************************************************************/
-import java.io.ByteArrayInputStream;
-import java.io.IOException;
-import java.io.InputStream;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
@@ -24,6 +21,7 @@ import net.sourceforge.phpdt.core.IProblemRequestor;
import net.sourceforge.phpdt.core.JavaCore;
import net.sourceforge.phpdt.core.JavaModelException;
import net.sourceforge.phpdt.core.compiler.IProblem;
+import net.sourceforge.phpdt.internal.ui.text.IPHPPartitions;
import net.sourceforge.phpdt.internal.ui.text.java.IProblemRequestorExtension;
import net.sourceforge.phpdt.internal.ui.text.spelling.SpellReconcileStrategy.SpellProblem;
import net.sourceforge.phpdt.ui.PreferenceConstants;
@@ -36,8 +34,6 @@ import org.eclipse.core.resources.IResourceRuleFactory;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.jobs.ISchedulingRule;
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.jface.text.Assert;
@@ -67,113 +63,115 @@ import org.eclipse.swt.widgets.Canvas;
import org.eclipse.swt.widgets.Display;
import org.eclipse.ui.IFileEditorInput;
import org.eclipse.ui.editors.text.EditorsUI;
+import org.eclipse.ui.editors.text.ForwardingDocumentProvider;
import org.eclipse.ui.editors.text.TextFileDocumentProvider;
import org.eclipse.ui.texteditor.AbstractMarkerAnnotationModel;
import org.eclipse.ui.texteditor.AnnotationPreference;
import org.eclipse.ui.texteditor.AnnotationPreferenceLookup;
+import org.eclipse.ui.texteditor.IDocumentProvider;
import org.eclipse.ui.texteditor.MarkerAnnotation;
import org.eclipse.ui.texteditor.MarkerUtilities;
import org.eclipse.ui.texteditor.ResourceMarkerAnnotationModel;
-/**
+/**
* The PHPDocumentProvider provides the IDocuments used by java editors.
*/
-public class PHPDocumentProvider extends TextFileDocumentProvider {
+public class PHPDocumentProvider extends TextFileDocumentProvider implements ICompilationUnitDocumentProvider {
/**
* Here for visibility issues only.
*/
/**
- * Bundle of all required informations to allow working copy management.
+ * Bundle of all required informations to allow working copy management.
*/
/**
- * Bundle of all required informations to allow working copy management.
+ * Bundle of all required informations to allow working copy management.
*/
static protected class CompilationUnitInfo extends FileInfo {
public ICompilationUnit fCopy;
}
-
+
/**
* Annotation model dealing with java marker annotations and temporary problems.
* Also acts as problem requestor for its compilation unit. Initialiy inactive. Must explicitly be
* activated.
*/
protected static class CompilationUnitAnnotationModel extends ResourceMarkerAnnotationModel implements IProblemRequestor, IProblemRequestorExtension {
-
+
private static class ProblemRequestorState {
boolean fInsideReportingSequence= false;
List fReportedProblems;
}
-
+
private ThreadLocal fProblemRequestorState= new ThreadLocal();
private int fStateCount= 0;
-
+
private ICompilationUnit fCompilationUnit;
private List fGeneratedAnnotations;
private IProgressMonitor fProgressMonitor;
private boolean fIsActive= false;
-
+
private ReverseMap fReverseMap= new ReverseMap();
- private List fPreviouslyOverlaid= null;
+ private List fPreviouslyOverlaid= null;
private List fCurrentlyOverlaid= new ArrayList();
-
+
public CompilationUnitAnnotationModel(IResource resource) {
super(resource);
}
-
+
public void setCompilationUnit(ICompilationUnit unit) {
fCompilationUnit= unit;
}
-
+
protected MarkerAnnotation createMarkerAnnotation(IMarker marker) {
String markerType= MarkerUtilities.getMarkerType(marker);
if (markerType != null && markerType.startsWith(JavaMarkerAnnotation.JAVA_MARKER_TYPE_PREFIX))
return new JavaMarkerAnnotation(marker);
return super.createMarkerAnnotation(marker);
}
-
+
/*
* @see org.eclipse.jface.text.source.AnnotationModel#createAnnotationModelEvent()
*/
protected AnnotationModelEvent createAnnotationModelEvent() {
return new CompilationUnitAnnotationModelEvent(this, getResource());
}
-
+
protected Position createPositionFromProblem(IProblem problem) {
int start= problem.getSourceStart();
if (start < 0)
return null;
-
+
int length= problem.getSourceEnd() - problem.getSourceStart() + 1;
if (length < 0)
return null;
-
+
return new Position(start, length);
}
-
+
/*
* @see IProblemRequestor#beginReporting()
*/
public void beginReporting() {
ProblemRequestorState state= (ProblemRequestorState) fProblemRequestorState.get();
if (state == null)
- internalBeginReporting(false);
+ internalBeginReporting(false);
}
-
+
/*
- * @see org.eclipse.jdt.internal.ui.text.java.IProblemRequestorExtension#beginReportingSequence()
+ * @see net.sourceforge.phpdt.internal.ui.text.java.IProblemRequestorExtension#beginReportingSequence()
*/
public void beginReportingSequence() {
ProblemRequestorState state= (ProblemRequestorState) fProblemRequestorState.get();
if (state == null)
internalBeginReporting(true);
}
-
+
/**
* Sets up the infrastructure necessary for problem reporting.
- *
+ *
* @param insideReportingSequence true
if this method
* call is issued from inside a reporting sequence
*/
@@ -200,7 +198,7 @@ public class PHPDocumentProvider extends TextFileDocumentProvider {
state.fReportedProblems.add(problem);
}
}
-
+
/*
* @see IProblemRequestor#endReporting()
*/
@@ -209,16 +207,16 @@ public class PHPDocumentProvider extends TextFileDocumentProvider {
if (state != null && !state.fInsideReportingSequence)
internalEndReporting(state);
}
-
+
/*
- * @see org.eclipse.jdt.internal.ui.text.java.IProblemRequestorExtension#endReportingSequence()
+ * @see net.sourceforge.phpdt.internal.ui.text.java.IProblemRequestorExtension#endReportingSequence()
*/
public void endReportingSequence() {
ProblemRequestorState state= (ProblemRequestorState) fProblemRequestorState.get();
if (state != null && state.fInsideReportingSequence)
internalEndReporting(state);
}
-
+
private void internalEndReporting(ProblemRequestorState state) {
int stateCount= 0;
synchronized(getLockObject()) {
@@ -226,53 +224,53 @@ public class PHPDocumentProvider extends TextFileDocumentProvider {
stateCount= fStateCount;
fProblemRequestorState.set(null);
}
-
+
if (stateCount == 0 && isActive())
reportProblems(state.fReportedProblems);
}
-
+
/**
* Signals the end of problem reporting.
*/
private void reportProblems(List reportedProblems) {
if (fProgressMonitor != null && fProgressMonitor.isCanceled())
return;
-
+
boolean temporaryProblemsChanged= false;
-
+
synchronized (getLockObject()) {
-
+
boolean isCanceled= false;
fPreviouslyOverlaid= fCurrentlyOverlaid;
fCurrentlyOverlaid= new ArrayList();
if (fGeneratedAnnotations.size() > 0) {
- temporaryProblemsChanged= true;
+ temporaryProblemsChanged= true;
removeAnnotations(fGeneratedAnnotations, false, true);
fGeneratedAnnotations.clear();
}
-
+
if (reportedProblems != null && reportedProblems.size() > 0) {
-
+
Iterator e= reportedProblems.iterator();
while (e.hasNext()) {
-
+
if (fProgressMonitor != null && fProgressMonitor.isCanceled()) {
isCanceled= true;
break;
}
-
+
IProblem problem= (IProblem) e.next();
Position position= createPositionFromProblem(problem);
if (position != null) {
-
+
try {
ProblemAnnotation annotation= new ProblemAnnotation(problem, fCompilationUnit);
- overlayMarkers(position, annotation);
+ overlayMarkers(position, annotation);
addAnnotation(annotation, position, false);
fGeneratedAnnotations.add(annotation);
-
+
temporaryProblemsChanged= true;
} catch (BadLocationException x) {
// ignore invalid position
@@ -280,11 +278,11 @@ public class PHPDocumentProvider extends TextFileDocumentProvider {
}
}
}
-
+
removeMarkerOverlays(isCanceled);
fPreviouslyOverlaid= null;
}
-
+
if (temporaryProblemsChanged)
fireModelChanged();
}
@@ -298,9 +296,9 @@ public class PHPDocumentProvider extends TextFileDocumentProvider {
JavaMarkerAnnotation annotation= (JavaMarkerAnnotation) e.next();
annotation.setOverlay(null);
}
- }
+ }
}
-
+
/**
* Overlays value with problem annotation.
* @param problemAnnotation
@@ -316,7 +314,7 @@ public class PHPDocumentProvider extends TextFileDocumentProvider {
} else {
}
}
-
+
private void overlayMarkers(Position position, ProblemAnnotation problemAnnotation) {
Object value= getAnnotations(position);
if (value instanceof List) {
@@ -327,14 +325,14 @@ public class PHPDocumentProvider extends TextFileDocumentProvider {
setOverlay(value, problemAnnotation);
}
}
-
+
/**
* Tells this annotation model to collect temporary problems from now on.
*/
private void startCollectingProblems() {
- fGeneratedAnnotations= new ArrayList();
+ fGeneratedAnnotations= new ArrayList();
}
-
+
/**
* Tells this annotation model to no longer collect temporary problems.
*/
@@ -343,21 +341,21 @@ public class PHPDocumentProvider extends TextFileDocumentProvider {
removeAnnotations(fGeneratedAnnotations, true, true);
fGeneratedAnnotations= null;
}
-
+
/*
* @see IProblemRequestor#isActive()
*/
public boolean isActive() {
return fIsActive;
}
-
+
/*
* @see IProblemRequestorExtension#setProgressMonitor(IProgressMonitor)
*/
public void setProgressMonitor(IProgressMonitor monitor) {
fProgressMonitor= monitor;
}
-
+
/*
* @see IProblemRequestorExtension#setIsActive(boolean)
*/
@@ -370,15 +368,15 @@ public class PHPDocumentProvider extends TextFileDocumentProvider {
stopCollectingProblems();
}
}
-
+
private Object getAnnotations(Position position) {
return fReverseMap.get(position);
}
-
+
/*
* @see AnnotationModel#addAnnotation(Annotation, Position, boolean)
*/
- protected void addAnnotation(Annotation annotation, Position position, boolean fireModelChanged) throws BadLocationException {
+ protected void addAnnotation(Annotation annotation, Position position, boolean fireModelChanged) throws BadLocationException {
super.addAnnotation(annotation, position, fireModelChanged);
Object cached= fReverseMap.get(position);
@@ -394,7 +392,7 @@ public class PHPDocumentProvider extends TextFileDocumentProvider {
fReverseMap.put(position, list);
}
}
-
+
/*
* @see AnnotationModel#removeAllAnnotations(boolean)
*/
@@ -402,7 +400,7 @@ public class PHPDocumentProvider extends TextFileDocumentProvider {
super.removeAllAnnotations(fireModelChanged);
fReverseMap.clear();
}
-
+
/*
* @see AnnotationModel#removeAnnotation(Annotation, boolean)
*/
@@ -422,9 +420,9 @@ public class PHPDocumentProvider extends TextFileDocumentProvider {
super.removeAnnotation(annotation, fireModelChanged);
}
}
-
-
-
+
+
+
protected static class GlobalAnnotationModelListener implements IAnnotationModelListener, IAnnotationModelListenerExtension {
private ListenerList fListenerList;
@@ -469,27 +467,27 @@ public class PHPDocumentProvider extends TextFileDocumentProvider {
* Annotation representating an IProblem
.
*/
static protected class ProblemAnnotation extends Annotation implements IJavaAnnotation, IAnnotationPresentation {
-
+
private static final String SPELLING_ANNOTATION_TYPE= "org.eclipse.ui.workbench.texteditor.spelling";
//XXX: To be fully correct these constants should be non-static
- /**
+ /**
* The layer in which task problem annotations are located.
*/
private static final int TASK_LAYER;
- /**
+ /**
* The layer in which info problem annotations are located.
*/
private static final int INFO_LAYER;
- /**
+ /**
* The layer in which warning problem annotations representing are located.
*/
private static final int WARNING_LAYER;
- /**
+ /**
* The layer in which error problem annotations representing are located.
*/
private static final int ERROR_LAYER;
-
+
static {
AnnotationPreferenceLookup lookup= EditorsUI.getAnnotationPreferenceLookup();
TASK_LAYER= computeLayer("org.eclipse.ui.workbench.texteditor.task", lookup); //$NON-NLS-1$
@@ -497,7 +495,7 @@ public class PHPDocumentProvider extends TextFileDocumentProvider {
WARNING_LAYER= computeLayer("net.sourceforge.phpdt.ui.warning", lookup); //$NON-NLS-1$
ERROR_LAYER= computeLayer("net.sourceforge.phpdt.ui.error", lookup); //$NON-NLS-1$
}
-
+
private static int computeLayer(String annotationType, AnnotationPreferenceLookup lookup) {
Annotation annotation= new Annotation(annotationType, false, null);
AnnotationPreference preference= lookup.getAnnotationPreference(annotation);
@@ -510,19 +508,19 @@ public class PHPDocumentProvider extends TextFileDocumentProvider {
// private static Image fgQuickFixImage;
// private static Image fgQuickFixErrorImage;
// private static boolean fgQuickFixImagesInitialized= false;
-
+
private ICompilationUnit fCompilationUnit;
private List fOverlaids;
private IProblem fProblem;
private Image fImage;
private boolean fQuickFixImagesInitialized= false;
private int fLayer= IAnnotationAccessExtension.DEFAULT_LAYER;
-
+
public ProblemAnnotation(IProblem problem, ICompilationUnit cu) {
-
+
fProblem= problem;
fCompilationUnit= cu;
-
+
if (SpellProblem.Spelling == fProblem.getID()) {
setType(SPELLING_ANNOTATION_TYPE);
fLayer= WARNING_LAYER;
@@ -540,14 +538,14 @@ public class PHPDocumentProvider extends TextFileDocumentProvider {
fLayer= INFO_LAYER;
}
}
-
+
/*
* @see org.eclipse.jface.text.source.IAnnotationPresentation#getLayer()
*/
public int getLayer() {
return fLayer;
}
-
+
private void initializeImages() {
// http://bugs.eclipse.org/bugs/show_bug.cgi?id=18936
// if (!fQuickFixImagesInitialized) {
@@ -569,7 +567,7 @@ public class PHPDocumentProvider extends TextFileDocumentProvider {
private boolean indicateQuixFixableProblems() {
return PreferenceConstants.getPreferenceStore().getBoolean(PreferenceConstants.EDITOR_CORRECTION_INDICATION);
}
-
+
/*
* @see Annotation#paint
*/
@@ -585,14 +583,14 @@ public class PHPDocumentProvider extends TextFileDocumentProvider {
initializeImages();
return fImage;
}
-
+
/*
* @see IJavaAnnotation#getMessage()
*/
public String getText() {
return fProblem.getMessage();
}
-
+
/*
* @see IJavaAnnotation#getArguments()
*/
@@ -612,25 +610,25 @@ public class PHPDocumentProvider extends TextFileDocumentProvider {
*/
public boolean isProblem() {
String type= getType();
- return JavaMarkerAnnotation.WARNING_ANNOTATION_TYPE.equals(type) ||
+ return JavaMarkerAnnotation.WARNING_ANNOTATION_TYPE.equals(type) ||
JavaMarkerAnnotation.ERROR_ANNOTATION_TYPE.equals(type) ||
SPELLING_ANNOTATION_TYPE.equals(type);
}
-
+
/*
* @see IJavaAnnotation#hasOverlay()
*/
public boolean hasOverlay() {
return false;
}
-
+
/*
- * @see org.eclipse.jdt.internal.ui.javaeditor.IJavaAnnotation#getOverlay()
+ * @see net.sourceforge.phpdt.internal.ui.javaeditor.IJavaAnnotation#getOverlay()
*/
public IJavaAnnotation getOverlay() {
return null;
}
-
+
/*
* @see IJavaAnnotation#addOverlaid(IJavaAnnotation)
*/
@@ -650,7 +648,7 @@ public class PHPDocumentProvider extends TextFileDocumentProvider {
fOverlaids= null;
}
}
-
+
/*
* @see IJavaAnnotation#getOverlaidIterator()
*/
@@ -659,18 +657,18 @@ public class PHPDocumentProvider extends TextFileDocumentProvider {
return fOverlaids.iterator();
return null;
}
-
+
/*
- * @see org.eclipse.jdt.internal.ui.javaeditor.IJavaAnnotation#getCompilationUnit()
+ * @see net.sourceforge.phpdt.internal.ui.javaeditor.IJavaAnnotation#getCompilationUnit()
*/
public ICompilationUnit getCompilationUnit() {
return fCompilationUnit;
}
}
-
-
+
+
/**
- * Internal structure for mapping positions to some value.
+ * Internal structure for mapping positions to some value.
* The reason for this specific structure is that positions can
* change over time. Thus a lookup is based on value and not
* on hash value.
@@ -836,15 +834,18 @@ public class PHPDocumentProvider extends TextFileDocumentProvider {
private GlobalAnnotationModelListener fGlobalAnnotationModelListener;
public PHPDocumentProvider() {
- setParentDocumentProvider(new TextFileDocumentProvider(new JavaStorageDocumentProvider()));
-
+// IDocumentProvider provider= new TextFileDocumentProvider(new JavaStorageDocumentProvider());
+ IDocumentProvider provider= new TextFileDocumentProvider();
+ provider= new ForwardingDocumentProvider(IPHPPartitions.PHP_PARTITIONING, new JavaDocumentSetupParticipant(), provider);
+ setParentDocumentProvider(provider);
+
+ fGlobalAnnotationModelListener= new GlobalAnnotationModelListener();
fPropertyListener= new IPropertyChangeListener() {
public void propertyChange(PropertyChangeEvent event) {
if (HANDLE_TEMPORARY_PROBLEMS.equals(event.getProperty()))
enableHandlingTemporaryProblems();
}
};
- fGlobalAnnotationModelListener= new GlobalAnnotationModelListener();
PHPeclipsePlugin.getDefault().getPreferenceStore().addPropertyChangeListener(fPropertyListener);
}
@@ -858,7 +859,7 @@ public class PHPDocumentProvider extends TextFileDocumentProvider {
/**
* Creates a compilation unit from the given file.
- *
+ *
* @param file the file from which to create the compilation unit
*/
protected ICompilationUnit createCompilationUnit(IFile file) {
@@ -867,7 +868,7 @@ public class PHPDocumentProvider extends TextFileDocumentProvider {
return (ICompilationUnit) element;
return null;
}
-
+
/*
* @see org.eclipse.ui.editors.text.TextFileDocumentProvider#createEmptyFileInfo()
@@ -1029,93 +1030,92 @@ public class PHPDocumentProvider extends TextFileDocumentProvider {
protected FileInfo createFileInfo(Object element) throws CoreException {
if (!(element instanceof IFileEditorInput))
return null;
-
+
IFileEditorInput input= (IFileEditorInput) element;
ICompilationUnit original= createCompilationUnit(input.getFile());
if (original == null)
return null;
-
+
FileInfo info= super.createFileInfo(element);
if (!(info instanceof CompilationUnitInfo))
return null;
-
+
CompilationUnitInfo cuInfo= (CompilationUnitInfo) info;
setUpSynchronization(cuInfo);
-
+
IProblemRequestor requestor= cuInfo.fModel instanceof IProblemRequestor ? (IProblemRequestor) cuInfo.fModel : null;
original.becomeWorkingCopy(requestor, getProgressMonitor());
cuInfo.fCopy= original;
-
+
if (cuInfo.fModel instanceof CompilationUnitAnnotationModel) {
CompilationUnitAnnotationModel model= (CompilationUnitAnnotationModel) cuInfo.fModel;
model.setCompilationUnit(cuInfo.fCopy);
- }
-
+ }
+
if (cuInfo.fModel != null)
cuInfo.fModel.addAnnotationModelListener(fGlobalAnnotationModelListener);
-
+
if (requestor instanceof IProblemRequestorExtension) {
IProblemRequestorExtension extension= (IProblemRequestorExtension) requestor;
extension.setIsActive(isHandlingTemporaryProblems());
}
-
+
return cuInfo;
}
-
+
private void setUpSynchronization(CompilationUnitInfo cuInfo) {
IDocument document= cuInfo.fTextFileBuffer.getDocument();
IAnnotationModel model= cuInfo.fModel;
-
+
if (document instanceof ISynchronizable && model instanceof ISynchronizable) {
Object lock= ((ISynchronizable) document).getLockObject();
((ISynchronizable) model).setLockObject(lock);
}
}
-
+
/*
* @see org.eclipse.ui.editors.text.TextFileDocumentProvider#disposeFileInfo(java.lang.Object, org.eclipse.ui.editors.text.TextFileDocumentProvider.FileInfo)
*/
protected void disposeFileInfo(Object element, FileInfo info) {
if (info instanceof CompilationUnitInfo) {
CompilationUnitInfo cuInfo= (CompilationUnitInfo) info;
-
+
try {
cuInfo.fCopy.discardWorkingCopy();
} catch (JavaModelException x) {
handleCoreException(x, x.getMessage());
- }
-
+ }
+
if (cuInfo.fModel != null)
cuInfo.fModel.removeAnnotationModelListener(fGlobalAnnotationModelListener);
}
super.disposeFileInfo(element, info);
}
-
+
protected void commitWorkingCopy(IProgressMonitor monitor, Object element, CompilationUnitInfo info, boolean overwrite) throws CoreException {
-
- synchronized (info.fCopy) {
+ synchronized (info.fCopy) {
info.fCopy.reconcile();
}
-
+
IDocument document= info.fTextFileBuffer.getDocument();
IResource resource= info.fCopy.getResource();
-
+
Assert.isTrue(resource instanceof IFile);
if (!resource.exists()) {
// underlying resource has been deleted, just recreate file, ignore the rest
createFileFromDocument(monitor, (IFile) resource, document);
return;
}
-
+
if (fSavePolicy != null)
fSavePolicy.preSave(info.fCopy);
-
+
try {
-
+
fIsAboutToSave= true;
info.fCopy.commitWorkingCopy(overwrite, monitor);
-
+
} catch (CoreException x) {
// inform about the failure
fireElementStateChangeFailed(element);
@@ -1127,32 +1127,59 @@ public class PHPDocumentProvider extends TextFileDocumentProvider {
} finally {
fIsAboutToSave= false;
}
-
+
// If here, the dirty state of the editor will change to "not dirty".
// Thus, the state changing flag will be reset.
if (info.fModel instanceof AbstractMarkerAnnotationModel) {
AbstractMarkerAnnotationModel model= (AbstractMarkerAnnotationModel) info.fModel;
model.updateMarkers(document);
}
-
+
if (fSavePolicy != null) {
ICompilationUnit unit= fSavePolicy.postSave(info.fCopy);
if (unit != null && info.fModel instanceof AbstractMarkerAnnotationModel) {
IResource r= unit.getResource();
IMarker[] markers= r.findMarkers(IMarker.MARKER, true, IResource.DEPTH_ZERO);
if (markers != null && markers.length > 0) {
- AbstractMarkerAnnotationModel model= (AbstractMarkerAnnotationModel) info.fModel;
+ AbstractMarkerAnnotationModel model= (AbstractMarkerAnnotationModel) info.fModel;
for (int i= 0; i < markers.length; i++)
model.updateMarker(document, markers[i], null);
}
}
}
+
}
/*
* @see org.eclipse.ui.editors.text.TextFileDocumentProvider#createSaveOperation(java.lang.Object, org.eclipse.jface.text.IDocument, boolean)
*/
protected DocumentProviderOperation createSaveOperation(final Object element, final IDocument document, final boolean overwrite) throws CoreException {
+// final FileInfo info= getFileInfo(element);
+// if (info instanceof CompilationUnitInfo) {
+// return new DocumentProviderOperation() {
+// /*
+// * @see org.eclipse.ui.editors.text.TextFileDocumentProvider.DocumentProviderOperation#execute(org.eclipse.core.runtime.IProgressMonitor)
+// */
+// protected void execute(IProgressMonitor monitor) throws CoreException {
+// commitWorkingCopy(monitor, element, (CompilationUnitInfo) info, overwrite);
+// }
+// /*
+// * @see org.eclipse.ui.editors.text.TextFileDocumentProvider.DocumentProviderOperation#getSchedulingRule()
+// */
+// public ISchedulingRule getSchedulingRule() {
+// if (info.fElement instanceof IFileEditorInput) {
+// IFile file= ((IFileEditorInput) info.fElement).getFile();
+// IResourceRuleFactory ruleFactory= ResourcesPlugin.getWorkspace().getRuleFactory();
+// if (file == null || !file.exists())
+// return ruleFactory.createRule(file);
+// else
+// return ruleFactory.modifyRule(file);
+// } else
+// return null;
+// }
+// };
+// }
+// return null;
final FileInfo info= getFileInfo(element);
if (info instanceof CompilationUnitInfo) {
return new DocumentProviderOperation() {
@@ -1168,11 +1195,7 @@ protected DocumentProviderOperation createSaveOperation(final Object element, fi
public ISchedulingRule getSchedulingRule() {
if (info.fElement instanceof IFileEditorInput) {
IFile file= ((IFileEditorInput) info.fElement).getFile();
- IResourceRuleFactory ruleFactory= ResourcesPlugin.getWorkspace().getRuleFactory();
- if (file == null || !file.exists())
- return ruleFactory.createRule(file);
- else
- return ruleFactory.modifyRule(file);
+ return computeSchedulingRule(file);
} else
return null;
}
@@ -1190,7 +1213,7 @@ protected DocumentProviderOperation createSaveOperation(final Object element, fi
// if (setDocumentContent(document, (IEditorInput) element, getEncoding(element))) {
// initializeDocument(document, (IEditorInput) element);
//
-// //
+// //
// // IDocument document = super.createDocument(element);
// // if (document != null) {
// // IDocumentPartitioner partitioner = null;
@@ -1249,7 +1272,7 @@ protected DocumentProviderOperation createSaveOperation(final Object element, fi
/**
* Creates a line tracker working with the same line delimiters as the document
* of the given element. Assumes the element to be managed by this document provider.
- *
+ *
* @param element the element serving as blue print
* @return a line tracker based on the same line delimiters as the element's document
*/
@@ -1330,56 +1353,56 @@ protected DocumentProviderOperation createSaveOperation(final Object element, fi
// protected void doResetDocument(Object element, IProgressMonitor monitor) throws CoreException {
// if (element == null)
// return;
-//
-// ElementInfo elementInfo= getElementInfo(element);
+//
+// ElementInfo elementInfo= getElementInfo(element);
// if (elementInfo instanceof CompilationUnitInfo) {
// CompilationUnitInfo info= (CompilationUnitInfo) elementInfo;
-//
+//
// IDocument document;
// IStatus status= null;
-//
+//
// try {
-//
+//
// ICompilationUnit original= (ICompilationUnit) info.fCopy.getOriginalElement();
// IResource resource= original.getResource();
// if (resource instanceof IFile) {
-//
+//
// IFile file= (IFile) resource;
-//
+//
// try {
// refreshFile(file, monitor);
// } catch (CoreException x) {
// handleCoreException(x, PHPEditorMessages.getString("CompilationUnitDocumentProvider.error.resetDocument")); //$NON-NLS-1$
// }
-//
+//
// IFileEditorInput input= new FileEditorInput(file);
// document= super.createDocument(input);
-//
+//
// } else {
// document= createEmptyDocument();
// }
-//
+//
// } catch (CoreException x) {
// document= createEmptyDocument();
// status= x.getStatus();
// }
-//
+//
// fireElementContentAboutToBeReplaced(element);
-//
+//
// removeUnchangedElementListeners(element, info);
// info.fDocument.set(document.get());
// info.fCanBeSaved= false;
// info.fStatus= status;
// addUnchangedElementListeners(element, info);
-//
+//
// fireElementContentReplaced(element);
// fireElementDirtyStateChanged(element, false);
-//
+//
// } else {
// super.doResetDocument(element, monitor);
// }
// }
-
+
/*
* @see AbstractDocumentProvider#resetDocument(Object)
*/
@@ -1438,7 +1461,7 @@ protected DocumentProviderOperation createSaveOperation(final Object element, fi
/**
* Saves the content of the given document to the given element.
* This is only performed when this provider initiated the save.
- *
+ *
* @param monitor the progress monitor
* @param element the element to which to save
* @param document the document to save
@@ -1446,44 +1469,46 @@ protected DocumentProviderOperation createSaveOperation(final Object element, fi
*/
public void saveDocumentContent(IProgressMonitor monitor, Object element, IDocument document, boolean overwrite)
throws CoreException {
-
- if (!fIsAboutToSave)
- return;
-
- if (element instanceof IFileEditorInput) {
- IFileEditorInput input = (IFileEditorInput) element;
- try {
- String encoding = getEncoding(element);
- if (encoding == null)
- encoding = ResourcesPlugin.getEncoding();
- InputStream stream = new ByteArrayInputStream(document.get().getBytes(encoding));
- IFile file = input.getFile();
- file.setContents(stream, overwrite, true, monitor);
- } catch (IOException x) {
- IStatus s = new Status(IStatus.ERROR, PHPeclipsePlugin.PLUGIN_ID, IStatus.OK, x.getMessage(), x);
- throw new CoreException(s);
- }
- }
+ if (!fIsAboutToSave)
+ return;
+ super.saveDocument(monitor, element, document, overwrite);
+// if (!fIsAboutToSave)
+// return;
+//
+// if (element instanceof IFileEditorInput) {
+// IFileEditorInput input = (IFileEditorInput) element;
+// try {
+// String encoding = getEncoding(element);
+// if (encoding == null)
+// encoding = ResourcesPlugin.getEncoding();
+// InputStream stream = new ByteArrayInputStream(document.get().getBytes(encoding));
+// IFile file = input.getFile();
+// file.setContents(stream, overwrite, true, monitor);
+// } catch (IOException x) {
+// IStatus s = new Status(IStatus.ERROR, PHPeclipsePlugin.PLUGIN_ID, IStatus.OK, x.getMessage(), x);
+// throw new CoreException(s);
+// }
+// }
}
/**
* Returns the underlying resource for the given element.
- *
+ *
* @param the element
* @return the underlying resource of the given element
*/
- public IResource getUnderlyingResource(Object element) {
- if (element instanceof IFileEditorInput) {
- IFileEditorInput input = (IFileEditorInput) element;
- return input.getFile();
- }
- return null;
- }
+// public IResource getUnderlyingResource(Object element) {
+// if (element instanceof IFileEditorInput) {
+// IFileEditorInput input = (IFileEditorInput) element;
+// return input.getFile();
+// }
+// return null;
+// }
/*
- * @see org.eclipse.jdt.internal.ui.javaeditor.ICompilationUnitDocumentProvider#getWorkingCopy(java.lang.Object)
+ * @see net.sourceforge.phpdt.internal.ui.javaeditor.ICompilationUnitDocumentProvider#getWorkingCopy(java.lang.Object)
*/
public ICompilationUnit getWorkingCopy(Object element) {
- FileInfo fileInfo= getFileInfo(element);
+ FileInfo fileInfo= getFileInfo(element);
if (fileInfo instanceof CompilationUnitInfo) {
CompilationUnitInfo info= (CompilationUnitInfo) fileInfo;
return info.fCopy;
@@ -1493,7 +1518,7 @@ protected DocumentProviderOperation createSaveOperation(final Object element, fi
/*
- * @see org.eclipse.jdt.internal.ui.javaeditor.ICompilationUnitDocumentProvider#shutdown()
+ * @see net.sourceforge.phpdt.internal.ui.javaeditor.ICompilationUnitDocumentProvider#shutdown()
*/
public void shutdown() {
PHPeclipsePlugin.getDefault().getPreferenceStore().removePropertyChangeListener(fPropertyListener);
@@ -1538,4 +1563,35 @@ protected DocumentProviderOperation createSaveOperation(final Object element, fi
fGlobalAnnotationModelListener.removeListener(listener);
}
+ /**
+ * Computes the scheduling rule needed to create or modify a resource. If
+ * the resource exists, its modify rule is returned. If it does not, the
+ * resource hierarchy is iterated towards the workspace root to find the
+ * first parent of toCreateOrModify
that exists. Then the
+ * 'create' rule for the last non-existing resource is returned.
+ *
+ * XXX This is a workaround for https://bugs.eclipse.org/bugs/show_bug.cgi?id=67601 + * IResourceRuleFactory.createRule should iterate the hierarchy itself. + *
+ *+ * XXX to be replaced by call to TextFileDocumentProvider.computeSchedulingRule after 3.0 + *
+ * + * @param toCreateOrModify the resource to create or modify + * @return the minimal scheduling rule needed to modify or create a resource + */ + protected ISchedulingRule computeSchedulingRule(IResource toCreateOrModify) { + IResourceRuleFactory factory= ResourcesPlugin.getWorkspace().getRuleFactory(); + if (toCreateOrModify.exists()) { + return factory.modifyRule(toCreateOrModify); + } else { + IResource parent= toCreateOrModify; + do { + toCreateOrModify= parent; + parent= toCreateOrModify.getParent(); + } while (parent != null && !parent.exists()); + + return factory.createRule(toCreateOrModify); + } + } }