X-Git-Url: http://git.phpeclipse.com diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/JavaSourceViewer.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/JavaSourceViewer.java new file mode 100644 index 0000000..80e6949 --- /dev/null +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/JavaSourceViewer.java @@ -0,0 +1,106 @@ +/******************************************************************************* + * Copyright (c) 2000, 2003 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ + +package net.sourceforge.phpeclipse.phpeditor; + + +import org.eclipse.swt.widgets.Composite; + +import org.eclipse.jface.text.information.IInformationPresenter; +import org.eclipse.jface.text.source.IOverviewRuler; +import org.eclipse.jface.text.source.IVerticalRuler; +import org.eclipse.jface.text.source.SourceViewer; +import org.eclipse.jface.text.source.SourceViewerConfiguration; + +//import net.sourceforge.phpdt.ui.text.JavaSourceViewerConfiguration; + + + +public class JavaSourceViewer extends SourceViewer { + + /** + * Text operation code for requesting the outline for the current input. + */ + public static final int SHOW_OUTLINE= 51; + + /** + * Text operation code for requesting the outline for the element at the current position. + */ + public static final int OPEN_STRUCTURE= 52; + + + private IInformationPresenter fOutlinePresenter; + private IInformationPresenter fStructurePresenter; + + public JavaSourceViewer(Composite parent, IVerticalRuler verticalRuler, IOverviewRuler overviewRuler, boolean showAnnotationsOverview, int styles) { + super(parent, verticalRuler, overviewRuler, showAnnotationsOverview, styles); + } + + /* + * @see ITextOperationTarget#doOperation(int) + */ + public void doOperation(int operation) { + if (getTextWidget() == null) + return; + + switch (operation) { + case SHOW_OUTLINE: + fOutlinePresenter.showInformation(); + return; + case OPEN_STRUCTURE: + fStructurePresenter.showInformation(); + return; + } + + super.doOperation(operation); + } + + /* + * @see ITextOperationTarget#canDoOperation(int) + */ + public boolean canDoOperation(int operation) { + if (operation == SHOW_OUTLINE) + return fOutlinePresenter != null; + if (operation == OPEN_STRUCTURE) + return fStructurePresenter != null; + return super.canDoOperation(operation); + } + + /* + * @see ISourceViewer#configure(SourceViewerConfiguration) + */ + public void configure(SourceViewerConfiguration configuration) { + super.configure(configuration); + if (configuration instanceof PHPSourceViewerConfiguration) { + fOutlinePresenter= ((PHPSourceViewerConfiguration)configuration).getOutlinePresenter(this, false); + fOutlinePresenter.install(this); + } + if (configuration instanceof PHPSourceViewerConfiguration) { + fStructurePresenter= ((PHPSourceViewerConfiguration)configuration).getOutlinePresenter(this, true); + fStructurePresenter.install(this); + } + } + + /* + * @see TextViewer#handleDispose() + */ + protected void handleDispose() { + if (fOutlinePresenter != null) { + fOutlinePresenter.uninstall(); + fOutlinePresenter= null; + } + if (fStructurePresenter != null) { + fStructurePresenter.uninstall(); + fStructurePresenter= null; + } + super.handleDispose(); + } +}