X-Git-Url: http://git.phpeclipse.com
diff --git a/net.sourceforge.phpeclipse.ui/src/net/sourceforge/phpeclipse/ui/editor/StructuredTextEditor.java b/net.sourceforge.phpeclipse.ui/src/net/sourceforge/phpeclipse/ui/editor/StructuredTextEditor.java
index c09a5be..5ee45b2 100644
--- a/net.sourceforge.phpeclipse.ui/src/net/sourceforge/phpeclipse/ui/editor/StructuredTextEditor.java
+++ b/net.sourceforge.phpeclipse.ui/src/net/sourceforge/phpeclipse/ui/editor/StructuredTextEditor.java
@@ -8,7 +8,7 @@
* Contributors:
* Christopher Lenz - initial API and implementation
*
- * $Id: StructuredTextEditor.java,v 1.1 2004-09-02 18:26:30 jsurfer Exp $
+ * $Id: StructuredTextEditor.java,v 1.2 2006-10-21 23:13:54 pombredanne Exp $
*/
package net.sourceforge.phpeclipse.ui.editor;
@@ -34,34 +34,34 @@ import org.eclipse.ui.views.contentoutline.IContentOutlinePage;
* Abstract base class for editors that keep a source model synchronized with
* the textual contants being edited.
*/
-public abstract class StructuredTextEditor extends TextEditor
- implements IReconcilingParticipant {
+public abstract class StructuredTextEditor extends TextEditor implements
+ IReconcilingParticipant {
// Inner Classes -----------------------------------------------------------
- /**
- * Listens to changes to the selection in the outline page, and changes the
- * selection and highlight range in the editor accordingly.
- */
- private class OutlineSelectionChangedListener
- implements ISelectionChangedListener {
-
- /*
- * @see ISelectionChangedListener#selectionChanged(SelectionChangedEvent)
- */
- public void selectionChanged(SelectionChangedEvent event) {
- IStructuredSelection selection =
- (IStructuredSelection) event.getSelection();
- if (selection.isEmpty()) {
- resetHighlightRange();
- } else {
- ISourceReference element = (ISourceReference)
- selection.getFirstElement();
- highlightElement(element, true);
- }
- }
-
- }
+ /**
+ * Listens to changes to the selection in the outline page, and changes the
+ * selection and highlight range in the editor accordingly.
+ */
+ private class OutlineSelectionChangedListener implements
+ ISelectionChangedListener {
+
+ /*
+ * @see ISelectionChangedListener#selectionChanged(SelectionChangedEvent)
+ */
+ public void selectionChanged(SelectionChangedEvent event) {
+ IStructuredSelection selection = (IStructuredSelection) event
+ .getSelection();
+ if (selection.isEmpty()) {
+ resetHighlightRange();
+ } else {
+ ISourceReference element = (ISourceReference) selection
+ .getFirstElement();
+ highlightElement(element, true);
+ }
+ }
+
+ }
// Instance Variables ------------------------------------------------------
@@ -85,10 +85,9 @@ public abstract class StructuredTextEditor extends TextEditor
if (adapter.equals(IContentOutlinePage.class)) {
if (outlinePage == null) {
outlinePage = createOutlinePage();
- outlinePageSelectionListener =
- new OutlineSelectionChangedListener();
- outlinePage.addSelectionChangedListener(
- outlinePageSelectionListener);
+ outlinePageSelectionListener = new OutlineSelectionChangedListener();
+ outlinePage
+ .addSelectionChangedListener(outlinePageSelectionListener);
}
return outlinePage;
}
@@ -106,7 +105,7 @@ public abstract class StructuredTextEditor extends TextEditor
// IReconcilingParticipant Implementation ----------------------------------
- /*
+ /*
* @see IReconcilingParticipant#reconciled()
*/
public void reconciled() {
@@ -150,9 +149,10 @@ public abstract class StructuredTextEditor extends TextEditor
/**
* Returns the source model element at the specified offset.
*
- * @param offset the offset into the document
- * @return the element at the given offset, or null if no model is
- * available or there is no element at the offset
+ * @param offset
+ * the offset into the document
+ * @return the element at the given offset, or null if no model
+ * is available or there is no element at the offset
*/
public ISourceReference getElementAt(int offset) {
ISourceReference retVal = null;
@@ -178,33 +178,34 @@ public abstract class StructuredTextEditor extends TextEditor
/**
* Informs the editor that its outliner has been closed.
*
- * TODO There must be a more elegant way to get notified when the outline
- * page was closed. Otherwise move this method into an interface
+ * TODO There must be a more elegant way to get notified when the outline
+ * page was closed. Otherwise move this method into an interface
*/
public void outlinePageClosed() {
if (outlinePage != null) {
- outlinePage.removeSelectionChangedListener(
- outlinePageSelectionListener);
+ outlinePage
+ .removeSelectionChangedListener(outlinePageSelectionListener);
outlinePage = null;
resetHighlightRange();
}
}
/**
- * Synchronizes the outliner selection with the given element position in
+ * Synchronizes the outliner selection with the given element position in
* the editor.
*
- * @param element the java element to select
+ * @param element
+ * the java element to select
*/
public void synchronizeOutlinePage(ISourceReference element) {
if (outlinePage != null) {
- outlinePage.removeSelectionChangedListener(
- outlinePageSelectionListener);
+ outlinePage
+ .removeSelectionChangedListener(outlinePageSelectionListener);
if (outlinePage instanceof ModelBasedOutlinePage) {
((ModelBasedOutlinePage) outlinePage).select(element);
}
- outlinePage.addSelectionChangedListener(
- outlinePageSelectionListener);
+ outlinePage
+ .addSelectionChangedListener(outlinePageSelectionListener);
}
}
@@ -224,15 +225,17 @@ public abstract class StructuredTextEditor extends TextEditor
/**
* Highlights the given element.
*
- * @param element the element that should be highlighted
- * @param moveCursor whether the cursor should be moved to the element
+ * @param element
+ * the element that should be highlighted
+ * @param moveCursor
+ * whether the cursor should be moved to the element
*/
protected final void highlightElement(ISourceReference element,
boolean moveCursor) {
if (element != null) {
IRegion highlightRegion = element.getSourceRegion();
- setHighlightRange(highlightRegion.getOffset(),
- highlightRegion.getLength(), moveCursor);
+ setHighlightRange(highlightRegion.getOffset(), highlightRegion
+ .getLength(), moveCursor);
} else {
resetHighlightRange();
}
@@ -252,23 +255,26 @@ public abstract class StructuredTextEditor extends TextEditor
/**
* Recursively searches the specified list of elements managed by the given
- * model for the element that covers the specified offfset with minimal
+ * model for the element that covers the specified offfset with minimal
* padding.
*
- * @param model the source model
- * @param elements the current list of elements
- * @param offset the offset into the document
+ * @param model
+ * the source model
+ * @param elements
+ * the current list of elements
+ * @param offset
+ * the offset into the document
* @return the model element at the specified offset, or null if
* no element could be found
*/
- private static ISourceReference getElementAt(
- ISourceModel model, ISourceReference elements[], int offset) {
+ private static ISourceReference getElementAt(ISourceModel model,
+ ISourceReference elements[], int offset) {
ISourceReference retVal = null;
for (int i = 0; i < elements.length; i++) {
ISourceReference element = elements[i];
IRegion region = element.getSourceRegion();
if ((offset > region.getOffset())
- && (offset < (region.getOffset() + region.getLength()))) {
+ && (offset < (region.getOffset() + region.getLength()))) {
ISourceReference[] children = model.getChildren(element);
if (children.length > 0) {
retVal = getElementAt(model, children, offset);