misc
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpeclipse / phpeditor / JavaOutlinePage.java
index 98681fa..8fcbaf0 100644 (file)
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2000, 2003 IBM Corporation and others.
+ * Copyright (c) 2000, 2004 IBM Corporation and others.
  * All rights reserved. This program and the accompanying materials 
  * are made available under the terms of the Common Public License v1.0
  * which accompanies this distribution, and is available at
@@ -19,6 +19,7 @@ import java.util.Vector;
 import net.sourceforge.phpdt.core.ElementChangedEvent;
 import net.sourceforge.phpdt.core.ICompilationUnit;
 import net.sourceforge.phpdt.core.IElementChangedListener;
+import net.sourceforge.phpdt.core.IField;
 import net.sourceforge.phpdt.core.IJavaElement;
 import net.sourceforge.phpdt.core.IJavaElementDelta;
 import net.sourceforge.phpdt.core.IMember;
@@ -27,10 +28,14 @@ import net.sourceforge.phpdt.core.IParent;
 import net.sourceforge.phpdt.core.ISourceRange;
 import net.sourceforge.phpdt.core.ISourceReference;
 import net.sourceforge.phpdt.core.IType;
+import net.sourceforge.phpdt.core.JavaCore;
 import net.sourceforge.phpdt.core.JavaModelException;
+import net.sourceforge.phpdt.internal.corext.util.JavaModelUtil;
+import net.sourceforge.phpdt.internal.ui.IJavaHelpContextIds;
 import net.sourceforge.phpdt.internal.ui.PHPUiImages;
+import net.sourceforge.phpdt.internal.ui.actions.AbstractToggleLinkingAction;
 import net.sourceforge.phpdt.internal.ui.actions.CompositeActionGroup;
-import net.sourceforge.phpdt.internal.ui.packageview.SelectionTransferDragAdapter;
+import net.sourceforge.phpdt.internal.ui.preferences.MembersOrderPreferenceCache;
 import net.sourceforge.phpdt.internal.ui.viewsupport.AppearanceAwareLabelProvider;
 import net.sourceforge.phpdt.internal.ui.viewsupport.DecoratingJavaLabelProvider;
 import net.sourceforge.phpdt.internal.ui.viewsupport.JavaElementLabels;
@@ -39,15 +44,14 @@ import net.sourceforge.phpdt.ui.JavaElementSorter;
 import net.sourceforge.phpdt.ui.JavaUI;
 import net.sourceforge.phpdt.ui.PreferenceConstants;
 import net.sourceforge.phpdt.ui.ProblemsLabelDecorator.ProblemsLabelChangedEvent;
+import net.sourceforge.phpdt.ui.actions.CustomFiltersActionGroup;
 import net.sourceforge.phpdt.ui.actions.GenerateActionGroup;
 import net.sourceforge.phpdt.ui.actions.MemberFilterActionGroup;
-import net.sourceforge.phpeclipse.PHPCore;
+import net.sourceforge.phpdt.ui.actions.PHPdtActionConstants;
 import net.sourceforge.phpeclipse.PHPeclipsePlugin;
 
 import org.eclipse.core.resources.IResource;
 import org.eclipse.core.runtime.IAdaptable;
-import net.sourceforge.phpdt.internal.ui.dnd.JdtViewerDragAdapter;
-import net.sourceforge.phpdt.internal.ui.dnd.TransferDragSourceListener;
 import org.eclipse.jface.action.Action;
 import org.eclipse.jface.action.IAction;
 import org.eclipse.jface.action.IMenuListener;
@@ -55,6 +59,7 @@ import org.eclipse.jface.action.IMenuManager;
 import org.eclipse.jface.action.IStatusLineManager;
 import org.eclipse.jface.action.IToolBarManager;
 import org.eclipse.jface.action.MenuManager;
+import org.eclipse.jface.action.Separator;
 import org.eclipse.jface.preference.IPreferenceStore;
 import org.eclipse.jface.text.Assert;
 import org.eclipse.jface.text.ITextSelection;
@@ -62,11 +67,13 @@ import org.eclipse.jface.util.IPropertyChangeListener;
 import org.eclipse.jface.util.ListenerList;
 import org.eclipse.jface.util.PropertyChangeEvent;
 import org.eclipse.jface.viewers.IBaseLabelProvider;
+import org.eclipse.jface.viewers.IPostSelectionProvider;
 import org.eclipse.jface.viewers.ISelection;
 import org.eclipse.jface.viewers.ISelectionChangedListener;
 import org.eclipse.jface.viewers.IStructuredSelection;
 import org.eclipse.jface.viewers.ITreeContentProvider;
 import org.eclipse.jface.viewers.LabelProviderChangedEvent;
+import org.eclipse.jface.viewers.SelectionChangedEvent;
 import org.eclipse.jface.viewers.StructuredSelection;
 import org.eclipse.jface.viewers.TreeViewer;
 import org.eclipse.jface.viewers.Viewer;
@@ -75,8 +82,6 @@ import org.eclipse.swt.SWT;
 import org.eclipse.swt.custom.BusyIndicator;
 import org.eclipse.swt.dnd.DND;
 import org.eclipse.swt.dnd.Transfer;
-import org.eclipse.swt.events.KeyAdapter;
-import org.eclipse.swt.events.KeyEvent;
 import org.eclipse.swt.widgets.Composite;
 import org.eclipse.swt.widgets.Control;
 import org.eclipse.swt.widgets.Display;
