1 package net.sourceforge.phpeclipse.phpeditor;
3 /**********************************************************************
4 Copyright (c) 2000, 2002 IBM Corp. and others.
5 All rights reserved. This program and the accompanying materials
6 are made available under the terms of the Common Public License v1.0
7 which accompanies this distribution, and is available at
8 http://www.eclipse.org/legal/cpl-v10.html
11 IBM Corporation - Initial implementation
13 **********************************************************************/
14 import java.lang.reflect.InvocationTargetException;
15 import java.lang.reflect.Method;
16 import java.text.BreakIterator;
17 import java.text.CharacterIterator;
18 import java.util.ArrayList;
19 import java.util.HashMap;
20 import java.util.Iterator;
21 import java.util.List;
23 import java.util.ResourceBundle;
24 import java.util.StringTokenizer;
26 import net.sourceforge.phpdt.core.ICompilationUnit;
27 import net.sourceforge.phpdt.core.IImportContainer;
28 import net.sourceforge.phpdt.core.IImportDeclaration;
29 import net.sourceforge.phpdt.core.IJavaElement;
30 import net.sourceforge.phpdt.core.IJavaProject;
31 import net.sourceforge.phpdt.core.IMember;
32 import net.sourceforge.phpdt.core.ISourceRange;
33 import net.sourceforge.phpdt.core.ISourceReference;
34 import net.sourceforge.phpdt.core.JavaCore;
35 import net.sourceforge.phpdt.core.JavaModelException;
36 import net.sourceforge.phpdt.core.compiler.ITerminalSymbols;
37 import net.sourceforge.phpdt.core.compiler.InvalidInputException;
38 import net.sourceforge.phpdt.internal.compiler.parser.Scanner;
39 import net.sourceforge.phpdt.internal.compiler.parser.SyntaxError;
40 import net.sourceforge.phpdt.internal.ui.actions.CompositeActionGroup;
41 import net.sourceforge.phpdt.internal.ui.actions.FoldingActionGroup;
42 import net.sourceforge.phpdt.internal.ui.actions.SelectionConverter;
43 import net.sourceforge.phpdt.internal.ui.text.CustomSourceInformationControl;
44 import net.sourceforge.phpdt.internal.ui.text.DocumentCharacterIterator;
45 import net.sourceforge.phpdt.internal.ui.text.HTMLTextPresenter;
46 import net.sourceforge.phpdt.internal.ui.text.IPHPPartitions;
47 import net.sourceforge.phpdt.internal.ui.text.JavaWordFinder;
48 import net.sourceforge.phpdt.internal.ui.text.JavaWordIterator;
49 import net.sourceforge.phpdt.internal.ui.text.PHPPairMatcher;
50 import net.sourceforge.phpdt.internal.ui.text.PreferencesAdapter;
51 import net.sourceforge.phpdt.internal.ui.text.java.hover.JavaExpandHover;
52 import net.sourceforge.phpdt.internal.ui.viewsupport.ISelectionListenerWithAST;
53 import net.sourceforge.phpdt.internal.ui.viewsupport.IViewPartInputProvider;
54 import net.sourceforge.phpdt.internal.ui.viewsupport.SelectionListenerWithASTManager;
55 import net.sourceforge.phpdt.ui.IContextMenuConstants;
56 import net.sourceforge.phpdt.ui.JavaUI;
57 import net.sourceforge.phpdt.ui.PreferenceConstants;
58 import net.sourceforge.phpdt.ui.actions.GotoMatchingBracketAction;
59 import net.sourceforge.phpdt.ui.actions.OpenEditorActionGroup;
60 import net.sourceforge.phpdt.ui.text.JavaTextTools;
61 import net.sourceforge.phpdt.ui.text.PHPSourceViewerConfiguration;
62 import net.sourceforge.phpdt.ui.text.folding.IJavaFoldingStructureProvider;
63 import net.sourceforge.phpeclipse.PHPeclipsePlugin;
64 import net.sourceforge.phpeclipse.ui.editor.BrowserUtil;
65 import net.sourceforge.phpeclipse.webbrowser.views.BrowserView;
67 import org.eclipse.core.resources.IFile;
68 import org.eclipse.core.resources.IMarker;
69 import org.eclipse.core.resources.IResource;
70 import org.eclipse.core.resources.ResourcesPlugin;
71 import org.eclipse.core.runtime.CoreException;
72 import org.eclipse.core.runtime.IProgressMonitor;
73 import org.eclipse.core.runtime.IStatus;
74 import org.eclipse.core.runtime.NullProgressMonitor;
75 import org.eclipse.core.runtime.Path;
76 import org.eclipse.core.runtime.Preferences;
77 import org.eclipse.core.runtime.Status;
78 import org.eclipse.core.runtime.jobs.Job;
79 import org.eclipse.jface.action.Action;
80 import org.eclipse.jface.action.GroupMarker;
81 import org.eclipse.jface.action.IAction;
82 import org.eclipse.jface.action.MenuManager;
83 import org.eclipse.jface.action.Separator;
84 import org.eclipse.jface.preference.IPreferenceStore;
85 import org.eclipse.jface.preference.PreferenceConverter;
86 import org.eclipse.jface.text.BadLocationException;
87 import org.eclipse.jface.text.DefaultInformationControl;
88 import org.eclipse.jface.text.DocumentEvent;
89 import org.eclipse.jface.text.IDocument;
90 import org.eclipse.jface.text.IDocumentExtension4;
91 import org.eclipse.jface.text.IDocumentListener;
92 import org.eclipse.jface.text.IInformationControl;
93 import org.eclipse.jface.text.IInformationControlCreator;
94 import org.eclipse.jface.text.IRegion;
95 import org.eclipse.jface.text.ISelectionValidator;
96 import org.eclipse.jface.text.ISynchronizable;
97 import org.eclipse.jface.text.ITextHover;
98 import org.eclipse.jface.text.ITextInputListener;
99 import org.eclipse.jface.text.ITextPresentationListener;
100 import org.eclipse.jface.text.ITextSelection;
101 import org.eclipse.jface.text.ITextViewer;
102 import org.eclipse.jface.text.ITextViewerExtension2;
103 import org.eclipse.jface.text.ITextViewerExtension4;
104 import org.eclipse.jface.text.ITextViewerExtension5;
105 import org.eclipse.jface.text.ITypedRegion;
106 import org.eclipse.jface.text.Position;
107 import org.eclipse.jface.text.Region;
108 import org.eclipse.jface.text.TextPresentation;
109 import org.eclipse.jface.text.TextSelection;
110 import org.eclipse.jface.text.TextUtilities;
111 import org.eclipse.jface.text.information.IInformationProvider;
112 import org.eclipse.jface.text.information.InformationPresenter;
113 import org.eclipse.jface.text.link.LinkedModeModel;
114 import org.eclipse.jface.text.reconciler.IReconciler;
115 import org.eclipse.jface.text.source.Annotation;
116 import org.eclipse.jface.text.source.AnnotationRulerColumn;
117 import org.eclipse.jface.text.source.CompositeRuler;
118 import org.eclipse.jface.text.source.IAnnotationModel;
119 import org.eclipse.jface.text.source.IAnnotationModelExtension;
120 import org.eclipse.jface.text.source.IOverviewRuler;
121 import org.eclipse.jface.text.source.ISourceViewer;
122 import org.eclipse.jface.text.source.ISourceViewerExtension2;
123 import org.eclipse.jface.text.source.IVerticalRuler;
124 import org.eclipse.jface.text.source.IVerticalRulerColumn;
125 import org.eclipse.jface.text.source.OverviewRuler;
126 import org.eclipse.jface.text.source.SourceViewerConfiguration;
127 import org.eclipse.jface.text.source.projection.ProjectionSupport;
128 import org.eclipse.jface.text.source.projection.ProjectionViewer;
129 import org.eclipse.jface.util.IPropertyChangeListener;
130 import org.eclipse.jface.util.ListenerList;
131 import org.eclipse.jface.util.PropertyChangeEvent;
132 import org.eclipse.jface.viewers.DoubleClickEvent;
133 import org.eclipse.jface.viewers.IDoubleClickListener;
134 import org.eclipse.jface.viewers.IPostSelectionProvider;
135 import org.eclipse.jface.viewers.ISelection;
136 import org.eclipse.jface.viewers.ISelectionChangedListener;
137 import org.eclipse.jface.viewers.ISelectionProvider;
138 import org.eclipse.jface.viewers.IStructuredSelection;
139 import org.eclipse.jface.viewers.SelectionChangedEvent;
140 import org.eclipse.jface.viewers.StructuredSelection;
141 import org.eclipse.swt.SWT;
142 import org.eclipse.swt.custom.BidiSegmentEvent;
143 import org.eclipse.swt.custom.BidiSegmentListener;
144 import org.eclipse.swt.custom.ST;
145 import org.eclipse.swt.custom.StyleRange;
146 import org.eclipse.swt.custom.StyledText;
147 import org.eclipse.swt.events.FocusEvent;
148 import org.eclipse.swt.events.FocusListener;
149 import org.eclipse.swt.events.KeyEvent;
150 import org.eclipse.swt.events.KeyListener;
151 import org.eclipse.swt.events.MouseEvent;
152 import org.eclipse.swt.events.MouseListener;
153 import org.eclipse.swt.events.MouseMoveListener;
154 import org.eclipse.swt.events.PaintEvent;
155 import org.eclipse.swt.events.PaintListener;
156 import org.eclipse.swt.graphics.Color;
157 import org.eclipse.swt.graphics.Cursor;
158 import org.eclipse.swt.graphics.GC;
159 import org.eclipse.swt.graphics.Image;
160 import org.eclipse.swt.graphics.Point;
161 import org.eclipse.swt.graphics.RGB;
162 import org.eclipse.swt.widgets.Composite;
163 import org.eclipse.swt.widgets.Control;
164 import org.eclipse.swt.widgets.Display;
165 import org.eclipse.swt.widgets.Shell;
166 import org.eclipse.ui.IEditorInput;
167 import org.eclipse.ui.IEditorPart;
168 import org.eclipse.ui.IPageLayout;
169 import org.eclipse.ui.IPartService;
170 import org.eclipse.ui.ISelectionListener;
171 import org.eclipse.ui.IViewPart;
172 import org.eclipse.ui.IWindowListener;
173 import org.eclipse.ui.IWorkbenchPage;
174 import org.eclipse.ui.IWorkbenchPart;
175 import org.eclipse.ui.IWorkbenchWindow;
176 import org.eclipse.ui.PlatformUI;
177 import org.eclipse.ui.actions.ActionContext;
178 import org.eclipse.ui.actions.ActionGroup;
179 import org.eclipse.ui.editors.text.DefaultEncodingSupport;
180 import org.eclipse.ui.editors.text.EditorsUI;
181 import org.eclipse.ui.editors.text.IEncodingSupport;
182 import org.eclipse.ui.ide.FileStoreEditorInput;
183 import org.eclipse.ui.part.FileEditorInput;
184 import org.eclipse.ui.part.IShowInSource;
185 import org.eclipse.ui.part.IShowInTargetList;
186 import org.eclipse.ui.part.ShowInContext;
187 import org.eclipse.ui.texteditor.AbstractDecoratedTextEditor;
188 import org.eclipse.ui.texteditor.AnnotationPreference;
189 import org.eclipse.ui.texteditor.ChainedPreferenceStore;
190 import org.eclipse.ui.texteditor.IDocumentProvider;
191 import org.eclipse.ui.texteditor.IEditorStatusLine;
192 import org.eclipse.ui.texteditor.ITextEditorActionConstants;
193 import org.eclipse.ui.texteditor.ITextEditorActionDefinitionIds;
194 import org.eclipse.ui.texteditor.IUpdate;
195 import org.eclipse.ui.texteditor.MarkerAnnotation;
196 import org.eclipse.ui.texteditor.SourceViewerDecorationSupport;
197 import org.eclipse.ui.texteditor.TextEditorAction;
198 import org.eclipse.ui.texteditor.TextNavigationAction;
199 import org.eclipse.ui.texteditor.TextOperationAction;
200 import org.eclipse.ui.views.contentoutline.ContentOutline;
201 import org.eclipse.ui.views.contentoutline.IContentOutlinePage;
202 import org.eclipse.ui.views.tasklist.TaskList;
205 * PHP specific text editor.
207 public abstract class PHPEditor extends AbstractDecoratedTextEditor implements
208 IViewPartInputProvider, IShowInTargetList, IShowInSource {
209 // extends StatusTextEditor implements IViewPartInputProvider { // extends
213 * Internal implementation class for a change listener.
217 protected abstract class AbstractSelectionChangedListener implements
218 ISelectionChangedListener {
221 * Installs this selection changed listener with the given selection
222 * provider. If the selection provider is a post selection provider,
223 * post selection changed events are the preferred choice, otherwise
224 * normal selection changed events are requested.
226 * @param selectionProvider
228 public void install(ISelectionProvider selectionProvider) {
229 if (selectionProvider == null)
232 if (selectionProvider instanceof IPostSelectionProvider) {
233 IPostSelectionProvider provider = (IPostSelectionProvider) selectionProvider;
234 provider.addPostSelectionChangedListener(this);
236 selectionProvider.addSelectionChangedListener(this);
241 * Removes this selection changed listener from the given selection
244 * @param selectionProvider
245 * the selection provider
247 public void uninstall(ISelectionProvider selectionProvider) {
248 if (selectionProvider == null)
251 if (selectionProvider instanceof IPostSelectionProvider) {
252 IPostSelectionProvider provider = (IPostSelectionProvider) selectionProvider;
253 provider.removePostSelectionChangedListener(this);
255 selectionProvider.removeSelectionChangedListener(this);
261 * Updates the Java outline page selection and this editor's range
266 private class EditorSelectionChangedListener extends
267 AbstractSelectionChangedListener {
270 * @see org.eclipse.jface.viewers.ISelectionChangedListener#selectionChanged(org.eclipse.jface.viewers.SelectionChangedEvent)
272 public void selectionChanged(SelectionChangedEvent event) {
273 // XXX: see https://bugs.eclipse.org/bugs/show_bug.cgi?id=56161
274 PHPEditor.this.selectionChanged();
279 * "Smart" runnable for updating the outline page's selection.
281 // class OutlinePageSelectionUpdater implements Runnable {
283 // /** Has the runnable already been posted? */
284 // private boolean fPosted = false;
286 // public OutlinePageSelectionUpdater() {
290 // * @see Runnable#run()
292 // public void run() {
293 // synchronizeOutlinePageSelection();
298 // * Posts this runnable into the event queue.
300 // public void post() {
304 // Shell shell = getSite().getShell();
305 // if (shell != null & !shell.isDisposed()) {
307 // shell.getDisplay().asyncExec(this);
311 class SelectionChangedListener implements ISelectionChangedListener {
312 public void selectionChanged(SelectionChangedEvent event) {
313 doSelectionChanged(event);
318 * Adapts an options {@link java.util.Map}to
319 * {@link org.eclipse.jface.preference.IPreferenceStore}.
321 * This preference store is read-only i.e. write access throws an
322 * {@link java.lang.UnsupportedOperationException}.
327 private static class OptionsAdapter implements IPreferenceStore {
330 * A property change event filter.
332 public interface IPropertyChangeEventFilter {
335 * Should the given event be filtered?
338 * The property change event.
339 * @return <code>true</code> iff the given event should be
342 public boolean isFiltered(PropertyChangeEvent event);
347 * Property change listener. Listens for events in the options Map and
348 * fires a {@link org.eclipse.jface.util.PropertyChangeEvent}on this
349 * adapter with arguments from the received event.
351 private class PropertyChangeListener implements IPropertyChangeListener {
356 public void propertyChange(PropertyChangeEvent event) {
357 if (getFilter().isFiltered(event))
360 if (event.getNewValue() == null)
361 fOptions.remove(event.getProperty());
363 fOptions.put(event.getProperty(), event.getNewValue());
365 firePropertyChangeEvent(event.getProperty(), event
366 .getOldValue(), event.getNewValue());
370 /** Listeners on this adapter */
371 private ListenerList fListeners = new ListenerList();
373 /** Listener on the adapted options Map */
374 private IPropertyChangeListener fListener = new PropertyChangeListener();
376 /** Adapted options Map */
377 private Map fOptions;
379 /** Preference store through which events are received. */
380 private IPreferenceStore fMockupPreferenceStore;
382 /** Property event filter. */
383 private IPropertyChangeEventFilter fFilter;
386 * Initialize with the given options.
389 * The options to wrap
390 * @param mockupPreferenceStore
391 * the mock-up preference store
393 * the property change filter
395 public OptionsAdapter(Map options,
396 IPreferenceStore mockupPreferenceStore,
397 IPropertyChangeEventFilter filter) {
398 fMockupPreferenceStore = mockupPreferenceStore;
406 public void addPropertyChangeListener(IPropertyChangeListener listener) {
407 if (fListeners.size() == 0)
408 fMockupPreferenceStore.addPropertyChangeListener(fListener);
409 fListeners.add(listener);
415 public void removePropertyChangeListener(
416 IPropertyChangeListener listener) {
417 fListeners.remove(listener);
418 if (fListeners.size() == 0)
419 fMockupPreferenceStore.removePropertyChangeListener(fListener);
425 public boolean contains(String name) {
426 return fOptions.containsKey(name);
432 public void firePropertyChangeEvent(String name, Object oldValue,
434 PropertyChangeEvent event = new PropertyChangeEvent(this, name,
436 Object[] listeners = fListeners.getListeners();
437 for (int i = 0; i < listeners.length; i++)
438 ((IPropertyChangeListener) listeners[i]).propertyChange(event);
444 public boolean getBoolean(String name) {
445 boolean value = BOOLEAN_DEFAULT_DEFAULT;
446 String s = (String) fOptions.get(name);
448 value = s.equals(TRUE);
455 public boolean getDefaultBoolean(String name) {
456 return BOOLEAN_DEFAULT_DEFAULT;
462 public double getDefaultDouble(String name) {
463 return DOUBLE_DEFAULT_DEFAULT;
469 public float getDefaultFloat(String name) {
470 return FLOAT_DEFAULT_DEFAULT;
476 public int getDefaultInt(String name) {
477 return INT_DEFAULT_DEFAULT;
483 public long getDefaultLong(String name) {
484 return LONG_DEFAULT_DEFAULT;
490 public String getDefaultString(String name) {
491 return STRING_DEFAULT_DEFAULT;
497 public double getDouble(String name) {
498 double value = DOUBLE_DEFAULT_DEFAULT;
499 String s = (String) fOptions.get(name);
502 value = new Double(s).doubleValue();
503 } catch (NumberFormatException e) {
512 public float getFloat(String name) {
513 float value = FLOAT_DEFAULT_DEFAULT;
514 String s = (String) fOptions.get(name);
517 value = new Float(s).floatValue();
518 } catch (NumberFormatException e) {
527 public int getInt(String name) {
528 int value = INT_DEFAULT_DEFAULT;
529 String s = (String) fOptions.get(name);
532 value = new Integer(s).intValue();
533 } catch (NumberFormatException e) {
542 public long getLong(String name) {
543 long value = LONG_DEFAULT_DEFAULT;
544 String s = (String) fOptions.get(name);
547 value = new Long(s).longValue();
548 } catch (NumberFormatException e) {
557 public String getString(String name) {
558 String value = (String) fOptions.get(name);
560 value = STRING_DEFAULT_DEFAULT;
567 public boolean isDefault(String name) {
574 public boolean needsSaving() {
575 return !fOptions.isEmpty();
581 public void putValue(String name, String value) {
582 throw new UnsupportedOperationException();
588 public void setDefault(String name, double value) {
589 throw new UnsupportedOperationException();
595 public void setDefault(String name, float value) {
596 throw new UnsupportedOperationException();
602 public void setDefault(String name, int value) {
603 throw new UnsupportedOperationException();
609 public void setDefault(String name, long value) {
610 throw new UnsupportedOperationException();
616 public void setDefault(String name, String defaultObject) {
617 throw new UnsupportedOperationException();
623 public void setDefault(String name, boolean value) {
624 throw new UnsupportedOperationException();
630 public void setToDefault(String name) {
631 throw new UnsupportedOperationException();
637 public void setValue(String name, double value) {
638 throw new UnsupportedOperationException();
644 public void setValue(String name, float value) {
645 throw new UnsupportedOperationException();
651 public void setValue(String name, int value) {
652 throw new UnsupportedOperationException();
658 public void setValue(String name, long value) {
659 throw new UnsupportedOperationException();
665 public void setValue(String name, String value) {
666 throw new UnsupportedOperationException();
672 public void setValue(String name, boolean value) {
673 throw new UnsupportedOperationException();
677 * Returns the adapted options Map.
679 * @return Returns the adapted options Map.
681 public Map getOptions() {
686 * Returns the mock-up preference store, events are received through
687 * this preference store.
689 * @return Returns the mock-up preference store.
691 public IPreferenceStore getMockupPreferenceStore() {
692 return fMockupPreferenceStore;
696 * Set the event filter to the given filter.
701 public void setFilter(IPropertyChangeEventFilter filter) {
706 * Returns the event filter.
708 * @return The event filter.
710 public IPropertyChangeEventFilter getFilter() {
718 // class MouseClickListener implements KeyListener, MouseListener,
719 // MouseMoveListener, FocusListener, PaintListener,
720 // IPropertyChangeListener, IDocumentListener, ITextInputListener {
722 // /** The session is active. */
723 // private boolean fActive;
725 // /** The currently active style range. */
726 // private IRegion fActiveRegion;
728 // /** The currently active style range as position. */
729 // private Position fRememberedPosition;
731 // /** The hand cursor. */
732 // private Cursor fCursor;
734 // /** The link color. */
735 // private Color fColor;
737 // /** The key modifier mask. */
738 // private int fKeyModifierMask;
740 // public void deactivate() {
741 // deactivate(false);
744 // public void deactivate(boolean redrawAll) {
748 // repairRepresentation(redrawAll);
752 // public void install() {
754 // ISourceViewer sourceViewer = getSourceViewer();
755 // if (sourceViewer == null)
758 // StyledText text = sourceViewer.getTextWidget();
759 // if (text == null || text.isDisposed())
762 // updateColor(sourceViewer);
764 // sourceViewer.addTextInputListener(this);
766 // IDocument document = sourceViewer.getDocument();
767 // if (document != null)
768 // document.addDocumentListener(this);
770 // text.addKeyListener(this);
771 // text.addMouseListener(this);
772 // text.addMouseMoveListener(this);
773 // text.addFocusListener(this);
774 // text.addPaintListener(this);
776 // updateKeyModifierMask();
778 // IPreferenceStore preferenceStore = getPreferenceStore();
779 // preferenceStore.addPropertyChangeListener(this);
782 // private void updateKeyModifierMask() {
783 // String modifiers =
784 // getPreferenceStore().getString(BROWSER_LIKE_LINKS_KEY_MODIFIER);
785 // fKeyModifierMask = computeStateMask(modifiers);
786 // if (fKeyModifierMask == -1) {
787 // // Fallback to stored state mask
788 // fKeyModifierMask =
789 // getPreferenceStore().getInt(BROWSER_LIKE_LINKS_KEY_MODIFIER_MASK);
794 // private int computeStateMask(String modifiers) {
795 // if (modifiers == null)
798 // if (modifiers.length() == 0)
801 // int stateMask = 0;
802 // StringTokenizer modifierTokenizer = new StringTokenizer(modifiers,
805 // while (modifierTokenizer.hasMoreTokens()) {
807 // EditorUtility.findLocalizedModifier(modifierTokenizer.nextToken());
808 // if (modifier == 0 || (stateMask & modifier) == modifier)
810 // stateMask = stateMask | modifier;
815 // public void uninstall() {
817 // if (fColor != null) {
822 // if (fCursor != null) {
823 // fCursor.dispose();
827 // ISourceViewer sourceViewer = getSourceViewer();
828 // if (sourceViewer == null)
831 // sourceViewer.removeTextInputListener(this);
833 // IDocument document = sourceViewer.getDocument();
834 // if (document != null)
835 // document.removeDocumentListener(this);
837 // IPreferenceStore preferenceStore = getPreferenceStore();
838 // if (preferenceStore != null)
839 // preferenceStore.removePropertyChangeListener(this);
841 // StyledText text = sourceViewer.getTextWidget();
842 // if (text == null || text.isDisposed())
845 // text.removeKeyListener(this);
846 // text.removeMouseListener(this);
847 // text.removeMouseMoveListener(this);
848 // text.removeFocusListener(this);
849 // text.removePaintListener(this);
853 // * @see IPropertyChangeListener#propertyChange(PropertyChangeEvent)
855 // public void propertyChange(PropertyChangeEvent event) {
856 // if (event.getProperty().equals(PHPEditor.LINK_COLOR)) {
857 // ISourceViewer viewer = getSourceViewer();
858 // if (viewer != null)
859 // updateColor(viewer);
860 // } else if (event.getProperty().equals(BROWSER_LIKE_LINKS_KEY_MODIFIER)) {
861 // updateKeyModifierMask();
865 // private void updateColor(ISourceViewer viewer) {
866 // if (fColor != null)
869 // StyledText text = viewer.getTextWidget();
870 // if (text == null || text.isDisposed())
873 // Display display = text.getDisplay();
874 // fColor = createColor(getPreferenceStore(), PHPEditor.LINK_COLOR,
879 // * Creates a color from the information stored in the given preference
880 // store. Returns <code>null</code> if there is no such
881 // * information available.
883 // private Color createColor(IPreferenceStore store, String key, Display
888 // if (store.contains(key)) {
890 // if (store.isDefault(key))
891 // rgb = PreferenceConverter.getDefaultColor(store, key);
893 // rgb = PreferenceConverter.getColor(store, key);
896 // return new Color(display, rgb);
902 // private void repairRepresentation() {
903 // repairRepresentation(false);
906 // private void repairRepresentation(boolean redrawAll) {
908 // if (fActiveRegion == null)
911 // ISourceViewer viewer = getSourceViewer();
912 // if (viewer != null) {
913 // resetCursor(viewer);
915 // int offset = fActiveRegion.getOffset();
916 // int length = fActiveRegion.getLength();
919 // if (!redrawAll && viewer instanceof ITextViewerExtension2)
920 // ((ITextViewerExtension2) viewer).invalidateTextPresentation(offset,
923 // viewer.invalidateTextPresentation();
925 // // remove underline
926 // if (viewer instanceof ITextViewerExtension3) {
927 // ITextViewerExtension3 extension = (ITextViewerExtension3) viewer;
928 // offset = extension.modelOffset2WidgetOffset(offset);
930 // offset -= viewer.getVisibleRegion().getOffset();
933 // StyledText text = viewer.getTextWidget();
935 // text.redrawRange(offset, length, true);
936 // } catch (IllegalArgumentException x) {
937 // PHPeclipsePlugin.log(x);
941 // fActiveRegion = null;
944 // // will eventually be replaced by a method provided by jdt.core
945 // private IRegion selectWord(IDocument document, int anchor) {
948 // int offset = anchor;
951 // while (offset >= 0) {
952 // c = document.getChar(offset);
953 // if (!Scanner.isPHPIdentifierPart(c))
958 // int start = offset;
961 // int length = document.getLength();
963 // while (offset < length) {
964 // c = document.getChar(offset);
965 // if (!Scanner.isPHPIdentifierPart(c))
973 // return new Region(start, 0);
975 // return new Region(start + 1, end - start - 1);
977 // } catch (BadLocationException x) {
982 // IRegion getCurrentTextRegion(ISourceViewer viewer) {
984 // int offset = getCurrentTextOffset(viewer);
989 // // IJavaElement input= SelectionConverter.getInput(PHPEditor.this);
990 // // if (input == null)
995 // // IJavaElement[] elements= null;
996 // // synchronized (input) {
997 // // elements= ((ICodeAssist) input).codeSelect(offset, 0);
1000 // // if (elements == null || elements.length == 0)
1003 // // return selectWord(viewer.getDocument(), offset);
1005 // // } catch (JavaModelException e) {
1010 // private int getCurrentTextOffset(ISourceViewer viewer) {
1013 // StyledText text = viewer.getTextWidget();
1014 // if (text == null || text.isDisposed())
1017 // Display display = text.getDisplay();
1018 // Point absolutePosition = display.getCursorLocation();
1019 // Point relativePosition = text.toControl(absolutePosition);
1021 // int widgetOffset = text.getOffsetAtLocation(relativePosition);
1022 // if (viewer instanceof ITextViewerExtension3) {
1023 // ITextViewerExtension3 extension = (ITextViewerExtension3) viewer;
1024 // return extension.widgetOffset2ModelOffset(widgetOffset);
1026 // return widgetOffset + viewer.getVisibleRegion().getOffset();
1029 // } catch (IllegalArgumentException e) {
1034 // private void highlightRegion(ISourceViewer viewer, IRegion region) {
1036 // if (region.equals(fActiveRegion))
1039 // repairRepresentation();
1041 // StyledText text = viewer.getTextWidget();
1042 // if (text == null || text.isDisposed())
1045 // // highlight region
1049 // if (viewer instanceof ITextViewerExtension3) {
1050 // ITextViewerExtension3 extension = (ITextViewerExtension3) viewer;
1051 // IRegion widgetRange = extension.modelRange2WidgetRange(region);
1052 // if (widgetRange == null)
1055 // offset = widgetRange.getOffset();
1056 // length = widgetRange.getLength();
1059 // offset = region.getOffset() - viewer.getVisibleRegion().getOffset();
1060 // length = region.getLength();
1063 // StyleRange oldStyleRange = text.getStyleRangeAtOffset(offset);
1064 // Color foregroundColor = fColor;
1065 // Color backgroundColor = oldStyleRange == null ? text.getBackground() :
1066 // oldStyleRange.background;
1067 // StyleRange styleRange = new StyleRange(offset, length, foregroundColor,
1068 // backgroundColor);
1069 // text.setStyleRange(styleRange);
1072 // text.redrawRange(offset, length, true);
1074 // fActiveRegion = region;
1077 // private void activateCursor(ISourceViewer viewer) {
1078 // StyledText text = viewer.getTextWidget();
1079 // if (text == null || text.isDisposed())
1081 // Display display = text.getDisplay();
1082 // if (fCursor == null)
1083 // fCursor = new Cursor(display, SWT.CURSOR_HAND);
1084 // text.setCursor(fCursor);
1087 // private void resetCursor(ISourceViewer viewer) {
1088 // StyledText text = viewer.getTextWidget();
1089 // if (text != null && !text.isDisposed())
1090 // text.setCursor(null);
1092 // if (fCursor != null) {
1093 // fCursor.dispose();
1100 // org.eclipse.swt.events.KeyListener#keyPressed(org.eclipse.swt.events.KeyEvent)
1102 // public void keyPressed(KeyEvent event) {
1109 // if (event.keyCode != fKeyModifierMask) {
1116 // // removed for #25871
1118 // // ISourceViewer viewer= getSourceViewer();
1119 // // if (viewer == null)
1122 // // IRegion region= getCurrentTextRegion(viewer);
1123 // // if (region == null)
1126 // // highlightRegion(viewer, region);
1127 // // activateCursor(viewer);
1132 // org.eclipse.swt.events.KeyListener#keyReleased(org.eclipse.swt.events.KeyEvent)
1134 // public void keyReleased(KeyEvent event) {
1144 // org.eclipse.swt.events.MouseListener#mouseDoubleClick(org.eclipse.swt.events.MouseEvent)
1146 // public void mouseDoubleClick(MouseEvent e) {
1151 // org.eclipse.swt.events.MouseListener#mouseDown(org.eclipse.swt.events.MouseEvent)
1153 // public void mouseDown(MouseEvent event) {
1158 // if (event.stateMask != fKeyModifierMask) {
1163 // if (event.button != 1) {
1171 // org.eclipse.swt.events.MouseListener#mouseUp(org.eclipse.swt.events.MouseEvent)
1173 // public void mouseUp(MouseEvent e) {
1178 // if (e.button != 1) {
1183 // boolean wasActive = fCursor != null;
1188 // IAction action = getAction("OpenEditor"); //$NON-NLS-1$
1189 // if (action != null)
1196 // org.eclipse.swt.events.MouseMoveListener#mouseMove(org.eclipse.swt.events.MouseEvent)
1198 // public void mouseMove(MouseEvent event) {
1200 // if (event.widget instanceof Control && !((Control)
1201 // event.widget).isFocusControl()) {
1207 // if (event.stateMask != fKeyModifierMask)
1209 // // modifier was already pressed
1213 // ISourceViewer viewer = getSourceViewer();
1214 // if (viewer == null) {
1219 // StyledText text = viewer.getTextWidget();
1220 // if (text == null || text.isDisposed()) {
1225 // if ((event.stateMask & SWT.BUTTON1) != 0 && text.getSelectionCount() !=
1232 // IRegion region = getCurrentTextRegion(viewer);
1233 // if (region == null || region.getLength() == 0) {
1234 // repairRepresentation();
1238 // highlightRegion(viewer, region);
1239 // activateCursor(viewer);
1244 // org.eclipse.swt.events.FocusListener#focusGained(org.eclipse.swt.events.FocusEvent)
1246 // public void focusGained(FocusEvent e) {
1251 // org.eclipse.swt.events.FocusListener#focusLost(org.eclipse.swt.events.FocusEvent)
1253 // public void focusLost(FocusEvent event) {
1259 // org.eclipse.jface.text.IDocumentListener#documentAboutToBeChanged(org.eclipse.jface.text.DocumentEvent)
1261 // public void documentAboutToBeChanged(DocumentEvent event) {
1262 // if (fActive && fActiveRegion != null) {
1263 // fRememberedPosition = new Position(fActiveRegion.getOffset(),
1264 // fActiveRegion.getLength());
1266 // event.getDocument().addPosition(fRememberedPosition);
1267 // } catch (BadLocationException x) {
1268 // fRememberedPosition = null;
1275 // org.eclipse.jface.text.IDocumentListener#documentChanged(org.eclipse.jface.text.DocumentEvent)
1277 // public void documentChanged(DocumentEvent event) {
1278 // if (fRememberedPosition != null && !fRememberedPosition.isDeleted()) {
1279 // event.getDocument().removePosition(fRememberedPosition);
1280 // fActiveRegion = new Region(fRememberedPosition.getOffset(),
1281 // fRememberedPosition.getLength());
1283 // fRememberedPosition = null;
1285 // ISourceViewer viewer = getSourceViewer();
1286 // if (viewer != null) {
1287 // StyledText widget = viewer.getTextWidget();
1288 // if (widget != null && !widget.isDisposed()) {
1289 // widget.getDisplay().asyncExec(new Runnable() {
1290 // public void run() {
1300 // org.eclipse.jface.text.ITextInputListener#inputDocumentAboutToBeChanged(org.eclipse.jface.text.IDocument,
1301 // * org.eclipse.jface.text.IDocument)
1303 // public void inputDocumentAboutToBeChanged(IDocument oldInput, IDocument
1305 // if (oldInput == null)
1308 // oldInput.removeDocumentListener(this);
1313 // org.eclipse.jface.text.ITextInputListener#inputDocumentChanged(org.eclipse.jface.text.IDocument,
1314 // * org.eclipse.jface.text.IDocument)
1316 // public void inputDocumentChanged(IDocument oldInput, IDocument newInput)
1318 // if (newInput == null)
1320 // newInput.addDocumentListener(this);
1324 // * @see PaintListener#paintControl(PaintEvent)
1326 // public void paintControl(PaintEvent event) {
1327 // if (fActiveRegion == null)
1330 // ISourceViewer viewer = getSourceViewer();
1331 // if (viewer == null)
1334 // StyledText text = viewer.getTextWidget();
1335 // if (text == null || text.isDisposed())
1341 // if (viewer instanceof ITextViewerExtension3) {
1343 // ITextViewerExtension3 extension = (ITextViewerExtension3) viewer;
1344 // IRegion widgetRange = extension.modelRange2WidgetRange(new Region(offset,
1346 // if (widgetRange == null)
1349 // offset = widgetRange.getOffset();
1350 // length = widgetRange.getLength();
1354 // IRegion region = viewer.getVisibleRegion();
1355 // if (!includes(region, fActiveRegion))
1358 // offset = fActiveRegion.getOffset() - region.getOffset();
1359 // length = fActiveRegion.getLength();
1362 // // support for bidi
1363 // Point minLocation = getMinimumLocation(text, offset, length);
1364 // Point maxLocation = getMaximumLocation(text, offset, length);
1366 // int x1 = minLocation.x;
1367 // int x2 = minLocation.x + maxLocation.x - minLocation.x - 1;
1368 // int y = minLocation.y + text.getLineHeight() - 1;
1370 // GC gc = event.gc;
1371 // if (fColor != null && !fColor.isDisposed())
1372 // gc.setForeground(fColor);
1373 // gc.drawLine(x1, y, x2, y);
1376 // private boolean includes(IRegion region, IRegion position) {
1377 // return position.getOffset() >= region.getOffset()
1378 // && position.getOffset() + position.getLength() <= region.getOffset() +
1379 // region.getLength();
1382 // private Point getMinimumLocation(StyledText text, int offset, int length)
1384 // Point minLocation = new Point(Integer.MAX_VALUE, Integer.MAX_VALUE);
1386 // for (int i = 0; i <= length; i++) {
1387 // Point location = text.getLocationAtOffset(offset + i);
1389 // if (location.x < minLocation.x)
1390 // minLocation.x = location.x;
1391 // if (location.y < minLocation.y)
1392 // minLocation.y = location.y;
1395 // return minLocation;
1398 // private Point getMaximumLocation(StyledText text, int offset, int length)
1400 // Point maxLocation = new Point(Integer.MIN_VALUE, Integer.MIN_VALUE);
1402 // for (int i = 0; i <= length; i++) {
1403 // Point location = text.getLocationAtOffset(offset + i);
1405 // if (location.x > maxLocation.x)
1406 // maxLocation.x = location.x;
1407 // if (location.y > maxLocation.y)
1408 // maxLocation.y = location.y;
1411 // return maxLocation;
1417 class MouseClickListener implements KeyListener, MouseListener,
1418 MouseMoveListener, FocusListener, PaintListener,
1419 IPropertyChangeListener, IDocumentListener, ITextInputListener,
1420 ITextPresentationListener {
1422 /** The session is active. */
1423 private boolean fActive;
1425 /** The currently active style range. */
1426 private IRegion fActiveRegion;
1428 /** The currently active style range as position. */
1429 private Position fRememberedPosition;
1431 /** The hand cursor. */
1432 private Cursor fCursor;
1434 /** The link color. */
1435 private Color fColor;
1437 /** The key modifier mask. */
1438 private int fKeyModifierMask;
1440 public void deactivate() {
1444 public void deactivate(boolean redrawAll) {
1448 repairRepresentation(redrawAll);
1452 public void install() {
1453 ISourceViewer sourceViewer = getSourceViewer();
1454 if (sourceViewer == null)
1457 StyledText text = sourceViewer.getTextWidget();
1458 if (text == null || text.isDisposed())
1461 updateColor(sourceViewer);
1463 sourceViewer.addTextInputListener(this);
1465 IDocument document = sourceViewer.getDocument();
1466 if (document != null)
1467 document.addDocumentListener(this);
1469 text.addKeyListener(this);
1470 text.addMouseListener(this);
1471 text.addMouseMoveListener(this);
1472 text.addFocusListener(this);
1473 text.addPaintListener(this);
1475 ((ITextViewerExtension4) sourceViewer)
1476 .addTextPresentationListener(this);
1478 updateKeyModifierMask();
1480 IPreferenceStore preferenceStore = getPreferenceStore();
1481 preferenceStore.addPropertyChangeListener(this);
1484 private void updateKeyModifierMask() {
1485 String modifiers = getPreferenceStore().getString(
1486 BROWSER_LIKE_LINKS_KEY_MODIFIER);
1487 fKeyModifierMask = computeStateMask(modifiers);
1488 if (fKeyModifierMask == -1) {
1489 // Fall back to stored state mask
1490 fKeyModifierMask = getPreferenceStore().getInt(
1491 BROWSER_LIKE_LINKS_KEY_MODIFIER_MASK);
1495 private int computeStateMask(String modifiers) {
1496 if (modifiers == null)
1499 if (modifiers.length() == 0)
1503 StringTokenizer modifierTokenizer = new StringTokenizer(modifiers,
1504 ",;.:+-* "); //$NON-NLS-1$
1505 while (modifierTokenizer.hasMoreTokens()) {
1506 int modifier = EditorUtility
1507 .findLocalizedModifier(modifierTokenizer.nextToken());
1508 if (modifier == 0 || (stateMask & modifier) == modifier)
1510 stateMask = stateMask | modifier;
1515 public void uninstall() {
1517 if (fColor != null) {
1522 if (fCursor != null) {
1527 ISourceViewer sourceViewer = getSourceViewer();
1528 if (sourceViewer != null)
1529 sourceViewer.removeTextInputListener(this);
1531 IDocumentProvider documentProvider = getDocumentProvider();
1532 if (documentProvider != null) {
1533 IDocument document = documentProvider
1534 .getDocument(getEditorInput());
1535 if (document != null)
1536 document.removeDocumentListener(this);
1539 IPreferenceStore preferenceStore = getPreferenceStore();
1540 if (preferenceStore != null)
1541 preferenceStore.removePropertyChangeListener(this);
1543 if (sourceViewer == null)
1546 StyledText text = sourceViewer.getTextWidget();
1547 if (text == null || text.isDisposed())
1550 text.removeKeyListener(this);
1551 text.removeMouseListener(this);
1552 text.removeMouseMoveListener(this);
1553 text.removeFocusListener(this);
1554 text.removePaintListener(this);
1556 ((ITextViewerExtension4) sourceViewer)
1557 .removeTextPresentationListener(this);
1561 * @see IPropertyChangeListener#propertyChange(PropertyChangeEvent)
1563 public void propertyChange(PropertyChangeEvent event) {
1564 if (event.getProperty().equals(PHPEditor.LINK_COLOR)) {
1565 ISourceViewer viewer = getSourceViewer();
1567 updateColor(viewer);
1568 } else if (event.getProperty().equals(
1569 BROWSER_LIKE_LINKS_KEY_MODIFIER)) {
1570 updateKeyModifierMask();
1574 private void updateColor(ISourceViewer viewer) {
1578 StyledText text = viewer.getTextWidget();
1579 if (text == null || text.isDisposed())
1582 Display display = text.getDisplay();
1583 fColor = createColor(getPreferenceStore(), PHPEditor.LINK_COLOR,
1588 * Creates a color from the information stored in the given preference
1592 * the preference store
1597 * @return the color or <code>null</code> if there is no such
1598 * information available
1600 private Color createColor(IPreferenceStore store, String key,
1605 if (store.contains(key)) {
1607 if (store.isDefault(key))
1608 rgb = PreferenceConverter.getDefaultColor(store, key);
1610 rgb = PreferenceConverter.getColor(store, key);
1613 return new Color(display, rgb);
1619 private void repairRepresentation() {
1620 repairRepresentation(false);
1623 private void repairRepresentation(boolean redrawAll) {
1625 if (fActiveRegion == null)
1628 int offset = fActiveRegion.getOffset();
1629 int length = fActiveRegion.getLength();
1630 fActiveRegion = null;
1632 ISourceViewer viewer = getSourceViewer();
1633 if (viewer != null) {
1635 resetCursor(viewer);
1637 // Invalidate ==> remove applied text presentation
1638 if (!redrawAll && viewer instanceof ITextViewerExtension2)
1639 ((ITextViewerExtension2) viewer)
1640 .invalidateTextPresentation(offset, length);
1642 viewer.invalidateTextPresentation();
1645 if (viewer instanceof ITextViewerExtension5) {
1646 ITextViewerExtension5 extension = (ITextViewerExtension5) viewer;
1647 offset = extension.modelOffset2WidgetOffset(offset);
1649 offset -= viewer.getVisibleRegion().getOffset();
1652 StyledText text = viewer.getTextWidget();
1654 text.redrawRange(offset, length, false);
1655 } catch (IllegalArgumentException x) {
1656 // JavaPlugin.log(x);
1661 // will eventually be replaced by a method provided by jdt.core
1662 private IRegion selectWord(IDocument document, int anchor) {
1665 int offset = anchor;
1668 while (offset >= 0) {
1669 c = document.getChar(offset);
1670 if (!Scanner.isPHPIdentifierPart(c) && c != '$')
1678 int length = document.getLength();
1680 while (offset < length) {
1681 c = document.getChar(offset);
1682 if (!Scanner.isPHPIdentifierPart(c) && c != '$')
1690 return new Region(start, 0);
1692 return new Region(start + 1, end - start - 1);
1694 } catch (BadLocationException x) {
1699 IRegion getCurrentTextRegion(ISourceViewer viewer) {
1701 int offset = getCurrentTextOffset(viewer);
1705 IJavaElement input = SelectionConverter.getInput(PHPEditor.this);
1711 // IJavaElement[] elements= null;
1712 // synchronized (input) {
1713 // elements= ((ICodeAssist) input).codeSelect(offset, 0);
1716 // if (elements == null || elements.length == 0)
1719 return selectWord(viewer.getDocument(), offset);
1721 // } catch (JavaModelException e) {
1726 private int getCurrentTextOffset(ISourceViewer viewer) {
1729 StyledText text = viewer.getTextWidget();
1730 if (text == null || text.isDisposed())
1733 Display display = text.getDisplay();
1734 Point absolutePosition = display.getCursorLocation();
1735 Point relativePosition = text.toControl(absolutePosition);
1737 int widgetOffset = text.getOffsetAtLocation(relativePosition);
1738 if (viewer instanceof ITextViewerExtension5) {
1739 ITextViewerExtension5 extension = (ITextViewerExtension5) viewer;
1740 return extension.widgetOffset2ModelOffset(widgetOffset);
1742 return widgetOffset + viewer.getVisibleRegion().getOffset();
1745 } catch (IllegalArgumentException e) {
1750 public void applyTextPresentation(TextPresentation textPresentation) {
1751 if (fActiveRegion == null)
1753 IRegion region = textPresentation.getExtent();
1754 if (fActiveRegion.getOffset() + fActiveRegion.getLength() >= region
1756 && region.getOffset() + region.getLength() > fActiveRegion
1758 textPresentation.mergeStyleRange(new StyleRange(fActiveRegion
1759 .getOffset(), fActiveRegion.getLength(), fColor, null));
1762 private void highlightRegion(ISourceViewer viewer, IRegion region) {
1764 if (region.equals(fActiveRegion))
1767 repairRepresentation();
1769 StyledText text = viewer.getTextWidget();
1770 if (text == null || text.isDisposed())
1776 if (viewer instanceof ITextViewerExtension5) {
1777 ITextViewerExtension5 extension = (ITextViewerExtension5) viewer;
1778 IRegion widgetRange = extension.modelRange2WidgetRange(region);
1779 if (widgetRange == null)
1782 offset = widgetRange.getOffset();
1783 length = widgetRange.getLength();
1786 offset = region.getOffset()
1787 - viewer.getVisibleRegion().getOffset();
1788 length = region.getLength();
1790 text.redrawRange(offset, length, false);
1792 // Invalidate region ==> apply text presentation
1793 fActiveRegion = region;
1794 if (viewer instanceof ITextViewerExtension2)
1795 ((ITextViewerExtension2) viewer).invalidateTextPresentation(
1796 region.getOffset(), region.getLength());
1798 viewer.invalidateTextPresentation();
1801 private void activateCursor(ISourceViewer viewer) {
1802 StyledText text = viewer.getTextWidget();
1803 if (text == null || text.isDisposed())
1805 Display display = text.getDisplay();
1806 if (fCursor == null)
1807 fCursor = new Cursor(display, SWT.CURSOR_HAND);
1808 text.setCursor(fCursor);
1811 private void resetCursor(ISourceViewer viewer) {
1812 StyledText text = viewer.getTextWidget();
1813 if (text != null && !text.isDisposed())
1814 text.setCursor(null);
1816 if (fCursor != null) {
1823 * @see org.eclipse.swt.events.KeyListener#keyPressed(org.eclipse.swt.events.KeyEvent)
1825 public void keyPressed(KeyEvent event) {
1832 if (event.keyCode != fKeyModifierMask) {
1839 // removed for #25871
1841 // ISourceViewer viewer= getSourceViewer();
1842 // if (viewer == null)
1845 // IRegion region= getCurrentTextRegion(viewer);
1846 // if (region == null)
1849 // highlightRegion(viewer, region);
1850 // activateCursor(viewer);
1854 * @see org.eclipse.swt.events.KeyListener#keyReleased(org.eclipse.swt.events.KeyEvent)
1856 public void keyReleased(KeyEvent event) {
1865 * @see org.eclipse.swt.events.MouseListener#mouseDoubleClick(org.eclipse.swt.events.MouseEvent)
1867 public void mouseDoubleClick(MouseEvent e) {
1871 * @see org.eclipse.swt.events.MouseListener#mouseDown(org.eclipse.swt.events.MouseEvent)
1873 public void mouseDown(MouseEvent event) {
1878 if (event.stateMask != fKeyModifierMask) {
1883 if (event.button != 1) {
1890 * @see org.eclipse.swt.events.MouseListener#mouseUp(org.eclipse.swt.events.MouseEvent)
1892 public void mouseUp(MouseEvent e) {
1897 if (e.button != 1) {
1902 boolean wasActive = fCursor != null;
1907 IAction action = getAction("OpenEditor"); //$NON-NLS-1$
1914 * @see org.eclipse.swt.events.MouseMoveListener#mouseMove(org.eclipse.swt.events.MouseEvent)
1916 public void mouseMove(MouseEvent event) {
1918 if (event.widget instanceof Control
1919 && !((Control) event.widget).isFocusControl()) {
1925 if (event.stateMask != fKeyModifierMask)
1927 // modifier was already pressed
1931 ISourceViewer viewer = getSourceViewer();
1932 if (viewer == null) {
1937 StyledText text = viewer.getTextWidget();
1938 if (text == null || text.isDisposed()) {
1943 if ((event.stateMask & SWT.BUTTON1) != 0
1944 && text.getSelectionCount() != 0) {
1949 IRegion region = getCurrentTextRegion(viewer);
1950 if (region == null || region.getLength() == 0) {
1951 repairRepresentation();
1955 highlightRegion(viewer, region);
1956 activateCursor(viewer);
1960 * @see org.eclipse.swt.events.FocusListener#focusGained(org.eclipse.swt.events.FocusEvent)
1962 public void focusGained(FocusEvent e) {
1966 * @see org.eclipse.swt.events.FocusListener#focusLost(org.eclipse.swt.events.FocusEvent)
1968 public void focusLost(FocusEvent event) {
1973 * @see org.eclipse.jface.text.IDocumentListener#documentAboutToBeChanged(org.eclipse.jface.text.DocumentEvent)
1975 public void documentAboutToBeChanged(DocumentEvent event) {
1976 if (fActive && fActiveRegion != null) {
1977 fRememberedPosition = new Position(fActiveRegion.getOffset(),
1978 fActiveRegion.getLength());
1980 event.getDocument().addPosition(fRememberedPosition);
1981 } catch (BadLocationException x) {
1982 fRememberedPosition = null;
1988 * @see org.eclipse.jface.text.IDocumentListener#documentChanged(org.eclipse.jface.text.DocumentEvent)
1990 public void documentChanged(DocumentEvent event) {
1991 if (fRememberedPosition != null) {
1992 if (!fRememberedPosition.isDeleted()) {
1994 event.getDocument().removePosition(fRememberedPosition);
1995 fActiveRegion = new Region(fRememberedPosition.getOffset(),
1996 fRememberedPosition.getLength());
1997 fRememberedPosition = null;
1999 ISourceViewer viewer = getSourceViewer();
2000 if (viewer != null) {
2001 StyledText widget = viewer.getTextWidget();
2002 if (widget != null && !widget.isDisposed()) {
2003 widget.getDisplay().asyncExec(new Runnable() {
2012 fActiveRegion = null;
2013 fRememberedPosition = null;
2020 * @see org.eclipse.jface.text.ITextInputListener#inputDocumentAboutToBeChanged(org.eclipse.jface.text.IDocument,
2021 * org.eclipse.jface.text.IDocument)
2023 public void inputDocumentAboutToBeChanged(IDocument oldInput,
2024 IDocument newInput) {
2025 if (oldInput == null)
2028 oldInput.removeDocumentListener(this);
2032 * @see org.eclipse.jface.text.ITextInputListener#inputDocumentChanged(org.eclipse.jface.text.IDocument,
2033 * org.eclipse.jface.text.IDocument)
2035 public void inputDocumentChanged(IDocument oldInput, IDocument newInput) {
2036 if (newInput == null)
2038 newInput.addDocumentListener(this);
2042 * @see PaintListener#paintControl(PaintEvent)
2044 public void paintControl(PaintEvent event) {
2045 if (fActiveRegion == null)
2048 ISourceViewer viewer = getSourceViewer();
2052 StyledText text = viewer.getTextWidget();
2053 if (text == null || text.isDisposed())
2059 if (viewer instanceof ITextViewerExtension5) {
2061 ITextViewerExtension5 extension = (ITextViewerExtension5) viewer;
2062 IRegion widgetRange = extension
2063 .modelRange2WidgetRange(fActiveRegion);
2064 if (widgetRange == null)
2067 offset = widgetRange.getOffset();
2068 length = widgetRange.getLength();
2072 IRegion region = viewer.getVisibleRegion();
2073 if (!includes(region, fActiveRegion))
2076 offset = fActiveRegion.getOffset() - region.getOffset();
2077 length = fActiveRegion.getLength();
2081 Point minLocation = getMinimumLocation(text, offset, length);
2082 Point maxLocation = getMaximumLocation(text, offset, length);
2084 int x1 = minLocation.x;
2085 int x2 = minLocation.x + maxLocation.x - minLocation.x - 1;
2086 int y = minLocation.y + text.getLineHeight() - 1;
2089 if (fColor != null && !fColor.isDisposed())
2090 gc.setForeground(fColor);
2091 gc.drawLine(x1, y, x2, y);
2094 private boolean includes(IRegion region, IRegion position) {
2095 return position.getOffset() >= region.getOffset()
2096 && position.getOffset() + position.getLength() <= region
2098 + region.getLength();
2101 private Point getMinimumLocation(StyledText text, int offset, int length) {
2102 Point minLocation = new Point(Integer.MAX_VALUE, Integer.MAX_VALUE);
2104 for (int i = 0; i <= length; i++) {
2105 Point location = text.getLocationAtOffset(offset + i);
2107 if (location.x < minLocation.x)
2108 minLocation.x = location.x;
2109 if (location.y < minLocation.y)
2110 minLocation.y = location.y;
2116 private Point getMaximumLocation(StyledText text, int offset, int length) {
2117 Point maxLocation = new Point(Integer.MIN_VALUE, Integer.MIN_VALUE);
2119 for (int i = 0; i <= length; i++) {
2120 Point location = text.getLocationAtOffset(offset + i);
2122 if (location.x > maxLocation.x)
2123 maxLocation.x = location.x;
2124 if (location.y > maxLocation.y)
2125 maxLocation.y = location.y;
2133 * This action dispatches into two behaviours: If there is no current text
2134 * hover, the javadoc is displayed using information presenter. If there is
2135 * a current text hover, it is converted into a information presenter in
2136 * order to make it sticky.
2138 class InformationDispatchAction extends TextEditorAction {
2140 /** The wrapped text operation action. */
2141 private final TextOperationAction fTextOperationAction;
2144 * Creates a dispatch action.
2146 public InformationDispatchAction(ResourceBundle resourceBundle,
2147 String prefix, final TextOperationAction textOperationAction) {
2148 super(resourceBundle, prefix, PHPEditor.this);
2149 if (textOperationAction == null)
2150 throw new IllegalArgumentException();
2151 fTextOperationAction = textOperationAction;
2155 * @see org.eclipse.jface.action.IAction#run()
2159 ISourceViewer sourceViewer = getSourceViewer();
2160 if (sourceViewer == null) {
2161 fTextOperationAction.run();
2165 if (!(sourceViewer instanceof ITextViewerExtension2)) {
2166 fTextOperationAction.run();
2170 ITextViewerExtension2 textViewerExtension2 = (ITextViewerExtension2) sourceViewer;
2172 // does a text hover exist?
2173 ITextHover textHover = textViewerExtension2.getCurrentTextHover();
2174 if (textHover == null) {
2175 fTextOperationAction.run();
2179 Point hoverEventLocation = textViewerExtension2
2180 .getHoverEventLocation();
2181 int offset = computeOffsetAtLocation(sourceViewer,
2182 hoverEventLocation.x, hoverEventLocation.y);
2184 fTextOperationAction.run();
2189 // get the text hover content
2190 IDocument document = sourceViewer.getDocument();
2191 String contentType = document.getContentType(offset);
2193 final IRegion hoverRegion = textHover.getHoverRegion(
2194 sourceViewer, offset);
2195 if (hoverRegion == null)
2198 final String hoverInfo = textHover.getHoverInfo(sourceViewer,
2201 // with information provider
2202 IInformationProvider informationProvider = new IInformationProvider() {
2204 * @see org.eclipse.jface.text.information.IInformationProvider#getSubject(org.eclipse.jface.text.ITextViewer,
2207 public IRegion getSubject(ITextViewer textViewer, int offset) {
2212 * @see org.eclipse.jface.text.information.IInformationProvider#getInformation(org.eclipse.jface.text.ITextViewer,
2213 * org.eclipse.jface.text.IRegion)
2215 public String getInformation(ITextViewer textViewer,
2221 fInformationPresenter.setOffset(offset);
2222 fInformationPresenter.setInformationProvider(
2223 informationProvider, contentType);
2224 fInformationPresenter.showInformation();
2226 } catch (BadLocationException e) {
2230 // modified version from TextViewer
2231 private int computeOffsetAtLocation(ITextViewer textViewer, int x, int y) {
2233 StyledText styledText = textViewer.getTextWidget();
2234 IDocument document = textViewer.getDocument();
2236 if (document == null)
2240 int widgetLocation = styledText.getOffsetAtLocation(new Point(
2242 if (textViewer instanceof ITextViewerExtension5) {
2243 ITextViewerExtension5 extension = (ITextViewerExtension5) textViewer;
2244 return extension.widgetOffset2ModelOffset(widgetLocation);
2246 IRegion visibleRegion = textViewer.getVisibleRegion();
2247 return widgetLocation + visibleRegion.getOffset();
2249 } catch (IllegalArgumentException e) {
2257 * This action implements smart home.
2259 * Instead of going to the start of a line it does the following: - if smart
2260 * home/end is enabled and the caret is after the line's first
2261 * non-whitespace then the caret is moved directly before it, taking JavaDoc
2262 * and multi-line comments into account. - if the caret is before the line's
2263 * first non-whitespace the caret is moved to the beginning of the line - if
2264 * the caret is at the beginning of the line see first case.
2268 protected class SmartLineStartAction extends LineStartAction {
2271 * Creates a new smart line start action
2274 * the styled text widget
2276 * a boolean flag which tells if the text up to the beginning
2277 * of the line should be selected
2279 public SmartLineStartAction(final StyledText textWidget,
2280 final boolean doSelect) {
2281 super(textWidget, doSelect);
2285 * @see org.eclipse.ui.texteditor.AbstractTextEditor.LineStartAction#getLineStartPosition(java.lang.String,
2286 * int, java.lang.String)
2288 protected int getLineStartPosition(final IDocument document,
2289 final String line, final int length, final int offset) {
2291 String type = IDocument.DEFAULT_CONTENT_TYPE;
2293 type = TextUtilities.getContentType(document,
2294 IPHPPartitions.PHP_PARTITIONING, offset, true);
2295 } catch (BadLocationException exception) {
2296 // Should not happen
2299 int index = super.getLineStartPosition(document, line, length,
2301 if (type.equals(IPHPPartitions.PHP_PHPDOC_COMMENT)
2302 || type.equals(IPHPPartitions.PHP_MULTILINE_COMMENT)) {
2303 if (index < length - 1 && line.charAt(index) == '*'
2304 && line.charAt(index + 1) != '/') {
2307 } while (index < length
2308 && Character.isWhitespace(line.charAt(index)));
2311 if (index < length - 1 && line.charAt(index) == '/'
2312 && line.charAt(index + 1) == '/') {
2316 } while (index < length
2317 && Character.isWhitespace(line.charAt(index)));
2325 * Text navigation action to navigate to the next sub-word.
2329 protected abstract class NextSubWordAction extends TextNavigationAction {
2331 protected JavaWordIterator fIterator = new JavaWordIterator();
2334 * Creates a new next sub-word action.
2337 * Action code for the default operation. Must be an action
2339 * @see org.eclipse.swt.custom.ST.
2341 protected NextSubWordAction(int code) {
2342 super(getSourceViewer().getTextWidget(), code);
2346 * @see org.eclipse.jface.action.IAction#run()
2349 // Check whether we are in a java code partition and the preference
2352 final IPreferenceStore store = getPreferenceStore();
2354 .getBoolean(PreferenceConstants.EDITOR_SUB_WORD_NAVIGATION)) {
2359 final ISourceViewer viewer = getSourceViewer();
2360 final IDocument document = viewer.getDocument();
2362 .setText((CharacterIterator) new DocumentCharacterIterator(
2364 int position = widgetOffset2ModelOffset(viewer, viewer
2365 .getTextWidget().getCaretOffset());
2369 int next = findNextPosition(position);
2370 if (next != BreakIterator.DONE) {
2371 setCaretPosition(next);
2372 getTextWidget().showSelection();
2373 fireSelectionChanged();
2379 * Finds the next position after the given position.
2382 * the current position
2383 * @return the next position
2385 protected int findNextPosition(int position) {
2386 ISourceViewer viewer = getSourceViewer();
2388 while (position != BreakIterator.DONE && widget == -1) { // TODO:
2390 position = fIterator.following(position);
2391 if (position != BreakIterator.DONE)
2392 widget = modelOffset2WidgetOffset(viewer, position);
2398 * Sets the caret position to the sub-word boundary given with
2399 * <code>position</code>.
2402 * Position where the action should move the caret
2404 protected abstract void setCaretPosition(int position);
2408 * Text navigation action to navigate to the next sub-word.
2412 protected class NavigateNextSubWordAction extends NextSubWordAction {
2415 * Creates a new navigate next sub-word action.
2417 public NavigateNextSubWordAction() {
2418 super(ST.WORD_NEXT);
2422 * @see net.sourceforge.phpdt.internal.ui.javaeditor.JavaEditor.NextSubWordAction#setCaretPosition(int)
2424 protected void setCaretPosition(final int position) {
2425 getTextWidget().setCaretOffset(
2426 modelOffset2WidgetOffset(getSourceViewer(), position));
2431 * Text operation action to delete the next sub-word.
2435 protected class DeleteNextSubWordAction extends NextSubWordAction implements
2439 * Creates a new delete next sub-word action.
2441 public DeleteNextSubWordAction() {
2442 super(ST.DELETE_WORD_NEXT);
2446 * @see net.sourceforge.phpdt.internal.ui.javaeditor.JavaEditor.NextSubWordAction#setCaretPosition(int)
2448 protected void setCaretPosition(final int position) {
2449 if (!validateEditorInputState())
2452 final ISourceViewer viewer = getSourceViewer();
2453 final int caret = widgetOffset2ModelOffset(viewer, viewer
2454 .getTextWidget().getCaretOffset());
2457 viewer.getDocument().replace(caret, position - caret, ""); //$NON-NLS-1$
2458 } catch (BadLocationException exception) {
2459 // Should not happen
2464 * @see net.sourceforge.phpdt.internal.ui.javaeditor.JavaEditor.NextSubWordAction#findNextPosition(int)
2466 protected int findNextPosition(int position) {
2467 return fIterator.following(position);
2471 * @see org.eclipse.ui.texteditor.IUpdate#update()
2473 public void update() {
2474 setEnabled(isEditorInputModifiable());
2479 * Text operation action to select the next sub-word.
2483 protected class SelectNextSubWordAction extends NextSubWordAction {
2486 * Creates a new select next sub-word action.
2488 public SelectNextSubWordAction() {
2489 super(ST.SELECT_WORD_NEXT);
2493 * @see net.sourceforge.phpdt.internal.ui.javaeditor.JavaEditor.NextSubWordAction#setCaretPosition(int)
2495 protected void setCaretPosition(final int position) {
2496 final ISourceViewer viewer = getSourceViewer();
2498 final StyledText text = viewer.getTextWidget();
2499 if (text != null && !text.isDisposed()) {
2501 final Point selection = text.getSelection();
2502 final int caret = text.getCaretOffset();
2503 final int offset = modelOffset2WidgetOffset(viewer, position);
2505 if (caret == selection.x)
2506 text.setSelectionRange(selection.y, offset - selection.y);
2508 text.setSelectionRange(selection.x, offset - selection.x);
2514 * Text navigation action to navigate to the previous sub-word.
2518 protected abstract class PreviousSubWordAction extends TextNavigationAction {
2520 protected JavaWordIterator fIterator = new JavaWordIterator();
2523 * Creates a new previous sub-word action.
2526 * Action code for the default operation. Must be an action
2528 * @see org.eclipse.swt.custom.ST.
2530 protected PreviousSubWordAction(final int code) {
2531 super(getSourceViewer().getTextWidget(), code);
2535 * @see org.eclipse.jface.action.IAction#run()
2538 // Check whether we are in a java code partition and the preference
2541 final IPreferenceStore store = getPreferenceStore();
2543 .getBoolean(PreferenceConstants.EDITOR_SUB_WORD_NAVIGATION)) {
2548 final ISourceViewer viewer = getSourceViewer();
2549 final IDocument document = viewer.getDocument();
2551 .setText((CharacterIterator) new DocumentCharacterIterator(
2553 int position = widgetOffset2ModelOffset(viewer, viewer
2554 .getTextWidget().getCaretOffset());
2558 int previous = findPreviousPosition(position);
2559 if (previous != BreakIterator.DONE) {
2560 setCaretPosition(previous);
2561 getTextWidget().showSelection();
2562 fireSelectionChanged();
2568 * Finds the previous position before the given position.
2571 * the current position
2572 * @return the previous position
2574 protected int findPreviousPosition(int position) {
2575 ISourceViewer viewer = getSourceViewer();
2577 while (position != BreakIterator.DONE && widget == -1) { // TODO:
2579 position = fIterator.preceding(position);
2580 if (position != BreakIterator.DONE)
2581 widget = modelOffset2WidgetOffset(viewer, position);
2587 * Sets the caret position to the sub-word boundary given with
2588 * <code>position</code>.
2591 * Position where the action should move the caret
2593 protected abstract void setCaretPosition(int position);
2597 * Text navigation action to navigate to the previous sub-word.
2601 protected class NavigatePreviousSubWordAction extends PreviousSubWordAction {
2604 * Creates a new navigate previous sub-word action.
2606 public NavigatePreviousSubWordAction() {
2607 super(ST.WORD_PREVIOUS);
2611 * @see net.sourceforge.phpdt.internal.ui.javaeditor.JavaEditor.PreviousSubWordAction#setCaretPosition(int)
2613 protected void setCaretPosition(final int position) {
2614 getTextWidget().setCaretOffset(
2615 modelOffset2WidgetOffset(getSourceViewer(), position));
2620 * Text operation action to delete the previous sub-word.
2624 protected class DeletePreviousSubWordAction extends PreviousSubWordAction
2625 implements IUpdate {
2628 * Creates a new delete previous sub-word action.
2630 public DeletePreviousSubWordAction() {
2631 super(ST.DELETE_WORD_PREVIOUS);
2635 * @see net.sourceforge.phpdt.internal.ui.javaeditor.JavaEditor.PreviousSubWordAction#setCaretPosition(int)
2637 protected void setCaretPosition(final int position) {
2638 if (!validateEditorInputState())
2641 final ISourceViewer viewer = getSourceViewer();
2642 final int caret = widgetOffset2ModelOffset(viewer, viewer
2643 .getTextWidget().getCaretOffset());
2646 viewer.getDocument().replace(position, caret - position, ""); //$NON-NLS-1$
2647 } catch (BadLocationException exception) {
2648 // Should not happen
2653 * @see net.sourceforge.phpdt.internal.ui.javaeditor.JavaEditor.PreviousSubWordAction#findPreviousPosition(int)
2655 protected int findPreviousPosition(int position) {
2656 return fIterator.preceding(position);
2660 * @see org.eclipse.ui.texteditor.IUpdate#update()
2662 public void update() {
2663 setEnabled(isEditorInputModifiable());
2668 * Text operation action to select the previous sub-word.
2672 protected class SelectPreviousSubWordAction extends PreviousSubWordAction {
2675 * Creates a new select previous sub-word action.
2677 public SelectPreviousSubWordAction() {
2678 super(ST.SELECT_WORD_PREVIOUS);
2682 * @see net.sourceforge.phpdt.internal.ui.javaeditor.JavaEditor.PreviousSubWordAction#setCaretPosition(int)
2684 protected void setCaretPosition(final int position) {
2685 final ISourceViewer viewer = getSourceViewer();
2687 final StyledText text = viewer.getTextWidget();
2688 if (text != null && !text.isDisposed()) {
2690 final Point selection = text.getSelection();
2691 final int caret = text.getCaretOffset();
2692 final int offset = modelOffset2WidgetOffset(viewer, position);
2694 if (caret == selection.x)
2695 text.setSelectionRange(selection.y, offset - selection.y);
2697 text.setSelectionRange(selection.x, offset - selection.x);
2702 // static protected class AnnotationAccess implements IAnnotationAccess {
2705 // org.eclipse.jface.text.source.IAnnotationAccess#getType(org.eclipse.jface.text.source.Annotation)
2707 // public Object getType(Annotation annotation) {
2708 // if (annotation instanceof IJavaAnnotation) {
2709 // IJavaAnnotation javaAnnotation = (IJavaAnnotation) annotation;
2710 // // if (javaAnnotation.isRelevant())
2711 // // return javaAnnotation.getAnnotationType();
2718 // org.eclipse.jface.text.source.IAnnotationAccess#isMultiLine(org.eclipse.jface.text.source.Annotation)
2720 // public boolean isMultiLine(Annotation annotation) {
2726 // org.eclipse.jface.text.source.IAnnotationAccess#isTemporary(org.eclipse.jface.text.source.Annotation)
2728 // public boolean isTemporary(Annotation annotation) {
2729 // if (annotation instanceof IJavaAnnotation) {
2730 // IJavaAnnotation javaAnnotation = (IJavaAnnotation) annotation;
2731 // if (javaAnnotation.isRelevant())
2732 // return javaAnnotation.isTemporary();
2738 private class PropertyChangeListener implements
2739 org.eclipse.core.runtime.Preferences.IPropertyChangeListener {
2741 * @see IPropertyChangeListener#propertyChange(PropertyChangeEvent)
2743 public void propertyChange(
2744 org.eclipse.core.runtime.Preferences.PropertyChangeEvent event) {
2745 handlePreferencePropertyChanged(event);
2750 * Finds and marks occurrence annotations.
2754 class OccurrencesFinderJob extends Job {
2756 private IDocument fDocument;
2758 private ISelection fSelection;
2760 private ISelectionValidator fPostSelectionValidator;
2762 private boolean fCanceled = false;
2764 private IProgressMonitor fProgressMonitor;
2766 private Position[] fPositions;
2768 public OccurrencesFinderJob(IDocument document, Position[] positions,
2769 ISelection selection) {
2770 super(PHPEditorMessages.JavaEditor_markOccurrences_job_name);
2771 fDocument = document;
2772 fSelection = selection;
2773 fPositions = positions;
2775 if (getSelectionProvider() instanceof ISelectionValidator)
2776 fPostSelectionValidator = (ISelectionValidator) getSelectionProvider();
2779 // cannot use cancel() because it is declared final
2785 private boolean isCanceled() {
2787 || fProgressMonitor.isCanceled()
2788 || fPostSelectionValidator != null
2789 && !(fPostSelectionValidator.isValid(fSelection) || fForcedMarkOccurrencesSelection == fSelection)
2790 || LinkedModeModel.hasInstalledModel(fDocument);
2794 * @see Job#run(org.eclipse.core.runtime.IProgressMonitor)
2796 public IStatus run(IProgressMonitor progressMonitor) {
2798 fProgressMonitor = progressMonitor;
2801 return Status.CANCEL_STATUS;
2803 ITextViewer textViewer = getViewer();
2804 if (textViewer == null)
2805 return Status.CANCEL_STATUS;
2807 IDocument document = textViewer.getDocument();
2808 if (document == null)
2809 return Status.CANCEL_STATUS;
2811 IDocumentProvider documentProvider = getDocumentProvider();
2812 if (documentProvider == null)
2813 return Status.CANCEL_STATUS;
2815 IAnnotationModel annotationModel = documentProvider
2816 .getAnnotationModel(getEditorInput());
2817 if (annotationModel == null)
2818 return Status.CANCEL_STATUS;
2820 // Add occurrence annotations
2821 int length = fPositions.length;
2822 Map annotationMap = new HashMap(length);
2823 for (int i = 0; i < length; i++) {
2826 return Status.CANCEL_STATUS;
2829 Position position = fPositions[i];
2831 // Create & add annotation
2833 message = document.get(position.offset, position.length);
2834 } catch (BadLocationException ex) {
2841 "net.sourceforge.phpdt.ui.occurrences", false, message), //$NON-NLS-1$
2846 return Status.CANCEL_STATUS;
2848 synchronized (getLockObject(annotationModel)) {
2849 if (annotationModel instanceof IAnnotationModelExtension) {
2850 ((IAnnotationModelExtension) annotationModel)
2851 .replaceAnnotations(fOccurrenceAnnotations,
2854 removeOccurrenceAnnotations();
2855 Iterator iter = annotationMap.entrySet().iterator();
2856 while (iter.hasNext()) {
2857 Map.Entry mapEntry = (Map.Entry) iter.next();
2858 annotationModel.addAnnotation((Annotation) mapEntry
2859 .getKey(), (Position) mapEntry.getValue());
2862 fOccurrenceAnnotations = (Annotation[]) annotationMap.keySet()
2863 .toArray(new Annotation[annotationMap.keySet().size()]);
2866 return Status.OK_STATUS;
2871 * Cancels the occurrences finder job upon document changes.
2875 class OccurrencesFinderJobCanceler implements IDocumentListener,
2876 ITextInputListener {
2878 public void install() {
2879 ISourceViewer sourceViewer = getSourceViewer();
2880 if (sourceViewer == null)
2883 StyledText text = sourceViewer.getTextWidget();
2884 if (text == null || text.isDisposed())
2887 sourceViewer.addTextInputListener(this);
2889 IDocument document = sourceViewer.getDocument();
2890 if (document != null)
2891 document.addDocumentListener(this);
2894 public void uninstall() {
2895 ISourceViewer sourceViewer = getSourceViewer();
2896 if (sourceViewer != null)
2897 sourceViewer.removeTextInputListener(this);
2899 IDocumentProvider documentProvider = getDocumentProvider();
2900 if (documentProvider != null) {
2901 IDocument document = documentProvider
2902 .getDocument(getEditorInput());
2903 if (document != null)
2904 document.removeDocumentListener(this);
2909 * @see org.eclipse.jface.text.IDocumentListener#documentAboutToBeChanged(org.eclipse.jface.text.DocumentEvent)
2911 public void documentAboutToBeChanged(DocumentEvent event) {
2912 if (fOccurrencesFinderJob != null)
2913 fOccurrencesFinderJob.doCancel();
2917 * @see org.eclipse.jface.text.IDocumentListener#documentChanged(org.eclipse.jface.text.DocumentEvent)
2919 public void documentChanged(DocumentEvent event) {
2923 * @see org.eclipse.jface.text.ITextInputListener#inputDocumentAboutToBeChanged(org.eclipse.jface.text.IDocument,
2924 * org.eclipse.jface.text.IDocument)
2926 public void inputDocumentAboutToBeChanged(IDocument oldInput,
2927 IDocument newInput) {
2928 if (oldInput == null)
2931 oldInput.removeDocumentListener(this);
2935 * @see org.eclipse.jface.text.ITextInputListener#inputDocumentChanged(org.eclipse.jface.text.IDocument,
2936 * org.eclipse.jface.text.IDocument)
2938 public void inputDocumentChanged(IDocument oldInput, IDocument newInput) {
2939 if (newInput == null)
2941 newInput.addDocumentListener(this);
2946 * Internal activation listener.
2950 private class ActivationListener implements IWindowListener {
2953 * @see org.eclipse.ui.IWindowListener#windowActivated(org.eclipse.ui.IWorkbenchWindow)
2956 public void windowActivated(IWorkbenchWindow window) {
2957 if (window == getEditorSite().getWorkbenchWindow()
2958 && fMarkOccurrenceAnnotations && isActivePart()) {
2959 fForcedMarkOccurrencesSelection = getSelectionProvider()
2961 SelectionListenerWithASTManager
2963 .forceSelectionChange(
2965 (ITextSelection) fForcedMarkOccurrencesSelection);
2970 * @see org.eclipse.ui.IWindowListener#windowDeactivated(org.eclipse.ui.IWorkbenchWindow)
2973 public void windowDeactivated(IWorkbenchWindow window) {
2974 if (window == getEditorSite().getWorkbenchWindow()
2975 && fMarkOccurrenceAnnotations && isActivePart())
2976 removeOccurrenceAnnotations();
2980 * @see org.eclipse.ui.IWindowListener#windowClosed(org.eclipse.ui.IWorkbenchWindow)
2983 public void windowClosed(IWorkbenchWindow window) {
2987 * @see org.eclipse.ui.IWindowListener#windowOpened(org.eclipse.ui.IWorkbenchWindow)
2990 public void windowOpened(IWorkbenchWindow window) {
2995 * Updates the selection in the editor's widget with the selection of the
2998 class OutlineSelectionChangedListener extends
2999 AbstractSelectionChangedListener {
3000 public void selectionChanged(SelectionChangedEvent event) {
3001 doSelectionChanged(event);
3006 * The internal shell activation listener for updating occurrences.
3010 private ActivationListener fActivationListener = new ActivationListener();
3012 private ISelectionListenerWithAST fPostSelectionListenerWithAST;
3014 private OccurrencesFinderJob fOccurrencesFinderJob;
3016 /** The occurrences finder job canceler */
3017 private OccurrencesFinderJobCanceler fOccurrencesFinderJobCanceler;
3020 * Holds the current occurrence annotations.
3024 private Annotation[] fOccurrenceAnnotations = null;
3027 * Tells whether all occurrences of the element at the current caret
3028 * location are automatically marked in this editor.
3032 private boolean fMarkOccurrenceAnnotations;
3035 * The selection used when forcing occurrence marking through code.
3039 private ISelection fForcedMarkOccurrencesSelection;
3042 * The document modification stamp at the time when the last occurrence
3043 * marking took place.
3047 private long fMarkOccurrenceModificationStamp = IDocumentExtension4.UNKNOWN_MODIFICATION_STAMP;
3050 * The region of the word under the caret used to when computing the current
3051 * occurrence markings.
3055 private IRegion fMarkOccurrenceTargetRegion;
3058 * Tells whether the occurrence annotations are sticky i.e. whether they
3059 * stay even if there's no valid Java element at the current caret position.
3060 * Only valid if {@link #fMarkOccurrenceAnnotations} is <code>true</code>.
3064 private boolean fStickyOccurrenceAnnotations;
3066 /** Preference key for the link color */
3067 private final static String LINK_COLOR = PreferenceConstants.EDITOR_LINK_COLOR;
3069 /** Preference key for compiler task tags */
3070 private final static String COMPILER_TASK_TAGS = JavaCore.COMPILER_TASK_TAGS;
3072 // protected PHPActionGroup fActionGroups;
3073 // /** The outline page */
3074 // private AbstractContentOutlinePage fOutlinePage;
3075 /** The outline page */
3076 protected JavaOutlinePage fOutlinePage;
3078 /** Outliner context menu Id */
3079 protected String fOutlinerContextMenuId;
3082 * Indicates whether this editor should react on outline page selection
3085 private int fIgnoreOutlinePageSelection;
3087 /** The outline page selection updater */
3088 // private OutlinePageSelectionUpdater fUpdater;
3089 // protected PHPSyntaxParserThread fValidationThread = null;
3090 // private IPreferenceStore fPHPPrefStore;
3091 /** The selection changed listener */
3092 // protected ISelectionChangedListener fSelectionChangedListener = new
3093 // SelectionChangedListener();
3095 * The editor selection changed listener.
3099 private EditorSelectionChangedListener fEditorSelectionChangedListener;
3101 /** The selection changed listener */
3102 protected AbstractSelectionChangedListener fOutlineSelectionChangedListener = new OutlineSelectionChangedListener();
3104 /** The editor's bracket matcher */
3105 private PHPPairMatcher fBracketMatcher = new PHPPairMatcher(BRACKETS);
3107 /** The line number ruler column */
3108 // private LineNumberRulerColumn fLineNumberRulerColumn;
3109 /** This editor's encoding support */
3110 private DefaultEncodingSupport fEncodingSupport;
3112 /** The mouse listener */
3113 private MouseClickListener fMouseListener;
3116 * Indicates whether this editor is about to update any annotation views.
3120 private boolean fIsUpdatingAnnotationViews = false;
3123 * The marker that served as last target for a goto marker request.
3127 private IMarker fLastMarkerTarget = null;
3129 protected CompositeActionGroup fActionGroups;
3131 protected CompositeActionGroup fContextMenuGroup;
3134 * This editor's projection support
3138 private ProjectionSupport fProjectionSupport;
3141 * This editor's projection model updater
3145 private IJavaFoldingStructureProvider fProjectionModelUpdater;
3148 * The override and implements indicator manager for this editor.
3152 // protected OverrideIndicatorManager fOverrideIndicatorManager;
3154 * The action group for folding.
3158 private FoldingActionGroup fFoldingGroup;
3160 /** The information presenter. */
3161 private InformationPresenter fInformationPresenter;
3163 /** The annotation access */
3164 // protected IAnnotationAccess fAnnotationAccess = new AnnotationAccess();
3165 /** The overview ruler */
3166 protected OverviewRuler isOverviewRulerVisible;
3168 /** The source viewer decoration support */
3169 // protected SourceViewerDecorationSupport fSourceViewerDecorationSupport;
3170 /** The overview ruler */
3171 // protected OverviewRuler fOverviewRuler;
3172 /** The preference property change listener for java core. */
3173 private org.eclipse.core.runtime.Preferences.IPropertyChangeListener fPropertyChangeListener = new PropertyChangeListener();
3176 * Returns the most narrow java element including the given offset
3179 * the offset inside of the requested element
3181 abstract protected IJavaElement getElementAt(int offset);
3184 * Returns the java element of this editor's input corresponding to the
3185 * given IJavaElement
3187 abstract protected IJavaElement getCorrespondingElement(IJavaElement element);
3190 * Sets the input of the editor's outline page.
3192 abstract protected void setOutlinePageInput(JavaOutlinePage page,
3193 IEditorInput input);
3196 * Default constructor.
3198 public PHPEditor() {
3203 * @see org.eclipse.ui.texteditor.AbstractDecoratedTextEditor#initializeKeyBindingScopes()
3205 protected void initializeKeyBindingScopes() {
3206 setKeyBindingScopes(new String[] { "net.sourceforge.phpdt.ui.phpEditorScope" }); //$NON-NLS-1$
3210 * @see org.eclipse.ui.texteditor.AbstractDecoratedTextEditor#initializeEditor()
3212 protected void initializeEditor() {
3214 // JavaTextTools textTools =
3215 // PHPeclipsePlugin.getDefault().getJavaTextTools();
3216 // setSourceViewerConfiguration(new
3217 // PHPSourceViewerConfiguration(textTools,
3218 // this, IPHPPartitions.PHP_PARTITIONING)); //,
3219 // IJavaPartitions.JAVA_PARTITIONING));
3220 IPreferenceStore store = createCombinedPreferenceStore(null);
3221 setPreferenceStore(store);
3222 JavaTextTools textTools = PHPeclipsePlugin.getDefault()
3223 .getJavaTextTools();
3224 setSourceViewerConfiguration(new PHPSourceViewerConfiguration(textTools
3225 .getColorManager(), store, this,
3226 IPHPPartitions.PHP_PARTITIONING));
3228 // TODO changed in 3.x ?
3229 // setRangeIndicator(new DefaultRangeIndicator());
3231 // (PreferenceConstants.getPreferenceStore().getBoolean(PreferenceConstants.EDITOR_SYNC_OUTLINE_ON_CURSOR_MOVE))
3232 // fUpdater = new OutlinePageSelectionUpdater();
3235 // IPreferenceStore store= createCombinedPreferenceStore(null);
3236 // setPreferenceStore(store);
3237 // JavaTextTools textTools=
3238 // PHPeclipsePlugin.getDefault().getJavaTextTools();
3239 // setSourceViewerConfiguration(new
3240 // JavaSourceViewerConfiguration(textTools.getColorManager(), store,
3241 // this, IJavaPartitions.JAVA_PARTITIONING));
3242 fMarkOccurrenceAnnotations = store
3243 .getBoolean(PreferenceConstants.EDITOR_MARK_OCCURRENCES);
3244 fStickyOccurrenceAnnotations = store
3245 .getBoolean(PreferenceConstants.EDITOR_STICKY_OCCURRENCES);
3246 // fMarkTypeOccurrences=
3247 // store.getBoolean(PreferenceConstants.EDITOR_MARK_TYPE_OCCURRENCES);
3248 // fMarkMethodOccurrences=
3249 // store.getBoolean(PreferenceConstants.EDITOR_MARK_METHOD_OCCURRENCES);
3250 // fMarkConstantOccurrences=
3251 // store.getBoolean(PreferenceConstants.EDITOR_MARK_CONSTANT_OCCURRENCES);
3252 // fMarkFieldOccurrences=
3253 // store.getBoolean(PreferenceConstants.EDITOR_MARK_FIELD_OCCURRENCES);
3254 // fMarkLocalVariableypeOccurrences=
3255 // store.getBoolean(PreferenceConstants.EDITOR_MARK_LOCAL_VARIABLE_OCCURRENCES);
3257 // store.getBoolean(PreferenceConstants.EDITOR_MARK_EXCEPTION_OCCURRENCES);
3258 // fMarkImplementors=
3259 // store.getBoolean(PreferenceConstants.EDITOR_MARK_IMPLEMENTORS);
3260 // fMarkMethodExitPoints=
3261 // store.getBoolean(PreferenceConstants.EDITOR_MARK_METHOD_EXIT_POINTS);
3266 * @see org.eclipse.ui.texteditor.AbstractTextEditor#updatePropertyDependentActions()
3268 protected void updatePropertyDependentActions() {
3269 super.updatePropertyDependentActions();
3270 if (fEncodingSupport != null)
3271 fEncodingSupport.reset();
3275 * Update the hovering behavior depending on the preferences.
3277 private void updateHoverBehavior() {
3278 SourceViewerConfiguration configuration = getSourceViewerConfiguration();
3279 String[] types = configuration
3280 .getConfiguredContentTypes(getSourceViewer());
3282 for (int i = 0; i < types.length; i++) {
3284 String t = types[i];
3286 int[] stateMasks = configuration.getConfiguredTextHoverStateMasks(
3287 getSourceViewer(), t);
3289 ISourceViewer sourceViewer = getSourceViewer();
3290 if (sourceViewer instanceof ITextViewerExtension2) {
3291 if (stateMasks != null) {
3292 for (int j = 0; j < stateMasks.length; j++) {
3293 int stateMask = stateMasks[j];
3294 ITextHover textHover = configuration.getTextHover(
3295 sourceViewer, t, stateMask);
3296 ((ITextViewerExtension2) sourceViewer).setTextHover(
3297 textHover, t, stateMask);
3300 ITextHover textHover = configuration.getTextHover(
3302 ((ITextViewerExtension2) sourceViewer).setTextHover(
3304 ITextViewerExtension2.DEFAULT_HOVER_STATE_MASK);
3307 sourceViewer.setTextHover(configuration.getTextHover(
3308 sourceViewer, t), t);
3312 public void updatedTitleImage(Image image) {
3313 setTitleImage(image);
3317 * @see net.sourceforge.phpdt.internal.ui.viewsupport.IViewPartInputProvider#getViewPartInput()
3319 public Object getViewPartInput() {
3320 return getEditorInput().getAdapter(IResource.class);
3324 * @see org.eclipse.ui.texteditor.AbstractTextEditor#doSetSelection(ISelection)
3326 protected void doSetSelection(ISelection selection) {
3327 super.doSetSelection(selection);
3328 synchronizeOutlinePageSelection();
3331 boolean isFoldingEnabled() {
3332 return PHPeclipsePlugin.getDefault().getPreferenceStore().getBoolean(
3333 PreferenceConstants.EDITOR_FOLDING_ENABLED);
3337 * @see org.eclipse.ui.IWorkbenchPart#createPartControl(org.eclipse.swt.
3338 * widgets.Composite)
3340 public void createPartControl(Composite parent) {
3341 super.createPartControl(parent);
3343 // fSourceViewerDecorationSupport.install(getPreferenceStore());
3345 ProjectionViewer projectionViewer = (ProjectionViewer) getSourceViewer();
3347 fProjectionSupport = new ProjectionSupport(projectionViewer,
3348 getAnnotationAccess(), getSharedColors());
3350 .addSummarizableAnnotationType("org.eclipse.ui.workbench.texteditor.error"); //$NON-NLS-1$
3352 .addSummarizableAnnotationType("org.eclipse.ui.workbench.texteditor.warning"); //$NON-NLS-1$
3354 .setHoverControlCreator(new IInformationControlCreator() {
3355 public IInformationControl createInformationControl(
3357 return new CustomSourceInformationControl(shell,
3358 IDocument.DEFAULT_CONTENT_TYPE);
3361 fProjectionSupport.install();
3363 fProjectionModelUpdater = PHPeclipsePlugin.getDefault()
3364 .getFoldingStructureProviderRegistry()
3365 .getCurrentFoldingProvider();
3366 if (fProjectionModelUpdater != null)
3367 fProjectionModelUpdater.install(this, projectionViewer);
3369 if (isFoldingEnabled())
3370 projectionViewer.doOperation(ProjectionViewer.TOGGLE);
3371 Preferences preferences = PHPeclipsePlugin.getDefault()
3372 .getPluginPreferences();
3373 preferences.addPropertyChangeListener(fPropertyChangeListener);
3374 IInformationControlCreator informationControlCreator = new IInformationControlCreator() {
3375 public IInformationControl createInformationControl(Shell parent) {
3376 boolean cutDown = false;
3377 int style = cutDown ? SWT.NONE : (SWT.V_SCROLL | SWT.H_SCROLL);
3378 return new DefaultInformationControl(parent, SWT.RESIZE, style,
3379 new HTMLTextPresenter(cutDown));
3383 fInformationPresenter = new InformationPresenter(
3384 informationControlCreator);
3385 fInformationPresenter.setSizeConstraints(60, 10, true, true);
3386 fInformationPresenter.install(getSourceViewer());
3388 fEditorSelectionChangedListener = new EditorSelectionChangedListener();
3389 fEditorSelectionChangedListener.install(getSelectionProvider());
3391 if (isBrowserLikeLinks())
3392 enableBrowserLikeLinks();
3394 if (PreferenceConstants.getPreferenceStore().getBoolean(
3395 PreferenceConstants.EDITOR_DISABLE_OVERWRITE_MODE))
3396 enableOverwriteMode(false);
3398 if (fMarkOccurrenceAnnotations)
3399 installOccurrencesFinder();
3401 PlatformUI.getWorkbench().addWindowListener(fActivationListener);
3404 * start of EDITOR_SAVE_ON_BLUR
3407 final PHPEditor editor = this;
3408 FocusListener focusListener = new FocusListener() {
3410 public void focusGained(FocusEvent e) {
3414 public void focusLost(FocusEvent e) {
3416 if(editor.isDirty() && PHPeclipsePlugin.getDefault().getPreferenceStore()
3417 .getBoolean(PreferenceConstants.EDITOR_SAVE_ON_BLUR)){
3418 editor.doSave(null);
3422 projectionViewer.getTextWidget().addFocusListener(focusListener);
3424 * end of EDITOR_SAVE_ON_BLUR
3431 private void setWordWrap() {
3432 if (getSourceViewer() != null) {
3433 getSourceViewer().getTextWidget().setWordWrap(
3434 PHPeclipsePlugin.getDefault().getPreferenceStore()
3435 .getBoolean(PreferenceConstants.EDITOR_WRAP_WORDS));
3439 protected void configureSourceViewerDecorationSupport(
3440 SourceViewerDecorationSupport support) {
3442 support.setCharacterPairMatcher(fBracketMatcher);
3443 support.setMatchingCharacterPainterPreferenceKeys(MATCHING_BRACKETS,
3444 MATCHING_BRACKETS_COLOR);
3446 super.configureSourceViewerDecorationSupport(support);
3450 * @see org.eclipse.ui.texteditor.AbstractTextEditor#gotoMarker(org.eclipse.core.resources.IMarker)
3452 public void gotoMarker(IMarker marker) {
3453 fLastMarkerTarget = marker;
3454 if (!fIsUpdatingAnnotationViews) {
3455 super.gotoMarker(marker);
3460 * Jumps to the next enabled annotation according to the given direction. An
3461 * annotation type is enabled if it is configured to be in the Next/Previous
3462 * tool bar drop down menu and if it is checked.
3465 * <code>true</code> if search direction is forward,
3466 * <code>false</code> if backward
3468 public Annotation gotoAnnotation(boolean forward) {
3469 ITextSelection selection = (ITextSelection) getSelectionProvider()
3471 Position position = new Position(0, 0);
3472 Annotation annotation = null;
3473 if (false /* delayed - see bug 18316 */) {
3474 annotation = getNextAnnotation(selection.getOffset(), selection
3475 .getLength(), forward, position);
3476 selectAndReveal(position.getOffset(), position.getLength());
3477 } else /* no delay - see bug 18316 */{
3478 annotation = getNextAnnotation(selection.getOffset(), selection
3479 .getLength(), forward, position);
3480 setStatusLineErrorMessage(null);
3481 setStatusLineMessage(null);
3482 if (annotation != null) {
3483 updateAnnotationViews(annotation);
3484 selectAndReveal(position.getOffset(), position.getLength());
3485 setStatusLineMessage(annotation.getText());
3492 * Returns the lock object for the given annotation model.
3494 * @param annotationModel
3495 * the annotation model
3496 * @return the annotation model's lock object
3499 private Object getLockObject(IAnnotationModel annotationModel) {
3500 if (annotationModel instanceof ISynchronizable)
3501 return ((ISynchronizable) annotationModel).getLockObject();
3503 return annotationModel;
3507 * Updates the annotation views that show the given annotation.
3512 private void updateAnnotationViews(Annotation annotation) {
3513 IMarker marker = null;
3514 if (annotation instanceof MarkerAnnotation)
3515 marker = ((MarkerAnnotation) annotation).getMarker();
3516 else if (annotation instanceof IJavaAnnotation) {
3517 Iterator e = ((IJavaAnnotation) annotation).getOverlaidIterator();
3519 while (e.hasNext()) {
3520 Object o = e.next();
3521 if (o instanceof MarkerAnnotation) {
3522 marker = ((MarkerAnnotation) o).getMarker();
3529 if (marker != null && !marker.equals(fLastMarkerTarget)) {
3531 boolean isProblem = marker.isSubtypeOf(IMarker.PROBLEM);
3532 IWorkbenchPage page = getSite().getPage();
3533 IViewPart view = page
3534 .findView(isProblem ? IPageLayout.ID_PROBLEM_VIEW
3535 : IPageLayout.ID_TASK_LIST); //$NON-NLS-1$ //$NON-NLS-2$
3537 Method method = view
3540 "setSelection", new Class[] { IStructuredSelection.class, boolean.class }); //$NON-NLS-1$
3541 method.invoke(view, new Object[] {
3542 new StructuredSelection(marker), Boolean.TRUE });
3544 } catch (CoreException x) {
3545 } catch (NoSuchMethodException x) {
3546 } catch (IllegalAccessException x) {
3547 } catch (InvocationTargetException x) {
3549 // ignore exceptions, don't update any of the lists, just set status
3555 * Returns this document's complete text.
3557 * @return the document's complete text
3559 public String get() {
3560 IDocument doc = this.getDocumentProvider().getDocument(
3561 this.getEditorInput());
3566 * Sets the outliner's context menu ID.
3568 protected void setOutlinerContextMenuId(String menuId) {
3569 fOutlinerContextMenuId = menuId;
3573 * Returns the standard action group of this editor.
3575 protected ActionGroup getActionGroup() {
3576 return fActionGroups;
3579 // public JavaOutlinePage getfOutlinePage() {
3580 // return fOutlinePage;
3584 * The <code>PHPEditor</code> implementation of this
3585 * <code>AbstractTextEditor</code> method extend the actions to add those
3586 * specific to the receiver
3588 protected void createActions() {
3589 super.createActions();
3591 ActionGroup oeg, ovg, jsg, sg;
3592 fActionGroups = new CompositeActionGroup(
3593 new ActionGroup[] { oeg = new OpenEditorActionGroup(this),
3594 // sg= new ShowActionGroup(this),
3595 // ovg= new OpenViewActionGroup(this),
3596 // jsg= new JavaSearchActionGroup(this)
3598 fContextMenuGroup = new CompositeActionGroup(new ActionGroup[] { oeg });
3599 // , ovg, sg, jsg});
3601 fFoldingGroup = new FoldingActionGroup(this, getViewer());
3603 // ResourceAction resAction = new
3604 // TextOperationAction(PHPEditorMessages.getResourceBundle(),
3605 // "ShowJavaDoc.", this, ISourceViewer.INFORMATION, true); //$NON-NLS-1$
3607 // InformationDispatchAction(PHPEditorMessages.getResourceBundle(),
3608 // "ShowJavaDoc.", (TextOperationAction) resAction); //$NON-NLS-1$
3609 // resAction.setActionDefinitionId(net.sourceforge.phpdt.ui.actions.PHPEditorActionDefinitionIds.SHOW_JAVADOC);
3610 // setAction("ShowJavaDoc", resAction); //$NON-NLS-1$
3612 // WorkbenchHelp.setHelp(resAction,
3613 // IJavaHelpContextIds.SHOW_JAVADOC_ACTION);
3615 Action action = new GotoMatchingBracketAction(this);
3617 .setActionDefinitionId(PHPEditorActionDefinitionIds.GOTO_MATCHING_BRACKET);
3618 setAction(GotoMatchingBracketAction.GOTO_MATCHING_BRACKET, action);
3621 // TextOperationAction(PHPEditorMessages.getResourceBundle(),"ShowOutline.",
3622 // this, JavaSourceViewer.SHOW_OUTLINE, true); //$NON-NLS-1$
3623 // action.setActionDefinitionId(PHPEditorActionDefinitionIds.SHOW_OUTLINE);
3624 // setAction(PHPEditorActionDefinitionIds.SHOW_OUTLINE, action);
3625 // // WorkbenchHelp.setHelp(action,
3626 // IJavaHelpContextIds.SHOW_OUTLINE_ACTION);
3629 // TextOperationAction(PHPEditorMessages.getResourceBundle(),"OpenStructure.",
3630 // this, JavaSourceViewer.OPEN_STRUCTURE, true); //$NON-NLS-1$
3631 // action.setActionDefinitionId(PHPEditorActionDefinitionIds.SHOW_OUTLINE.OPEN_STRUCTURE);
3632 // setAction(PHPEditorActionDefinitionIds.SHOW_OUTLINE.OPEN_STRUCTURE,
3634 // // WorkbenchHelp.setHelp(action,
3635 // IJavaHelpContextIds.OPEN_STRUCTURE_ACTION);
3638 // TextOperationAction(PHPEditorMessages.getResourceBundle(),"OpenHierarchy.",
3639 // this, JavaSourceViewer.SHOW_HIERARCHY, true); //$NON-NLS-1$
3640 // action.setActionDefinitionId(PHPEditorActionDefinitionIds.SHOW_OUTLINE.OPEN_HIERARCHY);
3641 // setAction(PHPEditorActionDefinitionIds.SHOW_OUTLINE.OPEN_HIERARCHY,
3643 // // WorkbenchHelp.setHelp(action,
3644 // IJavaHelpContextIds.OPEN_HIERARCHY_ACTION);
3646 fEncodingSupport = new DefaultEncodingSupport();
3647 fEncodingSupport.initialize(this);
3649 // fSelectionHistory= new SelectionHistory(this);
3651 // action= new StructureSelectEnclosingAction(this, fSelectionHistory);
3652 // action.setActionDefinitionId(PHPEditorActionDefinitionIds.SELECT_ENCLOSING);
3653 // setAction(StructureSelectionAction.ENCLOSING, action);
3655 // action= new StructureSelectNextAction(this, fSelectionHistory);
3656 // action.setActionDefinitionId(PHPEditorActionDefinitionIds.SELECT_NEXT);
3657 // setAction(StructureSelectionAction.NEXT, action);
3659 // action= new StructureSelectPreviousAction(this, fSelectionHistory);
3660 // action.setActionDefinitionId(PHPEditorActionDefinitionIds.SELECT_PREVIOUS);
3661 // setAction(StructureSelectionAction.PREVIOUS, action);
3663 // StructureSelectHistoryAction historyAction= new
3664 // StructureSelectHistoryAction(this, fSelectionHistory);
3665 // historyAction.setActionDefinitionId(PHPEditorActionDefinitionIds.SELECT_LAST);
3666 // setAction(StructureSelectionAction.HISTORY, historyAction);
3667 // fSelectionHistory.setHistoryAction(historyAction);
3669 // action= GoToNextPreviousMemberAction.newGoToNextMemberAction(this);
3670 // action.setActionDefinitionId(PHPEditorActionDefinitionIds.GOTO_NEXT_MEMBER);
3671 // setAction(GoToNextPreviousMemberAction.NEXT_MEMBER, action);
3674 // GoToNextPreviousMemberAction.newGoToPreviousMemberAction(this);
3675 // action.setActionDefinitionId(PHPEditorActionDefinitionIds.GOTO_PREVIOUS_MEMBER);
3676 // setAction(GoToNextPreviousMemberAction.PREVIOUS_MEMBER, action);
3678 // action= new QuickFormatAction();
3679 // action.setActionDefinitionId(PHPEditorActionDefinitionIds.QUICK_FORMAT);
3680 // setAction(IJavaEditorActionDefinitionIds.QUICK_FORMAT, action);
3682 // action= new RemoveOccurrenceAnnotations(this);
3683 // action.setActionDefinitionId(PHPEditorActionDefinitionIds.REMOVE_OCCURRENCE_ANNOTATIONS);
3684 // setAction("RemoveOccurrenceAnnotations", action); //$NON-NLS-1$
3686 // add annotation actions
3687 action = new JavaSelectMarkerRulerAction2(PHPEditorMessages
3688 .getResourceBundle(), "Editor.RulerAnnotationSelection.", this); //$NON-NLS-1$
3689 setAction("AnnotationAction", action); //$NON-NLS-1$
3692 private void internalDoSetInput(IEditorInput input) throws CoreException {
3693 super.doSetInput(input);
3695 if (getSourceViewer() instanceof JavaSourceViewer) {
3696 JavaSourceViewer viewer = (JavaSourceViewer) getSourceViewer();
3697 if (viewer.getReconciler() == null) {
3698 IReconciler reconciler = getSourceViewerConfiguration()
3699 .getReconciler(viewer);
3700 if (reconciler != null) {
3701 reconciler.install(viewer);
3702 viewer.setReconciler(reconciler);
3707 if (fEncodingSupport != null)
3708 fEncodingSupport.reset();
3710 setOutlinePageInput(fOutlinePage, input);
3712 if (fProjectionModelUpdater != null)
3713 fProjectionModelUpdater.initialize();
3715 // if (isShowingOverrideIndicators())
3716 // installOverrideIndicator(false);
3720 * @see org.eclipse.ui.texteditor.AbstractTextEditor#setPreferenceStore(org.eclipse.jface.preference.IPreferenceStore)
3723 protected void setPreferenceStore(IPreferenceStore store) {
3724 super.setPreferenceStore(store);
3725 if (getSourceViewerConfiguration() instanceof PHPSourceViewerConfiguration) {
3726 JavaTextTools textTools = PHPeclipsePlugin.getDefault()
3727 .getJavaTextTools();
3728 setSourceViewerConfiguration(new PHPSourceViewerConfiguration(
3729 textTools.getColorManager(), store, this,
3730 IPHPPartitions.PHP_PARTITIONING));
3732 if (getSourceViewer() instanceof JavaSourceViewer)
3733 ((JavaSourceViewer) getSourceViewer()).setPreferenceStore(store);
3737 * The <code>PHPEditor</code> implementation of this
3738 * <code>AbstractTextEditor</code> method performs any extra disposal
3739 * actions required by the php editor.
3741 public void dispose() {
3742 if (fProjectionModelUpdater != null) {
3743 fProjectionModelUpdater.uninstall();
3744 fProjectionModelUpdater = null;
3747 if (fProjectionSupport != null) {
3748 fProjectionSupport.dispose();
3749 fProjectionSupport = null;
3751 // PHPEditorEnvironment.disconnect(this);
3752 if (fOutlinePage != null)
3753 fOutlinePage.setInput(null);
3755 if (fActionGroups != null)
3756 fActionGroups.dispose();
3758 if (isBrowserLikeLinks())
3759 disableBrowserLikeLinks();
3761 // cancel possible running computation
3762 fMarkOccurrenceAnnotations = false;
3763 uninstallOccurrencesFinder();
3765 uninstallOverrideIndicator();
3767 if (fActivationListener != null) {
3768 PlatformUI.getWorkbench().removeWindowListener(fActivationListener);
3769 fActivationListener = null;
3772 if (fEncodingSupport != null) {
3773 fEncodingSupport.dispose();
3774 fEncodingSupport = null;
3777 if (fPropertyChangeListener != null) {
3778 Preferences preferences = PHPeclipsePlugin.getDefault()
3779 .getPluginPreferences();
3780 preferences.removePropertyChangeListener(fPropertyChangeListener);
3781 fPropertyChangeListener = null;
3784 // if (fSourceViewerDecorationSupport != null) {
3785 // fSourceViewerDecorationSupport.dispose();
3786 // fSourceViewerDecorationSupport = null;
3789 if (fBracketMatcher != null) {
3790 fBracketMatcher.dispose();
3791 fBracketMatcher = null;
3794 if (fEditorSelectionChangedListener != null) {
3795 fEditorSelectionChangedListener.uninstall(getSelectionProvider());
3796 fEditorSelectionChangedListener = null;
3803 * The <code>PHPEditor</code> implementation of this
3804 * <code>AbstractTextEditor</code> method performs any extra revert
3805 * behavior required by the php editor.
3807 // public void doRevertToSaved() {
3808 // super.doRevertToSaved();
3809 // if (fOutlinePage != null)
3810 // fOutlinePage.update();
3813 * The <code>PHPEditor</code> implementation of this
3814 * <code>AbstractTextEditor</code> method performs any extra save behavior
3815 * required by the php editor.
3817 // public void doSave(IProgressMonitor monitor) {
3818 // super.doSave(monitor);
3819 // compile or not, according to the user preferences
3820 // IPreferenceStore store = getPreferenceStore();
3821 // the parse on save was changed to the eclipse "builders" concept
3822 // if (store.getBoolean(PHPeclipsePlugin.PHP_PARSE_ON_SAVE)) {
3823 // IAction a = PHPParserAction.getInstance();
3827 // if (SWT.getPlatform().equals("win32")) {
3828 // IAction a = ShowExternalPreviewAction.getInstance();
3832 // if (fOutlinePage != null)
3833 // fOutlinePage.update();
3836 * The <code>PHPEditor</code> implementation of this
3837 * <code>AbstractTextEditor</code> method performs any extra save as
3838 * behavior required by the php editor.
3840 // public void doSaveAs() {
3841 // super.doSaveAs();
3842 // if (fOutlinePage != null)
3843 // fOutlinePage.update();
3846 * @see StatusTextEditor#getStatusHeader(IStatus)
3848 protected String getStatusHeader(IStatus status) {
3849 if (fEncodingSupport != null) {
3850 String message = fEncodingSupport.getStatusHeader(status);
3851 if (message != null)
3854 return super.getStatusHeader(status);
3858 * @see StatusTextEditor#getStatusBanner(IStatus)
3860 protected String getStatusBanner(IStatus status) {
3861 if (fEncodingSupport != null) {
3862 String message = fEncodingSupport.getStatusBanner(status);
3863 if (message != null)
3866 return super.getStatusBanner(status);
3870 * @see StatusTextEditor#getStatusMessage(IStatus)
3872 protected String getStatusMessage(IStatus status) {
3873 if (fEncodingSupport != null) {
3874 String message = fEncodingSupport.getStatusMessage(status);
3875 if (message != null)
3878 return super.getStatusMessage(status);
3882 * The <code>PHPEditor</code> implementation of this
3883 * <code>AbstractTextEditor</code> method performs sets the input of the
3884 * outline page after AbstractTextEditor has set input.
3886 // protected void doSetInput(IEditorInput input) throws CoreException {
3887 // super.doSetInput(input);
3888 // if (fEncodingSupport != null)
3889 // fEncodingSupport.reset();
3890 // setOutlinePageInput(fOutlinePage, input);
3893 * @see AbstractTextEditor#doSetInput
3895 protected void doSetInput(IEditorInput input) throws CoreException {
3896 ISourceViewer sourceViewer = getSourceViewer();
3897 if (!(sourceViewer instanceof ISourceViewerExtension2)) {
3898 setPreferenceStore(createCombinedPreferenceStore(input));
3899 internalDoSetInput(input);
3903 // uninstall & unregister preference store listener
3904 if (isBrowserLikeLinks())
3905 disableBrowserLikeLinks();
3906 getSourceViewerDecorationSupport(sourceViewer).uninstall();
3907 ((ISourceViewerExtension2) sourceViewer).unconfigure();
3909 setPreferenceStore(createCombinedPreferenceStore(input));
3911 // install & register preference store listener
3912 sourceViewer.configure(getSourceViewerConfiguration());
3913 getSourceViewerDecorationSupport(sourceViewer).install(
3914 getPreferenceStore());
3915 if (isBrowserLikeLinks())
3916 enableBrowserLikeLinks();
3918 internalDoSetInput(input);
3922 * @see org.phpeclipse.phpdt.internal.ui.viewsupport.IViewPartInputProvider#getViewPartInput()
3924 // public Object getViewPartInput() {
3925 // return getEditorInput().getAdapter(IFile.class);
3928 * The <code>PHPEditor</code> implementation of this
3929 * <code>AbstractTextEditor</code> method adds any PHPEditor specific
3932 public void editorContextMenuAboutToShow(MenuManager menu) {
3933 super.editorContextMenuAboutToShow(menu);
3934 menu.appendToGroup(ITextEditorActionConstants.GROUP_UNDO,
3935 new Separator(IContextMenuConstants.GROUP_OPEN));
3936 menu.insertAfter(IContextMenuConstants.GROUP_OPEN, new GroupMarker(
3937 IContextMenuConstants.GROUP_SHOW));
3939 ActionContext context = new ActionContext(getSelectionProvider()
3941 fContextMenuGroup.setContext(context);
3942 fContextMenuGroup.fillContextMenu(menu);
3943 fContextMenuGroup.setContext(null);
3944 // addAction(menu, ITextEditorActionConstants.GROUP_EDIT, "Format");
3947 // ActionContext context =
3948 // new ActionContext(getSelectionProvider().getSelection());
3949 // fContextMenuGroup.setContext(context);
3950 // fContextMenuGroup.fillContextMenu(menu);
3951 // fContextMenuGroup.setContext(null);
3955 * Creates the outline page used with this editor.
3957 protected JavaOutlinePage createOutlinePage() {
3958 JavaOutlinePage page = new JavaOutlinePage(fOutlinerContextMenuId, this);
3959 fOutlineSelectionChangedListener.install(page);
3960 setOutlinePageInput(page, getEditorInput());
3965 * Informs the editor that its outliner has been closed.
3967 public void outlinePageClosed() {
3968 if (fOutlinePage != null) {
3969 fOutlineSelectionChangedListener.uninstall(fOutlinePage);
3970 fOutlinePage = null;
3971 resetHighlightRange();
3976 * Synchronizes the outliner selection with the given element position in
3980 * the java element to select
3982 protected void synchronizeOutlinePage(ISourceReference element) {
3983 synchronizeOutlinePage(element, true);
3987 * Synchronizes the outliner selection with the given element position in
3991 * the java element to select
3992 * @param checkIfOutlinePageActive
3993 * <code>true</code> if check for active outline page needs to
3996 protected void synchronizeOutlinePage(ISourceReference element,
3997 boolean checkIfOutlinePageActive) {
3998 if (fOutlinePage != null && element != null
3999 && !(checkIfOutlinePageActive && isJavaOutlinePageActive())) {
4000 fOutlineSelectionChangedListener.uninstall(fOutlinePage);
4001 fOutlinePage.select(element);
4002 fOutlineSelectionChangedListener.install(fOutlinePage);
4007 * Synchronizes the outliner selection with the actual cursor position in
4010 public void synchronizeOutlinePageSelection() {
4011 synchronizeOutlinePage(computeHighlightRangeSourceReference());
4013 // ISourceViewer sourceViewer = getSourceViewer();
4014 // if (sourceViewer == null || fOutlinePage == null)
4017 // StyledText styledText = sourceViewer.getTextWidget();
4018 // if (styledText == null)
4022 // if (sourceViewer instanceof ITextViewerExtension3) {
4023 // ITextViewerExtension3 extension = (ITextViewerExtension3)
4026 // extension.widgetOffset2ModelOffset(styledText.getCaretOffset());
4028 // int offset = sourceViewer.getVisibleRegion().getOffset();
4029 // caret = offset + styledText.getCaretOffset();
4032 // IJavaElement element = getElementAt(caret);
4033 // if (element instanceof ISourceReference) {
4034 // fOutlinePage.removeSelectionChangedListener(fSelectionChangedListener);
4035 // fOutlinePage.select((ISourceReference) element);
4036 // fOutlinePage.addSelectionChangedListener(fSelectionChangedListener);
4040 protected void setSelection(ISourceReference reference, boolean moveCursor) {
4042 ISelection selection = getSelectionProvider().getSelection();
4043 if (selection instanceof TextSelection) {
4044 TextSelection textSelection = (TextSelection) selection;
4045 if (textSelection.getOffset() != 0
4046 || textSelection.getLength() != 0)
4047 markInNavigationHistory();
4050 if (reference != null) {
4052 StyledText textWidget = null;
4054 ISourceViewer sourceViewer = getSourceViewer();
4055 if (sourceViewer != null)
4056 textWidget = sourceViewer.getTextWidget();
4058 if (textWidget == null)
4063 ISourceRange range = reference.getSourceRange();
4067 int offset = range.getOffset();
4068 int length = range.getLength();
4070 if (offset < 0 || length < 0)
4073 textWidget.setRedraw(false);
4075 setHighlightRange(offset, length, moveCursor);
4083 if (reference instanceof IMember) {
4084 range = ((IMember) reference).getNameRange();
4085 if (range != null) {
4086 offset = range.getOffset();
4087 length = range.getLength();
4090 // else if (reference instanceof IImportDeclaration) {
4091 // String name= ((IImportDeclaration)
4092 // reference).getElementName();
4093 // if (name != null && name.length() > 0) {
4094 // String content= reference.getSource();
4095 // if (content != null) {
4096 // offset= range.getOffset() + content.indexOf(name);
4097 // length= name.length();
4100 // } else if (reference instanceof IPackageDeclaration) {
4101 // String name= ((IPackageDeclaration)
4102 // reference).getElementName();
4103 // if (name != null && name.length() > 0) {
4104 // String content= reference.getSource();
4105 // if (content != null) {
4106 // offset= range.getOffset() + content.indexOf(name);
4107 // length= name.length();
4112 if (offset > -1 && length > 0) {
4113 sourceViewer.revealRange(offset, length);
4114 sourceViewer.setSelectedRange(offset, length);
4117 } catch (JavaModelException x) {
4118 } catch (IllegalArgumentException x) {
4120 if (textWidget != null)
4121 textWidget.setRedraw(true);
4124 } else if (moveCursor) {
4125 resetHighlightRange();
4128 markInNavigationHistory();
4131 public void setSelection(IJavaElement element) {
4132 if (element == null || element instanceof ICompilationUnit) { // ||
4138 * If the element is an ICompilationUnit this unit is either the
4139 * input of this editor or not being displayed. In both cases,
4140 * nothing should happened.
4141 * (http://dev.eclipse.org/bugs/show_bug.cgi?id=5128)
4146 IJavaElement corresponding = getCorrespondingElement(element);
4147 if (corresponding instanceof ISourceReference) {
4148 ISourceReference reference = (ISourceReference) corresponding;
4149 // set highlight range
4150 setSelection(reference, true);
4151 // set outliner selection
4152 if (fOutlinePage != null) {
4153 fOutlineSelectionChangedListener.uninstall(fOutlinePage);
4154 fOutlinePage.select(reference);
4155 fOutlineSelectionChangedListener.install(fOutlinePage);
4160 public synchronized void editingScriptStarted() {
4161 ++fIgnoreOutlinePageSelection;
4164 public synchronized void editingScriptEnded() {
4165 --fIgnoreOutlinePageSelection;
4168 public synchronized boolean isEditingScriptRunning() {
4169 return (fIgnoreOutlinePageSelection > 0);
4173 * The <code>PHPEditor</code> implementation of this
4174 * <code>AbstractTextEditor</code> method performs gets the java content
4175 * outline page if request is for a an outline page.
4177 public Object getAdapter(Class required) {
4179 if (IContentOutlinePage.class.equals(required)) {
4180 if (fOutlinePage == null)
4181 fOutlinePage = createOutlinePage();
4182 return fOutlinePage;
4185 if (IEncodingSupport.class.equals(required))
4186 return fEncodingSupport;
4188 if (required == IShowInTargetList.class) {
4189 return new IShowInTargetList() {
4190 public String[] getShowInTargetIds() {
4191 return new String[] { JavaUI.ID_PACKAGES,
4192 IPageLayout.ID_OUTLINE, IPageLayout.ID_RES_NAV };
4197 if (fProjectionSupport != null) {
4198 Object adapter = fProjectionSupport.getAdapter(getSourceViewer(),
4200 if (adapter != null)
4204 return super.getAdapter(required);
4207 // public Object getAdapter(Class required) {
4208 // if (IContentOutlinePage.class.equals(required)) {
4209 // if (fOutlinePage == null) {
4210 // fOutlinePage = new PHPContentOutlinePage(getDocumentProvider(), this);
4211 // if (getEditorInput() != null)
4212 // fOutlinePage.setInput(getEditorInput());
4214 // return fOutlinePage;
4217 // if (IEncodingSupport.class.equals(required))
4218 // return fEncodingSupport;
4220 // return super.getAdapter(required);
4223 protected void doSelectionChanged(SelectionChangedEvent event) {
4224 ISourceReference reference = null;
4226 ISelection selection = event.getSelection();
4227 Iterator iter = ((IStructuredSelection) selection).iterator();
4228 while (iter.hasNext()) {
4229 Object o = iter.next();
4230 if (o instanceof ISourceReference) {
4231 reference = (ISourceReference) o;
4236 if (!isActivePart() && PHPeclipsePlugin.getActivePage() != null)
4237 PHPeclipsePlugin.getActivePage().bringToTop(this);
4240 editingScriptStarted();
4241 setSelection(reference, !isActivePart());
4243 editingScriptEnded();
4248 * @see AbstractTextEditor#adjustHighlightRange(int, int)
4250 protected void adjustHighlightRange(int offset, int length) {
4254 IJavaElement element = getElementAt(offset);
4255 while (element instanceof ISourceReference) {
4256 ISourceRange range = ((ISourceReference) element)
4258 if (offset < range.getOffset() + range.getLength()
4259 && range.getOffset() < offset + length) {
4261 ISourceViewer viewer = getSourceViewer();
4262 if (viewer instanceof ITextViewerExtension5) {
4263 ITextViewerExtension5 extension = (ITextViewerExtension5) viewer;
4264 extension.exposeModelRange(new Region(
4265 range.getOffset(), range.getLength()));
4268 setHighlightRange(range.getOffset(), range.getLength(),
4270 if (fOutlinePage != null) {
4271 fOutlineSelectionChangedListener
4272 .uninstall(fOutlinePage);
4273 fOutlinePage.select((ISourceReference) element);
4274 fOutlineSelectionChangedListener.install(fOutlinePage);
4279 element = element.getParent();
4282 } catch (JavaModelException x) {
4283 PHPeclipsePlugin.log(x.getStatus());
4286 ISourceViewer viewer = getSourceViewer();
4287 if (viewer instanceof ITextViewerExtension5) {
4288 ITextViewerExtension5 extension = (ITextViewerExtension5) viewer;
4289 extension.exposeModelRange(new Region(offset, length));
4291 resetHighlightRange();
4296 protected boolean isActivePart() {
4297 IWorkbenchWindow window = getSite().getWorkbenchWindow();
4298 IPartService service = window.getPartService();
4299 IWorkbenchPart part = service.getActivePart();
4300 return part != null && part.equals(this);
4303 // public void openContextHelp() {
4305 // this.getDocumentProvider().getDocument(this.getEditorInput());
4306 // ITextSelection selection = (ITextSelection)
4307 // this.getSelectionProvider().getSelection();
4308 // int pos = selection.getOffset();
4309 // String word = getFunctionName(doc, pos);
4310 // openContextHelp(word);
4313 // private void openContextHelp(String word) {
4317 // public static void open(String word) {
4318 // IHelp help = WorkbenchHelp.getHelpSupport();
4319 // if (help != null) {
4320 // IHelpResource helpResource = new PHPFunctionHelpResource(word);
4321 // WorkbenchHelp.getHelpSupport().displayHelpResource(helpResource);
4323 // // showMessage(shell, dialogTitle, ActionMessages.getString("Open help
4324 // not available"), false); //$NON-NLS-1$
4328 // private String getFunctionName(IDocument doc, int pos) {
4329 // Point word = PHPWordExtractor.findWord(doc, pos);
4330 // if (word != null) {
4332 // return doc.get(word.x, word.y).replace('_', '-');
4333 // } catch (BadLocationException e) {
4340 * @see AbstractTextEditor#handlePreferenceStoreChanged(PropertyChangeEvent)
4342 protected void handlePreferenceStoreChanged(PropertyChangeEvent event) {
4346 ISourceViewer sourceViewer = getSourceViewer();
4347 if (sourceViewer == null)
4350 String property = event.getProperty();
4352 if (PreferenceConstants.EDITOR_TAB_WIDTH.equals(property)) {
4353 Object value = event.getNewValue();
4354 if (value instanceof Integer) {
4355 sourceViewer.getTextWidget().setTabs(
4356 ((Integer) value).intValue());
4357 } else if (value instanceof String) {
4359 sourceViewer.getTextWidget().setTabs(
4360 Integer.parseInt((String) value));
4361 } catch (NumberFormatException e) {
4362 // bug #1038071 - set default tab:
4363 sourceViewer.getTextWidget().setTabs(80);
4369 // if (OVERVIEW_RULER.equals(property)) {
4370 // if (isOverviewRulerVisible())
4371 // showOverviewRuler();
4373 // hideOverviewRuler();
4377 // if (LINE_NUMBER_RULER.equals(property)) {
4378 // if (isLineNumberRulerVisible())
4379 // showLineNumberRuler();
4381 // hideLineNumberRuler();
4385 // if (fLineNumberRulerColumn != null
4386 // && (LINE_NUMBER_COLOR.equals(property) ||
4387 // PREFERENCE_COLOR_BACKGROUND_SYSTEM_DEFAULT.equals(property) ||
4388 // PREFERENCE_COLOR_BACKGROUND.equals(property))) {
4390 // initializeLineNumberRulerColumn(fLineNumberRulerColumn);
4393 if (isJavaEditorHoverProperty(property))
4394 updateHoverBehavior();
4396 if (BROWSER_LIKE_LINKS.equals(property)) {
4397 if (isBrowserLikeLinks())
4398 enableBrowserLikeLinks();
4400 disableBrowserLikeLinks();
4404 if (PreferenceConstants.EDITOR_DISABLE_OVERWRITE_MODE
4405 .equals(property)) {
4406 if (event.getNewValue() instanceof Boolean) {
4407 Boolean disable = (Boolean) event.getNewValue();
4408 enableOverwriteMode(!disable.booleanValue());
4413 boolean newBooleanValue = false;
4414 Object newValue = event.getNewValue();
4415 if (newValue != null)
4416 newBooleanValue = Boolean.valueOf(newValue.toString())
4419 if (PreferenceConstants.EDITOR_SYNC_OUTLINE_ON_CURSOR_MOVE
4420 .equals(property)) {
4421 if (newBooleanValue)
4426 if (PreferenceConstants.EDITOR_MARK_OCCURRENCES.equals(property)) {
4427 if (newBooleanValue != fMarkOccurrenceAnnotations) {
4428 fMarkOccurrenceAnnotations = newBooleanValue;
4429 if (!fMarkOccurrenceAnnotations)
4430 uninstallOccurrencesFinder();
4432 installOccurrencesFinder();
4437 if (PreferenceConstants.EDITOR_STICKY_OCCURRENCES.equals(property)) {
4438 fStickyOccurrenceAnnotations = newBooleanValue;
4444 // (PreferenceConstants.EDITOR_STICKY_OCCURRENCES.equals(property))
4446 // if (event.getNewValue() instanceof Boolean) {
4447 // boolean stickyOccurrenceAnnotations=
4448 // ((Boolean)event.getNewValue()).booleanValue();
4449 // if (stickyOccurrenceAnnotations != fStickyOccurrenceAnnotations)
4452 ((PHPSourceViewerConfiguration) getSourceViewerConfiguration())
4453 .handlePropertyChangeEvent(event);
4455 // if (affectsOverrideIndicatorAnnotations(event)) {
4456 // if (isShowingOverrideIndicators()) {
4457 // if (fOverrideIndicatorManager == null)
4458 // installOverrideIndicator(true);
4460 // if (fOverrideIndicatorManager != null)
4461 // uninstallOverrideIndicator();
4466 if (PreferenceConstants.EDITOR_FOLDING_PROVIDER.equals(property)) {
4467 if (sourceViewer instanceof ProjectionViewer) {
4468 ProjectionViewer projectionViewer = (ProjectionViewer) sourceViewer;
4469 if (fProjectionModelUpdater != null)
4470 fProjectionModelUpdater.uninstall();
4471 // either freshly enabled or provider changed
4472 fProjectionModelUpdater = PHPeclipsePlugin.getDefault()
4473 .getFoldingStructureProviderRegistry()
4474 .getCurrentFoldingProvider();
4475 if (fProjectionModelUpdater != null) {
4476 fProjectionModelUpdater.install(this, projectionViewer);
4482 super.handlePreferenceStoreChanged(event);
4488 // AbstractTextEditor#handlePreferenceStoreChanged(PropertyChangeEvent)
4490 // protected void handlePreferenceStoreChanged(PropertyChangeEvent event) {
4494 // ISourceViewer sourceViewer = getSourceViewer();
4495 // if (sourceViewer == null)
4498 // String property = event.getProperty();
4501 // (JavaSourceViewerConfiguration.PREFERENCE_TAB_WIDTH.equals(property)) {
4502 // // Object value= event.getNewValue();
4503 // // if (value instanceof Integer) {
4504 // // sourceViewer.getTextWidget().setTabs(((Integer) value).intValue());
4505 // // } else if (value instanceof String) {
4506 // // sourceViewer.getTextWidget().setTabs(Integer.parseInt((String)
4512 // if (IPreferenceConstants.LINE_NUMBER_RULER.equals(property)) {
4513 // if (isLineNumberRulerVisible())
4514 // showLineNumberRuler();
4516 // hideLineNumberRuler();
4520 // if (fLineNumberRulerColumn != null
4521 // && (IPreferenceConstants.LINE_NUMBER_COLOR.equals(property)
4522 // || PREFERENCE_COLOR_BACKGROUND_SYSTEM_DEFAULT.equals(property)
4523 // || PREFERENCE_COLOR_BACKGROUND.equals(property))) {
4525 // initializeLineNumberRulerColumn(fLineNumberRulerColumn);
4529 // super.handlePreferenceStoreChanged(event);
4533 // private boolean isJavaEditorHoverProperty(String property) {
4534 // return PreferenceConstants.EDITOR_DEFAULT_HOVER.equals(property)
4535 // || PreferenceConstants.EDITOR_NONE_HOVER.equals(property)
4536 // || PreferenceConstants.EDITOR_CTRL_HOVER.equals(property)
4537 // || PreferenceConstants.EDITOR_SHIFT_HOVER.equals(property)
4538 // || PreferenceConstants.EDITOR_CTRL_ALT_HOVER.equals(property)
4539 // || PreferenceConstants.EDITOR_CTRL_SHIFT_HOVER.equals(property)
4540 // || PreferenceConstants.EDITOR_CTRL_ALT_SHIFT_HOVER.equals(property)
4541 // || PreferenceConstants.EDITOR_ALT_SHIFT_HOVER.equals(property);
4545 * Shows the line number ruler column.
4547 // private void showLineNumberRuler() {
4548 // IVerticalRuler v = getVerticalRuler();
4549 // if (v instanceof CompositeRuler) {
4550 // CompositeRuler c = (CompositeRuler) v;
4551 // c.addDecorator(1, createLineNumberRulerColumn());
4554 private boolean isJavaEditorHoverProperty(String property) {
4555 return PreferenceConstants.EDITOR_TEXT_HOVER_MODIFIERS.equals(property);
4559 * Return whether the browser like links should be enabled according to the
4560 * preference store settings.
4562 * @return <code>true</code> if the browser like links should be enabled
4564 private boolean isBrowserLikeLinks() {
4565 IPreferenceStore store = getPreferenceStore();
4566 return store.getBoolean(BROWSER_LIKE_LINKS);
4570 * Enables browser like links.
4572 private void enableBrowserLikeLinks() {
4573 if (fMouseListener == null) {
4574 fMouseListener = new MouseClickListener();
4575 fMouseListener.install();
4580 * Disables browser like links.
4582 private void disableBrowserLikeLinks() {
4583 if (fMouseListener != null) {
4584 fMouseListener.uninstall();
4585 fMouseListener = null;
4590 * Handles a property change event describing a change of the java core's
4591 * preferences and updates the preference related editor properties.
4594 * the property change event
4596 protected void handlePreferencePropertyChanged(
4597 org.eclipse.core.runtime.Preferences.PropertyChangeEvent event) {
4598 if (COMPILER_TASK_TAGS.equals(event.getProperty())) {
4599 ISourceViewer sourceViewer = getSourceViewer();
4600 if (sourceViewer != null
4601 && affectsTextPresentation(new PropertyChangeEvent(event
4602 .getSource(), event.getProperty(), event
4603 .getOldValue(), event.getNewValue())))
4604 sourceViewer.invalidateTextPresentation();
4606 if (PreferenceConstants.EDITOR_WRAP_WORDS.equals(event.getProperty())) {
4612 * Return whether the line number ruler column should be visible according
4613 * to the preference store settings.
4615 * @return <code>true</code> if the line numbers should be visible
4617 // protected boolean isLineNumberRulerVisible() {
4618 // IPreferenceStore store = getPreferenceStore();
4619 // return store.getBoolean(LINE_NUMBER_RULER);
4622 * Hides the line number ruler column.
4624 // private void hideLineNumberRuler() {
4625 // IVerticalRuler v = getVerticalRuler();
4626 // if (v instanceof CompositeRuler) {
4627 // CompositeRuler c = (CompositeRuler) v;
4629 // c.removeDecorator(1);
4630 // } catch (Throwable e) {
4635 * @see AbstractTextEditor#handleCursorPositionChanged()
4637 // protected void handleCursorPositionChanged() {
4638 // super.handleCursorPositionChanged();
4639 // if (!isEditingScriptRunning() && fUpdater != null)
4643 * @see org.eclipse.ui.texteditor.AbstractTextEditor#handleElementContentReplaced()
4645 protected void handleElementContentReplaced() {
4646 super.handleElementContentReplaced();
4647 if (fProjectionModelUpdater != null)
4648 fProjectionModelUpdater.initialize();
4652 * Initializes the given line number ruler column from the preference store.
4654 * @param rulerColumn
4655 * the ruler column to be initialized
4657 // protected void initializeLineNumberRulerColumn(LineNumberRulerColumn
4659 // JavaTextTools textTools =
4660 // PHPeclipsePlugin.getDefault().getJavaTextTools();
4661 // IColorManager manager = textTools.getColorManager();
4663 // IPreferenceStore store = getPreferenceStore();
4664 // if (store != null) {
4667 // // foreground color
4668 // if (store.contains(LINE_NUMBER_COLOR)) {
4669 // if (store.isDefault(LINE_NUMBER_COLOR))
4670 // rgb = PreferenceConverter.getDefaultColor(store, LINE_NUMBER_COLOR);
4672 // rgb = PreferenceConverter.getColor(store, LINE_NUMBER_COLOR);
4674 // rulerColumn.setForeground(manager.getColor(rgb));
4677 // // background color
4678 // if (!store.getBoolean(PREFERENCE_COLOR_BACKGROUND_SYSTEM_DEFAULT)) {
4679 // if (store.contains(PREFERENCE_COLOR_BACKGROUND)) {
4680 // if (store.isDefault(PREFERENCE_COLOR_BACKGROUND))
4681 // rgb = PreferenceConverter.getDefaultColor(store,
4682 // PREFERENCE_COLOR_BACKGROUND);
4684 // rgb = PreferenceConverter.getColor(store, PREFERENCE_COLOR_BACKGROUND);
4687 // rulerColumn.setBackground(manager.getColor(rgb));
4691 * Creates a new line number ruler column that is appropriately initialized.
4693 // protected IVerticalRulerColumn createLineNumberRulerColumn() {
4694 // fLineNumberRulerColumn = new LineNumberRulerColumn();
4695 // initializeLineNumberRulerColumn(fLineNumberRulerColumn);
4696 // return fLineNumberRulerColumn;
4699 * @see AbstractTextEditor#createVerticalRuler()
4701 // protected IVerticalRuler createVerticalRuler() {
4702 // CompositeRuler ruler = new CompositeRuler();
4703 // ruler.addDecorator(0, new AnnotationRulerColumn(VERTICAL_RULER_WIDTH));
4704 // if (isLineNumberRulerVisible())
4705 // ruler.addDecorator(1, createLineNumberRulerColumn());
4708 // private static IRegion getSignedSelection(ITextViewer viewer) {
4710 // StyledText text = viewer.getTextWidget();
4711 // int caretOffset = text.getCaretOffset();
4712 // Point selection = text.getSelection();
4715 // int offset, length;
4716 // if (caretOffset == selection.x) {
4717 // offset = selection.y;
4718 // length = selection.x - selection.y;
4722 // offset = selection.x;
4723 // length = selection.y - selection.x;
4726 // return new Region(offset, length);
4728 protected IRegion getSignedSelection(ISourceViewer sourceViewer) {
4729 StyledText text = sourceViewer.getTextWidget();
4730 Point selection = text.getSelectionRange();
4732 if (text.getCaretOffset() == selection.x) {
4733 selection.x = selection.x + selection.y;
4734 selection.y = -selection.y;
4737 selection.x = widgetOffset2ModelOffset(sourceViewer, selection.x);
4739 return new Region(selection.x, selection.y);
4742 /** Preference key for matching brackets */
4743 protected final static String MATCHING_BRACKETS = PreferenceConstants.EDITOR_MATCHING_BRACKETS;
4745 /** Preference key for matching brackets color */
4746 protected final static String MATCHING_BRACKETS_COLOR = PreferenceConstants.EDITOR_MATCHING_BRACKETS_COLOR;
4748 /** Preference key for highlighting current line */
4749 // protected final static String CURRENT_LINE =
4750 // PreferenceConstants.EDITOR_CURRENT_LINE;
4751 /** Preference key for highlight color of current line */
4752 // protected final static String CURRENT_LINE_COLOR =
4753 // PreferenceConstants.EDITOR_CURRENT_LINE_COLOR;
4754 /** Preference key for showing print marging ruler */
4755 // protected final static String PRINT_MARGIN =
4756 // PreferenceConstants.EDITOR_PRINT_MARGIN;
4757 /** Preference key for print margin ruler color */
4758 // protected final static String PRINT_MARGIN_COLOR =
4759 // PreferenceConstants.EDITOR_PRINT_MARGIN_COLOR;
4760 /** Preference key for print margin ruler column */
4761 // protected final static String PRINT_MARGIN_COLUMN =
4762 // PreferenceConstants.EDITOR_PRINT_MARGIN_COLUMN;
4763 /** Preference key for error indication */
4764 // protected final static String ERROR_INDICATION =
4765 // PreferenceConstants.EDITOR_PROBLEM_INDICATION;
4766 /** Preference key for error color */
4767 // protected final static String ERROR_INDICATION_COLOR =
4768 // PreferenceConstants.EDITOR_PROBLEM_INDICATION_COLOR;
4769 /** Preference key for warning indication */
4770 // protected final static String WARNING_INDICATION =
4771 // PreferenceConstants.EDITOR_WARNING_INDICATION;
4772 /** Preference key for warning color */
4773 // protected final static String WARNING_INDICATION_COLOR =
4774 // PreferenceConstants.EDITOR_WARNING_INDICATION_COLOR;
4775 /** Preference key for task indication */
4776 protected final static String TASK_INDICATION = PreferenceConstants.EDITOR_TASK_INDICATION;
4778 /** Preference key for task color */
4779 protected final static String TASK_INDICATION_COLOR = PreferenceConstants.EDITOR_TASK_INDICATION_COLOR;
4781 /** Preference key for bookmark indication */
4782 protected final static String BOOKMARK_INDICATION = PreferenceConstants.EDITOR_BOOKMARK_INDICATION;
4784 /** Preference key for bookmark color */
4785 protected final static String BOOKMARK_INDICATION_COLOR = PreferenceConstants.EDITOR_BOOKMARK_INDICATION_COLOR;
4787 /** Preference key for search result indication */
4788 protected final static String SEARCH_RESULT_INDICATION = PreferenceConstants.EDITOR_SEARCH_RESULT_INDICATION;
4790 /** Preference key for search result color */
4791 protected final static String SEARCH_RESULT_INDICATION_COLOR = PreferenceConstants.EDITOR_SEARCH_RESULT_INDICATION_COLOR;
4793 /** Preference key for unknown annotation indication */
4794 protected final static String UNKNOWN_INDICATION = PreferenceConstants.EDITOR_UNKNOWN_INDICATION;
4796 /** Preference key for unknown annotation color */
4797 protected final static String UNKNOWN_INDICATION_COLOR = PreferenceConstants.EDITOR_UNKNOWN_INDICATION_COLOR;
4799 /** Preference key for shwoing the overview ruler */
4800 protected final static String OVERVIEW_RULER = PreferenceConstants.EDITOR_OVERVIEW_RULER;
4802 /** Preference key for error indication in overview ruler */
4803 protected final static String ERROR_INDICATION_IN_OVERVIEW_RULER = PreferenceConstants.EDITOR_ERROR_INDICATION_IN_OVERVIEW_RULER;
4805 /** Preference key for warning indication in overview ruler */
4806 protected final static String WARNING_INDICATION_IN_OVERVIEW_RULER = PreferenceConstants.EDITOR_WARNING_INDICATION_IN_OVERVIEW_RULER;
4808 /** Preference key for task indication in overview ruler */
4809 protected final static String TASK_INDICATION_IN_OVERVIEW_RULER = PreferenceConstants.EDITOR_TASK_INDICATION_IN_OVERVIEW_RULER;
4811 /** Preference key for bookmark indication in overview ruler */
4812 protected final static String BOOKMARK_INDICATION_IN_OVERVIEW_RULER = PreferenceConstants.EDITOR_BOOKMARK_INDICATION_IN_OVERVIEW_RULER;
4814 /** Preference key for search result indication in overview ruler */
4815 protected final static String SEARCH_RESULT_INDICATION_IN_OVERVIEW_RULER = PreferenceConstants.EDITOR_SEARCH_RESULT_INDICATION_IN_OVERVIEW_RULER;
4817 /** Preference key for unknown annotation indication in overview ruler */
4818 protected final static String UNKNOWN_INDICATION_IN_OVERVIEW_RULER = PreferenceConstants.EDITOR_UNKNOWN_INDICATION_IN_OVERVIEW_RULER;
4820 // /** Preference key for compiler task tags */
4821 // private final static String COMPILER_TASK_TAGS=
4822 // JavaCore.COMPILER_TASK_TAGS;
4823 /** Preference key for browser like links */
4824 private final static String BROWSER_LIKE_LINKS = PreferenceConstants.EDITOR_BROWSER_LIKE_LINKS;
4826 /** Preference key for key modifier of browser like links */
4827 private final static String BROWSER_LIKE_LINKS_KEY_MODIFIER = PreferenceConstants.EDITOR_BROWSER_LIKE_LINKS_KEY_MODIFIER;
4830 * Preference key for key modifier mask of browser like links. The value is
4831 * only used if the value of <code>EDITOR_BROWSER_LIKE_LINKS</code> cannot
4832 * be resolved to valid SWT modifier bits.
4836 private final static String BROWSER_LIKE_LINKS_KEY_MODIFIER_MASK = PreferenceConstants.EDITOR_BROWSER_LIKE_LINKS_KEY_MODIFIER_MASK;
4838 private final static char[] BRACKETS = { '{', '}', '(', ')', '[', ']' };
4840 private static boolean isBracket(char character) {
4841 for (int i = 0; i != BRACKETS.length; ++i)
4842 if (character == BRACKETS[i])
4847 private static boolean isSurroundedByBrackets(IDocument document, int offset) {
4848 if (offset == 0 || offset == document.getLength())
4852 return isBracket(document.getChar(offset - 1))
4853 && isBracket(document.getChar(offset));
4855 } catch (BadLocationException e) {
4860 // protected void configureSourceViewerDecorationSupport() {
4862 // fSourceViewerDecorationSupport.setCharacterPairMatcher(fBracketMatcher);
4864 // fSourceViewerDecorationSupport.setAnnotationPainterPreferenceKeys(
4865 // AnnotationType.UNKNOWN,
4866 // UNKNOWN_INDICATION_COLOR,
4867 // UNKNOWN_INDICATION,
4868 // UNKNOWN_INDICATION_IN_OVERVIEW_RULER,
4870 // fSourceViewerDecorationSupport.setAnnotationPainterPreferenceKeys(
4871 // AnnotationType.BOOKMARK,
4872 // BOOKMARK_INDICATION_COLOR,
4873 // BOOKMARK_INDICATION,
4874 // BOOKMARK_INDICATION_IN_OVERVIEW_RULER,
4876 // fSourceViewerDecorationSupport.setAnnotationPainterPreferenceKeys(
4877 // AnnotationType.TASK,
4878 // TASK_INDICATION_COLOR,
4880 // TASK_INDICATION_IN_OVERVIEW_RULER,
4882 // fSourceViewerDecorationSupport.setAnnotationPainterPreferenceKeys(
4883 // AnnotationType.SEARCH,
4884 // SEARCH_RESULT_INDICATION_COLOR,
4885 // SEARCH_RESULT_INDICATION,
4886 // SEARCH_RESULT_INDICATION_IN_OVERVIEW_RULER,
4888 // fSourceViewerDecorationSupport.setAnnotationPainterPreferenceKeys(
4889 // AnnotationType.WARNING,
4890 // WARNING_INDICATION_COLOR,
4891 // WARNING_INDICATION,
4892 // WARNING_INDICATION_IN_OVERVIEW_RULER,
4894 // fSourceViewerDecorationSupport.setAnnotationPainterPreferenceKeys(
4895 // AnnotationType.ERROR,
4896 // ERROR_INDICATION_COLOR,
4897 // ERROR_INDICATION,
4898 // ERROR_INDICATION_IN_OVERVIEW_RULER,
4901 // fSourceViewerDecorationSupport.setCursorLinePainterPreferenceKeys(CURRENT_LINE,
4902 // CURRENT_LINE_COLOR);
4903 // fSourceViewerDecorationSupport.setMarginPainterPreferenceKeys(PRINT_MARGIN,
4904 // PRINT_MARGIN_COLOR, PRINT_MARGIN_COLUMN);
4905 // fSourceViewerDecorationSupport.setMatchingCharacterPainterPreferenceKeys(MATCHING_BRACKETS,
4906 // MATCHING_BRACKETS_COLOR);
4908 // fSourceViewerDecorationSupport.setSymbolicFontName(getFontPropertyPreferenceKey());
4912 * Returns the Java element wrapped by this editors input.
4914 * @return the Java element wrapped by this editors input.
4917 abstract protected IJavaElement getInputJavaElement();
4919 protected void updateStatusLine() {
4920 ITextSelection selection = (ITextSelection) getSelectionProvider()
4922 Annotation annotation = getAnnotation(selection.getOffset(), selection
4924 setStatusLineErrorMessage(null);
4925 setStatusLineMessage(null);
4926 if (annotation != null) {
4928 fIsUpdatingAnnotationViews = true;
4929 updateAnnotationViews(annotation);
4931 fIsUpdatingAnnotationViews = false;
4933 if (annotation instanceof IJavaAnnotation
4934 && ((IJavaAnnotation) annotation).isProblem())
4935 setStatusLineMessage(annotation.getText());
4940 * Jumps to the matching bracket.
4942 public void gotoMatchingBracket() {
4944 ISourceViewer sourceViewer = getSourceViewer();
4945 IDocument document = sourceViewer.getDocument();
4946 if (document == null)
4949 IRegion selection = getSignedSelection(sourceViewer);
4951 int selectionLength = Math.abs(selection.getLength());
4952 if (selectionLength > 1) {
4953 setStatusLineErrorMessage(PHPEditorMessages
4954 .getString("GotoMatchingBracket.error.invalidSelection")); //$NON-NLS-1$
4955 sourceViewer.getTextWidget().getDisplay().beep();
4960 int sourceCaretOffset = selection.getOffset() + selection.getLength();
4961 if (isSurroundedByBrackets(document, sourceCaretOffset))
4962 sourceCaretOffset -= selection.getLength();
4964 IRegion region = fBracketMatcher.match(document, sourceCaretOffset);
4965 if (region == null) {
4966 setStatusLineErrorMessage(PHPEditorMessages
4967 .getString("GotoMatchingBracket.error.noMatchingBracket")); //$NON-NLS-1$
4968 sourceViewer.getTextWidget().getDisplay().beep();
4972 int offset = region.getOffset();
4973 int length = region.getLength();
4978 int anchor = fBracketMatcher.getAnchor();
4979 int targetOffset = (PHPPairMatcher.RIGHT == anchor) ? offset : offset
4982 boolean visible = false;
4983 if (sourceViewer instanceof ITextViewerExtension5) {
4984 ITextViewerExtension5 extension = (ITextViewerExtension5) sourceViewer;
4985 visible = (extension.modelOffset2WidgetOffset(targetOffset) > -1);
4987 IRegion visibleRegion = sourceViewer.getVisibleRegion();
4988 visible = (targetOffset >= visibleRegion.getOffset() && targetOffset < visibleRegion
4990 + visibleRegion.getLength());
4994 setStatusLineErrorMessage(PHPEditorMessages
4995 .getString("GotoMatchingBracket.error.bracketOutsideSelectedElement")); //$NON-NLS-1$
4996 sourceViewer.getTextWidget().getDisplay().beep();
5000 if (selection.getLength() < 0)
5001 targetOffset -= selection.getLength();
5003 sourceViewer.setSelectedRange(targetOffset, selection.getLength());
5004 sourceViewer.revealRange(targetOffset, selection.getLength());
5008 * Ses the given message as error message to this editor's status line.
5013 protected void setStatusLineErrorMessage(String msg) {
5014 IEditorStatusLine statusLine = (IEditorStatusLine) getAdapter(IEditorStatusLine.class);
5015 if (statusLine != null)
5016 statusLine.setMessage(true, msg, null);
5020 * Sets the given message as message to this editor's status line.
5026 protected void setStatusLineMessage(String msg) {
5027 IEditorStatusLine statusLine = (IEditorStatusLine) getAdapter(IEditorStatusLine.class);
5028 if (statusLine != null)
5029 statusLine.setMessage(false, msg, null);
5033 * Returns the annotation closest to the given range respecting the given
5034 * direction. If an annotation is found, the annotations current position is
5035 * copied into the provided annotation position.
5042 * <code>true</code> for forwards, <code>false</code> for
5044 * @param annotationPosition
5045 * the position of the found annotation
5046 * @return the found annotation
5048 private Annotation getNextAnnotation(final int offset, final int length,
5049 boolean forward, Position annotationPosition) {
5051 Annotation nextAnnotation = null;
5052 Position nextAnnotationPosition = null;
5053 Annotation containingAnnotation = null;
5054 Position containingAnnotationPosition = null;
5055 boolean currentAnnotation = false;
5057 IDocument document = getDocumentProvider()
5058 .getDocument(getEditorInput());
5059 int endOfDocument = document.getLength();
5060 int distance = Integer.MAX_VALUE;
5062 IAnnotationModel model = getDocumentProvider().getAnnotationModel(
5064 Iterator e = new JavaAnnotationIterator(model, true, true);
5065 while (e.hasNext()) {
5066 Annotation a = (Annotation) e.next();
5067 if ((a instanceof IJavaAnnotation)
5068 && ((IJavaAnnotation) a).hasOverlay()
5069 || !isNavigationTarget(a))
5072 Position p = model.getPosition(a);
5076 if (forward && p.offset == offset || !forward
5077 && p.offset + p.getLength() == offset + length) {// ||
5078 // p.includes(offset))
5080 if (containingAnnotation == null
5082 && p.length >= containingAnnotationPosition.length || !forward
5083 && p.length >= containingAnnotationPosition.length)) {
5084 containingAnnotation = a;
5085 containingAnnotationPosition = p;
5086 currentAnnotation = p.length == length;
5089 int currentDistance = 0;
5092 currentDistance = p.getOffset() - offset;
5093 if (currentDistance < 0)
5094 currentDistance = endOfDocument + currentDistance;
5096 if (currentDistance < distance
5097 || currentDistance == distance
5098 && p.length < nextAnnotationPosition.length) {
5099 distance = currentDistance;
5101 nextAnnotationPosition = p;
5104 currentDistance = offset + length
5105 - (p.getOffset() + p.length);
5106 if (currentDistance < 0)
5107 currentDistance = endOfDocument + currentDistance;
5109 if (currentDistance < distance
5110 || currentDistance == distance
5111 && p.length < nextAnnotationPosition.length) {
5112 distance = currentDistance;
5114 nextAnnotationPosition = p;
5119 if (containingAnnotationPosition != null
5120 && (!currentAnnotation || nextAnnotation == null)) {
5121 annotationPosition.setOffset(containingAnnotationPosition
5123 annotationPosition.setLength(containingAnnotationPosition
5125 return containingAnnotation;
5127 if (nextAnnotationPosition != null) {
5128 annotationPosition.setOffset(nextAnnotationPosition.getOffset());
5129 annotationPosition.setLength(nextAnnotationPosition.getLength());
5132 return nextAnnotation;
5136 * Returns the annotation overlapping with the given range or
5137 * <code>null</code>.
5143 * @return the found annotation or <code>null</code>
5146 private Annotation getAnnotation(int offset, int length) {
5147 IAnnotationModel model = getDocumentProvider().getAnnotationModel(
5149 Iterator e = new JavaAnnotationIterator(model, true, true);
5150 while (e.hasNext()) {
5151 Annotation a = (Annotation) e.next();
5152 if (!isNavigationTarget(a))
5155 Position p = model.getPosition(a);
5156 if (p != null && p.overlapsWith(offset, length))
5164 * Returns whether the given annotation is configured as a target for the
5165 * "Go to Next/Previous Annotation" actions
5169 * @return <code>true</code> if this is a target, <code>false</code>
5173 protected boolean isNavigationTarget(Annotation annotation) {
5174 Preferences preferences = EditorsUI.getPluginPreferences();
5175 AnnotationPreference preference = getAnnotationPreferenceLookup()
5176 .getAnnotationPreference(annotation);
5178 // String key= forward ? preference.getIsGoToNextNavigationTargetKey() :
5179 // preference.getIsGoToPreviousNavigationTargetKey();
5180 String key = preference == null ? null : preference
5181 .getIsGoToNextNavigationTargetKey();
5182 return (key != null && preferences.getBoolean(key));
5186 * Returns a segmentation of the line of the given document appropriate for
5187 * bidi rendering. The default implementation returns only the string
5188 * literals of a php code line as segments.
5193 * the offset of the line
5194 * @return the line's bidi segmentation
5195 * @throws BadLocationException
5196 * in case lineOffset is not valid in document
5198 public static int[] getBidiLineSegments(IDocument document, int lineOffset)
5199 throws BadLocationException {
5201 IRegion line = document.getLineInformationOfOffset(lineOffset);
5202 ITypedRegion[] linePartitioning = document.computePartitioning(
5203 lineOffset, line.getLength());
5205 List segmentation = new ArrayList();
5206 for (int i = 0; i < linePartitioning.length; i++) {
5207 if (IPHPPartitions.PHP_STRING_DQ.equals(linePartitioning[i]
5209 segmentation.add(linePartitioning[i]);
5210 } else if (IPHPPartitions.PHP_STRING_HEREDOC
5211 .equals(linePartitioning[i].getType())) {
5212 segmentation.add(linePartitioning[i]);
5216 if (segmentation.size() == 0)
5219 int size = segmentation.size();
5220 int[] segments = new int[size * 2 + 1];
5223 for (int i = 0; i < size; i++) {
5224 ITypedRegion segment = (ITypedRegion) segmentation.get(i);
5229 int offset = segment.getOffset() - lineOffset;
5230 if (offset > segments[j - 1])
5231 segments[j++] = offset;
5233 if (offset + segment.getLength() >= line.getLength())
5236 segments[j++] = offset + segment.getLength();
5239 if (j < segments.length) {
5240 int[] result = new int[j];
5241 System.arraycopy(segments, 0, result, 0, j);
5249 * Returns a segmentation of the given line appropriate for bidi rendering.
5250 * The default implementation returns only the string literals of a php code
5254 * the offset of the line
5256 * the content of the line
5257 * @return the line's bidi segmentation
5259 protected int[] getBidiLineSegments(int lineOffset, String line) {
5260 IDocumentProvider provider = getDocumentProvider();
5261 if (provider != null && line != null && line.length() > 0) {
5262 IDocument document = provider.getDocument(getEditorInput());
5263 if (document != null)
5265 return getBidiLineSegments(document, lineOffset);
5266 } catch (BadLocationException x) {
5274 * @see AbstractTextEditor#createSourceViewer(Composite, IVerticalRuler,
5277 // protected final ISourceViewer createSourceViewer(
5278 // Composite parent,
5279 // IVerticalRuler ruler,
5281 // ISourceViewer viewer = createJavaSourceViewer(parent, ruler, styles);
5282 // StyledText text = viewer.getTextWidget();
5283 // text.addBidiSegmentListener(new BidiSegmentListener() {
5284 // public void lineGetSegments(BidiSegmentEvent event) {
5285 // event.segments = getBidiLineSegments(event.lineOffset, event.lineText);
5288 // // JavaUIHelp.setHelp(this, text, IJavaHelpContextIds.JAVA_EDITOR);
5291 public final ISourceViewer getViewer() {
5292 return getSourceViewer();
5295 // protected void showOverviewRuler() {
5296 // if (fOverviewRuler != null) {
5297 // if (getSourceViewer() instanceof ISourceViewerExtension) {
5298 // ((ISourceViewerExtension)
5299 // getSourceViewer()).showAnnotationsOverview(true);
5300 // fSourceViewerDecorationSupport.updateOverviewDecorations();
5305 // protected void hideOverviewRuler() {
5306 // if (getSourceViewer() instanceof ISourceViewerExtension) {
5307 // fSourceViewerDecorationSupport.hideAnnotationOverview();
5308 // ((ISourceViewerExtension)
5309 // getSourceViewer()).showAnnotationsOverview(false);
5313 // protected boolean isOverviewRulerVisible() {
5314 // IPreferenceStore store = getPreferenceStore();
5315 // return store.getBoolean(OVERVIEW_RULER);
5318 * @see AbstractTextEditor#createSourceViewer(Composite, IVerticalRuler,
5321 // protected ISourceViewer createJavaSourceViewer(
5322 // Composite parent,
5323 // IVerticalRuler ruler,
5324 // IOverviewRuler overviewRuler,
5325 // boolean isOverviewRulerVisible,
5327 // return new SourceViewer(parent, ruler, overviewRuler,
5328 // isOverviewRulerVisible(), styles);
5331 * @see AbstractTextEditor#createSourceViewer(Composite, IVerticalRuler,
5334 protected ISourceViewer createJavaSourceViewer(Composite parent,
5335 IVerticalRuler verticalRuler, IOverviewRuler overviewRuler,
5336 boolean isOverviewRulerVisible, int styles, IPreferenceStore store) {
5337 return new JavaSourceViewer(parent, verticalRuler, getOverviewRuler(),
5338 isOverviewRulerVisible(), styles, store);
5342 * @see AbstractTextEditor#createSourceViewer(Composite, IVerticalRuler,
5345 protected final ISourceViewer createSourceViewer(Composite parent,
5346 IVerticalRuler verticalRuler, int styles) {
5348 ISourceViewer viewer = createJavaSourceViewer(parent, verticalRuler,
5349 getOverviewRuler(), isOverviewRulerVisible(), styles,
5350 getPreferenceStore());
5352 StyledText text = viewer.getTextWidget();
5353 text.addBidiSegmentListener(new BidiSegmentListener() {
5354 public void lineGetSegments(BidiSegmentEvent event) {
5355 event.segments = getBidiLineSegments(event.lineOffset,
5360 // JavaUIHelp.setHelp(this, text, IJavaHelpContextIds.JAVA_EDITOR);
5362 // ensure source viewer decoration support has been created and
5364 getSourceViewerDecorationSupport(viewer);
5370 * @see AbstractTextEditor#affectsTextPresentation(PropertyChangeEvent)
5372 protected boolean affectsTextPresentation(PropertyChangeEvent event) {
5373 return ((PHPSourceViewerConfiguration) getSourceViewerConfiguration())
5374 .affectsTextPresentation(event)
5375 || super.affectsTextPresentation(event);
5379 // protected boolean affectsTextPresentation(PropertyChangeEvent event) {
5380 // JavaTextTools textTools =
5381 // PHPeclipsePlugin.getDefault().getJavaTextTools();
5382 // return textTools.affectsBehavior(event);
5385 * Creates and returns the preference store for this Java editor with the
5389 * The editor input for which to create the preference store
5390 * @return the preference store for this editor
5394 private IPreferenceStore createCombinedPreferenceStore(IEditorInput input) {
5395 List stores = new ArrayList(3);
5397 IJavaProject project = EditorUtility.getJavaProject(input);
5398 if (project != null)
5399 stores.add(new OptionsAdapter(project.getOptions(false),
5400 PHPeclipsePlugin.getDefault().getMockupPreferenceStore(),
5401 new OptionsAdapter.IPropertyChangeEventFilter() {
5403 public boolean isFiltered(PropertyChangeEvent event) {
5404 IJavaElement inputJavaElement = getInputJavaElement();
5405 IJavaProject javaProject = inputJavaElement != null ? inputJavaElement
5408 if (javaProject == null)
5411 return !javaProject.getProject().equals(
5417 stores.add(PHPeclipsePlugin.getDefault().getPreferenceStore());
5418 stores.add(new PreferencesAdapter(JavaCore.getPlugin()
5419 .getPluginPreferences()));
5420 stores.add(EditorsUI.getPreferenceStore());
5422 return new ChainedPreferenceStore((IPreferenceStore[]) stores
5423 .toArray(new IPreferenceStore[stores.size()]));
5427 * Jumps to the error next according to the given direction.
5429 public void gotoError(boolean forward) {
5431 ISelectionProvider provider = getSelectionProvider();
5433 ITextSelection s = (ITextSelection) provider.getSelection();
5434 Position errorPosition = new Position(0, 0);
5435 IJavaAnnotation nextError = getNextError(s.getOffset(), forward,
5438 if (nextError != null) {
5440 IMarker marker = null;
5441 if (nextError instanceof MarkerAnnotation)
5442 marker = ((MarkerAnnotation) nextError).getMarker();
5444 Iterator e = nextError.getOverlaidIterator();
5446 while (e.hasNext()) {
5447 Object o = e.next();
5448 if (o instanceof MarkerAnnotation) {
5449 marker = ((MarkerAnnotation) o).getMarker();
5456 if (marker != null) {
5457 IWorkbenchPage page = getSite().getPage();
5458 IViewPart view = view = page
5459 .findView("org.eclipse.ui.views.TaskList"); //$NON-NLS-1$
5460 if (view instanceof TaskList) {
5461 StructuredSelection ss = new StructuredSelection(marker);
5462 ((TaskList) view).setSelection(ss, true);
5466 selectAndReveal(errorPosition.getOffset(), errorPosition
5468 // setStatusLineErrorMessage(nextError.getMessage());
5472 setStatusLineErrorMessage(null);
5477 private IJavaAnnotation getNextError(int offset, boolean forward,
5478 Position errorPosition) {
5480 IJavaAnnotation nextError = null;
5481 Position nextErrorPosition = null;
5483 IDocument document = getDocumentProvider()
5484 .getDocument(getEditorInput());
5485 int endOfDocument = document.getLength();
5488 IAnnotationModel model = getDocumentProvider().getAnnotationModel(
5490 Iterator e = new JavaAnnotationIterator(model, false);
5491 while (e.hasNext()) {
5493 IJavaAnnotation a = (IJavaAnnotation) e.next();
5494 if (a.hasOverlay() || !a.isProblem())
5497 Position p = model.getPosition((Annotation) a);
5498 if (!p.includes(offset)) {
5500 int currentDistance = 0;
5503 currentDistance = p.getOffset() - offset;
5504 if (currentDistance < 0)
5505 currentDistance = endOfDocument - offset
5508 currentDistance = offset - p.getOffset();
5509 if (currentDistance < 0)
5510 currentDistance = offset + endOfDocument
5514 if (nextError == null || currentDistance < distance) {
5515 distance = currentDistance;
5517 nextErrorPosition = p;
5522 if (nextErrorPosition != null) {
5523 errorPosition.setOffset(nextErrorPosition.getOffset());
5524 errorPosition.setLength(nextErrorPosition.getLength());
5530 protected void uninstallOverrideIndicator() {
5531 // if (fOverrideIndicatorManager != null) {
5532 // fOverrideIndicatorManager.removeAnnotations();
5533 // fOverrideIndicatorManager= null;
5537 protected void installOverrideIndicator(boolean waitForReconcilation) {
5538 uninstallOverrideIndicator();
5539 IAnnotationModel model = getDocumentProvider().getAnnotationModel(
5541 final IJavaElement inputElement = getInputJavaElement();
5543 if (model == null || inputElement == null)
5546 // fOverrideIndicatorManager= new OverrideIndicatorManager(model,
5547 // inputElement, null);
5549 // if (provideAST) {
5551 // Job(JavaEditorMessages.getString("OverrideIndicatorManager.intallJob"))
5556 // org.eclipse.core.runtime.jobs.Job#run(org.eclipse.core.runtime.IProgressMonitor)
5559 // protected IStatus run(IProgressMonitor monitor) {
5560 // CompilationUnit ast=
5561 // JavaPlugin.getDefault().getASTProvider().getAST(inputElement, true,
5563 // if (fOverrideIndicatorManager != null) // editor might have been
5566 // fOverrideIndicatorManager.reconciled(ast, true, monitor);
5567 // return Status.OK_STATUS;
5570 // job.setPriority(Job.DECORATE);
5571 // job.setSystem(true);
5577 * Tells whether override indicators are shown.
5579 * @return <code>true</code> if the override indicators are shown
5582 // protected boolean isShowingOverrideIndicators() {
5583 // AnnotationPreference preference=
5584 // getAnnotationPreferenceLookup().getAnnotationPreference(OverrideIndicatorManager.ANNOTATION_TYPE);
5585 // IPreferenceStore store= getPreferenceStore();
5586 // return getBoolean(store, preference.getHighlightPreferenceKey())
5587 // || getBoolean(store, preference.getVerticalRulerPreferenceKey())
5588 // || getBoolean(store, preference.getOverviewRulerPreferenceKey())
5589 // || getBoolean(store, preference.getTextPreferenceKey());
5592 * Returns the boolean preference for the given key.
5595 * the preference store
5597 * the preference key
5598 * @return <code>true</code> if the key exists in the store and its value
5599 * is <code>true</code>
5602 private boolean getBoolean(IPreferenceStore store, String key) {
5603 return key != null && store.getBoolean(key);
5606 protected boolean isPrefQuickDiffAlwaysOn() {
5607 return false; // never show change ruler for the non-editable java
5609 // Overridden in subclasses like PHPUnitEditor
5613 * @see org.eclipse.ui.texteditor.AbstractTextEditor#createNavigationActions()
5615 protected void createNavigationActions() {
5616 super.createNavigationActions();
5618 final StyledText textWidget = getSourceViewer().getTextWidget();
5620 IAction action = new SmartLineStartAction(textWidget, false);
5621 action.setActionDefinitionId(ITextEditorActionDefinitionIds.LINE_START);
5622 setAction(ITextEditorActionDefinitionIds.LINE_START, action);
5624 action = new SmartLineStartAction(textWidget, true);
5626 .setActionDefinitionId(ITextEditorActionDefinitionIds.SELECT_LINE_START);
5627 setAction(ITextEditorActionDefinitionIds.SELECT_LINE_START, action);
5629 action = new NavigatePreviousSubWordAction();
5631 .setActionDefinitionId(ITextEditorActionDefinitionIds.WORD_PREVIOUS);
5632 setAction(ITextEditorActionDefinitionIds.WORD_PREVIOUS, action);
5633 textWidget.setKeyBinding(SWT.CTRL | SWT.ARROW_LEFT, SWT.NULL);
5635 action = new NavigateNextSubWordAction();
5636 action.setActionDefinitionId(ITextEditorActionDefinitionIds.WORD_NEXT);
5637 setAction(ITextEditorActionDefinitionIds.WORD_NEXT, action);
5638 textWidget.setKeyBinding(SWT.CTRL | SWT.ARROW_RIGHT, SWT.NULL);
5640 action = new SelectPreviousSubWordAction();
5642 .setActionDefinitionId(ITextEditorActionDefinitionIds.SELECT_WORD_PREVIOUS);
5643 setAction(ITextEditorActionDefinitionIds.SELECT_WORD_PREVIOUS, action);
5644 textWidget.setKeyBinding(SWT.CTRL | SWT.SHIFT | SWT.ARROW_LEFT,
5647 action = new SelectNextSubWordAction();
5649 .setActionDefinitionId(ITextEditorActionDefinitionIds.SELECT_WORD_NEXT);
5650 setAction(ITextEditorActionDefinitionIds.SELECT_WORD_NEXT, action);
5651 textWidget.setKeyBinding(SWT.CTRL | SWT.SHIFT | SWT.ARROW_RIGHT,
5656 * @see org.eclipse.ui.texteditor.AbstractDecoratedTextEditor#createCompositeRuler()
5658 // protected CompositeRuler createCompositeRuler() {
5660 // (!getPreferenceStore().getBoolean(PreferenceConstants.EDITOR_ANNOTATION_ROLL_OVER))
5661 // return super.createCompositeRuler();
5663 // CompositeRuler ruler = new CompositeRuler();
5664 // AnnotationRulerColumn column = new
5665 // AnnotationRulerColumn(VERTICAL_RULER_WIDTH, getAnnotationAccess());
5666 // column.setHover(new JavaExpandHover(ruler, getAnnotationAccess(), new
5667 // IDoubleClickListener() {
5669 // public void doubleClick(DoubleClickEvent event) {
5670 // // for now: just invoke ruler double click action
5671 // triggerAction(ITextEditorActionConstants.RULER_DOUBLE_CLICK);
5674 // private void triggerAction(String actionID) {
5675 // IAction action = getAction(actionID);
5676 // if (action != null) {
5677 // if (action instanceof IUpdate)
5678 // ((IUpdate) action).update();
5679 // // hack to propagate line change
5680 // if (action instanceof ISelectionListener) {
5681 // ((ISelectionListener) action).selectionChanged(null, null);
5683 // if (action.isEnabled())
5689 // ruler.addDecorator(0, column);
5691 // if (isLineNumberRulerVisible())
5692 // ruler.addDecorator(1, createLineNumberRulerColumn());
5693 // else if (isPrefQuickDiffAlwaysOn())
5694 // ruler.addDecorator(1, createChangeRulerColumn());
5699 * @see org.eclipse.ui.texteditor.AbstractDecoratedTextEditor#createAnnotationRulerColumn(org.eclipse.jface.text.source.CompositeRuler)
5702 protected IVerticalRulerColumn createAnnotationRulerColumn(
5703 CompositeRuler ruler) {
5704 if (!getPreferenceStore().getBoolean(
5705 PreferenceConstants.EDITOR_ANNOTATION_ROLL_OVER))
5706 return super.createAnnotationRulerColumn(ruler);
5708 AnnotationRulerColumn column = new AnnotationRulerColumn(
5709 VERTICAL_RULER_WIDTH, getAnnotationAccess());
5710 column.setHover(new JavaExpandHover(ruler, getAnnotationAccess(),
5711 new IDoubleClickListener() {
5713 public void doubleClick(DoubleClickEvent event) {
5714 // for now: just invoke ruler double click action
5715 triggerAction(ITextEditorActionConstants.RULER_DOUBLE_CLICK);
5718 private void triggerAction(String actionID) {
5719 IAction action = getAction(actionID);
5720 if (action != null) {
5721 if (action instanceof IUpdate)
5722 ((IUpdate) action).update();
5723 // hack to propagate line change
5724 if (action instanceof ISelectionListener) {
5725 ((ISelectionListener) action).selectionChanged(
5728 if (action.isEnabled())
5739 * Returns the folding action group, or <code>null</code> if there is
5742 * @return the folding action group, or <code>null</code> if there is none
5745 protected FoldingActionGroup getFoldingActionGroup() {
5746 return fFoldingGroup;
5750 * @see org.eclipse.ui.texteditor.AbstractTextEditor#performRevert()
5752 protected void performRevert() {
5753 ProjectionViewer projectionViewer = (ProjectionViewer) getSourceViewer();
5754 projectionViewer.setRedraw(false);
5757 boolean projectionMode = projectionViewer.isProjectionMode();
5758 if (projectionMode) {
5759 projectionViewer.disableProjection();
5760 if (fProjectionModelUpdater != null)
5761 fProjectionModelUpdater.uninstall();
5764 super.performRevert();
5766 if (projectionMode) {
5767 if (fProjectionModelUpdater != null)
5768 fProjectionModelUpdater.install(this, projectionViewer);
5769 projectionViewer.enableProjection();
5773 projectionViewer.setRedraw(true);
5778 * React to changed selection.
5782 protected void selectionChanged() {
5783 if (getSelectionProvider() == null)
5785 ISourceReference element = computeHighlightRangeSourceReference();
5786 if (getPreferenceStore().getBoolean(
5787 PreferenceConstants.EDITOR_SYNC_OUTLINE_ON_CURSOR_MOVE))
5788 synchronizeOutlinePage(element);
5789 setSelection(element, false);
5793 private boolean isJavaOutlinePageActive() {
5794 IWorkbenchPart part = getActivePart();
5795 return part instanceof ContentOutline
5796 && ((ContentOutline) part).getCurrentPage() == fOutlinePage;
5799 private IWorkbenchPart getActivePart() {
5800 IWorkbenchWindow window = getSite().getWorkbenchWindow();
5801 IPartService service = window.getPartService();
5802 IWorkbenchPart part = service.getActivePart();
5807 * Computes and returns the source reference that includes the caret and
5808 * serves as provider for the outline page selection and the editor range
5811 * @return the computed source reference
5814 protected ISourceReference computeHighlightRangeSourceReference() {
5815 ISourceViewer sourceViewer = getSourceViewer();
5816 if (sourceViewer == null)
5819 StyledText styledText = sourceViewer.getTextWidget();
5820 if (styledText == null)
5824 if (sourceViewer instanceof ITextViewerExtension5) {
5825 ITextViewerExtension5 extension = (ITextViewerExtension5) sourceViewer;
5826 caret = extension.widgetOffset2ModelOffset(styledText
5829 int offset = sourceViewer.getVisibleRegion().getOffset();
5830 caret = offset + styledText.getCaretOffset();
5833 IJavaElement element = getElementAt(caret, false);
5835 if (!(element instanceof ISourceReference))
5838 if (element.getElementType() == IJavaElement.IMPORT_DECLARATION) {
5840 IImportDeclaration declaration = (IImportDeclaration) element;
5841 IImportContainer container = (IImportContainer) declaration
5843 ISourceRange srcRange = null;
5846 srcRange = container.getSourceRange();
5847 } catch (JavaModelException e) {
5850 if (srcRange != null && srcRange.getOffset() == caret)
5854 return (ISourceReference) element;
5858 * Returns the most narrow java element including the given offset.
5861 * the offset inside of the requested element
5863 * <code>true</code> if editor input should be reconciled in
5865 * @return the most narrow java element
5868 protected IJavaElement getElementAt(int offset, boolean reconcile) {
5869 return getElementAt(offset);
5872 public ShowInContext getShowInContext() {
5874 if(getEditorInput() instanceof FileStoreEditorInput){
5875 FileStoreEditorInput fei = (FileStoreEditorInput) getEditorInput();
5876 file = ResourcesPlugin.getWorkspace().getRoot().getFile(new Path(fei.getURI().getPath()));
5878 FileEditorInput fei = (FileEditorInput) getEditorInput();
5879 // added to fix ticket 637
5880 file = ResourcesPlugin.getWorkspace().getRoot().getFile(new Path(fei.getURI().getPath()));
5882 ShowInContext context = BrowserUtil.getShowInContext(file,
5884 if (context != null) {
5887 return new ShowInContext(file, null);
5890 public String[] getShowInTargetIds() {
5891 return new String[] { BrowserView.ID_BROWSER };
5895 * Updates the occurrences annotations based on the current selection.
5898 * the text selection
5900 * the compilation unit AST
5903 protected void updateOccurrenceAnnotations(ITextSelection selection) {// ,
5908 if (fOccurrencesFinderJob != null)
5909 fOccurrencesFinderJob.cancel();
5911 if (!fMarkOccurrenceAnnotations)
5914 // if (astRoot == null || selection == null)
5915 if (selection == null)
5918 IDocument document = getSourceViewer().getDocument();
5919 if (document == null)
5922 fMarkOccurrenceTargetRegion = null;
5923 if (document instanceof IDocumentExtension4) {
5924 int offset = selection.getOffset();
5925 long currentModificationStamp = ((IDocumentExtension4) document)
5926 .getModificationStamp();
5927 if (fMarkOccurrenceTargetRegion != null
5928 && currentModificationStamp == fMarkOccurrenceModificationStamp) {
5929 if (fMarkOccurrenceTargetRegion.getOffset() <= offset
5930 && offset <= fMarkOccurrenceTargetRegion.getOffset()
5931 + fMarkOccurrenceTargetRegion.getLength())
5934 fMarkOccurrenceTargetRegion = JavaWordFinder.findWord(document,
5936 fMarkOccurrenceModificationStamp = currentModificationStamp;
5939 if (fMarkOccurrenceTargetRegion == null
5940 || fMarkOccurrenceTargetRegion.getLength() == 0) {
5944 List matches = null;
5946 if (matches == null) {
5948 matches = new ArrayList();
5950 Scanner fScanner = new Scanner();
5951 fScanner.setSource(document.get().toCharArray());
5952 fScanner.setPHPMode(false);
5956 wordStr = document.get(fMarkOccurrenceTargetRegion.getOffset(),
5957 fMarkOccurrenceTargetRegion.getLength());
5958 if (wordStr != null) {
5959 word = wordStr.toCharArray();
5960 int fToken = ITerminalSymbols.TokenNameEOF;
5962 fToken = fScanner.getNextToken();
5963 while (fToken != ITerminalSymbols.TokenNameEOF) { // &&
5966 // TokenNameERROR) {
5967 if (fToken == ITerminalSymbols.TokenNameVariable
5968 || fToken == ITerminalSymbols.TokenNameIdentifier) {
5970 if (fScanner.equalsCurrentTokenSource(word)) {
5974 .getCurrentTokenStartPosition(),
5976 .getCurrentTokenEndPosition()
5978 .getCurrentTokenStartPosition()
5982 fToken = fScanner.getNextToken();
5984 } catch (InvalidInputException e) {
5986 } catch (SyntaxError e) {
5990 } catch (BadLocationException e1) {
5992 } catch (Exception e) {
5993 e.printStackTrace();
5999 if (matches == null || matches.size() == 0) {
6000 if (!fStickyOccurrenceAnnotations)
6001 removeOccurrenceAnnotations();
6005 Position[] positions = new Position[matches.size()];
6007 for (Iterator each = matches.iterator(); each.hasNext();) {
6008 IRegion currentNode = (IRegion) each.next();
6009 positions[i++] = new Position(currentNode.getOffset(), currentNode
6013 fOccurrencesFinderJob = new OccurrencesFinderJob(document, positions,
6015 // fOccurrencesFinderJob.setPriority(Job.DECORATE);
6016 // fOccurrencesFinderJob.setSystem(true);
6017 // fOccurrencesFinderJob.schedule();
6018 fOccurrencesFinderJob.run(new NullProgressMonitor());
6021 protected void installOccurrencesFinder() {
6022 fMarkOccurrenceAnnotations = true;
6024 fPostSelectionListenerWithAST = new ISelectionListenerWithAST() {
6025 public void selectionChanged(IEditorPart part,
6026 ITextSelection selection) { // ,
6030 updateOccurrenceAnnotations(selection);// , astRoot);
6033 SelectionListenerWithASTManager.getDefault().addListener(this,
6034 fPostSelectionListenerWithAST);
6035 if (getSelectionProvider() != null) {
6036 fForcedMarkOccurrencesSelection = getSelectionProvider()
6038 SelectionListenerWithASTManager.getDefault().forceSelectionChange(
6039 this, (ITextSelection) fForcedMarkOccurrencesSelection);
6042 if (fOccurrencesFinderJobCanceler == null) {
6043 fOccurrencesFinderJobCanceler = new OccurrencesFinderJobCanceler();
6044 fOccurrencesFinderJobCanceler.install();
6048 protected void uninstallOccurrencesFinder() {
6049 fMarkOccurrenceAnnotations = false;
6051 if (fOccurrencesFinderJob != null) {
6052 fOccurrencesFinderJob.cancel();
6053 fOccurrencesFinderJob = null;
6056 if (fOccurrencesFinderJobCanceler != null) {
6057 fOccurrencesFinderJobCanceler.uninstall();
6058 fOccurrencesFinderJobCanceler = null;
6061 if (fPostSelectionListenerWithAST != null) {
6062 SelectionListenerWithASTManager.getDefault().removeListener(this,
6063 fPostSelectionListenerWithAST);
6064 fPostSelectionListenerWithAST = null;
6067 removeOccurrenceAnnotations();
6070 protected boolean isMarkingOccurrences() {
6071 return fMarkOccurrenceAnnotations;
6074 void removeOccurrenceAnnotations() {
6075 fMarkOccurrenceModificationStamp = IDocumentExtension4.UNKNOWN_MODIFICATION_STAMP;
6076 fMarkOccurrenceTargetRegion = null;
6078 IDocumentProvider documentProvider = getDocumentProvider();
6079 if (documentProvider == null)
6082 IAnnotationModel annotationModel = documentProvider
6083 .getAnnotationModel(getEditorInput());
6084 if (annotationModel == null || fOccurrenceAnnotations == null)
6087 synchronized (getLockObject(annotationModel)) {
6088 if (annotationModel instanceof IAnnotationModelExtension) {
6089 ((IAnnotationModelExtension) annotationModel)
6090 .replaceAnnotations(fOccurrenceAnnotations, null);
6092 for (int i = 0, length = fOccurrenceAnnotations.length; i < length; i++)
6093 annotationModel.removeAnnotation(fOccurrenceAnnotations[i]);
6095 fOccurrenceAnnotations = null;