X-Git-Url: http://secure.phpeclipse.com diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/PHPEditor.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/PHPEditor.java index c37b2e4..3da3755 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/PHPEditor.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/PHPEditor.java @@ -21,6 +21,7 @@ import java.util.StringTokenizer; import net.sourceforge.phpdt.core.ICompilationUnit; import net.sourceforge.phpdt.core.IJavaElement; +import net.sourceforge.phpdt.core.IJavaProject; import net.sourceforge.phpdt.core.IMember; import net.sourceforge.phpdt.core.ISourceRange; import net.sourceforge.phpdt.core.ISourceReference; @@ -32,6 +33,7 @@ import net.sourceforge.phpdt.internal.ui.text.CustomSourceInformationControl; import net.sourceforge.phpdt.internal.ui.text.HTMLTextPresenter; import net.sourceforge.phpdt.internal.ui.text.IPHPPartitions; import net.sourceforge.phpdt.internal.ui.text.PHPPairMatcher; +import net.sourceforge.phpdt.internal.ui.text.PreferencesAdapter; import net.sourceforge.phpdt.internal.ui.viewsupport.IViewPartInputProvider; import net.sourceforge.phpdt.ui.IContextMenuConstants; import net.sourceforge.phpdt.ui.JavaUI; @@ -87,6 +89,7 @@ import org.eclipse.jface.text.source.SourceViewerConfiguration; import org.eclipse.jface.text.source.projection.ProjectionSupport; import org.eclipse.jface.text.source.projection.ProjectionViewer; import org.eclipse.jface.util.IPropertyChangeListener; +import org.eclipse.jface.util.ListenerList; import org.eclipse.jface.util.PropertyChangeEvent; import org.eclipse.jface.viewers.ISelection; import org.eclipse.jface.viewers.ISelectionChangedListener; @@ -128,9 +131,11 @@ import org.eclipse.ui.IWorkbenchWindow; import org.eclipse.ui.actions.ActionContext; import org.eclipse.ui.actions.ActionGroup; import org.eclipse.ui.editors.text.DefaultEncodingSupport; +import org.eclipse.ui.editors.text.EditorsUI; import org.eclipse.ui.editors.text.IEncodingSupport; import org.eclipse.ui.part.IShowInTargetList; import org.eclipse.ui.texteditor.AbstractDecoratedTextEditor; +import org.eclipse.ui.texteditor.ChainedPreferenceStore; import org.eclipse.ui.texteditor.DefaultRangeIndicator; import org.eclipse.ui.texteditor.IDocumentProvider; import org.eclipse.ui.texteditor.IEditorStatusLine; @@ -186,6 +191,387 @@ public abstract class PHPEditor extends AbstractDecoratedTextEditor implements } }; + /** + * Adapts an options {@link java.util.Map} to {@link org.eclipse.jface.preference.IPreferenceStore}. + *
+ * This preference store is read-only i.e. write access + * throws an {@link java.lang.UnsupportedOperationException}. + *
+ * + * @since 3.0 + */ + private static class OptionsAdapter implements IPreferenceStore { + + + /** + * A property change event filter. + */ + public interface IPropertyChangeEventFilter { + + /** + * Should the given event be filtered? + * @param event The property change event. + * @returntrue
iff the given event should be filtered.
+ */
+ public boolean isFiltered(PropertyChangeEvent event);
+
+ }
+ /**
+ * Property change listener. Listens for events in the options Map and
+ * fires a {@link org.eclipse.jface.util.PropertyChangeEvent}
+ * on this adapter with arguments from the received event.
+ */
+ private class PropertyChangeListener implements IPropertyChangeListener {
+
+ /**
+ * {@inheritDoc}
+ */
+ public void propertyChange(PropertyChangeEvent event) {
+ if (getFilter().isFiltered(event))
+ return;
+
+ if (event.getNewValue() == null)
+ fOptions.remove(event.getProperty());
+ else
+ fOptions.put(event.getProperty(), event.getNewValue());
+
+ firePropertyChangeEvent(event.getProperty(), event.getOldValue(), event.getNewValue());
+ }
+ }
+
+ /** Listeners on this adapter */
+ private ListenerList fListeners= new ListenerList();
+
+ /** Listener on the adapted options Map */
+ private IPropertyChangeListener fListener= new PropertyChangeListener();
+
+ /** Adapted options Map */
+ private Map fOptions;
+
+ /** Preference store through which events are received. */
+ private IPreferenceStore fMockupPreferenceStore;
+
+ /** Property event filter. */
+ private IPropertyChangeEventFilter fFilter;
+
+ /**
+ * Initialize with the given options.
+ *
+ * @param options The options to wrap
+ * @param mockupPreferenceStore the mock-up preference store
+ * @param filter the property change filter
+ */
+ public OptionsAdapter(Map options, IPreferenceStore mockupPreferenceStore, IPropertyChangeEventFilter filter) {
+ fMockupPreferenceStore= mockupPreferenceStore;
+ fOptions= options;
+ setFilter(filter);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void addPropertyChangeListener(IPropertyChangeListener listener) {
+ if (fListeners.size() == 0)
+ fMockupPreferenceStore.addPropertyChangeListener(fListener);
+ fListeners.add(listener);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void removePropertyChangeListener(IPropertyChangeListener listener) {
+ fListeners.remove(listener);
+ if (fListeners.size() == 0)
+ fMockupPreferenceStore.removePropertyChangeListener(fListener);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public boolean contains(String name) {
+ return fOptions.containsKey(name);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void firePropertyChangeEvent(String name, Object oldValue, Object newValue) {
+ PropertyChangeEvent event= new PropertyChangeEvent(this, name, oldValue, newValue);
+ Object[] listeners= fListeners.getListeners();
+ for (int i= 0; i < listeners.length; i++)
+ ((IPropertyChangeListener) listeners[i]).propertyChange(event);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public boolean getBoolean(String name) {
+ boolean value= BOOLEAN_DEFAULT_DEFAULT;
+ String s= (String) fOptions.get(name);
+ if (s != null)
+ value= s.equals(TRUE);
+ return value;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public boolean getDefaultBoolean(String name) {
+ return BOOLEAN_DEFAULT_DEFAULT;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public double getDefaultDouble(String name) {
+ return DOUBLE_DEFAULT_DEFAULT;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public float getDefaultFloat(String name) {
+ return FLOAT_DEFAULT_DEFAULT;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public int getDefaultInt(String name) {
+ return INT_DEFAULT_DEFAULT;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public long getDefaultLong(String name) {
+ return LONG_DEFAULT_DEFAULT;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public String getDefaultString(String name) {
+ return STRING_DEFAULT_DEFAULT;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public double getDouble(String name) {
+ double value= DOUBLE_DEFAULT_DEFAULT;
+ String s= (String) fOptions.get(name);
+ if (s != null) {
+ try {
+ value= new Double(s).doubleValue();
+ } catch (NumberFormatException e) {
+ }
+ }
+ return value;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public float getFloat(String name) {
+ float value= FLOAT_DEFAULT_DEFAULT;
+ String s= (String) fOptions.get(name);
+ if (s != null) {
+ try {
+ value= new Float(s).floatValue();
+ } catch (NumberFormatException e) {
+ }
+ }
+ return value;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public int getInt(String name) {
+ int value= INT_DEFAULT_DEFAULT;
+ String s= (String) fOptions.get(name);
+ if (s != null) {
+ try {
+ value= new Integer(s).intValue();
+ } catch (NumberFormatException e) {
+ }
+ }
+ return value;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public long getLong(String name) {
+ long value= LONG_DEFAULT_DEFAULT;
+ String s= (String) fOptions.get(name);
+ if (s != null) {
+ try {
+ value= new Long(s).longValue();
+ } catch (NumberFormatException e) {
+ }
+ }
+ return value;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public String getString(String name) {
+ String value= (String) fOptions.get(name);
+ if (value == null)
+ value= STRING_DEFAULT_DEFAULT;
+ return value;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public boolean isDefault(String name) {
+ return false;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public boolean needsSaving() {
+ return !fOptions.isEmpty();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void putValue(String name, String value) {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void setDefault(String name, double value) {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void setDefault(String name, float value) {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void setDefault(String name, int value) {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void setDefault(String name, long value) {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void setDefault(String name, String defaultObject) {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void setDefault(String name, boolean value) {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void setToDefault(String name) {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void setValue(String name, double value) {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void setValue(String name, float value) {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void setValue(String name, int value) {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void setValue(String name, long value) {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void setValue(String name, String value) {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void setValue(String name, boolean value) {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * Returns the adapted options Map.
+ *
+ * @return Returns the adapted options Map.
+ */
+ public Map getOptions() {
+ return fOptions;
+ }
+
+ /**
+ * Returns the mock-up preference store, events are received through this preference store.
+ * @return Returns the mock-up preference store.
+ */
+ public IPreferenceStore getMockupPreferenceStore() {
+ return fMockupPreferenceStore;
+ }
+
+ /**
+ * Set the event filter to the given filter.
+ *
+ * @param filter The new filter.
+ */
+ public void setFilter(IPropertyChangeEventFilter filter) {
+ fFilter= filter;
+ }
+
+ /**
+ * Returns the event filter.
+ *
+ * @return The event filter.
+ */
+ public IPropertyChangeEventFilter getFilter() {
+ return fFilter;
+ }
+ }
/*
* Link mode.
*/
@@ -1215,20 +1601,48 @@ public abstract class PHPEditor extends AbstractDecoratedTextEditor implements
*/
public PHPEditor() {
super();
- JavaTextTools textTools= PHPeclipsePlugin.getDefault().getJavaTextTools();
- setSourceViewerConfiguration(new PHPSourceViewerConfiguration(textTools, this)); //, IJavaPartitions.JAVA_PARTITIONING));
- setRangeIndicator(new DefaultRangeIndicator());
- IPreferenceStore store= PHPeclipsePlugin.getDefault().getPreferenceStore();
- setPreferenceStore(store);
- setKeyBindingScopes(new String[] { "net.sourceforge.phpdt.ui.phpEditorScope" }); //$NON-NLS-1$
-// fMarkOccurrenceAnnotations= store.getBoolean(PreferenceConstants.EDITOR_MARK_OCCURRENCES);
-// fStickyOccurrenceAnnotations= store.getBoolean(PreferenceConstants.EDITOR_STICKY_OCCURRENCES);
-
- // TODO changed in 3.x ?
- if (PreferenceConstants.getPreferenceStore().getBoolean(PreferenceConstants.EDITOR_SYNC_OUTLINE_ON_CURSOR_MOVE))
- fUpdater= new OutlinePageSelectionUpdater();
}
+
+ /*
+ * @see org.eclipse.ui.texteditor.AbstractDecoratedTextEditor#initializeKeyBindingScopes()
+ */
+ protected void initializeKeyBindingScopes() {
+ setKeyBindingScopes(new String[] { "net.sourceforge.phpdt.ui.phpEditorScope" }); //$NON-NLS-1$
+ }
+
+ /*
+ * @see org.eclipse.ui.texteditor.AbstractDecoratedTextEditor#initializeEditor()
+ */
+ protected void initializeEditor() {
+ //jsurfer old code
+ JavaTextTools textTools= PHPeclipsePlugin.getDefault().getJavaTextTools();
+ setSourceViewerConfiguration(new PHPSourceViewerConfiguration(textTools, this)); //, IJavaPartitions.JAVA_PARTITIONING));
+ setRangeIndicator(new DefaultRangeIndicator());
+// IPreferenceStore store= PHPeclipsePlugin.getDefault().getPreferenceStore();
+// setPreferenceStore(store);
+ IPreferenceStore store= createCombinedPreferenceStore(null);
+ setPreferenceStore(store);
+
+ // TODO changed in 3.x ?
+ if (PreferenceConstants.getPreferenceStore().getBoolean(PreferenceConstants.EDITOR_SYNC_OUTLINE_ON_CURSOR_MOVE))
+ fUpdater= new OutlinePageSelectionUpdater();
+ // jsurfer end
+
+// IPreferenceStore store= createCombinedPreferenceStore(null);
+// setPreferenceStore(store);
+// JavaTextTools textTools= PHPeclipsePlugin.getDefault().getJavaTextTools();
+// setSourceViewerConfiguration(new JavaSourceViewerConfiguration(textTools.getColorManager(), store, this, IJavaPartitions.JAVA_PARTITIONING));
+// fMarkOccurrenceAnnotations= store.getBoolean(PreferenceConstants.EDITOR_MARK_OCCURRENCES);
+// fStickyOccurrenceAnnotations= store.getBoolean(PreferenceConstants.EDITOR_STICKY_OCCURRENCES);
+// fMarkTypeOccurrences= store.getBoolean(PreferenceConstants.EDITOR_MARK_TYPE_OCCURRENCES);
+// fMarkMethodOccurrences= store.getBoolean(PreferenceConstants.EDITOR_MARK_METHOD_OCCURRENCES);
+// fMarkConstantOccurrences= store.getBoolean(PreferenceConstants.EDITOR_MARK_CONSTANT_OCCURRENCES);
+// fMarkFieldOccurrences= store.getBoolean(PreferenceConstants.EDITOR_MARK_FIELD_OCCURRENCES);
+// fMarkLocalVariableypeOccurrences= store.getBoolean(PreferenceConstants.EDITOR_MARK_LOCAL_VARIABLE_OCCURRENCES);
+// fMarkExceptionOccurrences= store.getBoolean(PreferenceConstants.EDITOR_MARK_EXCEPTION_OCCURRENCES);
+// fMarkMethodExitPoints= store.getBoolean(PreferenceConstants.EDITOR_MARK_METHOD_EXIT_POINTS);
+ }
/*
* @see org.eclipse.ui.texteditor.AbstractTextEditor#updatePropertyDependentActions()
*/
@@ -1370,7 +1784,7 @@ public abstract class PHPEditor extends AbstractDecoratedTextEditor implements
ResourceAction resAction= new TextOperationAction(PHPEditorMessages.getResourceBundle(), "ShowJavaDoc.", this, ISourceViewer.INFORMATION, true); //$NON-NLS-1$
resAction= new InformationDispatchAction(PHPEditorMessages.getResourceBundle(), "ShowJavaDoc.", (TextOperationAction) resAction); //$NON-NLS-1$
- resAction.setActionDefinitionId(PHPEditorActionDefinitionIds.SHOW_JAVADOC);
+ resAction.setActionDefinitionId(net.sourceforge.phpdt.ui.actions.PHPEditorActionDefinitionIds.SHOW_JAVADOC);
setAction("ShowJavaDoc", resAction); //$NON-NLS-1$
// WorkbenchHelp.setHelp(resAction, IJavaHelpContextIds.SHOW_JAVADOC_ACTION);
@@ -2446,6 +2860,14 @@ public abstract class PHPEditor extends AbstractDecoratedTextEditor implements
//
// }
/**
+ * Returns the Java element wrapped by this editors input.
+ *
+ * @return the Java element wrapped by this editors input.
+ * @since 3.0
+ */
+ abstract protected IJavaElement getInputJavaElement();
+
+ /**
* Jumps to the matching bracket.
*/
public void gotoMatchingBracket() {
@@ -2670,6 +3092,38 @@ public abstract class PHPEditor extends AbstractDecoratedTextEditor implements
return viewer;
}
+ /**
+ * Creates and returns the preference store for this Java editor with the given input.
+ *
+ * @param input The editor input for which to create the preference store
+ * @return the preference store for this editor
+ *
+ * @since 3.0
+ */
+ private IPreferenceStore createCombinedPreferenceStore(IEditorInput input) {
+ List stores= new ArrayList(3);
+
+ IJavaProject project= EditorUtility.getJavaProject(input);
+ if (project != null)
+ stores.add(new OptionsAdapter(project.getOptions(false), PHPeclipsePlugin.getDefault().getMockupPreferenceStore(), new OptionsAdapter.IPropertyChangeEventFilter() {
+
+ public boolean isFiltered(PropertyChangeEvent event) {
+ IJavaElement inputJavaElement= getInputJavaElement();
+ IJavaProject javaProject= inputJavaElement != null ? inputJavaElement.getJavaProject() : null;
+ if (javaProject == null)
+ return true;
+
+ return !javaProject.getProject().equals(event.getSource());
+ }
+
+ }));
+
+ stores.add(PHPeclipsePlugin.getDefault().getPreferenceStore());
+ stores.add(new PreferencesAdapter(JavaCore.getPlugin().getPluginPreferences()));
+ stores.add(EditorsUI.getPreferenceStore());
+
+ return new ChainedPreferenceStore((IPreferenceStore[]) stores.toArray(new IPreferenceStore[stores.size()]));
+ }
/*
* @see AbstractTextEditor#createSourceViewer(Composite, IVerticalRuler, int)
*/