@@ -87,8 +92,9 @@ import org.eclipse.swt.widgets.Widget;
 import org.eclipse.ui.IActionBars;
 import org.eclipse.ui.actions.ActionContext;
 import org.eclipse.ui.actions.ActionGroup;
-import org.eclipse.ui.internal.model.WorkbenchAdapter;
+import org.eclipse.ui.help.WorkbenchHelp;
 import org.eclipse.ui.model.IWorkbenchAdapter;
+import org.eclipse.ui.model.WorkbenchAdapter;
 import org.eclipse.ui.part.IPageSite;
 import org.eclipse.ui.part.IShowInSource;
 import org.eclipse.ui.part.IShowInTarget;
@@ -96,23 +102,20 @@ import org.eclipse.ui.part.IShowInTargetList;
 import org.eclipse.ui.part.Page;
 import org.eclipse.ui.part.ShowInContext;
 import org.eclipse.ui.texteditor.ITextEditorActionConstants;
+import org.eclipse.ui.texteditor.ITextEditorActionDefinitionIds;
 import org.eclipse.ui.texteditor.IUpdate;
 import org.eclipse.ui.texteditor.TextEditorAction;
-import org.eclipse.ui.texteditor.TextOperationAction;
 import org.eclipse.ui.views.contentoutline.IContentOutlinePage;
 import org.eclipse.ui.views.navigator.LocalSelectionTransfer;
 
 
-
-
-
 /**
  * The content outline page of the Java editor. The viewer implements a proprietary
  * update mechanism based on Java model deltas. It does not react on domain changes.
  * It is specified to show the content of ICompilationUnits and IClassFiles.
- * Pulishes its context menu under <code>JavaPlugin.getDefault().getPluginId() + ".outline"</code>.
+ * Publishes its context menu under <code>PHPeclipsePlugin.getDefault().getPluginId() + ".outline"</code>.
  */
-public class JavaOutlinePage extends Page implements IContentOutlinePage, IAdaptable {
+public class JavaOutlinePage extends Page implements IContentOutlinePage, IAdaptable , IPostSelectionProvider {
 
                        static Object[] NO_CHILDREN= new Object[0];
    
@@ -133,23 +136,34 @@ public class JavaOutlinePage extends Page implements IContentOutlinePage, IAdapt
                                                        public void run() {
                                                                ICompilationUnit cu= (ICompilationUnit) fInput;
                                                                IJavaElement base= cu;
-                                                               if (fTopLevelTypeOnly) {
-                                                                       base= getMainType(cu);
-                                                                       if (base == null) {
+//                                                             if (fTopLevelTypeOnly) {
+//                                                                     base= getMainType(cu);
+//                                                                     if (base == null) {
                                                                                if (fOutlineViewer != null)
                                                                                        fOutlineViewer.refresh(true);
                                                                                return;
-                                                                       }
-                                                               }
-                                                               IJavaElementDelta delta= findElement(base, e.getDelta());
-                                                               if (delta != null && fOutlineViewer != null) {
-                                                                       fOutlineViewer.reconcile(delta);
-                                                               }
+//                                                                     }
+//                                                             }
+//                                                             IJavaElementDelta delta= findElement(base, e.getDelta());
+//                                                             if (delta != null && fOutlineViewer != null) {
+//                                                                     fOutlineViewer.reconcile(delta);
+//                                                             }
                                                        }
                                                });
                                        }
                                }
                                
+                               private boolean isPossibleStructuralChange(IJavaElementDelta cuDelta) {
+                                       if (cuDelta.getKind() != IJavaElementDelta.CHANGED) {
+                                               return true; // add or remove
+                                       }
+                                       int flags= cuDelta.getFlags();
+                                       if ((flags & IJavaElementDelta.F_CHILDREN) != 0) {
+                                               return true;
+                                       }
+                                       return (flags & (IJavaElementDelta.F_CONTENT | IJavaElementDelta.F_FINE_GRAINED)) == IJavaElementDelta.F_CONTENT;
+                               }
+                               
                                protected IJavaElementDelta findElement(IJavaElement unit, IJavaElementDelta delta) {
                                        
                                        if (delta == null || unit == null)
@@ -157,8 +171,13 @@ public class JavaOutlinePage extends Page implements IContentOutlinePage, IAdapt
                                        
                                        IJavaElement element= delta.getElement();
                                        
-                                       if (unit.equals(element))
-                                               return delta;
+                                       if (unit.equals(element)) {
+                                               if (isPossibleStructuralChange(delta)) {
+                                                       return delta;
+                                               }
+                                               return null;
+                                       }
+                                               
                                        
                                        if (element.getElementType() > IJavaElement.CLASS_FILE)
                                                return null;
@@ -175,7 +194,7 @@ public class JavaOutlinePage extends Page implements IContentOutlinePage, IAdapt
                                        
                                        return null;
                                }
