001: /*******************************************************************************
002: * Copyright (c) 2006 IBM Corporation and others.
003: * All rights reserved. This program and the accompanying materials
004: * are made available under the terms of the Eclipse Public License v1.0
005: * which accompanies this distribution, and is available at
006: * http://www.eclipse.org/legal/epl-v10.html
007: *
008: * Contributors:
009: * IBM Corporation - initial API and implementation
010: *******************************************************************************/package org.eclipse.pde.internal.ui.editor;
011:
012: import org.eclipse.jface.text.information.IInformationPresenter;
013: import org.eclipse.jface.text.source.IOverviewRuler;
014: import org.eclipse.jface.text.source.IVerticalRuler;
015: import org.eclipse.jface.text.source.SourceViewerConfiguration;
016: import org.eclipse.jface.text.source.projection.ProjectionViewer;
017: import org.eclipse.pde.internal.ui.editor.text.ChangeAwareSourceViewerConfiguration;
018: import org.eclipse.swt.widgets.Composite;
019:
020: /**
021: * PDEProjectionViewer
022: *
023: */
024: public class PDEProjectionViewer extends ProjectionViewer {
025:
026: /**
027: * Text operation code for requesting the quick outline for the current input.
028: */
029: public static final int QUICK_OUTLINE = 513;
030:
031: private IInformationPresenter fOutlinePresenter;
032:
033: private boolean fIsQuickOutlineEnabled;
034:
035: /**
036: * @param parent
037: * @param ruler
038: * @param overviewRuler
039: * @param showsAnnotationOverview
040: * @param styles
041: */
042: public PDEProjectionViewer(Composite parent, IVerticalRuler ruler,
043: IOverviewRuler overviewRuler,
044: boolean showsAnnotationOverview, int styles,
045: boolean isQuickOutlineEnabled) {
046: super (parent, ruler, overviewRuler, showsAnnotationOverview,
047: styles);
048:
049: fIsQuickOutlineEnabled = isQuickOutlineEnabled;
050: }
051:
052: /* (non-Javadoc)
053: * @see org.eclipse.jface.text.source.projection.ProjectionViewer#doOperation(int)
054: */
055: public void doOperation(int operation) {
056: // Ensure underlying text widget is defined
057: if ((getTextWidget() == null) || getTextWidget().isDisposed()) {
058: return;
059: }
060: // Handle quick outline operation
061: if (operation == QUICK_OUTLINE) {
062: if (fOutlinePresenter != null) {
063: fOutlinePresenter.showInformation();
064: }
065: return;
066: }
067: // Handle default operations
068: super .doOperation(operation);
069: }
070:
071: /* (non-Javadoc)
072: * @see org.eclipse.jface.text.source.projection.ProjectionViewer#canDoOperation(int)
073: */
074: public boolean canDoOperation(int operation) {
075: // Verify quick outline operation
076: if (operation == QUICK_OUTLINE) {
077: if (fOutlinePresenter == null) {
078: return false;
079: }
080: return true;
081: }
082: // Verfify default operations
083: return super .canDoOperation(operation);
084: }
085:
086: /* (non-Javadoc)
087: * @see org.eclipse.jface.text.source.SourceViewer#configure(org.eclipse.jface.text.source.SourceViewerConfiguration)
088: */
089: public void configure(SourceViewerConfiguration configuration) {
090: // Ensure underlying text widget is defined
091: if ((getTextWidget() == null) || getTextWidget().isDisposed()) {
092: return;
093: }
094: // Configure default operations
095: super .configure(configuration);
096: // Configure quick outline operation for the source viewer only if the
097: // given source viewer supports it
098: if (fIsQuickOutlineEnabled
099: && configuration instanceof ChangeAwareSourceViewerConfiguration) {
100: ChangeAwareSourceViewerConfiguration sourceConfiguration = (ChangeAwareSourceViewerConfiguration) configuration;
101: fOutlinePresenter = sourceConfiguration
102: .getOutlinePresenter(this );
103: if (fOutlinePresenter != null) {
104: fOutlinePresenter.install(this );
105: }
106: }
107: }
108:
109: /* (non-Javadoc)
110: * @see org.eclipse.jface.text.source.SourceViewer#unconfigure()
111: */
112: public void unconfigure() {
113: // Unconfigure quick outline operation
114: if (fOutlinePresenter != null) {
115: fOutlinePresenter.uninstall();
116: fOutlinePresenter = null;
117: }
118: // Unconfigure default operations
119: super.unconfigure();
120: }
121:
122: }
|