KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > pde > internal > ui > editor > PDEProjectionViewer


1 /*******************************************************************************
2  * Copyright (c) 2006 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11
12 package org.eclipse.pde.internal.ui.editor;
13
14 import org.eclipse.jface.text.information.IInformationPresenter;
15 import org.eclipse.jface.text.source.IOverviewRuler;
16 import org.eclipse.jface.text.source.IVerticalRuler;
17 import org.eclipse.jface.text.source.SourceViewerConfiguration;
18 import org.eclipse.jface.text.source.projection.ProjectionViewer;
19 import org.eclipse.pde.internal.ui.editor.text.ChangeAwareSourceViewerConfiguration;
20 import org.eclipse.swt.widgets.Composite;
21
22 /**
23  * PDEProjectionViewer
24  *
25  */

26 public class PDEProjectionViewer extends ProjectionViewer {
27
28     /**
29      * Text operation code for requesting the quick outline for the current input.
30      */

31     public static final int QUICK_OUTLINE = 513;
32     
33     private IInformationPresenter fOutlinePresenter;
34     
35     private boolean fIsQuickOutlineEnabled;
36     
37     /**
38      * @param parent
39      * @param ruler
40      * @param overviewRuler
41      * @param showsAnnotationOverview
42      * @param styles
43      */

44     public PDEProjectionViewer(Composite parent, IVerticalRuler ruler,
45             IOverviewRuler overviewRuler, boolean showsAnnotationOverview,
46             int styles, boolean isQuickOutlineEnabled) {
47         super(parent, ruler, overviewRuler, showsAnnotationOverview, styles);
48         
49         fIsQuickOutlineEnabled = isQuickOutlineEnabled;
50     }
51
52     /* (non-Javadoc)
53      * @see org.eclipse.jface.text.source.projection.ProjectionViewer#doOperation(int)
54      */

55     public void doOperation(int operation) {
56         // Ensure underlying text widget is defined
57
if ((getTextWidget() == null) ||
58                 getTextWidget().isDisposed()) {
59             return;
60         }
61         // Handle quick outline operation
62
if (operation == QUICK_OUTLINE) {
63             if (fOutlinePresenter != null) {
64                 fOutlinePresenter.showInformation();
65             }
66             return;
67         }
68         // Handle default operations
69
super.doOperation(operation);
70     }
71     
72     /* (non-Javadoc)
73      * @see org.eclipse.jface.text.source.projection.ProjectionViewer#canDoOperation(int)
74      */

75     public boolean canDoOperation(int operation) {
76         // Verify quick outline operation
77
if (operation == QUICK_OUTLINE) {
78             if (fOutlinePresenter == null) {
79                 return false;
80             }
81             return true;
82         }
83         // Verfify default operations
84
return super.canDoOperation(operation);
85     }
86     
87     /* (non-Javadoc)
88      * @see org.eclipse.jface.text.source.SourceViewer#configure(org.eclipse.jface.text.source.SourceViewerConfiguration)
89      */

90     public void configure(SourceViewerConfiguration configuration) {
91         // Ensure underlying text widget is defined
92
if ((getTextWidget() == null) ||
93                 getTextWidget().isDisposed()) {
94             return;
95         }
96         // Configure default operations
97
super.configure(configuration);
98         // Configure quick outline operation for the source viewer only if the
99
// given source viewer supports it
100
if (fIsQuickOutlineEnabled &&
101                 configuration instanceof ChangeAwareSourceViewerConfiguration) {
102             ChangeAwareSourceViewerConfiguration sourceConfiguration =
103                 (ChangeAwareSourceViewerConfiguration)configuration;
104             fOutlinePresenter = sourceConfiguration.getOutlinePresenter(this);
105             if (fOutlinePresenter != null) {
106                 fOutlinePresenter.install(this);
107             }
108         }
109     }
110     
111     /* (non-Javadoc)
112      * @see org.eclipse.jface.text.source.SourceViewer#unconfigure()
113      */

114     public void unconfigure() {
115         // Unconfigure quick outline operation
116
if (fOutlinePresenter != null) {
117             fOutlinePresenter.uninstall();
118             fOutlinePresenter = null;
119         }
120         // Unconfigure default operations
121
super.unconfigure();
122     }
123     
124 }
125
Popular Tags