-                       };
+                       }
          
                        static class NoClassElement extends WorkbenchAdapter implements IAdaptable {
                                /*
@@ -243,7 +262,12 @@ public class JavaOutlinePage extends Page implements IContentOutlinePage, IAdapt
                                                try {
                                                        return filter(c.getChildren());
                                                } catch (JavaModelException x) {
-                                                       PHPeclipsePlugin.log(x);
+                                                       // https://bugs.eclipse.org/bugs/show_bug.cgi?id=38341
+                                                       // don't log NotExist exceptions as this is a valid case
+                                                       // since we might have been posted and the element
+                                                       // removed in the meantime.
+                                                       if (PHPeclipsePlugin.isDebug() || !x.isDoesNotExist())
+                                                               PHPeclipsePlugin.log(x);
                                                }
                                        }
                                        return NO_CHILDREN;
@@ -264,7 +288,7 @@ public class JavaOutlinePage extends Page implements IContentOutlinePage, IAdapt
 //                                                             IType type= getMainType((IClassFile) parent);
 //                                                             return type != null ? type.getChildren() : NO_CLASS;
 //                                                     } catch (JavaModelException e) {
-//                                                             JavaPlugin.log(e);
+//                                                             PHPeclipsePlugin.log(e);
 //                                                     }                                                       
 //                                             }
                                        }
@@ -286,7 +310,12 @@ public class JavaOutlinePage extends Page implements IContentOutlinePage, IAdapt
                                                        IJavaElement[] children= filter(c.getChildren());
                                                        return (children != null && children.length > 0);
                                                } catch (JavaModelException x) {
-                                                       PHPeclipsePlugin.log(x);
+                                                       // https://bugs.eclipse.org/bugs/show_bug.cgi?id=38341
+                                                       // don't log NotExist exceptions as this is a valid case
+                                                       // since we might have been posted and the element
+                                                       // removed in the meantime.
+                                                       if (PHPeclipsePlugin.isDebug() || !x.isDoesNotExist())
+                                                               PHPeclipsePlugin.log(x);
                                                }
                                        }
                                        return false;
@@ -298,7 +327,7 @@ public class JavaOutlinePage extends Page implements IContentOutlinePage, IAdapt
                                
                                public void dispose() {
                                        if (fListener != null) {
-                                               PHPCore.removeElementChangedListener(fListener);
+                                               JavaCore.removeElementChangedListener(fListener);
                                                fListener= null;
                                        }               
                                }
@@ -311,13 +340,13 @@ public class JavaOutlinePage extends Page implements IContentOutlinePage, IAdapt
                                                                        
                                        if (isCU && fListener == null) {
                                                fListener= new ElementChangedListener();
-                                               PHPCore.addElementChangedListener(fListener);
+                                               JavaCore.addElementChangedListener(fListener);
                                        } else if (!isCU && fListener != null) {
-                                               PHPCore.removeElementChangedListener(fListener);
+                                               JavaCore.removeElementChangedListener(fListener);
                                                fListener= null;
                                        }
                                }
-                       };
+                       }
                        
                        
                        class JavaOutlineViewer extends TreeViewer {
@@ -330,18 +359,23 @@ public class JavaOutlinePage extends Page implements IContentOutlinePage, IAdapt
                                 */
                                private Item fReusedExpandedItem;
                                private boolean fReorderedMembers;
+                               private boolean fForceFireSelectionChanged;
                                
                                public JavaOutlineViewer(Tree tree) {
                                        super(tree);
                                        setAutoExpandLevel(ALL_LEVELS);
+                                       setUseHashlookup(true);
                                }
                                
                                /**
-                                * Investigates the given element change event and if affected incrementally
-                                * updates the outline.
+                                * Investigates the given element change event and if affected
+                                * incrementally updates the Java outline.
+                                * 
+                                * @param delta the Java element delta used to reconcile the Java outline
                                 */
                                public void reconcile(IJavaElementDelta delta) {
                                        fReorderedMembers= false;
+                                       fForceFireSelectionChanged= false;
                                        if (getSorter() == null) {
                                                if (fTopLevelTypeOnly
                                                        && delta.getElement() instanceof IType
@@ -353,6 +387,8 @@ public class JavaOutlinePage extends Page implements IContentOutlinePage, IAdapt
                                                        Widget w= findItem(fInput);
                                                        if (w != null && !w.isDisposed())
                                                                update(w, delta);
+                                                       if (fForceFireSelectionChanged)
+                                                               fireSelectionChanged(new SelectionChangedEvent(getSite().getSelectionProvider(), this.getSelection()));
                                                        if (fReorderedMembers) {
                                                                refresh(false);
                                                                fReorderedMembers= false;
@@ -400,10 +436,11 @@ public class JavaOutlinePage extends Page implements IContentOutlinePage, IAdapt
                                        }
                                        
                                        updateItem(item, element);
-                                       updatePlus(item, element);                                      
+                                       updatePlus(item, element);
                                        internalExpandToLevel(item, ALL_LEVELS);
                                        
                                        fReusedExpandedItem= null;
+                                       fForceFireSelectionChanged= true;
                                }
                                
                                protected boolean mustUpdateParent(IJavaElementDelta delta, IJavaElement element) {
@@ -420,11 +457,21 @@ public class JavaOutlinePage extends Page implements IContentOutlinePage, IAdapt
                                        return false;
                                }
                                
+                               /*
+                                * @see org.eclipse.jface.viewers.AbstractTreeViewer#isExpandable(java.lang.Object)
+                                */
+                               public boolean isExpandable(Object element) {
+                                       if (hasFilters()) {
+                                               return getFilteredChildren(element).length > 0;
+                                       }
+                                       return super.isExpandable(element);
+                               }
+                               
                                protected ISourceRange getSourceRange(IJavaElement element) throws JavaModelException {
-                                       if (element instanceof IMember)// && !(element instanceof IInitializer))
-                                               return ((IMember) element).getNameRange();
                                        if (element instanceof ISourceReference)
                                                return ((ISourceReference) element).getSourceRange();
+                                       if (element instanceof IMember)// && !(element instanceof IInitializer))
+                                               return ((IMember) element).getNameRange();
                                        return null;
                                }
                                
@@ -454,6 +501,7 @@ public class JavaOutlinePage extends Page implements IContentOutlinePage, IAdapt
                                        Item[] children= getChildren(w);
 
                                        boolean doUpdateParent= false;
+                                       boolean doUpdateParentsPlus= false;
                                                                                
                                        Vector deletions= new Vector();
                                        Vector additions= new Vector();                         
@@ -470,6 +518,11 @@ public class JavaOutlinePage extends Page implements IContentOutlinePage, IAdapt
                                                        break;
                                                
                                                if (j == children.length) {
+                                                       // remove from collapsed parent
+                                                       if ((status & IJavaElementDelta.REMOVED) != 0) {
+                                                               doUpdateParentsPlus= true;
+                                                               continue;
+                                                       }                                                       
                                                        // addition
                                                        if ((status & IJavaElementDelta.CHANGED) != 0 &&                                                        
                                                                (affectedDelta.getFlags() & IJavaElementDelta.F_MODIFIERS) != 0 &&
@@ -533,6 +586,12 @@ public class JavaOutlinePage extends Page implements IContentOutlinePage, IAdapt
                                                        ISourceRange rng= getSourceRange(e);
                                                        int start= rng.getOffset();
                                                        int end= start + rng.getLength() - 1;
+                                                       int nameOffset= Integer.MAX_VALUE;
+                                                       if (e instanceof IField) {
+                                                               ISourceRange nameRange= ((IField) e).getNameRange();
+                                                               if (nameRange != null)
+                                                                       nameOffset= nameRange.getOffset();
+                                                       }
                                                        
                                                        Item last= null;
                                                        item= null;
@@ -550,22 +609,49 @@ public class JavaOutlinePage extends Page implements IContentOutlinePage, IAdapt
                                                                        
                                                                try {
                                                                        rng= getSourceRange(r);
-                                                                       if (overlaps(rng, start, end)) {
+
+                                                                       // multi-field declarations always start at 
+                                                                       // the same offset. They also have the same
+                                                                       // end offset if the field sequence is terminated
+                                                                       // with a semicolon. If not, the source range
+                                                                       // ends behind the identifier / initializer
+                                                                       // see https://bugs.eclipse.org/bugs/show_bug.cgi?id=51851
+                                                                       boolean multiFieldDeclaration= 
+                                                                               r.getElementType() == IJavaElement.FIELD 
+                                                                                       && e.getElementType() == IJavaElement.FIELD
+                                                                                       && rng.getOffset() == start;
+
+                                                                       // elements are inserted by occurrence
+                                                                       // however, multi-field declarations have
+                                                                       // equal source ranges offsets, therefore we
+                                                                       // compare name-range offsets.
+                                                                       boolean multiFieldOrderBefore= false;
+                                                                       if (multiFieldDeclaration) {
+                                                                               if (r instanceof IField) {
+                                                                                       ISourceRange nameRange= ((IField) r).getNameRange();
+                                                                                       if (nameRange != null) {
+                                                                                               if (nameRange.getOffset() > nameOffset)
+                                                                                                       multiFieldOrderBefore= true;
+                                                                                       }
+                                                                               }
+                                                                       }
+                                                                       
+                                                                       if (!multiFieldDeclaration && overlaps(rng, start, end)) {
                                                                                
                                                                                // be tolerant if the delta is not correct, or if 
                                                                                // the tree has been updated other than by a delta
                                                                                reuseTreeItem(item, e);
                                                                                continue go2;
                                                                                
-                                                                       } else if (rng.getOffset() > start) {
+                                                                       } else if (multiFieldOrderBefore || rng.getOffset() > start) {
                                                                                
                                                                                if (last != null && deletions.contains(last)) {
                                                                                        // reuse item
                                                                                        deletions.removeElement(last);
-                                                                                       reuseTreeItem(last, (Object) e);
+                                                                                       reuseTreeItem(last, e);
                                                                                } else {
                                                                                        // nothing to reuse
-                                                                                       createTreeItem(w, (Object) e, j);
+                                                                                       createTreeItem(w, e, j);
                                                                                }
                                                                                continue go2;
                                                                        }
@@ -603,6 +689,8 @@ public class JavaOutlinePage extends Page implements IContentOutlinePage, IAdapt
                                        
                                        if (doUpdateParent)
                                                updateItem(w, delta.getElement());
+                                       if (!doUpdateParent && doUpdateParentsPlus && w instanceof Item)
+                                               updatePlus((Item)w, delta.getElement());
                                }
                                
 
@@ -639,11 +727,8 @@ public class JavaOutlinePage extends Page implements IContentOutlinePage, IAdapt
                                        Object input= getInput();
                                        if (input instanceof ICompilationUnit) {
                                                ICompilationUnit cu= (ICompilationUnit) input;
-                                               if (cu.isWorkingCopy()) {
-                                                       return cu.getOriginalElement().getResource();
-                                               } else {
-                                                       return cu.getResource();
-                                               }                               
+                                               cu= JavaModelUtil.toOriginal(cu);
+                                               return cu.getResource();                
                                        } 
 //                                     else if (input instanceof IClassFile) {
 //                                             return ((IClassFile) input).getResource();
@@ -652,7 +737,7 @@ public class JavaOutlinePage extends Page implements IContentOutlinePage, IAdapt
                                }                               
                                
 
-                       };
+                       }
                                
                        class LexicalSortingAction extends Action {
                                
@@ -660,7 +745,7 @@ public class JavaOutlinePage extends Page implements IContentOutlinePage, IAdapt
 
                                public LexicalSortingAction() {
                                        super();
-//                                     WorkbenchHelp.setHelp(this, IJavaHelpContextIds.LEXICAL_SORTING_OUTLINE_ACTION);
+                                       WorkbenchHelp.setHelp(this, IJavaHelpContextIds.LEXICAL_SORTING_OUTLINE_ACTION);
                                        setText(PHPEditorMessages.getString("JavaOutlinePage.Sort.label")); //$NON-NLS-1$
                                        PHPUiImages.setLocalImageDescriptors(this, "alphab_sort_co.gif"); //$NON-NLS-1$
                                        setToolTipText(PHPEditorMessages.getString("JavaOutlinePage.Sort.tooltip")); //$NON-NLS-1$
@@ -682,15 +767,15 @@ public class JavaOutlinePage extends Page implements IContentOutlinePage, IAdapt
                                        });
 
                                        if (store)
-                                       PHPeclipsePlugin.getDefault().getPreferenceStore().setValue("LexicalSortingAction.isChecked", on); //$NON-NLS-1$
+                                               PHPeclipsePlugin.getDefault().getPreferenceStore().setValue("LexicalSortingAction.isChecked", on); //$NON-NLS-1$
                                }
-                       };
+                       }
 
                class ClassOnlyAction extends Action {
 
                        public ClassOnlyAction() {
                                super();
-//                             WorkbenchHelp.setHelp(this, IJavaHelpContextIds.GO_INTO_TOP_LEVEL_TYPE_ACTION);
+                               WorkbenchHelp.setHelp(this, IJavaHelpContextIds.GO_INTO_TOP_LEVEL_TYPE_ACTION);
                                setText(PHPEditorMessages.getString("JavaOutlinePage.GoIntoTopLevelType.label")); //$NON-NLS-1$
                                setToolTipText(PHPEditorMessages.getString("JavaOutlinePage.GoIntoTopLevelType.tooltip")); //$NON-NLS-1$
                                setDescription(PHPEditorMessages.getString("JavaOutlinePage.GoIntoTopLevelType.description")); //$NON-NLS-1$
@@ -716,7 +801,40 @@ public class JavaOutlinePage extends Page implements IContentOutlinePage, IAdapt
                                IPreferenceStore preferenceStore= PHPeclipsePlugin.getDefault().getPreferenceStore(); 
                                preferenceStore.setValue("GoIntoTopLevelTypeAction.isChecked", show); //$NON-NLS-1$
                        }
-               };
+               }
+
+               /**
+                * This action toggles whether this Java Outline page links
+                * its selection to the active editor.
+                * 
+                * @since 3.0
+                */
+               public class ToggleLinkingAction extends AbstractToggleLinkingAction {
+               
+                       JavaOutlinePage fJavaOutlinePage;
+               
+                       /**
+                        * Constructs a new action.
+                        * 
+                        * @param outlinePage the Java outline page
+                        */
+                       public ToggleLinkingAction(JavaOutlinePage outlinePage) {
+                               boolean isLinkingEnabled= PreferenceConstants.getPreferenceStore().getBoolean(PreferenceConstants.EDITOR_SYNC_OUTLINE_ON_CURSOR_MOVE);
+                               setChecked(isLinkingEnabled);
+                               fJavaOutlinePage= outlinePage;
+                       }
+       
+                       /**
+                        * Runs the action.
+                        */
+                       public void run() {
+                               PreferenceConstants.getPreferenceStore().setValue(PreferenceConstants.EDITOR_SYNC_OUTLINE_ON_CURSOR_MOVE, isChecked());
+                               if (isChecked() && fEditor != null)
+                                       fEditor.synchronizeOutlinePage(fEditor.computeHighlightRangeSourceReference(), false);
+                       }
+       
+               }
+
 
        /** A flag to show contents of top level type only */
        private boolean fTopLevelTypeOnly;
