1 /*******************************************************************************
2 * Copyright (c) 2000, 2003 IBM Corporation and others.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Common Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/cpl-v10.html
9 * IBM Corporation - initial API and implementation
10 *******************************************************************************/
12 package net.sourceforge.phpeclipse.phpeditor;
15 import org.eclipse.swt.widgets.Composite;
17 import org.eclipse.jface.text.information.IInformationPresenter;
18 import org.eclipse.jface.text.source.IOverviewRuler;
19 import org.eclipse.jface.text.source.IVerticalRuler;
20 import org.eclipse.jface.text.source.SourceViewer;
21 import org.eclipse.jface.text.source.SourceViewerConfiguration;
23 //import net.sourceforge.phpdt.ui.text.JavaSourceViewerConfiguration;
27 public class JavaSourceViewer extends SourceViewer {
30 * Text operation code for requesting the outline for the current input.
32 public static final int SHOW_OUTLINE= 51;
35 * Text operation code for requesting the outline for the element at the current position.
37 public static final int OPEN_STRUCTURE= 52;
40 private IInformationPresenter fOutlinePresenter;
41 private IInformationPresenter fStructurePresenter;
43 public JavaSourceViewer(Composite parent, IVerticalRuler verticalRuler, IOverviewRuler overviewRuler, boolean showAnnotationsOverview, int styles) {
44 super(parent, verticalRuler, overviewRuler, showAnnotationsOverview, styles);
48 * @see ITextOperationTarget#doOperation(int)
50 public void doOperation(int operation) {
51 if (getTextWidget() == null)
56 fOutlinePresenter.showInformation();
59 fStructurePresenter.showInformation();
63 super.doOperation(operation);
67 * @see ITextOperationTarget#canDoOperation(int)
69 public boolean canDoOperation(int operation) {
70 if (operation == SHOW_OUTLINE)
71 return fOutlinePresenter != null;
72 if (operation == OPEN_STRUCTURE)
73 return fStructurePresenter != null;
74 return super.canDoOperation(operation);
78 * @see ISourceViewer#configure(SourceViewerConfiguration)
80 public void configure(SourceViewerConfiguration configuration) {
81 super.configure(configuration);
82 if (configuration instanceof PHPSourceViewerConfiguration) {
83 fOutlinePresenter= ((PHPSourceViewerConfiguration)configuration).getOutlinePresenter(this, false);
84 fOutlinePresenter.install(this);
86 if (configuration instanceof PHPSourceViewerConfiguration) {
87 fStructurePresenter= ((PHPSourceViewerConfiguration)configuration).getOutlinePresenter(this, true);
88 fStructurePresenter.install(this);
93 * @see TextViewer#handleDispose()
95 protected void handleDispose() {
96 if (fOutlinePresenter != null) {
97 fOutlinePresenter.uninstall();
98 fOutlinePresenter= null;
100 if (fStructurePresenter != null) {
101 fStructurePresenter.uninstall();
102 fStructurePresenter= null;
104 super.handleDispose();