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;
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;
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;
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.
*/
}
/*
- * @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();
}
/*
- * @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();
}
/*
- * @see org.eclipse.jdt.internal.ui.javaeditor.IJavaAnnotation#getOverlay()
+ * @see net.sourceforge.phpdt.internal.ui.javaeditor.IJavaAnnotation#getOverlay()
*/
public IJavaAnnotation getOverlay() {
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;
private GlobalAnnotationModelListener fGlobalAnnotationModelListener;
public PHPDocumentProvider() {
- setParentDocumentProvider(new TextFileDocumentProvider(new JavaStorageDocumentProvider()));
+// setParentDocumentProvider(new TextFileDocumentProvider(new JavaStorageDocumentProvider()));
+//
+// fPropertyListener= new IPropertyChangeListener() {
+// public void propertyChange(PropertyChangeEvent event) {
+// if (HANDLE_TEMPORARY_PROBLEMS.equals(event.getProperty()))
+// enableHandlingTemporaryProblems();
+// }
+// };
+// fGlobalAnnotationModelListener= new GlobalAnnotationModelListener();
+// PHPeclipsePlugin.getDefault().getPreferenceStore().addPropertyChangeListener(fPropertyListener);
+ IDocumentProvider provider= new TextFileDocumentProvider(new JavaStorageDocumentProvider());
+ 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);
}
}
protected void commitWorkingCopy(IProgressMonitor monitor, Object element, CompilationUnitInfo info, boolean overwrite) throws CoreException {
-
- synchronized (info.fCopy) {
+ synchronized (info.fCopy) {
info.fCopy.reconcile();
}
}
}
}
+
}
/*
* @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() {
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;
}
*/
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);
/*
- * @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);
public void removeGlobalAnnotationModelListener(IAnnotationModelListener listener) {
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 <code>toCreateOrModify</code> that exists. Then the
+ * 'create' rule for the last non-existing resource is returned.
+ * <p>
+ * XXX This is a workaround for https://bugs.eclipse.org/bugs/show_bug.cgi?id=67601
+ * IResourceRuleFactory.createRule should iterate the hierarchy itself.
+ * </p>
+ * <p>
+ * XXX to be replaced by call to TextFileDocumentProvider.computeSchedulingRule after 3.0
+ * </p>
+ *
+ * @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);
+ }
+ }
}