@@ -730,19 +848,26 @@ public class JavaOutlinePage extends Page implements IContentOutlinePage, IAdapt
        private MemberFilterActionGroup fMemberFilterActionGroup;
                
        private ListenerList fSelectionChangedListeners= new ListenerList();
+       private ListenerList fPostSelectionChangedListeners= new ListenerList();
        private Hashtable fActions= new Hashtable();
        
        private TogglePresentationAction fTogglePresentation;
-       private GotoErrorAction fPreviousError;
-       private GotoErrorAction fNextError;
+       private GotoAnnotationAction fPreviousAnnotation;
+       private GotoAnnotationAction fNextAnnotation;
        private TextEditorAction fShowJavadoc;
-       private TextOperationAction fUndo;
-       private TextOperationAction fRedo;
+       private IAction fUndo;
+       private IAction fRedo;
+       
+       private ToggleLinkingAction fToggleLinkingAction;
        
        private CompositeActionGroup fActionGroups;
-//     private CCPActionGroup fCCPActionGroup;
 
        private IPropertyChangeListener fPropertyChangeListener;
+       /**
+        * Custom filter action group.
+        * @since 3.0
+        */
+       private CustomFiltersActionGroup fCustomFiltersActionGroup;
        
        public JavaOutlinePage(String contextMenuID, PHPEditor editor) {
                super();
@@ -751,19 +876,16 @@ public class JavaOutlinePage extends Page implements IContentOutlinePage, IAdapt
                
                fContextMenuID= contextMenuID;
                fEditor= editor;
-               
                fTogglePresentation= new TogglePresentationAction();
-               fPreviousError= new GotoErrorAction("PreviousError.", false); //$NON-NLS-1$
-               fPreviousError.setImageDescriptor(PHPUiImages.DESC_TOOL_GOTO_PREV_ERROR);
-               fNextError= new GotoErrorAction("NextError.", true); //$NON-NLS-1$
-               fNextError.setImageDescriptor(PHPUiImages.DESC_TOOL_GOTO_NEXT_ERROR);
+               fPreviousAnnotation= new GotoAnnotationAction("PreviousAnnotation.", false); //$NON-NLS-1$
+               fNextAnnotation= new GotoAnnotationAction("NextAnnotation.", true); //$NON-NLS-1$
                fShowJavadoc= (TextEditorAction) fEditor.getAction("ShowJavaDoc"); //$NON-NLS-1$
-               fUndo= (TextOperationAction) fEditor.getAction(ITextEditorActionConstants.UNDO);
-               fRedo= (TextOperationAction) fEditor.getAction(ITextEditorActionConstants.REDO);
+               fUndo= fEditor.getAction(ITextEditorActionConstants.UNDO);
+               fRedo= fEditor.getAction(ITextEditorActionConstants.REDO);
                
                fTogglePresentation.setEditor(editor);
-               fPreviousError.setEditor(editor);
-               fNextError.setEditor(editor);   
+               fPreviousAnnotation.setEditor(editor);
+               fNextAnnotation.setEditor(editor);      
                
                fPropertyChangeListener= new IPropertyChangeListener() {
                        public void propertyChange(PropertyChangeEvent event) {
@@ -782,6 +904,10 @@ public class JavaOutlinePage extends Page implements IContentOutlinePage, IAdapt
         * <code>null</code> if is does not have one
         */
        protected IType getMainType(ICompilationUnit compilationUnit) {
+               
+               if (compilationUnit == null)
+                       return null;
+               
                String name= compilationUnit.getElementName();
                int index= name.indexOf('.');
                if (index != -1)
@@ -815,7 +941,7 @@ public class JavaOutlinePage extends Page implements IContentOutlinePage, IAdapt
        
        private void doPropertyChange(PropertyChangeEvent event) {
                if (fOutlineViewer != null) {
-                       if (PreferenceConstants.APPEARANCE_MEMBER_SORT_ORDER.equals(event.getProperty())) {
+                       if (MembersOrderPreferenceCache.isMemberOrderProperty(event.getProperty())) {
                                fOutlineViewer.refresh(false);
                        }
                }
@@ -826,7 +952,7 @@ public class JavaOutlinePage extends Page implements IContentOutlinePage, IAdapt
         */
        public void addSelectionChangedListener(ISelectionChangedListener listener) {
                if (fOutlineViewer != null)
-                       fOutlineViewer.addPostSelectionChangedListener(listener);
+                       fOutlineViewer.addSelectionChangedListener(listener);
                else
                        fSelectionChangedListeners.add(listener);
        }
@@ -836,7 +962,7 @@ public class JavaOutlinePage extends Page implements IContentOutlinePage, IAdapt
         */
        public void removeSelectionChangedListener(ISelectionChangedListener listener) {
                if (fOutlineViewer != null)
-                       fOutlineViewer.removePostSelectionChangedListener(listener);
+                       fOutlineViewer.removeSelectionChangedListener(listener);
                else
                        fSelectionChangedListeners.remove(listener);
        }
@@ -858,15 +984,43 @@ public class JavaOutlinePage extends Page implements IContentOutlinePage, IAdapt
                return fOutlineViewer.getSelection();
        }
        
-       private void registerToolbarActions() {
+       /*
+        * @see org.eclipse.jface.text.IPostSelectionProvider#addPostSelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener)
+        */
+       public void addPostSelectionChangedListener(ISelectionChangedListener listener) {
+               if (fOutlineViewer != null)
+                       fOutlineViewer.addPostSelectionChangedListener(listener);
+               else
+                       fPostSelectionChangedListeners.add(listener);
+       }
+       
+       /*
+        * @see org.eclipse.jface.text.IPostSelectionProvider#removePostSelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener)
+        */
+       public void removePostSelectionChangedListener(ISelectionChangedListener listener) {
+               if (fOutlineViewer != null)
+                       fOutlineViewer.removePostSelectionChangedListener(listener);
+               else
+                       fPostSelectionChangedListeners.remove(listener);        
+       }
+       
+       private void registerToolbarActions(IActionBars actionBars) {
                
-               IToolBarManager toolBarManager= getSite().getActionBars().getToolBarManager();
+               IToolBarManager toolBarManager= actionBars.getToolBarManager();
                if (toolBarManager != null) {   
-                       toolBarManager.add(new ClassOnlyAction());              
                        toolBarManager.add(new LexicalSortingAction());
                        
-                       fMemberFilterActionGroup= new MemberFilterActionGroup(fOutlineViewer, "JavaOutlineViewer"); //$NON-NLS-1$
+                       fMemberFilterActionGroup= new MemberFilterActionGroup(fOutlineViewer, "net.sourceforge.phpeclipse.JavaOutlinePage"); //$NON-NLS-1$
                        fMemberFilterActionGroup.contributeToToolBar(toolBarManager);
+
+                       fCustomFiltersActionGroup.fillActionBars(actionBars);
+                       
+                       IMenuManager menu= actionBars.getMenuManager();
+                       menu.add(new Separator("EndFilterGroup")); //$NON-NLS-1$
+                       
+                       fToggleLinkingAction= new ToggleLinkingAction(this);
+                       menu.add(new ClassOnlyAction());                
+                       menu.add(fToggleLinkingAction);
                }
        }
        
@@ -883,20 +1037,27 @@ public class JavaOutlinePage extends Page implements IContentOutlinePage, IAdapt
                );
 
                fOutlineViewer= new JavaOutlineViewer(tree);            
+               initDragAndDrop();
                fOutlineViewer.setContentProvider(new ChildrenProvider());
                fOutlineViewer.setLabelProvider(new DecoratingJavaLabelProvider(lprovider));
                
                Object[] listeners= fSelectionChangedListeners.getListeners();
                for (int i= 0; i < listeners.length; i++) {
                        fSelectionChangedListeners.remove(listeners[i]);
+                       fOutlineViewer.addSelectionChangedListener((ISelectionChangedListener) listeners[i]);
+               }
+               
+               listeners= fPostSelectionChangedListeners.getListeners();
+               for (int i= 0; i < listeners.length; i++) {
+                       fPostSelectionChangedListeners.remove(listeners[i]);
                        fOutlineViewer.addPostSelectionChangedListener((ISelectionChangedListener) listeners[i]);
                }
-                               
+                                               
                MenuManager manager= new MenuManager(fContextMenuID, fContextMenuID);
                manager.setRemoveAllWhenShown(true);
                manager.addMenuListener(new IMenuListener() {
-                       public void menuAboutToShow(IMenuManager manager) {
-                               contextMenuAboutToShow(manager);
+                       public void menuAboutToShow(IMenuManager m) {
+                               contextMenuAboutToShow(m);
                        }
                });
                fMenu= manager.createContextMenu(tree);
@@ -909,7 +1070,7 @@ public class JavaOutlinePage extends Page implements IContentOutlinePage, IAdapt
                // we must create the groups after we have set the selection provider to the site
                fActionGroups= new CompositeActionGroup(new ActionGroup[] {
 //                             new OpenViewActionGroup(this), 
-//                             fCCPActionGroup= new CCPActionGroup(this),
+//                             new CCPActionGroup(this),
                                new GenerateActionGroup(this)});
 //                             new RefactorActionGroup(this), 
 //                             new JavaSearchActionGroup(this)});
@@ -919,32 +1080,27 @@ public class JavaOutlinePage extends Page implements IContentOutlinePage, IAdapt
                
                bars.setGlobalActionHandler(ITextEditorActionConstants.UNDO, fUndo);
                bars.setGlobalActionHandler(ITextEditorActionConstants.REDO, fRedo);
-               bars.setGlobalActionHandler(ITextEditorActionConstants.PREVIOUS, fPreviousError);
-               bars.setGlobalActionHandler(ITextEditorActionConstants.NEXT, fNextError);
-//             bars.setGlobalActionHandler(PHPdtActionConstants.SHOW_PHP_DOC, fShowJavadoc);
-               bars.setGlobalActionHandler(IJavaEditorActionConstants.TOGGLE_PRESENTATION, fTogglePresentation);
-               // http://dev.eclipse.org/bugs/show_bug.cgi?id=18968
-               bars.setGlobalActionHandler(IJavaEditorActionConstants.PREVIOUS_ERROR, fPreviousError);
-               bars.setGlobalActionHandler(IJavaEditorActionConstants.NEXT_ERROR, fNextError);
+               bars.setGlobalActionHandler(ITextEditorActionConstants.PREVIOUS, fPreviousAnnotation);
+               bars.setGlobalActionHandler(ITextEditorActionConstants.NEXT, fNextAnnotation);
+               bars.setGlobalActionHandler(PHPdtActionConstants.SHOW_JAVA_DOC, fShowJavadoc);
+               bars.setGlobalActionHandler(ITextEditorActionDefinitionIds.TOGGLE_SHOW_SELECTED_ELEMENT_ONLY, fTogglePresentation);
+               bars.setGlobalActionHandler(ITextEditorActionDefinitionIds.GOTO_NEXT_ANNOTATION, fNextAnnotation);
+               bars.setGlobalActionHandler(ITextEditorActionDefinitionIds.GOTO_PREVIOUS_ANNOTATION, fPreviousAnnotation);
+               
                
                fActionGroups.fillActionBars(bars);
 
-               IStatusLineManager statusLineManager= site.getActionBars().getStatusLineManager();
+               IStatusLineManager statusLineManager= bars.getStatusLineManager();
                if (statusLineManager != null) {
                        StatusBarUpdater updater= new StatusBarUpdater(statusLineManager);
                        fOutlineViewer.addPostSelectionChangedListener(updater);
                }
-               
-               registerToolbarActions();
+               // Custom filter group
+               fCustomFiltersActionGroup= new CustomFiltersActionGroup("net.sourceforge.phpdt.ui.JavaOutlinePage", fOutlineViewer); //$NON-NLS-1$
+
+               registerToolbarActions(bars);
                                
                fOutlineViewer.setInput(fInput);        
-               fOutlineViewer.getControl().addKeyListener(new KeyAdapter() {
-                       public void keyPressed(KeyEvent e) {
-                               handleKeyReleased(e);
-                       }
-               });
-               
-               initDragAndDrop();
        }
 
        public void dispose() {
@@ -956,6 +1112,11 @@ public class JavaOutlinePage extends Page implements IContentOutlinePage, IAdapt
                        fMemberFilterActionGroup.dispose();
                        fMemberFilterActionGroup= null;
                }
+               
+               if (fCustomFiltersActionGroup != null) {
+                       fCustomFiltersActionGroup.dispose();
+                       fCustomFiltersActionGroup= null;
+               }
                        
                        
                fEditor.outlinePageClosed();
@@ -963,6 +1124,9 @@ public class JavaOutlinePage extends Page implements IContentOutlinePage, IAdapt
 
                fSelectionChangedListeners.clear();
                fSelectionChangedListeners= null;
+               
+               fPostSelectionChangedListeners.clear();
+               fPostSelectionChangedListeners= null;
 
                if (fPropertyChangeListener != null) {
                        PHPeclipsePlugin.getDefault().getPreferenceStore().removePropertyChangeListener(fPropertyChangeListener);
@@ -978,8 +1142,8 @@ public class JavaOutlinePage extends Page implements IContentOutlinePage, IAdapt
                        fActionGroups.dispose();
                        
                fTogglePresentation.setEditor(null);
-               fPreviousError.setEditor(null);
-               fNextError.setEditor(null);     
+               fPreviousAnnotation.setEditor(null);
+               fNextAnnotation.setEditor(null);        
                
                fOutlineViewer= null;
                
@@ -1026,8 +1190,8 @@ public class JavaOutlinePage extends Page implements IContentOutlinePage, IAdapt
                return (IAction) fActions.get(actionID);
        }
 
-       /**
-        * Answer the property defined by key.
+       /*
+        * @see org.eclipse.core.runtime.IAdaptable#getAdapter(java.lang.Class)
         */
        public Object getAdapter(Class key) {
                if (key == IShowInSource.class) {
@@ -1051,6 +1215,10 @@ public class JavaOutlinePage extends Page implements IContentOutlinePage, IAdapt
        /**
         * Convenience method to add the action installed under the given actionID to the
         * specified group of the menu.
+        * 
+        * @param menu          the menu manager
+        * @param group         the group to which to add the action
+        * @param actionID      the ID of the new action
         */
        protected void addAction(IMenuManager menu, String group, String actionID) {
                IAction action= getAction(actionID);
@@ -1086,38 +1254,33 @@ public class JavaOutlinePage extends Page implements IContentOutlinePage, IAdapt
        }
        
        /**
-        * Checkes whether a given Java element is an inner type.
+        * Checks whether a given Java element is an inner type.
+        * 
+        * @param element the java element
+        * @return <code>true</code> iff the given element is an inner type
         */
        private boolean isInnerType(IJavaElement element) {
                
-               if (element.getElementType() == IJavaElement.TYPE) {
-                       IJavaElement parent= element.getParent();
-                       int type= parent.getElementType();
-                       return (type != IJavaElement.COMPILATION_UNIT && type != IJavaElement.CLASS_FILE);
+               if (element != null && element.getElementType() == IJavaElement.TYPE) {
+                       IType type= (IType)element;
+                       try {
+                               return type.isMember();
+                       } catch (JavaModelException e) {
+                               IJavaElement parent= type.getParent();
+                               if (parent != null) {
+                                       int parentElementType= parent.getElementType();
+                                       return (parentElementType != IJavaElement.COMPILATION_UNIT && parentElementType != IJavaElement.CLASS_FILE);
+                               }
+                       }
                }
                
                return false;           
        }
        
        /**
-        * Handles key events in viewer.
-        */
-       private void handleKeyReleased(KeyEvent event) {
-               
-               if (event.stateMask != 0)
-                       return;
-               
-               IAction action= null;
-//             if (event.character == SWT.DEL) {
-//                     action= fCCPActionGroup.getDeleteAction();
-//             }
-                       
-               if (action != null && action.isEnabled())
-                       action.run();
-       }
-       
-       /**
         * Returns the <code>IShowInSource</code> for this view.
+        * 
+        * @return the {@link IShowInSource}
         */
        protected IShowInSource getShowInSource() {
                return new IShowInSource() {
@@ -1131,6 +1294,8 @@ public class JavaOutlinePage extends Page implements IContentOutlinePage, IAdapt
 
        /**
         * Returns the <code>IShowInTarget</code> for this view.
+        * 
+        * @return the {@link IShowInTarget}
         */
        protected IShowInTarget getShowInTarget() {
                return new IShowInTarget() {
@@ -1163,9 +1328,9 @@ public class JavaOutlinePage extends Page implements IContentOutlinePage, IAdapt
 //             fOutlineViewer.addDropSupport(ops | DND.DROP_DEFAULT, transfers, new DelegatingDropAdapter(dropListeners));
                
                // Drag Adapter
-               TransferDragSourceListener[] dragListeners= new TransferDragSourceListener[] {
-                       new SelectionTransferDragAdapter(fOutlineViewer)
-               };
-               fOutlineViewer.addDragSupport(ops, transfers, new JdtViewerDragAdapter(fOutlineViewer, dragListeners));
+//             TransferDragSourceListener[] dragListeners= new TransferDragSourceListener[] {
+//                     new SelectionTransferDragAdapter(fOutlineViewer)
+//             };
+//             fOutlineViewer.addDragSupport(ops, transfers, new JdtViewerDragAdapter(fOutlineViewer, dragListeners));
        }
 }