changes for new Action
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpeclipse / phpeditor / JavaSourceViewer.java
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
7  * 
8  * Contributors:
9  *     IBM Corporation - initial API and implementation
10  *******************************************************************************/
11
12 package net.sourceforge.phpeclipse.phpeditor;
13
14
15 import org.eclipse.swt.widgets.Composite;
16
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;
22
23 //import net.sourceforge.phpdt.ui.text.JavaSourceViewerConfiguration;
24
25
26
27 public class JavaSourceViewer extends SourceViewer {
28
29         /**
30          * Text operation code for requesting the outline for the current input.
31          */
32         public static final int SHOW_OUTLINE= 51;
33
34         /**
35          * Text operation code for requesting the outline for the element at the current position.
36          */
37         public static final int OPEN_STRUCTURE= 52;
38
39
40         private IInformationPresenter fOutlinePresenter;
41         private IInformationPresenter fStructurePresenter;
42
43         public JavaSourceViewer(Composite parent, IVerticalRuler verticalRuler, IOverviewRuler overviewRuler, boolean showAnnotationsOverview, int styles) {
44                 super(parent, verticalRuler, overviewRuler, showAnnotationsOverview, styles);
45         }
46
47         /*
48          * @see ITextOperationTarget#doOperation(int)
49          */
50         public void doOperation(int operation) {
51                 if (getTextWidget() == null)
52                         return;
53
54                 switch (operation) {
55                         case SHOW_OUTLINE:
56                                 fOutlinePresenter.showInformation();
57                                 return;
58                         case OPEN_STRUCTURE:
59                                 fStructurePresenter.showInformation();
60                                 return;
61                 }
62                 
63                 super.doOperation(operation);
64         }
65
66         /*
67          * @see ITextOperationTarget#canDoOperation(int)
68          */
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);
75         }
76
77         /*
78          * @see ISourceViewer#configure(SourceViewerConfiguration)
79          */
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);
85                 }
86                 if (configuration instanceof PHPSourceViewerConfiguration) {
87                         fStructurePresenter= ((PHPSourceViewerConfiguration)configuration).getOutlinePresenter(this, true);
88                         fStructurePresenter.install(this);
89                 }
90         }
91
92         /*
93          * @see TextViewer#handleDispose()
94          */
95         protected void handleDispose() {
96                 if (fOutlinePresenter != null) {
97                         fOutlinePresenter.uninstall();  
98                         fOutlinePresenter= null;
99                 }
100                 if (fStructurePresenter != null) {
101                         fStructurePresenter.uninstall();
102                         fStructurePresenter= null;
103                 }
104                 super.handleDispose();
105         }
106 }