KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > pde > internal > ui > editor > text > PDESourceInfoProvider


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.text;
13
14 import org.eclipse.jface.text.IRegion;
15 import org.eclipse.jface.text.ITextViewer;
16 import org.eclipse.jface.text.Region;
17 import org.eclipse.jface.text.information.IInformationProvider;
18 import org.eclipse.jface.text.information.IInformationProviderExtension;
19 import org.eclipse.pde.internal.ui.editor.PDESourcePage;
20
21 /**
22  * PDESourceInfoProvider
23  *
24  */

25 public class PDESourceInfoProvider implements IInformationProvider,
26         IInformationProviderExtension {
27
28     private PDESourcePage fSourcePage;
29     
30     /**
31      *
32      */

33     public PDESourceInfoProvider(PDESourcePage sourcePage) {
34         fSourcePage = sourcePage;
35     }
36
37     /* (non-Javadoc)
38      * @see org.eclipse.jface.text.information.IInformationProvider#getInformation(org.eclipse.jface.text.ITextViewer, org.eclipse.jface.text.IRegion)
39      */

40     public String JavaDoc getInformation(ITextViewer textViewer, IRegion subject) {
41         // This method is deprecated. Call the non-deprecated method
42
return getInformation2(textViewer, subject).toString();
43     }
44
45     /* (non-Javadoc)
46      * @see org.eclipse.jface.text.information.IInformationProvider#getSubject(org.eclipse.jface.text.ITextViewer, int)
47      */

48     public IRegion getSubject(ITextViewer textViewer, int offset) {
49         // Subject used in getInformation2
50
if ((textViewer == null) ||
51                 (fSourcePage == null)) {
52             return null;
53         }
54         // Get the selected region
55
IRegion region = PDEWordFinder.findWord(textViewer.getDocument(), offset);
56         // Ensure the region is defined. Define an empty one if it is not.
57
if (region == null) {
58             return new Region(offset, 0);
59         }
60         return region;
61     }
62
63     /* (non-Javadoc)
64      * @see org.eclipse.jface.text.information.IInformationProviderExtension#getInformation2(org.eclipse.jface.text.ITextViewer, org.eclipse.jface.text.IRegion)
65      */

66     public Object JavaDoc getInformation2(ITextViewer textViewer, IRegion subject) {
67         // Calls setInput on the quick outline popup dialog
68
if ((textViewer == null) ||
69                 (fSourcePage == null)) {
70             return null;
71         }
72         // Get the current selection, if any
73
Object JavaDoc selection = fSourcePage.getSelection();
74         // If the input is null, then the dialog does not open
75
// Define an empty object for no selection instead of null
76
if (selection == null) {
77             selection = new Object JavaDoc();
78         }
79         return selection;
80         // TODO: MP: QO: LOW: Determine range on MANIFEST.MF to do initial
81
// dynamic selection. Use IRegion. Already implemented for plugin.xml file
82
// see XMLContentAssistProcessor.assignRange()
83
}
84
85 }
86
Popular Tags