From 97b3569dc3699d0171b80abdb51511bf64d4f4f6 Mon Sep 17 00:00:00 2001 From: khartlage Date: Sat, 31 May 2003 13:50:30 +0000 Subject: [PATCH] Use abstraction of PHPOutlinePage --- .../phpeditor/AbstractContentOutlinePage.java | 51 ++++++++++++++++++++ .../phpeditor/PHPContentOutlinePage.java | 51 +++++-------------- .../phpeclipse/phpeditor/PHPEditor.java | 7 +-- .../phpeditor/php/PHPCompletionProcessor.java | 15 ++++-- 4 files changed, 76 insertions(+), 48 deletions(-) create mode 100644 net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/AbstractContentOutlinePage.java diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/AbstractContentOutlinePage.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/AbstractContentOutlinePage.java new file mode 100644 index 0000000..726536a --- /dev/null +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/AbstractContentOutlinePage.java @@ -0,0 +1,51 @@ +package net.sourceforge.phpeclipse.phpeditor; + +/********************************************************************** +Copyright (c) 2000, 2002 IBM Corp. and others. +All rights reserved. This program and the accompanying materials +are made available under the terms of the Common Public License v1.0 +which accompanies this distribution, and is available at +http://www.eclipse.org/legal/cpl-v10.html + +Contributors: + IBM Corporation - Initial implementation + Klaus Hartlage - www.eclipseproject.de +**********************************************************************/ + +import org.eclipse.jface.viewers.TreeViewer; +import org.eclipse.swt.widgets.Control; +import org.eclipse.ui.views.contentoutline.ContentOutlinePage; + +/** + * An abstraction of a content outline page + */ +public abstract class AbstractContentOutlinePage extends ContentOutlinePage { + + protected Object fInput; + /** + * Sets the input of the outline page + */ + public void setInput(Object input) { + fInput = input; + update(); + } + + /** + * Updates the outline page. + */ + public void update() { + TreeViewer viewer = getTreeViewer(); + + if (viewer != null) { + Control control = viewer.getControl(); + if (control != null && !control.isDisposed()) { + control.setRedraw(false); + viewer.setInput(fInput); + viewer.expandAll(); + control.setRedraw(true); + } + } + } + + +} diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/PHPContentOutlinePage.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/PHPContentOutlinePage.java index 78afe4e..1544023 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/PHPContentOutlinePage.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/PHPContentOutlinePage.java @@ -18,7 +18,11 @@ import java.util.Comparator; import java.util.List; import java.util.TreeSet; -import net.sourceforge.phpdt.internal.compiler.parser.*; +import net.sourceforge.phpdt.internal.compiler.parser.Outlineable; +import net.sourceforge.phpdt.internal.compiler.parser.OutlineableWithChildren; +import net.sourceforge.phpdt.internal.compiler.parser.PHPOutlineInfo; +import net.sourceforge.phpdt.internal.compiler.parser.PHPSegment; +import net.sourceforge.phpdt.internal.compiler.parser.PHPSegmentWithChildren; import net.sourceforge.phpdt.internal.ui.viewsupport.ImageDescriptorRegistry; import net.sourceforge.phpeclipse.PHPeclipsePlugin; @@ -36,18 +40,17 @@ import org.eclipse.jface.viewers.TreeViewer; import org.eclipse.jface.viewers.Viewer; import org.eclipse.swt.graphics.Image; import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Control; import org.eclipse.ui.texteditor.IDocumentProvider; import org.eclipse.ui.texteditor.ITextEditor; -import org.eclipse.ui.views.contentoutline.ContentOutlinePage; -import test.PHPParserSuperclass; + import test.PHPParserManager; +import test.PHPParserSuperclass; /** * A content outline page which always represents the functions of the * connected PHPEditor. */ -public class PHPContentOutlinePage extends ContentOutlinePage { +public class PHPContentOutlinePage extends AbstractContentOutlinePage { private static final String ERROR = "error"; //$NON-NLS-1$ private static final String WARNING = "warning"; //$NON-NLS-1$ @@ -230,18 +233,17 @@ public class PHPContentOutlinePage extends ContentOutlinePage { } } - protected Object fInput; protected IDocumentProvider fDocumentProvider; protected ITextEditor fTextEditor; protected PHPEditor fEditor; - protected ContentProvider contentProvider; + protected ContentProvider fContentProvider; /** * Creates a content outline page using the given provider and the given editor. */ public PHPContentOutlinePage(IDocumentProvider provider, ITextEditor editor) { super(); - contentProvider = null; + fContentProvider = null; fDocumentProvider = provider; fTextEditor = editor; if (editor instanceof PHPEditor) @@ -257,8 +259,8 @@ public class PHPContentOutlinePage extends ContentOutlinePage { TreeViewer viewer = getTreeViewer(); - contentProvider = new ContentProvider(); - viewer.setContentProvider(contentProvider); + fContentProvider = new ContentProvider(); + viewer.setContentProvider(fContentProvider); viewer.setLabelProvider(new OutlineLabelProvider()); viewer.addSelectionChangedListener(this); @@ -288,35 +290,10 @@ public class PHPContentOutlinePage extends ContentOutlinePage { } } } - - /** - * Sets the input of the outline page - */ - public void setInput(Object input) { - fInput = input; - update(); - } - - /** - * Updates the outline page. - */ - public void update() { - TreeViewer viewer = getTreeViewer(); - - if (viewer != null) { - Control control = viewer.getControl(); - if (control != null && !control.isDisposed()) { - control.setRedraw(false); - viewer.setInput(fInput); - viewer.expandAll(); - control.setRedraw(true); - } - } - } public Object[] getVariables() { - if (contentProvider != null) { - return contentProvider.getVariables(); + if (fContentProvider != null) { + return fContentProvider.getVariables(); } return null; } diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/PHPEditor.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/PHPEditor.java index 701ebf9..b61c156 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/PHPEditor.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/PHPEditor.java @@ -65,9 +65,6 @@ import org.eclipse.swt.graphics.RGB; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Shell; import org.eclipse.ui.IEditorInput; -import org.eclipse.ui.IViewPart; -import org.eclipse.ui.IWorkbenchPage; -import org.eclipse.ui.PartInitException; import org.eclipse.ui.actions.ActionContext; import org.eclipse.ui.actions.ActionGroup; import org.eclipse.ui.texteditor.ContentAssistAction; @@ -92,7 +89,7 @@ public class PHPEditor extends StatusTextEditor implements IViewPartInputProvide // protected PHPActionGroup fActionGroups; /** The outline page */ - private PHPContentOutlinePage fOutlinePage; + private AbstractContentOutlinePage fOutlinePage; // protected PHPSyntaxParserThread fValidationThread = null; @@ -216,7 +213,7 @@ public class PHPEditor extends StatusTextEditor implements IViewPartInputProvide return fActionGroups; } - public PHPContentOutlinePage getfOutlinePage() { + public AbstractContentOutlinePage getfOutlinePage() { return fOutlinePage; } diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/php/PHPCompletionProcessor.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/php/PHPCompletionProcessor.java index 64fcaff..dee6cca 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/php/PHPCompletionProcessor.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/php/PHPCompletionProcessor.java @@ -23,6 +23,7 @@ import net.sourceforge.phpdt.internal.ui.text.template.BuiltInEngine; import net.sourceforge.phpdt.internal.ui.text.template.IdentifierEngine; import net.sourceforge.phpdt.internal.ui.text.template.TemplateEngine; import net.sourceforge.phpeclipse.PHPeclipsePlugin; +import net.sourceforge.phpeclipse.phpeditor.AbstractContentOutlinePage; import net.sourceforge.phpeclipse.phpeditor.PHPContentOutlinePage; import net.sourceforge.phpeclipse.phpeditor.PHPEditor; @@ -249,7 +250,7 @@ public class PHPCompletionProcessor implements IContentAssistProcessor { fComparator = new PHPCompletionProposalComparator(); } - + /** * Tells this processor to order the proposals alphabetically. * @@ -258,7 +259,7 @@ public class PHPCompletionProcessor implements IContentAssistProcessor { public void orderProposalsAlphabetically(boolean order) { fComparator.setOrderAlphabetically(order); } - + /** * Sets this processor's set of characters triggering the activation of the * completion proposal computation. @@ -266,7 +267,7 @@ public class PHPCompletionProcessor implements IContentAssistProcessor { * @param activationSet the activation set */ public void setCompletionProposalAutoActivationCharacters(char[] activationSet) { - fProposalAutoActivationSet= activationSet; + fProposalAutoActivationSet = activationSet; } /* (non-Javadoc) * Method declared on IContentAssistProcessor @@ -308,13 +309,15 @@ public class PHPCompletionProcessor implements IContentAssistProcessor { if (offset > 0) { PHPEditor editor = null; - PHPContentOutlinePage outlinePage = null; + AbstractContentOutlinePage outlinePage = null; IEditorPart targetEditor = PHPeclipsePlugin.getActiveWorkbenchWindow().getActivePage().getActiveEditor(); if (targetEditor != null && (targetEditor instanceof PHPEditor)) { editor = (PHPEditor) targetEditor; outlinePage = editor.getfOutlinePage(); - identifiers = outlinePage.getVariables(); + if (outlinePage instanceof PHPContentOutlinePage) { + identifiers = ((PHPContentOutlinePage) outlinePage).getVariables(); + } } } @@ -463,7 +466,7 @@ public class PHPCompletionProcessor implements IContentAssistProcessor { */ public char[] getCompletionProposalAutoActivationCharacters() { return fProposalAutoActivationSet; -// return null; // new char[] { '$' }; + // return null; // new char[] { '$' }; } /* (non-Javadoc) -- 1.7.1